📄 common.php
字号:
* @param $link HTML to use as the link [deprecated: use the factory instead] * @return string The link * @access private */ function _getNextLink($url='', $link='') { //legacy settings... the preferred way to set an option //now is passing it to the factory if (!empty($url)) { $this->_path = $url; } if (!empty($link)) { $this->_nextImg = $link; } $next = ''; if ($this->_currentPage < $this->_totalPages) { $this->_linkData[$this->_urlVar] = $this->getNextPageID(); $next = $this->_spacesAfter . $this->_renderLink($this->_altNext, $this->_nextImg) . $this->_spacesBefore . $this->_spacesAfter; } return $next; } // }}} // {{{ _getFirstLinkTag() /** * @return string * @access private */ function _getFirstLinkTag() { if ($this->isFirstPage() || ($this->_httpMethod != 'GET')) { return ''; } return sprintf('<link rel="first" href="%s" title="%s" />'."\n", $this->_getLinkTagUrl(1), $this->_firstLinkTitle ); } // }}} // {{{ _getPrevLinkTag() /** * Returns previous link tag * * @return string the link tag * @access private */ function _getPrevLinkTag() { if ($this->isFirstPage() || ($this->_httpMethod != 'GET')) { return ''; } return sprintf('<link rel="previous" href="%s" title="%s" />'."\n", $this->_getLinkTagUrl($this->getPreviousPageID()), $this->_prevLinkTitle ); } // }}} // {{{ _getNextLinkTag() /** * Returns next link tag * * @return string the link tag * @access private */ function _getNextLinkTag() { if ($this->isLastPage() || ($this->_httpMethod != 'GET')) { return ''; } return sprintf('<link rel="next" href="%s" title="%s" />'."\n", $this->_getLinkTagUrl($this->getNextPageID()), $this->_nextLinkTitle ); } // }}} // {{{ _getLastLinkTag() /** * @return string the link tag * @access private */ function _getLastLinkTag() { if ($this->isLastPage() || ($this->_httpMethod != 'GET')) { return ''; } return sprintf('<link rel="last" href="%s" title="%s" />'."\n", $this->_getLinkTagUrl($this->_totalPages), $this->_lastLinkTitle ); } // }}} // {{{ _getLinkTagUrl() /** * Helper method * @return string the link tag url * @access private */ function _getLinkTagUrl($pageID) { $this->_linkData[$this->_urlVar] = $pageID; if ($this->_append) { $href = '?' . $this->_http_build_query_wrapper($this->_linkData); } else { $href = str_replace('%d', $this->_linkData[$this->_urlVar], $this->_fileName); } return htmlentities($this->_url . $href); } // }}} // {{{ 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 * @param integer $end * @param integer $step * @param boolean $showAllData If true, perPage is set equal to totalItems. * @param array (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 * <select> tag * @return string xhtml select box * @access public */ function getPerPageSelectBox($start=5, $end=30, $step=5, $showAllData=false, $extraParams=array()) { require_once 'Pager/HtmlWidgets.php'; $widget =& new Pager_HtmlWidgets($this); return $widget->getPerPageSelectBox($start, $end, $step, $showAllData, $extraParams); } // }}} // {{{ getPageSelectBox() /** * Returns a string with a XHTML SELECT menu with the page numbers, * useful as an alternative to the links * * @param array - '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 * <select> tag * @return string xhtml select box * @access public */ function getPageSelectBox($params = array(), $extraAttributes = '') { require_once 'Pager/HtmlWidgets.php'; $widget =& new Pager_HtmlWidgets($this); return $widget->getPageSelectBox($params, $extraAttributes); } // }}} // {{{ _printFirstPage() /** * Print [1] * * @return string String with link to 1st page, * or empty string if this is the 1st page. * @access private */ function _printFirstPage() { if ($this->isFirstPage()) { return ''; } $this->_linkData[$this->_urlVar] = 1; return $this->_renderLink( str_replace('%d', 1, $this->_altFirst), $this->_firstPagePre . $this->_firstPageText . $this->_firstPagePost ) . $this->_spacesBefore . $this->_spacesAfter; } // }}} // {{{ _printLastPage() /** * Print [numPages()] * * @return string String with link to last page, * or empty string if this is the 1st page. * @access private */ function _printLastPage() { if ($this->isLastPage()) { return ''; } $this->_linkData[$this->_urlVar] = $this->_totalPages; return $this->_renderLink( str_replace('%d', $this->_totalPages, $this->_altLast), $this->_lastPagePre . $this->_lastPageText . $this->_lastPagePost ); } // }}} // {{{ _setFirstLastText() /** * sets the private _firstPageText, _lastPageText variables * based on whether they were set in the options * * @access private */ function _setFirstLastText() { if ($this->_firstPageText == '') { $this->_firstPageText = '1'; } if ($this->_lastPageText == '') { $this->_lastPageText = $this->_totalPages; } } // }}} // {{{ _http_build_query_wrapper() /** * This is a slightly modified version of the http_build_query() function; * it heavily borrows code from PHP_Compat's http_build_query(). * The main change is the usage of htmlentities instead of urlencode, * since it's too aggressive * * @author Stephan Schmidt <schst@php.net> * @author Aidan Lister <aidan@php.net> * @author Lorenzo Alberton <l dot alberton at quipo dot it> * @param array $data * @return string * @access private */ function _http_build_query_wrapper($data) { $data = (array)$data; if (empty($data)) { return ''; } $separator = ini_get('arg_separator.output'); if ($separator == '&') { $separator = '&'; //the string is escaped by htmlentities anyway... } $tmp = array (); foreach ($data as $key => $val) { if (is_scalar($val)) { //array_push($tmp, $key.'='.$val); $val = urlencode($val); array_push($tmp, $key .'='. str_replace('%2F', '/', $val)); continue; } // If the value is an array, recursively parse it if (is_array($val)) { array_push($tmp, $this->__http_build_query($val, htmlentities($key))); continue; } } return implode($separator, $tmp); } // }}} // {{{ __http_build_query() /** * Helper function * @author Stephan Schmidt <schst@php.net> * @author Aidan Lister <aidan@php.net> * @access private */ function __http_build_query($array, $name) { $tmp = array (); $separator = ini_get('arg_separator.output'); if ($separator == '&') { $separator = '&'; //the string is escaped by htmlentities anyway... } foreach ($array as $key => $value) { if (is_array($value)) { //array_push($tmp, $this->__http_build_query($value, sprintf('%s[%s]', $name, $key))); array_push($tmp, $this->__http_build_query($value, $name.'%5B'.$key.'%5D')); } elseif (is_scalar($value)) { //array_push($tmp, sprintf('%s[%s]=%s', $name, htmlentities($key), htmlentities($value))); array_push($tmp, $name.'%5B'.htmlentities($key).'%5D='.htmlentities($value)); } elseif (is_object($value)) { //array_push($tmp, $this->__http_build_query(get_object_vars($value), sprintf('%s[%s]', $name, $key))); array_push($tmp, $this->__http_build_query(get_object_vars($value), $name.'%5B'.$key.'%5D')); } } return implode($separator, $tmp); } // }}} // {{{ _isEncoded() /** * Helper function * Check if a string is an encoded multibyte string * @param string $string * @return boolean * @access private */ function _isEncoded($string) { $hexchar = '&#[\dA-Fx]{2,};'; return preg_match("/^(\s|($hexchar))*$/Uims", $string) ? true : false; } // }}} // {{{ raiseError() /** * conditionally includes PEAR base class and raise an error * * @param string $msg Error message * @param int $code Error code * @access private */ function raiseError($msg, $code) { include_once 'PEAR.php'; if (empty($this->_pearErrorMode)) { $this->_pearErrorMode = PEAR_ERROR_RETURN; } return PEAR::raiseError($msg, $code, $this->_pearErrorMode); } // }}} // {{{ setOptions() /** * Set and sanitize options * * @param mixed $options An associative array of option names and * their values. * @return integer error code (PAGER_OK on success) * @access public */ function setOptions($options) { foreach ($options as $key => $value) { if (in_array($key, $this->_allowed_options) && (!is_null($value))) { $this->{'_' . $key} = $value; } } //autodetect http method if (!isset($options['httpMethod']) && !isset($_GET[$this->_urlVar]) && isset($_POST[$this->_urlVar]) ) { $this->_httpMethod = 'POST'; } else { $this->_httpMethod = strtoupper($this->_httpMethod); } $this->_fileName = ltrim($this->_fileName, '/'); //strip leading slash $this->_path = rtrim($this->_path, '/'); //strip trailing slash if ($this->_append) { if ($this->_fixFileName) { $this->_fileName = CURRENT_FILENAME; //avoid possible user error; } $this->_url = $this->_path.'/'.$this->_fileName; } else { $this->_url = $this->_path; if (strncasecmp($this->_fileName, 'javascript', 10) != 0) { $this->_url .= '/'; } if (!strstr($this->_fileName, '%d')) { trigger_error($this->errorMessage(ERROR_PAGER_INVALID_USAGE), E_USER_WARNING); } } $this->_classString = ''; if (strlen($this->_linkClass)) { $this->_classString = 'class="'.$this->_linkClass.'"'; } if (strlen($this->_curPageLinkClassName)) { $this->_curPageSpanPre = '<span class="'.$this->_curPageLinkClassName.'">'; $this->_curPageSpanPost = '</span>'; } $this->_perPage = max($this->_perPage, 1); //avoid possible user errors if ($this->_useSessions && !isset($_SESSION)) { session_start(); } if (!empty($_REQUEST[$this->_sessionVar])) { $this->_perPage = max(1, (int)$_REQUEST[$this->_sessionVar]); if ($this->_useSessions) { $_SESSION[$this->_sessionVar] = $this->_perPage; } } if (!empty($_SESSION[$this->_sessionVar])) { $this->_perPage = $_SESSION[$this->_sessionVar]; } if ($this->_closeSession) { session_write_close(); } $this->_spacesBefore = str_repeat(' ', $this->_spacesBeforeSeparator); $this->_spacesAfter = str_repeat(' ', $this->_spacesAfterSeparator); if (isset($_REQUEST[$this->_urlVar]) && empty($options['currentPage'])) { $this->_currentPage = (int)$_REQUEST[$this->_urlVar]; } $this->_currentPage = max($this->_currentPage, 1); $this->_linkData = $this->_getLinksData(); return PAGER_OK; } // }}} // {{{ getOption() /** * Return the current value of a given option * * @param string option name * @return mixed option value */ function getOption($name) { if (!in_array($name, $this->_allowed_options)) { $msg = '<b>PEAR::Pager Error:</b>' .' invalid option: '.$name; return $this->raiseError($msg, ERROR_PAGER_INVALID); } return $this->{'_' . $name}; } // }}} // {{{ getOptions() /** * Return an array with all the current pager options * * @return array list of all the pager options */ function getOptions() { $options = array(); foreach ($this->_allowed_options as $option) { $options[$option] = $this->{'_' . $option}; } return $options; } // }}} // {{{ errorMessage() /** * Return a textual error message for a PAGER error code * * @param int $code error code * @return string error message * @access public */ function errorMessage($code) { static $errorMessages; if (!isset($errorMessages)) { $errorMessages = array( ERROR_PAGER => 'unknown error', ERROR_PAGER_INVALID => 'invalid', ERROR_PAGER_INVALID_PLACEHOLDER => 'invalid format - use "%d" as placeholder.', ERROR_PAGER_INVALID_USAGE => 'if $options[\'append\'] is set to false, ' .' $options[\'fileName\'] MUST contain the "%d" placeholder.', ERROR_PAGER_NOT_IMPLEMENTED => 'not implemented' ); } return '<b>PEAR::Pager error:</b> '. (isset($errorMessages[$code]) ? $errorMessages[$code] : $errorMessages[ERROR_PAGER]); } // }}}}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -