<?php
/*
Plugin Name: Page Links
Plugin URI: http://bbpress.org/plugins/topic/page-links-for-bbpress/
Plugin Author: based on work by Sam Bauers, mod by _ck_
*/
function page_links_add_css() { // pure css solution with inline stylesheet (no externals to load/check)
echo "
<style type='text/css'>
#latest a.page-numbers {
display: inline-block;
text-align: center;
padding: 0 3px 1px 1px;
margin-left: 4px;
min-width: 7px;
letter-spacing: -2px;
font: 11px/14px Arial, san-serif;
border: 1px solid #ccc; border-right: 1px solid #aaa; border-bottom: 1px solid #999;
-moz-border-radius: 1px; -khtml-border-radius: 1px; -webkit-border-radius: 1px; border-radius: 1px;
-moz-border-radius-topleft: 3px 5px; -khtml-border-top-left-radius: 3px 5px; -webkit-border-top-left-radius: 3px 5px; border-top-left-radius: 3px 5px;
color: #444; background:#eee;
}
#latest a.page-numbers:hover { color: #fff; background: #ccc; }
</style>";
add_filter('topic_title', 'page_links_add_links', 200); // don't add the filter until we are actually on the page ie. not RSS
}
if (in_array(bb_get_location(),array('front-page','forum-page','tag-page','view-page'))) { // 'search-page','favorites-page','profile-page',
add_action('bb_head', 'page_links_add_css');
}
function page_links_add_links($title) {
global $topic; static $perPage, $mod_rewrite; // speedup
$posts = $topic->topic_posts; // + topic_pages_add($topic->topic_id); // no need for pages_add on topic tables
if (!isset($perPage)) { // speedup by static and avoiding extra query if front-page-topics not installed
if (function_exists('front_page_topics') && $perPage = bb_get_option('front_page_topics')) { $perPage = $perPage['topic-page']; }
elseif (function_exists('topics_per_page')) { global $topics_per_page; $perPage = $topics_per_page['topic-page']; }
if (empty($perPage)) { $perPage = bb_get_option('page_topics'); }
}
if ($posts<=$perPage) {return $title;} // speedup
$uri = get_topic_link();
if (!isset($mod_rewrite)) {$mod_rewrite=bb_get_option('mod_rewrite');} // speedup
if ($mod_rewrite) {
$uri = (false === $pos = strpos($uri, '?')) ? $uri . '%_%' : substr_replace($uri, '%_%', $pos, 0);
} else {
$uri = add_query_arg('page', '%_%', $uri);
}
$links = paginate_links(
array(
'base' => $uri,
'format' => $mod_rewrite ? '/page/%#%' : '%#%',
'total' => ceil($posts/$perPage),
'current' => ceil($posts/$perPage) + 1,
'show_all' => false,
'type' => 'array'
)
);
if ($links) { unset($links[0]); unset($links[1]); } // no previous/first page links
if (count($links)>2) { unset($links[2]); } // no dots
if ($links) { $title .= '</a> '.substr(join('', $links), 0, -4).' ';} // close original title and cleanup
return $title;
}
?>