PluginProbe
Booking Calendar / 10.10.2
Booking Calendar v10.10.2
11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 10.11.2 All 203 releases
booking / includes / _pagination / pagination.php

pagination.php in Booking Calendar 10.10.2, at includes/_pagination/pagination.php

324 lines 10.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php /**
2 * @version 1.0
3 * @description Pagination
4 * @category Pagination Class
5 * @author wpdevelop
6 *
7 * @web-site http://oplugins.com/
8 * @email info@oplugins.com
9 *
10 * @modified 2020-01-23
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
14
15
16 /*
17 * Usage: Pagination Class
18
19 <div class="wpbc_rules_pagination"></div>
20 <?php
21 $wpbc_pagination = new WPBC_Pagination();
22 $wpbc_pagination->init(
23 array(
24 'load_on_page' => 'wpbc-rules',
25 'container' => '.wpbc_rules_pagination',
26 'on_click' => 'wpbc_rules_pagination_click' // onclick = "javascript: wpbc_rules_listing_page( page_num );" - need to define this function in JS file
27 )
28 );
29 $wpbc_pagination->show( // Its showing with JavaScript on document ready
30 array(
31 'page_active' => 3,
32 'pages_count' => 20
33 )
34 );
35
36 OR (for showing with JavaScript) :
37
38 <script type="text/javascript">
39 jQuery( document ).ready( function (){
40
41 wpbc_pagination_echo( '.wpbc_rules_pagination',
42 {
43 'page_active': page_number,
44 'pages_count': Math.ceil( ajx_count / ajx_page_items_count )
45 }
46 );
47 } );
48 </script>
49
50 */
51
52
53 class WPBC_Pagination {
54
55 private $settings;
56
57 /**
58 * Get parameter Value
59 *
60 * @param string $parameter - name of parameter
61 *
62 * @return mixed
63 */
64 public function get_settings( $parameter ){
65
66 if ( ! empty( $this->settings[ $parameter ] ) ) {
67 return $this->settings[ $parameter ];
68 } else {
69 return false;
70 }
71 }
72
73
74 // <editor-fold defaultstate="collapsed" desc=" /// JS | CSS files /// " >
75 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76 /// JS | CSS files
77 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
78
79 /**
80 * Define HOOKs for loading CSS and JavaScript files
81 */
82 public function init_load_css_js() {
83 // JS & CSS
84 add_action( 'wpbc_enqueue_js_files', array( $this, 'js_load_files' ), 50 );
85 add_action( 'wpbc_enqueue_css_files', array( $this, 'enqueue_css_files' ), 50 );
86 }
87
88 /** JSS */
89 public function js_load_files( $where_to_load ) {
90
91 $in_footer = true;
92
93 if ( ( is_admin() ) && ( in_array( $where_to_load, array( 'admin', 'both' ) ) ) ) {
94
95 //wp_enqueue_script( 'wpbc-live_search', wpbc_plugin_url( '/_out/js/live_search.js' ), array( 'wpbc_all' ), WP_BK_VERSION_NUM, $in_footer );
96 wp_enqueue_script( 'wpbc-pagination'
97 , trailingslashit( plugins_url( '', __FILE__ ) ) . 'pagination.js' /* wpbc_plugin_url( '/_out/js/code_mirror.js' ) */
98 , array( 'wpbc_all' ), WP_BK_VERSION_NUM, $in_footer );
99
100 /**
101 wp_localize_script( 'wpbc_all', 'wpbc_live_request_obj'
102 , array(
103 'contacts' => '',
104 'reminders' => ''
105 )
106 );
107 */
108 }
109 }
110
111 /** CSS */
112 public function enqueue_css_files( $where_to_load ) {
113
114 if ( ( is_admin() ) && ( in_array( $where_to_load, array( 'admin', 'both' ) ) ) ) {
115
116 wp_enqueue_style( 'wpbc-pagination', trailingslashit( plugins_url( '', __FILE__ ) ) . 'pagination.css', array(), WP_BK_VERSION_NUM );
117 }
118 }
119
120 // </editor-fold>
121
122
123 // <editor-fold defaultstate="collapsed" desc=" /// Templates /// " >
124 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
125 /// Templates
126 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
127
128 public function init_load_templates() {
129
130 add_action( 'wpbc_hook_settings_page_footer', array( $this, 'hook__page_footer_tmpl' ) );
131 }
132
133
134 /**
135 * Templates at footer of page
136 *
137 * @param $page string
138 */
139 public function hook__page_footer_tmpl( $page ){
140
141 if ( $this->get_settings( 'load_on_page' ) === $page ) {
142
143 $this->template__pagination();
144 }
145 }
146
147
148 private function template__pagination(){
149
150 // Pagination
151 ?><script type="text/html" id="tmpl-wpbc_pagination">
152 <div class="wpbc-ajax-pagination wpbc-ajax-pagination-container">
153 <# if ( data.pages_count > 1 ) { #>
154 <div class="ui_element">
155 <a class="wpbc_ui_control wpbc_ui_button <# if ( 1 == data.page_active ) { #> disabled<# } #>"
156 href="javascript:void(0)"
157 <# if ( 1 != data.page_active ) { #> onclick="javascript:<?php
158 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
159 echo $this->get_settings( 'on_click' ); ?>( parseInt( {{ data.page_active }} ) - 1 );" <# } #>
160 >
161 <?php esc_html_e('Prev', 'booking'); ?>
162 </a>
163 </div>
164 <# }
165
166 /** Number visible pages (links) that linked to active page, other pages skipped by "..." */
167 var num_closed_steps = 2;
168
169 for ( var pg_num = 1; pg_num <= data.pages_count; pg_num++ ){
170
171 if ( ! (
172 ( data.pages_count > ( num_closed_steps * 4) )
173 && ( pg_num > num_closed_steps )
174 && ( ( data.pages_count - pg_num + 1 ) > num_closed_steps )
175 && ( Math.abs( data.page_active - pg_num ) > num_closed_steps )
176 ) )
177 {
178 #> <div class="ui_element"><a class="wpbc_ui_control wpbc_ui_button <# if ( pg_num == data.page_active ) { #> active<# } #>"
179 href="javascript:void(0)" onclick="javascript:<?php
180 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
181 echo $this->get_settings( 'on_click' ); ?>( {{pg_num}} );" >
182 {{pg_num}}</a></div> <#
183
184 if ( ( data.pages_count > ( num_closed_steps * 4) )
185 && ( (pg_num+1) > num_closed_steps )
186 && ( ( data.pages_count - ( pg_num + 1 ) ) > num_closed_steps )
187 && ( Math.abs(data.page_active - ( pg_num + 1 ) ) > num_closed_steps )
188 ) {
189 #><div class="ui_element"><a class="wpbc_ui_control wpbc_ui_button disabled" href="javascript:void(0);">...</a></div><#
190 }
191 }
192 }
193
194 if ( data.pages_count > 1 ) { #>
195 <div class="ui_element">
196 <a class="wpbc_ui_control wpbc_ui_button <# if ( data.pages_count == data.page_active ) { #> disabled<# } #>"
197 href="javascript:void(0)"
198 <# if ( data.pages_count != data.page_active ) { #> onclick="javascript:<?php
199 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
200 echo $this->get_settings( 'on_click' ); ?>( parseInt( {{ data.page_active }} ) + 1 );" <# } #>
201 >
202 <?php esc_html_e('Next', 'booking'); ?>
203 </a>
204 </div>
205 <# } #>
206 </div>
207 </script><?php
208
209 // Pagination Items per page
210 ?><script type="text/html" id="tmpl-wpbc_pagination_items_per_page">
211 <div class="wpbc-ajax-pagination_items_per_page">
212 <div class="ui_element">
213 <select class="wpbc_items_per_page wpbc_ui_control wpbc_ui_select " autocomplete="off">
214 <#
215 var my_options_arr = [5, 10, 50, 100];
216 var is_selected = '';
217 _.each( my_options_arr, function ( p_val, p_key, p_data ) {
218 is_selected = '';
219 if ( data.page_items_count == p_val ) {
220 is_selected = ' selected="selected" ';
221 }
222 #><option value="{{p_val}}" {{is_selected}}>{{p_val}}</option><#
223 });
224 #>
225 </select>
226 </div>
227 <div class="ui_element">
228 <label class="wpbc_ui_control_label"><?php esc_html_e('per page','booking'); ?></label>
229 </div>
230 <?php
231
232 if (0) {
233 ?>
234 <div class="ui_element">
235 <select class="wpbc_items_sort_type wpbc_ui_control wpbc_ui_select" autocomplete="off">
236 <#
237 my_options_arr = {
238 'ASC': '<?php echo esc_js(__( 'ASC', 'booking' )); ?>',
239 'DESC': '<?php echo esc_js(__( 'DESC', 'booking' )); ?>',
240 };
241 is_selected = '';
242 _.each( my_options_arr, function ( p_val, p_key, p_data ) {
243 is_selected = '';
244 if ( data.sort_type == p_key ) {
245 is_selected = ' selected="selected" ';
246 }
247 #><option value="{{p_key}}" {{is_selected}}>{{p_val}}</option><#
248 });
249 #>
250 </select>
251 </div>
252 <?php } ?>
253 </div>
254 </script><?php
255 }
256
257 // </editor-fold>
258
259
260 /**
261 * Init Pagination on start - define 'load_on_page', 'container', 'on_click' function
262 *
263 * @param array $params = array(
264 'load_on_page' => 'wpbc-settings', // defined at function in_page() {
265 'container' => '.wpbc_settings_pagination', // defined in function content(), like <div class="wpbc_rules_pagination"></div>
266 'on_click' => 'wpbc_pagination_click_page' // onclick = "javascript: wpbc_pagination_click_page( page_active );" - need to define this function in JS file
267 );
268 */
269 public function init( $params = array() ) {
270
271 $defaults = array(
272 'load_on_page' => 'wpbc-settings', // defined at function in_page() {
273 'container' => '.wpbc_settings_pagination', // defined in function content(), like <div class="wpbc_rules_pagination"></div>
274 'on_click' => 'wpbc_pagination_click_page' // onclick = "javascript: wpbc_pagination_click_page( page_active );" - need to define this function in JS file
275 );
276 $this->settings = wp_parse_args( $params, $defaults );
277
278 $this->init_load_templates();
279 }
280
281
282 /**
283 * Show pagination
284 *
285 * @param array $params = array(
286 'page_active' => 1,
287 'pages_count' => 10
288 )
289 */
290 public function show( $params = array() ) {
291 $defaults = array(
292 'page_active' => 1,
293 'pages_count' => 1
294 );
295 $params = wp_parse_args( $params, $defaults );
296 ?>
297 <script type="text/javascript">
298
299 jQuery( document ).ready( function (){
300
301 wpbc_pagination_echo( '<?php echo esc_attr( $this->get_settings( 'container' ) ); ?>', <?php
302 echo wp_json_encode(
303 array(
304 'page_active' => $params['page_active'],
305 'pages_count' => $params['pages_count']
306 )
307 );
308 ?> );
309 } );
310 </script>
311 <?php
312 }
313 }
314
315 /**
316 * Just for loading CSS and JavaScript files for all Settings pages
317 */
318 if ( true ) {
319 $js_css_loading = new WPBC_Pagination;
320 $js_css_loading->init_load_css_js();
321 }
322
323
324 //TODO: delete ../email-reminders/_src/css/o-pagination.css