PluginProbe
Booking Calendar / 10.15.7
Booking Calendar v10.15.7
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 / page-setup / setup_support.php

setup_support.php in Booking Calendar 10.15.7, at includes/page-setup/setup_support.php

324 lines 13.0 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 Support functions for the Setup Wizard Page
4 * @category Setup Class
5 * @author wpdevelop
6 *
7 * @web-site http://oplugins.com/
8 * @email info@oplugins.com
9 *
10 * @modified 2024-09-06
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
14
15
16 /**
17 * Do we need to start 'Setup Wizard' ?
18 *
19 * @return bool
20 */
21 function wpbc_setup_wizard_page__is_need_start(){
22
23 if ( wpbc_setup_wizard_page__is_all_steps_completed() ) {
24 return false; // Wizard Completed!
25 }
26
27 // Some steps were not completed or wizard was not started at all
28
29 $days_num_ago = wpbc_how_old_in_days();
30
31 // No bookings, so maybe need to start
32 if ( - 1 === $days_num_ago ) {
33 return true;
34 }
35
36 // If older than 3 days ago, then no need to start !
37 if ( $days_num_ago < 3 ){
38 return true;
39 }
40
41 // No need to start, because this installation already OLD
42 return false;
43 }
44
45 /**
46 * Do we need to Continue 'Setup Wizard' or all steps already completed ?
47 *
48 * @return bool
49 */
50 function wpbc_setup_wizard_page__is_all_steps_completed() {
51
52 $setup_steps = new WPBC_SETUP_WIZARD_STEPS();
53
54 $is_all_steps_completed = $setup_steps->db__is_all_steps_completed();
55
56 return $is_all_steps_completed;
57 }
58
59 /**
60 * Is user can access Wizard Setup page ?
61 * @return bool
62 */
63 function wpbc_is_user_can_access_wizard_page() {
64 $is_user_can_access_wizard_page = true;
65 if ( class_exists( 'wpdev_bk_multiuser' ) ) {
66
67 $real_current_user_id = get_current_user_id(); // Is current user suer booking admin and if this user was simulated log in
68 $is_user_super_admin = apply_bk_filter( 'is_user_super_admin', $real_current_user_id );
69 if ( ! $is_user_super_admin ) {
70 $is_user_can_access_wizard_page = false;
71 }
72 }
73
74 return $is_user_can_access_wizard_page;
75 }
76
77
78 // =====================================================================================================================
79 // == Shortcodes Content ==
80 // =====================================================================================================================
81
82 /**
83 * Get "Booking Form" Shortcode Content
84 *
85 * @param $resource_id
86 *
87 * @return false|string
88 */
89 function wpbc_setup_wizard_page__get_shortcode_html( $resource_id = 1 , $is_show_only_calendar = false ) {
90
91 ob_start();
92
93 $localized_js_vars_script = wpbc_get_localized_js_vars();
94
95 if ( $is_show_only_calendar ) {
96 // Center calendar.
97 ?><style type="text/css">
98 .wpbc_calendar_wraper {
99 display: flex;
100 flex-flow: column nowrap;
101 align-items: center;
102 justify-content: flex-start;
103 }
104 .wpbc_calendar_wraper div {
105 margin-bottom: 10px;
106 }
107 </style>
108 <div class="wpbc_shortcode_container"><?php
109 echo do_shortcode( '[bookingcalendar resource_id=' . $resource_id . ']' );
110 ?></div><?php
111
112 // If we use the [bookingcalendar] shortcode, then we remove this tag, for ability to select dates in calendar.
113 ?><script tye="text/javascript">
114 jQuery(document).ready(function(){
115 <?php
116 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
117 echo $localized_js_vars_script;
118 ?>
119 jQuery( 'body' ).on( 'wpbc_calendar_ajx__loaded_data', function( event, resource_id ) {
120 jQuery( '#calendar_booking_unselectable' + resource_id ).remove();
121 } );
122 });
123 </script><?php
124
125 } else {
126
127 // Help message
128 ?><div class="wpbc-settings-notice notice-warning notice-helpful-info" style="padding: 8px 20px;font-size: 14px;margin: 0 auto;max-width: Min(54em,100%);">
129 <strong><?php esc_html_e('Note','booking'); ?>: </strong>
130 <?php
131 esc_html_e( 'This is a preview of your booking form.', 'booking' ); echo ' ';
132 esc_html_e( 'You can adjust settings in the widgets on the right side of the page.', 'booking' );
133 //echo '<a href="'. esc_attr( wpbc_get_settings_url() . '&scroll_to_section=wpbc_general_settings_availability_tab' ).'">Settings > Availability</a>';
134 ?>
135 </div><?php
136
137 // If we use the [bookingcalendar] shortcode, then we remove this tag, for ability to select dates in calendar.
138 ?><script type="text/javascript">
139 jQuery( document ).ready( function () {
140 <?php
141 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
142 echo $localized_js_vars_script;
143 ?>
144 _wpbc.set_other_param( 'calendars__on_this_page', [] );
145 <?php if ( 'On' === get_bk_option( 'booking_timeslot_picker') ) { ?>
146 wpbc_hook__init_timeselector();
147 <?php } ?>
148 wpbc_hook__init_booking_form_wizard_buttons();
149 // wpbc__calendar__change_skin( '<?php echo esc_url( WPBC_PLUGIN_URL . get_bk_option( 'booking_skin' ) ); ?>' );
150 // wpbc__css__change_skin( '<?php echo esc_url( WPBC_PLUGIN_URL . get_bk_option( 'booking_timeslot_picker_skin' ) ); ?>' );
151 <?php if ('wpbc_theme_dark_1' === get_bk_option( 'booking_form_theme' ) ){ ?>
152 jQuery( '.wpbc_widget_preview_booking_form .wpbc_center_preview,.wpbc_widget_preview_booking_form .wpbc_container.wpbc_container_booking_form,.wpbc_widget_preview_booking_form .wpbc_widget_content' ).addClass( 'wpbc_theme_dark_1' );
153 <?php } ?>
154 if ( 'function' === typeof( wpbc_update_capacity_hint ) ) {
155 jQuery( '.booking_form_div' ).on( 'wpbc_booking_date_or_option_selected', function ( event, resource_id ) {
156 wpbc_update_capacity_hint( resource_id );
157 } );
158 }
159 //jQuery( 'body' ).on( 'wpbc_datepick_inline_calendar_loaded', function ( event, resource_id, jCalContainer, inst ) { });
160 // jQuery( 'body' ).off( 'wpbc_calendar_ajx__loaded_data' );
161 // jQuery( 'body' ).on( 'wpbc_calendar_ajx__loaded_data', function ( event, loaded_resource_id ){
162 // // wpbc_blink_element( '.wpbc_widget_change_form_structure', 3, 220 );
163 // wpbc_blink_element( '#ui_btn_cstm__set_booking_form_template_pro', 2, 220 );
164 // wpbc_blink_element( '#ui_btn_cstm__set_booking_form_template_apply', 4, 220 );
165 // });
166
167 // jQuery( 'body' ).on( 'wpbc_calendar_ajx__before_loaded_data', function( event, resource_id ) {
168 // wpbc_calendar__loading__stop( resource_id );
169 // } );
170 });
171 //if ( 'undefined' !== typeof _wpbc ) {
172 // <?php
173 // echo "_wpbc.set_other_param( 'availability__week_days_unavailable', ["
174 // . ( ( get_bk_option( 'booking_unavailable_day0') == 'On' ) ? '0,' : '' )
175 // . ( ( get_bk_option( 'booking_unavailable_day1') == 'On' ) ? '1,' : '' )
176 // . ( ( get_bk_option( 'booking_unavailable_day2') == 'On' ) ? '2,' : '' )
177 // . ( ( get_bk_option( 'booking_unavailable_day3') == 'On' ) ? '3,' : '' )
178 // . ( ( get_bk_option( 'booking_unavailable_day4') == 'On' ) ? '4,' : '' )
179 // . ( ( get_bk_option( 'booking_unavailable_day5') == 'On' ) ? '5,' : '' )
180 // . ( ( get_bk_option( 'booking_unavailable_day6') == 'On' ) ? '6,' : '' )
181 // . "999] ); ";
182 // ?>
183 //}
184 </script><?php
185
186 ?><div class="wpbc_shortcode_container"><?php
187 echo do_shortcode( '[booking resource_id=' . $resource_id . ']' );
188 ?></div><?php
189
190
191 }
192
193 return ob_get_clean();
194 }
195
196
197
198 //TODO: Left Menu - TEMP . Delete it ?
199 function wpbc_setup_wizard_page__get_left_navigation_menu_arr(){
200
201 $navigation_menu_arr = array();
202
203 $navigation_menu_arr['general_info'] = array(
204 'title' => __( 'General Info', 'booking' ),
205 'icon' => 'wpbc_icn_check wpbc_icn_dashboard0 wpbc_icn_task_alt0 0wpbc_icn_circle_outline',
206 'class' => '',
207 //'style' => 'cursor:not-allowed;',
208 //'a_style' => 'pointer-events: none;',
209 'action' => "wpbc_ajx__setup_wizard_page__send_request_with_params( { 'current_step':'general_info' } );"
210 ,'right_icon' => array(
211 'icon' => '',
212 'text' => __('Done', 'booking'),
213 'action' => "console.log( this );",
214 )
215
216 );
217 $navigation_menu_arr['optional_other_settings'] = array(
218 'title' => __( 'Bookings Type', 'booking' ),
219 'icon' => 'wpbc-bi-calendar2-range 0wpbc_icn_radio_button_checked',
220 'class' => '',
221 //'a_style' => 'color: var(--wpbc_settings__nav_menu_left__active_border_color);',
222 'action' => "wpbc_ajx__setup_wizard_page__send_request_with_params( { 'current_step':'optional_other_settings' } );"
223 );
224 $navigation_menu_arr['next_step'] = array(
225 'title' => '',//__( 'Bookings Type', 'booking' ),
226 'icon' => 'wpbc-bi-three-dots 0wpbc_icn_radio_button_unchecked',
227 'class' => '',
228 'a_style' => 'pointer-events: none;cursor:not-allowed;',
229 'action' => "wpbc_navigation_click_show_section(this,'#wpbc_general_settings_calendar_metabox' );"
230 );
231 // $navigation_menu_arr['booking_notification'] = array(
232 // 'title' => __( 'Publishing', 'booking' ),
233 // 'icon' => 'wpbc-bi-calendar2-range',
234 // 'class' => 'wpbc_top_border',
235 // 'action' => "wpbc_navigation_click_show_section(this,'#wpbc_general_settings_calendar_metabox' );",
236 // 'right_icon' => array(
237 // 'icon' => 'wpbc_icn_navigate_next expand_more',
238 // 'action' => "console.log( this );",
239 // )
240 // );
241 // $navigation_menu_arr['booking_form'] = array(
242 // 'title' => __( 'Booking Form', 'booking' ),
243 // 'icon' => 'wpbc_icn_dashboard',
244 // 'class' => 'wpbc_sub_option',
245 // 'action' => "wpbc_navigation_click_show_section(this,'#wpbc_general_settings_calendar_metabox' );"
246 // );
247
248 return $navigation_menu_arr;
249 }
250
251
252 /**
253 * Show Warning Conflict with "Wordfence" plugin
254 *
255 * @return void
256 */
257 function wpbc_maybe_show_warning_conflict__wordfence( $style = '' ) {
258 if ( class_exists( 'wordfence' ) ) {
259
260 $is_panel_visible = wpbc_is_dismissed_panel_visible( 'wpbc_show_warning_wordfence' ); // FixIn: 9.9.0.8.
261 if ( $is_panel_visible ) {
262 ?><div id="wpbc_show_warning_wordfence" class="wpbc-settings-notice notice-error notice-helpful-info0"
263 style="max-width: Min(450px, 100%);margin: auto;padding: 4px 15px 7px 20px;font-size: 14px;line-height: 28px;margin-bottom: 25px; display: flex;flex-flow:row nowrap;justify-content: space-between;align-items: flex-start;border-left-color: #e2892b;<?php echo esc_attr( $style ); ?>"
264 >
265 <div>
266 <span style="margin: 0 5px 0 0;color: #e2892b;" ><i class="menu_icon icon-1x wpbc_icn_warning_amber"></i></span>
267 <?php
268 echo '<strong>' . esc_html__('Important!' ,'booking') . '</strong> ' ;
269 // FixIn: 10.9.1.1.
270 /* translators: 1: ... */
271 echo wp_kses_post( sprintf( __( 'We detect that you use %s plugin.', 'booking' ), '<strong>Wordfence</strong>' ) );
272
273 echo '<br>';
274
275 /* translators: 1: ... */
276 echo wp_kses_post( sprintf( __( 'If you encounter any issues, follow this %1$stroubleshooting instruction%2$s.', 'booking' ),
277 '<a href="https://wpbookingcalendar.com/faq/setup-wizard-on-step-4-keeps-going-to-blank-page/" target="_blank" style="font-weight:600;text-underline-offset: 3px;text-decoration-thickness: 0px;text-decoration-style: dashed;">', '</a>' ) );
278 ?>
279 </div>
280 <div><?php
281 ob_start();
282 $is_panel_visible = wpbc_is_dismissed( 'wpbc_show_warning_wordfence', array(
283 'title' => '<i class="menu_icon icon-1x wpbc_icn_close"></i> ',
284 'hint' => __( 'Dismiss', 'booking' ),
285 'class' => 'wpbc_panel_get_started_dismiss',
286 'css' => 'background: #fff;border-radius: 7px;'
287 ));
288
289 $dismiss_x_button = ob_get_clean();
290
291 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
292 echo wpbc_replace__js_scripts__to__tpl_scripts( $dismiss_x_button );
293
294 ?></div>
295 </div><?php
296 }
297
298
299
300 }
301 }
302
303
304 /**
305 * Escape scripts from the Booking Calendar shortcode content for showing in Wizard templates.
306 *
307 * @param string $calendar_html_content - usualy it is the content of [booking ...] shortcode.
308 *
309 * @return mixed
310 */
311 function wpbc_clean_calendar_loading_scripts( $calendar_html_content ) {
312
313 // Prevent of any intention usage od this tag.
314 $calendar_html_content = str_replace( 'ajax_scrpt', '', $calendar_html_content );
315
316 $pattern = '/<script\s*(type=[\'"]+text\/javascript[\'"]+)?\s*>/i';
317 $calendar_html_content = preg_replace( $pattern, '<ajax_scrpt>', $calendar_html_content );
318
319 $pattern = '/<\/script>/i';
320 $calendar_html_content = preg_replace( $pattern, '</ajax_scrpt>', $calendar_html_content );
321
322 return $calendar_html_content;
323 }
324