PluginProbe
Booking Calendar / 10.11.2
Booking Calendar v10.11.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 / ui_settings / class-page-structure.php

class-page-structure.php in Booking Calendar 10.11.2, at includes/ui_settings/class-page-structure.php

446 lines 20.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Page Structure in Admin Panel
4 *
5 * @version 1.2
6 * @package Any
7 * @category Page Structure in Admin Panel
8 * @author wpdevelop
9 *
10 * @web-site https://wpbookingcalendar.com/
11 * @email info@wpbookingcalendar.com
12 *
13 * @modified 2024-12-23, 2015-11-02
14 */
15
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit; // Exit, if accessed directly.
18 }
19
20 // FixIn: 11.0.0.1.
21
22 /**
23 * Define Settings Page Structure
24 */
25 abstract class WPBC_Page_Structure extends WPBC_Menu_Structure {
26
27 /**
28 * Constructor
29 */
30 public function __construct() {
31
32 parent::__construct();
33
34 // This Hook fire in the class WPBC_Admin_Menus for showing page content of specific menu.
35 add_action( 'wpbc_page_structure_show', array( $this, 'content_structure' ) );
36 }
37
38 // -----------------------------------------------------------------------------------------------------------------
39 // Abstract Methods
40 // -----------------------------------------------------------------------------------------------------------------
41
42 /**
43 * Define slug in what menu to show this page. // Parameter relative: $_GET['page'].
44 *
45 * @return string
46 *
47 * Example:
48 *
49 * return 'wpbc-settings';
50 */
51 abstract public function in_page();
52
53 /**
54 * Define Tabs and Subtabs of this Admin Page
55 *
56 * @return array();
57 *
58 * Example:
59 *
60 * $tabs = array();
61 * $tabs[ 'form' ] = array(
62 * 'title' => __('Form','booking') // Title of TAB
63 * , 'hint' => __('Customization of Form Fields', 'booking') // Hint
64 * , 'page_title' =>ucwords( __('Form fields', 'booking') ) // Title of Page
65 * //, 'link' => '' // Can be skiped, then generated link based on Page and Tab tags. Or can be extenral link
66 * //, 'position' => '' // 'left' || 'right' || ''
67 * //, 'css_classes' => '' // CSS class(es)
68 * //, 'icon' => '' // Icon - link to the real PNG img
69 * , 'font_icon' => 'wpbc_icn_draw' // CSS definition of forn Icon
70 * , 'default' => false // Is this tab activated by default or not: true || false.
71 * , 'disabled' => false // Is this tab disbaled: true || false.
72 * , 'hided' => false // Is this tab hided: true || false.
73 * , 'subtabs' => array()
74 *
75 * );
76 * $tabs[ 'upgrade' ] = array(
77 * 'title' => __('Upgrade','booking') // Title of TAB
78 * , 'hint' => __('Upgrade to higher version', 'booking') // Hint
79 * //, 'page_title' => __('Upgrade', 'booking') // Title of Page
80 * , 'link' => 'http://server.com/' // Can be skiped, then generated link based on Page and Tab tags. Or can be extenral link
81 * , 'position' => 'right' // 'left' || 'right' || ''
82 * //, 'css_classes' => '' // CSS class(es)
83 * //, 'icon' => '' // Icon - link to the real PNG img
84 * , 'font_icon' => 'wpbc_icn_auto_graph'// CSS definition of forn Icon
85 * //, 'default' => false // Is this tab activated by default or not: true || false.
86 * //, 'subtabs' => array()
87 *
88 * );
89 *
90 * $subtabs = array();
91 *
92 * $subtabs['fields'] = array(
93 * 'type' => 'subtab' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html'
94 * , 'title' => __('Form','booking') // Title of TAB
95 * , 'page_title' => __('Form Settings', 'booking') // Title of Page
96 * , 'hint' => __('Customization of Form Settings', 'booking') // Hint
97 * , 'link' => '' // link
98 * , 'position' => '' // 'left' || 'right' || ''
99 * , 'css_classes' => '' // CSS class(es)
100 * //, 'icon' => 'https://www.paypalobjects.com/webstatic/icon/pp258.png' // Icon - link to the real PNG img
101 * //, 'font_icon' => 'wpbc_icn_payment' // CSS definition of Font Icon
102 * , 'default' => true // Is this sub tab activated by default or not: true || false.
103 * , 'disabled' => false // Is this sub tab deactivated: true || false.
104 * , 'checkbox' => false // or definition array for specific checkbox: array( 'checked' => true, 'name' => 'feature1_active_status' )
105 * , 'content' => 'content' // Function to load as conten of this TAB
106 * );
107 *
108 * $subtabs['form-separator'] = array(
109 * 'type' => 'separator' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html'
110 * );
111 * $subtabs['form-goto'] = array(
112 * 'type' => 'goto-link' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html'
113 * , 'title' =>ucwords( __('Form fields', 'booking') ) // Title of TAB
114 * , 'hint' => '' // Hint
115 * , 'show_section' => 'id_of_show_section' // ID of HTML element, for scroll to.
116 * );
117 *
118 * ob_start();
119 * ...
120 * $html_element_data = ob_get_clean();
121 *
122 * $subtabs['form-selection'] = array(
123 * 'type' => 'html' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html'
124 * , 'html' => $html_element_data
125 * );
126 *
127 * $subtabs['form-save'] = array(
128 * 'type' => 'button' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html'
129 * , 'title' => __('Save Changes','booking') // Title of TAB
130 * , 'form' => 'wpbc_form' // Required for 'button'! Name of Form to submit
131 * );
132 *
133 * $tabs[ 'form' ][ 'subtabs' ] = $subtabs;
134 *
135 * return $tabs;
136 */
137 abstract public function tabs();
138
139 /**
140 * Show Content of this page - Main function.
141 *
142 * In top of this function have to be checking ubout Update (saving POST request).
143 *
144 * Exmaple:
145 *
146 * // S u b m i t ///////////////////////////////////////////////////////
147 *
148 * $this_submit_form = 'wpbc_emails_toolbar'; // Define form name
149 *
150 * // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
151 * if ( isset( $_POST['is_form_sbmitted_'. $this_submit_form ] ) ) {
152 *
153 * // Check N o n c e
154 * check_admin_referer( 'wpbc_settings_page_' . $this_submit_form ); // Its stop show anything on submiting, if its not refear to the original page
155 *
156 * // Make Update of settings
157 * $edit_field_data = $this->update_wpbc_emails_toolbar( $menu_slug );
158 * }
159 */
160 abstract public function content();
161
162 /**
163 * Child classes ovveride it for auto update / save options in main form
164 *
165 * @return void
166 */
167 public function maybe_update() {}
168
169
170 // -----------------------------------------------------------------------------------------------------------------
171 // C O N T E N T
172 // -----------------------------------------------------------------------------------------------------------------
173
174 /**
175 * General Page Structure
176 *
177 * @param string $page_tag - its the same that return $this->in_page ().
178 */
179 public function content_structure( $page_tag ) {
180
181 // -------------------------------------------------------------------------------------------------------------
182 // Checking if this page - A C T I V E
183 // -------------------------------------------------------------------------------------------------------------
184 if ( ! $this->is_page_activated() ) {
185 return false;
186 }
187
188 $active_page_tab = $this->get_active__tab__tag();
189 $active_page_subtab = $this->get_active__subtab__tag();
190
191 // Fires Before showing settings Content page. Used in MultiUser version for blocking access to some pages.
192 $is_show_this_page = apply_filters( 'wpbc_before_showing_settings_page_is_show_page', true, $page_tag, $active_page_tab, $active_page_subtab );
193 if ( false === $is_show_this_page ) {
194 return false;
195 }
196
197 $this->update_nav_tabs_structure( $page_tag, $active_page_tab, $active_page_subtab );
198
199 // -------------------------------------------------------------------------------------------------------------
200 // -- U p d a t e --
201 // -------------------------------------------------------------------------------------------------------------
202 $this->maybe_update();
203
204 // -------------------------------------------------------------------------------------------------------------
205 // -- T e m p l a t e --
206 // -------------------------------------------------------------------------------------------------------------
207
208 // Hook: Fires Before showing settings Content page.
209 do_action( 'wpbc_before_settings_content', $page_tag, $active_page_tab, $active_page_subtab );
210
211
212 $template_params_arr = array(
213 'active_page' => $page_tag,
214 'active_tab' => $active_page_tab,
215 'active_subtab' => $active_page_subtab,
216 'page_structure_obj' => $this,
217 );
218 $settings_templates = new WPBC_Settings_Page_Parts( $template_params_arr );
219
220 // ---------------------------------------------------------------------------------------------------------
221 // Template Header
222 // ---------------------------------------------------------------------------------------------------------
223 $settings_templates->template_header();
224
225 wp_nonce_field( 'wpbc_ajax_admin_nonce', 'wpbc_admin_panel_nonce', true, true ); // Nonce.
226
227 // ---------------------------------------------------------------------------------------------------------
228 // Content.
229 // ---------------------------------------------------------------------------------------------------------
230 if ( ( isset( $this->current_page_params['subtab'] ) ) && ( isset( $this->current_page_params['subtab']['content'] ) ) ) {
231 call_user_func( array( $this, $this->current_page_params['subtab']['content'] ) );
232 } elseif ( ( isset( $this->current_page_params['tab'] ) ) && ( isset( $this->current_page_params['tab']['content'] ) ) ) {
233 call_user_func( array( $this, $this->current_page_params['tab']['content'] ) );
234 } else {
235 $this->content();
236 }
237
238 do_action( 'wpbc_show_settings_content', $page_tag, $active_page_tab, $active_page_subtab ); // Hook.
239
240 // ---------------------------------------------------------------------------------------------------------
241 // Template Footer
242 // ---------------------------------------------------------------------------------------------------------
243 $settings_templates->template_footer();
244
245 do_action( 'wpbc_after_settings_content', $page_tag, $active_page_tab, $active_page_subtab ); // Hook: Fires After showing settings Content page.
246 }
247
248
249 // -----------------------------------------------------------------------------------------------------------------
250 // == Support ==
251 // -----------------------------------------------------------------------------------------------------------------
252
253 /**
254 * Update structure of self::$nav_tabs with 'is_active' and 'url' parameters.
255 * We can do this here, because this function executed at step of showing content, and we know about all the structure of the menus, already.
256 *
257 * Based on URL: /admin.php?page=wpbc-settings&tab=email&subtab=new-visitor
258 *
259 * @param string $page_tag - 'wpbc-settings'.
260 * @param string $active_page_tab - 'email'.
261 * @param string $active_page_subtab - 'new-visitor'.
262 *
263 * @return bool
264 */
265 private function update_nav_tabs_structure( $page_tag, $active_page_tab, $active_page_subtab ) {
266
267 if ( empty( self::$nav_tabs ) ) {
268 return false;
269 }
270
271 // Menu Pages [Bookings, Resources, Prices, Settings ].
272 foreach ( self::$nav_tabs as $nav_page_tag => $nav_page_arr ) {
273
274 // Tabs [ General, Emails, ... ].
275 foreach ( self::$nav_tabs[ $nav_page_tag ] as $nav_tab_tag => $nav_tab_arr ) {
276
277 self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['is_active'] = false;
278 self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['url'] = ( ! empty( self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['link'] ) )
279 ? self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['link']
280 : $this->get_tab_url( $nav_page_tag, $nav_tab_tag );
281 // Inside of this page 'wpbc-settings' ?
282 if ( $nav_page_tag === $page_tag ) {
283
284 // Tab not selected -> clicked on Left menu only, but this is 'DEFAULT' TAB, so true.
285 if ( ( empty( $active_page_tab ) ) && ( ! empty( self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['default'] ) ) ) {
286 self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['is_active'] = true;
287 }
288
289 // Page and Tab clicked !
290 if ( ( $nav_page_tag === $page_tag ) && ( $active_page_tab === $nav_tab_tag ) ) {
291 self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['is_active'] = true;
292 }
293 }
294
295 if ( ! empty( self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['subtabs'] ) ) {
296 // SubTabs e.g.: [ "New booking", "Approved", ... ].
297 foreach ( self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['subtabs'] as $nav_subtab_tag => $nav_subtab_arr ) {
298
299 self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['subtabs'][ $nav_subtab_tag ]['is_active'] = false;
300
301 self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['subtabs'][ $nav_subtab_tag ]['url'] = ( ! empty( self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['subtabs'][ $nav_subtab_tag ]['link'] ) )
302 ? self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['subtabs'][ $nav_subtab_tag ]['link']
303 : $this->get_tab_url( $nav_page_tag, $nav_tab_tag, $nav_subtab_tag );
304 // We know that this TAB is active.
305 if ( ! empty( self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['is_active'] ) ) {
306
307 // SubTab not selected -> clicked on Left menu and Tab only, but not clicked on submenu (e.g. Stripe or "approved email") and if we have this is 'DEFAULT' TAB, so true.
308 if ( ( empty( $active_page_subtab ) ) && ( ! empty( self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['subtabs'][ $nav_subtab_tag ]['default'] ) ) ) {
309 self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['subtabs'][ $nav_subtab_tag ]['is_active'] = true;
310 }
311
312 // Page and SubTab clicked !
313 if ( $active_page_subtab === $nav_subtab_tag ) {
314 self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['subtabs'][ $nav_subtab_tag ]['is_active'] = true;
315 }
316 }
317 }
318 }
319 }
320 }
321 return true;
322 }
323
324 /**
325 * Get current active TAB 'Tag'
326 *
327 * @return mixed|string
328 */
329 protected function get_active__tab__tag() {
330
331 $active_page_tab = '';
332
333 if ( ( isset( $this->current_page_params['tab'] ) ) && ( ! empty( $this->current_page_params['tab']['tag'] ) ) ) {
334 $active_page_tab = $this->current_page_params['tab']['tag'];
335 }
336
337 return $active_page_tab;
338 }
339
340 /**
341 * Get current active SubTAB 'Tag'
342 *
343 * @return mixed|string
344 */
345 protected function get_active__subtab__tag() {
346
347 $active_page_subtab = '';
348
349 if ( ( isset( $this->current_page_params['subtab'] ) ) && ( ! empty( $this->current_page_params['subtab']['tag'] ) ) ) {
350 $active_page_subtab = $this->current_page_params['subtab']['tag'];
351 }
352
353 return $active_page_subtab;
354 }
355
356 /**
357 * Get Option. Check if this defined in Tabs or Subtabs array Otherwise return false.
358 *
359 * @param string $option_name - name of the option, like 'is_use_new_settings_skin'.
360 *
361 * @return false|mixed
362 *
363 * Example: $is_use_new_settings_skin = $this->is_use_option__in_subtabs( 'is_use_new_settings_skin' );
364 */
365 public function is_use_option__in_subtabs_or_tabs( $option_name ) {
366
367 // Check if this otion defined in tabs or 'subtabs' ?
368 $is_use_option = $this->is_use_option__in_subtabs( $option_name );
369
370 // If this option not defined in 'subtabs', then we check it in 'tab'.
371 if ( false === $is_use_option ) {
372 $is_use_option = ( $this->is_use_option__in_tabs( $option_name ) );
373 }
374
375 return $is_use_option;
376 }
377
378 /**
379 * Get Option. Check if this defined in subtabs array Otherwise return false.
380 *
381 * @param string $option_name - name of the option, like 'is_use_new_settings_skin'.
382 *
383 * @return false|mixed
384 *
385 * Example: $is_use_new_settings_skin = $this->is_use_option__in_subtabs( 'is_use_new_settings_skin' );
386 */
387 public function is_use_option__in_subtabs( $option_name ) {
388
389 // Check if this otion defined in subtabs ?
390 $is_use_option = ( ( isset( $this->current_page_params['subtab'] ) ) && ( ! empty( $this->current_page_params['subtab'][ $option_name ] ) ) )
391 ? $this->current_page_params['subtab'][ $option_name ]
392 : false;
393
394 return $is_use_option;
395 }
396
397 /**
398 * Get Option. Check if this defined in btabs array Otherwise return false.
399 *
400 * @param string $option_name - name of the option, like 'is_use_new_settings_skin'.
401 *
402 * @return false|mixed
403 *
404 * Example: $is_use_new_settings_skin = $this->is_use_option__in_subtabs( 'is_use_new_settings_skin' );
405 */
406 public function is_use_option__in_tabs( $option_name ) {
407
408 // Check if this otion defined in subtabs ?
409 $is_use_option = ( ( isset( $this->current_page_params['tab'] ) ) && ( ! empty( $this->current_page_params['tab'][ $option_name ] ) ) )
410 ? $this->current_page_params['tab'][ $option_name ]
411 : false;
412
413 return $is_use_option;
414 }
415
416 /**
417 * Get Navigation path for header, if applicable.
418 * Used in Setup Wizard page.
419 *
420 * @return false|array
421 */
422 protected function is_use_navigation_path_arr() {
423
424 // Use Top line as Path in Setup Wizard page // FixIn: 10.4.0.2.
425 $is_use_navigation_path_arr = $this->is_use_option__in_subtabs( 'is_use_navigation_path' );
426
427 return $is_use_navigation_path_arr;
428 }
429
430 /**
431 * Get URL of settings page, based on Page Slug and Tab Slug e.g. page=wpbc-settings&tab=email&subtab=approved
432 *
433 * @param string $page_tag - e.g. 'wpbc-settings'.
434 * @param string $tab_name - e.g. 'email'.
435 * @param string $subtab_name ( Optional ) - e.g. 'approved'.
436 *
437 * @return string - Escaped URL to plugin page.
438 */
439 private function get_tab_url( $page_tag, $tab_name, $subtab_name = false ) {
440 if ( false === $subtab_name ) {
441 return esc_url( admin_url( add_query_arg( array( 'page' => $page_tag, $this->tags['tab'] => $tab_name ), 'admin.php' ) ) );
442 } else {
443 return esc_url( admin_url( add_query_arg( array( 'page' => $page_tag, $this->tags['tab'] => $tab_name, $this->tags['subtab'] => $subtab_name ), 'admin.php' ) ) );
444 }
445 }
446 }