PluginProbe
Booking Calendar / 11.8.3
Booking Calendar v11.8.3
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 +104 -4 11.011.8.3 View file →
@@ -233,8 +233,108 @@
233 233 }
234 234
235 235
236 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 + /**
237 337 * Get Time-Slots == RANGE TIME == [ '10:00 - 12:00', '12:00 - 14:00' ... ] from provided booking form configuration content
238 338 *
239 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"] ...'
240 340 *
@@ -253,9 +353,9 @@
253 353 */
254 354 function wpbc_get_timeslots__for_rangetime( $bookingform_configuration_content ) {
255 355
256 356 $time_slots_arr = array();
257 - $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 );
258 358
259 359 if ( ! empty( $shortcode_values ) ) {
260 360 foreach ( $shortcode_values as $timeslot_value ) {
261 361
@@ -290,9 +390,9 @@
290 390 function wpbc_get_timeslots__for_starttime( $bookingform_configuration_content , $time_shift_duration_in_seconds = 60 ) {
291 391
292 392 $time_slots_arr = array();
293 393
294 - $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 );
295 395 if ( ! empty( $shortcode_values ) ) {
296 396 foreach ( $shortcode_values as $timeslot_value ) {
297 397
298 398 if ( ! empty( $timeslot_value['value'] ) ) {
@@ -337,9 +437,9 @@
337 437 function wpbc_get_timeslots__for_endtime( $bookingform_configuration_content , $time_shift_duration_in_seconds = 60 ) {
338 438
339 439 $time_slots_arr = array();
340 440
341 - $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 );
342 442 if ( ! empty( $shortcode_values ) ) {
343 443 foreach ( $shortcode_values as $timeslot_value ) {
344 444
345 445 if ( ! empty( $timeslot_value['value'] ) ) {
@@ -373,9 +473,9 @@
373 473
374 474 $min_time_duration = false;
375 475 $time_duration_in_seconds_arr = array();
376 476
377 - $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 );
378 478 if ( ! empty( $shortcode_values ) ) {
379 479 foreach ( $shortcode_values as $timeslot_value ) {
380 480
381 481 if ( ! empty( $timeslot_value['value'] ) ) {