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 / ui_settings / class-page-structure.php

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

400 lines 17.1 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 /**
21 * == All Page Parameters ==
22 *
23 * TODO Refactorig: Continue work with description of the: List of all parameters, that possible to use in public function tabs() { ... }
24
25 'is_default_full_screen' => false, // true | false. Default: false.
26 'right_vertical_sidebar__is_show' => false, // true | false. Default: false.
27 'right_vertical_sidebar__default_view_mode' => 'max', // '' | 'min' | 'compact' | 'max' | 'none'. Default: ''.
28 'left_navigation__default_view_mode' => 'max', // '' | 'min' | 'compact' | 'max' | 'none'. Default: ''.
29 'right_vertical_sidebar_compact__is_show' => false, // true | false. Default: false.
30
31 // TODO: recheck functionality and ability to use:
32
33 'is_show_top_path' => true, // true | false. By default value is: false.
34 'is_show_top_navigation' => false, // true | false. By default value is: false.
35 'title' => __( 'Booking Form Builder', 'booking' ), // Title of TAB //FixIn: 9.8.15.2.2.
36 'hint' => __( 'Define available days', 'booking' ), // Hint.
37 'page_title' => __( 'Booking Form Builder', 'booking' ), // Title of Page.
38 'link' => '', // Can be skiped, then generated link based on Page and Tab tags. Or can be extenral link.
39 'position' => '', // 'left' / 'right' / ''.
40 'css_classes' => '', // CSS c l a s s(es).
41 'icon' => '', // Icon - link to the real PNG img.
42 'font_icon' => 'wpbc_icn_flip_x0 wpbc-bi-input-cursor-text', // 'wpbc_icn_free_cancellation' // CSS definition of forn Icon.
43 'font_icon_right' => 'wpbc-bi-asterisk',
44 'default' => false, // Is this tab activated by default or not: true || false.
45 'disabled' => false, // Is this tab disbaled: true || false.
46 'hided' => false, // Is this tab hided: true || false.
47 'subtabs' => array(),
48 'folder_style' => 'order:11;',
49
50 */
51
52
53 /**
54 * Define Settings Page Structure
55 */
56 abstract class WPBC_Page_Structure extends WPBC_Menu_Structure {
57
58 // FixIn: 11.0.0.1.
59
60 /**
61 * Constructor
62 */
63 public function __construct() {
64
65 parent::__construct();
66
67 // This Hook fire in the class WPBC_Admin_Menus for showing page content of specific menu.
68 add_action( 'wpbc_page_structure_show', array( $this, 'content_structure' ) );
69
70 add_filter( 'admin_body_class', array( $this, 'wpbc_add_admin_body_class' ) );
71 }
72
73
74 /**
75 * Set the wpbc_admin class to body.
76 *
77 * @param bool $classes Body classes.
78 *
79 * @return array
80 */
81 public function wpbc_add_admin_body_class( $classes ) {
82
83
84 if ( $this->is_page_activated() ) {
85 $classes .= ' wpbc_admin';
86 }
87
88 return $classes;
89 }
90
91
92 // -----------------------------------------------------------------------------------------------------------------
93 // Abstract Methods
94 // -----------------------------------------------------------------------------------------------------------------
95 // FixIn: 10.11.4.4. Removed abstarct classes that exists in the parent class.
96
97 /**
98 * Child classes ovveride it for auto update / save options in main form
99 *
100 * @return void
101 */
102 public function maybe_update() {}
103
104
105 /**
106 * Child classes ovveride -- show vertical "Right Sidebar Content".
107 * // FixIn: 10.14.1.3.
108 *
109 * @return void
110 */
111 public function right_sidebar_content(){}
112
113
114
115 /**
116 * Child classes ovveride -- show vertical "Right Sidebar Content - Compact".
117 * // FixIn: 10.14.1.3.
118 *
119 * @return void
120 */
121 public function right_sidebar_compact_content(){}
122
123
124 // -----------------------------------------------------------------------------------------------------------------
125 // C O N T E N T
126 // -----------------------------------------------------------------------------------------------------------------
127
128 /**
129 * General Page Structure
130 *
131 * @param string $page_tag - its the same that return $this->in_page ().
132 */
133 public function content_structure( $page_tag ) {
134
135 // -------------------------------------------------------------------------------------------------------------
136 // Checking if this page - A C T I V E
137 // -------------------------------------------------------------------------------------------------------------
138 if ( ! $this->is_page_activated() ) {
139 return false;
140 }
141
142 $active_page_tab = $this->get_active__tab__tag();
143 $active_page_subtab = $this->get_active__subtab__tag();
144
145 // Fires Before showing settings Content page. Used in MultiUser version for blocking access to some pages.
146 $is_show_this_page = apply_filters( 'wpbc_before_showing_settings_page_is_show_page', true, $page_tag, $active_page_tab, $active_page_subtab );
147 if ( false === $is_show_this_page ) {
148 return false;
149 }
150
151 $this->update_nav_tabs_structure( $page_tag, $active_page_tab, $active_page_subtab );
152
153 // -------------------------------------------------------------------------------------------------------------
154 // -- U p d a t e --
155 // -------------------------------------------------------------------------------------------------------------
156 $this->maybe_update();
157
158 // -------------------------------------------------------------------------------------------------------------
159 // -- T e m p l a t e --
160 // -------------------------------------------------------------------------------------------------------------
161
162 // Hook: Fires Before showing settings Content page.
163 do_action( 'wpbc_before_settings_content', $page_tag, $active_page_tab, $active_page_subtab );
164
165
166 $template_params_arr = array(
167 'active_page' => $page_tag,
168 'active_tab' => $active_page_tab,
169 'active_subtab' => $active_page_subtab,
170 'page_structure_obj' => $this,
171 );
172 $settings_templates = new WPBC_Settings_Page_Parts( $template_params_arr );
173
174 // ---------------------------------------------------------------------------------------------------------
175 // Template Header
176 // ---------------------------------------------------------------------------------------------------------
177 $settings_templates->template_header();
178
179 wp_nonce_field( 'wpbc_ajax_admin_nonce', 'wpbc_admin_panel_nonce', true, true ); // Nonce.
180
181 // ---------------------------------------------------------------------------------------------------------
182 // Content.
183 // ---------------------------------------------------------------------------------------------------------
184 if ( ( isset( $this->current_page_params['subtab'] ) ) && ( isset( $this->current_page_params['subtab']['content'] ) ) ) {
185 call_user_func( array( $this, $this->current_page_params['subtab']['content'] ) );
186 } elseif ( ( isset( $this->current_page_params['tab'] ) ) && ( isset( $this->current_page_params['tab']['content'] ) ) ) {
187 call_user_func( array( $this, $this->current_page_params['tab']['content'] ) );
188 } else {
189 $this->content();
190 }
191
192 do_action( 'wpbc_show_settings_content', $page_tag, $active_page_tab, $active_page_subtab ); // Hook.
193
194 // ---------------------------------------------------------------------------------------------------------
195 // Template Footer
196 // ---------------------------------------------------------------------------------------------------------
197 $settings_templates->template_footer();
198
199 do_action( 'wpbc_after_settings_content', $page_tag, $active_page_tab, $active_page_subtab ); // Hook: Fires After showing settings Content page.
200 }
201
202
203 // -----------------------------------------------------------------------------------------------------------------
204 // == Support ==
205 // -----------------------------------------------------------------------------------------------------------------
206
207 /**
208 * Update structure of self::$nav_tabs with 'is_active' and 'url' parameters.
209 * 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.
210 *
211 * Based on URL: /admin.php?page=wpbc-settings&tab=email&subtab=new-visitor
212 *
213 * @param string $page_tag - 'wpbc-settings'.
214 * @param string $active_page_tab - 'email'.
215 * @param string $active_page_subtab - 'new-visitor'.
216 *
217 * @return bool
218 */
219 private function update_nav_tabs_structure( $page_tag, $active_page_tab, $active_page_subtab ) {
220
221 if ( empty( self::$nav_tabs ) ) {
222 return false;
223 }
224
225 // Menu Pages [Bookings, Resources, Prices, Settings ].
226 foreach ( self::$nav_tabs as $nav_page_tag => $nav_page_arr ) {
227
228 // Tabs [ General, Emails, ... ].
229 foreach ( self::$nav_tabs[ $nav_page_tag ] as $nav_tab_tag => $nav_tab_arr ) {
230
231 self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['is_active'] = false;
232 self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['url'] = ( ! empty( self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['link'] ) )
233 ? self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['link']
234 : $this->get_tab_url( $nav_page_tag, $nav_tab_tag );
235 // Inside of this page 'wpbc-settings' ?
236 if ( $nav_page_tag === $page_tag ) {
237
238 // Tab not selected -> clicked on Left menu only, but this is 'DEFAULT' TAB, so true.
239 if ( ( empty( $active_page_tab ) ) && ( ! empty( self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['default'] ) ) ) {
240 self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['is_active'] = true;
241 }
242
243 // Page and Tab clicked !
244 if ( ( $nav_page_tag === $page_tag ) && ( $active_page_tab === $nav_tab_tag ) ) {
245 self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['is_active'] = true;
246 }
247 }
248
249 if ( ! empty( self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['subtabs'] ) ) {
250 // SubTabs e.g.: [ "New booking", "Approved", ... ].
251 foreach ( self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['subtabs'] as $nav_subtab_tag => $nav_subtab_arr ) {
252
253 self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['subtabs'][ $nav_subtab_tag ]['is_active'] = false;
254
255 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'] ) )
256 ? self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['subtabs'][ $nav_subtab_tag ]['link']
257 : $this->get_tab_url( $nav_page_tag, $nav_tab_tag, $nav_subtab_tag );
258 // We know that this TAB is active.
259 if ( ! empty( self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['is_active'] ) ) {
260
261 // 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.
262 if ( ( empty( $active_page_subtab ) ) && ( ! empty( self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['subtabs'][ $nav_subtab_tag ]['default'] ) ) ) {
263 self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['subtabs'][ $nav_subtab_tag ]['is_active'] = true;
264 }
265
266 // Page and SubTab clicked !
267 if ( $active_page_subtab === $nav_subtab_tag ) {
268 self::$nav_tabs[ $nav_page_tag ][ $nav_tab_tag ]['subtabs'][ $nav_subtab_tag ]['is_active'] = true;
269 }
270 }
271 }
272 }
273 }
274 }
275 return true;
276 }
277
278 /**
279 * Get current active TAB 'Tag'
280 *
281 * @return mixed|string
282 */
283 protected function get_active__tab__tag() {
284
285 $active_page_tab = '';
286
287 if ( ( isset( $this->current_page_params['tab'] ) ) && ( ! empty( $this->current_page_params['tab']['tag'] ) ) ) {
288 $active_page_tab = $this->current_page_params['tab']['tag'];
289 }
290
291 return $active_page_tab;
292 }
293
294 /**
295 * Get current active SubTAB 'Tag'
296 *
297 * @return mixed|string
298 */
299 protected function get_active__subtab__tag() {
300
301 $active_page_subtab = '';
302
303 if ( ( isset( $this->current_page_params['subtab'] ) ) && ( ! empty( $this->current_page_params['subtab']['tag'] ) ) ) {
304 $active_page_subtab = $this->current_page_params['subtab']['tag'];
305 }
306
307 return $active_page_subtab;
308 }
309
310 /**
311 * Get Option. Check if this defined in Tabs or Subtabs array Otherwise return false.
312 *
313 * @param string $option_name - name of the option, like 'is_use_new_settings_skin'.
314 *
315 * @return false|mixed
316 *
317 * Example: $is_use_new_settings_skin = $this->is_use_option__in_subtabs( 'is_use_new_settings_skin' );
318 */
319 public function is_use_option__in_subtabs_or_tabs( $option_name ) {
320
321 // Check if this otion defined in tabs or 'subtabs' ?
322 $is_use_option = $this->is_use_option__in_subtabs( $option_name );
323
324 // If this option not defined in 'subtabs', then we check it in 'tab'.
325 if ( false === $is_use_option ) {
326 $is_use_option = ( $this->is_use_option__in_tabs( $option_name ) );
327 }
328
329 return $is_use_option;
330 }
331
332 /**
333 * Get Option. Check if this defined in subtabs array Otherwise return false.
334 *
335 * @param string $option_name - name of the option, like 'is_use_new_settings_skin'.
336 *
337 * @return false|mixed
338 *
339 * Example: $is_use_new_settings_skin = $this->is_use_option__in_subtabs( 'is_use_new_settings_skin' );
340 */
341 public function is_use_option__in_subtabs( $option_name ) {
342
343 // Check if this otion defined in subtabs ?
344 $is_use_option = ( ( isset( $this->current_page_params['subtab'] ) ) && ( ! empty( $this->current_page_params['subtab'][ $option_name ] ) ) )
345 ? $this->current_page_params['subtab'][ $option_name ]
346 : false;
347
348 return $is_use_option;
349 }
350
351 /**
352 * Get Option. Check if this defined in btabs array Otherwise return false.
353 *
354 * @param string $option_name - name of the option, like 'is_use_new_settings_skin'.
355 *
356 * @return false|mixed
357 *
358 * Example: $is_use_new_settings_skin = $this->is_use_option__in_subtabs( 'is_use_new_settings_skin' );
359 */
360 public function is_use_option__in_tabs( $option_name ) {
361
362 // Check if this otion defined in subtabs ?
363 $is_use_option = ( ( isset( $this->current_page_params['tab'] ) ) && ( ! empty( $this->current_page_params['tab'][ $option_name ] ) ) )
364 ? $this->current_page_params['tab'][ $option_name ]
365 : false;
366
367 return $is_use_option;
368 }
369
370 /**
371 * Get Navigation path for header, if applicable.
372 * Used in Setup Wizard page.
373 *
374 * @return false|array
375 */
376 protected function is_use_navigation_path_arr() {
377
378 // Use Top line as Path in Setup Wizard page // FixIn: 10.4.0.2.
379 $is_use_navigation_path_arr = $this->is_use_option__in_subtabs( 'is_use_navigation_path' );
380
381 return $is_use_navigation_path_arr;
382 }
383
384 /**
385 * Get URL of settings page, based on Page Slug and Tab Slug e.g. page=wpbc-settings&tab=email&subtab=approved
386 *
387 * @param string $page_tag - e.g. 'wpbc-settings'.
388 * @param string $tab_name - e.g. 'email'.
389 * @param string $subtab_name ( Optional ) - e.g. 'approved'.
390 *
391 * @return string - Escaped URL to plugin page.
392 */
393 private function get_tab_url( $page_tag, $tab_name, $subtab_name = false ) {
394 if ( false === $subtab_name ) {
395 return esc_url( admin_url( add_query_arg( array( 'page' => $page_tag, $this->tags['tab'] => $tab_name ), 'admin.php' ) ) );
396 } else {
397 return esc_url( admin_url( add_query_arg( array( 'page' => $page_tag, $this->tags['tab'] => $tab_name, $this->tags['subtab'] => $subtab_name ), 'admin.php' ) ) );
398 }
399 }
400 }