Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <?php
  2. /*
  3. Plugin Name: Page Links
  4. Plugin URI: http://bbpress.org/plugins/topic/page-links-for-bbpress/
  5. Plugin Author: based on work by Sam Bauers, mod by _ck_
  6. */
  7.  
  8. function page_links_add_css() { // pure css solution with inline stylesheet (no externals to load/check)   
  9.     echo "
  10.     <style type='text/css'>
  11.     #latest a.page-numbers {           
  12.         display: inline-block;
  13.         text-align: center;
  14.         padding: 0 3px 1px 1px;
  15.             margin-left: 4px;
  16.         min-width: 7px;
  17.             letter-spacing: -2px;
  18.             font: 11px/14px Arial, san-serif;
  19.             border: 1px solid #ccc; border-right: 1px solid #aaa; border-bottom: 1px solid #999;
  20.         -moz-border-radius: 1px; -khtml-border-radius: 1px; -webkit-border-radius: 1px; border-radius: 1px;
  21.         -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;
  22.             color: #444; background:#eee;          
  23.         }
  24.     #latest a.page-numbers:hover { color: #fff; background: #ccc; }
  25.     </style>";
  26.     add_filter('topic_title', 'page_links_add_links', 200); // don't add the filter until we are actually on the page  ie. not RSS 
  27. }
  28.  
  29. if (in_array(bb_get_location(),array('front-page','forum-page','tag-page','view-page'))) {  // 'search-page','favorites-page','profile-page',  
  30.     add_action('bb_head', 'page_links_add_css');
  31. }
  32.  
  33. function page_links_add_links($title) {
  34.     global $topic; static $perPage, $mod_rewrite;  // speedup
  35.    
  36.     $posts = $topic->topic_posts;   //  + topic_pages_add($topic->topic_id);  //  no need for pages_add on  topic tables
  37.    
  38.     if (!isset($perPage)) { // speedup by static and avoiding extra query if front-page-topics not installed
  39.         if (function_exists('front_page_topics') && $perPage = bb_get_option('front_page_topics')) { $perPage = $perPage['topic-page']; }
  40.         elseif (function_exists('topics_per_page')) { global $topics_per_page; $perPage = $topics_per_page['topic-page']; }    
  41.         if (empty($perPage)) { $perPage = bb_get_option('page_topics'); }
  42.     }
  43.    
  44.     if ($posts<=$perPage) {return $title;}  // speedup
  45.  
  46.     $uri = get_topic_link();
  47.     if (!isset($mod_rewrite)) {$mod_rewrite=bb_get_option('mod_rewrite');}  // speedup
  48.     if ($mod_rewrite) {
  49.         $uri = (false === $pos = strpos($uri, '?')) ? $uri . '%_%' : substr_replace($uri, '%_%', $pos, 0);
  50.     } else {
  51.         $uri = add_query_arg('page', '%_%', $uri);
  52.     }
  53.    
  54.     $links = paginate_links(
  55.         array(
  56.             'base' => $uri,
  57.             'format' => $mod_rewrite ? '/page/%#%' : '%#%',
  58.             'total' => ceil($posts/$perPage),
  59.             'current' => ceil($posts/$perPage) + 1,
  60.             'show_all' => false,
  61.             'type' => 'array'
  62.         )
  63.     );
  64.    
  65.     if ($links) { unset($links[0]); unset($links[1]); }     // no previous/first page links
  66.     if (count($links)>2) { unset($links[2]); }          // no dots
  67.     if ($links) { $title .= '</a> '.substr(join('', $links), 0, -4).' ';}   // close original title and cleanup
  68.    
  69.     return $title;
  70. }
  71.  
  72. ?>