PluginProbe
Booking Calendar / 11.8.1
Booking Calendar v11.8.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 / page-setup / setup_support.php

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

407 lines 15.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 * Check whether this site was initialized by the current first-install flow.
18 *
19 * This persisted marker is intentionally separate from wizard completion and
20 * prompt dismissal. It prevents plugin updates from adding the native Setup menu
21 * while allowing a new administrator to postpone the popup and return through
22 * that menu later.
23 *
24 * @return bool True for sites marked during genuine first installation.
25 */
26 function wpbc_setup_wizard_is_initial_install_site() {
27
28 return 'On' === get_bk_option( 'booking_setup_wizard_initial_install' );
29 }
30
31
32 /**
33 * Do we need to start 'Setup Wizard' ?
34 *
35 * @return bool
36 */
37 function wpbc_setup_wizard_page__is_need_start(){
38
39 if ( wpbc_setup_wizard_page__is_all_steps_completed() ) {
40 return false; // Wizard Completed!
41 }
42
43 // Some steps were not completed or wizard was not started at all
44
45 $days_num_ago = wpbc_how_old_in_days();
46
47 // No bookings, so maybe need to start
48 if ( - 1 === $days_num_ago ) {
49 return true;
50 }
51
52 // If older than 3 days ago, then no need to start !
53 if ( $days_num_ago < 3 ){
54 return true;
55 }
56
57 // No need to start, because this installation already OLD
58 return false;
59 }
60
61 /**
62 * Do we need to Continue 'Setup Wizard' or all steps already completed ?
63 *
64 * @return bool
65 */
66 function wpbc_setup_wizard_page__is_all_steps_completed() {
67
68 $setup_steps = new WPBC_SETUP_WIZARD_STEPS();
69
70 $is_all_steps_completed = $setup_steps->db__is_all_steps_completed();
71
72 return $is_all_steps_completed;
73 }
74
75
76 /**
77 * Check whether the Setup Wizard has started and is not yet complete.
78 *
79 * Explicit Setup Wizard requests count as active before the first step has
80 * been saved. Persisted completed steps keep the wizard active while the user
81 * visits another Booking Calendar administration page. A completed or skipped
82 * wizard is not considered in progress.
83 *
84 * @return bool True while an unfinished Setup Wizard is in progress.
85 */
86 function wpbc_setup_wizard_page__is_in_progress() {
87
88 if ( wpbc_setup_wizard_page__is_all_steps_completed() ) {
89 return false;
90 }
91
92 if ( function_exists( 'wpbc_is_setup_wizard_page' ) && wpbc_is_setup_wizard_page() ) {
93 return true;
94 }
95
96 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only UI context.
97 $setup_context = isset( $_GET['wpbc_setup'] ) && is_scalar( $_GET['wpbc_setup'] )
98 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only UI context.
99 ? sanitize_text_field( wp_unslash( $_GET['wpbc_setup'] ) )
100 : '';
101
102 if ( '1' === $setup_context ) {
103 return true;
104 }
105
106 $steps_is_done = get_bk_option( 'booking_setup_wizard_page_steps_is_done' );
107
108 if ( ! is_array( $steps_is_done ) ) {
109 return false;
110 }
111
112 foreach ( $steps_is_done as $is_step_done ) {
113 if ( ! empty( $is_step_done ) ) {
114 return true;
115 }
116 }
117
118 return false;
119 }
120
121
122 /**
123 * Check whether the current request explicitly targets one Setup Wizard step.
124 *
125 * This read-only request check is intentionally independent from saved wizard
126 * completion state. It lets an authorized user follow an explicit external
127 * setup URL without causing ordinary administration-page visits to reopen the
128 * completed wizard.
129 *
130 * @param string $step_name Expected Setup Wizard step identifier.
131 *
132 * @return bool True when the current URL explicitly requests the step.
133 */
134 function wpbc_setup_wizard_page__has_explicit_step_context( $step_name ) {
135
136 $step_name = sanitize_key( (string) $step_name );
137
138 if ( '' === $step_name ) {
139 return false;
140 }
141
142 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only UI context.
143 $setup_context = isset( $_GET['wpbc_setup'] ) && is_scalar( $_GET['wpbc_setup'] )
144 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only UI context.
145 ? sanitize_text_field( wp_unslash( $_GET['wpbc_setup'] ) )
146 : '';
147 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only UI context.
148 $request_step = isset( $_GET['wpbc_setup_step'] ) && is_scalar( $_GET['wpbc_setup_step'] )
149 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only UI context.
150 ? sanitize_key( wp_unslash( $_GET['wpbc_setup_step'] ) )
151 : '';
152
153 return '1' === $setup_context && $step_name === $request_step;
154 }
155
156
157 /**
158 * Check whether the current request is one explicit external Setup Wizard step.
159 *
160 * The setup context flag prevents ordinary visits to the same administration
161 * page from receiving wizard-only defaults.
162 *
163 * @param string $step_name Expected Setup Wizard step identifier.
164 *
165 * @return bool True when the unfinished wizard explicitly requested the step.
166 */
167 function wpbc_setup_wizard_page__is_active_step( $step_name ) {
168
169 $step_name = sanitize_key( (string) $step_name );
170
171 if ( '' === $step_name || ! wpbc_setup_wizard_page__is_in_progress() ) {
172 return false;
173 }
174
175 return wpbc_setup_wizard_page__has_explicit_step_context( $step_name );
176 }
177
178 /**
179 * Is user can access Wizard Setup page ?
180 * @return bool
181 */
182 function wpbc_is_user_can_access_wizard_page() {
183 $is_user_can_access_wizard_page = true;
184 if ( class_exists( 'wpdev_bk_multiuser' ) ) {
185
186 $real_current_user_id = get_current_user_id(); // Is current user suer booking admin and if this user was simulated log in
187 $is_user_super_admin = apply_bk_filter( 'is_user_super_admin', $real_current_user_id );
188 if ( ! $is_user_super_admin ) {
189 $is_user_can_access_wizard_page = false;
190 }
191 }
192
193 return $is_user_can_access_wizard_page;
194 }
195
196
197 // =====================================================================================================================
198 // == Shortcodes Content ==
199 // =====================================================================================================================
200
201 /**
202 * Get "Booking Form" Shortcode Content
203 *
204 * @param $resource_id
205 *
206 * @return false|string
207 */
208 function wpbc_setup_wizard_page__get_shortcode_html( $resource_id = 1 , $is_show_only_calendar = false ) {
209
210 ob_start();
211
212 $localized_js_vars_script = wpbc_get_localized_js_vars();
213
214 if ( $is_show_only_calendar ) {
215 // Center calendar.
216 ?><style type="text/css">
217 .wpbc_calendar_wraper {
218 display: flex;
219 flex-flow: column nowrap;
220 align-items: center;
221 justify-content: flex-start;
222 }
223 .wpbc_calendar_wraper div {
224 margin-bottom: 10px;
225 }
226 </style>
227 <div class="wpbc_shortcode_container"><?php
228 echo do_shortcode( '[bookingcalendar resource_id=' . $resource_id . ']' );
229 ?></div><?php
230
231 // If we use the [bookingcalendar] shortcode, then we remove this tag, for ability to select dates in calendar.
232 ?><script tye="text/javascript">
233 jQuery(document).ready(function(){
234 <?php
235 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
236 echo $localized_js_vars_script;
237 ?>
238 jQuery( 'body' ).on( 'wpbc_calendar_ajx__loaded_data', function( event, resource_id ) {
239 jQuery( '#calendar_booking_unselectable' + resource_id ).remove();
240 } );
241 });
242 </script><?php
243
244 } else {
245
246 // Help message
247 ?><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%);">
248 <strong><?php esc_html_e('Note','booking'); ?>: </strong>
249 <?php
250 esc_html_e( 'This is a preview of your booking form.', 'booking' ); echo ' ';
251 esc_html_e( 'You can adjust settings in the widgets on the right side of the page.', 'booking' );
252 //echo '<a href="' . esc_attr( function_exists( 'wpbc_get_general_availability_url' ) ? wpbc_get_general_availability_url() : admin_url( 'admin.php?page=wpbc-availability&tab=general_availability' ) ) . '">Availability > General Availability</a>';
253 ?>
254 </div><?php
255
256 // If we use the [bookingcalendar] shortcode, then we remove this tag, for ability to select dates in calendar.
257 ?><script type="text/javascript">
258 jQuery( document ).ready( function () {
259 <?php
260 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
261 echo $localized_js_vars_script;
262 ?>
263 _wpbc.set_other_param( 'calendars__on_this_page', [] );
264 <?php if ( 'On' === get_bk_option( 'booking_timeslot_picker') ) { ?>
265 wpbc_hook__init_timeselector();
266 <?php } ?>
267 wpbc_hook__init_booking_form_wizard_buttons();
268 // wpbc__calendar__change_skin( '<?php echo esc_url( WPBC_PLUGIN_URL . get_bk_option( 'booking_skin' ) ); ?>' );
269 // wpbc__css__change_skin( '<?php echo esc_url( WPBC_PLUGIN_URL . get_bk_option( 'booking_timeslot_picker_skin' ) ); ?>' );
270 <?php if ('wpbc_theme_dark_1' === get_bk_option( 'booking_form_theme' ) ){ ?>
271 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' );
272 <?php } ?>
273 if ( 'function' === typeof( wpbc_update_capacity_hint ) ) {
274 jQuery( '.booking_form_div' ).on( 'wpbc_booking_date_or_option_selected', function ( event, resource_id ) {
275 wpbc_update_capacity_hint( resource_id );
276 } );
277 }
278 //jQuery( 'body' ).on( 'wpbc_datepick_inline_calendar_loaded', function ( event, resource_id, jCalContainer, inst ) { });
279 // jQuery( 'body' ).off( 'wpbc_calendar_ajx__loaded_data' );
280 // jQuery( 'body' ).on( 'wpbc_calendar_ajx__loaded_data', function ( event, loaded_resource_id ){
281 // // wpbc_blink_element( '.wpbc_widget_change_form_structure', 3, 220 );
282 // wpbc_blink_element( '#ui_btn_cstm__set_booking_form_template_pro', 2, 220 );
283 // wpbc_blink_element( '#ui_btn_cstm__set_booking_form_template_apply', 4, 220 );
284 // });
285
286 // jQuery( 'body' ).on( 'wpbc_calendar_ajx__before_loaded_data', function( event, resource_id ) {
287 // wpbc_calendar__loading__stop( resource_id );
288 // } );
289 });
290 //if ( 'undefined' !== typeof _wpbc ) {
291 // <?php
292 // echo "_wpbc.set_other_param( 'availability__week_days_unavailable', ["
293 // . ( ( get_bk_option( 'booking_unavailable_day0') == 'On' ) ? '0,' : '' )
294 // . ( ( get_bk_option( 'booking_unavailable_day1') == 'On' ) ? '1,' : '' )
295 // . ( ( get_bk_option( 'booking_unavailable_day2') == 'On' ) ? '2,' : '' )
296 // . ( ( get_bk_option( 'booking_unavailable_day3') == 'On' ) ? '3,' : '' )
297 // . ( ( get_bk_option( 'booking_unavailable_day4') == 'On' ) ? '4,' : '' )
298 // . ( ( get_bk_option( 'booking_unavailable_day5') == 'On' ) ? '5,' : '' )
299 // . ( ( get_bk_option( 'booking_unavailable_day6') == 'On' ) ? '6,' : '' )
300 // . "999] ); ";
301 // ?>
302 //}
303 </script><?php
304
305 ?><div class="wpbc_shortcode_container"><?php
306 echo do_shortcode( '[booking resource_id=' . $resource_id . ']' );
307 ?></div><?php
308
309
310 }
311
312 return ob_get_clean();
313 }
314
315
316
317 function wpbc_setup_wizard_page__get_left_navigation_menu_arr(){
318
319 $navigation_menu_arr = array();
320 $setup_steps = new WPBC_SETUP_WIZARD_STEPS();
321
322 foreach ( array_keys( $setup_steps->get_steps_arr() ) as $step_name ) {
323 $navigation_menu_arr[ $step_name ] = array(
324 'title' => function_exists( 'wpbc_setup_wizard__get_step_title' ) ? wpbc_setup_wizard__get_step_title( $step_name ) : $step_name,
325 'icon' => 'wpbc_icn_circle_outline',
326 'class' => '',
327 'action' => "wpbc_ajx__setup_wizard_page__send_request_with_params( { 'current_step':'" . esc_js( $step_name ) . "' } );",
328 );
329 }
330
331 return $navigation_menu_arr;
332 }
333
334
335 /**
336 * Show Warning Conflict with "Wordfence" plugin
337 *
338 * @return void
339 */
340 function wpbc_maybe_show_warning_conflict__wordfence( $style = '' ) {
341 if ( class_exists( 'wordfence' ) ) {
342
343 $is_panel_visible = wpbc_is_dismissed_panel_visible( 'wpbc_show_warning_wordfence' ); // FixIn: 9.9.0.8.
344 if ( $is_panel_visible ) {
345 ?><div id="wpbc_show_warning_wordfence" class="wpbc-settings-notice notice-error notice-helpful-info0"
346 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 ); ?>"
347 >
348 <div>
349 <span style="margin: 0 5px 0 0;color: #e2892b;" ><i class="menu_icon icon-1x wpbc_icn_warning_amber"></i></span>
350 <?php
351 echo '<strong>' . esc_html__('Important!' ,'booking') . '</strong> ' ;
352 // FixIn: 10.9.1.1.
353 /* translators: 1: ... */
354 echo wp_kses_post( sprintf( __( 'We detect that you use %s plugin.', 'booking' ), '<strong>Wordfence</strong>' ) );
355
356 echo '<br>';
357
358 /* translators: 1: ... */
359 echo wp_kses_post( sprintf( __( 'If you encounter any issues, follow this %1$stroubleshooting instruction%2$s.', 'booking' ),
360 '<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>' ) );
361 ?>
362 </div>
363 <div><?php
364 ob_start();
365 $is_panel_visible = wpbc_is_dismissed( 'wpbc_show_warning_wordfence', array(
366 'title' => '<i class="menu_icon icon-1x wpbc_icn_close"></i> ',
367 'hint' => __( 'Dismiss', 'booking' ),
368 'class' => 'wpbc_panel_get_started_dismiss',
369 'css' => 'background: #fff;border-radius: 7px;'
370 ));
371
372 $dismiss_x_button = ob_get_clean();
373
374 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
375 echo wpbc_replace__js_scripts__to__tpl_scripts( $dismiss_x_button );
376
377 ?></div>
378 </div><?php
379 }
380
381
382
383 }
384 }
385
386
387 /**
388 * Escape scripts from the Booking Calendar shortcode content for showing in Wizard templates.
389 *
390 * @param string $calendar_html_content - usualy it is the content of [booking ...] shortcode.
391 *
392 * @return mixed
393 */
394 function wpbc_clean_calendar_loading_scripts( $calendar_html_content ) {
395
396 // Prevent of any intention usage od this tag.
397 $calendar_html_content = str_replace( 'ajax_scrpt', '', $calendar_html_content );
398
399 $pattern = '/<script\s*(type=[\'"]+text\/javascript[\'"]+)?\s*>/i';
400 $calendar_html_content = preg_replace( $pattern, '<ajax_scrpt>', $calendar_html_content );
401
402 $pattern = '/<\/script>/i';
403 $calendar_html_content = preg_replace( $pattern, '</ajax_scrpt>', $calendar_html_content );
404
405 return $calendar_html_content;
406 }
407