PluginProbe
Booking Calendar / 11.7
Booking Calendar v11.7
11.9 11.8.4 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 All 205 releases
booking / includes / ui_settings / parts / ui__nav_top.php

ui__nav_top.php in Booking Calendar 11.7, at includes/ui_settings/parts/ui__nav_top.php

499 lines 16.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin Panel UI - Parts
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 [email protected]
12 *
13 * @modified 2025-02-15
14 */
15
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit; // Exit, if accessed directly.
18 }
19
20 /**
21 * Show Top Nav bar
22 *
23 * @param array $args - parameters.
24 *
25 * @return void
26 */
27 function wpbc_ui__top_nav( $args = array() ) {
28
29 $defaults = array(
30 'attr' => array(),
31 'is_full_screen_user_mode_enabled' => true,
32 );
33 $params = wp_parse_args( $args, $defaults );
34
35 echo '<div class="wpbc_ui_el wpbc_ui_el__top_nav">';
36
37 wpbc_ui__vert_left_bar__do_toggle();
38 wpbc_ui_el__divider_vertical( array( 'class' => 'wpbc_ui_el__vertical_line wpbc_ui__top_nav__btn_show_left_vertical_nav_divider' ) );
39
40 wpbc_ui__top_nav__dropdown__wpbc();
41
42 do_action( 'wpbc_ui_el__top_nav__content_start', $params['page_tag'], $params['active_page_tab'], $params['active_page_subtab'] );
43
44
45 ?><div class="wpbc_ui_el__make_space"></div><?php // Spacer.
46
47 do_action( 'wpbc_ui_el__top_nav__content_center', $params['page_tag'], $params['active_page_tab'], $params['active_page_subtab'] );
48
49 // Load Top News Message and "Search by ID" fields.
50 echo '<style type="text/css"> .wpbc_message_wrapper { margin-left: 0px !important; } </style>';
51 make_bk_action( 'wpbc_h1_header_content_end', $params['page_tag'], $params['active_page_tab'], $params['active_page_subtab'] );
52
53 ?><div class="wpbc_ui_el__make_space"></div><?php // Spacer.
54
55 do_action( 'wpbc_ui_el__top_nav__content_end', $params['page_tag'], $params['active_page_tab'], $params['active_page_subtab'] );
56
57 wpbc_ui_el__divider_vertical();
58
59 // Right sidebar toggle button.
60 wpbc_ui__vert_right_bar__do_toggle();
61 wpbc_ui_el__divider_vertical( array( 'class' => 'wpbc_ui_el__vertical_line wpbc_ui__top_nav__btn_show_right_vertical_nav_divider' ) );
62
63
64 // Full Screen Buttons.
65 wpbc_ui__top_nav__btn_full_screen( $params );
66 wpbc_ui__top_nav__btn_normal_screen( $params );
67
68 echo '</div>';
69 }
70
71
72
73 /**
74 * Show element - "WPBC - Main Dropdown"
75 *
76 * @return void
77 */
78 function wpbc_ui__top_nav__dropdown__wpbc() {
79
80 $svg_size = '22px';
81 $svg_icon_style = 'margin:5px 5px 0 0;'; // 'background-position: 0 0;background-size: ' . $svg_size . ' ' . $svg_size . ';width: ' . $svg_size . ';height: ' . $svg_size . ';'; //.
82 $svg_icon = wpbc_get_svg_logo_for_background( '#555', '#e5e5e5', '1.0' );
83
84 $wpbc_starter_pages = function_exists( 'wpbc_get_published_activation_booking_pages' ) ? wpbc_get_published_activation_booking_pages() : array();
85 $wp_post_booking_absolute = false;
86
87 if (
88 empty( $wpbc_starter_pages ) &&
89 function_exists( 'wpbc_stp_wiz__is_exist_published_page_with_booking_form' )
90 ) {
91 $wp_post_booking_absolute = wpbc_stp_wiz__is_exist_published_page_with_booking_form();
92 }
93
94 $el_arr = array(
95 // 'title' => 'Booking Calendar',
96 // 'font_icon' => 'wpbc-bi-calendar2-range',
97 'title_html' => '<span class="nav-tab-text" style="margin: -3px 0 0 5px;font-size: 16px;padding: 0;"><span style="position: absolute;font-size: 7px;margin-top: 13px;margin-left: 1px;">WP</span>Booking Calendar</span>',
98 'svg_icon' => $svg_icon,
99 'svg_icon_style' => $svg_icon_style,
100 'style' => 'display: flex;flex-flow:row nowrap;align-items: center;justify-content: flex-start; ',
101 'container_style' => 'padding: 0 15px 0 10px;',
102 'position' => 'left',
103 'has_down_arrow' => true,
104 'items' => array(),
105 );
106
107 if ( ! empty( $wpbc_starter_pages ) && is_array( $wpbc_starter_pages ) ) {
108 $el_arr['items'][] = array(
109 'type' => 'header',
110 'title' => __( 'Visit Booking Pages', 'booking' ),
111 );
112 $el_arr['items'][] = array(
113 'type' => 'link',
114 'title' => __( 'Visit Home Page', 'booking' ),
115 'url' => esc_url( home_url( '/' ) ),
116 );
117
118 foreach ( $wpbc_starter_pages as $wpbc_starter_page ) {
119 if ( empty( $wpbc_starter_page['url'] ) ) {
120 continue;
121 }
122
123 $wpbc_starter_page_title = __( 'Go to page with booking form', 'booking' );
124 if ( ! empty( $wpbc_starter_page['button_title'] ) ) {
125 $wpbc_starter_page_title = $wpbc_starter_page['button_title'];
126 } elseif ( ! empty( $wpbc_starter_page['page_title'] ) ) {
127 $wpbc_starter_page_title = $wpbc_starter_page['page_title'];
128 }
129
130 $el_arr['items'][] = array(
131 'type' => 'link',
132 'title' => $wpbc_starter_page_title,
133 'url' => esc_url( $wpbc_starter_page['url'] ),
134 );
135 }
136 } elseif ( ! empty( $wp_post_booking_absolute ) ) {
137 $el_arr['items'][] = array(
138 'type' => 'header',
139 'title' => __( 'Visit Booking Page', 'booking' ),
140 );
141 $el_arr['items'][] = array(
142 'type' => 'link',
143 'title' => __( 'Visit Home Page', 'booking' ),
144 'url' => esc_url( home_url( '/' ) ),
145 );
146 $el_arr['items'][] = array(
147 'type' => 'link',
148 'title' => __( 'Go to page with booking form', 'booking' ),
149 'url' => esc_url( $wp_post_booking_absolute ),
150 );
151 }
152 $el_arr['items'][] = array(
153 'type' => 'header',
154 'title' => __( 'Help', 'booking' ),
155 );
156 $el_arr['items'][] = array(
157 'type' => 'link',
158 'title' => __( 'FAQ', 'booking' ),
159 'url' => 'https://wpbookingcalendar.com/faq/',
160 );
161 $el_arr['items'][] = array(
162 'type' => 'header',
163 'title' => __( 'Support', 'booking' ),
164 );
165 $el_arr['items'][] = array(
166 'type' => 'link',
167 'title' => __( 'Support Forum', 'booking' ),
168 'url' => 'https://wpbookingcalendar.com/support/',
169 );
170 $el_arr['items'][] = array(
171 'type' => 'link',
172 'title' => __( 'Contact Support', 'booking' ),
173 'url' => 'mailto:[email protected]',
174 'attr' => array( 'style' => 'font-weight: 600;' ),
175 );
176 $el_arr['items'][] = array( 'type' => 'divider' );
177 $el_arr['items'][] = array(
178 'type' => 'link',
179 'title' => __( 'Release History', 'booking' ),
180 'url' => 'https://wpbookingcalendar.com/wn/',
181 );
182 $el_arr['items'][] = array(
183 'type' => 'link',
184 'title' => __( 'What\'s New', 'booking' ) . ' <span style="float:right">' . esc_attr( WP_BK_VERSION_NUM ) . '</span>',
185 'url' => esc_url( admin_url( add_query_arg( array( 'page' => 'wpbc-about' ), 'index.php' ) ) ),
186 );
187 // $el_arr['items'][] = array(
188 // 'type' => 'link',
189 // 'title' => __( 'About', 'booking' ),
190 // 'url' => 'https://wpbookingcalendar.com/',
191 // );
192
193
194 $is_show_up = wpbc_is_show_up();
195
196 if ( $is_show_up ) {
197 $el_arr['items'][] = array( 'type' => 'divider' );
198 $el_arr['items'][] = array(
199 'type' => 'link',
200 'title' => ( class_exists( 'wpdev_bk_personal' ) )
201 ? __( 'View Upgrade Options', 'booking' )
202 : __( 'Upgrade to Pro', 'booking' ),
203 'url' => wpbc_up_link(),
204 'attr' => array(
205 'class' => 'wpbc_ui_el_upgrade_button wpbc_button_light wpbc_button_green',
206 'style' => 'color:#fff;font-weight: 600;',
207 ),
208 );
209 }
210
211 wpbc_ui_el__dropdown_menu( $el_arr );
212 }
213
214
215 /**
216 * Show element - "Full Screen"
217 *
218 * @return void
219 */
220 function wpbc_ui__top_nav__btn_full_screen( $args = array() ) {
221
222 $defaults = array(
223 'is_full_screen_user_mode_enabled' => true,
224 );
225 $params = wp_parse_args( $args, $defaults );
226
227 $el_arr = array();
228
229 $el_arr['onclick'] = 'wpbc_admin_ui__full_screen__do_on( this, ' . ( $params['is_full_screen_user_mode_enabled'] ? 'true' : 'false' ) . ' );';
230
231 $el_arr['font_icon'] = 'wpbc-bi-arrows-fullscreen';
232 $el_arr['hint'] = array(
233 'title' => __( 'Full Screen', 'booking' ),
234 'position' => 'top',
235 );
236
237 $el_arr['container_class'] = 'wpbc_ui__top_nav__btn_full_screen';
238
239 if ( ( ! wpbc_is_setup_wizard_page() ) && ( $params['is_full_screen_user_mode_enabled'] ) ) {
240
241 // Params for saving user option.
242 $user_cust_option = 'is_full_screen';
243 $nonce_action = $user_cust_option . '_nonce_act';
244
245 $el_arr['attr'] = array(
246 'data-wpbc-u-save-name' => $user_cust_option,
247 'data-wpbc-u-save-value' => 'On',
248 'data-wpbc-u-save-nonce' => wp_create_nonce( $nonce_action ), // do not need to make escaping the values because: wpbc_get_custom_attr() should handle escaping.
249 'data-wpbc-u-save-user-id' => wpbc_get_current_user_id(),
250 'data-wpbc-u-save-action' => $nonce_action,
251 );
252 ?><script type="text/javascript"><?php
253
254 $is_full_screen = WPBC_User_Custom_Data_Saver::get_user_data_value( wpbc_get_current_user_id(), $user_cust_option );
255 $is_full_screen = ( 'On' === wpbc_ui__get_full_screen_mode_from_cookie( $is_full_screen ) );
256
257 echo wpbc_jq_ready_start(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
258
259 if ( $is_full_screen ) {
260 echo " jQuery( '.wpbc_ui__top_nav__btn_full_screen,.wpbc_ui__top_nav__btn_normal_screen' ).toggleClass( 'wpbc_ui__hide' ); ";
261 }
262 echo ' wpbc_check_full_screen_mode(); ';
263 echo wpbc_jq_ready_end(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
264
265 ?></script><?php
266 }
267 wpbc_ui_el__a( $el_arr );
268 }
269
270
271 /**
272 * Show element - "Normal Screen"
273 *
274 * @return void
275 */
276 function wpbc_ui__top_nav__btn_normal_screen( $args = array() ) {
277
278 $defaults = array(
279 'is_full_screen_user_mode_enabled' => true,
280 );
281 $params = wp_parse_args( $args, $defaults );
282
283 $el_arr = array();
284
285 $el_arr['onclick'] = 'wpbc_admin_ui__full_screen__do_off( this, ' . ( $params['is_full_screen_user_mode_enabled'] ? 'true' : 'false' ) . ' );';
286
287 $el_arr['title'] = '';
288 $el_arr['font_icon'] = 'wpbc-bi-arrows-angle-contract';
289 $el_arr['hint'] = array(
290 'title' => __( 'Exit Full Screen', 'booking' ),
291 'position' => 'top',
292 );
293 $el_arr['container_class'] = 'wpbc_ui__top_nav__btn_normal_screen wpbc_ui__hide';
294
295 if ( $params['is_full_screen_user_mode_enabled'] ) {
296 // Params for saving user option.
297 $user_cust_option = 'is_full_screen';
298 $nonce_action = $user_cust_option . '_nonce_act';
299 $el_arr['attr'] = array(
300 'data-wpbc-u-save-name' => $user_cust_option,
301 'data-wpbc-u-save-value' => 'Off',
302 'data-wpbc-u-save-nonce' => wp_create_nonce( $nonce_action ), // do not need to make escaping the values because: wpbc_get_custom_attr() should handle escaping.
303 'data-wpbc-u-save-user-id' => wpbc_get_current_user_id(),
304 'data-wpbc-u-save-action' => $nonce_action,
305 );
306 }
307
308 wpbc_ui_el__a( $el_arr );
309 }
310
311
312 /**
313 * Build a short-lived browser value for an immediately changed fullscreen preference.
314 *
315 * The timestamp distinguishes a pending navigation safeguard from legacy
316 * year-long cookies, which must not override a successfully stored user value.
317 *
318 * @param string $mode Fullscreen mode, either `On` or `Off`.
319 * @param int|null $issued_timestamp Optional Unix timestamp for deterministic tests.
320 *
321 * @return string Pending cookie value, or an empty string for an invalid mode.
322 */
323 function wpbc_ui__create_full_screen_mode_cookie_value( $mode, $issued_timestamp = null ) {
324
325 if ( ! in_array( $mode, array( 'On', 'Off' ), true ) ) {
326 return '';
327 }
328
329 $issued_timestamp = null === $issued_timestamp ? time() : absint( $issued_timestamp );
330
331 return $mode . '|' . $issued_timestamp;
332 }
333
334 /**
335 * Return every server-side cookie path used by Booking Calendar administration.
336 *
337 * Multiple paths are updated together to replace legacy cookies created by
338 * root, subdirectory, or WordPress administration requests.
339 *
340 * @return string[] Unique absolute cookie paths.
341 */
342 function wpbc_ui__get_full_screen_mode_cookie_paths() {
343
344 $cookie_paths = array( '/' );
345
346 if ( defined( 'COOKIEPATH' ) && COOKIEPATH ) {
347 $cookie_paths[] = COOKIEPATH;
348 }
349
350 if ( defined( 'ADMIN_COOKIE_PATH' ) && ADMIN_COOKIE_PATH ) {
351 $cookie_paths[] = ADMIN_COOKIE_PATH;
352 }
353
354 return array_values( array_unique( array_filter( $cookie_paths ) ) );
355 }
356
357 /**
358 * Set the pending fullscreen cookie on every applicable administration path.
359 *
360 * User metadata remains authoritative. This short-lived cookie only bridges
361 * immediate navigation and replaces stale same-name cookies on narrower paths.
362 *
363 * @param string $mode Fullscreen mode, either `On` or `Off`.
364 *
365 * @return bool True when the mode was valid; otherwise false.
366 */
367 function wpbc_ui__set_full_screen_mode_cookie( $mode ) {
368
369 $cookie_value = wpbc_ui__create_full_screen_mode_cookie_value( $mode );
370 if ( '' === $cookie_value ) {
371 return false;
372 }
373
374 if ( ! headers_sent() ) {
375 $cookie_domain = defined( 'COOKIE_DOMAIN' ) ? COOKIE_DOMAIN : '';
376
377 foreach ( wpbc_ui__get_full_screen_mode_cookie_paths() as $cookie_path ) {
378 setcookie(
379 'wpbc_admin_full_screen',
380 $cookie_value,
381 time() + ( 5 * 60 ),
382 $cookie_path,
383 $cookie_domain,
384 is_ssl(),
385 false
386 );
387 }
388 }
389
390 $_COOKIE['wpbc_admin_full_screen'] = $cookie_value;
391
392 return true;
393 }
394
395 /**
396 * Resolve fullscreen mode from saved user data and an optional pending cookie.
397 *
398 * A fresh timestamped cookie temporarily wins so immediate navigation remains
399 * deterministic if the asynchronous AJAX request is interrupted. A legacy
400 * plain `On` or `Off` cookie is accepted only when no valid user preference
401 * exists, preventing stale or duplicate-path cookies from overriding storage.
402 *
403 * @param string $saved_value Saved user-meta value.
404 * @param string $cookie_value Browser cookie value.
405 * @param int|null $current_timestamp Optional Unix timestamp for deterministic tests.
406 *
407 * @return string `On`, `Off`, or an empty string.
408 */
409 function wpbc_ui__resolve_full_screen_mode( $saved_value = '', $cookie_value = '', $current_timestamp = null ) {
410
411 $saved_value = in_array( $saved_value, array( 'On', 'Off' ), true ) ? $saved_value : '';
412 $cookie_value = is_scalar( $cookie_value ) ? (string) $cookie_value : '';
413
414 if ( in_array( $cookie_value, array( 'On', 'Off' ), true ) ) {
415 return '' === $saved_value ? $cookie_value : $saved_value;
416 }
417
418 if ( ! preg_match( '/^(On|Off)\|([0-9]{10,})$/', $cookie_value, $cookie_parts ) ) {
419 return $saved_value;
420 }
421
422 $current_timestamp = null === $current_timestamp ? time() : absint( $current_timestamp );
423 $issued_timestamp = absint( $cookie_parts[2] );
424 $pending_cookie_lifetime = 5 * 60;
425 $allowed_clock_skew = 60;
426
427 if (
428 $issued_timestamp > ( $current_timestamp + $allowed_clock_skew )
429 || $issued_timestamp < ( $current_timestamp - $pending_cookie_lifetime )
430 ) {
431 return $saved_value;
432 }
433
434 return $cookie_parts[1];
435 }
436
437 /**
438 * Get fullscreen mode from the immediate browser cookie and saved user metadata.
439 *
440 * @param string $saved_value Saved user-meta value.
441 *
442 * @return string `On`, `Off`, or an empty string.
443 */
444 function wpbc_ui__get_full_screen_mode_from_cookie( $saved_value = '' ) {
445
446 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated -- Optional same-origin UI preference.
447 $cookie_value = isset( $_COOKIE['wpbc_admin_full_screen'] ) && is_scalar( $_COOKIE['wpbc_admin_full_screen'] )
448 ? sanitize_text_field( wp_unslash( $_COOKIE['wpbc_admin_full_screen'] ) )
449 : '';
450
451 return wpbc_ui__resolve_full_screen_mode( $saved_value, $cookie_value );
452 }
453
454 /**
455 * Synchronize the fullscreen navigation cookie after verified user-meta storage.
456 *
457 * @param int $user_id User whose preference was saved.
458 * @param string $data_name Saved Booking Calendar preference name.
459 * @param array $sanitized_data Sanitized value stored in user metadata.
460 *
461 * @return void
462 */
463 function wpbc_ui__sync_full_screen_cookie_after_user_data_save( $user_id, $data_name, $sanitized_data ) {
464
465 if (
466 'is_full_screen' !== $data_name
467 || wpbc_get_current_user_id() !== absint( $user_id )
468 || ! isset( $sanitized_data['value'] )
469 || ! is_scalar( $sanitized_data['value'] )
470 ) {
471 return;
472 }
473
474 wpbc_ui__set_full_screen_mode_cookie( (string) $sanitized_data['value'] );
475 }
476 add_action( 'wpbc_user_custom_data_saved', 'wpbc_ui__sync_full_screen_cookie_after_user_data_save', 10, 3 );
477
478
479 /**
480 * Set the admin full screen class
481 *
482 * @param bool $classes Body classes.
483 *
484 * @return array
485 */
486 function wpbc_check_full_screen_mode_on_loading( $classes ) {
487
488 $is_full_screen = WPBC_User_Custom_Data_Saver::get_user_data_value( wpbc_get_current_user_id(), 'is_full_screen' );
489 $is_full_screen = wpbc_ui__get_full_screen_mode_from_cookie( $is_full_screen );
490 $is_full_screen = ( 'On' === $is_full_screen );
491
492 if ( ( wpbc_is_this_plugin_page() ) && ( $is_full_screen ) && ( ! wpbc_is_setup_wizard_page() ) ) {
493 $classes .= ' wpbc_admin_full_screen';
494 }
495
496 return $classes;
497 }
498 add_filter( 'admin_body_class', 'wpbc_check_full_screen_mode_on_loading' );
499