PageRenderTime 24ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/s3db3.5.10/pearlib/Pager/Pager.php

https://code.google.com/p/s3db/
PHP | 173 lines | 25 code | 5 blank | 143 comment | 3 complexity | 46c7342e7d1f353cf20a479741a7e41a MD5 | raw file
  1. <?php
  2. // +-----------------------------------------------------------------------+
  3. // | Copyright (c) 2002-2003, Richard Heyes |
  4. // | All rights reserved. |
  5. // | |
  6. // | Redistribution and use in source and binary forms, with or without |
  7. // | modification, are permitted provided that the following conditions |
  8. // | are met: |
  9. // | |
  10. // | o Redistributions of source code must retain the above copyright |
  11. // | notice, this list of conditions and the following disclaimer. |
  12. // | o 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. // | o The names of the authors may not be used to endorse or promote |
  16. // | products derived from this software without specific prior written |
  17. // | permission. |
  18. // | |
  19. // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
  20. // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
  21. // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
  22. // | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
  23. // | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
  24. // | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
  25. // | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
  26. // | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
  27. // | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
  28. // | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
  29. // | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
  30. // | |
  31. // +-----------------------------------------------------------------------+
  32. // | Authors: Richard Heyes <richard@phpguru.org> |
  33. // | Lorenzo Alberton <l.alberton at quipo.it> |
  34. // +-----------------------------------------------------------------------+
  35. //
  36. // $Id: Pager.php,v 1.15 2004/09/08 16:33:06 quipo Exp $
  37. /**
  38. * File Pager.php
  39. *
  40. * @package Pager
  41. */
  42. /**
  43. * Pager - Wrapper class for [Sliding|Jumping]-window Pager
  44. *
  45. * Usage examples can be found in the doc provided
  46. *
  47. * @author Richard Heyes <richard@phpguru.org>,
  48. * @author Lorenzo Alberton <l.alberton at quipo.it>
  49. * @version $Id: Pager.php,v 1.15 2004/09/08 16:33:06 quipo Exp $
  50. * @package Pager
  51. */
  52. class Pager
  53. {
  54. // {{{ Pager()
  55. /**
  56. * Constructor
  57. *
  58. * -------------------------------------------------------------------------
  59. * VALID options are (default values are set some lines before):
  60. * - mode (string): "Jumping" or "Sliding" -window - It determines
  61. * pager behaviour. See the manual for more details
  62. * - totalItems (int): # of items to page.
  63. * - perPage (int): # of items per page.
  64. * - delta (int): # of page #s to show before and after the current
  65. * one
  66. * - linkClass (string): name of CSS class used for link styling.
  67. * - append (bool): if true pageID is appended as GET value to the
  68. * URL - if false it is embedded in the URL
  69. * according to "fileName" specs
  70. * - path (string): complete path to the page (without the page name)
  71. * - fileName (string): name of the page, with a %d if append=true
  72. * - urlVar (string): name of pageNumber URL var, for example "pageID"
  73. * - altPrev (string): alt text to display for prev page, on prev link.
  74. * - altNext (string): alt text to display for next page, on next link.
  75. * - altPage (string): alt text to display before the page number.
  76. * - prevImg (string): sth (it can be text such as "<< PREV" or an
  77. * <img/> as well...) to display instead of "<<".
  78. * - nextImg (string): same as prevImg, used for NEXT link, instead of
  79. * the default value, which is ">>".
  80. * - separator (string): what to use to separate numbers (can be an
  81. * <img/>, a comma, an hyphen, or whatever.
  82. * - spacesBeforeSeparator
  83. * (int): number of spaces before the separator.
  84. * - firstPagePre (string):
  85. * string used before first page number (can be an
  86. * <img/>, a "{", an empty string, or whatever.
  87. * - firstPageText (string):
  88. * string used in place of first page number
  89. * - firstPagePost (string):
  90. * string used after first page number (can be an
  91. * <img/>, a "}", an empty string, or whatever.
  92. * - lastPagePre (string):
  93. * similar to firstPagePre.
  94. * - lastPageText (string):
  95. * similar to firstPageText.
  96. * - lastPagePost (string):
  97. * similar to firstPagePost.
  98. * - spacesAfterSeparator
  99. * (int): number of spaces after the separator.
  100. * - firstLinkTitle (string):
  101. * string used as title in <link rel="first"> tag
  102. * - lastLinkTitle (string):
  103. * string used as title in <link rel="last"> tag
  104. * - prevLinkTitle (string):
  105. * string used as title in <link rel="prev"> tag
  106. * - nextLinkTitle (string):
  107. * string used as title in <link rel="next"> tag
  108. * - curPageLinkClassName
  109. * (string): name of CSS class used for current page link.
  110. * - clearIfVoid(bool): if there's only one page, don't display pager.
  111. * - extraVars (array): additional URL vars to be added to the querystring
  112. * - itemData (array): array of items to page.
  113. * - useSessions (bool): if true, number of items to display per page is
  114. * stored in the $_SESSION[$_sessionVar] var.
  115. * - closeSession (bool): if true, the session is closed just after R/W.
  116. * - sessionVar (string): name of the session var for perPage value.
  117. * A value != from default can be useful when
  118. * using more than one Pager istance in the page.
  119. * - pearErrorMode (constant):
  120. * PEAR_ERROR mode for raiseError().
  121. * Default is PEAR_ERROR_RETURN.
  122. * -------------------------------------------------------------------------
  123. * REQUIRED options are:
  124. * - fileName IF append==false (default is true)
  125. * - itemData OR totalItems (if itemData is set, totalItems is overwritten)
  126. * -------------------------------------------------------------------------
  127. *
  128. * @param mixed $options An associative array of option names and
  129. * their values.
  130. * @access public
  131. */
  132. function Pager($options = array())
  133. {
  134. //this check evaluates to true on 5.0.0RC-dev,
  135. //so i'm using another one, for now...
  136. //if (version_compare(phpversion(), '5.0.0') == -1) {
  137. if (get_class($this) == 'pager') { //php4 lowers class names
  138. // assign factoried method to this for PHP 4
  139. eval('$this = Pager::factory($options);');
  140. } else { //php5 is case sensitive
  141. $msg = 'Pager constructor is deprecated.'
  142. .' You must use the "Pager::factory($params)" method'
  143. .' instead of "new Pager($params)"';
  144. trigger_error($msg, E_USER_ERROR);
  145. }
  146. }
  147. // }}}
  148. // {{{ factory()
  149. /**
  150. * Return a pager based on $mode and $options
  151. *
  152. * @access public
  153. * @static
  154. * @param string $options Optional parameters for the storage class
  155. * @return object Object Storage object
  156. */
  157. function &factory($options = array())
  158. {
  159. $mode = (isset($options['mode']) ? ucfirst($options['mode']) : 'Jumping');
  160. $classname = 'Pager_' . $mode;
  161. $classfile = 'Pager' . DIRECTORY_SEPARATOR . $mode . '.php';
  162. require_once $classfile;
  163. $pager =& new $classname($options);
  164. return $pager;
  165. }
  166. // }}}
  167. }
  168. ?>