From 99a077c642ee15a03838e8d2ef8fb455e99478c3 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 12 Jul 2012 18:07:06 +0000 Subject: [PATCH] - web: make "jump to first unread" for with pagination svn path=/trunk/boinc/; revision=25868 --- checkin_notes | 9 ++++++++ html/inc/forum.inc | 46 ++++++++++++++++++++++++++------------ html/user/forum_thread.php | 4 +--- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/checkin_notes b/checkin_notes index a7f40fc217..4a806915bf 100644 --- a/checkin_notes +++ b/checkin_notes @@ -4893,3 +4893,12 @@ Charlie 12 July 2012 project.pbxproj wrapper/ BuildMacWrapper.sh + +David 12 July 2012 + - web: make "jump to first unread" for with pagination + + html/ + inc/ + forum.inc + user/ + forum_thread.php diff --git a/html/inc/forum.inc b/html/inc/forum.inc index 32faae284d..50be5d92b0 100644 --- a/html/inc/forum.inc +++ b/html/inc/forum.inc @@ -312,13 +312,13 @@ function can_reply($thread, $forum, $user) { } // Show the posts in a thread for a user. +// If $start is null, enforce jump-to-first-unread // function show_posts( $thread, $forum, $start, $sort_style, $filter, $logged_in_user, $show_controls=true ) { $n = 1; - $first_unread_post = null; if ($show_controls) { $controls = FORUM_CONTROLS; @@ -340,7 +340,6 @@ function show_posts( } $posts = get_thread_posts($thread->id, $sort_style, $show_hidden); - $postcount = (sizeof($posts)-1); $latest_viewed = 0; $forum_log = null; @@ -351,6 +350,32 @@ function show_posts( } } + // jump to first unread post if needed + // + $first_unread_post = null; + if ($start === null) { + if ($latest_viewed && $logged_in_user->prefs->jump_to_unread) { + $i = 0; + $ibest = 0; + foreach ($posts as $post) { + if ($post->timestamp > $latest_viewed) { + if (!$first_unread_post || ($post->timestamp < $first_unread_post->timestamp)) { + $first_unread_post = $post; + $ibest = $i; + } + } + $i++; + } + if ($first_unread_post) { + $start = $ibest - ($ibest % $num_to_show); + } else { + $start = 0; + } + } else { + $start = 0; + } + } + $page_nav = page_links( "forum_thread.php?id=$thread->id&sort_style=$sort_style", sizeof($posts), @@ -367,7 +392,7 @@ function show_posts( $latest_post_shown = 0; $first_unread_post = null; - foreach ($posts as $post){ + foreach ($posts as $post) { if ($num_skipped < $start) { $num_skipped++; continue; @@ -381,11 +406,6 @@ function show_posts( ); $n = ($n+1)%2; - if (($post->timestamp>$latest_viewed) && - ((!$first_unread_post) || ($post->timestamp<$first_unread_post->timestamp)) - ){ - $first_unread_post = $post; - } if ($post->timestamp > $latest_post_shown) { $latest_post_shown = $post->timestamp; } @@ -394,12 +414,10 @@ function show_posts( end_table(); echo $page_nav; - if ($logged_in_user && $logged_in_user->prefs->jump_to_unread){ - if ($first_unread_post) { - echo ""; - } else { - echo ""; - } + if ($first_unread_post) { + echo ""; + } else { + echo ""; } if (!$forum_log || $latest_post_shown > $forum_log->timestamp) { diff --git a/html/user/forum_thread.php b/html/user/forum_thread.php index 0c004b327f..8f8a84c92e 100644 --- a/html/user/forum_thread.php +++ b/html/user/forum_thread.php @@ -26,7 +26,6 @@ require_once('../inc/news.inc'); $threadid = get_int('id'); $sort_style = get_int('sort', true); $start = get_int('start', true); -if (!$start) $start = 0; $filter = get_str('filter', true); if ($filter != "false"){ @@ -259,8 +258,7 @@ echo " "; show_posts( - $thread, $forum, $start, $sort_style, $filter, - $logged_in_user, true + $thread, $forum, $start, $sort_style, $filter, $logged_in_user, true ); if ($reply_url) {