芝麻web文件管理V1.00
编辑当前文件:/home/strato/chroot/opt/RZphp80/includes/Pager/HtmlWidgets.php
* @copyright 2003-2007 Lorenzo Alberton * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) * @version CVS: $Id$ * @link http://pear.php.net/package/Pager */ /** * Pager_HtmlWidgets * * @category HTML * @package Pager * @author Lorenzo Alberton
* @copyright 2003-2007 Lorenzo Alberton * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) * @link http://pear.php.net/package/Pager */ class Pager_HtmlWidgets { var $pager = null; // {{{ constructor /** * Constructor * * @param object &$pager Pager instance */ function __construct(&$pager) { $this->pager =& $pager; } /** * Constructor for PHP4 compatibility * * @param object &$pager Pager instance * * @see http://cweiske.de/tagebuch/php4-constructors-php7.htm */ public function Pager_HtmlWidgets(&$pager) { self::__construct($pager); } // }}} // {{{ getPerPageSelectBox() /** * Returns a string with a XHTML SELECT menu, * useful for letting the user choose how many items per page should be * displayed. If parameter useSessions is TRUE, this value is stored in * a session var. The string isn't echoed right now so you can use it * with template engines. * * @param integer $start starting value for the select menu * @param integer $end ending value for the select menu * @param integer $step step between values in the select menu * @param boolean $showAllData If true, perPage is set equal to totalItems. * @param array $extraParams (or string $optionText for BC reasons) * - 'optionText': text to show in each option. * Use '%d' where you want to see the number of pages selected. * - 'attributes': (html attributes) Tag attributes or * HTML attributes (id="foo" pairs), will be inserted in the *
tag * - 'checkMaxLimit': if true, Pager checks if $end is bigger * than $totalItems, and doesn't show the extra select options * - 'autoSubmit': if TRUE, add some js code * to submit the form on the onChange event * * @return string xhtml select box * @access public */ function getPerPageSelectBox($start=5, $end=30, $step=5, $showAllData=false, $extraParams=array()) { // FIXME: needs POST support $optionText = '%d'; $attributes = ''; $checkMaxLimit = false; if (is_string($extraParams)) { //old behavior, BC maintained $optionText = $extraParams; } else { if (array_key_exists('optionText', $extraParams)) { $optionText = $extraParams['optionText']; } if (array_key_exists('attributes', $extraParams)) { $attributes = $extraParams['attributes']; } if (array_key_exists('checkMaxLimit', $extraParams)) { $checkMaxLimit = $extraParams['checkMaxLimit']; } } if (!strstr($optionText, '%d')) { return $this->pager->raiseError( $this->pager->errorMessage(ERROR_PAGER_INVALID_PLACEHOLDER), ERROR_PAGER_INVALID_PLACEHOLDER ); } $start = (int)$start; $end = (int)$end; $step = (int)$step; if (!empty($_SESSION[$this->pager->_sessionVar])) { $selected = (int)$_SESSION[$this->pager->_sessionVar]; } else { $selected = $this->pager->_perPage; } if ($checkMaxLimit && $this->pager->_totalItems >= 0 && $this->pager->_totalItems < $end) { $end = $this->pager->_totalItems; } $tmp = '
pager->_httpMethod) { $selector = '\' + '.'this.options[this.selectedIndex].value + \''; if ($this->pager->_append) { $tmpLinkData = $this->pager->_linkData; if (isset($tmpLinkData[$this->pager->_urlVar])) { $tmpLinkData[$this->pager->_urlVar] = $this->pager->getCurrentPageID(); } $tmpLinkData[$this->pager->_sessionVar] = '1'; $href = '?' . $this->pager->_http_build_query_wrapper($tmpLinkData); $href = htmlentities($this->pager->_url, ENT_COMPAT, 'UTF-8'). preg_replace( '/(&|&|\?)('.$this->pager->_sessionVar.'=)(\d+)/', '\\1\\2'.$selector, htmlentities($href, ENT_COMPAT, 'UTF-8') ); } else { $href = htmlentities($this->pager->_url . str_replace('%d', $selector, $this->pager->_fileName), ENT_COMPAT, 'UTF-8'); } $tmp .= ' onchange="document.location.href=\'' . $href .'\'' . '"'; } elseif ($this->pager->_httpMethod == 'POST') { $tmp .= " onchange='" . $this->pager->_generateFormOnClick($this->pager->_url, $this->pager->_linkData) . "'"; $tmp = preg_replace( '/(input\.name = \"'.$this->pager->_sessionVar.'\"; input\.value =) \"(\d+)\";/', '\\1 this.options[this.selectedIndex].value;', $tmp ); } } $tmp .= '>'; $last = $start; for ($i=$start; $i<=$end; $i+=$step) { $last = $i; $tmp .= '
'; } if ($showAllData && $last != $this->pager->_totalItems) { $tmp .= '
pager->_totalItems == $selected) { $tmp .= ' selected="selected"'; } $tmp .= '>'; if (empty($this->pager->_showAllText)) { $tmp .= str_replace('%d', $this->pager->_totalItems, $optionText); } else { $tmp .= $this->pager->_showAllText; } $tmp .= '
'; } if (substr($tmp, -9, 9) !== '') { //empty select $tmp .= '
'; } $tmp .= '
'; return $tmp; } // }}} // {{{ getPageSelectBox() /** * Returns a string with a XHTML SELECT menu with the page numbers, * useful as an alternative to the links * * @param array $params - 'optionText': text to show in each option. * Use '%d' where you want to see the number * of pages selected. * - 'autoSubmit': if TRUE, add some js code * to submit the form on the onChange event * @param string $extraAttributes (html attributes) Tag attributes or * HTML attributes (id="foo" pairs), will be * inserted in the
tag * * @return string xhtml select box * @access public */ function getPageSelectBox($params = array(), $extraAttributes = '') { $optionText = '%d'; if (array_key_exists('optionText', $params)) { $optionText = $params['optionText']; } if (!strstr($optionText, '%d')) { return $this->pager->raiseError( $this->pager->errorMessage(ERROR_PAGER_INVALID_PLACEHOLDER), ERROR_PAGER_INVALID_PLACEHOLDER ); } $tmp = '
pager->_httpMethod == 'GET') { $selector = '\' + '.'this.options[this.selectedIndex].value + \''; if ($this->pager->_append) { $href = '?' . $this->pager->_http_build_query_wrapper($this->pager->_linkData); $href = htmlentities($this->pager->_url, ENT_COMPAT, 'UTF-8'). preg_replace( '/(&|&|\?)('.$this->pager->_urlVar.'=)(\d+)/', '\\1\\2'.$selector, htmlentities($href, ENT_COMPAT, 'UTF-8') ); } else { $href = htmlentities($this->pager->_url . str_replace('%d', $selector, $this->pager->_fileName), ENT_COMPAT, 'UTF-8'); } $tmp .= ' onchange="document.location.href=\'' . $href .'\'' . '"'; } elseif ($this->pager->_httpMethod == 'POST') { $tmp .= " onchange='" . $this->pager->_generateFormOnClick($this->pager->_url, $this->pager->_linkData) . "'"; $tmp = preg_replace( '/(input\.name = \"'.$this->pager->_urlVar.'\"; input\.value =) \"(\d+)\";/', '\\1 this.options[this.selectedIndex].value;', $tmp ); } } $tmp .= '>'; $start = 1; $end = $this->pager->numPages(); $selected = $this->pager->getCurrentPageID(); for ($i=$start; $i<=$end; $i++) { $tmp .= '
'; } $tmp .= '
'; return $tmp; } // }}} } ?>