PluginProbe
Booking Calendar / 11.1
Booking Calendar v11.1
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 10.11.3 All 202 releases
booking / includes / _pagination / pagination.php

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

462 lines 14.7 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','.wpbc_rules_pagination_header','.wpbc_rules_pagination_footer',
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-pagination'
96 , trailingslashit( plugins_url( '', __FILE__ ) ) . 'pagination.js' /* wpbc_plugin_url( '/_out/js/code_mirror.js' ) */
97 , array( 'wpbc_all' ), WP_BK_VERSION_NUM, $in_footer );
98
99 /**
100 wp_localize_script( 'wpbc_all', 'wpbc_live_request_obj'
101 , array(
102 'contacts' => '',
103 'reminders' => ''
104 )
105 );
106 */
107 }
108 }
109
110 /** CSS */
111 public function enqueue_css_files( $where_to_load ) {
112
113 if ( ( is_admin() ) && ( in_array( $where_to_load, array( 'admin', 'both' ) ) ) ) {
114
115 wp_enqueue_style( 'wpbc-pagination', trailingslashit( plugins_url( '', __FILE__ ) ) . 'pagination.css', array(), WP_BK_VERSION_NUM );
116 }
117 }
118
119 // </editor-fold>
120
121
122 // <editor-fold defaultstate="collapsed" desc=" /// Templates /// " >
123 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
124 /// Templates
125 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
126
127 public function init_load_templates() {
128
129 add_action( 'wpbc_hook_settings_page_footer', array( $this, 'hook__page_footer_tmpl' ) );
130 }
131
132
133 /**
134 * Templates at footer of page
135 *
136 * @param $page string
137 */
138 public function hook__page_footer_tmpl( $page ){
139
140 if ( $this->get_settings( 'load_on_page' ) === $page ) {
141
142 $this->template__prev_next();
143 $this->template__items_per_page();
144 $this->template__active_page_in_selectbox();
145 }
146 }
147
148 /**
149 * Pagination - " 1 - 9 of many | < > "
150 *
151 * @return void
152 */
153 private function template__prev_next() {
154
155 ?>
156 <script type="text/html" id="tmpl-wpbc_pagination__prev_next">
157 <div class="wpbc_pagination__prev_next wpbc_pagination_el">
158 <#
159 var items = {};
160 items['start'] = ( data.page_active - 1 ) * data.page_items_count + 1;
161 items['end'] = data.page_active * data.page_items_count;
162 items['end'] = ( items['end'] > data.total_count ) ? data.total_count : items['end'];
163 items['total'] = data.total_count;
164 #>
165 <# if ( data.pages_count > 1 ) { #>
166 <?php
167 echo '<div class="wpbc_ui_el">{{items.start}} - {{items.end}} ' . esc_html__( 'of', 'booking' ) . ' {{items.total}}</div>';
168 ?>
169 <# } else { #>
170 <?php
171 echo '<div class="wpbc_ui_el">{{items.start}} - {{items.end}} ' . esc_html__( 'bookings', 'booking' ) . ' </div>';
172 ?>
173 <# } #>
174 <# if ( data.pages_count > 1 ) { #>
175 <div class="wpbc_ui_el">
176 <a class="wpbc_ui_el__a <# if ( 1 == data.page_active ) { #> disabled<# } #>"
177 href="javascript:void(0)"
178 <# if ( 1 != data.page_active ) { #> onclick="javascript:<?php
179 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
180 echo $this->get_settings( 'on_click' ); ?>( parseInt( {{ data.page_active }} ) - 1 );" <# } #>
181 >
182 <?php
183 echo '<i class="menu_icon icon-1x wpbc_icn_chevron_left"></i>';
184 ?>
185 </a>
186 </div>
187 <# } #>
188 <# if ( data.pages_count > 1 ) { #>
189 <div class="wpbc_ui_el">
190 <a class="wpbc_ui_el__a <# if ( data.pages_count == data.page_active ) { #> disabled<# } #>"
191 href="javascript:void(0)"
192 <# if ( data.pages_count != data.page_active ) { #> onclick="javascript:<?php
193 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
194 echo $this->get_settings( 'on_click' ); ?>( parseInt( {{ data.page_active }} ) + 1 );" <# } #>
195 >
196 <?php
197 echo '<i class="menu_icon icon-1x wpbc_icn_chevron_right"></i>';
198 ?>
199 </a>
200 </div>
201 <# } #>
202
203 </div>
204 </script><?php
205
206 }
207
208
209 /**
210 * Pagination - select Number of Items / Page.
211 *
212 * @return void
213 */
214 private function template__items_per_page() {
215 ?>
216 <script type="text/html" id="tmpl-wpbc_pagination_items_per_page">
217 <div class="wpbc_pagination_items_per_page wpbc_pagination_el">
218 <div class="">
219 <label class="wpbc_ui_el"><?php esc_html_e( 'Show', 'booking' ); ?></label>
220 <select class="wpbc_ui_el wpbc_items_per_page" autocomplete="off">
221 <#
222 var my_options_arr = [5, 10, 50, 100];
223 var is_selected = '';
224 _.each(
225 my_options_arr,
226 function ( p_val, p_key, p_data ) {
227 is_selected = '';
228 if ( data.page_items_count == p_val ) {
229 is_selected = ' selected="selected" ';
230 }
231 #><option value="{{p_val}}" {{is_selected}}>{{p_val}}</option><#
232 }
233 );
234 #>
235 </select>
236 <label class="wpbc_ui_el"><?php esc_html_e( 'per page', 'booking' ); ?></label>
237 </div>
238 </div>
239 </script>
240 <?php
241 }
242
243 /**
244 * Pagination - Active page Number in Selectbox
245 *
246 * @return void
247 */
248 private function template__active_page_in_selectbox(){
249 ?>
250 <script type="text/html" id="tmpl-wpbc_pagination_active_page_in_selectbox">
251 <div class="wpbc_pagination_active_page_in_selectbox wpbc_pagination_el">
252 <# if ( data.pages_count > 1 ) { #>
253 <div class="">
254 <label class="wpbc_ui_el"><?php esc_html_e( 'Page', 'booking' ); ?>: </label>
255 <select class="wpbc_ui_el"
256 autocomplete="off"
257 onchange="javascript:<?php
258 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
259 echo $this->get_settings( 'on_click' );
260 ?>( ( parseInt( jQuery( this ).val() ) ) );"
261 >
262 <#
263 var is_selected = '';
264 for ( var pg_num = 1; pg_num <= data.pages_count; pg_num++ ){
265 is_selected = ( pg_num == data.page_active ) ? ' selected="selected" ' : '';
266 #><option value="{{pg_num}}" {{is_selected}}>{{pg_num}}</option><#
267 }
268 #>
269 </select>
270 </div>
271 <# } #>
272 </div>
273 </script>
274 <?php
275 }
276
277
278
279 private function template__pagination_old(){
280
281 // Pagination
282 ?><script type="text/html" id="tmpl-wpbc_pagination">
283 <div class="wpbc-ajax-pagination wpbc-ajax-pagination-container">
284 <# if ( data.pages_count > 1 ) { #>
285 <div class="ui_element">
286 <a class="wpbc_ui_control wpbc_ui_button <# if ( 1 == data.page_active ) { #> disabled<# } #>"
287 href="javascript:void(0)"
288 <# if ( 1 != data.page_active ) { #> onclick="javascript:<?php
289 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
290 echo $this->get_settings( 'on_click' ); ?>( parseInt( {{ data.page_active }} ) - 1 );" <# } #>
291 >
292 <?php esc_html_e('Prev', 'booking'); ?>
293 </a>
294 </div>
295 <# }
296
297 /** Number visible pages (links) that linked to active page, other pages skipped by "..." */
298 var num_closed_steps = 2;
299
300 for ( var pg_num = 1; pg_num <= data.pages_count; pg_num++ ){
301
302 if ( ! (
303 ( data.pages_count > ( num_closed_steps * 4) )
304 && ( pg_num > num_closed_steps )
305 && ( ( data.pages_count - pg_num + 1 ) > num_closed_steps )
306 && ( Math.abs( data.page_active - pg_num ) > num_closed_steps )
307 ) )
308 {
309 #> <div class="ui_element"><a class="wpbc_ui_control wpbc_ui_button <# if ( pg_num == data.page_active ) { #> active<# } #>"
310 href="javascript:void(0)" onclick="javascript:<?php
311 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
312 echo $this->get_settings( 'on_click' ); ?>( {{pg_num}} );" >
313 {{pg_num}}</a></div> <#
314
315 if ( ( data.pages_count > ( num_closed_steps * 4) )
316 && ( (pg_num+1) > num_closed_steps )
317 && ( ( data.pages_count - ( pg_num + 1 ) ) > num_closed_steps )
318 && ( Math.abs(data.page_active - ( pg_num + 1 ) ) > num_closed_steps )
319 ) {
320 #><div class="ui_element"><a class="wpbc_ui_control wpbc_ui_button disabled" href="javascript:void(0);">...</a></div><#
321 }
322 }
323 }
324
325 if ( data.pages_count > 1 ) { #>
326 <div class="ui_element">
327 <a class="wpbc_ui_control wpbc_ui_button <# if ( data.pages_count == data.page_active ) { #> disabled<# } #>"
328 href="javascript:void(0)"
329 <# if ( data.pages_count != data.page_active ) { #> onclick="javascript:<?php
330 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
331 echo $this->get_settings( 'on_click' ); ?>( parseInt( {{ data.page_active }} ) + 1 );" <# } #>
332 >
333 <?php esc_html_e('Next', 'booking'); ?>
334 </a>
335 </div>
336 <# } #>
337 </div>
338 </script><?php
339
340 // Pagination Items per page
341 ?><script type="text/html" id="tmpl-wpbc_pagination_items_per_page">
342 <div class="wpbc-ajax-pagination_items_per_page">
343 <div class="ui_element">
344 <select class="wpbc_items_per_page wpbc_ui_control wpbc_ui_select " autocomplete="off">
345 <#
346 var my_options_arr = [5, 10, 50, 100];
347 var is_selected = '';
348 _.each( my_options_arr, function ( p_val, p_key, p_data ) {
349 is_selected = '';
350 if ( data.page_items_count == p_val ) {
351 is_selected = ' selected="selected" ';
352 }
353 #><option value="{{p_val}}" {{is_selected}}>{{p_val}}</option><#
354 });
355 #>
356 </select>
357 </div>
358 <div class="ui_element">
359 <label class="wpbc_ui_control_label"><?php esc_html_e('per page','booking'); ?></label>
360 </div>
361 <?php
362
363 if (0) {
364 ?>
365 <div class="ui_element">
366 <select class="wpbc_items_sort_type wpbc_ui_control wpbc_ui_select" autocomplete="off">
367 <#
368 my_options_arr = {
369 'ASC': '<?php echo esc_js(__( 'ASC', 'booking' )); ?>',
370 'DESC': '<?php echo esc_js(__( 'DESC', 'booking' )); ?>',
371 };
372 is_selected = '';
373 _.each( my_options_arr, function ( p_val, p_key, p_data ) {
374 is_selected = '';
375 if ( data.sort_type == p_key ) {
376 is_selected = ' selected="selected" ';
377 }
378 #><option value="{{p_key}}" {{is_selected}}>{{p_val}}</option><#
379 });
380 #>
381 </select>
382 </div>
383 <?php } ?>
384 </div>
385 </script><?php
386 }
387
388 // </editor-fold>
389
390
391 /**
392 * Init Pagination on start - define 'load_on_page', 'container', 'on_click' function
393 *
394 * @param array $params = array(
395 'load_on_page' => 'wpbc-settings', // defined at function in_page() {
396 'container' => '.wpbc_settings_pagination', // defined in function content(), like <div class="wpbc_rules_pagination"></div>
397 'on_click' => 'wpbc_pagination_click_page' // onclick = "javascript: wpbc_pagination_click_page( page_active );" - need to define this function in JS file
398 );
399 */
400 public function init( $params = array() ) {
401
402 $defaults = array(
403 'load_on_page' => 'wpbc-settings', // defined at function in_page() {
404 'container' => '.wpbc_settings_pagination', // defined in function content(), like <div class="wpbc_rules_pagination"></div>
405 'on_click' => 'wpbc_pagination_click_page' // onclick = "javascript: wpbc_pagination_click_page( page_active );" - need to define this function in JS file
406 );
407 $this->settings = wp_parse_args( $params, $defaults );
408
409 $this->init_load_templates();
410 }
411
412
413 /**
414 * Show pagination
415 *
416 * @param array $params = array(
417 'page_active' => 1,
418 'pages_count' => 10
419 )
420 */
421 public function show( $params = array() ) {
422 $defaults = array(
423 'page_active' => 1,
424 'pages_count' => 1,
425 'total_count' => 1
426 );
427 $params = wp_parse_args( $params, $defaults );
428 ?>
429 <script type="text/javascript">
430
431 jQuery( document ).ready( function () {
432
433 wpbc_pagination_echo(
434 '<?php echo esc_attr( $this->get_settings( 'container' ) ); ?>',
435 '<?php echo esc_attr( $this->get_settings( 'container_header' ) ); ?>',
436 '<?php echo esc_attr( $this->get_settings( 'container_footer' ) ); ?>',
437 <?php
438 echo wp_json_encode(
439 array(
440 'page_active' => $params['page_active'],
441 'pages_count' => $params['pages_count'],
442 'total_count' => $params['total_count'],
443 )
444 );
445 ?>
446 );
447 } );
448 </script>
449 <?php
450 }
451 }
452
453 /**
454 * Just for loading CSS and JavaScript files for all Settings pages
455 */
456 if ( true ) {
457 $wpbc_js_css_loading = new WPBC_Pagination;
458 $wpbc_js_css_loading->init_load_css_js();
459 }
460
461
462 //TODO: delete ../email-reminders/_src/css/o-pagination.css