PluginProbe
AliNext – WooCommerce Dropshipping Plugin for AliExpress / trunk
AliNext – WooCommerce Dropshipping Plugin for AliExpress vtrunk
ali2woo-lite / includes / classes / utils / Paginator.php

Paginator.php in AliNext – WooCommerce Dropshipping Plugin for AliExpress trunk, at includes/classes/utils/Paginator.php

47 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Description of Paginator
5 *
6 * @author Ali2Woo Team
7 */
8
9 namespace AliNext_Lite;;
10
11 class Paginator {
12 public static function build($total, $per_page=20, $links=4, $request_param = 'cur_page')
13 {
14 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
15 $page = isset($_REQUEST[$request_param]) && intval($_REQUEST[$request_param]) ? intval($_REQUEST[$request_param]) : 1;
16
17 $pages_list = array();
18
19 $last = ceil($total / $per_page);
20
21 if($page<1){
22 $page=1;
23 }
24
25 if($page>$last){
26 $page = $last;
27 }
28
29 $start = ( ( $page - $links ) > 0 ) ? $page - $links : 1;
30 $end = ( ( $page + $links ) < $last ) ? $page + $links : $last;
31 if ($start > 1) {
32 $pages_list[] = 1;
33 $pages_list[] = '';
34 }
35 for ($i = $start; $i <= $end; $i++) {
36 $pages_list[] = $i;
37 }
38 if ($end < $last) {
39 $pages_list[] = '';
40 $pages_list[] = $last;
41 }
42
43 return array('total_pages'=>$last, 'cur_page'=>$page, 'per_page'=>$per_page, 'pages_list'=>$pages_list);
44 }
45 }
46
47