Forum/Topic marking updates

git-svn-id: file:///svn/phpbb/trunk@2879 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Paul S. Owen 2002-08-22 13:58:35 +00:00
parent 6cf59bc2e9
commit 69e89c9067
3 changed files with 68 additions and 158 deletions

View file

@ -55,7 +55,7 @@ $session->configure($userdata);
// //
if ( $mark_read == 'forums' ) if ( $mark_read == 'forums' )
{ {
if ( $userdata['user_id'] != ANONYMOUS ) if ( $userdata['user_id'] )
{ {
setcookie($board_config['cookie_name'] . '_f_all', time(), 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']); setcookie($board_config['cookie_name'] . '_f_all', time(), 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
} }
@ -71,8 +71,8 @@ if ( $mark_read == 'forums' )
// End handle marking posts // End handle marking posts
// //
$tracking_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) : array(); $mark_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize(stripslashes($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t'])) : array();
$tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) : array(); $mark_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize(stripslashes($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f'])) : array();
// //
// If you don't use these stats on your index you may want to consider // If you don't use these stats on your index you may want to consider
@ -235,37 +235,23 @@ if ( ( $total_categories = count($category_rows) ) )
else else
{ {
$unread_topics = false; $unread_topics = false;
if ( $userdata['user_id'] != ANONYMOUS ) if ( $userdata['user_id'] && $forum_data[$j]['forum_last_post_time'] > $userdata['user_lastvisit'] )
{
if ( !empty($new_topic_data[$row_forum_id]) )
{
$forum_last_post_time = 0;
foreach ( $new_topic_data[$row_forum_id] as $check_topic_id => $check_post_time )
{
if ( empty($tracking_topics[$check_topic_id]) || $tracking_topics[$check_topic_id] < $check_post_time)
{ {
$unread_topics = true; $unread_topics = true;
$forum_last_post_time = max($check_post_time, $forum_last_post_time);
}
}
if ( !empty($tracking_forums[$row_forum_id]) )
{
if ( $tracking_forums[$row_forum_id] > $forum_last_post_time )
{
$unread_topics = false;
}
}
if ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all']) ) if ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all']) )
{ {
if ( $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all'] > $forum_last_post_time ) if ( $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all'] > $forum_data[$j]['forum_last_post_time'] )
{ {
$unread_topics = false; $unread_topics = false;
} }
} }
if ( isset($mark_topics[$row_forum_id]) || isset($mark_forums[$row_forum_id]) )
{
if ( $mark_forums[$row_forum_id] > $userdata['user_lastvisit'] || !max($mark_topics[$row_forum_id]) )
{
$unread_topics = false;
}
} }
} }

View file

@ -111,8 +111,8 @@ if ( !$acl->get_acl($forum_id, 'forum', 'read') )
// //
// Topic read tracking cookie info // Topic read tracking cookie info
// //
$tracking_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) : ''; $mark_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize(stripslashes($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t'])) : array();
$tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) : ''; $mark_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize(stripslashes($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f'])) : array();
// //
// Handle marking posts // Handle marking posts
@ -121,26 +121,9 @@ if ( $mark_read == 'topics' )
{ {
if ( $userdata['user_id'] ) if ( $userdata['user_id'] )
{ {
$sql = "SELECT MAX(topic_last_post_time) AS last_post $mark_forums[$forum_id] = time();
FROM " . TOPICS_TABLE . "
WHERE forum_id = $forum_id";
$result = $db->sql_query($sql);
if ( $row = $db->sql_fetchrow($result) ) setcookie($board_config['cookie_name'] . '_f', serialize($mark_forums), 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
{
if ( ( count($tracking_forums) + count($tracking_topics) ) >= 150 && empty($tracking_forums[$forum_id]) )
{
asort($tracking_forums);
unset($tracking_forums[key($tracking_forums)]);
}
if ( $row['last_post'] > $userdata['user_lastvisit'] )
{
$tracking_forums[$forum_id] = time();
setcookie($board_config['cookie_name'] . '_f', serialize($tracking_forums), 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
}
}
$template->assign_vars(array( $template->assign_vars(array(
'META' => '<meta http-equiv="refresh" content="3;url=' . "viewforum.$phpEx$SID&amp;f=$forum_id" . '">') 'META' => '<meta http-equiv="refresh" content="3;url=' . "viewforum.$phpEx$SID&amp;f=$forum_id" . '">')
@ -337,6 +320,7 @@ if ( $start )
$topic_rowset[] = $row; $topic_rowset[] = $row;
$total_topics++; $total_topics++;
} }
$db->sql_freeresult($result);
} }
// //
@ -358,7 +342,6 @@ while( $row = $db->sql_fetchrow($result) )
$topic_rowset[] = $row; $topic_rowset[] = $row;
$total_topics++; $total_topics++;
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
// //
@ -366,16 +349,13 @@ $db->sql_freeresult($result);
// //
if ( $total_topics ) if ( $total_topics )
{ {
$row_count = 0;
for($i = 0; $i < $total_topics; $i++) for($i = 0; $i < $total_topics; $i++)
{ {
$topic_id = $topic_rowset[$i]['topic_id']; $topic_id = $topic_rowset[$i]['topic_id'];
$topic_title = ( count($orig_word) ) ? preg_replace($orig_word, $replacement_word, $topic_rowset[$i]['topic_title']) : $topic_rowset[$i]['topic_title']; //
// Type and folder
$topic_type = $topic_rowset[$i]['topic_type']; //
$topic_type = ''; $topic_type = '';
if ( $topic_rowset[$i]['topic_status'] == TOPIC_MOVED ) if ( $topic_rowset[$i]['topic_status'] == TOPIC_MOVED )
{ {
@ -418,77 +398,36 @@ if ( $total_topics )
break; break;
} }
$newest_post_img = ''; $unread_topic = false;
if ( $userdata['user_id'] != ANONYMOUS ) if ( $userdata['user_id'] && $topic_rowset[$i]['topic_last_post_time'] > $userdata['user_lastvisit'] )
{ {
if ( $topic_rowset[$i]['post_time'] > $userdata['user_lastvisit'] ) $unread_topic = true;
{
if ( !empty($tracking_topics) || !empty($tracking_forums) || isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all']) )
{
$unread_topics = true;
if ( !empty($tracking_topics[$topic_id]) )
{
if ( $tracking_topics[$topic_id] >= $topic_rowset[$i]['post_time'] )
{
$unread_topics = false;
}
}
if ( !empty($tracking_forums[$forum_id]) )
{
if ( $tracking_forums[$forum_id] >= $topic_rowset[$i]['post_time'] )
{
$unread_topics = false;
}
}
if ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all']) ) if ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all']) )
{ {
if ( $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all'] >= $topic_rowset[$i]['post_time'] ) if ( $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all'] > $topic_rowset[$i]['topic_last_post_time'] )
{ {
$unread_topics = false; $unread_topic = false;
} }
} }
if ( $unread_topics ) if ( isset($mark_topics[$forum_id]) || isset($mark_forums[$forum_id][$topic_id]) )
{ {
$folder_image = $folder_new; if ( $mark_forums[$forum_id] > $topic_rowset[$i]['topic_last_post_time'] || !$mark_topics[$forum_id][$topic_id] )
$folder_alt = $lang['New_posts'];
$newest_post_img = '<a href="viewtopic.' . $phpEx . $SID . '&amp;t=' . $topic_id . '&amp;view=newest">' . create_img($theme['goto_post_newest'], $lang['View_newest_post']) . '</a> ';
}
else
{ {
$folder_image = $folder; $unread_topic = false;
$folder_alt = ( $topic_rowset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts']; }
}
$newest_post_img = ''; if ( !isset($mark_topics[$forum_id][$topic_id]) )
}
}
else
{ {
$folder_image = $folder_new; $mark_topics[$forum_id][$topic_id] = $topic_rowset[$i]['topic_last_post_time'];
$folder_alt = ( $topic_rowset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts']; }
}
$newest_post_img = '<a href="viewtopic.' . $phpEx . $SID . '&amp;t=' . $topic_id . '&amp;view=newest">' . create_img($theme['goto_post_newest'], $lang['View_newest_post']) . '</a> '; $newest_post_img = ( $unread_topic ) ? '<a href="viewtopic.' . $phpEx . $SID . '&amp;t=' . $topic_id . '&amp;view=newest">' . create_img($theme['goto_post_newest'], $lang['View_newest_post']) . '</a> ' : '';
} $folder_img = ( $unread_topic ) ? $folder_new : $folder;
} $folder_alt = ( $unread_topic ) ? $lang['New_posts'] : ( ( $topic_rowset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts'] );
else
{
$folder_image = $folder;
$folder_alt = ( $topic_rowset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts'];
$newest_post_img = '';
}
}
else
{
$folder_image = $folder;
$folder_alt = ( $topic_rowset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['No_new_posts'];
$newest_post_img = '';
}
} }
if ( $topic_rowset[$i]['topic_vote'] ) if ( $topic_rowset[$i]['topic_vote'] )
@ -496,6 +435,9 @@ if ( $total_topics )
$topic_type .= $lang['Topic_Poll'] . ' '; $topic_type .= $lang['Topic_Poll'] . ' ';
} }
//
// Goto message
//
if ( ( $replies + 1 ) > $board_config['posts_per_page'] ) if ( ( $replies + 1 ) > $board_config['posts_per_page'] )
{ {
$total_pages = ceil( ( $replies + 1 ) / $board_config['posts_per_page'] ); $total_pages = ceil( ( $replies + 1 ) / $board_config['posts_per_page'] );
@ -524,6 +466,9 @@ if ( $total_topics )
$goto_page = ''; $goto_page = '';
} }
//
// Generate all the URIs ...
//
$view_topic_url = 'viewtopic.' . $phpEx . $SID . '&amp;f=' . $forum_id . '&amp;t=' . $topic_id; $view_topic_url = 'viewtopic.' . $phpEx . $SID . '&amp;f=' . $forum_id . '&amp;t=' . $topic_id;
$topic_author = ( $topic_rowset[$i]['user_id'] != ANONYMOUS ) ? '<a href="profile.' . $phpEx . $SID . '&amp;mode=viewprofile&amp;u=' . $topic_rowset[$i]['user_id'] . '">' : ''; $topic_author = ( $topic_rowset[$i]['user_id'] != ANONYMOUS ) ? '<a href="profile.' . $phpEx . $SID . '&amp;mode=viewprofile&amp;u=' . $topic_rowset[$i]['user_id'] . '">' : '';
@ -539,40 +484,39 @@ if ( $total_topics )
$last_post_url = '<a href="viewtopic.' . $phpEx . $SID . '&amp;p=' . $topic_rowset[$i]['topic_last_post_id'] . '#' . $topic_rowset[$i]['topic_last_post_id'] . '">' . create_img($theme['goto_post_latest'], $lang['View_latest_post']) . '</a>'; $last_post_url = '<a href="viewtopic.' . $phpEx . $SID . '&amp;p=' . $topic_rowset[$i]['topic_last_post_id'] . '#' . $topic_rowset[$i]['topic_last_post_id'] . '">' . create_img($theme['goto_post_latest'], $lang['View_latest_post']) . '</a>';
$views = $topic_rowset[$i]['topic_views']; //
$replies = $topic_rowset[$i]['topic_replies']; // Send vars to template
//
$topic_icon = ( !empty($topic_rowset[$i]['icons_url']) ) ? '<img src="' . $board_config['icons_path'] . '/' . $topic_rowset[$i]['icons_url'] . '" width="' . $topic_rowset[$i]['icons_width'] . '" height="' . $topic_rowset[$i]['icons_height'] . '" alt="" title="" />' : '';
$topic_rating = ( !empty($topic_rowset[$i]['topic_rating']) ) ? '<img src=' . str_replace('{RATE}', $topic_rowset[$i]['topic_rating'], $theme['rating']) . ' alt="' . $topic_rowset[$i]['topic_rating'] . '" title="' . $topic_rowset[$i]['topic_rating'] . '" />' : '';
$template->assign_block_vars('topicrow', array( $template->assign_block_vars('topicrow', array(
'FORUM_ID' => $forum_id, 'FORUM_ID' => $forum_id,
'TOPIC_ID' => $topic_id, 'TOPIC_ID' => $topic_id,
'TOPIC_FOLDER_IMG' => create_img($folder_image, $folder_alt), 'TOPIC_FOLDER_IMG' => create_img($folder_img, $folder_alt),
'TOPIC_AUTHOR' => $topic_author, 'TOPIC_AUTHOR' => $topic_author,
'GOTO_PAGE' => $goto_page,
'REPLIES' => $replies,
'NEWEST_POST_IMG' => $newest_post_img, 'NEWEST_POST_IMG' => $newest_post_img,
'TOPIC_TITLE' => $topic_title,
'TOPIC_TYPE' => $topic_type,
'TOPIC_ICON' => $topic_icon,
'TOPIC_RATING' => $topic_rating,
'VIEWS' => $views,
'FIRST_POST_TIME' => $first_post_time, 'FIRST_POST_TIME' => $first_post_time,
'LAST_POST_TIME' => $last_post_time, 'LAST_POST_TIME' => $last_post_time,
'LAST_POST_AUTHOR' => $last_post_author, 'LAST_POST_AUTHOR' => $last_post_author,
'LAST_POST_IMG' => $last_post_url, 'LAST_POST_IMG' => $last_post_url,
'GOTO_PAGE' => $goto_page,
'REPLIES' => $topic_rowset[$i]['topic_replies'],
'VIEWS' => $topic_rowset[$i]['topic_views'],
'TOPIC_TITLE' => ( count($orig_word) ) ? preg_replace($orig_word, $replacement_word, $topic_rowset[$i]['topic_title']) : $topic_rowset[$i]['topic_title'],
'TOPIC_TYPE' => $topic_type,
'TOPIC_ICON' => ( !empty($topic_rowset[$i]['icons_url']) ) ? '<img src="' . $board_config['icons_path'] . '/' . $topic_rowset[$i]['icons_url'] . '" width="' . $topic_rowset[$i]['icons_width'] . '" height="' . $topic_rowset[$i]['icons_height'] . '" alt="" title="" />' : '',
'TOPIC_RATING' => ( !empty($topic_rowset[$i]['topic_rating']) ) ? '<img src=' . str_replace('{RATE}', $topic_rowset[$i]['topic_rating'], $theme['rating']) . ' alt="' . $topic_rowset[$i]['topic_rating'] . '" title="' . $topic_rowset[$i]['topic_rating'] . '" />' : '',
'S_ROW_COUNT' => $i, 'S_ROW_COUNT' => $i,
'U_VIEW_TOPIC' => $view_topic_url) 'U_VIEW_TOPIC' => $view_topic_url)
); );
$row_count++;
} }
} }
if ( $userdata['user_id'] )
{
setcookie($board_config['cookie_name'] . '_t', serialize($mark_topics), 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
}
// //
// Dump out the page header and load viewforum template // Dump out the page header and load viewforum template
// //

View file

@ -370,33 +370,13 @@ $post_img = ( $forum_status == FORUM_LOCKED ) ? create_img($theme['post_locked']
// //
// Set a cookie for this topic // Set a cookie for this topic
// //
if ( $userdata['user_id'] != ANONYMOUS ) if ( $userdata['user_id'] )
{ {
$tracking_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) : array(); $mark_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize(stripslashes($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t'])) : array();
$tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) : array();
if ( !empty($tracking_topics[$topic_id]) && !empty($tracking_forums[$forum_id]) ) $mark_topics[$forum_id][$topic_id] = 0;
{ setcookie($board_config['cookie_name'] . '_t', serialize($mark_topics), 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
$topic_last_read = ( $tracking_topics[$topic_id] > $tracking_forums[$forum_id] ) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id];
}
else if ( !empty($tracking_topics[$topic_id]) || !empty($tracking_forums[$forum_id]) )
{
$topic_last_read = ( !empty($tracking_topics[$topic_id]) ) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id];
}
else
{
$topic_last_read = $userdata['user_lastvisit'];
}
if ( count($tracking_topics) >= 150 && empty($tracking_topics[$topic_id]) )
{
asort($tracking_topics);
unset($tracking_topics[key($tracking_topics)]);
}
$tracking_topics[$topic_id] = time();
setcookie($board_config['cookie_name'] . '_t', serialize($tracking_topics), 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
} }
// //