PluginProbe
Booking Calendar / 11.4
Booking Calendar v11.4
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 10.11.4 10.12.0 10.12.1 All 199 releases
booking / includes / _functions / booking_data__parse.php

booking_data__parse.php in Booking Calendar 11.4, at includes/_functions/booking_data__parse.php

1,212 lines 44.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @version 1.0
4 * @package Booking Calendar
5 * @subpackage Booking Data Parsing functions
6 * @category Functions
7 *
8 * @author wpdevelop
9 * @link https://wpbookingcalendar.com/
10 * @email info@wpbookingcalendar.com
11 *
12 * @modified 2024-05-14
13 * @file ../includes/_functions/booking_data__parse.php
14 */
15
16 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
17
18 // =====================================================================================================================
19 // == B o o k i n g F o r m s P a r s i n g ==
20 // =====================================================================================================================
21
22 /**
23 * Parse "text^firstname1^John~..." -> [ 'firstname':[name:"firstname", value:"John" ...] ... ] - Parse (DB) form_data and get fields array values
24 *
25 * @param string $form_data - formatted booking form data from database, like this: 'text^selected_short_dates_hint15^21/02/2023 - 24/02/2023~text^days_number_hint15^4~text^cost_hint15^&amp;#36;400.00~text^deposit_hint15^&amp;#36;40.00~text^standard_bk_cost15^100~...'
26 * @param int $resource_id - ID of booking resource
27 * @param array $params - (optional) default: array() define here what field we need to get array( 'get' => 'value' )
28 *
29 * @return array
30 * [
31 * rangetime = [
32 * type = "selectbox-multiple"
33 * original_name = "rangetime3[]"
34 * name = "rangetime"
35 * value = "12:00 - 14:00"
36 * ]
37 * name = [
38 * type = "text"
39 * original_name = "name3"
40 * name = "name"
41 * value = "test 1"
42 * ]
43 * secondname = [...]
44 * email = [...]
45 * ]
46 *
47 * Example 1:
48 * $structured_booking_data_arr = wpbc_get_parsed_booking_data_arr( $this_booking->form, $resource_id, array( 'get' => 'value' ) );
49 * output: [ "rangetime" : "12:00 - 14:00",
50 * "name": "John" ,
51 * "secondname" : "Smith" , "email" : "test@wpbookingcalendar.com" , "visitors" : "1" ... ]
52 *
53 * Example 2:
54 * $structured_booking_data_arr = wpbc_get_parsed_booking_data_arr( $this_booking->form, $resource_id );
55 * output: [ rangetime = [
56 * type = "selectbox-multiple"
57 * original_name = "rangetime3[]"
58 * name = "rangetime"
59 * value = "12:00 - 14:00"
60 * ]
61 * name = [
62 * type = "text"
63 * original_name = "name3"
64 * name = "name"
65 * value = "test 1"
66 * ]
67 * secondname = [...]
68 * email = [...]
69 * ]
70 */
71 function wpbc_get_parsed_booking_data_arr( $form_data, $resource_id = 1, $params = array( ) ) {
72
73 $booking_data_arr = array();
74
75 if ( ! empty( $form_data ) ) {
76
77 $fields_arr = explode( '~', $form_data );
78
79 foreach ( $fields_arr as $field ) {
80
81 if ( false === strpos( $field, '^' ) ) {
82 break; // FixIn: 9.8.10.2.
83 }
84
85 list( $field_type, $field_original_name, $field_value ) = explode( '^', $field );
86
87 $field_name = $field_original_name;
88
89 // Is this multi select in checkboxes: [checkbox* ConducenteExtra "Si" "No"] => [... 6: "checkbox^ConducenteExtra4[]^Si", 7: "checkbox^ConducenteExtra4[]^" ... ]
90 $is_multi_options = ( '[]' == substr( $field_name, - 2 ) );
91
92 $minus_additional = ( '[]' == substr( $field_name, - 2 ) ) ? 2 : 0;
93 $field_name = ( $minus_additional > 0 ) ? substr( $field_name, 0, - $minus_additional ) : $field_name;
94
95
96 $minus_additional = ( strval( $resource_id ) == substr( $field_name, - 1 * ( strlen( strval( $resource_id ) ) ) ) )
97 ? strlen( strval( $resource_id ) ) : 0;
98 $field_name = ( $minus_additional > 0 ) ? substr( $field_name, 0, - $minus_additional ) : $field_name;
99
100 if ( ( 'checkbox' === $field_type ) && ( 'true' === $field_value ) ) {
101 //$field_value = strtolower( __( 'Yes', 'booking' ) );
102 $field_value = 'true';
103 }
104 if ( ( 'checkbox' === $field_type ) && ( 'false' === $field_value ) ) {
105 //$field_value = strtolower( __( 'No', 'booking' ) );
106 $field_value = 'false';
107 }
108
109 if ( ! isset( $booking_data_arr[ $field_name ] ) ) {
110 $booking_data_arr[ $field_name ] = array(
111 'type' => $field_type,
112 'original_name' => $field_original_name,
113 'name' => $field_name,
114 'value' => array( $field_value )
115 );
116 } else {
117 // All values we save as array values, for situations of MULTI options:
118 // [checkbox* ConducenteExtra "Si" "No"] => [... 6: "checkbox^ConducenteExtra4[]^Si", 7: "checkbox^ConducenteExtra4[]^" ... ]
119 $booking_data_arr[ $field_name ]['value'][] = $field_value;
120 }
121 }
122
123 // Convert arrays to string
124 foreach ( $booking_data_arr as $field_name => $field_structure_arr ) { // FixIn: 9.8.9.1.
125 $field_structure_arr['value'] = array_filter( $field_structure_arr['value'], function ( $v ) {
126 return ( $v !== '' ); // Remove All '' entries
127 } );
128 $booking_data_arr[ $field_name ]['value'] = implode( ', ', $field_structure_arr['value'] );
129 }
130
131
132 if ( isset( $params['get'] ) ) {
133 /**
134 * Now get only values or other fields: [
135 * "rangetime" : "12:00 - 14:00",
136 * "name":"test 1" ,
137 * "secondname" : "test 1" ,
138 * "email" : "test@wpbookingcalendar.com" ,
139 * "visitors" : "1"
140 * ...
141 * ]
142 */
143
144 foreach ( $booking_data_arr as $field_name => $field_structure_arr ) {
145
146 if ( isset( $field_structure_arr[ $params['get'] ] ) ) {
147 $booking_data_arr[ $field_name ] = $field_structure_arr[ $params['get'] ];
148 } else {
149 $booking_data_arr[ $field_name ] = '-';
150 }
151 }
152 }
153 }
154
155 return $booking_data_arr;
156 }
157
158 /**
159 * Convert [ ... ] -> "text^firstname1^John~..." - encoded booking data string (Usually for inserting into DB), from parsed booking data array
160 *
161 * @param array $booking_data_arr - parsed booking data.
162 * @param int $resource_id - ID of booking resource - In case, if we need to RE-UPDATE booking resource, Otherwise skip it
163 *
164 * @return string
165 */
166 function wpbc_encode_booking_data_to_string( $booking_data_arr, $resource_id = 0 ) {
167
168 $fields_arr = array();
169
170 foreach ( $booking_data_arr as $fields ) {
171
172 if ( ! empty( $resource_id ) ) {
173 $fields_arr[] = $fields['type']
174 . '^' . $fields['name'] . $resource_id . ( ( '[]' == substr( $fields['original_name'], - 2 ) ) ? '[]' : '' )
175 . '^' . $fields['value'];
176 } else {
177 $fields_arr[] = $fields['type'] . '^' . $fields['original_name'] . '^' . $fields['value'];
178 }
179
180 }
181
182 $form_data = implode( '~', $fields_arr );
183
184 return $form_data;
185 }
186
187 // -------------------------------------------------------------------------------------------------------------
188
189 /**
190 * Get Time fields in booking form_data
191 *
192 * @param string $form_data - formatted booking form data from database, like this: 'text^selected_short_dates_hint15^21/02/2023 - 24/02/2023~text^days_number_hint15^4~text^cost_hint15^&amp;#36;400.00~text^deposit_hint15^&amp;#36;40.00~text^standard_bk_cost15^100~...'
193 * @param int $resource_id - ID of booking resource
194 * @param array $params - (optional) default: array() define here what field we need to get array( 'get' => 'value' )
195 *
196 * @return array [ "18:00:00", "20:00:00" ] <- default
197 *
198 * Example #1: $times_his_arr = wpbc_get_times_his_arr__in_form_data( $form_data, $resource_id); --> [ "18:00:01", "20:00:02" ]
199 * same: $times_his_arr = wpbc_get_times_his_arr__in_form_data( $form_data, $resource_id, array( 'get' => 'times_his_arr' ) ); --> [ "18:00:01", "20:00:02" ]
200 * Example #2: $time_as_seconds_arr = wpbc_get_times_his_arr__in_form_data( $form_data, $resource_id, array( 'get' => 'time_as_seconds_arr' ) ); --> [ 64800, 72000 ]
201 * Example #4: $booking_data_arr = wpbc_get_times_his_arr__in_form_data( $form_data, $resource_id, array( 'get' => 'structured_booking_data_arr' ) ); --> [ name = "John", secondname = "Smith", email = "john.smith@server.com", visitors = "2",... ]
202 *
203 * Example #5: $booking_data_arr = wpbc_get_times_his_arr__in_form_data( $form_data, $resource_id, array( 'get' => 'all' ) );
204 * --> [
205 * 'structured_booking_data_arr' => [ name = "John", secondname = "Smith", email = "john.smith@server.com", visitors = "2",... ]
206 * 'time_as_seconds_arr' => [ 64800, 72000 ]
207 * 'time_as_his_arr' => [ "18:00:01", "20:00:02" ]
208 * ]
209 */
210 function wpbc_get_times_his_arr__in_form_data( $form_data, $resource_id = 1, $params = array() ) {
211
212 $defaults = array(
213 'get' => 'times_his_arr'
214 );
215 $params = wp_parse_args( $params, $defaults );
216
217
218 // Get Time from booking form
219 $local_params = array();
220 /**
221 * Get parsed booking form: = [ name = "John", secondname = "Smith", email = "john.smith@server.com", visitors = "2",... ]
222 */
223 $local_params['structured_booking_data_arr'] = wpbc_get_parsed_booking_data_arr( $form_data, $resource_id, array( 'get' => 'value' ) );
224 // $local_params['all_booking_data_arr'] = wpbc_get_parsed_booking_data_arr( $form_data, $resource_id );
225
226 // Important! : [ 64800, 72000 ]
227 $local_params['time_as_seconds_arr'] = wpbc_get_in_booking_form__time_to_book_as_seconds_arr( $local_params['structured_booking_data_arr'] );
228
229 // [ "18:00:00", "20:00:00" ]
230 $time_as_seconds_arr = $local_params['time_as_seconds_arr'];
231 $time_as_seconds_arr[0] = ( 0 != $time_as_seconds_arr[0] ) ? $time_as_seconds_arr[0] + 1 : $time_as_seconds_arr[0]; // set check in time with ended 1 second
232 $time_as_seconds_arr[1] = ( ( 24 * 60 * 60 ) != $time_as_seconds_arr[1] ) ? $time_as_seconds_arr[1] + 2 : $time_as_seconds_arr[1]; // set check out time with ended 2 seconds
233 if ( ( 0 != $time_as_seconds_arr[0] ) && ( ( 24 * 60 * 60 ) == $time_as_seconds_arr[1] ) ) {
234 //FixIn: 10.0.0.49 - in case if we have start time != 00:00 and end time as 24:00 then set end time as 23:59:52
235 $time_as_seconds_arr[1] += - 8;
236 }
237 // [ '16:00:01', '18:00:02' ]
238 $local_params['times_his_arr'] = array(
239 wpbc_transform__seconds__in__24_hours_his( $time_as_seconds_arr[0] ),
240 wpbc_transform__seconds__in__24_hours_his( $time_as_seconds_arr[1] )
241 );
242 if (
243 ( isset( $params['get'] ) )
244 && ( isset( $local_params[ $params['get'] ] ) )
245 ) {
246 return $local_params[ $params['get'] ];
247 }
248
249 return $local_params;
250 }
251
252 // -------------------------------------------------------------------------------------------------------------
253
254 /**
255 * Get readable booking form data. Escape values here, as well!
256 *
257 * - 1. <= BS : 'Booking form show' configuration from standard form in versions up to Business Small version ,
258 * - 2 >= BM : If form data has field of custom form, then from custom form configuration,
259 * - 3 >= BM : Otherwise if resource has default custom booking form, then from this default custom booking form
260 * - 4 = MU : specific form of specific WP User
261 * - 5 finally : simple standard form
262 *
263 * @param string $form_data
264 * @param int $resource_id
265 *
266 * @return string
267 */
268 function wpbc_get__booking_form_data__show( $form_data, $resource_id = 1 , $params = array() ) {
269
270 $defaults = array(
271 'is_replace_unknown_shortcodes' => true,
272 'unknown_shortcodes_replace_by' => ''
273 );
274 $params = wp_parse_args( $params, $defaults );
275
276 $booking_form_show = wpbc_get__booking_form_data_configuration( $resource_id, $form_data, $params );
277
278 $booking_data_arr = wpbc_get_parsed_booking_data_arr( $form_data, $resource_id, array( 'get' => 'value' ) );
279
280 foreach ( $booking_data_arr as $key_param => $value_param ) { // FixIn: 6.1.1.4.
281
282 $value_param = esc_html( $value_param ); //FixIn: 9.7.4.1 - escape coded html/xss
283 $value_param = esc_html( html_entity_decode( $value_param ) );
284 $value_param = nl2br($value_param); // Add BR instead if /n elements // FixIn: 9.7.4.2.
285 $value_param = wpbc_string__escape__then_convert__n_amp__html( $value_param );
286
287 $value_param = wpbc_replace__true_false__to__yes_no( $value_param ); // FixIn: 9.8.9.1.
288
289 if (
290 ( gettype( $value_param ) != 'array' )
291 && ( gettype( $value_param ) != 'object' )
292 ) {
293 $booking_form_show = str_replace( '[' . $key_param . ']', $value_param, $booking_form_show );
294 }
295 }
296
297 if ($params['is_replace_unknown_shortcodes']) {
298 // Remove all shortcodes, which is not replaced early.
299 $booking_form_show = preg_replace( '/[\s]{0,}\[[a-zA-Z0-9.,-_]{0,}\][\s]{0,}/', $params['unknown_shortcodes_replace_by'], $booking_form_show ); // FixIn: 6.1.1.4.
300 }
301
302 $booking_form_show = str_replace( "&amp;", '&', $booking_form_show ); // FixIn: 7.1.2.12.
303
304
305
306 return $booking_form_show;
307 }
308
309 /**
310 * Get name of custom booking form, if it was used in form data OR booking resource use this default custom form
311 *
312 * @param int $resource_id
313 * @param string $form_data Form data here, required in >= BM, because such form_data can contain fields about used custom booking form
314 *
315 * @return string
316 */
317 function wpbc_get__custom_booking_form_name( $resource_id = 1, $form_data = '' ) {
318
319 $my_booking_form_name = '';
320
321 if ( class_exists( 'wpdev_bk_biz_m' ) ) {
322
323 if ( false !== strpos( $form_data, 'wpbc_custom_booking_form' . $resource_id . '^' ) ) { // FixIn: 9.4.3.12.
324
325 $custom_booking_form_name = substr( $form_data, strpos( $form_data, 'wpbc_custom_booking_form' . $resource_id . '^' ) + strlen( 'wpbc_custom_booking_form' . $resource_id . '^' ) );
326
327 if ( false !== strpos( $custom_booking_form_name, '~' ) ) {
328 $custom_booking_form_name = substr( $custom_booking_form_name, 0, strpos( $custom_booking_form_name, '~' ) );
329 $my_booking_form_name = $custom_booking_form_name;
330 }
331
332 } else {
333
334 // BM :: Get default Custom Form of Resource
335 $my_booking_form_name = apply_bk_filter( 'wpbc_get_default_custom_form', 'standard', $resource_id );
336 }
337
338 if ( 'standard' == $my_booking_form_name ) {
339 $my_booking_form_name = '';
340 }
341 }
342
343 return $my_booking_form_name;
344 }
345
346 /**
347 * Get configuration of 'BOOKING FORM F I E L D S SHORTCODES' from - Booking > Settings > Form page
348 *
349 * - 1. <= BS : 'Booking form show' configuration from standard form in versions up to Business Small version ,
350 * - 2 >= BM : If form data has field of custom form, then from custom form configuration,
351 * - 3 >= BM : Otherwise if resource has default custom booking form, then from this default custom booking form
352 * - 4 = MU : specific form of specific WP User
353 * - 5 finally : simple standard form
354 *
355 * @param int $resource_id
356 * @param string $form_name Name of custom booking form, required in >= BM
357 *
358 * @return string
359 *
360 * Example 1: $booking_form = wpbc_get__booking_form_fields__configuration( 1 ); <- Load STANDARD booking form
361 * Example 2: $booking_form = wpbc_get__booking_form_fields__configuration( 1 , 'standard' ); <- Load STANDARD booking form
362 * Example 3: $booking_form = wpbc_get__booking_form_fields__configuration( 1 , 'my_custom_form' ); <- Load CUSTOM booking form with name 'my_custom_form'
363 * Example 4: $booking_form = wpbc_get__booking_form_fields__configuration( 1 , '' ); <- Load CUSTOM booking form, which is DEFAULT for RESOURCE
364 * Example 4: $booking_form = wpbc_get__booking_form_fields__configuration( 10 ); <- If resource ID = 10 belong to REGULAR User, then load booking form for this REGULAR USER
365 *
366 */
367 function wpbc_get__booking_form_fields__configuration( $resource_id = 1, $form_name = 'standard' ) {
368
369 $pair = wpbc_get__bfb_booking_form_pair__for_field_names_listing( $resource_id, $form_name, wpbc_get_request_form_context() );
370
371 // Language
372 $booking_form_configuration = isset( $pair['form'] ) ? wpbc_lang( (string) $pair['form'] ) : '';
373
374 return $booking_form_configuration;
375 }
376
377
378 /**
379 * Load BFB preview payload from transient (for booking created inside preview iframe).
380 *
381 * @param array $ctx
382 * @return array|null
383 */
384 function wpbc_bfb_preview__maybe_get_payload_from_context( $ctx ) {
385
386 $ctx = ( is_array( $ctx ) ) ? $ctx : array();
387
388 $user_id = isset( $ctx['user_id'] ) ? absint( $ctx['user_id'] ) : 0;
389 $form_id = isset( $ctx['wpbc_bfb_preview_form_id'] ) ? absint( $ctx['wpbc_bfb_preview_form_id'] ) : 0;
390 $token = isset( $ctx['wpbc_bfb_preview_token'] ) ? sanitize_key( $ctx['wpbc_bfb_preview_token'] ) : '';
391 $nonce = isset( $ctx['wpbc_bfb_preview_nonce'] ) ? sanitize_text_field( $ctx['wpbc_bfb_preview_nonce'] ) : '';
392
393 if ( $user_id <= 0 || $form_id <= 0 || '' === $token ) {
394 return null;
395 }
396
397 // Optional hardening: verify nonce if present.
398 if ( '' !== $nonce ) {
399 if ( ! wp_verify_nonce( $nonce, 'wpbc_bfb_preview_' . $token ) ) {
400 return null;
401 }
402 }
403
404 // Optional hardening: capability check (preview is admin-only anyway).
405 $cap = ( function_exists( 'wpbc_bfb_get_manage_cap' ) ) ? wpbc_bfb_get_manage_cap() : 'manage_options';
406 if ( ! is_user_logged_in() || ! current_user_can( $cap ) ) {
407 return null;
408 }
409
410 $transient_key = 'wpbc_bfb_preview_' . $user_id . '_' . $form_id . '_' . $token;
411
412 $data = get_transient( $transient_key );
413 if ( empty( $data ) || ! is_array( $data ) ) {
414 return null;
415 }
416
417 return $data;
418 }
419
420
421 /**
422 * Get configuration of 'BOOKING FORM DATA' from - Booking > Settings > Form page
423 *
424 * - 1. <= BS : 'Booking form show' configuration from standard form in versions up to Business Small version ,
425 * - 2 >= BM : If form data has field of custom form, then from custom form configuration,
426 * - 3 >= BM : Otherwise if resource has default custom booking form, then from this default custom booking form
427 * - 4 = MU : specific form of specific WP User
428 * - 5 finally : simple standard form
429 *
430 * @param int $resource_id
431 * @param string $form_data Form data here, required in >= BM, because such form_data can contain fields about used custom booking form
432 *
433 * @return string
434 */
435 function wpbc_get__booking_form_data_configuration( $resource_id = 1, $form_data = '', $params = array() ) {
436
437 // FixIn: 2026-02-05 - allow preview booking submissions to use preview "content_form".
438 $ctx = wp_parse_args( ( is_array( $params ) ? $params : array() ), wpbc_get_request_form_context() );
439
440 $form_status = ( isset( $ctx['form_status'] ) ) ? sanitize_key( $ctx['form_status'] ) : 'published';
441
442 if ( 'preview' === $form_status ) {
443
444 $payload = wpbc_bfb_preview__maybe_get_payload_from_context( $ctx );
445
446 // content_form is exactly the "Booking form show" template exported for preview session.
447 if ( ! empty( $payload ) && isset( $payload['content_form'] ) && ( '' !== (string) $payload['content_form'] ) ) {
448 return (string) $payload['content_form'];
449 }
450 }
451
452 $resource_id = (int) $resource_id;
453 $form_data = (string) $form_data;
454 $my_booking_form_name = 'standard';
455
456 // Maybe get name of custom booking form, that was saved in the booking data.
457 if ( false !== strpos( $form_data, 'wpbc_custom_booking_form' . $resource_id . '^' ) ) { // FixIn: 9.4.3.12.
458
459 $custom_booking_form_name = substr( $form_data, strpos( $form_data, 'wpbc_custom_booking_form' . $resource_id . '^' ) + strlen( 'wpbc_custom_booking_form' . $resource_id . '^' ) );
460
461 if ( false !== strpos( $custom_booking_form_name, '~' ) ) {
462 $custom_booking_form_name = substr( $custom_booking_form_name, 0, strpos( $custom_booking_form_name, '~' ) );
463 }
464 if ( ! empty( $custom_booking_form_name ) ) {
465 $my_booking_form_name = $custom_booking_form_name;
466 }
467 }
468
469
470 if ( 'standard' === $my_booking_form_name || '' === $my_booking_form_name ) {
471 $resource_default_custom_form_name = apply_bk_filter( 'wpbc_get_default_custom_form', 'standard', $resource_id );
472 if ( ! empty( $resource_default_custom_form_name ) ) {
473 $my_booking_form_name = $resource_default_custom_form_name;
474 }
475 }
476
477 $booking_form_show = WPBC_BFB_Booking_Data_Content_Resolver::maybe_override_booking_form_show_by_bfb( '', $resource_id, $my_booking_form_name, $form_data, $ctx );
478
479 // Language.
480 $booking_form_show = wpbc_lang( $booking_form_show );
481
482 return $booking_form_show;
483 }
484
485
486 // -------------------------------------------------------------------------------------------------------------
487
488 /**
489 * Replace resource_ID of booking in 'form_data'
490 * Useful, when we need to save booking from one resource into another.
491 *
492 * @param $booking__form_data__str 'selectbox-multiple^rangetime2[]^18:00 - 20:00~checkbox^fee2[]^true~text^name2^John~text^secondname2^Smith...'
493 * @param $new_resource_id 10
494 * @param $old_resource_id 2
495 *
496 * @return string 'selectbox-multiple^rangetime10[]^18:00 - 20:00~checkbox^fee10[]^true~text^name10^John~text^secondname10^Smith...'
497 */
498 function wpbc_get__form_data__with_replaced_id( $booking__form_data__str, $new_resource_id, $old_resource_id ) {
499
500 $all_booking_data_arr = wpbc_get_parsed_booking_data_arr( $booking__form_data__str, $old_resource_id );
501
502 $new__form_data__str = wpbc_encode_booking_data_to_string( $all_booking_data_arr, $new_resource_id );
503
504 return $new__form_data__str;
505 }
506
507 // FixIn: 10.15.4.1.
508 /**
509 * Extract "advanced_form" from BFB loader result.
510 *
511 * @param mixed $bfb_pair
512 *
513 * @return string
514 */
515 function wpbc_extract__advanced_form_from_bfb_pair__for_field_names_listing( $bfb_pair ) {
516
517 $containers = array();
518
519 if ( ! is_array( $bfb_pair ) ) {
520 return '';
521 }
522
523 /**
524 * Safety:
525 * Do not override if loader already fell back to legacy.
526 */
527 if ( isset( $bfb_pair['source'] ) && ( 'builder' !== $bfb_pair['source'] ) ) {
528 return '';
529 }
530
531 $containers[] = $bfb_pair;
532
533 if ( isset( $bfb_pair['pair'] ) && is_array( $bfb_pair['pair'] ) ) {
534 $containers[] = $bfb_pair['pair'];
535 }
536
537 if ( isset( $bfb_pair['form'] ) && is_array( $bfb_pair['form'] ) ) {
538 $containers[] = $bfb_pair['form'];
539 }
540
541 foreach ( $containers as $container ) {
542
543 if ( isset( $container['form'] ) && is_string( $container['form'] ) ) {
544 return (string) $container['form'];
545 }
546
547 if ( isset( $container['advanced_form'] ) && is_string( $container['advanced_form'] ) ) {
548 return (string) $container['advanced_form'];
549 }
550 }
551
552 return '';
553 }
554
555
556 /**
557 * Extract "content_form" from BFB loader result.
558 *
559 * @param mixed $bfb_pair
560 *
561 * @return string
562 */
563 function wpbc_extract__content_form_from_bfb_pair__for_field_names_listing( $bfb_pair ) {
564
565 $containers = array();
566
567 if ( ! is_array( $bfb_pair ) ) {
568 return '';
569 }
570
571 /**
572 * Safety:
573 * Do not override if loader already fell back to legacy.
574 */
575 if ( isset( $bfb_pair['source'] ) && ( 'builder' !== $bfb_pair['source'] ) ) {
576 return '';
577 }
578
579 $containers[] = $bfb_pair;
580
581 if ( isset( $bfb_pair['pair'] ) && is_array( $bfb_pair['pair'] ) ) {
582 $containers[] = $bfb_pair['pair'];
583 }
584
585 if ( isset( $bfb_pair['form'] ) && is_array( $bfb_pair['form'] ) ) {
586 $containers[] = $bfb_pair['form'];
587 }
588
589 foreach ( $containers as $container ) {
590
591 if ( isset( $container['content'] ) && is_string( $container['content'] ) ) {
592 return (string) $container['content'];
593 }
594
595 if ( isset( $container['content_form'] ) && is_string( $container['content_form'] ) ) {
596 return (string) $container['content_form'];
597 }
598 }
599
600 return '';
601 }
602
603
604 /**
605 * Maybe get booking form pair from BFB using the same resolver chain as front-end rendering.
606 *
607 * @param int $resource_id
608 * @param string $form_name
609 * @param array $ctx
610 *
611 * @return array
612 */
613 function wpbc_get__bfb_booking_form_pair__for_field_names_listing( $resource_id = 1, $form_name = 'standard', $ctx = array() ) {
614
615 $resource_id = absint( $resource_id );
616 $form_name = sanitize_text_field( (string) $form_name );
617 $ctx = ( is_array( $ctx ) ) ? $ctx : array();
618
619 if ( '' === $form_name ) {
620 $form_name = 'standard';
621 }
622
623 $owner_user_id = isset( $ctx['owner_user_id'] ) ? absint( $ctx['owner_user_id'] ) : null;
624
625 if ( ! class_exists( 'WPBC_FE_Form_Source_Resolver' ) ) {
626 return array();
627 }
628
629 if ( ! function_exists( 'wpbc_bfb_get_booking_form_pair' ) ) {
630 return array();
631 }
632
633 $form_status = isset( $ctx['form_status'] ) ? sanitize_key( $ctx['form_status'] ) : 'published';
634
635 if ( in_array( $form_status, array( 'publish', 'published' ), true ) ) {
636 $form_status = 'published';
637 }
638 if ( 'preview' !== $form_status ) {
639 $form_status = 'published';
640 }
641
642 /**
643 * Preview payload shortcut.
644 */
645 if (
646 ( 'preview' === $form_status )
647 && function_exists( 'wpbc_bfb_preview__maybe_get_payload_from_context' )
648 ) {
649 $payload = wpbc_bfb_preview__maybe_get_payload_from_context( $ctx );
650
651 if ( ! empty( $payload ) && is_array( $payload ) ) {
652
653 $pair = array(
654 'form' => isset( $payload['advanced_form'] ) ? (string) $payload['advanced_form'] : '',
655 'content' => isset( $payload['content_form'] ) ? (string) $payload['content_form'] : '',
656 );
657
658 if ( ( '' !== trim( $pair['form'] ) ) || ( '' !== trim( $pair['content'] ) ) ) {
659 return $pair;
660 }
661 }
662 }
663
664 $req = array(
665 'resource_id' => $resource_id,
666 'form_slug' => $form_name,
667 'form_status' => $form_status,
668 'custom_params' => array(),
669 'legacy_instance' => null,
670 'ctx' => $ctx,
671 );
672
673 if ( null !== $owner_user_id ) {
674 $req['owner_user_id'] = $owner_user_id;
675 }
676
677 $resolved = WPBC_FE_Form_Source_Resolver::resolve( $req );
678
679 // Same behavior as your content resolver: preview can fallback to published.
680 if (
681 ( empty( $resolved['engine'] ) || ( 'bfb_db' !== $resolved['engine'] ) )
682 && ( 'preview' === $form_status )
683 ) {
684 $req['form_status'] = 'published';
685 $resolved = WPBC_FE_Form_Source_Resolver::resolve( $req );
686 }
687
688 if ( empty( $resolved['engine'] ) || ( 'bfb_db' !== $resolved['engine'] ) ) {
689 return array();
690 }
691
692 $bfb_loader_args = array();
693
694 if ( ! empty( $resolved['bfb_loader_args'] ) && is_array( $resolved['bfb_loader_args'] ) ) {
695 $bfb_loader_args = $resolved['bfb_loader_args'];
696 }
697
698 $bfb_pair = wpbc_bfb_get_booking_form_pair( $bfb_loader_args );
699
700 $pair = array(
701 'form' => wpbc_extract__advanced_form_from_bfb_pair__for_field_names_listing( $bfb_pair ),
702 'content' => wpbc_extract__content_form_from_bfb_pair__for_field_names_listing( $bfb_pair ),
703 );
704
705 if ( '' === trim( $pair['form'] ) && '' === trim( $pair['content'] ) ) {
706 return array();
707 }
708
709 return $pair;
710 }
711
712
713 /**
714 * Get booking form pair (fields + show template) for listing/inspection purposes.
715 *
716 * Uses BFB resolver and returns advanced_form + content_form.
717 *
718 * @param int $resource_id
719 * @param string $form_name
720 * @param array $ctx
721 *
722 * @return array
723 */
724 function wpbc_get__booking_form_pair__for_field_names_listing( $resource_id = 1, $form_name = 'standard', $ctx = array() ) {
725
726 $resource_id = absint( $resource_id );
727 $form_name = sanitize_text_field( (string) $form_name );
728 $ctx = ( is_array( $ctx ) ) ? $ctx : array();
729
730 if ( '' === $form_name ) {
731 $form_name = 'standard';
732 }
733
734 $bfb_pair = wpbc_get__bfb_booking_form_pair__for_field_names_listing( $resource_id, $form_name, $ctx );
735 $pair = is_array( $bfb_pair ) ? $bfb_pair : array();
736 $pair = wp_parse_args( $pair, array( 'form' => '', 'content' => '' ) );
737
738 $pair['form'] = wpbc_bf__replace_custom_html_shortcodes( (string) $pair['form'] );
739 $pair['content'] = wpbc_bf__replace_custom_html_shortcodes( (string) $pair['content'] );
740
741 $pair['form'] = wpbc_lang( (string) $pair['form'] );
742 $pair['content'] = wpbc_lang( (string) $pair['content'] );
743
744
745 return $pair;
746 }
747
748 /**
749 * Get arr of all fields names from all booking forms (including custom).
750 *
751 * Load form names through BFB helpers and inspect each stored form pair.
752 *
753 * @return array
754 */
755 function wpbc_get__in_all_forms__field_names_arr() {
756
757 $booking_form_fields_arr = array();
758
759 $ctx = wpbc_get_request_form_context();
760 $ctx['form_status'] = 'published';
761
762 $form_names = array( 'standard' );
763
764 if (
765 class_exists( 'WPBC_FE_Custom_Form_Helper' )
766 && method_exists( 'WPBC_FE_Custom_Form_Helper', 'get_custom_booking_forms_list' )
767 ) {
768 $owner_user_id = 0;
769
770 if ( method_exists( 'WPBC_FE_Custom_Form_Helper', 'wpbc_mu__get_current__owner_user_id' ) ) {
771 $owner_user_id = absint( WPBC_FE_Custom_Form_Helper::wpbc_mu__get_current__owner_user_id() );
772 }
773
774 $ctx['owner_user_id'] = $owner_user_id;
775
776 $forms_list = WPBC_FE_Custom_Form_Helper::get_custom_booking_forms_list(
777 array(
778 'include_standard' => false,
779 'owner_user_id' => $owner_user_id,
780 'statuses' => array( 'published' ),
781 'list_mode' => 'bfb',
782 )
783 );
784
785 if ( is_array( $forms_list ) ) {
786 foreach ( $forms_list as $form_data ) {
787
788 if ( empty( $form_data['name'] ) ) {
789 continue;
790 }
791
792 $form_name = sanitize_text_field( (string) $form_data['name'] );
793
794 if ( ( '' !== $form_name ) && ( 'standard' !== $form_name ) ) {
795 $form_names[] = $form_name;
796 }
797 }
798 }
799 }
800
801 $form_names = array_values( array_unique( $form_names ) );
802
803 foreach ( $form_names as $form_name ) {
804
805 $pair = wpbc_get__booking_form_pair__for_field_names_listing(
806 wpbc_get_default_resource(),
807 $form_name,
808 $ctx
809 );
810
811 $booking_form_fields_arr[] = array(
812 'name' => $form_name,
813 'form' => $pair['form'],
814 'content' => $pair['content'],
815 );
816 }
817
818 // ---------------------------------------------------------------------
819 // Common parser.
820 // ---------------------------------------------------------------------
821 foreach ( $booking_form_fields_arr as $form_key => $booking_form_element ) {
822
823 $booking_form = isset( $booking_form_element['form'] ) ? (string) $booking_form_element['form'] : '';
824
825 $types = 'text[*]?|email[*]?|time[*]?|textarea[*]?|select[*]?|selectbox[*]?|checkbox[*]?|radio|acceptance|captchac|captchar|file[*]?|quiz';
826 $regex = '%\[\s*(' . $types . ')(\s+[a-zA-Z][0-9a-zA-Z:._-]*)([-0-9a-zA-Z:#_/|\s]*)?((?:\s*(?:"[^"]*"|\'[^\']*\'))*)?\s*\]%';
827 $regex2 = '%\[\s*(country[*]?|starttime[*]?|endtime[*]?)(\s*[a-zA-Z]*[0-9a-zA-Z:._-]*)([-0-9a-zA-Z:#_/|\s]*)*((?:\s*(?:"[^"]*"|\'[^\']*\'))*)?\s*\]%';
828
829 $fields_matches = array();
830 $fields_matches2 = array();
831
832 $fields_count = preg_match_all( $regex, $booking_form, $fields_matches );
833 $fields_count2 = preg_match_all( $regex2, $booking_form, $fields_matches2 );
834
835 foreach ( $fields_matches2 as $key => $value ) {
836
837 if ( 2 === (int) $key ) {
838 $value = $fields_matches2[1];
839 }
840
841 if ( ! isset( $fields_matches[ $key ] ) || ! is_array( $fields_matches[ $key ] ) ) {
842 $fields_matches[ $key ] = array();
843 }
844
845 foreach ( $value as $single_value ) {
846 $fields_matches[ $key ][] = $single_value;
847 }
848 }
849
850 $fields_count += $fields_count2;
851
852 $booking_form_fields_arr[ $form_key ]['num'] = $fields_count;
853 $booking_form_fields_arr[ $form_key ]['listing'] = array();
854
855 if ( ! isset( $fields_matches[1] ) ) {
856 $fields_matches[1] = array();
857 }
858 if ( ! isset( $fields_matches[2] ) ) {
859 $fields_matches[2] = array();
860 }
861
862 $fields_matches[1] = array_map( 'trim', $fields_matches[1] );
863 $fields_matches[2] = array_map( 'trim', $fields_matches[2] );
864
865 $booking_form_fields_arr[ $form_key ]['listing']['labels'] = array_map( 'ucfirst', $fields_matches[2] );
866 $booking_form_fields_arr[ $form_key ]['listing']['fields'] = $fields_matches[2];
867
868 foreach ( $fields_matches[1] as $key_fm => $value_fm ) {
869 $fields_matches[1][ $key_fm ] = trim( str_replace( '*', '', $value_fm ) );
870 }
871
872 $booking_form_fields_arr[ $form_key ]['listing']['fields_type'] = $fields_matches[1];
873
874 unset( $booking_form_fields_arr[ $form_key ]['form'] );
875 unset( $booking_form_fields_arr[ $form_key ]['content'] );
876 }
877
878 return $booking_form_fields_arr;
879 }
880
881 /**
882 * Get options for billing field assignment from all available booking forms.
883 *
884 * Important:
885 * - Collect fields from standard, legacy custom, and BFB forms.
886 * - Keep option VALUE as plain field name for backwards compatibility.
887 * - Use the first found label as option title.
888 *
889 * @return array
890 */
891 function wpbc_get__field_options__for_billing_assignment() {
892
893 $field_options = array(
894 '' => __( 'Please select', 'booking' ),
895 );
896
897 $booking_forms = wpbc_get__in_all_forms__field_names_arr();
898
899 if ( empty( $booking_forms ) || ! is_array( $booking_forms ) ) {
900 return $field_options;
901 }
902
903 $unique_fields = array();
904
905 foreach ( $booking_forms as $single_booking_form ) {
906
907 if (
908 empty( $single_booking_form['listing'] )
909 || ! is_array( $single_booking_form['listing'] )
910 || empty( $single_booking_form['listing']['fields'] )
911 || ! is_array( $single_booking_form['listing']['fields'] )
912 ) {
913 continue;
914 }
915
916 $field_labels = array();
917
918 if (
919 isset( $single_booking_form['listing']['labels'] )
920 && is_array( $single_booking_form['listing']['labels'] )
921 ) {
922 $field_labels = $single_booking_form['listing']['labels'];
923 }
924
925 foreach ( $single_booking_form['listing']['fields'] as $field_index => $field_name ) {
926
927 $field_name = trim( (string) $field_name );
928
929 if ( '' === $field_name ) {
930 continue;
931 }
932
933 // Keep first found label/value pair.
934 if ( isset( $unique_fields[ $field_name ] ) ) {
935 continue;
936 }
937
938 $field_label = isset( $field_labels[ $field_index ] ) ? trim( (string) $field_labels[ $field_index ] ) : '';
939
940 if ( '' === $field_label ) {
941 $field_label = $field_name;
942 }
943
944 $unique_fields[ $field_name ] = $field_label;
945 }
946 }
947
948 foreach ( $unique_fields as $field_name => $field_label ) {
949 $field_options[ $field_name ] = $field_label;
950 }
951
952 return $field_options;
953 }
954
955 // -------------------------------------------------------------------------------------------------------------
956
957 /**
958 * Get arr with booking form fields values, after parsing form_data. Avoid to use this function in a future.
959 *
960 * @param $formdata
961 * @param $bktype
962 * @param $booking_form_show
963 * @param $extended_params
964 *
965 * @return array
966 */
967 function wpbc__legacy__get_form_content_arr ( $formdata, $bktype =-1, $booking_form_show ='', $extended_params = array() ) {
968
969 if ( $bktype == -1 ) {
970 $bktype = ( function_exists( 'get__default_type' ) ) ? get__default_type() : 1;
971 }
972
973 if ( $booking_form_show === '' ) {
974
975 $booking_form_show = wpbc_get__booking_form_data_configuration( $bktype, $formdata );
976 }
977
978 $formdata_array = explode('~',$formdata);
979 $formdata_array_count = count($formdata_array);
980 $email_adress='';
981 $name_of_person = '';
982 $coupon_code = '';
983 $secondname_of_person = '';
984 $visitors_count = 1;
985 $select_box_selected_items = array();
986 $check_box_selected_items = array();
987 $all_fields_array = array();
988 $all_fields_array_without_types = array();
989 $checkbox_value=array();
990
991 for ( $i=0 ; $i < $formdata_array_count ; $i++) {
992
993 if ( empty( $formdata_array[$i] ) ) {
994 continue;
995 }
996
997 $elemnts = explode('^',$formdata_array[$i]);
998
999 $type = $elemnts[0];
1000 $element_name = $elemnts[1];
1001 $value = $elemnts[2];
1002
1003 //FixIn: 9.7.4.1 - escape coded html/xss
1004 $value = esc_html( $value );
1005 $value = esc_html( html_entity_decode( $value ) );
1006 $value = nl2br($value); // Add BR instead if /n elements // FixIn: 9.7.4.2.
1007 // Escaping for timeline popovers and for other places
1008 $value = wpbc_string__escape__then_convert__n_amp__html( $value );
1009
1010 $count_pos = strlen( $bktype );
1011
1012 $type_name = $elemnts[1];
1013 $type_name = str_replace('[]','',$type_name);
1014 if ($bktype == substr( $type_name, -1*$count_pos ) ) $type_name = substr( $type_name, 0, -1*$count_pos ); // $type_name = str_replace($bktype,'',$elemnts[1]);
1015
1016 if ( ( ($type_name == 'email') || ($type == 'email') ) && ( empty($email_adress) ) ) $email_adress = $value; // FixIn: 6.0.1.9.
1017 if ( ($type_name == 'coupon') || ($type == 'coupon') ) $coupon_code = $value;
1018 if ( ($type_name == 'name') || ($type == 'name') ) $name_of_person = $value;
1019 if ( ($type_name == 'secondname') || ($type == 'secondname') ) $secondname_of_person = $value;
1020 if ( ($type_name == 'visitors') || ($type == 'visitors') ) $visitors_count = $value;
1021
1022
1023 if ($type == 'checkbox') {
1024 if ($value == 'true') {
1025 $value = strtolower( __( 'yes', 'booking' ) );
1026 }
1027
1028 if ($value == 'false') {
1029 $value = strtolower( __( 'no', 'booking' ) );
1030 }
1031
1032 if ( $value !='' )
1033 if ( ( isset($checkbox_value[ str_replace('[]','',(string) $element_name) ]) ) && ( is_array($checkbox_value[ str_replace('[]','',(string) $element_name) ]) ) ) {
1034 $checkbox_value[ str_replace('[]','',(string) $element_name) ][] = $value;
1035 } else {
1036 $checkbox_value[ str_replace('[]','',(string) $element_name) ] = array($value);
1037 }
1038
1039 $value = '['. $type_name .']'; // FixIn: 6.1.1.14.
1040 }
1041
1042 if ( ( $type == 'select-one') || ( $type == 'selectbox-one') || ( $type == 'select-multiple' ) || ( $type == 'selectbox-multiple' ) || ( $type == 'radio' ) ) { // add all select box selected items to return array
1043 $select_box_selected_items[$type_name] = $value;
1044 }
1045
1046 if ( ($type == 'checkbox') && (isset($checkbox_value)) ) {
1047 if (isset( $checkbox_value[ str_replace('[]','',(string) $element_name) ] )) {
1048 if (is_array( $checkbox_value[ str_replace('[]','',(string) $element_name) ] ))
1049 $current_checkbox_value = implode(', ', $checkbox_value[ str_replace('[]','',(string) $element_name) ] );
1050 else
1051 $current_checkbox_value = $checkbox_value[ str_replace('[]','',(string) $element_name) ] ;
1052 } else {
1053 $current_checkbox_value = '';
1054 }
1055 $all_fields_array[ str_replace('[]','',(string) $element_name) ] = $current_checkbox_value;
1056 $all_fields_array_without_types[ substr( str_replace('[]','',(string) $element_name), 0 , -1*strlen( $bktype ) ) ] = $current_checkbox_value;
1057
1058 $check_box_selected_items[$type_name] = $current_checkbox_value;
1059 } else {
1060
1061 // FixIn: 8.4.2.11.
1062 $all_fields_array_without_types[ substr( str_replace('[]','',(string) $element_name), 0 , -1*strlen( $bktype ) ) ] = $value;
1063 /**
1064 ['_all_'] => $all_fields_array, CONVERT to " AM/PM "
1065 ['_all_fields_'] => $all_fields_array_without_types => in " 24 hour " format - for ability correct calculate Booking > Resources > Advanced cost page.
1066 */
1067 if ( ( $type_name == 'rangetime' ) || ( $type == 'rangetime' ) ) {
1068 $value = wpbc_time_slot_in_format( $value );
1069 }
1070 $all_fields_array[ str_replace('[]','',(string) $element_name) ] = $value;
1071 // FixIn: 8.4.2.11.
1072
1073 }
1074 $is_skip_replace = false; // FixIn: 7.0.1.45.
1075 if ( ( $type == 'radio' ) && empty( $value ) )
1076 $is_skip_replace = true;
1077 if ( ! $is_skip_replace ) {
1078 $booking_form_show = str_replace( '[' . $type_name . ']', $value, $booking_form_show );
1079 }
1080 }
1081
1082 if (! isset($all_fields_array_without_types[ 'booking_resource_id' ])) $all_fields_array_without_types[ 'booking_resource_id' ] = $bktype;
1083 if (! isset($all_fields_array_without_types[ 'resource_id' ])) $all_fields_array_without_types[ 'resource_id' ] = $bktype;
1084 if (! isset($all_fields_array_without_types[ 'type_id' ])) $all_fields_array_without_types[ 'type_id' ] = $bktype;
1085
1086 if (! isset($all_fields_array_without_types[ 'type' ])) $all_fields_array_without_types[ 'type' ] = $bktype;
1087 if (! isset($all_fields_array_without_types[ 'resource' ])) $all_fields_array_without_types[ 'resource' ] = $bktype;
1088
1089 foreach ($extended_params as $key_param=>$value_param) {
1090 if (! isset($all_fields_array_without_types[ $key_param ])) $all_fields_array_without_types[ $key_param ] = $value_param;
1091 }
1092
1093 foreach ( $all_fields_array_without_types as $key_param=>$value_param) { // FixIn: 6.1.1.4.
1094 if ( ( gettype ( $value_param ) != 'array' )
1095 && ( gettype ( $value_param ) != 'object' )
1096 ) {
1097 $booking_form_show = str_replace( '['. $key_param .']', $value_param ,$booking_form_show);
1098
1099 $all_fields_array_without_types[ $key_param ] = str_replace( "&amp;", '&', $value_param ); // FixIn: 7.1.2.12.
1100 }
1101
1102
1103 }
1104 // Remove all shortcodes, which is not replaced early.
1105 $booking_form_show = preg_replace ('/[\s]{0,}\[[a-zA-Z0-9.,-_]{0,}\][\s]{0,}/', '', $booking_form_show); // FixIn: 6.1.1.4.
1106
1107 $booking_form_show = str_replace( "&amp;", '&', $booking_form_show ); // FixIn: 7.1.2.12.
1108
1109 $return_array = array(
1110 'content' => $booking_form_show,
1111 'email' => $email_adress,
1112 'name' => $name_of_person,
1113 'secondname' => $secondname_of_person,
1114 'visitors' => $visitors_count,
1115 'coupon' => $coupon_code,
1116 '_all_' => $all_fields_array,
1117 '_all_fields_' => $all_fields_array_without_types
1118 );
1119
1120 foreach ( $select_box_selected_items as $key => $value ) {
1121 if ( ! isset( $return_array[ $key ] ) ) {
1122 $return_array[ $key ] = $value;
1123 }
1124 }
1125 foreach ( $check_box_selected_items as $key => $value ) {
1126 if ( ! isset( $return_array[ $key ] ) ) {
1127 $return_array[ $key ] = $value;
1128 }
1129 }
1130
1131 return $return_array;
1132 }
1133
1134
1135 /**
1136 * Check whether custom booking forms are enabled for the current user.
1137 *
1138 * This function determines if the current user is allowed to access custom booking forms
1139 * based on plugin version and user permissions. It checks:
1140 * - If the business version of the plugin is active (`wpdev_bk_biz_m` class exists).
1141 * - If the user is a super admin (via `multiuser_is_user_can_be_here` filter).
1142 * - If regular users are allowed to use custom forms (via `booking_is_custom_forms_for_regular_users` option).
1143 *
1144 * @return bool True if custom forms are enabled for the current user; false otherwise.
1145 */
1146 function wpbc_is_custom_forms_enabled() {
1147
1148 if ( ! class_exists( 'wpdev_bk_biz_m' ) ) {
1149 return false;
1150 }
1151
1152 $is_super_admin = apply_bk_filter( 'multiuser_is_user_can_be_here', true, 'only_super_admin' );
1153 $custom_forms_allowed = ( 'On' === get_bk_option( 'booking_is_custom_forms_for_regular_users' ) );
1154
1155 return $is_super_admin || $custom_forms_allowed;
1156 }
1157
1158 // ---------------------------------------------------------------------------------------------------------------------
1159 // == Shortcode Replacers ==
1160 // ---------------------------------------------------------------------------------------------------------------------
1161 /**
1162 * Replace folowing shortcodes in the booking form at Booking > Settings > Fields page:
1163 * [bookingresource show='id'] - to booking resource ID
1164 * [bookingresource show='title'] - to booking resource Title
1165 * [bookingresource show='cost'] - to booking resource Cost
1166 * [bookingresource show='capacity'] - to booking resource Capacity
1167 *
1168 * @param string $return_form
1169 * @param int $resource_id
1170 *
1171 * @return string
1172 */
1173 function wpbc_replace_bookingresource_info_in_form( $return_form, $resource_id ) { // FixIn: 5.4.5.4.
1174
1175 $patterns = array();
1176
1177 $parameters = array( 'id', 'title', 'cost', 'capacity' );
1178 foreach ( $parameters as $parameter ) {
1179 $patterns[] = '/\[bookingresource\s*show=\'' . $parameter . '\'\\s*]/';
1180 }
1181
1182 $replaced_form = $return_form;
1183
1184 $replacements = array( $resource_id );
1185
1186 if ( function_exists( 'get_booking_resource_attr' ) ) {
1187 $booking_resource_attr = get_booking_resource_attr( $resource_id );
1188
1189 if ( ! empty( $booking_resource_attr ) ) {
1190
1191 if ( isset( $booking_resource_attr->title ) ) {
1192 $bk_res_title = wpbc_lang( $booking_resource_attr->title );
1193 $replacements[] = $bk_res_title;
1194 } else {
1195 $replacements[] = '';
1196 }
1197
1198 if ( ( class_exists( 'wpdev_bk_biz_s' ) ) && ( isset ( $booking_resource_attr->cost ) ) ) {
1199
1200 $replacements[] = wpbc_get_cost_with_currency_for_user( $booking_resource_attr->cost, $resource_id );
1201
1202 } else {
1203 $replacements[] = '';
1204 }
1205 }
1206 $replaced_form = preg_replace( $patterns, $replacements, $return_form );
1207 }
1208
1209
1210 return $replaced_form;
1211 }
1212