Pager.php 8.3 KB

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