Pager
[ class tree: Pager ] [ index: Pager ] [ all elements ]

Source for file Common.php

Documentation is available at Common.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3.  
  4. /**
  5.  * Contains the Pager_Common class
  6.  *
  7.  * PHP versions 4 and 5
  8.  *
  9.  * LICENSE: Redistribution and use in source and binary forms, with or without
  10.  * modification, are permitted provided that the following conditions are met:
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  * 2. Redistributions in binary form must reproduce the above copyright
  14.  *    notice, this list of conditions and the following disclaimer in the
  15.  *    documentation and/or other materials provided with the distribution.
  16.  * 3. The name of the author may not be used to endorse or promote products
  17.  *    derived from this software without specific prior written permission.
  18.  *
  19.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
  20.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  22.  * IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
  23.  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  26.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  28.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29.  *
  30.  * @category   HTML
  31.  * @package    Pager
  32.  * @author     Lorenzo Alberton <l dot alberton at quipo dot it>
  33.  * @author     Richard Heyes <richard@phpguru.org>
  34.  * @copyright  2003-2006 Lorenzo Alberton, Richard Heyes
  35.  * @license    http://www.debian.org/misc/bsd.license  BSD License (3 Clause)
  36.  * @version    CVS: $Id: Common.php 12273 2007-05-03 14:49:21Z elixir_julian $
  37.  * @link       http://pear.php.net/package/Pager
  38.  */
  39.  
  40. /**
  41.  * Two constants used to guess the path- and file-name of the page
  42.  * when the user doesn't set any other value
  43.  */
  44. if (substr(api_get_self()-1== '/'{
  45.     define('CURRENT_FILENAME''');
  46.     define('CURRENT_PATHNAME''http://'.$_SERVER['HTTP_HOST'].str_replace('\\''/'api_get_self()));
  47. else {
  48.     define('CURRENT_FILENAME'preg_replace('/(.*)\?.*/''\\1'basename(api_get_self())));
  49.     define('CURRENT_PATHNAME'str_replace('\\''/'dirname(api_get_self())));
  50. }
  51. /**
  52.  * Error codes
  53.  */
  54. define('PAGER_OK',                         0);
  55. define('ERROR_PAGER',                     -1);
  56. define('ERROR_PAGER_INVALID',             -2);
  57. define('ERROR_PAGER_INVALID_PLACEHOLDER'-3);
  58. define('ERROR_PAGER_INVALID_USAGE',       -4);
  59. define('ERROR_PAGER_NOT_IMPLEMENTED',     -5);
  60.  
  61. /**
  62.  * Pager_Common - Common base class for [Sliding|Jumping] Window Pager
  63.  * Extend this class to write a custom paging class
  64.  *
  65.  * @category   HTML
  66.  * @package    Pager
  67.  * @author     Lorenzo Alberton <l dot alberton at quipo dot it>
  68.  * @author     Richard Heyes <richard@phpguru.org>
  69.  * @copyright  2003-2005 Lorenzo Alberton, Richard Heyes
  70.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  71.  * @link       http://pear.php.net/package/Pager
  72.  */
  73. {
  74.     // {{{ class vars
  75.  
  76.     /**
  77.      * @var integer number of items
  78.      * @access private
  79.      */
  80.     var $_totalItems;
  81.  
  82.     /**
  83.      * @var integer number of items per page
  84.      * @access private
  85.      */
  86.     var $_perPage     = 10;
  87.  
  88.     /**
  89.      * @var integer number of page links for each window
  90.      * @access private
  91.      */
  92.     var $_delta       = 10;
  93.  
  94.     /**
  95.      * @var integer current page number
  96.      * @access private
  97.      */
  98.     var $_currentPage = 1;
  99.  
  100.     /**
  101.      * @var integer total pages number
  102.      * @access private
  103.      */
  104.     var $_totalPages  = 1;
  105.  
  106.     /**
  107.      * @var string CSS class for links
  108.      * @access private
  109.      */
  110.     var $_linkClass   = '';
  111.  
  112.     /**
  113.      * @var string wrapper for CSS class name
  114.      * @access private
  115.      */
  116.     var $_classString = '';
  117.  
  118.     /**
  119.      * @var string path name
  120.      * @access private
  121.      */
  122.     var $_path        = CURRENT_PATHNAME;
  123.  
  124.     /**
  125.      * @var string file name
  126.      * @access private
  127.      */
  128.     var $_fileName    = CURRENT_FILENAME;
  129.     
  130.     /**
  131.      * @var boolean If false, don't override the fileName option. Use at your own risk.
  132.      * @access private
  133.      */
  134.     var $_fixFileName = true;
  135.  
  136.     /**
  137.      * @var boolean you have to use FALSE with mod_rewrite
  138.      * @access private
  139.      */
  140.     var $_append      = true;
  141.  
  142.     /**
  143.      * @var string specifies which HTTP method to use
  144.      * @access private
  145.      */
  146.     var $_httpMethod  = 'GET';
  147.     
  148.     /**
  149.      * @var string specifies which HTML form to use
  150.      * @access private
  151.      */
  152.     var $_formID  = '';
  153.  
  154.     /**
  155.      * @var boolean whether or not to import submitted data
  156.      * @access private
  157.      */
  158.     var $_importQuery = true;
  159.  
  160.     /**
  161.      * @var string name of the querystring var for pageID
  162.      * @access private
  163.      */
  164.     var $_urlVar      = 'pageID';
  165.  
  166.     /**
  167.      * @var array data to pass through the link
  168.      * @access private
  169.      */
  170.     var $_linkData    = array();
  171.  
  172.     /**
  173.      * @var array additional URL vars
  174.      * @access private
  175.      */
  176.     var $_extraVars   = array();
  177.     
  178.     /**
  179.      * @var array URL vars to ignore
  180.      * @access private
  181.      */
  182.     var $_excludeVars = array();
  183.  
  184.     /**
  185.      * @var boolean TRUE => expanded mode (for Pager_Sliding)
  186.      * @access private
  187.      */
  188.     var $_expanded    = true;
  189.     
  190.     /**
  191.      * @var boolean TRUE => show accesskey attribute on <a> tags
  192.      * @access private
  193.      */
  194.     var $_accesskey   = false;
  195.  
  196.     /**
  197.      * @var string extra attributes for the <a> tag
  198.      * @access private
  199.      */
  200.     var $_attributes  = '';
  201.  
  202.     /**
  203.      * @var string alt text for "first page" (use "%d" placeholder for page number)
  204.      * @access private
  205.      */
  206.     var $_altFirst     = 'first page';
  207.  
  208.     /**
  209.      * @var string alt text for "previous page"
  210.      * @access private
  211.      */
  212.     var $_altPrev     = 'previous page';
  213.  
  214.     /**
  215.      * @var string alt text for "next page"
  216.      * @access private
  217.      */
  218.     var $_altNext     = 'next page';
  219.  
  220.     /**
  221.      * @var string alt text for "last page" (use "%d" placeholder for page number)
  222.      * @access private
  223.      */
  224.     var $_altLast     = 'last page';
  225.  
  226.     /**
  227.      * @var string alt text for "page"
  228.      * @access private
  229.      */
  230.     var $_altPage     = 'page';
  231.  
  232.     /**
  233.      * @var string image/text to use as "prev" link
  234.      * @access private
  235.      */
  236.     var $_prevImg     = '&lt;&lt; Back';
  237.  
  238.     /**
  239.      * @var string image/text to use as "next" link
  240.      * @access private
  241.      */
  242.     var $_nextImg     = 'Next &gt;&gt;';
  243.  
  244.     /**
  245.      * @var string link separator
  246.      * @access private
  247.      */
  248.     var $_separator   = '';
  249.  
  250.     /**
  251.      * @var integer number of spaces before separator
  252.      * @access private
  253.      */
  254.     var $_spacesBeforeSeparator = 0;
  255.  
  256.     /**
  257.      * @var integer number of spaces after separator
  258.      * @access private
  259.      */
  260.     var $_spacesAfterSeparator  = 1;
  261.  
  262.     /**
  263.      * @var string CSS class name for current page link
  264.      * @access private
  265.      */
  266.     var $_curPageLinkClassName  = '';
  267.  
  268.     /**
  269.      * @var string Text before current page link
  270.      * @access private
  271.      */
  272.     var $_curPageSpanPre        = '';
  273.  
  274.     /**
  275.      * @var string Text after current page link
  276.      * @access private
  277.      */
  278.     var $_curPageSpanPost       = '';
  279.  
  280.     /**
  281.      * @var string Text before first page link
  282.      * @access private
  283.      */
  284.     var $_firstPagePre  = '[';
  285.  
  286.     /**
  287.      * @var string Text to be used for first page link
  288.      * @access private
  289.      */
  290.     var $_firstPageText = '';
  291.  
  292.     /**
  293.      * @var string Text after first page link
  294.      * @access private
  295.      */
  296.     var $_firstPagePost = ']';
  297.  
  298.     /**
  299.      * @var string Text before last page link
  300.      * @access private
  301.      */
  302.     var $_lastPagePre   = '[';
  303.  
  304.     /**
  305.      * @var string Text to be used for last page link
  306.      * @access private
  307.      */
  308.     var $_lastPageText  = '';
  309.  
  310.     /**
  311.      * @var string Text after last page link
  312.      * @access private
  313.      */
  314.     var $_lastPagePost  = ']';
  315.  
  316.     /**
  317.      * @var string Will contain the HTML code for the spaces
  318.      * @access private
  319.      */
  320.     var $_spacesBefore  = '';
  321.  
  322.     /**
  323.      * @var string Will contain the HTML code for the spaces
  324.      * @access private
  325.      */
  326.     var $_spacesAfter   = '';
  327.  
  328.     /**
  329.      * @var string $_firstLinkTitle 
  330.      * @access private
  331.      */
  332.     var $_firstLinkTitle = 'first page';
  333.  
  334.     /**
  335.      * @var string $_nextLinkTitle 
  336.      * @access private
  337.      */
  338.     var $_nextLinkTitle = 'next page';
  339.  
  340.     /**
  341.      * @var string $_prevLinkTitle 
  342.      * @access private
  343.      */
  344.     var $_prevLinkTitle = 'previous page';
  345.  
  346.     /**
  347.      * @var string $_lastLinkTitle 
  348.      * @access private
  349.      */
  350.     var $_lastLinkTitle = 'last page';
  351.  
  352.     /**
  353.      * @var string Text to be used for the 'show all' option in the select box
  354.      * @access private
  355.      */
  356.     var $_showAllText   = '';
  357.  
  358.     /**
  359.      * @var array data to be paged
  360.      * @access private
  361.      */
  362.     var $_itemData      = null;
  363.  
  364.     /**
  365.      * @var boolean If TRUE and there's only one page, links aren't shown
  366.      * @access private
  367.      */
  368.     var $_clearIfVoid   = true;
  369.  
  370.     /**
  371.      * @var boolean Use session for storing the number of items per page
  372.      * @access private
  373.      */
  374.     var $_useSessions   = false;
  375.  
  376.     /**
  377.      * @var boolean Close the session when finished reading/writing data
  378.      * @access private
  379.      */
  380.     var $_closeSession  = false;
  381.  
  382.     /**
  383.      * @var string name of the session var for number of items per page
  384.      * @access private
  385.      */
  386.     var $_sessionVar    = 'setPerPage';
  387.  
  388.     /**
  389.      * Pear error mode (when raiseError is called)
  390.      * (see PEAR doc)
  391.      *
  392.      * @var int $_pearErrorMode 
  393.      * @access private
  394.      */
  395.     var $_pearErrorMode = null;
  396.  
  397.     // }}}
  398.     // {{{ public vars
  399.  
  400.     /**
  401.      * @var string Complete set of links
  402.      * @access public
  403.      */
  404.     var $links = '';
  405.  
  406.     /**
  407.      * @var string Complete set of link tags
  408.      * @access public
  409.      */
  410.     var $linkTags = '';
  411.  
  412.     /**
  413.      * @var array Array with a key => value pair representing
  414.      *             page# => bool value (true if key==currentPageNumber).
  415.      *             can be used for extreme customization.
  416.      * @access public
  417.      */
  418.     var $range = array();
  419.     
  420.     /**
  421.      * @var array list of available options (safety check)
  422.      * @access private
  423.      */
  424.     var $_allowed_options = array(
  425.         'totalItems',
  426.         'perPage',
  427.         'delta',
  428.         'linkClass',
  429.         'path',
  430.         'fileName',
  431.         'fixFileName',
  432.         'append',
  433.         'httpMethod',
  434.         'formID',
  435.         'importQuery',
  436.         'urlVar',
  437.         'altFirst',
  438.         'altPrev',
  439.         'altNext',
  440.         'altLast',
  441.         'altPage',
  442.         'prevImg',
  443.         'nextImg',
  444.         'expanded',
  445.         'accesskey',
  446.         'attributes',
  447.         'separator',
  448.         'spacesBeforeSeparator',
  449.         'spacesAfterSeparator',
  450.         'curPageLinkClassName',
  451.         'curPageSpanPre',
  452.         'curPageSpanPost',
  453.         'firstPagePre',
  454.         'firstPageText',
  455.         'firstPagePost',
  456.         'lastPagePre',
  457.         'lastPageText',
  458.         'lastPagePost',
  459.         'firstLinkTitle',
  460.         'nextLinkTitle',
  461.         'prevLinkTitle',
  462.         'lastLinkTitle',
  463.         'showAllText',
  464.         'itemData',
  465.         'clearIfVoid',
  466.         'useSessions',
  467.         'closeSession',
  468.         'sessionVar',
  469.         'pearErrorMode',
  470.         'extraVars',
  471.         'excludeVars',
  472.         'currentPage',
  473.     );
  474.  
  475.     // }}}
  476.     // {{{ build()
  477.     
  478.     /**
  479.      * Generate or refresh the links and paged data after a call to setOptions()
  480.      *
  481.      * @access public
  482.      */
  483.     function build()
  484.     {
  485.         $msg '<b>PEAR::Pager Error:</b>'
  486.               .' function "build()" not implemented.';
  487.         return $this->raiseError($msgERROR_PAGER_NOT_IMPLEMENTED);
  488.     }
  489.  
  490.     // }}}
  491.     // {{{ getPageData()
  492.  
  493.     /**
  494.      * Returns an array of current pages data
  495.      *
  496.      * @param $pageID Desired page ID (optional)
  497.      * @return array Page data
  498.      * @access public
  499.      */
  500.     function getPageData($pageID null)
  501.     {
  502.         $pageID empty($pageID$this->_currentPage : $pageID;
  503.  
  504.         if (!isset($this->_pageData)) {
  505.             $this->_generatePageData();
  506.         }
  507.         if (!empty($this->_pageData[$pageID])) {
  508.             return $this->_pageData[$pageID];
  509.         }
  510.         return array();
  511.     }
  512.  
  513.     // }}}
  514.     // {{{ getPageIdByOffset()
  515.  
  516.     /**
  517.      * Returns pageID for given offset
  518.      *
  519.      * @param $index Offset to get pageID for
  520.      * @return int PageID for given offset
  521.      */
  522.     function getPageIdByOffset($index)
  523.     {
  524.         $msg '<b>PEAR::Pager Error:</b>'
  525.               .' function "getPageIdByOffset()" not implemented.';
  526.         return $this->raiseError($msgERROR_PAGER_NOT_IMPLEMENTED);
  527.     }
  528.  
  529.     // }}}
  530.     // {{{ getOffsetByPageId()
  531.  
  532.     /**
  533.      * Returns offsets for given pageID. Eg, if you
  534.      * pass it pageID one and your perPage limit is 10
  535.      * it will return (1, 10). PageID of 2 would
  536.      * give you (11, 20).
  537.      *
  538.      * @param integer PageID to get offsets for
  539.      * @return array  First and last offsets
  540.      * @access public
  541.      */
  542.     function getOffsetByPageId($pageid null)
  543.     {
  544.         $pageid = isset($pageid$pageid $this->_currentPage;
  545.         if (!isset($this->_pageData)) {
  546.             $this->_generatePageData();
  547.         }
  548.  
  549.         if (isset($this->_pageData[$pageid]|| is_null($this->_itemData)) {
  550.             return array(
  551.                         max(($this->_perPage * ($pageid 1)) 11),
  552.                         min($this->_totalItems$this->_perPage * $pageid)
  553.                    );
  554.         else {
  555.             return array(00);
  556.         }
  557.     }
  558.  
  559.     // }}}
  560.     // {{{ getPageRangeByPageId()
  561.  
  562.     /**
  563.      * @param integer PageID to get offsets for
  564.      * @return array  First and last offsets
  565.      */
  566.     function getPageRangeByPageId($pageID)
  567.     {
  568.         $msg '<b>PEAR::Pager Error:</b>'
  569.               .' function "getPageRangeByPageId()" not implemented.';
  570.         return $this->raiseError($msgERROR_PAGER_NOT_IMPLEMENTED);
  571.     }
  572.  
  573.     // }}}
  574.     // {{{ getLinks()
  575.  
  576.     /**
  577.      * Returns back/next/first/last and page links,
  578.      * both as ordered and associative array.
  579.      *
  580.      * NB: in original PEAR::Pager this method accepted two parameters,
  581.      * $back_html and $next_html. Now the only parameter accepted is
  582.      * an integer ($pageID), since the html text for prev/next links can
  583.      * be set in the factory. If a second parameter is provided, then
  584.      * the method act as it previously did. This hack was done to mantain
  585.      * backward compatibility only.
  586.      *
  587.      * @param integer $pageID Optional pageID. If specified, links
  588.      *                 for that page are provided instead of current one.  [ADDED IN NEW PAGER VERSION]
  589.      * @param  string $next_html HTML to put inside the next link [deprecated: use the factory instead]
  590.      * @return array back/next/first/last and page links
  591.      */
  592.     function getLinks($pageID=null$next_html='')
  593.     {
  594.         $msg '<b>PEAR::Pager Error:</b>'
  595.               .' function "getLinks()" not implemented.';
  596.         return $this->raiseError($msgERROR_PAGER_NOT_IMPLEMENTED);
  597.     }
  598.  
  599.     // }}}
  600.     // {{{ getCurrentPageID()
  601.  
  602.     /**
  603.      * Returns ID of current page
  604.      *
  605.      * @return integer ID of current page
  606.      */
  607.     function getCurrentPageID()
  608.     {
  609.         return $this->_currentPage;
  610.     }
  611.  
  612.     // }}}
  613.     // {{{ getNextPageID()
  614.  
  615.     /**
  616.      * Returns next page ID. If current page is last page
  617.      * this function returns FALSE
  618.      *
  619.      * @return mixed Next page ID
  620.      */
  621.     function getNextPageID()
  622.     {
  623.         return ($this->getCurrentPageID(== $this->numPages(false $this->getCurrentPageID(1);
  624.     }
  625.  
  626.     // }}}
  627.     // {{{ getPreviousPageID()
  628.  
  629.     /**
  630.      * Returns previous page ID. If current page is first page
  631.      * this function returns FALSE
  632.      *
  633.      * @return mixed Previous pages' ID
  634.      */
  635.     function getPreviousPageID()
  636.     {
  637.         return $this->isFirstPage(false $this->getCurrentPageID(1;
  638.     }
  639.  
  640.     // }}}
  641.     // {{{ numItems()
  642.  
  643.     /**
  644.      * Returns number of items
  645.      *
  646.      * @return int Number of items
  647.      */
  648.     function numItems()
  649.     {
  650.         return $this->_totalItems;
  651.     }
  652.  
  653.     // }}}
  654.     // {{{ numPages()
  655.  
  656.     /**
  657.      * Returns number of pages
  658.      *
  659.      * @return int Number of pages
  660.      */
  661.     function numPages()
  662.     {
  663.         return (int)$this->_totalPages;
  664.     }
  665.  
  666.     // }}}
  667.     // {{{ isFirstPage()
  668.  
  669.     /**
  670.      * Returns whether current page is first page
  671.      *
  672.      * @return bool First page or not
  673.      */
  674.     function isFirstPage()
  675.     {
  676.         return ($this->_currentPage < 2);
  677.     }
  678.  
  679.     // }}}
  680.     // {{{ isLastPage()
  681.  
  682.     /**
  683.      * Returns whether current page is last page
  684.      *
  685.      * @return bool Last page or not
  686.      */
  687.     function isLastPage()
  688.     {
  689.         return ($this->_currentPage == $this->_totalPages);
  690.     }
  691.  
  692.     // }}}
  693.     // {{{ isLastPageComplete()
  694.  
  695.     /**
  696.      * Returns whether last page is complete
  697.      *
  698.      * @return bool Last age complete or not
  699.      */
  700.     function isLastPageComplete()
  701.     {
  702.         return !($this->_totalItems % $this->_perPage);
  703.     }
  704.  
  705.     // }}}
  706.     // {{{ _generatePageData()
  707.  
  708.     /**
  709.      * Calculates all page data
  710.      * @access private
  711.      */
  712.     function _generatePageData()
  713.     {
  714.         // Been supplied an array of data?
  715.         if (!is_null($this->_itemData)) {
  716.             $this->_totalItems = count($this->_itemData);
  717.         }
  718.         $this->_totalPages = ceil((float)$this->_totalItems / (float)$this->_perPage);
  719.         $i 1;
  720.         if (!empty($this->_itemData)) {
  721.             foreach ($this->_itemData as $key => $value{
  722.                 $this->_pageData[$i][$key$value;
  723.                 if (count($this->_pageData[$i]>= $this->_perPage{
  724.                     $i++;
  725.                 }
  726.             }
  727.         else {
  728.             $this->_pageData array();
  729.         }
  730.  
  731.         //prevent URL modification
  732.         $this->_currentPage = min($this->_currentPage$this->_totalPages);
  733.     }
  734.  
  735.     // }}}
  736.     // {{{ _renderLink()
  737.  
  738.     /**
  739.      * Renders a link using the appropriate method
  740.      *
  741.      * @param altText Alternative text for this link (title property)
  742.      * @param linkText Text contained by this link
  743.      * @return string The link in string form
  744.      * @access private
  745.      */
  746.     function _renderLink($altText$linkText)
  747.     {
  748.         if ($this->_httpMethod == 'GET'{
  749.             if ($this->_append{
  750.                 $href '?' $this->_http_build_query_wrapper($this->_linkData);
  751.             else {
  752.                 $href str_replace('%d'$this->_linkData[$this->_urlVar]$this->_fileName);
  753.             }
  754.             return sprintf('<a href="%s"%s%s%s title="%s">%s</a>',
  755.                            htmlentities($this->_url $href),
  756.                            empty($this->_classString'' ' '.$this->_classString,
  757.                            empty($this->_attributes)  '' ' '.$this->_attributes,
  758.                            empty($this->_accesskey)   '' ' accesskey="'.$this->_linkData[$this->_urlVar].'"',
  759.                            $altText,
  760.                            $linkText
  761.             );
  762.         elseif ($this->_httpMethod == 'POST'{
  763.             return sprintf("<a href='javascript:void(0)' onclick='%s'%s%s%s title='%s'>%s</a>",
  764.                            $this->_generateFormOnClick($this->_url$this->_linkData),
  765.                            empty($this->_classString'' ' '.$this->_classString,
  766.                            empty($this->_attributes)  '' ' '.$this->_attributes,
  767.                            empty($this->_accesskey)   '' ' accesskey=\''.$this->_linkData[$this->_urlVar].'\'',
  768.                            $altText,
  769.                            $linkText
  770.             );
  771.         }
  772.         return '';
  773.     }
  774.  
  775.     // }}}
  776.     // {{{ _generateFormOnClick()
  777.  
  778.     /**
  779.      * Mimics http_build_query() behavior in the way the data
  780.      * in $data will appear when it makes it back to the server.
  781.      *  For example:
  782.      * $arr =  array('array' => array(array('hello', 'world'),
  783.      *                                'things' => array('stuff', 'junk'));
  784.      * http_build_query($arr)
  785.      * and _generateFormOnClick('foo.php', $arr)
  786.      * will yield
  787.      * $_REQUEST['array'][0][0] === 'hello'
  788.      * $_REQUEST['array'][0][1] === 'world'
  789.      * $_REQUEST['array']['things'][0] === 'stuff'
  790.      * $_REQUEST['array']['things'][1] === 'junk'
  791.      *
  792.      * However, instead of  generating a query string, it generates
  793.      * Javascript to create and submit a form.
  794.      *
  795.      * @param string $formAction where the form should be submitted
  796.      * @param array  $data the associative array of names and values
  797.      * @return string A string of javascript that generates a form and submits it
  798.      * @access private
  799.      */
  800.     function _generateFormOnClick($formAction$data)
  801.     {
  802.         // Check we have an array to work with
  803.         if (!is_array($data)) {
  804.             trigger_error(
  805.                 '_generateForm() Parameter 1 expected to be Array or Object. Incorrect value given.',
  806.                 E_USER_WARNING
  807.             );
  808.             return false;
  809.         }
  810.  
  811.         if (!empty($this->_formID)) {
  812.             $str 'var form = document.getElementById("'.$this->_formID.'"); var input = ""; ';
  813.         else {
  814.             $str 'var form = document.createElement("form"); var input = ""; ';
  815.         }
  816.         
  817.         // We /shouldn't/ need to escape the URL ...
  818.         $str .= sprintf('form.action = "%s"; 'htmlentities($formAction));
  819.         $str .= sprintf('form.method = "%s"; '$this->_httpMethod);
  820.         foreach ($data as $key => $val{
  821.             $str .= $this->_generateFormOnClickHelper($val$key);
  822.         }
  823.  
  824.         if (empty($this->_formID)) {
  825.             $str .= 'document.getElementsByTagName("body")[0].appendChild(form);';
  826.         }
  827.         
  828.         $str .= 'form.submit(); return false;';
  829.         return $str;
  830.     }
  831.  
  832.     // }}}
  833.     // {{{ _generateFormOnClickHelper
  834.  
  835.     /**
  836.      * This is used by _generateFormOnClick().
  837.      * Recursively processes the arrays, objects, and literal values.
  838.      *
  839.      * @param data Data that should be rendered
  840.      * @param prev The name so far
  841.      * @return string A string of Javascript that creates form inputs
  842.      *                 representing the data
  843.      * @access private
  844.      */
  845.     function _generateFormOnClickHelper($data$prev '')
  846.     {
  847.         $str '';
  848.         if (is_array($data|| is_object($data)) {
  849.             // foreach key/visible member
  850.             foreach ((array)$data as $key => $val{
  851.                 // append [$key] to prev
  852.                 $tempKey sprintf('%s[%s]'$prev$key);
  853.                 $str .= $this->_generateFormOnClickHelper($val$tempKey);
  854.             }
  855.         else {  // must be a literal value
  856.             // escape newlines and carriage returns
  857.             $search  array("\n""\r");
  858.             $replace array('\n''\n');
  859.             $escapedData str_replace($search$replace$data);
  860.             // am I forgetting any dangerous whitespace?
  861.             // would a regex be faster?
  862.             // if it's already encoded, don't encode it again
  863.             if (!$this->_isEncoded($escapedData)) {
  864.                 $escapedData urlencode($escapedData);
  865.             }
  866.             $escapedData htmlentities($escapedDataENT_QUOTES'UTF-8');
  867.  
  868.             $str .= 'input = document.createElement("input"); ';
  869.             $str .= 'input.type = "hidden"; ';
  870.             $str .= sprintf('input.name = "%s"; '$prev);
  871.             $str .= sprintf('input.value = "%s"; '$escapedData);
  872.             $str .= 'form.appendChild(input); ';
  873.         }
  874.         return $str;
  875.     }
  876.  
  877.     // }}}
  878.     // {{{ _getLinksData()
  879.  
  880.     /**
  881.      * Returns the correct link for the back/pages/next links
  882.      *
  883.      * @return array Data
  884.      * @access private
  885.      */
  886.     function _getLinksData()
  887.     {
  888.         $qs array();
  889.         if ($this->_importQuery{
  890.             if ($this->_httpMethod == 'POST'{
  891.                 $qs $_POST;
  892.             elseif ($this->_httpMethod == 'GET'{
  893.                 $qs $_GET;
  894.             }
  895.         }
  896.         if (count($this->_extraVars)){
  897.             $this->_recursive_urldecode($this->_extraVars);
  898.         }
  899.         $qs array_merge($qs$this->_extraVars);
  900.         foreach ($this->_excludeVars as $exclude{
  901.             if (array_key_exists($exclude$qs)) {
  902.                 unset($qs[$exclude]);
  903.             }
  904.         }
  905.         if (count($qs&& get_magic_quotes_gpc()){
  906.             $this->_recursive_stripslashes($qs);
  907.         }
  908.         return $qs;
  909.     }
  910.  
  911.     // }}}
  912.     // {{{ _recursive_stripslashes()
  913.     
  914.     /**
  915.      * Helper method
  916.      * @param mixed $var 
  917.      * @access private
  918.      */
  919.     function _recursive_stripslashes(&$var)
  920.     {
  921.         if (is_array($var)) {
  922.             foreach (array_keys($varas $k{
  923.                 $this->_recursive_stripslashes($var[$k]);
  924.             }
  925.         else {
  926.             $var stripslashes($var);
  927.         }
  928.     }
  929.  
  930.     // }}}
  931.     // {{{ _recursive_urldecode()
  932.  
  933.     /**
  934.      * Helper method
  935.      * @param mixed $var 
  936.      * @access private
  937.      */
  938.     function _recursive_urldecode(&$var)
  939.     {
  940.         if (is_array($var)) {
  941.             foreach (array_keys($varas $k{
  942.                 $this->_recursive_urldecode($var[$k]);
  943.             }
  944.         else {
  945.             $trans_tbl array_flip(get_html_translation_table(HTML_ENTITIES));
  946.             $var strtr($var$trans_tbl);
  947.         }
  948.     }
  949.  
  950.     // }}}
  951.     // {{{ _getBackLink()
  952.  
  953.     /**
  954.      * Returns back link
  955.      *
  956.      * @param $url  URL to use in the link  [deprecated: use the factory instead]
  957.      * @param $link HTML to use as the link [deprecated: use the factory instead]
  958.      * @return string The link
  959.      * @access private
  960.      */
  961.     function _getBackLink($url=''$link='')
  962.     {
  963.         //legacy settings... the preferred way to set an option
  964.         //now is passing it to the factory
  965.         if (!empty($url)) {
  966.             $this->_path = $url;
  967.         }
  968.         if (!empty($link)) {
  969.             $this->_prevImg = $link;
  970.         }
  971.         $back '';
  972.         if ($this->_currentPage > 1{
  973.             $this->_linkData[$this->_urlVar$this->getPreviousPageID();
  974.             $back $this->_renderLink($this->_altPrev$this->_prevImg)
  975.                   . $this->_spacesBefore . $this->_spacesAfter;
  976.         }
  977.         return $back;
  978.     }
  979.  
  980.     // }}}
  981.     // {{{ _getPageLinks()
  982.  
  983.     /**
  984.      * Returns pages link
  985.      *
  986.      * @param $url  URL to use in the link [deprecated: use the factory instead]
  987.      * @return string Links
  988.      * @access private
  989.      */
  990.     function _getPageLinks($url='')
  991.     {
  992.         $msg '<b>PEAR::Pager Error:</b>'
  993.               .' function "_getPageLinks()" not implemented.';
  994.         return $this->raiseError($msgERROR_PAGER_NOT_IMPLEMENTED);
  995.     }
  996.  
  997.     // }}}
  998.     // {{{ _getNextLink()
  999.  
  1000.     /**
  1001.      * Returns next link
  1002.      *
  1003.      * @param $url  URL to use in the link  [deprecated: use the factory instead]
  1004.      * @param $link HTML to use as the link [deprecated: use the factory instead]
  1005.      * @return string The link
  1006.      * @access private
  1007.      */
  1008.     function _getNextLink($url=''$link='')
  1009.     {
  1010.         //legacy settings... the preferred way to set an option
  1011.         //now is passing it to the factory
  1012.         if (!empty($url)) {
  1013.             $this->_path = $url;
  1014.         }
  1015.         if (!empty($link)) {
  1016.             $this->_nextImg = $link;
  1017.         }
  1018.         $next '';
  1019.         if ($this->_currentPage < $this->_totalPages{
  1020.             $this->_linkData[$this->_urlVar$this->getNextPageID();
  1021.             $next $this->_spacesAfter
  1022.                   . $this->_renderLink($this->_altNext$this->_nextImg)
  1023.                   . $this->_spacesBefore . $this->_spacesAfter;
  1024.         }
  1025.         return $next;
  1026.     }
  1027.  
  1028.     // }}}
  1029.     // {{{ _getFirstLinkTag()
  1030.  
  1031.     /**
  1032.      * @return string 
  1033.      * @access private
  1034.      */
  1035.     function _getFirstLinkTag()
  1036.     {
  1037.         if ($this->isFirstPage(|| ($this->_httpMethod != 'GET')) {
  1038.             return '';
  1039.         }
  1040.         return sprintf('<link rel="first" href="%s" title="%s" />'."\n",
  1041.             $this->_getLinkTagUrl(1),
  1042.             $this->_firstLinkTitle
  1043.         );
  1044.     }
  1045.  
  1046.     // }}}
  1047.     // {{{ _getPrevLinkTag()
  1048.  
  1049.     /**
  1050.      * Returns previous link tag
  1051.      *
  1052.      * @return string the link tag
  1053.      * @access private
  1054.      */
  1055.     function _getPrevLinkTag()
  1056.     {
  1057.         if ($this->isFirstPage(|| ($this->_httpMethod != 'GET')) {
  1058.             return '';
  1059.         }
  1060.         return sprintf('<link rel="previous" href="%s" title="%s" />'."\n",
  1061.             $this->_getLinkTagUrl($this->getPreviousPageID()),
  1062.             $this->_prevLinkTitle
  1063.         );
  1064.     }
  1065.  
  1066.     // }}}
  1067.     // {{{ _getNextLinkTag()
  1068.  
  1069.     /**
  1070.      * Returns next link tag
  1071.      *
  1072.      * @return string the link tag
  1073.      * @access private
  1074.      */
  1075.     function _getNextLinkTag()
  1076.     {
  1077.         if ($this->isLastPage(|| ($this->_httpMethod != 'GET')) {
  1078.             return '';
  1079.         }
  1080.         return sprintf('<link rel="next" href="%s" title="%s" />'."\n",
  1081.             $this->_getLinkTagUrl($this->getNextPageID()),
  1082.             $this->_nextLinkTitle
  1083.         );
  1084.     }
  1085.  
  1086.     // }}}
  1087.     // {{{ _getLastLinkTag()
  1088.  
  1089.     /**
  1090.      * @return string the link tag
  1091.      * @access private
  1092.      */
  1093.     function _getLastLinkTag()
  1094.     {
  1095.         if ($this->isLastPage(|| ($this->_httpMethod != 'GET')) {
  1096.             return '';
  1097.         }
  1098.         return sprintf('<link rel="last" href="%s" title="%s" />'."\n",
  1099.             $this->_getLinkTagUrl($this->_totalPages),
  1100.             $this->_lastLinkTitle
  1101.         );
  1102.     }
  1103.  
  1104.     // }}}
  1105.     // {{{ _getLinkTagUrl()
  1106.  
  1107.     /**
  1108.      * Helper method
  1109.      * @return string the link tag url
  1110.      * @access private
  1111.      */
  1112.     function _getLinkTagUrl($pageID)
  1113.     {
  1114.         $this->_linkData[$this->_urlVar$pageID;
  1115.         if ($this->_append{
  1116.             $href '?' $this->_http_build_query_wrapper($this->_linkData);
  1117.         else {
  1118.             $href str_replace('%d'$this->_linkData[$this->_urlVar]$this->_fileName);
  1119.         }
  1120.         return htmlentities($this->_url $href);
  1121.     }
  1122.     
  1123.     // }}}
  1124.     // {{{ getPerPageSelectBox()
  1125.  
  1126.     /**
  1127.      * Returns a string with a XHTML SELECT menu,
  1128.      * useful for letting the user choose how many items per page should be
  1129.      * displayed. If parameter useSessions is TRUE, this value is stored in
  1130.      * a session var. The string isn't echoed right now so you can use it
  1131.      * with template engines.
  1132.      *
  1133.      * @param integer $start 
  1134.      * @param integer $end 
  1135.      * @param integer $step 
  1136.      * @param boolean $showAllData If true, perPage is set equal to totalItems.
  1137.      * @param array   (or string $optionText for BC reasons)
  1138.      *                 - 'optionText': text to show in each option.
  1139.      *                   Use '%d' where you want to see the number of pages selected.
  1140.      *                 - 'attributes': (html attributes) Tag attributes or
  1141.      *                   HTML attributes (id="foo" pairs), will be inserted in the
  1142.      *                   <select> tag
  1143.      * @return string xhtml select box
  1144.      * @access public
  1145.      */
  1146.     function getPerPageSelectBox($start=5$end=30$step=5$showAllData=false$extraParams=array())
  1147.     {
  1148.         require_once 'Pager/HtmlWidgets.php';
  1149.         $widget =new Pager_HtmlWidgets($this);
  1150.         return $widget->getPerPageSelectBox($start$end$step$showAllData$extraParams);
  1151.     }
  1152.  
  1153.     // }}}
  1154.     // {{{ getPageSelectBox()
  1155.  
  1156.     /**
  1157.      * Returns a string with a XHTML SELECT menu with the page numbers,
  1158.      * useful as an alternative to the links
  1159.      *
  1160.      * @param array   - 'optionText': text to show in each option.
  1161.      *                   Use '%d' where you want to see the number of pages selected.
  1162.      *                 - 'autoSubmit': if TRUE, add some js code to submit the
  1163.      *                   form on the onChange event
  1164.      * @param string   $extraAttributes (html attributes) Tag attributes or
  1165.      *                   HTML attributes (id="foo" pairs), will be inserted in the
  1166.      *                   <select> tag
  1167.      * @return string xhtml select box
  1168.      * @access public
  1169.      */
  1170.     function getPageSelectBox($params array()$extraAttributes '')
  1171.     {
  1172.         require_once 'Pager/HtmlWidgets.php';
  1173.         $widget =new Pager_HtmlWidgets($this);
  1174.         return $widget->getPageSelectBox($params$extraAttributes);
  1175.     }
  1176.  
  1177.     // }}}
  1178.     // {{{ _printFirstPage()
  1179.  
  1180.     /**
  1181.      * Print [1]
  1182.      *
  1183.      * @return string String with link to 1st page,
  1184.      *                 or empty string if this is the 1st page.
  1185.      * @access private
  1186.      */
  1187.     function _printFirstPage()
  1188.     {
  1189.         if ($this->isFirstPage()) {
  1190.             return '';
  1191.         }
  1192.         $this->_linkData[$this->_urlVar1;
  1193.         return $this->_renderLink(
  1194.                 str_replace('%d'1$this->_altFirst),
  1195.                 $this->_firstPagePre . $this->_firstPageText . $this->_firstPagePost
  1196.         $this->_spacesBefore . $this->_spacesAfter;
  1197.     }
  1198.  
  1199.     // }}}
  1200.     // {{{ _printLastPage()
  1201.  
  1202.     /**
  1203.      * Print [numPages()]
  1204.      *
  1205.      * @return string String with link to last page,
  1206.      *                 or empty string if this is the 1st page.
  1207.      * @access private
  1208.      */
  1209.     function _printLastPage()
  1210.     {
  1211.         if ($this->isLastPage()) {
  1212.             return '';
  1213.         }
  1214.         $this->_linkData[$this->_urlVar$this->_totalPages;
  1215.         return $this->_renderLink(
  1216.                 str_replace('%d'$this->_totalPages$this->_altLast),
  1217.                 $this->_lastPagePre . $this->_lastPageText . $this->_lastPagePost
  1218.         );
  1219.     }
  1220.  
  1221.     // }}}
  1222.     // {{{ _setFirstLastText()
  1223.  
  1224.     /**
  1225.      * sets the private _firstPageText, _lastPageText variables
  1226.      * based on whether they were set in the options
  1227.      *
  1228.      * @access private
  1229.      */
  1230.     function _setFirstLastText()
  1231.     {
  1232.         if ($this->_firstPageText == ''{
  1233.             $this->_firstPageText = '1';
  1234.         }
  1235.         if ($this->_lastPageText == ''{
  1236.             $this->_lastPageText = $this->_totalPages;
  1237.         }
  1238.     }
  1239.  
  1240.     // }}}
  1241.     // {{{ _http_build_query_wrapper()
  1242.     
  1243.     /**
  1244.      * This is a slightly modified version of the http_build_query() function;
  1245.      * it heavily borrows code from PHP_Compat's http_build_query().
  1246.      * The main change is the usage of htmlentities instead of urlencode,
  1247.      * since it's too aggressive
  1248.      *
  1249.      * @author Stephan Schmidt <schst@php.net>
  1250.      * @author Aidan Lister <aidan@php.net>
  1251.      * @author Lorenzo Alberton <l dot alberton at quipo dot it>
  1252.      * @param array $data 
  1253.      * @return string 
  1254.      * @access private
  1255.      */
  1256.     function _http_build_query_wrapper($data)
  1257.     {
  1258.         $data = (array)$data;
  1259.         if (empty($data)) {
  1260.             return '';
  1261.         }
  1262.         $separator ini_get('arg_separator.output');
  1263.         if ($separator == '&amp;'{
  1264.             $separator '&'//the string is escaped by htmlentities anyway...
  1265.         }
  1266.         $tmp array ();
  1267.         foreach ($data as $key => $val{
  1268.             if (is_scalar($val)) {
  1269.                 //array_push($tmp, $key.'='.$val);
  1270.                 $val urlencode($val);
  1271.                 array_push($tmp$key .'='str_replace('%2F''/'$val));
  1272.                 continue;
  1273.             }
  1274.             // If the value is an array, recursively parse it
  1275.             if (is_array($val)) {
  1276.                 array_push($tmp$this->__http_build_query($valhtmlentities($key)));
  1277.                 continue;
  1278.             }
  1279.         }
  1280.         return implode($separator$tmp);
  1281.     }
  1282.  
  1283.     // }}}
  1284.     // {{{ __http_build_query()
  1285.  
  1286.     /**
  1287.      * Helper function
  1288.      * @author Stephan Schmidt <schst@php.net>
  1289.      * @author Aidan Lister <aidan@php.net>
  1290.      * @access private
  1291.      */
  1292.     function __http_build_query($array$name)
  1293.     {
  1294.         $tmp array ();
  1295.         $separator ini_get('arg_separator.output');
  1296.         if ($separator == '&amp;'{
  1297.             $separator '&'//the string is escaped by htmlentities anyway...
  1298.         }
  1299.         foreach ($array as $key => $value{
  1300.             if (is_array($value)) {
  1301.                 //array_push($tmp, $this->__http_build_query($value, sprintf('%s[%s]', $name, $key)));
  1302.                 array_push($tmp$this->__http_build_query($value$name.'%5B'.$key.'%5D'));
  1303.             elseif (is_scalar($value)) {
  1304.                 //array_push($tmp, sprintf('%s[%s]=%s', $name, htmlentities($key), htmlentities($value)));
  1305.                 array_push($tmp$name.'%5B'.htmlentities($key).'%5D='.htmlentities($value));
  1306.             elseif (is_object($value)) {
  1307.                 //array_push($tmp, $this->__http_build_query(get_object_vars($value), sprintf('%s[%s]', $name, $key)));
  1308.                 array_push($tmp$this->__http_build_query(get_object_vars($value)$name.'%5B'.$key.'%5D'));
  1309.             }
  1310.         }
  1311.         return implode($separator$tmp);
  1312.     }
  1313.  
  1314.     // }}}
  1315.     // {{{ _isEncoded()
  1316.  
  1317.     /**
  1318.      * Helper function
  1319.      * Check if a string is an encoded multibyte string
  1320.      * @param string $string 
  1321.      * @return boolean 
  1322.      * @access private
  1323.      */
  1324.     
  1325.     function _isEncoded($string)
  1326.     {
  1327.         $hexchar '&#[\dA-Fx]{2,};';
  1328.         return preg_match("/^(\s|($hexchar))*$/Uims"$stringtrue false;
  1329.     }
  1330.  
  1331.     // }}}
  1332.     // {{{ raiseError()
  1333.  
  1334.     /**
  1335.      * conditionally includes PEAR base class and raise an error
  1336.      *
  1337.      * @param string $msg  Error message
  1338.      * @param int    $code Error code
  1339.      * @access private
  1340.      */
  1341.     function raiseError($msg$code)
  1342.     {
  1343.         include_once 'PEAR.php';
  1344.         if (empty($this->_pearErrorMode)) {
  1345.             $this->_pearErrorMode = PEAR_ERROR_RETURN;
  1346.         }
  1347.         return PEAR::raiseError($msg$code$this->_pearErrorMode);
  1348.     }
  1349.  
  1350.     // }}}
  1351.     // {{{ setOptions()
  1352.  
  1353.     /**
  1354.      * Set and sanitize options
  1355.      *
  1356.      * @param mixed $options    An associative array of option names and
  1357.      *                           their values.
  1358.      * @return integer error code (PAGER_OK on success)
  1359.      * @access public
  1360.      */
  1361.     function setOptions($options)
  1362.     {
  1363.         foreach ($options as $key => $value{
  1364.             if (in_array($key$this->_allowed_options&& (!is_null($value))) {
  1365.                 $this->{'_' $key$value;
  1366.             }
  1367.         }
  1368.  
  1369.         //autodetect http method
  1370.         if (!isset($options['httpMethod'])
  1371.             && !isset($_GET[$this->_urlVar])
  1372.             && isset($_POST[$this->_urlVar])
  1373.         {
  1374.             $this->_httpMethod 'POST';
  1375.         else {
  1376.             $this->_httpMethod strtoupper($this->_httpMethod);
  1377.         }
  1378.  
  1379.         $this->_fileName ltrim($this->_fileName'/');  //strip leading slash
  1380.         $this->_path     rtrim($this->_path'/');      //strip trailing slash
  1381.  
  1382.         if ($this->_append{
  1383.             if ($this->_fixFileName{
  1384.                 $this->_fileName CURRENT_FILENAME//avoid possible user error;
  1385.             }
  1386.             $this->_url $this->_path.'/'.$this->_fileName;
  1387.         else {
  1388.             $this->_url $this->_path;
  1389.             if (strncasecmp($this->_fileName'javascript'10!= 0{
  1390.                 $this->_url .= '/';
  1391.             }
  1392.             if (!strstr($this->_fileName'%d')) {
  1393.                 trigger_error($this->errorMessage(ERROR_PAGER_INVALID_USAGE)E_USER_WARNING);
  1394.             }
  1395.         }
  1396.  
  1397.         $this->_classString '';
  1398.         if (strlen($this->_linkClass)) {
  1399.             $this->_classString 'class="'.$this->_linkClass.'"';
  1400.         }
  1401.  
  1402.         if (strlen($this->_curPageLinkClassName)) {
  1403.             $this->_curPageSpanPre  '<span class="'.$this->_curPageLinkClassName.'">';
  1404.             $this->_curPageSpanPost '</span>';
  1405.         }
  1406.  
  1407.         $this->_perPage max($this->_perPage1)//avoid possible user errors
  1408.  
  1409.         if ($this->_useSessions && !isset($_SESSION)) {
  1410.             session_start();
  1411.         }
  1412.         if (!empty($_REQUEST[$this->_sessionVar])) {
  1413.             $this->_perPage max(1(int)$_REQUEST[$this->_sessionVar]);
  1414.             if ($this->_useSessions{
  1415.                 $_SESSION[$this->_sessionVar$this->_perPage;
  1416.             }
  1417.         }
  1418.  
  1419.         if (!empty($_SESSION[$this->_sessionVar])) {
  1420.              $this->_perPage $_SESSION[$this->_sessionVar];
  1421.         }
  1422.  
  1423.         if ($this->_closeSession{
  1424.             session_write_close();
  1425.         }
  1426.  
  1427.         $this->_spacesBefore str_repeat('&nbsp;'$this->_spacesBeforeSeparator);
  1428.         $this->_spacesAfter  str_repeat('&nbsp;'$this->_spacesAfterSeparator);
  1429.  
  1430.         if (isset($_REQUEST[$this->_urlVar]&& empty($options['currentPage'])) {
  1431.             $this->_currentPage = (int)$_REQUEST[$this->_urlVar];
  1432.         }
  1433.         $this->_currentPage max($this->_currentPage1);
  1434.         $this->_linkData $this->_getLinksData();
  1435.  
  1436.         return PAGER_OK;
  1437.     }
  1438.  
  1439.     // }}}
  1440.     // {{{ getOption()
  1441.     
  1442.     /**
  1443.      * Return the current value of a given option
  1444.      *
  1445.      * @param string option name
  1446.      * @return mixed option value
  1447.      */
  1448.     function getOption($name)
  1449.     {
  1450.         if (!in_array($name$this->_allowed_options)) {
  1451.             $msg '<b>PEAR::Pager Error:</b>'
  1452.                   .' invalid option: '.$name;
  1453.             return $this->raiseError($msgERROR_PAGER_INVALID);
  1454.         }
  1455.         return $this->{'_' $name};
  1456.     }
  1457.  
  1458.     // }}}
  1459.     // {{{ getOptions()
  1460.  
  1461.     /**
  1462.      * Return an array with all the current pager options
  1463.      *
  1464.      * @return array list of all the pager options
  1465.      */
  1466.     function getOptions()
  1467.     {
  1468.         $options array();
  1469.         foreach ($this->_allowed_options as $option{
  1470.             $options[$option$this->{'_' $option};
  1471.         }
  1472.         return $options;
  1473.     }
  1474.  
  1475.     // }}}
  1476.     // {{{ errorMessage()
  1477.  
  1478.     /**
  1479.      * Return a textual error message for a PAGER error code
  1480.      *
  1481.      * @param   int     $code error code
  1482.      * @return  string  error message
  1483.      * @access public
  1484.      */
  1485.     function errorMessage($code)
  1486.     {
  1487.         static $errorMessages;
  1488.         if (!isset($errorMessages)) {
  1489.             $errorMessages array(
  1490.                 ERROR_PAGER                     => 'unknown error',
  1491.                 ERROR_PAGER_INVALID             => 'invalid',
  1492.                 ERROR_PAGER_INVALID_PLACEHOLDER => 'invalid format - use "%d" as placeholder.',
  1493.                 ERROR_PAGER_INVALID_USAGE       => 'if $options[\'append\'] is set to false, '
  1494.                                                   .' $options[\'fileName\'] MUST contain the "%d" placeholder.',
  1495.                 ERROR_PAGER_NOT_IMPLEMENTED     => 'not implemented'
  1496.             );
  1497.         }
  1498.  
  1499.         return '<b>PEAR::Pager error:</b> '(isset($errorMessages[$code]?
  1500.             $errorMessages[$code$errorMessages[ERROR_PAGER]);
  1501.     }
  1502.  
  1503.     // }}}
  1504. }
  1505. ?>

Documentation generated on Thu, 12 Jun 2008 13:08:32 -0500 by phpDocumentor 1.4.1