function _advanced_forum_create_topic_pager in Advanced Forum 5
Same name and namespace in other branches
- 6 advanced_forum.module \_advanced_forum_create_topic_pager()
Creates a pager to place on each multi-page topic of the topic listing page.
Parameters
$max_pages_to_display: Number of pages to include on the pager.
$topic: Topic object to create a pager for.
Return value
Asembled pager.
1 call to _advanced_forum_create_topic_pager()
- advanced_forum_preprocess_forum_topic_list in ./
advanced_forum.module - Preprocesses template variables for the topic list template.
File
- ./
advanced_forum.module, line 1506 - Enables the look and feel of other popular forum software.
Code
function _advanced_forum_create_topic_pager($max_pages_to_display, $topic) {
// Find the number of comments per page for the node type of the topic.
// It's the same for all types in D5, but varies in D6.
$comments_per_page = _comment_get_display_setting('comments_per_page', $topic);
if ($max_pages_to_display > 0 && $topic->num_comments > $comments_per_page) {
// Topic has more than one page and a pager is wanted. Start off the
// first page because that doesn't have a query.
$pager_array = array();
$current_display_page = 1;
$pager_array[] = l(t('1'), "node/{$topic->nid}");
// Find the ending point. The pager URL is always 1 less than
// the number being displayed because the first page is 0.
$last_display_page = ceil($topic->num_comments / $comments_per_page);
$last_pager_page = $last_display_page - 1;
// Add pages until we run out or until we hit the max to show.
while ($current_display_page < $last_display_page && $current_display_page < $max_pages_to_display) {
// Move to the next page
$current_display_page++;
// The page number we link to is 1 less than what's displayed
$link_to_page = $current_display_page - 1;
// Add the link to the array
$pager_array[] = l($current_display_page, "node/{$topic->nid}", NULL, 'page=' . $link_to_page);
}
// Move to the next page
$current_display_page++;
if ($current_display_page == $last_display_page) {
// We are one past the max to display, but it's the last page,
// so putting the ...last is silly. Just display it normally.
$link_to_page = $current_display_page - 1;
$pager_array[] = l($current_display_page, "node/{$topic->nid}", NULL, 'page=' . $link_to_page);
}
$pager_last = '';
if ($current_display_page < $last_display_page) {
// We are one past the max to display and still aren't
// on the last page, so put in ... Last Page(N)
$text = t('Last Page') . '(' . $last_display_page . ')';
$pager_last = ' … ' . l($text, "node/{$topic->nid}", NULL, 'page=' . $last_pager_page);
}
// Put it all together
return '[' . t('Page') . ' ' . implode(", ", $pager_array) . $pager_last . ']';
}
}