PluginProbe
Booking Calendar / 10.1.3
Booking Calendar v10.1.3
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.1.3, at includes/_pagination/pagination.php

318 lines 10.1 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-global-vars' ), WP_BK_VERSION_NUM, $in_footer );
96 wp_enqueue_script( 'wpbc-pagination'
97 , trailingslashit( plugins_url( '', __FILE__ ) ) . 'pagination.js' /* wpbc_plugin_url( '/_out/js/codemirror.js' ) */
98 , array( 'wpbc-global-vars' ), WP_BK_VERSION_NUM, $in_footer );
99
100 /**
101 wp_localize_script( 'wpbc-global-vars', '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 echo $this->get_settings( 'on_click' ); ?>( parseInt( {{ data.page_active }} ) - 1 );" <# } #>
158 >
159 <?php _e('Prev', 'booking'); ?>
160 </a>
161 </div>
162 <# }
163
164 /** Number visible pages (links) that linked to active page, other pages skipped by "..." */
165 var num_closed_steps = 2;
166
167 for ( var pg_num = 1; pg_num <= data.pages_count; pg_num++ ){
168
169 if ( ! (
170 ( data.pages_count > ( num_closed_steps * 4) )
171 && ( pg_num > num_closed_steps )
172 && ( ( data.pages_count - pg_num + 1 ) > num_closed_steps )
173 && ( Math.abs( data.page_active - pg_num ) > num_closed_steps )
174 ) )
175 {
176 #> <div class="ui_element"><a class="wpbc_ui_control wpbc_ui_button <# if ( pg_num == data.page_active ) { #> active<# } #>"
177 href="javascript:void(0)" onclick="javascript:<?php echo $this->get_settings( 'on_click' ); ?>( {{pg_num}} );" >
178 {{pg_num}}</a></div> <#
179
180 if ( ( data.pages_count > ( num_closed_steps * 4) )
181 && ( (pg_num+1) > num_closed_steps )
182 && ( ( data.pages_count - ( pg_num + 1 ) ) > num_closed_steps )
183 && ( Math.abs(data.page_active - ( pg_num + 1 ) ) > num_closed_steps )
184 ) {
185 #><div class="ui_element"><a class="wpbc_ui_control wpbc_ui_button disabled" href="javascript:void(0);">...</a></div><#
186 }
187 }
188 }
189
190 if ( data.pages_count > 1 ) { #>
191 <div class="ui_element">
192 <a class="wpbc_ui_control wpbc_ui_button <# if ( data.pages_count == data.page_active ) { #> disabled<# } #>"
193 href="javascript:void(0)"
194 <# if ( data.pages_count != data.page_active ) { #> onclick="javascript:<?php echo $this->get_settings( 'on_click' ); ?>( parseInt( {{ data.page_active }} ) + 1 );" <# } #>
195 >
196 <?php _e('Next', 'booking'); ?>
197 </a>
198 </div>
199 <# } #>
200 </div>
201 </script><?php
202
203 // Pagination Items per page
204 ?><script type="text/html" id="tmpl-wpbc_pagination_items_per_page">
205 <div class="wpbc-ajax-pagination_items_per_page">
206 <div class="ui_element">
207 <select class="wpbc_items_per_page wpbc_ui_control wpbc_ui_select " autocomplete="off">
208 <#
209 var my_options_arr = [5, 10, 50, 100];
210 var is_selected = '';
211 _.each( my_options_arr, function ( p_val, p_key, p_data ) {
212 is_selected = '';
213 if ( data.page_items_count == p_val ) {
214 is_selected = ' selected="selected" ';
215 }
216 #><option value="{{p_val}}" {{is_selected}}>{{p_val}}</option><#
217 });
218 #>
219 </select>
220 </div>
221 <div class="ui_element">
222 <label class="wpbc_ui_control_label"><?php _e('per page','booking') ?></label>
223 </div>
224 <?php
225
226 if (0) {
227 ?>
228 <div class="ui_element">
229 <select class="wpbc_items_sort_type wpbc_ui_control wpbc_ui_select" autocomplete="off">
230 <#
231 my_options_arr = {
232 'ASC': '<?php echo esc_js(__( 'ASC', 'booking' )); ?>',
233 'DESC': '<?php echo esc_js(__( 'DESC', 'booking' )); ?>',
234 };
235 is_selected = '';
236 _.each( my_options_arr, function ( p_val, p_key, p_data ) {
237 is_selected = '';
238 if ( data.sort_type == p_key ) {
239 is_selected = ' selected="selected" ';
240 }
241 #><option value="{{p_key}}" {{is_selected}}>{{p_val}}</option><#
242 });
243 #>
244 </select>
245 </div>
246 <?php } ?>
247 </div>
248 </script><?php
249 }
250
251 // </editor-fold>
252
253
254 /**
255 * Init Pagination on start - define 'load_on_page', 'container', 'on_click' function
256 *
257 * @param array $params = array(
258 'load_on_page' => 'wpbc-settings', // defined at function in_page() {
259 'container' => '.wpbc_settings_pagination', // defined in function content(), like <div class="wpbc_rules_pagination"></div>
260 'on_click' => 'wpbc_pagination_click_page' // onclick = "javascript: wpbc_pagination_click_page( page_active );" - need to define this function in JS file
261 );
262 */
263 public function init( $params = array() ) {
264
265 $defaults = array(
266 'load_on_page' => 'wpbc-settings', // defined at function in_page() {
267 'container' => '.wpbc_settings_pagination', // defined in function content(), like <div class="wpbc_rules_pagination"></div>
268 'on_click' => 'wpbc_pagination_click_page' // onclick = "javascript: wpbc_pagination_click_page( page_active );" - need to define this function in JS file
269 );
270 $this->settings = wp_parse_args( $params, $defaults );
271
272 $this->init_load_templates();
273 }
274
275
276 /**
277 * Show pagination
278 *
279 * @param array $params = array(
280 'page_active' => 1,
281 'pages_count' => 10
282 )
283 */
284 public function show( $params = array() ) {
285 $defaults = array(
286 'page_active' => 1,
287 'pages_count' => 1
288 );
289 $params = wp_parse_args( $params, $defaults );
290 ?>
291 <script type="text/javascript">
292
293 jQuery( document ).ready( function (){
294
295 wpbc_pagination_echo( '<?php echo $this->get_settings( 'container' ); ?>', <?php
296 echo wp_json_encode(
297 array(
298 'page_active' => $params['page_active'],
299 'pages_count' => $params['pages_count']
300 )
301 );
302 ?> );
303 } );
304 </script>
305 <?php
306 }
307 }
308
309 /**
310 * Just for loading CSS and JavaScript files for all Settings pages
311 */
312 if ( true ) {
313 $js_css_loading = new WPBC_Pagination;
314 $js_css_loading->init_load_css_js();
315 }
316
317
318 //TODO: delete ../email-reminders/_src/css/o-pagination.css