Annotation of /mambo/branches/4.6/includes/pageNavigation.php
Parent Directory
|
Revision Log
Revision 738 - (view) (download)
| 1 : | root | 1 | <?php |
| 2 : | /** | ||
| 3 : | csouza | 297 | * @package Mambo Open Source |
| 4 : | * @copyright (C) 2005 - 2006 Mambo Foundation Inc. | ||
| 5 : | root | 1 | * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL |
| 6 : | csouza | 297 | * |
| 7 : | * Mambo was originally developed by Miro (www.miro.com.au) in 2000. Miro assigned the copyright in Mambo to The Mambo Foundation in 2005 to ensure | ||
| 8 : | * that Mambo remained free Open Source software owned and managed by the community. | ||
| 9 : | root | 1 | * Mambo is Free Software |
| 10 : | csouza | 297 | */ |
| 11 : | root | 1 | |
| 12 : | /** ensure this file is being included by a parent file */ | ||
| 13 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 14 : | |||
| 15 : | /** | ||
| 16 : | * Page navigation support class | ||
| 17 : | */ | ||
| 18 : | class mosPageNav { | ||
| 19 : | /** @var int The record number to start dislpaying from */ | ||
| 20 : | var $limitstart = null; | ||
| 21 : | /** @var int Number of rows to display per page */ | ||
| 22 : | var $limit = null; | ||
| 23 : | /** @var int Total number of rows */ | ||
| 24 : | var $total = null; | ||
| 25 : | |||
| 26 : | function mosPageNav( $total, $limitstart, $limit ) { | ||
| 27 : | $this->total = intval( $total ); | ||
| 28 : | cauld | 680 | $this->limitstart = max( intval($limitstart), 0 ); |
| 29 : | $this->limit = max( intval($limit), 0 ); | ||
| 30 : | root | 1 | } |
| 31 : | /** | ||
| 32 : | * Returns the html limit # input box | ||
| 33 : | * @param string The basic link to include in the href | ||
| 34 : | * @return string | ||
| 35 : | */ | ||
| 36 : | function getLimitBox ( $link ) { | ||
| 37 : | $limits = array(); | ||
| 38 : | for ($i=5; $i <= 30; $i+=5) { | ||
| 39 : | $limits[] = mosHTML::makeOption( "$i" ); | ||
| 40 : | } | ||
| 41 : | $limits[] = mosHTML::makeOption( "50" ); | ||
| 42 : | |||
| 43 : | // build the html select list | ||
| 44 : | $link = sefRelToAbs($link.'&limit=\' + this.options[selectedIndex].value + \'&limitstart='.$this->limitstart); | ||
| 45 : | return mosHTML::selectList( $limits, 'limit', | ||
| 46 : | 'class="inputbox" size="1" onchange="document.location.href=\''.$link.'\';"', | ||
| 47 : | 'value', 'text', $this->limit ); | ||
| 48 : | } | ||
| 49 : | /** | ||
| 50 : | * Writes the html limit # input box | ||
| 51 : | * @param string The basic link to include in the href | ||
| 52 : | */ | ||
| 53 : | function writeLimitBox ( $link ) { | ||
| 54 : | echo mosPageNav::getLimitBox( $link ); | ||
| 55 : | } | ||
| 56 : | /** | ||
| 57 : | * Writes the html for the pages counter, eg, Results 1-10 of x | ||
| 58 : | */ | ||
| 59 : | function writePagesCounter() { | ||
| 60 : | $txt = ''; | ||
| 61 : | $from_result = $this->limitstart+1; | ||
| 62 : | if ($this->limitstart + $this->limit < $this->total) { | ||
| 63 : | $to_result = $this->limitstart + $this->limit; | ||
| 64 : | } else { | ||
| 65 : | $to_result = $this->total; | ||
| 66 : | } | ||
| 67 : | if ($this->total > 0) { | ||
| 68 : | csouza | 39 | $txt .= sprintf(T_('Results %d - %d of %d'), $from_result, $to_result, $this->total); |
| 69 : | root | 1 | } |
| 70 : | return $txt; | ||
| 71 : | } | ||
| 72 : | |||
| 73 : | /** | ||
| 74 : | * Writes the html for the leafs counter, eg, Page 1 of x | ||
| 75 : | */ | ||
| 76 : | function writeLeafsCounter() { | ||
| 77 : | $txt = ''; | ||
| 78 : | $page = $this->limitstart+1; | ||
| 79 : | if ($this->total > 0) { | ||
| 80 : | csouza | 39 | $txt .= sprintf(T_('Page %d of %d'), $page, $this->total); |
| 81 : | root | 1 | } |
| 82 : | return $txt; | ||
| 83 : | } | ||
| 84 : | |||
| 85 : | /** | ||
| 86 : | * Writes the html links for pages, eg, previous, next, 1 2 3 ... x | ||
| 87 : | * @param string The basic link to include in the href | ||
| 88 : | */ | ||
| 89 : | neilt | 738 | function writePagesLinks( $link ) { |
| 90 : | |||
| 91 : | // clean link - could be better filtered in rewrite | ||
| 92 : | // stops XSS | ||
| 93 : | require_once(mamboCore::get('mosConfig_absolute_path').'/includes/phpInputFilter/class.inputfilter.php'); | ||
| 94 : | $iFilter = new InputFilter( null, null, 1, 1 ); | ||
| 95 : | $link = trim( $iFilter->process( $link ) ); | ||
| 96 : | $link = preg_replace("/(task.*?)&/i", "", $link); | ||
| 97 : | |||
| 98 : | root | 1 | $txt = ''; |
| 99 : | |||
| 100 : | $displayed_pages = 10; | ||
| 101 : | $total_pages = ceil( $this->total / $this->limit ); | ||
| 102 : | $this_page = ceil( ($this->limitstart+1) / $this->limit ); | ||
| 103 : | $start_loop = (floor(($this_page-1)/$displayed_pages))*$displayed_pages+1; | ||
| 104 : | if ($start_loop + $displayed_pages - 1 < $total_pages) { | ||
| 105 : | $stop_loop = $start_loop + $displayed_pages - 1; | ||
| 106 : | } else { | ||
| 107 : | $stop_loop = $total_pages; | ||
| 108 : | } | ||
| 109 : | |||
| 110 : | $link .= '&limit='. $this->limit; | ||
| 111 : | |||
| 112 : | if ($this_page > 1) { | ||
| 113 : | $page = ($this_page - 2) * $this->limit; | ||
| 114 : | csouza | 194 | $txt .= '<a href="'. sefRelToAbs( "$link&limitstart=0" ) .'" class="pagenav" title="'.T_('first page').'"><< '. T_('Start') .'</a> '; |
| 115 : | $txt .= '<a href="'. sefRelToAbs( "$link&limitstart=$page" ) .'" class="pagenav" title="'.T_('previous page').'">< '. T_('Previous') .'</a> '; | ||
| 116 : | root | 1 | } else { |
| 117 : | csouza | 39 | $txt .= '<span class="pagenav"><< '. T_('Start') .'</span> '; |
| 118 : | $txt .= '<span class="pagenav">< '. T_('Previous') .'</span> '; | ||
| 119 : | root | 1 | } |
| 120 : | |||
| 121 : | for ($i=$start_loop; $i <= $stop_loop; $i++) { | ||
| 122 : | $page = ($i - 1) * $this->limit; | ||
| 123 : | if ($i == $this_page) { | ||
| 124 : | $txt .= '<span class="pagenav">'. $i .'</span> '; | ||
| 125 : | } else { | ||
| 126 : | $txt .= '<a href="'. sefRelToAbs( $link .'&limitstart='. $page ) .'" class="pagenav"><strong>'. $i .'</strong></a> '; | ||
| 127 : | } | ||
| 128 : | } | ||
| 129 : | |||
| 130 : | if ($this_page < $total_pages) { | ||
| 131 : | $page = $this_page * $this->limit; | ||
| 132 : | $end_page = ($total_pages-1) * $this->limit; | ||
| 133 : | csouza | 194 | $txt .= '<a href="'. sefRelToAbs( $link .'&limitstart='. $page ) .' " class="pagenav" title="'.T_('next page').'">'. T_('Next') .' ></a> '; |
| 134 : | $txt .= '<a href="'. sefRelToAbs( $link .'&limitstart='. $end_page ) .' " class="pagenav" title="'.T_('end page').'">'. T_('End') .' >></a>'; | ||
| 135 : | root | 1 | } else { |
| 136 : | csouza | 39 | $txt .= '<span class="pagenav">'. T_('Next') .' ></span> '; |
| 137 : | $txt .= '<span class="pagenav">'. T_('End') .' >></span>'; | ||
| 138 : | root | 1 | } |
| 139 : | neilt | 738 | |
| 140 : | |||
| 141 : | |||
| 142 : | return $txt; | ||
| 143 : | root | 1 | } |
| 144 : | } | ||
| 145 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

