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

