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 / core / wpbc-js-vars.php

wpbc-js-vars.php in Booking Calendar 10.1.3, at core/wpbc-js-vars.php

127 lines 10.4 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 * @package Booking Calendar - JavaScript
4 * @category Define JavaScript variables
5 * @author wpdevelop
6 *
7 * @web-site https://wpbookingcalendar.com/
8 * @email info@wpbookingcalendar.com
9 *
10 * @modified 19.10.2015
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
14
15
16 /**
17 * Define General inline JavaScript variables for the Booking Calendar
18 *
19 * This function run after ENQUEUE of WPBC JavaScript files
20 *
21 * @param $where_to_load
22 *
23 * @return void
24 */
25 function wpbc_localize_js_vars( $where_to_load = 'both' ){ //FixIn: 10.0.0.43
26
27 //$script = 'var1 = '. json_encode('var1') .'; '; // JSON.parse(wpbc_global_var);
28 $script = '';
29 $script .= "_wpbc.set_other_param( 'locale_active', '" . esc_js( wpbc_get_maybe_reloaded_booking_locale() ) . "' ); ";
30
31 $today_local = wpbc_datetime_localized__use_wp_timezone( date( 'Y-m-d H:i:s', strtotime( 'now' ) ), 'Y,m,d,H,i' ); //FixIn: 9.9.0.17
32 $script .= "_wpbc.set_other_param( 'today_arr', [" . $today_local . "] ); ";
33
34 $script .= "_wpbc.set_other_param( 'url_plugin', '" . esc_url( plugins_url( '', WPBC_FILE ) ) . "' ); ";
35 //'_wpbc.get_other_param( 'url_plugin' )'
36 $script .= "_wpbc.set_other_param( 'this_page_booking_hash', '" . esc_js( ( ! empty( $_GET['booking_hash'] ) ) ? $_GET['booking_hash'] : '' ) . "' ); ";
37
38
39 $script .= "_wpbc.set_other_param( 'calendars__on_this_page', [] ); ";
40
41 $script .= "_wpbc.set_other_param( 'calendars__first_day', '" . esc_js( get_bk_option( 'booking_start_day_weeek' ) ) . "' ); "; //."\n";
42 $script .= "_wpbc.set_other_param( 'calendars__max_monthes_in_calendar', '" . esc_js( get_bk_option( 'booking_max_monthes_in_calendar' ) ) . "' ); ";
43 $script .= "_wpbc.set_other_param( 'availability__unavailable_from_today', '" . esc_js( get_bk_option( 'booking_unavailable_days_num_from_today' ) ) . "' ); "; //Default: 0 ' Old JS: block_some_dates_from_today' _wpbc.get_other_param( 'availability__unavailable_from_today' )
44 if ( class_exists( 'wpdev_bk_biz_m' ) ) {
45 $script .= "_wpbc.set_other_param( 'availability__available_from_today', '" . esc_js( get_bk_option( 'booking_available_days_num_from_today' ) ) . "' ); "; //Default '' - all days. Old JS: 'wpbc_available_days_num_from_today'
46 }
47 $script .= "_wpbc.set_other_param( 'availability__week_days_unavailable', ["
48 . ( ( get_bk_option( 'booking_unavailable_day0') == 'On' ) ? '0,' : '' )
49 . ( ( get_bk_option( 'booking_unavailable_day1') == 'On' ) ? '1,' : '' )
50 . ( ( get_bk_option( 'booking_unavailable_day2') == 'On' ) ? '2,' : '' )
51 . ( ( get_bk_option( 'booking_unavailable_day3') == 'On' ) ? '3,' : '' )
52 . ( ( get_bk_option( 'booking_unavailable_day4') == 'On' ) ? '4,' : '' )
53 . ( ( get_bk_option( 'booking_unavailable_day5') == 'On' ) ? '5,' : '' )
54 . ( ( get_bk_option( 'booking_unavailable_day6') == 'On' ) ? '6,' : '' )
55 . "999] ); "; // 999 - blank day, which will not impact to the checking of the week days. Required for correct creation of this array.
56 // General days selection
57 $days_selection_arr = wpbc__calendar__js_params__get_days_selection_arr();
58 $script .= "_wpbc.set_other_param( 'calendars__days_select_mode', '" . $days_selection_arr['days_select_mode'] . "' ); ";
59 $script .= "_wpbc.set_other_param( 'calendars__fixed__days_num', " . $days_selection_arr['fixed__days_num'] . " ); ";
60 $script .= "_wpbc.set_other_param( 'calendars__fixed__week_days__start', [" .$days_selection_arr['fixed__week_days__start'] . "] ); ";
61 $script .= "_wpbc.set_other_param( 'calendars__dynamic__days_min', " . $days_selection_arr['dynamic__days_min'] . " ); ";
62 $script .= "_wpbc.set_other_param( 'calendars__dynamic__days_max', " . $days_selection_arr['dynamic__days_max'] . " ); ";
63 $script .= "_wpbc.set_other_param( 'calendars__dynamic__days_specific', [" .$days_selection_arr['dynamic__days_specific'] . "] ); ";
64 $script .= "_wpbc.set_other_param( 'calendars__dynamic__week_days__start', [" .$days_selection_arr['dynamic__week_days__start'] . "] ); ";
65
66 // Defined in BS
67 $script .= "_wpbc.set_other_param( 'is_enabled_booking_recurrent_time', " . ( ( get_bk_option( 'booking_recurrent_time' ) !== 'On' ) ? 'false' : 'true' ) . " ); ";
68 $script .= "_wpbc.set_other_param( 'is_enabled_change_over', " . (
69 (
70 ( function_exists( 'wpbc_is_booking_used_check_in_out_time' ) )
71 && ( wpbc_is_booking_used_check_in_out_time() )
72 ) ? 'true' : 'false'
73 ) . " ); ";
74 if ( class_exists( 'wpdev_bk_biz_l' ) ) {
75 $script .= "_wpbc.set_other_param( 'is_enabled_booking_search_results_days_select', '" . esc_js( get_bk_option( 'booking_search_results_days_select' ) ) . "' ); ";
76 }
77
78 $script .= "_wpbc.set_other_param( 'update', '" . WP_BK_VERSION_NUM . "' ); ";
79 $script .= "_wpbc.set_other_param( 'version', '" . wpbc_get_version_type__and_mu() . "' ); ";
80
81 // Warning Messages
82 $script .= "_wpbc.set_message( 'message_dates_times_unavailable', " . wp_json_encode( __( 'These dates and times in this calendar are already booked or unavailable.', 'booking' ) ) . " ); ";
83 $script .= "_wpbc.set_message( 'message_choose_alternative_dates', " . wp_json_encode( __( 'Please choose alternative date(s), times, or adjust the number of slots booked.', 'booking' ) ) . " ); ";
84 $script .= "_wpbc.set_message( 'message_cannot_save_in_one_resource', " . wp_json_encode( __( 'It is not possible to store this sequence of the dates into the one same resource.', 'booking' ) ) . " ); ";
85 $script .= "_wpbc.set_message( 'message_check_required', " . wp_json_encode( __( 'This field is required', 'booking' ) ) . " ); ";
86 $script .= "_wpbc.set_message( 'message_check_required_for_check_box', " . wp_json_encode( __( 'This checkbox must be checked', 'booking' ) ) . " ); ";
87 $script .= "_wpbc.set_message( 'message_check_required_for_radio_box', " . wp_json_encode( __( 'At least one option must be selected', 'booking' ) ) . " ); ";
88 $script .= "_wpbc.set_message( 'message_check_email', " . wp_json_encode( __( 'Incorrect email field', 'booking' ) ) . " ); ";
89 $script .= "_wpbc.set_message( 'message_check_same_email', " . wp_json_encode( __( 'Your emails do not match', 'booking' ) ) . " ); ";
90 $script .= "_wpbc.set_message( 'message_check_no_selected_dates', " . wp_json_encode( __( 'Please, select booking date(s) at Calendar.', 'booking' ) ) . " ); ";
91 $script .= "_wpbc.set_message( 'message_processing', " . wp_json_encode( __( 'Processing', 'booking' ) ) . " ); ";
92 $script .= "_wpbc.set_message( 'message_deleting', " . wp_json_encode( __( 'Deleting', 'booking' ) ) . " ); ";
93 $script .= "_wpbc.set_message( 'message_updating', " . wp_json_encode( __( 'Updating', 'booking' ) ) . " ); ";
94 $script .= "_wpbc.set_message( 'message_saving', " . wp_json_encode( __( 'Saving', 'booking' ) ) . " ); ";
95 $script .= "_wpbc.set_message( 'message_error_check_in_out_time', " . wp_json_encode( __( 'Error! Please reset your check-in/check-out dates above.', 'booking' ) ) . " ); ";
96 $script .= "_wpbc.set_message( 'message_error_start_time', " . wp_json_encode( __( 'Start Time is invalid. The date or time may be booked, or already in the past! Please choose another date or time.', 'booking' ) ) . " ); ";
97 $script .= "_wpbc.set_message( 'message_error_end_time', " . wp_json_encode( __( 'End Time is invalid. The date or time may be booked, or already in the past. The End Time may also be earlier that the start time, if only 1 day was selected! Please choose another date or time.', 'booking' ) ) . " ); ";
98 $script .= "_wpbc.set_message( 'message_error_range_time', " . wp_json_encode( __( 'The time(s) may be booked, or already in the past!', 'booking' ) ) . " ); ";
99 $script .= "_wpbc.set_message( 'message_error_duration_time', " . wp_json_encode( __( 'The time(s) may be booked, or already in the past!', 'booking' ) ) . " ); ";
100
101 $script_before = 'var wpbc_url_ajax =' . wp_json_encode( admin_url( 'admin-ajax.php' ) ) . ';';
102 wp_add_inline_script( 'wpbc_all', $script_before, 'before' );
103
104 $script .= "console.log( '== WPBC VARS " . WP_BK_VERSION_NUM . ' ['.wpbc_get_version_type__and_mu() . "] LOADED ==' );";
105
106
107 // Load this _wpbc only after loading of all scripts //FixIn: 10.1.3.4
108 $script = " function wpbc_init__head(){ " . $script . " } ";
109 $script .= "( function() { if ( document.readyState === 'loading' ){ document.addEventListener( 'DOMContentLoaded', wpbc_init__head ); } else { wpbc_init__head(); } }() );";
110
111 wp_add_inline_script( 'wpbc_all', $script );
112
113 /**
114 * Help info. Order of JS events:
115 *
116 * window.addEventListener("load", (event) => { log.textContent += "load\n"; }); -> window.onload (which is implemented even in old browsers), which fires when the entire page loads (images, styles, etc.)
117 * document.addEventListener("readystatechange", (event) => { log.textContent += `readystate: ${document.readyState}\n`; });
118 * document.addEventListener("DOMContentLoaded", (event) => { log.textContent += "DOMContentLoaded\n"; }); -> newish event which fires when the document's DOM is loaded (which may be some time before the images, etc. are loaded);
119 * ::
120 * DOMContentLoaded
121 * readystate: complete
122 * load
123 */
124 }
125 add_action( 'wpbc_enqueue_js_files', 'wpbc_localize_js_vars', 51 ); // Need to set here 51, because some JS has 50 priority, for example at WP Booking Calendar > Availability > Days Availability page -> This hook fired after ENQUEUE of WPBC JS - wp_enqueue_script
126
127