wpml-admin-pagination.php
2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
/**
* Class WPML_Admin_Pagination
*
* @author OnTheGoSystems
*/
class WPML_Admin_Pagination {
/** @var int $items_per_page */
private $items_per_page;
/** @var int $total_items */
private $total_items;
/** @var int $current_page */
private $current_page;
/** @var string $current_url */
private $current_url;
/** @var string */
private $page_param_name = 'paged';
/**
* @param string $page_param_name
*/
public function set_page_param_name( $page_param_name ) {
$this->page_param_name = $page_param_name;
}
/**
* @return string
*/
public function get_page_param_name() {
return $this->page_param_name;
}
/**
* @param int $items_per_page
*/
public function set_items_per_page( $items_per_page ) {
$this->items_per_page = (int) $items_per_page;
}
/**
* @return int
*/
public function get_items_per_page() {
return $this->items_per_page;
}
/**
* @param int $total_items
*/
public function set_total_items( $total_items ) {
$this->total_items = (int) $total_items;
}
/**
* @return int
*/
public function get_total_items() {
return $this->total_items;
}
/**
* @return int
*/
public function get_total_pages() {
return ceil( $this->get_total_items() / $this->get_items_per_page() );
}
/**
* @param int $page
*/
public function set_current_page( $page ) {
$this->current_page = (int) $page;
}
/**
* @return int
*/
public function get_current_page() {
return $this->current_page;
}
/**
* @return null|string
*/
public function get_first_page_url() {
$url = null;
if ( 2 < $this->get_current_page() ) {
$url = remove_query_arg( $this->page_param_name, $this->get_current_url() );
}
return $url;
}
/**
* @return null|string
*/
public function get_previous_page_url() {
$url = null;
if ( 1 < $this->get_current_page() ) {
$url = add_query_arg( $this->page_param_name, $this->get_current_page() - 1, $this->get_current_url() );
}
return $url;
}
/**
* @return null|string
*/
public function get_next_page_url() {
$url = null;
if ( $this->get_current_page() < $this->get_total_pages() ) {
$url = add_query_arg( $this->page_param_name, $this->get_current_page() + 1, $this->get_current_url() );
}
return $url;
}
/**
* @return null|string
*/
public function get_last_page_url() {
$url = null;
if ( $this->get_current_page() < $this->get_total_pages() - 1 ) {
$url = add_query_arg( $this->page_param_name, $this->get_total_pages(), $this->get_current_url() );
}
return $url;
}
/**
* @return string
*/
private function get_current_url() {
if ( ! $this->current_url ) {
$removable_query_args = wp_removable_query_args();
$this->current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
$this->current_url = remove_query_arg( $removable_query_args, $this->current_url );
}
return $this->current_url;
}
}