PluginProbe
SEO Redirection Plugin – 301 Redirect Manager / 8.4
SEO Redirection Plugin – 301 Redirect Manager v8.4
9.19 trunk 4.17 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 9.1 9.10 9.11 9.12 All 39 releases
seo-redirection / common / controls / pagination.class.php

pagination.class.php in SEO Redirection Plugin – 301 Redirect Manager 8.4, at common/controls/pagination.class.php

665 lines 15.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /****************************************************************************
3 * pagination.class.php
4 *
5 * version 1.0
6 *
7 * This script can be used to generate dynamically pagination for any list of rows or items from MySQL Database
8 *
9 * ----------------------------------------------------------------
10 *
11 * A demo example is included in demo folder.
12 *
13 * Copyright (C) 2012 Fakhri Alsadi <fakrhi.s@hotmail.com>
14 *
15 *******************************************************************************/
16
17 if(!class_exists('cf_pagination')){
18 class cf_pagination{
19
20 private $rows=15; //The rows per page.
21 private $table_rows_count; //The total rows to show.
22 private $pages_count; //The pages number to generate.
23 private $current_page=1; //The number of the current page displayed.
24 private $start=0; //The start of the mysql limit keyword.
25 private $printed_pages=7; //Number of pages to display.
26 private $parameter='page_num'; //The pgination paramerter name.
27 private $url_rewrite=''; //The URL rewrite structure.
28 private $data_source; //The MySQL Table or Tables used.
29 private $filter; //The MySQL Where clouse.
30 private $current_parameters; //The existing query string parameters
31 private $prev_page; //The previous page.
32 private $next_page; //The next page
33 private $run_count=0; //Times that the funtion run() invoked.
34 private $show_pages_number=true; //Pages number box status.
35 private $show_go_button=true; //Showing Go button status.
36 private $show_prev_next=true; //Showing pervious and next page buttons status.
37 private $show_first_last=true; //Showing first and last page buttons status.
38 private $direction=''; //The direction of pagination.
39 private $alignment=''; //The alignment of pagination.
40 private $go_button_text= "GO"; //Set text of Go button
41 private $pages_number_text= "of pages"; //Set text of pages number
42 private $next_page_text= ">"; //Set text of next page button
43 private $prev_page_text= "<"; //Set text of previous button
44 private $first_page_text= "<<"; //Set text of first page button
45 private $last_page_text= ">>"; //Set text of last button
46 private $invalid_page_number_text= "invalid page number!"; //Set text of invalid page number error
47
48 public function __construct($data_source='',$filter='',$rows=15,$parameter='page_num')
49 {
50 $this->data_source=$data_source;
51 $this->set_filter($filter);
52 $this->rows=$rows;
53 $this->parameter= $parameter;
54 }
55
56
57 //------------------------------------------------------------------------
58
59 private function run()
60 {
61 global $wpdb;
62
63 if($this->run_count == 0)
64 {
65
66 if($this->data_source== '')
67 {
68 echo 'You must set the Data Source using the function set_data_source($data_source)';
69 exit(0);
70 }
71
72
73
74 $sql=" select count(*) as cnt from {$this->data_source} {$this->filter} ";
75 $result=$wpdb->get_row($sql);
76 $this->table_rows_count = intval($result->cnt);
77
78
79 $this->pages_count = intval($this->table_rows_count/$this->rows);
80 if($this->table_rows_count%$this->rows !=0)
81 $this->pages_count=$this->pages_count+1;
82 if($this->pages_count ==0)
83 $this->pages_count=1;
84
85 if(array_key_exists($this->parameter,$_GET))
86 $this->current_page = intval($_GET[$this->parameter]);
87 else
88 $this->current_page =1;
89
90 if($this->current_page<1)
91 $this->current_page=1;
92 else if($this->current_page > $this->pages_count)
93 $this->current_page=$this->pages_count;
94
95 $this->current_parameters = $this->WPSR_get_current_parameters($this->parameter);
96 $this->prev_page= $this->current_page -1;
97 $this->next_page= $this->current_page +1;
98
99 $this->start = (($this->current_page - 1) * $this->rows);
100
101 }
102
103 $this->run_count ++;
104
105 }
106
107
108 //------------------------------------------------------------------------
109
110
111
112 public function print_pagination()
113 {
114
115 $this->run();
116
117 $this->pagination_header_html();
118
119
120
121 $stop=0;
122 $half_pages="";
123 $frompage="";
124 $topage ="";
125
126 if($this->printed_pages>1){
127
128 $half_pages= intval($this->printed_pages/2);
129 if($this->printed_pages%$half_pages ==0)
130 $half_pages--;
131
132 $frompage=($this->current_page - $half_pages );
133 $topage = ($this->current_page + $this->printed_pages);
134
135 }
136
137 if($this->printed_pages==1)
138 {
139 $frompage = $this->current_page;
140 $topage = $this->current_page;
141 }
142
143 if($this->printed_pages==3)
144 {
145 $frompage = $this->current_page -1;
146 $topage = $this->current_page + 1 ;
147 }
148
149
150 if($this->current_page > ( $this->pages_count - ($this->printed_pages - $half_pages ) ))
151 {
152 $topage = $this->pages_count ;
153 $frompage= ( $this->pages_count - $this->printed_pages +1 );
154 }
155
156 for($i=$frompage;$i<=$topage;$i++)
157 {
158
159 if($i>0 && $i<=$this->pages_count && $this->pages_count>1)
160 {
161 if($i==$this->current_page)
162 echo $this->get_current_page_html($i);
163 else
164 echo $this->get_page_html($i,$i);
165
166 $stop++;
167 if($stop >= $this->printed_pages)
168 break;
169 }
170
171 }
172
173
174
175
176
177
178
179 echo esc_html($this->get_go_button_html());
180
181 $this->pagination_footer_html();
182
183 }
184
185
186 //------------------------------------------------------------------------
187
188 private function get_page_html($page,$name)
189 {
190 return '<a href="' . esc_url($this->get_page_url($page)) . '">' . esc_html($name) . '</a>';
191 }
192
193 //------------------------------------------------------------------------
194
195 private function get_current_page_html($name)
196 {
197
198 return '<span class="currentpage">' . esc_html($name) . '</span>';
199 }
200
201 //------------------------------------------------------------------------
202
203 private function pagination_header_html()
204 {
205
206 $options="";
207 if($this->direction!='')
208 $options= $options . ' dir="' . esc_attr($this->direction) . '" ';
209
210 if($this->alignment!='')
211 $options= $options . ' align="' . esc_attr($this->alignment) . '" ';
212
213
214 echo '<div style="text-align:right;" class="pagination tablenav-page" ' . esc_attr($options) . ' >';
215
216
217 }
218
219 //------------------------------------------------------------------------
220
221 private function pagination_footer_html()
222 {
223 echo '</div>';
224 }
225
226 //------------------------------------------------------------------------
227
228 private function random_id()
229 {
230 srand ((double) microtime( )*1000000000);
231 return rand();
232 }
233
234 //------------------------------------------------------------------------
235 private function get_go_button_html()
236 {
237
238 $id='gopage' . $this->random_id();
239
240 $url_structure="";
241 if($this->url_rewrite !='')
242 $url_structure = $this->url_rewrite;
243 else
244 $url_structure = $this->get_page_url_parameter() . '{pagination}';
245
246 if($this->show_go_button)
247 echo '<script>
248 function fun_'. esc_js($id) .'()
249 {
250 var page=parseInt(document.getElementById(\''. esc_js($id) .'\').value);
251 var url = "' . esc_js($url_structure) . '";
252 if(page>0)
253 {
254 window.location= url.replace(/{pagination}/gi, page);
255 }else
256 {
257 alert(\'' . esc_js($this->invalid_page_number_text) . '\');
258 }
259 }
260 function keypress_'. esc_js($id) .'(event)
261 {
262 var key=event.keyCode;
263
264 if(key == 13)
265 {
266 fun_'. esc_js($id) .'();
267 return false;
268 }
269 }
270 </script><input onkeydown="return keypress_'. esc_js($id) .'(event)" type="text" name="' . esc_js($id) . '" id="' . esc_js($id) . '" size="3" value="' . esc_js($this->current_page) . '" ><a onclick="fun_'. esc_js($id) .'()" href="#">' . esc_js($this->go_button_text) .'</a>';
271 }
272
273
274 //------------------------------------------------------------------------
275
276
277 public function get_page_url($page)
278 {
279 if($this->url_rewrite == '')
280 {
281 if($this->current_parameters =="")
282 return "?" . $this->parameter . "=" . $page;
283 else
284 return $this->current_parameters . "&" . $this->parameter . "=" . $page;
285 }else
286 {
287 return str_replace('{pagination}',$page, $this->url_rewrite);
288 }
289 }
290
291
292 //------------------------------------------------------------------------
293
294
295
296 private function get_page_url_parameter()
297 {
298 if($this->current_parameters =="")
299 return "?" . $this->parameter . "=";
300 else
301 return $this->current_parameters . "&" . $this->parameter . "=";
302 }
303
304 //------------------------------------------------------------------------
305
306 private function WPSR_get_current_parameters($remove_parameter="")
307 {
308
309 if($_SERVER['QUERY_STRING']!='')
310 {
311 $qry = '?' . sanitize_text_field($_SERVER['QUERY_STRING']);
312 if($remove_parameter!='')
313 {
314 if(array_key_exists($remove_parameter,$_GET)){
315 $string_remove = '&' . $remove_parameter . "=" . sanitize_text_field($_GET[$remove_parameter]);
316 $qry=str_replace($string_remove,"",$qry);
317 $string_remove = '?' . $remove_parameter . "=" . sanitize_text_field($_GET[$remove_parameter]);
318 $qry=str_replace($string_remove,"",$qry);
319 }
320 }
321
322 return $qry;
323 }else
324 {
325 return "";
326 }
327 }
328
329 //------------------------------------------------------------------------
330
331
332 public function get_sql_limit()
333 {
334 $this->run();
335 return " limit {$this->start},{$this->rows} ";
336 }
337
338 //------------------------------------------------------------------------
339
340 public function get_rows()
341 {
342 return $this->rows;
343 }
344
345 //------------------------------------------------------------------------
346
347 public function set_rows($rows)
348 {
349 if(intval($rows)>0)
350 {
351 $this->rows=$rows;
352 $this->run_count=0;
353 }
354 }
355
356 //------------------------------------------------------------------------
357
358 public function get_total_records()
359 {
360 return $this->table_rows_count;
361 }
362
363
364 //------------------------------------------------------------------------
365
366 public function get_printed_pages()
367 {
368 return $this->printed_pages;
369 }
370
371 //------------------------------------------------------------------------
372
373 public function set_printed_pages($printed_pages)
374 {
375 if(intval($printed_pages)>0)
376 {
377 $this->printed_pages=$printed_pages;
378 $this->run_count=0;
379 }
380 }
381
382 //------------------------------------------------------------------------
383
384 public function get_parameter_name()
385 {
386 return $this->parameter;
387 }
388
389 //------------------------------------------------------------------------
390
391 public function set_parameter_name($parameter)
392 {
393 $this->parameter=$parameter;
394 $this->run_count=0;
395 }
396 //------------------------------------------------------------------------
397
398 public function get_url_rewrite()
399 {
400 return $this->url_rewrite;
401 }
402
403 //------------------------------------------------------------------------
404
405 public function set_url_rewrite($url_rewrite)
406 {
407 $this->url_rewrite=$url_rewrite;
408 $this->run_count=0;
409 }
410 //------------------------------------------------------------------------
411
412
413 public function get_data_source()
414 {
415 return $this->data_source;
416 }
417
418 //------------------------------------------------------------------------
419
420 public function set_data_source($data_source)
421 {
422 $this->data_source=$data_source;
423 $this->run_count=0;
424 }
425
426 //------------------------------------------------------------------------
427
428 public function get_filter()
429 {
430 return $this->filter;
431 }
432
433 //------------------------------------------------------------------------
434
435 public function set_filter($filter)
436 {
437 if($filter!='')
438 $this->filter= ' where ' . $filter;
439 $this->run_count=0;
440 }
441
442 //------------------------------------------------------------------------
443
444 public function get_go_button_text()
445 {
446 return $this->go_button_text;
447 }
448
449 //------------------------------------------------------------------------
450
451 public function set_go_button_text($go_button_text)
452 {
453 $this->go_button_text=$go_button_text;
454 $this->run_count=0;
455 }
456
457 //------------------------------------------------------------------------
458
459 public function get_pages_number_text()
460 {
461 return $this->pages_number_text;
462 }
463
464 //------------------------------------------------------------------------
465
466 public function set_pages_number_text($pages_number_text)
467 {
468 $this->pages_number_text=$pages_number_text;
469 $this->run_count=0;
470 }
471 //------------------------------------------------------------------------
472
473 public function get_next_page_text()
474 {
475 return $this->next_page_text;
476 }
477
478 //------------------------------------------------------------------------
479
480 public function set_next_page_text($next_page_text)
481 {
482 $this->next_page_text=$next_page_text;
483 $this->run_count=0;
484 }
485
486 //------------------------------------------------------------------------
487
488 public function get_prev_page_text()
489 {
490 return $this->prev_page_text;
491 }
492
493 //------------------------------------------------------------------------
494
495 public function set_prev_page_text($prev_page_text)
496 {
497 $this->prev_page_text=$prev_page_text;
498 $this->run_count=0;
499 }
500
501 //------------------------------------------------------------------------
502
503 public function get_first_page_text()
504 {
505 return $this->first_page_text;
506 }
507
508 //------------------------------------------------------------------------
509
510 public function set_first_page_text($first_page_text)
511 {
512 $this->first_page_text=$first_page_text;
513 $this->run_count=0;
514 }
515
516 //------------------------------------------------------------------------
517
518 public function get_last_page_text()
519 {
520 return $this->last_page_text;
521 }
522
523 //------------------------------------------------------------------------
524
525 public function set_last_page_text($last_page_text)
526 {
527 $this->last_page_text=$last_page_text;
528 $this->run_count=0;
529 }
530
531 //------------------------------------------------------------------------
532
533 public function get_invalid_page_number_text()
534 {
535 return $this->invalid_page_number_text;
536 }
537
538 //------------------------------------------------------------------------
539
540 public function set_invalid_page_number_text($invalid_page_number_text)
541 {
542 $this->invalid_page_number_text=$invalid_page_number_text;
543 $this->run_count=0;
544 }
545
546 //------------------------------------------------------------------------
547
548 public function get_alignment()
549 {
550 return $this->$alignment;
551 }
552
553 //------------------------------------------------------------------------
554
555 public function set_alignment($alignment)
556 {
557 $this->alignment=$alignment;
558 $this->run_count=0;
559 }
560
561 //------------------------------------------------------------------------
562
563 public function get_direction()
564 {
565 return $this->$direction;
566 }
567
568 //------------------------------------------------------------------------
569
570 public function set_direction($direction)
571 {
572 $this->direction=$direction;
573 $this->run_count=0;
574 }
575
576 //------------------------------------------------------------------------
577
578 public function show_pages_number($value)
579 {
580
581 if($value)
582 $this->show_pages_number = true;
583 else
584 $this->show_pages_number = false;
585
586 $this->run_count=0;
587
588 }
589 //------------------------------------------------------------------------
590
591 public function can_show_pages_number()
592 {
593 return $this->show_pages_number;
594 }
595
596 //------------------------------------------------------------------------
597
598 public function show_go_button($value)
599 {
600
601 if($value)
602 $this->show_go_button = true;
603 else
604 $this->show_go_button = false;
605
606 $this->run_count=0;
607
608 }
609
610 //------------------------------------------------------------------------
611
612 public function can_show_go_button()
613 {
614 return $this->show_go_button;
615 }
616
617 //------------------------------------------------------------------------
618
619 public function show_prev_next($value)
620 {
621
622 if($value)
623 $this->show_prev_next = true;
624 else
625 $this->show_prev_next = false;
626
627 $this->run_count=0;
628
629 }
630
631 //------------------------------------------------------------------------
632
633 public function can_show_prev_next()
634 {
635 return $this->show_prev_next;
636 }
637
638 //------------------------------------------------------------------------
639
640 public function show_first_last($value)
641 {
642
643 if($value)
644 $this->show_first_last = true;
645 else
646 $this->show_first_last = false;
647
648 $this->run_count=0;
649
650 }
651
652 //------------------------------------------------------------------------
653
654 public function can_show_first_last()
655 {
656 return $this->show_first_last;
657 }
658
659
660 //------------------------------------------------------------------------
661
662 }}
663
664 ?>
665