function advanced_forum_create_topic_pager in Advanced Forum 6.2
Same name and namespace in other branches
- 7.2 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
Object containing the linked pages ready assembly by the theme function.
1 call to advanced_forum_create_topic_pager()
- theme_advanced_forum_topic_pager in includes/
theme.inc - Theme function to return assembled pager for use on each topic in list.
File
- ./
advanced_forum.module, line 1223 - 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.
$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('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}", array(
'query' => '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}", array(
'query' => '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');
$pager_last_text = l($text, "node/{$topic->nid}", array(
'query' => 'page=' . $last_pager_page,
));
$pager_last_number = l($last_display_page, "node/{$topic->nid}", array(
'query' => 'page=' . $last_pager_page,
));
}
$topic_pager = new stdClass();
$topic_pager->initial_pages = empty($pager_array) ? array() : $pager_array;
$topic_pager->last_page_text = empty($pager_last_text) ? '' : $pager_last_text;
$topic_pager->last_page_number = empty($pager_last_numer) ? '' : $pager_last_number;
return $topic_pager;
}
}