PluginProbe
Booking Calendar / 11.8.2
Booking Calendar v11.8.2
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 10.11.3 All 202 releases
← All changes | includes/_functions/booking_data__parse.php +106 -115 11.411.8.2 View file →
@@ -363,19 +363,19 @@
363 363 * Example 4: $booking_form = wpbc_get__booking_form_fields__configuration( 1 , '' ); <- Load CUSTOM booking form, which is DEFAULT for RESOURCE
364 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 365 *
366 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 -}
367 +function wpbc_get__booking_form_fields__configuration( $resource_id = 1, $form_name = 'standard' ) {
376 368
369 + $pair = wpbc_get__bfb_booking_form_pair__for_field_names_listing( $resource_id, $form_name, wpbc_get_request_form_context() );
377 370
371 + // Keep the complete BFB source intact. Languages use separate custom forms.
372 + $booking_form_configuration = isset( $pair['form'] ) ? (string) $pair['form'] : '';
373 +
374 + return $booking_form_configuration;
375 +}
376 +
377 +
378 378 /**
379 379 * Load BFB preview payload from transient (for booking created inside preview iframe).
380 380 *
381 381 * @param array $ctx
@@ -466,20 +466,18 @@
466 466 }
467 467 }
468 468
469 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 );
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 + }
478 476
479 - // Language.
480 - $booking_form_show = wpbc_lang( $booking_form_show );
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 );
481 478
479 + // Keep the complete BFB content template intact. Languages use separate custom forms.
482 480 return $booking_form_show;
483 481 }
484 482
485 483
@@ -712,9 +710,9 @@
712 710
713 711 /**
714 712 * Get booking form pair (fields + show template) for listing/inspection purposes.
715 713 *
716 - * Uses BFB resolver and returns advanced_form + content_form.
714 + * Uses BFB resolver and returns advanced_form + content_form.
717 715 *
718 716 * @param int $resource_id
719 717 * @param string $form_name
720 718 * @param array $ctx
@@ -730,19 +728,16 @@
730 728 if ( '' === $form_name ) {
731 729 $form_name = 'standard';
732 730 }
733 731
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' => '' ) );
732 + $bfb_pair = wpbc_get__bfb_booking_form_pair__for_field_names_listing( $resource_id, $form_name, $ctx );
733 + $pair = is_array( $bfb_pair ) ? $bfb_pair : array();
734 + $pair = wp_parse_args( $pair, array( 'form' => '', 'content' => '' ) );
737 735
738 736 $pair['form'] = wpbc_bf__replace_custom_html_shortcodes( (string) $pair['form'] );
739 737 $pair['content'] = wpbc_bf__replace_custom_html_shortcodes( (string) $pair['content'] );
740 738
741 - $pair['form'] = wpbc_lang( (string) $pair['form'] );
742 - $pair['content'] = wpbc_lang( (string) $pair['content'] );
743 -
744 -
739 + // Do not interpret inline [lang=LOCALE] markers as whole-form language blocks.
745 740 return $pair;
746 741 }
747 742
748 743 /**
@@ -747,9 +742,9 @@
747 742
748 743 /**
749 744 * Get arr of all fields names from all booking forms (including custom).
750 745 *
751 - * Load form names through BFB helpers and inspect each stored form pair.
746 + * Load form names through BFB helpers and inspect each stored form pair.
752 747 *
753 748 * @return array
754 749 */
755 750 function wpbc_get__in_all_forms__field_names_arr() {
@@ -755,101 +750,84 @@
755 750 function wpbc_get__in_all_forms__field_names_arr() {
756 751
757 752 $booking_form_fields_arr = array();
758 753
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 ) {
754 + $ctx = wpbc_get_request_form_context();
755 + $ctx['form_status'] = 'published';
822 756
823 - $booking_form = isset( $booking_form_element['form'] ) ? (string) $booking_form_element['form'] : '';
757 + $form_names = array( 'standard' );
824 758
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*\]%';
759 + if (
760 + class_exists( 'WPBC_FE_Custom_Form_Helper' )
761 + && method_exists( 'WPBC_FE_Custom_Form_Helper', 'get_custom_booking_forms_list' )
762 + ) {
763 + $owner_user_id = 0;
828 764
829 - $fields_matches = array();
830 - $fields_matches2 = array();
765 + if ( method_exists( 'WPBC_FE_Custom_Form_Helper', 'wpbc_mu__get_current__owner_user_id' ) ) {
766 + $owner_user_id = absint( WPBC_FE_Custom_Form_Helper::wpbc_mu__get_current__owner_user_id() );
767 + }
831 768
832 - $fields_count = preg_match_all( $regex, $booking_form, $fields_matches );
833 - $fields_count2 = preg_match_all( $regex2, $booking_form, $fields_matches2 );
769 + $ctx['owner_user_id'] = $owner_user_id;
834 770
835 - foreach ( $fields_matches2 as $key => $value ) {
771 + $forms_list = WPBC_FE_Custom_Form_Helper::get_custom_booking_forms_list(
772 + array(
773 + 'include_standard' => false,
774 + 'owner_user_id' => $owner_user_id,
775 + 'statuses' => array( 'published' ),
776 + 'list_mode' => 'bfb',
777 + )
778 + );
836 779
837 - if ( 2 === (int) $key ) {
838 - $value = $fields_matches2[1];
839 - }
780 + if ( is_array( $forms_list ) ) {
781 + foreach ( $forms_list as $form_data ) {
840 782
841 - if ( ! isset( $fields_matches[ $key ] ) || ! is_array( $fields_matches[ $key ] ) ) {
842 - $fields_matches[ $key ] = array();
843 - }
783 + if ( empty( $form_data['name'] ) ) {
784 + continue;
785 + }
844 786
845 - foreach ( $value as $single_value ) {
846 - $fields_matches[ $key ][] = $single_value;
787 + $form_name = sanitize_text_field( (string) $form_data['name'] );
788 +
789 + if ( ( '' !== $form_name ) && ( 'standard' !== $form_name ) ) {
790 + $form_names[] = $form_name;
791 + }
847 792 }
848 793 }
794 + }
849 795
850 - $fields_count += $fields_count2;
796 + $form_names = array_values( array_unique( $form_names ) );
851 797
798 + foreach ( $form_names as $form_name ) {
799 +
800 + $pair = wpbc_get__booking_form_pair__for_field_names_listing(
801 + wpbc_get_default_resource(),
802 + $form_name,
803 + $ctx
804 + );
805 +
806 + $booking_form_fields_arr[] = array(
807 + 'name' => $form_name,
808 + 'form' => $pair['form'],
809 + 'content' => $pair['content'],
810 + );
811 + }
812 +
813 + // ---------------------------------------------------------------------
814 + // Common parser.
815 + // ---------------------------------------------------------------------
816 + foreach ( $booking_form_fields_arr as $form_key => $booking_form_element ) {
817 +
818 + $booking_form = isset( $booking_form_element['form'] ) ? (string) $booking_form_element['form'] : '';
819 +
820 + // Keep field-assignment inventories aligned with the shared shortcode parser. Builder choice fields can
821 + // contain named attributes such as default="1", which the former duplicate regex did not recognize.
822 + $parsed_booking_fields = '' !== trim( $booking_form ) ? wpbc_get_fields_from_booking_form( $booking_form ) : false;
823 + $fields_count = 0;
824 + $fields_matches = array_fill( 0, 5, array() );
825 +
826 + if ( false !== $parsed_booking_fields ) {
827 + list( $fields_count, $fields_matches ) = $parsed_booking_fields;
828 + }
829 +
852 830 $booking_form_fields_arr[ $form_key ]['num'] = $fields_count;
853 831 $booking_form_fields_arr[ $form_key ]['listing'] = array();
854 832
855 833 if ( ! isset( $fields_matches[1] ) ) {
@@ -1078,14 +1056,27 @@
1078 1056 $booking_form_show = str_replace( '[' . $type_name . ']', $value, $booking_form_show );
1079 1057 }
1080 1058 }
1081 1059
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;
1060 + if ( ! isset( $all_fields_array_without_types['booking_resource_id'] ) ) {
1061 + $all_fields_array_without_types['booking_resource_id'] = $bktype;
1062 + }
1063 + if ( ! isset( $all_fields_array_without_types['resource_id'] ) ) {
1064 + $all_fields_array_without_types['resource_id'] = $bktype;
1065 + }
1066 + if ( ! isset( $all_fields_array_without_types['type_id'] ) ) {
1067 + $all_fields_array_without_types['type_id'] = $bktype;
1068 + }
1085 1069
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;
1070 + if ( ! isset( $all_fields_array_without_types['type'] ) ) {
1071 + $all_fields_array_without_types['type'] = $bktype;
1072 + }
1073 + if ( ! isset( $all_fields_array_without_types['resource'] ) ) {
1074 + $all_fields_array_without_types['resource'] = wpbc_get_resource_title( $bktype );
1075 + }
1076 + if ( ! isset( $all_fields_array_without_types['resource_title'] ) ) {
1077 + $all_fields_array_without_types['resource_title'] = wpbc_get_resource_title( $bktype );
1078 + }
1088 1079
1089 1080 foreach ($extended_params as $key_param=>$value_param) {
1090 1081 if (! isset($all_fields_array_without_types[ $key_param ])) $all_fields_array_without_types[ $key_param ] = $value_param;
1091 1082 }
@@ -1207,5 +1198,5 @@
1207 1198 }
1208 1199
1209 1200
1210 1201 return $replaced_form;
1211 -}
1202 +}