⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 common.php

📁 FP2 CRM code+Mysql DB
💻 PHP
📖 第 1 页 / 共 3 页
字号:
     * @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 = sprintf($this->_fileName, $this->_linkData[$this->_urlVar]);        }        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())    {        // FIXME: needs POST support        $optionText = '%d';        $attributes = '';        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 (!strstr($optionText, '%d')) {            return $this->raiseError(                $this->errorMessage(ERROR_PAGER_INVALID_PLACEHOLDER),                ERROR_PAGER_INVALID_PLACEHOLDER            );        }        $start = (int)$start;        $end   = (int)$end;        $step  = (int)$step;        if (!empty($_SESSION[$this->_sessionVar])) {            $selected = (int)$_SESSION[$this->_sessionVar];        } else {            $selected = $this->_perPage;        }        $tmp = '<select name="'.$this->_sessionVar.'"';        if (!empty($attributes)) {            $tmp .= ' '.$attributes;        }        $tmp .= '>';        for ($i=$start; $i<=$end; $i+=$step) {            $tmp .= '<option value="'.$i.'"';            if ($i == $selected) {                $tmp .= ' selected="selected"';            }            $tmp .= '>'.sprintf($optionText, $i).'</option>';        }        if ($showAllData && $end < $this->_totalItems) {            $tmp .= '<option value="'.$this->_totalItems.'"';            if ($this->_totalItems == $selected) {                $tmp .= ' selected="selected"';            }            $tmp .= '>';            if (empty($this->_showAllText)) {                $tmp .= str_replace('%d', $this->_totalItems, $optionText);            } else {                $tmp .= $this->_showAllText;            }            $tmp .= '</option>';        }        $tmp .= '</select>';        return $tmp;    }    // }}}    // {{{ _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 == '&amp;') {            $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 ();        foreach ($array as $key => $value) {            if (is_array($value)) {                array_push($tmp, $this->__http_build_query($value, $name.'%5B'.$key.'%5D'));            } elseif (is_scalar($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), $name.'%5B'.$key.'%5D'));            }        }        return implode(ini_get('arg_separator.output'), $tmp);    }    // }}}    // {{{ 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 private     */    function _setOptions($options)    {        $allowed_options = array(            'totalItems',            'perPage',            'delta',            'linkClass',            'path',            'fileName',            'append',            'httpMethod',            'importQuery',            'urlVar',            'altFirst',            'altPrev',            'altNext',            'altLast',            'altPage',            'prevImg',            'nextImg',            'expanded',            'separator',            'spacesBeforeSeparator',            'spacesAfterSeparator',            'curPageLinkClassName',            'curPageSpanPre',            'curPageSpanPost',            'firstPagePre',            'firstPageText',            'firstPagePost',            'lastPagePre',            'lastPageText',            'lastPagePost',            'firstLinkTitle',            'nextLinkTitle',            'prevLinkTitle',            'lastLinkTitle',            'showAllText',            'itemData',            'clearIfVoid',            'useSessions',            'closeSession',            'sessionVar',            'pearErrorMode',            'extraVars',            'excludeVars',            'currentPage',        );                foreach ($options as $key => $value) {            if (in_array($key, $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) {            $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('&nbsp;', $this->_spacesBeforeSeparator);        $this->_spacesAfter  = str_repeat('&nbsp;', $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;    }    // }}}    // {{{ 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 + -