- introducing read/unread images in the MCP, if you view something through the MCP it will not update the "read" status of a post/topic/forum [includes Bug #6796]

git-svn-id: file:///svn/phpbb/trunk@6936 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Nils Adermann 2007-01-27 16:04:58 +00:00
parent 14e209a487
commit aa8ebc7bf3
7 changed files with 194 additions and 30 deletions

View file

@ -99,8 +99,18 @@ function mcp_forum_view($id, $mode, $action, $forum_info)
$topic_rows = array();
$sql = 'SELECT t.*
FROM ' . TOPICS_TABLE . " t
if ($config['load_db_lastread'])
{
$read_tracking_join = ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id'] . ')';
$read_tracking_select = ', tt.mark_time';
}
else
{
$read_tracking_join = $read_tracking_select = '';
}
$sql = "SELECT t.*$read_tracking_select
FROM " . TOPICS_TABLE . " t $read_tracking_join
WHERE (t.forum_id = $forum_id OR t.forum_id = 0)
" . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1') . "
$limit_time_sql
@ -109,19 +119,40 @@ function mcp_forum_view($id, $mode, $action, $forum_info)
while ($row = $db->sql_fetchrow($result))
{
$topic_rows[] = $row;
$topic_rows[$row['topic_id']] = $row;
$topic_list[] = $row['topic_id'];
}
$db->sql_freeresult($result);
foreach ($topic_rows as $row)
$topic_tracking_info = array();
// Get topic tracking info
if ($config['load_db_lastread'])
{
$topic_tracking_info = get_topic_tracking($forum_id, $topic_list, $topic_rows, array($forum_id => $forum_info['mark_time']), array());
}
else
{
$topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_list, array());
}
foreach ($topic_rows as $topic_id => $row)
{
$topic_title = '';
$replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
if ($row['topic_status'] == ITEM_MOVED)
{
$unread_topic = false;
}
else
{
$unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
}
// Get folder img, topic status/type related information
$folder_img = $folder_alt = $topic_type = '';
topic_status($row, $replies, false, $folder_img, $folder_alt, $topic_type);
topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
$topic_title = censor_text($row['topic_title']);
@ -159,6 +190,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info)
'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && $auth->acl_get('m_report', $row['forum_id'])) ? true : false,
'S_TOPIC_UNAPPROVED' => $topic_unapproved,
'S_POSTS_UNAPPROVED' => $posts_unapproved,
'S_UNREAD_TOPIC' => $unread_topic,
);
if ($row['topic_status'] == ITEM_MOVED)

View file

@ -145,7 +145,7 @@ class mcp_main
$forum_id = request_var('f', 0);
$forum_info = get_forum_data($forum_id, 'm_');
$forum_info = get_forum_data($forum_id, 'm_', true);
if (!sizeof($forum_info))
{

View file

@ -22,7 +22,7 @@ function mcp_post_details($id, $mode, $action)
$start = request_var('start', 0);
// Get post data
$post_info = get_post_data(array($post_id));
$post_info = get_post_data(array($post_id), false, true);
if (!sizeof($post_info))
{
@ -91,6 +91,21 @@ function mcp_post_details($id, $mode, $action)
// Set some vars
$users_ary = $usernames_ary = array();
$post_id = $post_info['post_id'];
$topic_tracking_info = array();
// Get topic tracking info
if ($config['load_db_lastread'])
{
$tmp_topic_data = array($post_info['topic_id'] => $post_info);
$topic_tracking_info = get_topic_tracking($post_info['forum_id'], $post_info['topic_id'], $tmp_topic_data, array($post_info['forum_id'] => $post_info['forum_mark_time']));
unset($tmp_topic_data);
}
else
{
$topic_tracking_info = get_complete_topic_tracking($post_info['forum_id'], $post_info['topic_id']);
}
$post_unread = (isset($topic_tracking_info[$post_info['topic_id']]) && $post_info['post_time'] > $topic_tracking_info[$post_info['topic_id']]) ? true : false;
// Process message, leave it uncensored
$message = $post_info['post_text'];
@ -128,6 +143,8 @@ function mcp_post_details($id, $mode, $action)
'U_VIEW_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&p=' . $post_info['post_id'] . '#p' . $post_info['post_id']),
'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&t=' . $post_info['topic_id']),
'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'NEW_POST') : $user->img('icon_post_target', 'POST'),
'RETURN_TOPIC' => sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$post_info['forum_id']}&amp;p=$post_id") . "#p$post_id\">", '</a>'),
'RETURN_FORUM' => sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f={$post_info['forum_id']}&amp;start={$start}") . '">', '</a>'),
'REPORTED_IMG' => $user->img('icon_topic_reported', $user->lang['POST_REPORTED']),

View file

@ -82,7 +82,7 @@ class mcp_queue
}
}
$post_info = get_post_data(array($post_id), 'm_approve');
$post_info = get_post_data(array($post_id), 'm_approve', true);
if (!sizeof($post_info))
{
@ -99,6 +99,21 @@ class mcp_queue
);
}
$topic_tracking_info = array();
// Get topic tracking info
if ($config['load_db_lastread'])
{
$tmp_topic_data = array($post_info['topic_id'] => $post_info);
$topic_tracking_info = get_topic_tracking($post_info['forum_id'], $post_info['topic_id'], $tmp_topic_data, array($post_info['forum_id'] => $post_info['forum_mark_time']));
unset($tmp_topic_data);
}
else
{
$topic_tracking_info = get_complete_topic_tracking($post_info['forum_id'], $post_info['topic_id']);
}
$post_unread = (isset($topic_tracking_info[$post_info['topic_id']]) && $post_info['post_time'] > $topic_tracking_info[$post_info['topic_id']]) ? true : false;
// Process message, leave it uncensored
$message = $post_info['post_text'];
$message = str_replace("\n", '<br />', $message);
@ -130,6 +145,8 @@ class mcp_queue
'U_VIEW_POST' => $post_url,
'U_VIEW_TOPIC' => $topic_url,
'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'NEW_POST') : $user->img('icon_post_target', 'POST'),
'RETURN_QUEUE' => sprintf($user->lang['RETURN_QUEUE'], '<a href="' . append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue' . (($topic_id) ? '&amp;mode=unapproved_topics' : '&amp;mode=unapproved_posts')) . "&amp;start=$start\">", '</a>'),
'RETURN_POST' => sprintf($user->lang['RETURN_POST'], '<a href="' . $post_url . '">', '</a>'),
'RETURN_TOPIC_SIMPLE' => sprintf($user->lang['RETURN_TOPIC_SIMPLE'], '<a href="' . $topic_url . '">', '</a>'),

View file

@ -83,7 +83,7 @@ class mcp_reports
$post_id = $report['post_id'];
}
$post_info = get_post_data(array($post_id), 'm_report');
$post_info = get_post_data(array($post_id), 'm_report', true);
if (!sizeof($post_info))
{
@ -107,13 +107,27 @@ class mcp_reports
);
}
$topic_tracking_info = array();
// Get topic tracking info
if ($config['load_db_lastread'])
{
$tmp_topic_data = array($post_info['topic_id'] => $post_info);
$topic_tracking_info = get_topic_tracking($post_info['forum_id'], $post_info['topic_id'], $tmp_topic_data, array($post_info['forum_id'] => $post_info['forum_mark_time']));
unset($tmp_topic_data);
}
else
{
$topic_tracking_info = get_complete_topic_tracking($post_info['forum_id'], $post_info['topic_id']);
}
$post_unread = (isset($topic_tracking_info[$post_info['topic_id']]) && $post_info['post_time'] > $topic_tracking_info[$post_info['topic_id']]) ? true : false;
// Process message, leave it uncensored
$message = $post_info['post_text'];
$message = str_replace("\n", '<br />', $message);
if ($post_info['bbcode_bitfield'])
{
include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
$bbcode = new bbcode($post_info['bbcode_bitfield']);
$bbcode->bbcode_second_pass($message, $post_info['bbcode_uid'], $post_info['bbcode_bitfield']);
}
@ -139,6 +153,7 @@ class mcp_reports
'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&amp;t=' . $post_info['topic_id']),
'EDIT_IMG' => $user->img('icon_post_edit', $user->lang['EDIT_POST']),
'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'NEW_POST') : $user->img('icon_post_target', 'POST'),
'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', $user->lang['POST_UNAPPROVED']),
'RETURN_REPORTS' => sprintf($user->lang['RETURN_REPORTS'], '<a href="' . append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports' . (($post_info['post_reported']) ? '&amp;mode=reports' : '&amp;mode=reports_closed') . '&amp;start=' . $start . '&amp;f=' . $post_info['forum_id']) . '">', '</a>'),

View file

@ -21,7 +21,7 @@ function mcp_topic_view($id, $mode, $action)
$user->add_lang('viewtopic');
$topic_id = request_var('t', 0);
$topic_info = get_topic_data(array($topic_id));
$topic_info = get_topic_data(array($topic_id), false, true);
if (!sizeof($topic_info))
{
@ -118,6 +118,20 @@ function mcp_topic_view($id, $mode, $action)
$bbcode = new bbcode(base64_encode($bbcode_bitfield));
}
$topic_tracking_info = array();
// Get topic tracking info
if ($config['load_db_lastread'])
{
$tmp_topic_data = array($topic_id => $topic_info);
$topic_tracking_info = get_topic_tracking($topic_info['forum_id'], $topic_id, $tmp_topic_data, array($topic_info['forum_id'] => $topic_info['forum_mark_time']));
unset($tmp_topic_data);
}
else
{
$topic_tracking_info = get_complete_topic_tracking($topic_info['forum_id'], $topic_id);
}
foreach ($rowset as $i => $row)
{
$has_unapproved_posts = false;
@ -138,6 +152,8 @@ function mcp_topic_view($id, $mode, $action)
$has_unapproved_posts = true;
}
$post_unread = (isset($topic_tracking_info[$topic_id]) && $row['post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
$template->assign_block_vars('postrow', array(
'POST_AUTHOR_FULL' => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
'POST_AUTHOR_COLOUR' => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
@ -150,7 +166,7 @@ function mcp_topic_view($id, $mode, $action)
'POST_ID' => $row['post_id'],
'RETURN_TOPIC' => sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $topic_id) . '">', '</a>'),
'MINI_POST_IMG' => ($row['post_time'] > $user->data['user_lastvisit'] && $user->data['is_registered']) ? $user->img('icon_post_target_unread', $user->lang['NEW_POST']) : $user->img('icon_post_target', $user->lang['POST']),
'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'NEW_POST') : $user->img('icon_post_target', 'POST'),
'S_POST_REPORTED' => ($row['post_reported']) ? true : false,
'S_POST_UNAPPROVED' => ($row['post_approved']) ? false : true,

View file

@ -262,9 +262,9 @@ function extra_url()
/**
* Get simple topic data
*/
function get_topic_data($topic_ids, $acl_list = false)
function get_topic_data($topic_ids, $acl_list = false, $read_tracking = false)
{
global $auth, $db;
global $auth, $db, $config, $user;
static $rowset = array();
$topics = array();
@ -274,15 +274,53 @@ function get_topic_data($topic_ids, $acl_list = false)
return array();
}
$cache_topic_ids = array_intersect($topic_ids, array_keys($rowset));
$topic_ids = array_diff($topic_ids, array_keys($rowset));
// cache might not contain read tracking info, so we can't use it if read
// tracking information is requested
if (!$read_tracking)
{
$cache_topic_ids = array_intersect($topic_ids, array_keys($rowset));
$topic_ids = array_diff($topic_ids, array_keys($rowset));
}
else
{
$cache_topic_ids = array();
}
if (sizeof($topic_ids))
{
$sql = 'SELECT f.*, t.*
FROM ' . TOPICS_TABLE . ' t
LEFT JOIN ' . FORUMS_TABLE . ' f ON t.forum_id = f.forum_id
WHERE ' . $db->sql_in_set('t.topic_id', $topic_ids);
$sql_array = array(
'SELECT' => 't.*, f.*',
'FROM' => array(
TOPICS_TABLE => 't',
),
'LEFT_JOIN' => array(
array(
'FROM' => array(FORUMS_TABLE => 'f'),
'ON' => 'f.forum_id = t.forum_id'
)
),
'WHERE' => $db->sql_in_set('t.topic_id', $topic_ids)
);
if ($read_tracking && $config['load_db_lastread'])
{
$sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time as forum_mark_time';
$sql_array['LEFT_JOIN'][] = array(
'FROM' => array(TOPICS_TRACK_TABLE => 'tt'),
'ON' => 'tt.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tt.topic_id'
);
$sql_array['LEFT_JOIN'][] = array(
'FROM' => array(FORUMS_TRACK_TABLE => 'ft'),
'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND t.forum_id = ft.forum_id'
);
}
$sql = $db->sql_build_query('SELECT', $sql_array);
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
@ -319,9 +357,9 @@ function get_topic_data($topic_ids, $acl_list = false)
/**
* Get simple post data
*/
function get_post_data($post_ids, $acl_list = false)
function get_post_data($post_ids, $acl_list = false, $read_tracking = false)
{
global $db, $auth;
global $db, $auth, $config, $user;
$rowset = array();
@ -330,7 +368,7 @@ function get_post_data($post_ids, $acl_list = false)
return array();
}
$sql = $db->sql_build_query('SELECT', array(
$sql_array = array(
'SELECT' => 'p.*, u.*, t.*, f.*',
'FROM' => array(
@ -349,8 +387,26 @@ function get_post_data($post_ids, $acl_list = false)
'WHERE' => $db->sql_in_set('p.post_id', $post_ids) . '
AND u.user_id = p.poster_id
AND t.topic_id = p.topic_id',
));
);
if ($read_tracking && $config['load_db_lastread'])
{
$sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time as forum_mark_time';
$sql_array['LEFT_JOIN'][] = array(
'FROM' => array(TOPICS_TRACK_TABLE => 'tt'),
'ON' => 'tt.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tt.topic_id'
);
$sql_array['LEFT_JOIN'][] = array(
'FROM' => array(FORUMS_TRACK_TABLE => 'ft'),
'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND t.forum_id = ft.forum_id'
);
}
$sql = $db->sql_build_query('SELECT', $sql_array);
$result = $db->sql_query($sql);
unset($sql_array);
while ($row = $db->sql_fetchrow($result))
{
@ -381,9 +437,9 @@ function get_post_data($post_ids, $acl_list = false)
/**
* Get simple forum data
*/
function get_forum_data($forum_id, $acl_list = 'f_list')
function get_forum_data($forum_id, $acl_list = 'f_list', $read_tracking = false)
{
global $auth, $db;
global $auth, $db, $user, $config;
$rowset = array();
@ -397,9 +453,20 @@ function get_forum_data($forum_id, $acl_list = 'f_list')
return array();
}
$sql = 'SELECT *
FROM ' . FORUMS_TABLE . '
WHERE ' . $db->sql_in_set('forum_id', $forum_id);
if ($read_tracking && $config['load_db_lastread'])
{
$read_tracking_join = ' LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . '
AND ft.forum_id = f.forum_id)';
$read_tracking_select = ', ft.mark_time';
}
else
{
$read_tracking_join = $read_tracking_select = '';
}
$sql = "SELECT * $read_tracking_select
FROM " . FORUMS_TABLE . " f$read_tracking_join
WHERE " . $db->sql_in_set('f.forum_id', $forum_id);
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))