PluginProbe
Booking Calendar / 11.8.4
Booking Calendar v11.8.4
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
← All changes | includes/_capacity/get_times_fields.php +123 -9 10.1.311.8.4 View file →
@@ -1,7 +1,7 @@
1 1 <?php
2 2
3 -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly //FixIn: 9.8.0.4
3 +if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly // FixIn: 9.8.0.4.
4 4
5 5
6 6 /**
7 7 * Get Time Slots from booking form for Each date: [ '2023-10-25' => [ '12:20 - 12:55', '13:00 - 14:00' ], '2023-10-26' => [ ... ], ... ]
@@ -16,17 +16,31 @@
16 16 * Example:
17 17 * $timeslots_arr = wpbc_get_times_fields_configuration(
18 18 * 1,
19 19 * 'my_custom_form_name',
20 - * strtotime( date( 'Y-m-d 00:00:00', strtotime( 'now' ) ) ),
20 + * strtotime( gmdate( 'Y-m-d 00:00:00', strtotime( 'now' ) ) ),
21 21 * 365
22 22 * );
23 23 */
24 24 function wpbc_get_times_fields_configuration__by_dates( $resource_id, $custom_form_name, $start_date_unix_timestamp, $days_count ){
25 25
26 - // Get booking form configuration CONTENT
26 + // Get booking form configuration CONTENT.
27 27 $booking_form_fields = wpbc_get__booking_form_fields__configuration( $resource_id, $custom_form_name );
28 + // FixIn: 10.15.8.2.
29 + // In BFB mode use the same resolved form source as the front-end renderer. The legacy loader above stays as a fallback.
30 + if ( function_exists( 'wpbc_get__booking_form_pair__for_field_names_listing' ) ) {
28 31
32 + $booking_form_pair = wpbc_get__booking_form_pair__for_field_names_listing( $resource_id, $custom_form_name );
33 +
34 + if (
35 + is_array( $booking_form_pair )
36 + && isset( $booking_form_pair['form'] )
37 + && ( '' !== trim( (string) $booking_form_pair['form'] ) )
38 + ) {
39 + $booking_form_fields = (string) $booking_form_pair['form'];
40 + }
41 + }
42 +
29 43 // -----------------------------------------------------------------------------------------------------------------
30 44 // Get conditional sections, if exist
31 45 // -----------------------------------------------------------------------------------------------------------------
32 46 /**
@@ -80,9 +94,9 @@
80 94 // -----------------------------------------------------------------------------------------------------------------
81 95 $dates_times_fields_arr = array();
82 96 for ( $day_num = 0; $day_num <= $days_count; $day_num ++ ) {
83 97
84 - $my_day_tag = date( 'Y-m-d', $start_date_unix_timestamp ); // '2023-07-19'
98 + $my_day_tag = gmdate( 'Y-m-d', $start_date_unix_timestamp ); // '2023-07-19'
85 99
86 100 if ( ( ! empty( $conditions ) ) && ( function_exists( 'wpbc_conditions_form__get_section__depend_from_date' ) ) ){
87 101
88 102 // Get booking form conditional section depends on DATE
@@ -219,8 +233,108 @@
219 233 }
220 234
221 235
222 236 /**
237 + * Get values for the first shortcode with this name.
238 + *
239 + * The legacy parser is intentionally kept as the first path. The fallback handles Booking Form Builder exports
240 + * that can include named attributes before option tokens, e.g.:
241 + * [selectbox* starttime default="08:00" "08:00" "09:00"].
242 + *
243 + * @param string $shortcode_name
244 + * @param string $bookingform_configuration_content
245 + *
246 + * @return false|array
247 + */
248 + function wpbc_get_times_fields__get_first_shortcode_values( $shortcode_name, $bookingform_configuration_content ) {
249 +
250 + $shortcode_values = wpbc_parse_form__get_first_shortcode_values( $shortcode_name, $bookingform_configuration_content );
251 +
252 + if ( ! empty( $shortcode_values ) ) {
253 + return $shortcode_values;
254 + }
255 +
256 + $shortcode_values = wpbc_get_times_fields__parse_first_shortcode_values__fallback( $shortcode_name, $bookingform_configuration_content );
257 +
258 + return empty( $shortcode_values ) ? false : $shortcode_values;
259 + }
260 +
261 +
262 + /**
263 + * Fallback parser for time select shortcodes with named attributes.
264 + *
265 + * @param string $shortcode_name
266 + * @param string $bookingform_configuration_content
267 + *
268 + * @return array
269 + */
270 + function wpbc_get_times_fields__parse_first_shortcode_values__fallback( $shortcode_name, $bookingform_configuration_content ) {
271 +
272 + $shortcode_name = trim( (string) $shortcode_name );
273 +
274 + if ( '' === $shortcode_name ) {
275 + return array();
276 + }
277 +
278 + $regex = "%\\[\\s*([a-zA-Z][0-9a-zA-Z_-]*\\*?)\\s+" . preg_quote( $shortcode_name, '%' ) . "(?=\\s|\\])((?:[^\\]\"']+|\"[^\"]*\"|'[^']*')*)\\]%u";
279 +
280 + if ( ! preg_match( $regex, (string) $bookingform_configuration_content, $shortcode_match ) ) {
281 + return array();
282 + }
283 +
284 + $shortcode_text = $shortcode_match[0];
285 + $consumed_attr_value_offsets = array();
286 +
287 + if ( preg_match_all( '/\b[a-zA-Z][\w:-]*\s*[:=]\s*(?:"([^"]*)"|\'([^\']*)\'|([^\s\]"]+))/u', $shortcode_text, $attr_matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE ) ) {
288 + foreach ( $attr_matches as $attr_match ) {
289 + if ( isset( $attr_match[1][1] ) && ( $attr_match[1][1] >= 0 ) ) {
290 + $consumed_attr_value_offsets[ $attr_match[1][1] ] = true;
291 + }
292 + if ( isset( $attr_match[2][1] ) && ( $attr_match[2][1] >= 0 ) ) {
293 + $consumed_attr_value_offsets[ $attr_match[2][1] ] = true;
294 + }
295 + }
296 + }
297 +
298 + if ( ! preg_match_all( '/"([^"]*)"|\'([^\']*)\'/u', $shortcode_text, $quoted_matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE ) ) {
299 + return array();
300 + }
301 +
302 + $shortcode_values = array();
303 +
304 + foreach ( $quoted_matches as $quoted_match ) {
305 +
306 + if ( isset( $quoted_match[1][1] ) && ( $quoted_match[1][1] >= 0 ) ) {
307 + $raw_value = $quoted_match[1][0];
308 + $raw_offset = $quoted_match[1][1];
309 + } else {
310 + $raw_value = $quoted_match[2][0];
311 + $raw_offset = $quoted_match[2][1];
312 + }
313 +
314 + if ( isset( $consumed_attr_value_offsets[ $raw_offset ] ) ) {
315 + continue;
316 + }
317 +
318 + $value_parts = explode( '@@', $raw_value, 2 );
319 +
320 + if ( 2 === count( $value_parts ) ) {
321 + $shortcode_values[] = array(
322 + 'title' => $value_parts[0],
323 + 'value' => $value_parts[1],
324 + );
325 + } else {
326 + $shortcode_values[] = array(
327 + 'value' => $value_parts[0],
328 + );
329 + }
330 + }
331 +
332 + return $shortcode_values;
333 + }
334 +
335 +
336 + /**
223 337 * Get Time-Slots == RANGE TIME == [ '10:00 - 12:00', '12:00 - 14:00' ... ] from provided booking form configuration content
224 338 *
225 339 * @param $bookingform_configuration_content - '[calendar]... <p>Time: [select* rangetime "Full Day@@00:00 - 24:00" "10:00 AM - 12:00 PM@@10:00 - 12:00"] ...'
226 340 *
@@ -239,9 +353,9 @@
239 353 */
240 354 function wpbc_get_timeslots__for_rangetime( $bookingform_configuration_content ) {
241 355
242 356 $time_slots_arr = array();
243 - $shortcode_values = wpbc_parse_form__get_first_shortcode_values( 'rangetime', $bookingform_configuration_content );
357 + $shortcode_values = wpbc_get_times_fields__get_first_shortcode_values( 'rangetime', $bookingform_configuration_content );
244 358
245 359 if ( ! empty( $shortcode_values ) ) {
246 360 foreach ( $shortcode_values as $timeslot_value ) {
247 361
@@ -276,9 +390,9 @@
276 390 function wpbc_get_timeslots__for_starttime( $bookingform_configuration_content , $time_shift_duration_in_seconds = 60 ) {
277 391
278 392 $time_slots_arr = array();
279 393
280 - $shortcode_values = wpbc_parse_form__get_first_shortcode_values( 'starttime', $bookingform_configuration_content );
394 + $shortcode_values = wpbc_get_times_fields__get_first_shortcode_values( 'starttime', $bookingform_configuration_content );
281 395 if ( ! empty( $shortcode_values ) ) {
282 396 foreach ( $shortcode_values as $timeslot_value ) {
283 397
284 398 if ( ! empty( $timeslot_value['value'] ) ) {
@@ -323,9 +437,9 @@
323 437 function wpbc_get_timeslots__for_endtime( $bookingform_configuration_content , $time_shift_duration_in_seconds = 60 ) {
324 438
325 439 $time_slots_arr = array();
326 440
327 - $shortcode_values = wpbc_parse_form__get_first_shortcode_values( 'endtime', $bookingform_configuration_content );
441 + $shortcode_values = wpbc_get_times_fields__get_first_shortcode_values( 'endtime', $bookingform_configuration_content );
328 442 if ( ! empty( $shortcode_values ) ) {
329 443 foreach ( $shortcode_values as $timeslot_value ) {
330 444
331 445 if ( ! empty( $timeslot_value['value'] ) ) {
@@ -359,9 +473,9 @@
359 473
360 474 $min_time_duration = false;
361 475 $time_duration_in_seconds_arr = array();
362 476
363 - $shortcode_values = wpbc_parse_form__get_first_shortcode_values( 'durationtime', $bookingform_configuration_content );
477 + $shortcode_values = wpbc_get_times_fields__get_first_shortcode_values( 'durationtime', $bookingform_configuration_content );
364 478 if ( ! empty( $shortcode_values ) ) {
365 479 foreach ( $shortcode_values as $timeslot_value ) {
366 480
367 481 if ( ! empty( $timeslot_value['value'] ) ) {
@@ -378,5 +492,5 @@
378 492 $min_time_duration = min( $time_duration_in_seconds_arr );
379 493 }
380 494
381 495 return $min_time_duration;
382 - }
496 + }