PluginProbe
Booking Calendar / 11.5
Booking Calendar v11.5
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 10.11 All 204 releases
booking / includes / page-setup / setup_support.php

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

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