Pager.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3. /**
  4. * Contains the Pager class
  5. *
  6. * PHP versions 4 and 5
  7. *
  8. * LICENSE: Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. The name of the author may not be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
  19. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  20. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  21. * IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * @category HTML
  30. * @package Pager
  31. * @author Lorenzo Alberton <l.alberton@quipo.it>
  32. * @author Richard Heyes <richard@phpguru.org>
  33. * @copyright 2003-2008 Lorenzo Alberton, Richard Heyes
  34. * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
  35. * @version CVS: $Id: Pager.php,v 1.26 2008/02/02 16:55:04 quipo Exp $
  36. * @link http://pear.php.net/package/Pager
  37. */
  38. /**
  39. * Pager - Wrapper class for [Sliding|Jumping]-window Pager
  40. * Usage examples can be found in the PEAR manual
  41. *
  42. * @category HTML
  43. * @package Pager
  44. * @author Lorenzo Alberton <l.alberton@quipo.it>
  45. * @author Richard Heyes <richard@phpguru.org>
  46. * @copyright 2003-2008 Lorenzo Alberton, Richard Heyes
  47. * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
  48. * @link http://pear.php.net/package/Pager
  49. */
  50. class Pager
  51. {
  52. // {{{ Pager()
  53. /**
  54. * Constructor
  55. *
  56. * -------------------------------------------------------------------------
  57. * VALID options are (default values are set some lines before):
  58. * - mode (string): "Jumping" or "Sliding" -window - It determines
  59. * pager behaviour. See the manual for more details
  60. * - totalItems (int): # of items to page.
  61. * - perPage (int): # of items per page.
  62. * - delta (int): # of page #s to show before and after the current
  63. * one
  64. * - linkClass (string): name of CSS class used for link styling.
  65. * - append (bool): if true pageID is appended as GET value to the
  66. * URL - if false it is embedded in the URL
  67. * according to "fileName" specs
  68. * - httpMethod (string): Specifies the HTTP method to use. Valid values
  69. * are 'GET' or 'POST'
  70. * according to "fileName" specs
  71. * - importQuery (bool): if true (default behaviour), variables and
  72. * values are imported from the submitted data
  73. * (query string) and used in the generated links
  74. * otherwise they're ignored completely
  75. * - path (string): complete path to the page (without the page name)
  76. * - fileName (string): name of the page, with a %d if append=true
  77. * - urlVar (string): name of pageNumber URL var, for example "pageID"
  78. * - altPrev (string): alt text to display for prev page, on prev link.
  79. * - altNext (string): alt text to display for next page, on next link.
  80. * - altPage (string): alt text to display before the page number.
  81. * - prevImg (string): sth (it can be text such as "<< PREV" or an
  82. * <img/> as well...) to display instead of "<<".
  83. * - nextImg (string): same as prevImg, used for NEXT link, instead of
  84. * the default value, which is ">>".
  85. * - separator (string): what to use to separate numbers (can be an
  86. * <img/>, a comma, an hyphen, or whatever.
  87. * - spacesBeforeSeparator
  88. * (int): number of spaces before the separator.
  89. * - firstPagePre (string):
  90. * string used before first page number (can be an
  91. * <img/>, a "{", an empty string, or whatever.
  92. * - firstPageText (string):
  93. * string used in place of first page number
  94. * - firstPagePost (string):
  95. * string used after first page number (can be an
  96. * <img/>, a "}", an empty string, or whatever.
  97. * - lastPagePre (string):
  98. * similar to firstPagePre.
  99. * - lastPageText (string):
  100. * similar to firstPageText.
  101. * - lastPagePost (string):
  102. * similar to firstPagePost.
  103. * - spacesAfterSeparator
  104. * (int): number of spaces after the separator.
  105. * - firstLinkTitle (string):
  106. * string used as title in <link rel="first"> tag
  107. * - lastLinkTitle (string):
  108. * string used as title in <link rel="last"> tag
  109. * - prevLinkTitle (string):
  110. * string used as title in <link rel="prev"> tag
  111. * - nextLinkTitle (string):
  112. * string used as title in <link rel="next"> tag
  113. * - curPageLinkClassName
  114. * (string): name of CSS class used for current page link.
  115. * - clearIfVoid(bool): if there's only one page, don't display pager.
  116. * - extraVars (array): additional URL vars to be added to the querystring
  117. * - excludeVars (array): URL vars to be excluded in the querystring
  118. * - itemData (array): array of items to page.
  119. * - useSessions (bool): if true, number of items to display per page is
  120. * stored in the $_SESSION[$_sessionVar] var.
  121. * - closeSession (bool): if true, the session is closed just after R/W.
  122. * - sessionVar (string): name of the session var for perPage value.
  123. * A value != from default can be useful when
  124. * using more than one Pager istance in the page.
  125. * - pearErrorMode (constant):
  126. * PEAR_ERROR mode for raiseError().
  127. * Default is PEAR_ERROR_RETURN.
  128. * -------------------------------------------------------------------------
  129. * REQUIRED options are:
  130. * - fileName IF append==false (default is true)
  131. * - itemData OR totalItems (if itemData is set, totalItems is overwritten)
  132. * -------------------------------------------------------------------------
  133. *
  134. * @param mixed $options Associative array of option names and their values
  135. *
  136. * @access public
  137. */
  138. public function __construct($options = array())
  139. {
  140. }
  141. // }}}
  142. // {{{ factory()
  143. /**
  144. * Return a pager based on $mode and $options
  145. *
  146. * @param array $options Optional parameters for the storage class
  147. *
  148. * @return object Storage object
  149. * @static
  150. * @access public
  151. */
  152. static function &factory($options = array())
  153. {
  154. $mode = (isset($options['mode']) ? ucfirst($options['mode']) : 'Jumping');
  155. $classname = 'Pager_' . $mode;
  156. $classfile = 'Pager' . DIRECTORY_SEPARATOR . $mode . '.php';
  157. // Attempt to include a custom version of the named class, but don't treat
  158. // a failure as fatal. The caller may have already included their own
  159. // version of the named class.
  160. if (!class_exists($classname)) {
  161. include_once $classfile;
  162. }
  163. // If the class exists, return a new instance of it.
  164. if (class_exists($classname)) {
  165. $pager = new $classname($options);
  166. return $pager;
  167. }
  168. $null = null;
  169. return $null;
  170. }
  171. // }}}
  172. }
  173. ?>