PluginProbe
Booking Calendar / 11.2
Booking Calendar v11.2
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 / includes / page-setup / setup_support.php

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

288 lines 11.2 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( 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>';
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 function wpbc_setup_wizard_page__get_left_navigation_menu_arr(){
199
200 $navigation_menu_arr = array();
201 $setup_steps = new WPBC_SETUP_WIZARD_STEPS();
202
203 foreach ( array_keys( $setup_steps->get_steps_arr() ) as $step_name ) {
204 $navigation_menu_arr[ $step_name ] = array(
205 'title' => function_exists( 'wpbc_setup_wizard__get_step_title' ) ? wpbc_setup_wizard__get_step_title( $step_name ) : $step_name,
206 'icon' => 'wpbc_icn_circle_outline',
207 'class' => '',
208 'action' => "wpbc_ajx__setup_wizard_page__send_request_with_params( { 'current_step':'" . esc_js( $step_name ) . "' } );",
209 );
210 }
211
212 return $navigation_menu_arr;
213 }
214
215
216 /**
217 * Show Warning Conflict with "Wordfence" plugin
218 *
219 * @return void
220 */
221 function wpbc_maybe_show_warning_conflict__wordfence( $style = '' ) {
222 if ( class_exists( 'wordfence' ) ) {
223
224 $is_panel_visible = wpbc_is_dismissed_panel_visible( 'wpbc_show_warning_wordfence' ); // FixIn: 9.9.0.8.
225 if ( $is_panel_visible ) {
226 ?><div id="wpbc_show_warning_wordfence" class="wpbc-settings-notice notice-error notice-helpful-info0"
227 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 ); ?>"
228 >
229 <div>
230 <span style="margin: 0 5px 0 0;color: #e2892b;" ><i class="menu_icon icon-1x wpbc_icn_warning_amber"></i></span>
231 <?php
232 echo '<strong>' . esc_html__('Important!' ,'booking') . '</strong> ' ;
233 // FixIn: 10.9.1.1.
234 /* translators: 1: ... */
235 echo wp_kses_post( sprintf( __( 'We detect that you use %s plugin.', 'booking' ), '<strong>Wordfence</strong>' ) );
236
237 echo '<br>';
238
239 /* translators: 1: ... */
240 echo wp_kses_post( sprintf( __( 'If you encounter any issues, follow this %1$stroubleshooting instruction%2$s.', 'booking' ),
241 '<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>' ) );
242 ?>
243 </div>
244 <div><?php
245 ob_start();
246 $is_panel_visible = wpbc_is_dismissed( 'wpbc_show_warning_wordfence', array(
247 'title' => '<i class="menu_icon icon-1x wpbc_icn_close"></i> ',
248 'hint' => __( 'Dismiss', 'booking' ),
249 'class' => 'wpbc_panel_get_started_dismiss',
250 'css' => 'background: #fff;border-radius: 7px;'
251 ));
252
253 $dismiss_x_button = ob_get_clean();
254
255 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
256 echo wpbc_replace__js_scripts__to__tpl_scripts( $dismiss_x_button );
257
258 ?></div>
259 </div><?php
260 }
261
262
263
264 }
265 }
266
267
268 /**
269 * Escape scripts from the Booking Calendar shortcode content for showing in Wizard templates.
270 *
271 * @param string $calendar_html_content - usualy it is the content of [booking ...] shortcode.
272 *
273 * @return mixed
274 */
275 function wpbc_clean_calendar_loading_scripts( $calendar_html_content ) {
276
277 // Prevent of any intention usage od this tag.
278 $calendar_html_content = str_replace( 'ajax_scrpt', '', $calendar_html_content );
279
280 $pattern = '/<script\s*(type=[\'"]+text\/javascript[\'"]+)?\s*>/i';
281 $calendar_html_content = preg_replace( $pattern, '<ajax_scrpt>', $calendar_html_content );
282
283 $pattern = '/<\/script>/i';
284 $calendar_html_content = preg_replace( $pattern, '</ajax_scrpt>', $calendar_html_content );
285
286 return $calendar_html_content;
287 }
288