6 |
jpm |
1 |
<?php
|
|
|
2 |
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
|
|
3 |
|
|
|
4 |
/**
|
|
|
5 |
* Contains the Pager 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: Pager.php 19 2010-03-24 18:22:25Z jpm $
|
|
|
37 |
* @link http://pear.php.net/package/Pager
|
|
|
38 |
*/
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
* Pager - Wrapper class for [Sliding|Jumping]-window Pager
|
|
|
42 |
* Usage examples can be found in the PEAR manual
|
|
|
43 |
*
|
|
|
44 |
* @category HTML
|
|
|
45 |
* @package Pager
|
|
|
46 |
* @author Lorenzo Alberton <l dot alberton at quipo dot it>
|
|
|
47 |
* @author Richard Heyes <richard@phpguru.org>,
|
|
|
48 |
* @copyright 2003-2005 Lorenzo Alberton, Richard Heyes
|
|
|
49 |
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
|
|
50 |
* @link http://pear.php.net/package/Pager
|
|
|
51 |
*/
|
|
|
52 |
class Pager
|
|
|
53 |
{
|
|
|
54 |
// {{{ Pager()
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
* Constructor
|
|
|
58 |
*
|
|
|
59 |
* -------------------------------------------------------------------------
|
|
|
60 |
* VALID options are (default values are set some lines before):
|
|
|
61 |
* - mode (string): "Jumping" or "Sliding" -window - It determines
|
|
|
62 |
* pager behaviour. See the manual for more details
|
|
|
63 |
* - totalItems (int): # of items to page.
|
|
|
64 |
* - perPage (int): # of items per page.
|
|
|
65 |
* - delta (int): # of page #s to show before and after the current
|
|
|
66 |
* one
|
|
|
67 |
* - linkClass (string): name of CSS class used for link styling.
|
|
|
68 |
* - append (bool): if true pageID is appended as GET value to the
|
|
|
69 |
* URL - if false it is embedded in the URL
|
|
|
70 |
* according to "fileName" specs
|
|
|
71 |
* - httpMethod (string): Specifies the HTTP method to use. Valid values
|
|
|
72 |
* are 'GET' or 'POST'
|
|
|
73 |
* according to "fileName" specs
|
|
|
74 |
* - importQuery (bool): if true (default behaviour), variables and
|
|
|
75 |
* values are imported from the submitted data
|
|
|
76 |
* (query string) and used in the generated links
|
|
|
77 |
* otherwise they're ignored completely
|
|
|
78 |
* - path (string): complete path to the page (without the page name)
|
|
|
79 |
* - fileName (string): name of the page, with a %d if append=true
|
|
|
80 |
* - urlVar (string): name of pageNumber URL var, for example "pageID"
|
|
|
81 |
* - altPrev (string): alt text to display for prev page, on prev link.
|
|
|
82 |
* - altNext (string): alt text to display for next page, on next link.
|
|
|
83 |
* - altPage (string): alt text to display before the page number.
|
|
|
84 |
* - prevImg (string): sth (it can be text such as "<< PREV" or an
|
|
|
85 |
* <img/> as well...) to display instead of "<<".
|
|
|
86 |
* - nextImg (string): same as prevImg, used for NEXT link, instead of
|
|
|
87 |
* the default value, which is ">>".
|
|
|
88 |
* - separator (string): what to use to separate numbers (can be an
|
|
|
89 |
* <img/>, a comma, an hyphen, or whatever.
|
|
|
90 |
* - spacesBeforeSeparator
|
|
|
91 |
* (int): number of spaces before the separator.
|
|
|
92 |
* - firstPagePre (string):
|
|
|
93 |
* string used before first page number (can be an
|
|
|
94 |
* <img/>, a "{", an empty string, or whatever.
|
|
|
95 |
* - firstPageText (string):
|
|
|
96 |
* string used in place of first page number
|
|
|
97 |
* - firstPagePost (string):
|
|
|
98 |
* string used after first page number (can be an
|
|
|
99 |
* <img/>, a "}", an empty string, or whatever.
|
|
|
100 |
* - lastPagePre (string):
|
|
|
101 |
* similar to firstPagePre.
|
|
|
102 |
* - lastPageText (string):
|
|
|
103 |
* similar to firstPageText.
|
|
|
104 |
* - lastPagePost (string):
|
|
|
105 |
* similar to firstPagePost.
|
|
|
106 |
* - spacesAfterSeparator
|
|
|
107 |
* (int): number of spaces after the separator.
|
|
|
108 |
* - firstLinkTitle (string):
|
|
|
109 |
* string used as title in <link rel="first"> tag
|
|
|
110 |
* - lastLinkTitle (string):
|
|
|
111 |
* string used as title in <link rel="last"> tag
|
|
|
112 |
* - prevLinkTitle (string):
|
|
|
113 |
* string used as title in <link rel="prev"> tag
|
|
|
114 |
* - nextLinkTitle (string):
|
|
|
115 |
* string used as title in <link rel="next"> tag
|
|
|
116 |
* - curPageLinkClassName
|
|
|
117 |
* (string): name of CSS class used for current page link.
|
|
|
118 |
* - clearIfVoid(bool): if there's only one page, don't display pager.
|
|
|
119 |
* - extraVars (array): additional URL vars to be added to the querystring
|
|
|
120 |
* - excludeVars (array): URL vars to be excluded in the querystring
|
|
|
121 |
* - itemData (array): array of items to page.
|
|
|
122 |
* - useSessions (bool): if true, number of items to display per page is
|
|
|
123 |
* stored in the $_SESSION[$_sessionVar] var.
|
|
|
124 |
* - closeSession (bool): if true, the session is closed just after R/W.
|
|
|
125 |
* - sessionVar (string): name of the session var for perPage value.
|
|
|
126 |
* A value != from default can be useful when
|
|
|
127 |
* using more than one Pager istance in the page.
|
|
|
128 |
* - pearErrorMode (constant):
|
|
|
129 |
* PEAR_ERROR mode for raiseError().
|
|
|
130 |
* Default is PEAR_ERROR_RETURN.
|
|
|
131 |
* -------------------------------------------------------------------------
|
|
|
132 |
* REQUIRED options are:
|
|
|
133 |
* - fileName IF append==false (default is true)
|
|
|
134 |
* - itemData OR totalItems (if itemData is set, totalItems is overwritten)
|
|
|
135 |
* -------------------------------------------------------------------------
|
|
|
136 |
*
|
|
|
137 |
* @param mixed $options An associative array of option names and
|
|
|
138 |
* their values.
|
|
|
139 |
* @access public
|
|
|
140 |
*/
|
|
|
141 |
function Pager($options = array())
|
|
|
142 |
{
|
|
|
143 |
//this check evaluates to true on 5.0.0RC-dev,
|
|
|
144 |
//so i'm using another one, for now...
|
|
|
145 |
//if (version_compare(phpversion(), '5.0.0') == -1) {
|
|
|
146 |
if (get_class($this) == 'pager') { //php4 lowers class names
|
|
|
147 |
// assign factoried method to this for PHP 4
|
|
|
148 |
eval('$this = Pager::factory($options);');
|
|
|
149 |
} else { //php5 is case sensitive
|
|
|
150 |
$msg = 'Pager constructor is deprecated.'
|
|
|
151 |
.' You must use the "Pager::factory($params)" method'
|
|
|
152 |
.' instead of "new Pager($params)"';
|
|
|
153 |
trigger_error($msg, E_USER_ERROR);
|
|
|
154 |
}
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
// }}}
|
|
|
158 |
// {{{ factory()
|
|
|
159 |
|
|
|
160 |
/**
|
|
|
161 |
* Return a pager based on $mode and $options
|
|
|
162 |
*
|
|
|
163 |
* @param array $options Optional parameters for the storage class
|
|
|
164 |
* @return object Object Storage object
|
|
|
165 |
* @static
|
|
|
166 |
* @access public
|
|
|
167 |
*/
|
|
|
168 |
static function &factory($options = array())
|
|
|
169 |
{
|
|
|
170 |
$mode = (isset($options['mode']) ? ucfirst($options['mode']) : 'Jumping');
|
|
|
171 |
$classname = 'Pager_' . $mode;
|
|
|
172 |
$classfile = 'Pager' . DIRECTORY_SEPARATOR . $mode . '.php';
|
|
|
173 |
|
|
|
174 |
// Attempt to include a custom version of the named class, but don't treat
|
|
|
175 |
// a failure as fatal. The caller may have already included their own
|
|
|
176 |
// version of the named class.
|
|
|
177 |
if (!class_exists($classname)) {
|
|
|
178 |
include_once $classfile;
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
// If the class exists, return a new instance of it.
|
|
|
182 |
if (class_exists($classname)) {
|
|
|
183 |
$pager = new $classname($options);
|
|
|
184 |
return $pager;
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
$null = null;
|
|
|
188 |
return $null;
|
|
|
189 |
}
|
|
|
190 |
|
|
|
191 |
// }}}
|
|
|
192 |
}
|
|
|
193 |
?>
|