@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | private $pagination; |
54 | 54 | |
55 | 55 | /** |
56 | - * @param $mode |
|
56 | + * @param string $mode |
|
57 | 57 | * @param array $config |
58 | 58 | * @return $this |
59 | 59 | */ |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | /** |
69 | 69 | * Total items |
70 | 70 | * |
71 | - * @param $value |
|
71 | + * @param integer $value |
|
72 | 72 | * @return $this |
73 | 73 | */ |
74 | 74 | public function items($value) |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | /** |
108 | 108 | * Current page |
109 | 109 | * |
110 | - * @param $value |
|
110 | + * @param integer $value |
|
111 | 111 | * @return $this |
112 | 112 | */ |
113 | 113 | public function currentPage($value) |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | |
283 | 283 | /** |
284 | 284 | * @param $id |
285 | - * @return mixed|string |
|
285 | + * @return string |
|
286 | 286 | */ |
287 | 287 | public function get_pagenum_link($id) |
288 | 288 | { |
@@ -415,8 +415,8 @@ discard block |
||
415 | 415 | } |
416 | 416 | |
417 | 417 | /** |
418 | - * @param $tpl |
|
419 | - * @param $num |
|
418 | + * @param string $tpl |
|
419 | + * @param integer $num |
|
420 | 420 | * @return mixed |
421 | 421 | */ |
422 | 422 | protected function renderItemTPL($tpl, $num) |
@@ -3,8 +3,8 @@ discard block |
||
3 | 3 | /** |
4 | 4 | * Class DLpaginate |
5 | 5 | */ |
6 | -class DLpaginate |
|
7 | -{ |
|
6 | +class DLpaginate |
|
7 | +{ |
|
8 | 8 | /** |
9 | 9 | * Script Name: *Digg Style Paginator Class |
10 | 10 | * Script URI: http://www.mis-algoritmos.com/2007/05/27/digg-style-pagination-class/ |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | * @param array $config |
58 | 58 | * @return $this |
59 | 59 | */ |
60 | - public function setMode($mode, array $config = array()) |
|
61 | - { |
|
60 | + public function setMode($mode, array $config = array()) |
|
61 | + { |
|
62 | 62 | $this->mode = $mode; |
63 | 63 | $this->modeConfig = $config; |
64 | 64 | |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | * @param $value |
72 | 72 | * @return $this |
73 | 73 | */ |
74 | - public function items($value) |
|
75 | - { |
|
74 | + public function items($value) |
|
75 | + { |
|
76 | 76 | $this->total_pages = (int)$value; |
77 | 77 | |
78 | 78 | return $this; |
@@ -84,8 +84,8 @@ discard block |
||
84 | 84 | * @param $value |
85 | 85 | * @return $this |
86 | 86 | */ |
87 | - public function limit($value) |
|
88 | - { |
|
87 | + public function limit($value) |
|
88 | + { |
|
89 | 89 | $this->limit = (int)$value; |
90 | 90 | |
91 | 91 | return $this; |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | * @param $value |
98 | 98 | * @return $this |
99 | 99 | */ |
100 | - public function target($value) |
|
101 | - { |
|
100 | + public function target($value) |
|
101 | + { |
|
102 | 102 | $this->target = $value; |
103 | 103 | |
104 | 104 | return $this; |
@@ -110,8 +110,8 @@ discard block |
||
110 | 110 | * @param $value |
111 | 111 | * @return $this |
112 | 112 | */ |
113 | - public function currentPage($value) |
|
114 | - { |
|
113 | + public function currentPage($value) |
|
114 | + { |
|
115 | 115 | $this->page = (int)$value; |
116 | 116 | |
117 | 117 | return $this; |
@@ -123,8 +123,8 @@ discard block |
||
123 | 123 | * @param $value |
124 | 124 | * @return $this |
125 | 125 | */ |
126 | - public function adjacents($value) |
|
127 | - { |
|
126 | + public function adjacents($value) |
|
127 | + { |
|
128 | 128 | $this->adjacents = (int)$value; |
129 | 129 | |
130 | 130 | return $this; |
@@ -136,8 +136,8 @@ discard block |
||
136 | 136 | * @param string $value |
137 | 137 | * @return $this |
138 | 138 | */ |
139 | - public function showCounter($value = "") |
|
140 | - { |
|
139 | + public function showCounter($value = "") |
|
140 | + { |
|
141 | 141 | $this->showCounter = ($value === true) ? true : false; |
142 | 142 | |
143 | 143 | return $this; |
@@ -149,8 +149,8 @@ discard block |
||
149 | 149 | * @param string $value |
150 | 150 | * @return $this |
151 | 151 | */ |
152 | - public function changeClass($value = "") |
|
153 | - { |
|
152 | + public function changeClass($value = "") |
|
153 | + { |
|
154 | 154 | $this->className = $value; |
155 | 155 | |
156 | 156 | return $this; |
@@ -160,8 +160,8 @@ discard block |
||
160 | 160 | * @param $value |
161 | 161 | * @return $this |
162 | 162 | */ |
163 | - public function mainTpl($value) |
|
164 | - { |
|
163 | + public function mainTpl($value) |
|
164 | + { |
|
165 | 165 | $this->mainTpl = $value; |
166 | 166 | |
167 | 167 | return $this; |
@@ -171,8 +171,8 @@ discard block |
||
171 | 171 | * @param $value |
172 | 172 | * @return $this |
173 | 173 | */ |
174 | - public function nextLabel($value) |
|
175 | - { |
|
174 | + public function nextLabel($value) |
|
175 | + { |
|
176 | 176 | $this->nextT = $value; |
177 | 177 | |
178 | 178 | return $this; |
@@ -182,8 +182,8 @@ discard block |
||
182 | 182 | * @param $value |
183 | 183 | * @return $this |
184 | 184 | */ |
185 | - public function nextIcon($value) |
|
186 | - { |
|
185 | + public function nextIcon($value) |
|
186 | + { |
|
187 | 187 | $this->nextI = $value; |
188 | 188 | |
189 | 189 | return $this; |
@@ -193,8 +193,8 @@ discard block |
||
193 | 193 | * @param $value |
194 | 194 | * @return $this |
195 | 195 | */ |
196 | - public function prevLabel($value) |
|
197 | - { |
|
196 | + public function prevLabel($value) |
|
197 | + { |
|
198 | 198 | $this->prevT = $value; |
199 | 199 | |
200 | 200 | return $this; |
@@ -204,8 +204,8 @@ discard block |
||
204 | 204 | * @param $value |
205 | 205 | * @return $this |
206 | 206 | */ |
207 | - public function prevIcon($value) |
|
208 | - { |
|
207 | + public function prevIcon($value) |
|
208 | + { |
|
209 | 209 | $this->prevI = $value; |
210 | 210 | |
211 | 211 | return $this; |
@@ -217,8 +217,8 @@ discard block |
||
217 | 217 | * @param string $value |
218 | 218 | * @return $this |
219 | 219 | */ |
220 | - public function parameterName($value = "") |
|
221 | - { |
|
220 | + public function parameterName($value = "") |
|
221 | + { |
|
222 | 222 | $this->parameterName = $value; |
223 | 223 | |
224 | 224 | return $this; |
@@ -230,9 +230,9 @@ discard block |
||
230 | 230 | * @param string $value |
231 | 231 | * @return $this |
232 | 232 | */ |
233 | - public function urlFriendly($value = "%") |
|
234 | - { |
|
235 | - if (preg_match('/^\s/', $value)) { |
|
233 | + public function urlFriendly($value = "%") |
|
234 | + { |
|
235 | + if (preg_match('/^\s/', $value)) { |
|
236 | 236 | $this->urlF = false; |
237 | 237 | } |
238 | 238 | $this->urlF = $value; |
@@ -240,18 +240,18 @@ discard block |
||
240 | 240 | return $this; |
241 | 241 | } |
242 | 242 | |
243 | - public function show() |
|
244 | - { |
|
243 | + public function show() |
|
244 | + { |
|
245 | 245 | echo $this->getOutput(); |
246 | 246 | } |
247 | 247 | |
248 | 248 | /** |
249 | 249 | * @return string |
250 | 250 | */ |
251 | - public function getOutput() |
|
252 | - { |
|
251 | + public function getOutput() |
|
252 | + { |
|
253 | 253 | $out = ''; |
254 | - if (!$this->calculate && $this->calculate() && !empty($this->pagination)) { |
|
254 | + if (!$this->calculate && $this->calculate() && !empty($this->pagination)) { |
|
255 | 255 | $out = str_replace(array("[+class+]", "[+wrap+]"), array($this->className, $this->pagination), |
256 | 256 | $this->mainTpl) . "\n"; |
257 | 257 | } |
@@ -263,9 +263,9 @@ discard block |
||
263 | 263 | * @param $page |
264 | 264 | * @return int|mixed |
265 | 265 | */ |
266 | - protected function getPageQuery($page) |
|
267 | - { |
|
268 | - switch ($this->mode) { |
|
266 | + protected function getPageQuery($page) |
|
267 | + { |
|
268 | + switch ($this->mode) { |
|
269 | 269 | case 'offset': |
270 | 270 | $display = isset($this->modeConfig['display']) ? $this->modeConfig['display'] : 0; |
271 | 271 | $out = $display * ($page - 1); |
@@ -284,15 +284,15 @@ discard block |
||
284 | 284 | * @param $id |
285 | 285 | * @return mixed|string |
286 | 286 | */ |
287 | - public function get_pagenum_link($id) |
|
288 | - { |
|
287 | + public function get_pagenum_link($id) |
|
288 | + { |
|
289 | 289 | $flag = (strpos($this->target, '?') === false); |
290 | 290 | $value = $this->getPageQuery($id); |
291 | - if ($flag && !empty($this->urlF)) { |
|
291 | + if ($flag && !empty($this->urlF)) { |
|
292 | 292 | $out = str_replace($this->urlF, $value, $this->target); |
293 | - } else { |
|
293 | + } else { |
|
294 | 294 | $out = $this->target; |
295 | - if ($id > 1) { |
|
295 | + if ($id > 1) { |
|
296 | 296 | $out .= ($flag ? "?" : "&") . $this->parameterName . "=" . $value; |
297 | 297 | } |
298 | 298 | } |
@@ -303,30 +303,30 @@ discard block |
||
303 | 303 | /** |
304 | 304 | * @return bool |
305 | 305 | */ |
306 | - public function calculate() |
|
307 | - { |
|
306 | + public function calculate() |
|
307 | + { |
|
308 | 308 | $this->pagination = ""; |
309 | 309 | $this->calculate = true; |
310 | 310 | $error = false; |
311 | 311 | |
312 | 312 | if (!empty($this->urlF) && is_scalar($this->urlF) && $this->urlF != '%' && strpos($this->target, |
313 | 313 | $this->urlF) === false |
314 | - ) { |
|
314 | + ) { |
|
315 | 315 | //Es necesario especificar el comodin para sustituir |
316 | 316 | $error = true; |
317 | 317 | } elseif (!empty($this->urlF) && is_scalar($this->urlF) && $this->urlF == '%' && strpos($this->target, |
318 | 318 | $this->urlF) === false |
319 | - ) { |
|
319 | + ) { |
|
320 | 320 | $error = true; |
321 | 321 | } |
322 | 322 | |
323 | - if ($this->total_pages < 0) { |
|
323 | + if ($this->total_pages < 0) { |
|
324 | 324 | $error = true; |
325 | 325 | } |
326 | - if (!is_int($this->limit)) { |
|
326 | + if (!is_int($this->limit)) { |
|
327 | 327 | $error = true; |
328 | 328 | } |
329 | - if ($error) { |
|
329 | + if ($error) { |
|
330 | 330 | return false; |
331 | 331 | } |
332 | 332 | |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | $prev = ($this->page <= 1) ? 0 : $this->page - 1; //previous page is page - 1 |
337 | 337 | $next = (($this->page == $this->total_pages) ? 0 : ($this->page + 1)); //next page is page + 1 |
338 | 338 | $lastpage = $this->total_pages; |
339 | - if ($this->limit > 1 && $lastpage > $this->limit) { |
|
339 | + if ($this->limit > 1 && $lastpage > $this->limit) { |
|
340 | 340 | $lastpage = $this->limit; |
341 | 341 | } |
342 | 342 | $lpm1 = $lastpage - 1; //last page minus 1 |
@@ -345,26 +345,28 @@ discard block |
||
345 | 345 | Now we apply our rules and draw the pagination object. |
346 | 346 | We're actually saving the code to a variable in case we want to draw it more than once. |
347 | 347 | */ |
348 | - if ($lastpage > 1) { |
|
349 | - if ($this->page) { |
|
350 | - if ($this->page > 1) { |
|
348 | + if ($lastpage > 1) { |
|
349 | + if ($this->page) { |
|
350 | + if ($this->page > 1) { |
|
351 | 351 | $this->pagination .= $this->firstT ? $this->renderItemTPL($this->firstT, 0) : ''; |
352 | 352 | $this->pagination .= $this->prevT ? $this->renderItemTPL($this->prevT, $prev) : ''; |
353 | - } else { |
|
353 | + } else { |
|
354 | 354 | $this->pagination .= $this->firstI ? $this->renderItemTPL($this->firstI, 0) : ''; |
355 | 355 | $this->pagination .= $this->prevI ? $this->renderItemTPL($this->prevI, $prev) : ''; |
356 | 356 | } |
357 | 357 | } |
358 | 358 | //pages |
359 | - if ($lastpage < 7 + ($this->adjacents * 2)) { //not enough pages to bother breaking it up |
|
360 | - for ($counter = 1; $counter <= $lastpage; $counter++) { |
|
359 | + if ($lastpage < 7 + ($this->adjacents * 2)) { |
|
360 | +//not enough pages to bother breaking it up |
|
361 | + for ($counter = 1; $counter <= $lastpage; $counter++) { |
|
361 | 362 | $tpl = ($counter == $this->page) ? $this->currentT : $this->numberT; |
362 | 363 | $this->pagination .= $this->renderItemTPL($tpl, $counter); |
363 | 364 | } |
364 | - } elseif ($lastpage > 5 + ($this->adjacents * 2)) { //enough pages to hide some |
|
365 | + } elseif ($lastpage > 5 + ($this->adjacents * 2)) { |
|
366 | +//enough pages to hide some |
|
365 | 367 | //close to beginning; only hide later pages |
366 | - if ($this->page <= 2 + ($this->adjacents * 2)) { |
|
367 | - for ($counter = 1; $counter < 4 + ($this->adjacents * 2); $counter++) { |
|
368 | + if ($this->page <= 2 + ($this->adjacents * 2)) { |
|
369 | + for ($counter = 1; $counter < 4 + ($this->adjacents * 2); $counter++) { |
|
368 | 370 | $tpl = ($counter == $this->page) ? $this->currentT : $this->numberT; |
369 | 371 | $this->pagination .= $this->renderItemTPL($tpl, $counter); |
370 | 372 | } |
@@ -372,12 +374,12 @@ discard block |
||
372 | 374 | $this->pagination .= $this->renderItemTPL($this->numberT, $lpm1); |
373 | 375 | $this->pagination .= $this->renderItemTPL($this->numberT, $lastpage); |
374 | 376 | } //in middle; hide some front and some back |
375 | - elseif ($lastpage - ($this->adjacents * 2) > $this->page && $this->page > ($this->adjacents * 2)) { |
|
377 | + elseif ($lastpage - ($this->adjacents * 2) > $this->page && $this->page > ($this->adjacents * 2)) { |
|
376 | 378 | $this->pagination .= $this->renderItemTPL($this->numberT, 1); |
377 | 379 | $this->pagination .= $this->renderItemTPL($this->numberT, 2); |
378 | 380 | $this->pagination .= $this->renderItemTPL($this->dotsT, 3); |
379 | 381 | |
380 | - for ($counter = $this->page - $this->adjacents; $counter <= $this->page + $this->adjacents; $counter++) { |
|
382 | + for ($counter = $this->page - $this->adjacents; $counter <= $this->page + $this->adjacents; $counter++) { |
|
381 | 383 | $tpl = ($counter == $this->page) ? $this->currentT : $this->numberT; |
382 | 384 | $this->pagination .= $this->renderItemTPL($tpl, $counter); |
383 | 385 | } |
@@ -385,27 +387,27 @@ discard block |
||
385 | 387 | $this->pagination .= $this->renderItemTPL($this->numberT, $lpm1); |
386 | 388 | $this->pagination .= $this->renderItemTPL($this->numberT, $lastpage); |
387 | 389 | } //close to end; only hide early pages |
388 | - else { |
|
390 | + else { |
|
389 | 391 | $this->pagination .= $this->renderItemTPL($this->numberT, 1); |
390 | 392 | $this->pagination .= $this->renderItemTPL($this->numberT, 2); |
391 | 393 | $this->pagination .= $this->renderItemTPL($this->dotsT, 3); |
392 | 394 | |
393 | - for ($counter = $lastpage - (2 + ($this->adjacents * 2)); $counter <= $lastpage; $counter++) { |
|
395 | + for ($counter = $lastpage - (2 + ($this->adjacents * 2)); $counter <= $lastpage; $counter++) { |
|
394 | 396 | $tpl = ($counter == $this->page) ? $this->currentT : $this->numberT; |
395 | 397 | $this->pagination .= $this->renderItemTPL($tpl, $counter); |
396 | 398 | } |
397 | 399 | } |
398 | 400 | } |
399 | - if ($this->page) { |
|
400 | - if ($this->page < $counter - 1) { |
|
401 | + if ($this->page) { |
|
402 | + if ($this->page < $counter - 1) { |
|
401 | 403 | $this->pagination .= $this->nextT ? $this->renderItemTPL($this->nextT, $next) : ''; |
402 | 404 | $this->pagination .= $this->lastT ? $this->renderItemTPL($this->lastT, $lastpage) : ''; |
403 | - } else { |
|
405 | + } else { |
|
404 | 406 | $this->pagination .= $this->nextI ? $this->renderItemTPL($this->nextI, $next) : ''; |
405 | 407 | $this->pagination .= $this->lastI ? $this->renderItemTPL($this->lastI, $lastpage) : ''; |
406 | 408 | } |
407 | 409 | |
408 | - if ($this->showCounter) { |
|
410 | + if ($this->showCounter) { |
|
409 | 411 | $this->pagination .= "<div class=\"pagination_data\">($this->total_pages Pages)</div>"; |
410 | 412 | } |
411 | 413 | } |
@@ -419,8 +421,8 @@ discard block |
||
419 | 421 | * @param $num |
420 | 422 | * @return mixed |
421 | 423 | */ |
422 | - protected function renderItemTPL($tpl, $num) |
|
423 | - { |
|
424 | + protected function renderItemTPL($tpl, $num) |
|
425 | + { |
|
424 | 426 | return str_replace(array('[+num+]', '[+link+]'), array($num, $this->get_pagenum_link($num)), $tpl); |
425 | 427 | } |
426 | 428 | } |