[ Index ]

PHP Cross Reference of Mambo 4.6.5

[ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/includes/ -> pageNavigation.php (source)

   1  <?php
   2  /**
   3  * @package Mambo
   4  * @author Mambo Foundation Inc see README.php
   5  * @copyright (C) 2000 - 2009 Mambo Foundation Inc.
   6  * See COPYRIGHT.php for copyright notices and details.
   7  * @license GNU/GPL Version 2, see LICENSE.php
   8  *
   9  * Redistributions of files must retain the above copyright notice.
  10  *
  11  * Mambo is free software; you can redistribute it and/or
  12  * modify it under the terms of the GNU General Public License
  13  * as published by the Free Software Foundation; version 2 of the License.
  14  */
  15  
  16  /** ensure this file is being included by a parent file */
  17  defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  18  
  19  /**
  20  * Page navigation support class
  21  */
  22  class mosPageNav {
  23      /** @var int The record number to start dislpaying from */
  24      var $limitstart = null;
  25      /** @var int Number of rows to display per page */
  26      var $limit = null;
  27      /** @var int Total number of rows */
  28      var $total = null;
  29  
  30  	function mosPageNav( $total, $limitstart, $limit ) {
  31          $this->total = intval( $total );
  32          $this->limitstart = max( intval($limitstart), 0 );
  33          $this->limit = max( intval($limit), 0 );
  34      }
  35      /**
  36      * Returns the html limit # input box
  37      * @param string The basic link to include in the href
  38      * @return string
  39      */
  40  	function getLimitBox () {
  41          $limits = array();
  42          for ($i=5; $i <= 30; $i+=5) {
  43              $limits[] = mosHTML::makeOption( "$i" );
  44          }
  45          $limits[] = mosHTML::makeOption( "50" );
  46          $limits[] = mosHTML::makeOption( "100" );
  47          $limits[] = mosHTML::makeOption( "500" );
  48          $limits[] = mosHTML::makeOption( "1000" );
  49          $limits[] = mosHTML::makeOption( "2500" );
  50          $limits[] = mosHTML::makeOption( "5000" );
  51  
  52          // build the html select list
  53          $html = mosHTML::selectList( $limits, 'limit', 'class="inputbox" size="1" onchange="document.adminForm.submit();"',
  54          'value', 'text', $this->limit );
  55          $html .= "\n<input type=\"hidden\" name=\"limitstart\" value=\"$this->limitstart\" />";
  56          return $html;
  57      }
  58      /**
  59      * Writes the html limit # input box
  60      * @param string The basic link to include in the href
  61      */
  62  	function writeLimitBox ( $link ) {
  63          echo mosPageNav::getLimitBox( $link );
  64      }
  65      /**
  66      * Writes the html for the pages counter, eg, Results 1-10 of x
  67      */
  68  	function writePagesCounter() {
  69          $txt = '';
  70          $from_result = $this->limitstart+1;
  71          if ($this->limitstart + $this->limit < $this->total) {
  72              $to_result = $this->limitstart + $this->limit;
  73          } else {
  74              $to_result = $this->total;
  75          }
  76          if ($this->total > 0) {
  77              $txt .= sprintf(T_('Results %d - %d of %d'), $from_result, $to_result, $this->total);
  78          }
  79          return $txt;
  80      }
  81  
  82      /**
  83      * Writes the html for the leafs counter, eg, Page 1 of x
  84      */
  85  	function writeLeafsCounter() {
  86          $txt = '';
  87          $page = $this->limitstart+1;
  88          if ($this->total > 0) {
  89              $txt .= sprintf(T_('Page %d of %d'), $page, $this->total);
  90          }
  91          return $txt;
  92      }
  93  
  94      /**
  95      * Writes the html links for pages, eg, previous, next, 1 2 3 ... x
  96      * @param string The basic link to include in the href
  97      */
  98  	function writePagesLinks( $link ) {        
  99          
 100          // clean link - could be better filtered in rewrite
 101          // stops XSS
 102          require_once(mamboCore::get('mosConfig_absolute_path').'/includes/phpInputFilter/class.inputfilter.php');
 103          $iFilter = new InputFilter( null, null, 1, 1 );            
 104          $link = trim( $iFilter->process( $link ) );            
 105  
 106          // Removing task breaks nagivation - temporarily removed for 4.6.2 release
 107          // For more information, See FS#127
 108          //        $link = preg_replace("/(task.*?)&/i", "", $link);        
 109          
 110          $txt = '';
 111  
 112          $displayed_pages = 10;
 113          $total_pages = ceil( $this->total / $this->limit );
 114          $this_page = ceil( ($this->limitstart+1) / $this->limit );
 115          $start_loop = (floor(($this_page-1)/$displayed_pages))*$displayed_pages+1;
 116          if ($start_loop + $displayed_pages - 1 < $total_pages) {
 117              $stop_loop = $start_loop + $displayed_pages - 1;
 118          } else {
 119              $stop_loop = $total_pages;
 120          }
 121  
 122          $link .= '&amp;limit='. $this->limit;
 123  
 124          if ($this_page > 1) {
 125              $page = ($this_page - 2) * $this->limit;
 126              $txt .= '<a href="'. sefRelToAbs( "$link&amp;limitstart=0" ) .'" class="pagenav" title="'.T_('first page').'">&lt;&lt; '. T_('Start') .'</a> ';
 127              $txt .= '<a href="'. sefRelToAbs( "$link&amp;limitstart=$page" ) .'" class="pagenav" title="'.T_('previous page').'">&lt; '. T_('Previous') .'</a> ';
 128          } else {
 129              $txt .= '<span class="pagenav">&lt;&lt; '. T_('Start') .'</span> ';
 130              $txt .= '<span class="pagenav">&lt; '. T_('Previous') .'</span> ';
 131          }
 132  
 133          for ($i=$start_loop; $i <= $stop_loop; $i++) {
 134              $page = ($i - 1) * $this->limit;
 135              if ($i == $this_page) {
 136                  $txt .= '<span class="pagenav">'. $i .'</span> ';
 137              } else {
 138                  $txt .= '<a href="'. sefRelToAbs( $link .'&amp;limitstart='. $page ) .'" class="pagenav"><strong>'. $i .'</strong></a> ';
 139              }
 140          }
 141  
 142          if ($this_page < $total_pages) {
 143              $page = $this_page * $this->limit;
 144              $end_page = ($total_pages-1) * $this->limit;
 145              $txt .= '<a href="'. sefRelToAbs( $link .'&amp;limitstart='. $page ) .' " class="pagenav" title="'.T_('next page').'">'. T_('Next') .' &gt;</a> ';
 146              $txt .= '<a href="'. sefRelToAbs( $link .'&amp;limitstart='. $end_page ) .' " class="pagenav" title="'.T_('end page').'">'. T_('End') .' &gt;&gt;</a>';
 147          } else {
 148              $txt .= '<span class="pagenav">'. T_('Next') .' &gt;</span> ';
 149              $txt .= '<span class="pagenav">'. T_('End') .' &gt;&gt;</span>';
 150          }
 151          
 152  
 153              
 154              return $txt;
 155      }
 156  }
 157  ?>