PluginProbe
Booking Calendar / 10.11.3
Booking Calendar v10.11.3
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 / _functions / booking_data__parse.php

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

760 lines 33.3 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 */
14
15 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
16
17 // =====================================================================================================================
18 // == B o o k i n g F o r m s P a r s i n g ==
19 // =====================================================================================================================
20
21 /**
22 * Parse "text^firstname1^John~..." -> [ 'firstname':[name:"firstname", value:"John" ...] ... ] - Parse (DB) form_data and get fields array values
23 *
24 * @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~...'
25 * @param int $resource_id - ID of booking resource
26 * @param array $params - (optional) default: array() define here what field we need to get array( 'get' => 'value' )
27 *
28 * @return array
29 * [
30 * rangetime = [
31 * type = "selectbox-multiple"
32 * original_name = "rangetime3[]"
33 * name = "rangetime"
34 * value = "12:00 - 14:00"
35 * ]
36 * name = [
37 * type = "text"
38 * original_name = "name3"
39 * name = "name"
40 * value = "test 1"
41 * ]
42 * secondname = [...]
43 * email = [...]
44 * ]
45 *
46 * Example 1:
47 * $structured_booking_data_arr = wpbc_get_parsed_booking_data_arr( $this_booking->form, $resource_id, array( 'get' => 'value' ) );
48 * output: [ "rangetime" : "12:00 - 14:00",
49 * "name": "John" ,
50 * "secondname" : "Smith" , "email" : "test@wpbookingcalendar.com" , "visitors" : "1" ... ]
51 *
52 * Example 2:
53 * $structured_booking_data_arr = wpbc_get_parsed_booking_data_arr( $this_booking->form, $resource_id );
54 * output: [ rangetime = [
55 * type = "selectbox-multiple"
56 * original_name = "rangetime3[]"
57 * name = "rangetime"
58 * value = "12:00 - 14:00"
59 * ]
60 * name = [
61 * type = "text"
62 * original_name = "name3"
63 * name = "name"
64 * value = "test 1"
65 * ]
66 * secondname = [...]
67 * email = [...]
68 * ]
69 */
70 function wpbc_get_parsed_booking_data_arr( $form_data, $resource_id = 1, $params = array( ) ) {
71
72 $booking_data_arr = array();
73
74 if ( ! empty( $form_data ) ) {
75
76 $fields_arr = explode( '~', $form_data );
77
78 foreach ( $fields_arr as $field ) {
79
80 if ( false === strpos( $field, '^' ) ) {
81 break; // FixIn: 9.8.10.2.
82 }
83
84 list( $field_type, $field_original_name, $field_value ) = explode( '^', $field );
85
86 $field_name = $field_original_name;
87
88 // Is this multi select in checkboxes: [checkbox* ConducenteExtra "Si" "No"] => [... 6: "checkbox^ConducenteExtra4[]^Si", 7: "checkbox^ConducenteExtra4[]^" ... ]
89 $is_multi_options = ( '[]' == substr( $field_name, - 2 ) );
90
91 $minus_additional = ( '[]' == substr( $field_name, - 2 ) ) ? 2 : 0;
92 $field_name = ( $minus_additional > 0 ) ? substr( $field_name, 0, - $minus_additional ) : $field_name;
93
94
95 $minus_additional = ( strval( $resource_id ) == substr( $field_name, - 1 * ( strlen( strval( $resource_id ) ) ) ) )
96 ? strlen( strval( $resource_id ) ) : 0;
97 $field_name = ( $minus_additional > 0 ) ? substr( $field_name, 0, - $minus_additional ) : $field_name;
98
99 if ( ( 'checkbox' === $field_type ) && ( 'true' === $field_value ) ) {
100 //$field_value = strtolower( __( 'Yes', 'booking' ) );
101 $field_value = 'true';
102 }
103 if ( ( 'checkbox' === $field_type ) && ( 'false' === $field_value ) ) {
104 //$field_value = strtolower( __( 'No', 'booking' ) );
105 $field_value = 'false';
106 }
107
108 if ( ! isset( $booking_data_arr[ $field_name ] ) ) {
109 $booking_data_arr[ $field_name ] = array(
110 'type' => $field_type,
111 'original_name' => $field_original_name,
112 'name' => $field_name,
113 'value' => array( $field_value )
114 );
115 } else {
116 // All values we save as array values, for situations of MULTI options:
117 // [checkbox* ConducenteExtra "Si" "No"] => [... 6: "checkbox^ConducenteExtra4[]^Si", 7: "checkbox^ConducenteExtra4[]^" ... ]
118 $booking_data_arr[ $field_name ]['value'][] = $field_value;
119 }
120 }
121
122 // Convert arrays to string
123 foreach ( $booking_data_arr as $field_name => $field_structure_arr ) { // FixIn: 9.8.9.1.
124 $field_structure_arr['value'] = array_filter( $field_structure_arr['value'], function ( $v ) {
125 return ( $v !== '' ); // Remove All '' entries
126 } );
127 $booking_data_arr[ $field_name ]['value'] = implode( ', ', $field_structure_arr['value'] );
128 }
129
130
131 if ( isset( $params['get'] ) ) {
132 /**
133 * Now get only values or other fields: [
134 * "rangetime" : "12:00 - 14:00",
135 * "name":"test 1" ,
136 * "secondname" : "test 1" ,
137 * "email" : "test@wpbookingcalendar.com" ,
138 * "visitors" : "1"
139 * ...
140 * ]
141 */
142
143 foreach ( $booking_data_arr as $field_name => $field_structure_arr ) {
144
145 if ( isset( $field_structure_arr[ $params['get'] ] ) ) {
146 $booking_data_arr[ $field_name ] = $field_structure_arr[ $params['get'] ];
147 } else {
148 $booking_data_arr[ $field_name ] = '-';
149 }
150 }
151 }
152 }
153
154 return $booking_data_arr;
155 }
156
157 /**
158 * Convert [ ... ] -> "text^firstname1^John~..." - encoded booking data string (Usually for inserting into DB), from parsed booking data array
159 *
160 * @param array $booking_data_arr - parsed booking data.
161 * @param int $resource_id - ID of booking resource - In case, if we need to RE-UPDATE booking resource, Otherwise skip it
162 *
163 * @return string
164 */
165 function wpbc_encode_booking_data_to_string( $booking_data_arr, $resource_id = 0 ) {
166
167 $fields_arr = array();
168
169 foreach ( $booking_data_arr as $fields ) {
170
171 if ( ! empty( $resource_id ) ) {
172 $fields_arr[] = $fields['type']
173 . '^' . $fields['name'] . $resource_id . ( ( '[]' == substr( $fields['original_name'], - 2 ) ) ? '[]' : '' )
174 . '^' . $fields['value'];
175 } else {
176 $fields_arr[] = $fields['type'] . '^' . $fields['original_name'] . '^' . $fields['value'];
177 }
178
179 }
180
181 $form_data = implode( '~', $fields_arr );
182
183 return $form_data;
184 }
185
186 // -------------------------------------------------------------------------------------------------------------
187
188 /**
189 * Get Time fields in booking form_data
190 *
191 * @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~...'
192 * @param int $resource_id - ID of booking resource
193 * @param array $params - (optional) default: array() define here what field we need to get array( 'get' => 'value' )
194 *
195 * @return array [ "18:00:00", "20:00:00" ] <- default
196 *
197 * Example #1: $times_his_arr = wpbc_get_times_his_arr__in_form_data( $form_data, $resource_id); --> [ "18:00:01", "20:00:02" ]
198 * 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" ]
199 * 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 ]
200 * 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",... ]
201 *
202 * Example #5: $booking_data_arr = wpbc_get_times_his_arr__in_form_data( $form_data, $resource_id, array( 'get' => 'all' ) );
203 * --> [
204 * 'structured_booking_data_arr' => [ name = "John", secondname = "Smith", email = "john.smith@server.com", visitors = "2",... ]
205 * 'time_as_seconds_arr' => [ 64800, 72000 ]
206 * 'time_as_his_arr' => [ "18:00:01", "20:00:02" ]
207 * ]
208 */
209 function wpbc_get_times_his_arr__in_form_data( $form_data, $resource_id = 1, $params = array() ) {
210
211 $defaults = array(
212 'get' => 'times_his_arr'
213 );
214 $params = wp_parse_args( $params, $defaults );
215
216
217 // Get Time from booking form
218 $local_params = array();
219 /**
220 * Get parsed booking form: = [ name = "John", secondname = "Smith", email = "john.smith@server.com", visitors = "2",... ]
221 */
222 $local_params['structured_booking_data_arr'] = wpbc_get_parsed_booking_data_arr( $form_data, $resource_id, array( 'get' => 'value' ) );
223 // $local_params['all_booking_data_arr'] = wpbc_get_parsed_booking_data_arr( $form_data, $resource_id );
224
225 // Important! : [ 64800, 72000 ]
226 $local_params['time_as_seconds_arr'] = wpbc_get_in_booking_form__time_to_book_as_seconds_arr( $local_params['structured_booking_data_arr'] );
227
228 // [ "18:00:00", "20:00:00" ]
229 $time_as_seconds_arr = $local_params['time_as_seconds_arr'];
230 $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
231 $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
232 if ( ( 0 != $time_as_seconds_arr[0] ) && ( ( 24 * 60 * 60 ) == $time_as_seconds_arr[1] ) ) {
233 //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
234 $time_as_seconds_arr[1] += - 8;
235 }
236 // [ '16:00:01', '18:00:02' ]
237 $local_params['times_his_arr'] = array(
238 wpbc_transform__seconds__in__24_hours_his( $time_as_seconds_arr[0] ),
239 wpbc_transform__seconds__in__24_hours_his( $time_as_seconds_arr[1] )
240 );
241 if (
242 ( isset( $params['get'] ) )
243 && ( isset( $local_params[ $params['get'] ] ) )
244 ) {
245 return $local_params[ $params['get'] ];
246 }
247
248 return $local_params;
249 }
250
251 // -------------------------------------------------------------------------------------------------------------
252
253 /**
254 * Get readable booking form data. Escape values here, as well!
255 *
256 * - 1. <= BS : 'Booking form show' configuration from standard form in versions up to Business Small version ,
257 * - 2 >= BM : If form data has field of custom form, then from custom form configuration,
258 * - 3 >= BM : Otherwise if resource has default custom booking form, then from this default custom booking form
259 * - 4 = MU : specific form of specific WP User
260 * - 5 finally : simple standard form
261 *
262 * @param string $form_data
263 * @param int $resource_id
264 *
265 * @return string
266 */
267 function wpbc_get__booking_form_data__show( $form_data, $resource_id = 1 , $params = array() ) {
268
269 $defaults = array(
270 'is_replace_unknown_shortcodes' => true,
271 'unknown_shortcodes_replace_by' => ''
272 );
273 $params = wp_parse_args( $params, $defaults );
274
275 $booking_form_show = wpbc_get__booking_form_data_configuration( $resource_id, $form_data );
276
277 $booking_data_arr = wpbc_get_parsed_booking_data_arr( $form_data, $resource_id, array( 'get' => 'value' ) );
278
279 foreach ( $booking_data_arr as $key_param => $value_param ) { // FixIn: 6.1.1.4.
280
281 $value_param = esc_html( $value_param ); //FixIn: 9.7.4.1 - escape coded html/xss
282 $value_param = esc_html( html_entity_decode( $value_param ) );
283 $value_param = nl2br($value_param); // Add BR instead if /n elements // FixIn: 9.7.4.2.
284 $value_param = wpbc_string__escape__then_convert__n_amp__html( $value_param );
285
286 $value_param = wpbc_replace__true_false__to__yes_no( $value_param ); // FixIn: 9.8.9.1.
287
288 if (
289 ( gettype( $value_param ) != 'array' )
290 && ( gettype( $value_param ) != 'object' )
291 ) {
292 $booking_form_show = str_replace( '[' . $key_param . ']', $value_param, $booking_form_show );
293 }
294 }
295
296 if ($params['is_replace_unknown_shortcodes']) {
297 // Remove all shortcodes, which is not replaced early.
298 $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.
299 }
300
301 $booking_form_show = str_replace( "&amp;", '&', $booking_form_show ); // FixIn: 7.1.2.12.
302
303
304
305 return $booking_form_show;
306 }
307
308 /**
309 * Get name of custom booking form, if it was used in form data OR booking resource use this default custom form
310 *
311 * @param int $resource_id
312 * @param string $form_data Form data here, required in >= BM, because such form_data can contain fields about used custom booking form
313 *
314 * @return string
315 */
316 function wpbc_get__custom_booking_form_name( $resource_id = 1, $form_data = '' ) {
317
318 $my_booking_form_name = '';
319
320 if ( class_exists( 'wpdev_bk_biz_m' ) ) {
321
322 if ( false !== strpos( $form_data, 'wpbc_custom_booking_form' . $resource_id . '^' ) ) { // FixIn: 9.4.3.12.
323
324 $custom_booking_form_name = substr( $form_data, strpos( $form_data, 'wpbc_custom_booking_form' . $resource_id . '^' ) + strlen( 'wpbc_custom_booking_form' . $resource_id . '^' ) );
325
326 if ( false !== strpos( $custom_booking_form_name, '~' ) ) {
327 $custom_booking_form_name = substr( $custom_booking_form_name, 0, strpos( $custom_booking_form_name, '~' ) );
328 $my_booking_form_name = $custom_booking_form_name;
329 }
330
331 } else {
332
333 // BM :: Get default Custom Form of Resource
334 $my_booking_form_name = apply_bk_filter( 'wpbc_get_default_custom_form', 'standard', $resource_id );
335 }
336
337 if ( 'standard' == $my_booking_form_name ) {
338 $my_booking_form_name = '';
339 }
340 }
341
342 return $my_booking_form_name;
343 }
344
345 /**
346 * Get configuration of 'BOOKING FORM F I E L D S SHORTCODES' from - Booking > Settings > Form page
347 *
348 * - 1. <= BS : 'Booking form show' configuration from standard form in versions up to Business Small version ,
349 * - 2 >= BM : If form data has field of custom form, then from custom form configuration,
350 * - 3 >= BM : Otherwise if resource has default custom booking form, then from this default custom booking form
351 * - 4 = MU : specific form of specific WP User
352 * - 5 finally : simple standard form
353 *
354 * @param int $resource_id
355 * @param string $form_name Name of custom booking form, required in >= BM
356 *
357 * @return string
358 *
359 * Example 1: $booking_form = wpbc_get__booking_form_fields__configuration( 1 ); <- Load STANDARD booking form
360 * Example 2: $booking_form = wpbc_get__booking_form_fields__configuration( 1 , 'standard' ); <- Load STANDARD booking form
361 * Example 3: $booking_form = wpbc_get__booking_form_fields__configuration( 1 , 'my_custom_form' ); <- Load CUSTOM booking form with name 'my_custom_form'
362 * Example 4: $booking_form = wpbc_get__booking_form_fields__configuration( 1 , '' ); <- Load CUSTOM booking form, which is DEFAULT for RESOURCE
363 * 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
364 *
365 */
366 function wpbc_get__booking_form_fields__configuration( $resource_id = 1, $form_name = 'standard' ) {
367
368 if ( ! class_exists( 'wpdev_bk_personal' ) ) {
369 $booking_form_configuration = wpbc_simple_form__get_booking_form__as_shortcodes();
370 } else {
371 $booking_form_configuration = get_bk_option( 'booking_form' );
372
373 if ( class_exists( 'wpdev_bk_biz_m' ) ) {
374
375 if ( $form_name != 'standard' ) {
376
377 $booking_form_configuration = apply_bk_filter( 'wpdev_get_booking_form', $booking_form_configuration, $form_name );
378 }
379
380 // Get default Custom Form for resource, if $form_name == '' wpbc_get__booking_form_fields__configuration(1,'')
381 if ( empty( $form_name ) ) {
382
383 $resource_default_custom_form_name = apply_bk_filter( 'wpbc_get_default_custom_form', 'standard', $resource_id );
384
385 $booking_form_configuration = apply_bk_filter( 'wpdev_get_booking_form', $booking_form_configuration, $resource_default_custom_form_name );
386 }
387
388 //MU :: if resource of "Regular User" - then GET STANDARD user form ( if ( get_bk_option( 'booking_is_custom_forms_for_regular_users' ) !== 'On' ) )
389 $booking_form_configuration = apply_bk_filter( 'wpbc_multiuser_get_booking_form_fields_configuration_of_regular_user', $booking_form_configuration, $resource_id, $form_name ); // FixIn: 8.1.3.19.
390 }
391 }
392
393 // Language
394 $booking_form_configuration = wpbc_lang( $booking_form_configuration );
395
396 return $booking_form_configuration;
397 }
398
399 /**
400 * Get configuration of 'BOOKING FORM DATA' from - Booking > Settings > Form page
401 *
402 * - 1. <= BS : 'Booking form show' configuration from standard form in versions up to Business Small version ,
403 * - 2 >= BM : If form data has field of custom form, then from custom form configuration,
404 * - 3 >= BM : Otherwise if resource has default custom booking form, then from this default custom booking form
405 * - 4 = MU : specific form of specific WP User
406 * - 5 finally : simple standard form
407 *
408 * @param int $resource_id
409 * @param string $form_data Form data here, required in >= BM, because such form_data can contain fields about used custom booking form
410 *
411 * @return string
412 */
413 function wpbc_get__booking_form_data_configuration( $resource_id = 1, $form_data = '' ) {
414
415 if ( ! class_exists( 'wpdev_bk_personal' ) ) {
416
417 $booking_form_show = wpbc_simple_form__get_form_show__as_shortcodes();
418 $booking_form_show = wpbc_bf__replace_custom_html_shortcodes( $booking_form_show );
419
420 } else {
421
422 $booking_form_show = get_bk_option( 'booking_form_show' );
423 $booking_form_show = wpbc_bf__replace_custom_html_shortcodes( $booking_form_show );
424
425 if ( class_exists( 'wpdev_bk_biz_m' ) ) {
426
427 if ( false !== strpos( $form_data, 'wpbc_custom_booking_form' . $resource_id . '^' ) ) { // FixIn: 9.4.3.12.
428
429 $custom_booking_form_name = substr( $form_data, strpos( $form_data, 'wpbc_custom_booking_form' . $resource_id . '^' ) + strlen( 'wpbc_custom_booking_form' . $resource_id . '^' ) );
430 if ( false !== strpos( $custom_booking_form_name, '~' ) ) {
431 $custom_booking_form_name = substr( $custom_booking_form_name, 0, strpos( $custom_booking_form_name, '~' ) );
432 }
433 $booking_form_show = apply_bk_filter( 'wpdev_get_booking_form_content', $booking_form_show, $custom_booking_form_name );
434 $my_booking_form_name = $custom_booking_form_name;
435 } else {
436
437 // BM :: Get default Custom Form of Resource
438 $my_booking_form_name = apply_bk_filter( 'wpbc_get_default_custom_form', 'standard', $resource_id );
439 if ( ( $my_booking_form_name != 'standard' ) && ( ! empty( $my_booking_form_name ) ) ) {
440 $booking_form_show = apply_bk_filter( 'wpdev_get_booking_form_content', $booking_form_show, $my_booking_form_name );
441 }
442 }
443
444 //MU :: if resource of "Regular User" - then GET STANDARD user form ( if ( get_bk_option( 'booking_is_custom_forms_for_regular_users' ) !== 'On' ) )
445 $booking_form_show = apply_bk_filter( 'wpbc_multiuser_get_booking_form_show_of_regular_user', $booking_form_show, $resource_id, $my_booking_form_name ); // FixIn: 8.1.3.19.
446 }
447 }
448
449 // Language
450 $booking_form_show = wpbc_lang( $booking_form_show );
451
452 return $booking_form_show;
453 }
454
455 // -------------------------------------------------------------------------------------------------------------
456
457 /**
458 * Replace resource_ID of booking in 'form_data'
459 * Useful, when we need to save booking from one resource into another.
460 *
461 * @param $booking__form_data__str 'selectbox-multiple^rangetime2[]^18:00 - 20:00~checkbox^fee2[]^true~text^name2^John~text^secondname2^Smith...'
462 * @param $new_resource_id 10
463 * @param $old_resource_id 2
464 *
465 * @return string 'selectbox-multiple^rangetime10[]^18:00 - 20:00~checkbox^fee10[]^true~text^name10^John~text^secondname10^Smith...'
466 */
467 function wpbc_get__form_data__with_replaced_id( $booking__form_data__str, $new_resource_id, $old_resource_id ) {
468
469 $all_booking_data_arr = wpbc_get_parsed_booking_data_arr( $booking__form_data__str, $old_resource_id );
470
471 $new__form_data__str = wpbc_encode_booking_data_to_string( $all_booking_data_arr, $new_resource_id );
472
473 return $new__form_data__str;
474 }
475
476
477 /**
478 * Get arr of all Fields Names from all booking forms (including custom)
479 *
480 * @return array = [
481 0: [ name = "standard", num = 8, listing = [ ... ] ],
482 1: [
483 name = "minimal"
484 num = 7
485 listing = [
486 labels = [
487 0 = " adults"
488 1 = " children"
489 2 = " infants"
490 3 = " gender"
491 4 = " full_name"
492 5 = " email"
493 6 = " phone"
494 fields = {array[7]}
495 0 = " adults"
496 1 = " children"
497 2 = " infants"
498 3 = " gender"
499 4 = " full_name"
500 5 = " email"
501 6 = " phone"
502 fields_type = {array[7]}
503 0 = "select"
504 1 = "select"
505 2 = "select"
506 3 = "radio"
507 4 = "text"
508 5 = "email"
509 6 = "text"
510 ]
511 ]
512 2: [], ...
513 * ]
514 */
515 function wpbc_get__in_all_forms__field_names_arr() {
516
517 $booking_form_fields_arr = array();
518 $booking_form_fields_arr[] = array( 'name' => 'standard', 'form' => wpbc_bf__replace_custom_html_shortcodes( get_bk_option( 'booking_form' ) ), 'content' => wpbc_bf__replace_custom_html_shortcodes( get_bk_option( 'booking_form_show' ) ) );
519
520 /**
521 * Get custom booking form configurations: [
522 * [ name = "minimal",
523 * form = "[calendar]...",
524 * content = "<div class="payment-content-form"> [name] ..."
525 * ],
526 * ...
527 * ]
528 */
529 $is_can = apply_bk_filter( 'multiuser_is_user_can_be_here', true, 'only_super_admin' );
530 if ( ( $is_can ) || ( get_bk_option( 'booking_is_custom_forms_for_regular_users' ) === 'On' ) ) {
531 $booking_forms_extended = get_bk_option( 'booking_forms_extended' );
532 $booking_forms_extended = maybe_unserialize( $booking_forms_extended );
533 if ( false !== $booking_forms_extended ) {
534 foreach ( $booking_forms_extended as $form_extended ) {
535 $booking_form_fields_arr[] = $form_extended;
536 }
537 }
538 }
539
540 foreach ( $booking_form_fields_arr as $form_key => $booking_form_element ) {
541
542 $booking_form = $booking_form_element['form'];
543
544 $types = 'text[*]?|email[*]?|time[*]?|textarea[*]?|select[*]?|selectbox[*]?|checkbox[*]?|radio|acceptance|captchac|captchar|file[*]?|quiz';
545 $regex = '%\[\s*(' . $types . ')(\s+[a-zA-Z][0-9a-zA-Z:._-]*)([-0-9a-zA-Z:#_/|\s]*)?((?:\s*(?:"[^"]*"|\'[^\']*\'))*)?\s*\]%';
546 $regex2 = '%\[\s*(country[*]?|starttime[*]?|endtime[*]?)(\s*[a-zA-Z]*[0-9a-zA-Z:._-]*)([-0-9a-zA-Z:#_/|\s]*)*((?:\s*(?:"[^"]*"|\'[^\']*\'))*)?\s*\]%';
547 $fields_count = preg_match_all($regex, $booking_form, $fields_matches) ;
548 $fields_count2 = preg_match_all($regex2, $booking_form, $fields_matches2) ;
549
550 //Gathering Together 2 arrays $fields_matches and $fields_matches2
551 foreach ($fields_matches2 as $key => $value) {
552 if ($key == 2) $value = $fields_matches2[1];
553 foreach ($value as $v) {
554 $fields_matches[$key][count($fields_matches[$key])] = $v;
555 }
556 }
557 $fields_count += $fields_count2;
558
559 $booking_form_fields_arr[ $form_key ]['num'] = $fields_count;
560 $booking_form_fields_arr[ $form_key ]['listing'] = array(); //$fields_matches;
561
562 $fields_matches[1] = array_map( 'trim', $fields_matches[1] );
563 $fields_matches[2] = array_map( 'trim', $fields_matches[2] );
564
565 $booking_form_fields_arr[ $form_key ]['listing']['labels'] = array_map( 'ucfirst', $fields_matches[2] );
566 $booking_form_fields_arr[ $form_key ]['listing']['fields'] = $fields_matches[2] ;
567
568 foreach ( $fields_matches[1] as $key_fm => $value_fm ) {
569 $fields_matches[1][ $key_fm ] = trim( str_replace( '*', '', $value_fm ) );
570 }
571
572 $booking_form_fields_arr[ $form_key ]['listing']['fields_type'] = $fields_matches[1];
573
574 // Reset
575 unset( $booking_form_fields_arr[ $form_key ]['form'] );
576 unset( $booking_form_fields_arr[ $form_key ]['content'] );
577 }
578
579 return $booking_form_fields_arr;
580 }
581
582 // -------------------------------------------------------------------------------------------------------------
583
584 /**
585 * Get arr with booking form fields values, after parsing form_data. Avoid to use this function in a future.
586 *
587 * @param $formdata
588 * @param $bktype
589 * @param $booking_form_show
590 * @param $extended_params
591 *
592 * @return array
593 */
594 function wpbc__legacy__get_form_content_arr ( $formdata, $bktype =-1, $booking_form_show ='', $extended_params = array() ) {
595
596 if ( $bktype == -1 ) {
597 $bktype = ( function_exists( 'get__default_type' ) ) ? get__default_type() : 1;
598 }
599
600 if ( $booking_form_show === '' ) {
601
602 $booking_form_show = wpbc_get__booking_form_data_configuration( $bktype, $formdata );
603 }
604
605 $formdata_array = explode('~',$formdata);
606 $formdata_array_count = count($formdata_array);
607 $email_adress='';
608 $name_of_person = '';
609 $coupon_code = '';
610 $secondname_of_person = '';
611 $visitors_count = 1;
612 $select_box_selected_items = array();
613 $check_box_selected_items = array();
614 $all_fields_array = array();
615 $all_fields_array_without_types = array();
616 $checkbox_value=array();
617
618 for ( $i=0 ; $i < $formdata_array_count ; $i++) {
619
620 if ( empty( $formdata_array[$i] ) ) {
621 continue;
622 }
623
624 $elemnts = explode('^',$formdata_array[$i]);
625
626 $type = $elemnts[0];
627 $element_name = $elemnts[1];
628 $value = $elemnts[2];
629
630 //FixIn: 9.7.4.1 - escape coded html/xss
631 $value = esc_html( $value );
632 $value = esc_html( html_entity_decode( $value ) );
633 $value = nl2br($value); // Add BR instead if /n elements // FixIn: 9.7.4.2.
634 // Escaping for timeline popovers and for other places
635 $value = wpbc_string__escape__then_convert__n_amp__html( $value );
636
637 $count_pos = strlen( $bktype );
638
639 $type_name = $elemnts[1];
640 $type_name = str_replace('[]','',$type_name);
641 if ($bktype == substr( $type_name, -1*$count_pos ) ) $type_name = substr( $type_name, 0, -1*$count_pos ); // $type_name = str_replace($bktype,'',$elemnts[1]);
642
643 if ( ( ($type_name == 'email') || ($type == 'email') ) && ( empty($email_adress) ) ) $email_adress = $value; // FixIn: 6.0.1.9.
644 if ( ($type_name == 'coupon') || ($type == 'coupon') ) $coupon_code = $value;
645 if ( ($type_name == 'name') || ($type == 'name') ) $name_of_person = $value;
646 if ( ($type_name == 'secondname') || ($type == 'secondname') ) $secondname_of_person = $value;
647 if ( ($type_name == 'visitors') || ($type == 'visitors') ) $visitors_count = $value;
648
649
650 if ($type == 'checkbox') {
651 if ($value == 'true') {
652 $value = strtolower( __( 'yes', 'booking' ) );
653 }
654
655 if ($value == 'false') {
656 $value = strtolower( __( 'no', 'booking' ) );
657 }
658
659 if ( $value !='' )
660 if ( ( isset($checkbox_value[ str_replace('[]','',(string) $element_name) ]) ) && ( is_array($checkbox_value[ str_replace('[]','',(string) $element_name) ]) ) ) {
661 $checkbox_value[ str_replace('[]','',(string) $element_name) ][] = $value;
662 } else {
663 $checkbox_value[ str_replace('[]','',(string) $element_name) ] = array($value);
664 }
665
666 $value = '['. $type_name .']'; // FixIn: 6.1.1.14.
667 }
668
669 if ( ( $type == 'select-one') || ( $type == 'selectbox-one') || ( $type == 'select-multiple' ) || ( $type == 'selectbox-multiple' ) || ( $type == 'radio' ) ) { // add all select box selected items to return array
670 $select_box_selected_items[$type_name] = $value;
671 }
672
673 if ( ($type == 'checkbox') && (isset($checkbox_value)) ) {
674 if (isset( $checkbox_value[ str_replace('[]','',(string) $element_name) ] )) {
675 if (is_array( $checkbox_value[ str_replace('[]','',(string) $element_name) ] ))
676 $current_checkbox_value = implode(', ', $checkbox_value[ str_replace('[]','',(string) $element_name) ] );
677 else
678 $current_checkbox_value = $checkbox_value[ str_replace('[]','',(string) $element_name) ] ;
679 } else {
680 $current_checkbox_value = '';
681 }
682 $all_fields_array[ str_replace('[]','',(string) $element_name) ] = $current_checkbox_value;
683 $all_fields_array_without_types[ substr( str_replace('[]','',(string) $element_name), 0 , -1*strlen( $bktype ) ) ] = $current_checkbox_value;
684
685 $check_box_selected_items[$type_name] = $current_checkbox_value;
686 } else {
687
688 // FixIn: 8.4.2.11.
689 $all_fields_array_without_types[ substr( str_replace('[]','',(string) $element_name), 0 , -1*strlen( $bktype ) ) ] = $value;
690 /**
691 ['_all_'] => $all_fields_array, CONVERT to " AM/PM "
692 ['_all_fields_'] => $all_fields_array_without_types => in " 24 hour " format - for ability correct calculate Booking > Resources > Advanced cost page.
693 */
694 if ( ( $type_name == 'rangetime' ) || ( $type == 'rangetime' ) ) {
695 $value = wpbc_time_slot_in_format( $value );
696 }
697 $all_fields_array[ str_replace('[]','',(string) $element_name) ] = $value;
698 // FixIn: 8.4.2.11.
699
700 }
701 $is_skip_replace = false; // FixIn: 7.0.1.45.
702 if ( ( $type == 'radio' ) && empty( $value ) )
703 $is_skip_replace = true;
704 if ( ! $is_skip_replace ) {
705 $booking_form_show = str_replace( '[' . $type_name . ']', $value, $booking_form_show );
706 }
707 }
708
709 if (! isset($all_fields_array_without_types[ 'booking_resource_id' ])) $all_fields_array_without_types[ 'booking_resource_id' ] = $bktype;
710 if (! isset($all_fields_array_without_types[ 'resource_id' ])) $all_fields_array_without_types[ 'resource_id' ] = $bktype;
711 if (! isset($all_fields_array_without_types[ 'type_id' ])) $all_fields_array_without_types[ 'type_id' ] = $bktype;
712
713 if (! isset($all_fields_array_without_types[ 'type' ])) $all_fields_array_without_types[ 'type' ] = $bktype;
714 if (! isset($all_fields_array_without_types[ 'resource' ])) $all_fields_array_without_types[ 'resource' ] = $bktype;
715
716 foreach ($extended_params as $key_param=>$value_param) {
717 if (! isset($all_fields_array_without_types[ $key_param ])) $all_fields_array_without_types[ $key_param ] = $value_param;
718 }
719
720 foreach ( $all_fields_array_without_types as $key_param=>$value_param) { // FixIn: 6.1.1.4.
721 if ( ( gettype ( $value_param ) != 'array' )
722 && ( gettype ( $value_param ) != 'object' )
723 ) {
724 $booking_form_show = str_replace( '['. $key_param .']', $value_param ,$booking_form_show);
725
726 $all_fields_array_without_types[ $key_param ] = str_replace( "&amp;", '&', $value_param ); // FixIn: 7.1.2.12.
727 }
728
729
730 }
731 // Remove all shortcodes, which is not replaced early.
732 $booking_form_show = preg_replace ('/[\s]{0,}\[[a-zA-Z0-9.,-_]{0,}\][\s]{0,}/', '', $booking_form_show); // FixIn: 6.1.1.4.
733
734 $booking_form_show = str_replace( "&amp;", '&', $booking_form_show ); // FixIn: 7.1.2.12.
735
736 $return_array = array(
737 'content' => $booking_form_show,
738 'email' => $email_adress,
739 'name' => $name_of_person,
740 'secondname' => $secondname_of_person,
741 'visitors' => $visitors_count,
742 'coupon' => $coupon_code,
743 '_all_' => $all_fields_array,
744 '_all_fields_' => $all_fields_array_without_types
745 );
746
747 foreach ( $select_box_selected_items as $key => $value ) {
748 if ( ! isset( $return_array[ $key ] ) ) {
749 $return_array[ $key ] = $value;
750 }
751 }
752 foreach ( $check_box_selected_items as $key => $value ) {
753 if ( ! isset( $return_array[ $key ] ) ) {
754 $return_array[ $key ] = $value;
755 }
756 }
757
758 return $return_array;
759 }
760