mirror of https://github.com/BOINC/boinc.git
- web: improve forum pagination
svn path=/trunk/boinc/; revision=25863
This commit is contained in:
parent
72007821b7
commit
490b740682
|
@ -4854,3 +4854,16 @@ Charlie 11 July 2012
|
|||
project.pbxproj
|
||||
wrapper/
|
||||
BuildMacWrapper.sh
|
||||
|
||||
David 11 July 2012
|
||||
- web: improve forum pagination
|
||||
|
||||
client/
|
||||
client_msgs.cpp
|
||||
html/
|
||||
inc/
|
||||
forum.inc
|
||||
user/
|
||||
forum_forum.php
|
||||
forum_reply.php
|
||||
forum_threads.php
|
||||
|
|
|
@ -163,16 +163,15 @@ void msg_printf_notice(PROJ_AM *p, bool is_html, const char* link, const char *f
|
|||
// add to cache, and delete old messages if cache too big.
|
||||
// If high priority, create a notice.
|
||||
//
|
||||
void MESSAGE_DESCS::insert(
|
||||
PROJ_AM* p, int priority, int now, char* message
|
||||
) {
|
||||
void MESSAGE_DESCS::insert(PROJ_AM* p, int priority, int now, char* message) {
|
||||
MESSAGE_DESC* mdp = new MESSAGE_DESC;
|
||||
static int seqno = 1;
|
||||
strcpy(mdp->project_name, "");
|
||||
if (p) {
|
||||
strlcpy(
|
||||
mdp->project_name, p->get_project_name(), sizeof(mdp->project_name)
|
||||
);
|
||||
} else {
|
||||
strcpy(mdp->project_name, "");
|
||||
}
|
||||
mdp->priority = (priority==MSG_SCHEDULER_ALERT)?MSG_USER_ALERT:priority;
|
||||
mdp->timestamp = now;
|
||||
|
|
|
@ -220,54 +220,64 @@ function start_forum_table($headings, $extra=null) {
|
|||
echo "</tr>\n";
|
||||
}
|
||||
|
||||
// return a string containing a paged navigation bar
|
||||
// for the given forum. The default start place is 0.
|
||||
//
|
||||
function show_page_nav($forum, $sort, $start=0){
|
||||
// How many pages to potentially show before and after this one:
|
||||
$preshow = 5; $postshow = 10;
|
||||
$navbar = "";
|
||||
|
||||
if ($forum->threads > THREADS_PER_PAGE) {
|
||||
$total = ceil($forum->threads / THREADS_PER_PAGE);
|
||||
$curpage = ceil($start / THREADS_PER_PAGE);
|
||||
// If this is not the first page, display "previous"
|
||||
if ($curpage > 0){
|
||||
$navbar = '<a href="forum_forum.php?id='.$forum->id.'&start='.(($curpage-1)*THREADS_PER_PAGE);
|
||||
if ($sort) $navbar.='&sort='.$sort;
|
||||
$navbar.= '"> <-- '.tra("Previous")."</a> ";
|
||||
}
|
||||
|
||||
// Display a list of pages surrounding this one
|
||||
for ($i=$curpage-$preshow;$i<($curpage+$postshow);$i++){
|
||||
if ($i<1) continue;
|
||||
if ($i>$total) break;
|
||||
// If this is the current page, emphasize it.
|
||||
if ($i == $curpage+1) {
|
||||
$navbar .= "<b>$i</b>";
|
||||
} else {
|
||||
$navbar.='<a href="forum_forum.php?id='.$forum->id.'&start='.(($i-1)*THREADS_PER_PAGE);
|
||||
if ($sort) $navbar.='&sort='.$sort;
|
||||
$navbar.='">'.$i.'</a>';
|
||||
}
|
||||
$navbar .= " | ";
|
||||
}
|
||||
|
||||
// If there is a next page
|
||||
if ($curpage+1 < $total){
|
||||
$navbar.= '<a href="forum_forum.php?id='.$forum->id.'&start='.(($curpage+1)*THREADS_PER_PAGE);
|
||||
if ($sort) $navbar.='&sort='.$sort;
|
||||
$navbar.= '"> '.tra("Next")." --></a>";
|
||||
}
|
||||
|
||||
}
|
||||
return $navbar;
|
||||
function page_link($url, $page_num, $items_per_page, $text) {
|
||||
return " <a href=\"$url&start=" . $page_num*$items_per_page . "\">$text</a> ";
|
||||
}
|
||||
|
||||
function thread_last_visit($user, $thread) {
|
||||
if (!$user) return false;
|
||||
$log = BoincForumLogging::lookup($user->id, $thread->id);
|
||||
return $log->timestamp;
|
||||
// return a string for navigating pages
|
||||
//
|
||||
function page_links($url, $nitems, $items_per_page, $start){
|
||||
// How many pages to potentially show before and after this one:
|
||||
$preshow = 3;
|
||||
$postshow = 3;
|
||||
|
||||
$x = "";
|
||||
|
||||
if ($nitems <= $items_per_page) return "";
|
||||
$npages = ceil($nitems / $items_per_page);
|
||||
$curpage = ceil($start / $items_per_page);
|
||||
|
||||
// If this is not the first page, display "previous"
|
||||
//
|
||||
if ($curpage > 0){
|
||||
$x .= page_link(
|
||||
$url, $curpage-1, $items_per_page,
|
||||
tra("Previous")." · "
|
||||
);
|
||||
}
|
||||
|
||||
if ($curpage - $preshow > 0) {
|
||||
$x .= page_link($url, 0, $items_per_page, "1");
|
||||
$x .= " . . . ";
|
||||
}
|
||||
// Display a list of pages surrounding this one
|
||||
//
|
||||
for ($i=$curpage-$preshow; $i<=$curpage+$postshow; $i++){
|
||||
$page_str = (string)($i+1);
|
||||
if ($i < 0) continue;
|
||||
if ($i >= $npages) break;
|
||||
|
||||
if ($i == $curpage) {
|
||||
$x .= "<b>$page_str</b>";
|
||||
} else {
|
||||
$x .= page_link($url, $i, $items_per_page, $page_str);
|
||||
}
|
||||
$x .= " · ";
|
||||
}
|
||||
|
||||
if ($curpage + $postshow < $npages-1) {
|
||||
$x .= " . . . ";
|
||||
$x .= page_link($url, $npages-1, $items_per_page, $npages);
|
||||
}
|
||||
// If there is a next page
|
||||
//
|
||||
if ($curpage < $npages-1){
|
||||
$x .= page_link(
|
||||
$url, $curpage+1, $items_per_page,
|
||||
" · ".tra("Next")
|
||||
);
|
||||
}
|
||||
return $x;
|
||||
}
|
||||
|
||||
function thread_is_unread($user, $thread) {
|
||||
|
@ -297,12 +307,11 @@ function can_reply($thread, $forum, $user) {
|
|||
// Show the posts in a thread for a user.
|
||||
//
|
||||
function show_posts(
|
||||
$thread, $forum, $offset, $sort_style, $filter, $logged_in_user,
|
||||
$thread, $forum, $start, $sort_style, $filter, $logged_in_user,
|
||||
$show_controls=true
|
||||
) {
|
||||
$n = 1;
|
||||
$first_unread_post = null;
|
||||
$last_visit = 0;
|
||||
|
||||
if ($show_controls) {
|
||||
$controls = FORUM_CONTROLS;
|
||||
|
@ -315,66 +324,66 @@ function show_posts(
|
|||
$num_to_show = $logged_in_user->prefs->display_wrap_postcount;
|
||||
}
|
||||
|
||||
// If logged in user is moderator,
|
||||
// let him see all posts - including hidden ones
|
||||
// let moderators see all posts, including hidden ones
|
||||
//
|
||||
if (is_moderator($logged_in_user, $forum)) {
|
||||
$show_hidden = true;
|
||||
} else {
|
||||
$show_hidden = false;
|
||||
}
|
||||
|
||||
$posts = get_thread_posts($thread->id, $sort_style, $show_hidden);
|
||||
$postcount = (sizeof($posts)-1);
|
||||
|
||||
$latest_viewed = 0;
|
||||
if ($logged_in_user) {
|
||||
$last_visit = thread_last_visit($logged_in_user, $thread);
|
||||
$log = BoincForumLogging::lookup($logged_in_user->id, $thread->id);
|
||||
if ($log) {
|
||||
$latest_viewed = $log->timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
if ($offset) {
|
||||
$new_off = $offset - $num_to_show;
|
||||
if ($new_off < 0) $new_off = 0;
|
||||
echo "<tr colspan=2><td>";
|
||||
show_button(
|
||||
"forum_thread.php?id=$thread->id&offset=$new_off&sort_style=$sort_style",
|
||||
"Previous $num_to_show posts",
|
||||
"Show previous $num_to_show posts"
|
||||
);
|
||||
echo "</td></tr>\n";
|
||||
}
|
||||
$show_next_link = false;
|
||||
$page_nav = page_links(
|
||||
"forum_thread.php?id=$thread->id&sort_style=$sort_style",
|
||||
sizeof($posts),
|
||||
$num_to_show,
|
||||
$start
|
||||
);
|
||||
|
||||
echo $page_nav;
|
||||
|
||||
$num_shown = 0;
|
||||
$num_skipped = 0;
|
||||
$headings = array(array(tra("Author"),"authorcol"), array(tra("Message"),""));
|
||||
start_forum_table($headings, "id=\"thread\" cellspacing=0");
|
||||
|
||||
$latest_post_shown = 0;
|
||||
foreach ($posts as $post){
|
||||
if ($num_skipped < $offset) {
|
||||
if ($num_skipped < $start) {
|
||||
$num_skipped++;
|
||||
continue;
|
||||
}
|
||||
if ($num_shown == $num_to_show) {
|
||||
$show_next_link = true;
|
||||
break;
|
||||
}
|
||||
show_post(
|
||||
$post, $thread, $forum, $logged_in_user, $last_visit, $n,
|
||||
$post, $thread, $forum, $logged_in_user, $latest_viewed, $n,
|
||||
$controls, $filter
|
||||
);
|
||||
$n = ($n+1)%2;
|
||||
|
||||
if (($post->timestamp>$last_visit) &&
|
||||
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;
|
||||
}
|
||||
$num_shown++;
|
||||
}
|
||||
if ($show_next_link) {
|
||||
$new_off = $offset + $num_to_show;
|
||||
echo "<tr colspan=2><td>";
|
||||
show_button(
|
||||
"forum_thread.php?id=$thread->id&offset=$new_off&sort_style=$sort_style",
|
||||
"Next $num_to_show posts",
|
||||
"Show next $num_to_show posts"
|
||||
);
|
||||
echo "</td></tr>\n";
|
||||
}
|
||||
end_table();
|
||||
echo $page_nav;
|
||||
|
||||
if ($logged_in_user && $logged_in_user->prefs->jump_to_unread){
|
||||
if ($first_unread_post){
|
||||
|
@ -385,7 +394,9 @@ function show_posts(
|
|||
}
|
||||
|
||||
if ($logged_in_user) {
|
||||
BoincForumLogging::replace($logged_in_user->id, $thread->id, time());
|
||||
BoincForumLogging::replace(
|
||||
$logged_in_user->id, $thread->id, $latest_post_shown
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -424,7 +435,7 @@ function is_ignoring($user, $other_user) {
|
|||
// Display an individual post
|
||||
//
|
||||
function show_post(
|
||||
$post, $thread, $forum, $logged_in_user, $last_visit, $n,
|
||||
$post, $thread, $forum, $logged_in_user, $latest_viewed, $n,
|
||||
$controls=FORUM_CONTROLS, $filter=true
|
||||
) {
|
||||
global $country_to_iso3166_2;
|
||||
|
@ -554,7 +565,7 @@ function show_post(
|
|||
echo "<form action=\"forum_rate.php?post=", $post->id, "\" method=\"post\">";
|
||||
}
|
||||
|
||||
if ($logged_in_user && $post->timestamp>$last_visit){
|
||||
if ($logged_in_user && $post->timestamp>$latest_viewed){
|
||||
show_image(NEW_IMAGE, tra("You haven't read this message yet"), tra("Unread"), NEW_IMAGE_HEIGHT);
|
||||
}
|
||||
|
||||
|
|
|
@ -123,12 +123,16 @@ page_tail();
|
|||
// and using the features for the logged in user in $user.
|
||||
//
|
||||
function show_forum($forum, $start, $sort_style, $user) {
|
||||
$gotoStr = "";
|
||||
$nav = show_page_nav($forum, $sort_style, $start);
|
||||
if ($nav) {
|
||||
$gotoStr = "<div align=\"right\">$nav</div><br>";
|
||||
$page_nav = page_links(
|
||||
"forum_forum.php?id=$forum->id&sort=$sort_style",
|
||||
sizeof($forum->threads),
|
||||
THREADS_PER_PAGE,
|
||||
start
|
||||
);
|
||||
if ($page_nav) {
|
||||
$page_nav = "<div align=\"right\">$page_nav</div><br>";
|
||||
}
|
||||
echo $gotoStr; // Display the navbar
|
||||
echo $page_nav;
|
||||
start_forum_table(array(
|
||||
"",
|
||||
tra("Threads"),
|
||||
|
@ -153,6 +157,7 @@ function show_forum($forum, $start, $sort_style, $user) {
|
|||
}
|
||||
|
||||
// Run through the list of threads, displaying each of them
|
||||
//
|
||||
$n = 0; $i=0;
|
||||
foreach ($threads as $thread) {
|
||||
$owner = BoincUser::lookup_id($thread->owner);
|
||||
|
@ -219,7 +224,7 @@ function show_forum($forum, $start, $sort_style, $user) {
|
|||
flush();
|
||||
}
|
||||
end_table();
|
||||
echo "<br>$gotoStr"; // show page links
|
||||
echo "<br>$page_nav"; // show page links
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -112,9 +112,11 @@ if ($preview == tra("Preview")) {
|
|||
start_forum_table(array(tra("Author"), tra("Message")));
|
||||
|
||||
show_message_row($thread, $parent_post);
|
||||
show_posts(
|
||||
$thread, $forum, 0, $sort_style, $filter, $logged_in_user, true
|
||||
);
|
||||
if ($parent_post) {
|
||||
show_post(
|
||||
$parent_post, $thread, $forum, $logged_in_user, 0, 0, false, false
|
||||
);
|
||||
}
|
||||
end_table();
|
||||
|
||||
page_tail();
|
||||
|
|
|
@ -25,8 +25,8 @@ require_once('../inc/news.inc');
|
|||
|
||||
$threadid = get_int('id');
|
||||
$sort_style = get_int('sort', true);
|
||||
$offset = get_int('offset', true);
|
||||
if (!$offset) $offset = 0;
|
||||
$start = get_int('start', true);
|
||||
if (!$start) $start = 0;
|
||||
$filter = get_str('filter', true);
|
||||
|
||||
if ($filter != "false"){
|
||||
|
@ -258,17 +258,13 @@ echo "<input type=\"submit\" value=\"".tra('Sort')."\">
|
|||
</td></tr></table></form>
|
||||
";
|
||||
|
||||
// Here is where the actual thread begins.
|
||||
$headings = array(array(tra("Author"),"authorcol"), array(tra("Message"),""));
|
||||
|
||||
start_forum_table($headings, "id=\"thread\" cellspacing=0");
|
||||
show_posts(
|
||||
$thread, $forum, $offset, $sort_style, $filter,
|
||||
$thread, $forum, $start, $sort_style, $filter,
|
||||
$logged_in_user, true
|
||||
);
|
||||
end_table();
|
||||
|
||||
if ($reply_url) {
|
||||
echo "<br>";
|
||||
show_button(
|
||||
$reply_url,
|
||||
tra("Post to thread"),
|
||||
|
|
Loading…
Reference in New Issue