File manager - Edit - /home/premiey/www/wp-includes/images/media/_functions.tar
Back
parse_booking_data.php 0000666 00000103155 15165456057 0011117 0 ustar 00 <?php /** * @version 1.0 * @package Booking Calendar * @subpackage Booking Data Parsing functions * @category Functions * * @author wpdevelop * @link https://wpbookingcalendar.com/ * @email info@wpbookingcalendar.com * * @modified 2024-05-14 */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly // ===================================================================================================================== // == B o o k i n g F o r m s P a r s i n g == // ===================================================================================================================== /** * Parse "text^firstname1^John~..." -> [ 'firstname':[name:"firstname", value:"John" ...] ... ] - Parse (DB) form_data and get fields array values * * @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^&#36;400.00~text^deposit_hint15^&#36;40.00~text^standard_bk_cost15^100~...' * @param int $resource_id - ID of booking resource * @param array $params - (optional) default: array() define here what field we need to get array( 'get' => 'value' ) * * @return array * [ * rangetime = [ * type = "selectbox-multiple" * original_name = "rangetime3[]" * name = "rangetime" * value = "12:00 - 14:00" * ] * name = [ * type = "text" * original_name = "name3" * name = "name" * value = "test 1" * ] * secondname = [...] * email = [...] * ] * * Example 1: * $structured_booking_data_arr = wpbc_get_parsed_booking_data_arr( $this_booking->form, $resource_id, array( 'get' => 'value' ) ); * output: [ "rangetime" : "12:00 - 14:00", * "name": "John" , * "secondname" : "Smith" , "email" : "test@wpbookingcalendar.com" , "visitors" : "1" ... ] * * Example 2: * $structured_booking_data_arr = wpbc_get_parsed_booking_data_arr( $this_booking->form, $resource_id ); * output: [ rangetime = [ * type = "selectbox-multiple" * original_name = "rangetime3[]" * name = "rangetime" * value = "12:00 - 14:00" * ] * name = [ * type = "text" * original_name = "name3" * name = "name" * value = "test 1" * ] * secondname = [...] * email = [...] * ] */ function wpbc_get_parsed_booking_data_arr( $form_data, $resource_id = 1, $params = array( ) ) { $booking_data_arr = array(); if ( ! empty( $form_data ) ) { $fields_arr = explode( '~', $form_data ); foreach ( $fields_arr as $field ) { if ( false === strpos( $field, '^' ) ) { break; //FixIn: 9.8.10.2 } list( $field_type, $field_original_name, $field_value ) = explode( '^', $field ); $field_name = $field_original_name; // Is this multi select in checkboxes: [checkbox* ConducenteExtra "Si" "No"] => [... 6: "checkbox^ConducenteExtra4[]^Si", 7: "checkbox^ConducenteExtra4[]^" ... ] $is_multi_options = ( '[]' == substr( $field_name, - 2 ) ); $minus_additional = ( '[]' == substr( $field_name, - 2 ) ) ? 2 : 0; $field_name = ( $minus_additional > 0 ) ? substr( $field_name, 0, - $minus_additional ) : $field_name; $minus_additional = ( strval( $resource_id ) == substr( $field_name, - 1 * ( strlen( strval( $resource_id ) ) ) ) ) ? strlen( strval( $resource_id ) ) : 0; $field_name = ( $minus_additional > 0 ) ? substr( $field_name, 0, - $minus_additional ) : $field_name; if ( ( 'checkbox' === $field_type ) && ( 'true' === $field_value ) ) { //$field_value = strtolower( __( 'Yes', 'booking' ) ); $field_value = 'true'; } if ( ( 'checkbox' === $field_type ) && ( 'false' === $field_value ) ) { //$field_value = strtolower( __( 'No', 'booking' ) ); $field_value = 'false'; } if ( ! isset( $booking_data_arr[ $field_name ] ) ) { $booking_data_arr[ $field_name ] = array( 'type' => $field_type, 'original_name' => $field_original_name, 'name' => $field_name, 'value' => array( $field_value ) ); } else { // All values we save as array values, for situations of MULTI options: // [checkbox* ConducenteExtra "Si" "No"] => [... 6: "checkbox^ConducenteExtra4[]^Si", 7: "checkbox^ConducenteExtra4[]^" ... ] $booking_data_arr[ $field_name ]['value'][] = $field_value; } } // Convert arrays to string foreach ( $booking_data_arr as $field_name => $field_structure_arr ) { //FixIn: 9.8.9.1 $field_structure_arr['value'] = array_filter( $field_structure_arr['value'], function ( $v ) { return ( $v !== '' ); // Remove All '' entries } ); $booking_data_arr[ $field_name ]['value'] = implode( ', ', $field_structure_arr['value'] ); } if ( isset( $params['get'] ) ) { /** * Now get only values or other fields: [ * "rangetime" : "12:00 - 14:00", * "name":"test 1" , * "secondname" : "test 1" , * "email" : "test@wpbookingcalendar.com" , * "visitors" : "1" * ... * ] */ foreach ( $booking_data_arr as $field_name => $field_structure_arr ) { if ( isset( $field_structure_arr[ $params['get'] ] ) ) { $booking_data_arr[ $field_name ] = $field_structure_arr[ $params['get'] ]; } else { $booking_data_arr[ $field_name ] = '-'; } } } } return $booking_data_arr; } /** * Convert [ ... ] -> "text^firstname1^John~..." - encoded booking data string (Usually for inserting into DB), from parsed booking data array * * @param array $booking_data_arr - parsed booking data. * @param int $resource_id - ID of booking resource - In case, if we need to RE-UPDATE booking resource, Otherwise skip it * * @return string */ function wpbc_encode_booking_data_to_string( $booking_data_arr, $resource_id = 0 ) { $fields_arr = array(); foreach ( $booking_data_arr as $fields ) { if ( ! empty( $resource_id ) ) { $fields_arr[] = $fields['type'] . '^' . $fields['name'] . $resource_id . ( ( '[]' == substr( $fields['original_name'], - 2 ) ) ? '[]' : '' ) . '^' . $fields['value']; } else { $fields_arr[] = $fields['type'] . '^' . $fields['original_name'] . '^' . $fields['value']; } } $form_data = implode( '~', $fields_arr ); return $form_data; } // ------------------------------------------------------------------------------------------------------------- /** * Get Time fields in booking form_data * * @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^&#36;400.00~text^deposit_hint15^&#36;40.00~text^standard_bk_cost15^100~...' * @param int $resource_id - ID of booking resource * @param array $params - (optional) default: array() define here what field we need to get array( 'get' => 'value' ) * * @return array [ "18:00:00", "20:00:00" ] <- default * * Example #1: $times_his_arr = wpbc_get_times_his_arr__in_form_data( $form_data, $resource_id); --> [ "18:00:01", "20:00:02" ] * 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" ] * 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 ] * 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",... ] * * Example #5: $booking_data_arr = wpbc_get_times_his_arr__in_form_data( $form_data, $resource_id, array( 'get' => 'all' ) ); * --> [ * 'structured_booking_data_arr' => [ name = "John", secondname = "Smith", email = "john.smith@server.com", visitors = "2",... ] * 'time_as_seconds_arr' => [ 64800, 72000 ] * 'time_as_his_arr' => [ "18:00:01", "20:00:02" ] * ] */ function wpbc_get_times_his_arr__in_form_data( $form_data, $resource_id = 1, $params = array() ) { $defaults = array( 'get' => 'times_his_arr' ); $params = wp_parse_args( $params, $defaults ); // Get Time from booking form $local_params = array(); /** * Get parsed booking form: = [ name = "John", secondname = "Smith", email = "john.smith@server.com", visitors = "2",... ] */ $local_params['structured_booking_data_arr'] = wpbc_get_parsed_booking_data_arr( $form_data, $resource_id, array( 'get' => 'value' ) ); // $local_params['all_booking_data_arr'] = wpbc_get_parsed_booking_data_arr( $form_data, $resource_id ); // Important! : [ 64800, 72000 ] $local_params['time_as_seconds_arr'] = wpbc_get_in_booking_form__time_to_book_as_seconds_arr( $local_params['structured_booking_data_arr'] ); // [ "18:00:00", "20:00:00" ] $time_as_seconds_arr = $local_params['time_as_seconds_arr']; $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 $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 if ( ( 0 != $time_as_seconds_arr[0] ) && ( ( 24 * 60 * 60 ) == $time_as_seconds_arr[1] ) ) { //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 $time_as_seconds_arr[1] += - 8; } // [ '16:00:01', '18:00:02' ] $local_params['times_his_arr'] = array( wpbc_transform__seconds__in__24_hours_his( $time_as_seconds_arr[0] ), wpbc_transform__seconds__in__24_hours_his( $time_as_seconds_arr[1] ) ); if ( ( isset( $params['get'] ) ) && ( isset( $local_params[ $params['get'] ] ) ) ) { return $local_params[ $params['get'] ]; } return $local_params; } // ------------------------------------------------------------------------------------------------------------- /** * Get readable booking form data. Escape values here, as well! * * - 1. <= BS : 'Booking form show' configuration from standard form in versions up to Business Small version , * - 2 >= BM : If form data has field of custom form, then from custom form configuration, * - 3 >= BM : Otherwise if resource has default custom booking form, then from this default custom booking form * - 4 = MU : specific form of specific WP User * - 5 finally : simple standard form * * @param string $form_data * @param int $resource_id * * @return string */ function wpbc_get__booking_form_data__show( $form_data, $resource_id = 1 , $params = array() ) { $defaults = array( 'is_replace_unknown_shortcodes' => true, 'unknown_shortcodes_replace_by' => '' ); $params = wp_parse_args( $params, $defaults ); $booking_form_show = wpbc_get__booking_form_data_configuration( $resource_id, $form_data ); $booking_data_arr = wpbc_get_parsed_booking_data_arr( $form_data, $resource_id, array( 'get' => 'value' ) ); foreach ( $booking_data_arr as $key_param => $value_param ) { //FixIn: 6.1.1.4 $value_param = esc_html( $value_param ); //FixIn: 9.7.4.1 - escape coded html/xss $value_param = esc_html( html_entity_decode( $value_param ) ); $value_param = nl2br($value_param); // Add BR instead if /n elements //FixIn: 9.7.4.2 $value_param = wpbc_string__escape__then_convert__n_amp__html( $value_param ); $value_param = wpbc_replace__true_false__to__yes_no( $value_param ); //FixIn: 9.8.9.1 if ( ( gettype( $value_param ) != 'array' ) && ( gettype( $value_param ) != 'object' ) ) { $booking_form_show = str_replace( '[' . $key_param . ']', $value_param, $booking_form_show ); } } if ($params['is_replace_unknown_shortcodes']) { // Remove all shortcodes, which is not replaced early. $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 } $booking_form_show = str_replace( "&", '&', $booking_form_show ); //FixIn:7.1.2.12 return $booking_form_show; } /** * Get name of custom booking form, if it was used in form data OR booking resource use this default custom form * * @param int $resource_id * @param string $form_data Form data here, required in >= BM, because such form_data can contain fields about used custom booking form * * @return string */ function wpbc_get__custom_booking_form_name( $resource_id = 1, $form_data = '' ) { $my_booking_form_name = ''; if ( class_exists( 'wpdev_bk_biz_m' ) ) { if ( false !== strpos( $form_data, 'wpbc_custom_booking_form' . $resource_id . '^' ) ) { //FixIn: 9.4.3.12 $custom_booking_form_name = substr( $form_data, strpos( $form_data, 'wpbc_custom_booking_form' . $resource_id . '^' ) + strlen( 'wpbc_custom_booking_form' . $resource_id . '^' ) ); if ( false !== strpos( $custom_booking_form_name, '~' ) ) { $custom_booking_form_name = substr( $custom_booking_form_name, 0, strpos( $custom_booking_form_name, '~' ) ); $my_booking_form_name = $custom_booking_form_name; } } else { // BM :: Get default Custom Form of Resource $my_booking_form_name = apply_bk_filter( 'wpbc_get_default_custom_form', 'standard', $resource_id ); } if ( 'standard' == $my_booking_form_name ) { $my_booking_form_name = ''; } } return $my_booking_form_name; } /** * Get configuration of 'BOOKING FORM F I E L D S SHORTCODES' from - Booking > Settings > Form page * * - 1. <= BS : 'Booking form show' configuration from standard form in versions up to Business Small version , * - 2 >= BM : If form data has field of custom form, then from custom form configuration, * - 3 >= BM : Otherwise if resource has default custom booking form, then from this default custom booking form * - 4 = MU : specific form of specific WP User * - 5 finally : simple standard form * * @param int $resource_id * @param string $form_name Name of custom booking form, required in >= BM * * @return string * * Example 1: $booking_form = wpbc_get__booking_form_fields__configuration( 1 ); <- Load STANDARD booking form * Example 2: $booking_form = wpbc_get__booking_form_fields__configuration( 1 , 'standard' ); <- Load STANDARD booking form * Example 3: $booking_form = wpbc_get__booking_form_fields__configuration( 1 , 'my_custom_form' ); <- Load CUSTOM booking form with name 'my_custom_form' * Example 4: $booking_form = wpbc_get__booking_form_fields__configuration( 1 , '' ); <- Load CUSTOM booking form, which is DEFAULT for RESOURCE * 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 * */ function wpbc_get__booking_form_fields__configuration( $resource_id = 1, $form_name = 'standard' ) { if ( ! class_exists( 'wpdev_bk_personal' ) ) { $booking_form_configuration = wpbc_get_free_form_fields_configuration(); } else { $booking_form_configuration = get_bk_option( 'booking_form' ); if ( class_exists( 'wpdev_bk_biz_m' ) ) { if ( $form_name != 'standard' ) { $booking_form_configuration = apply_bk_filter( 'wpdev_get_booking_form', $booking_form_configuration, $form_name ); } // Get default Custom Form for resource, if $form_name == '' wpbc_get__booking_form_fields__configuration(1,'') if ( empty( $form_name ) ) { $resource_default_custom_form_name = apply_bk_filter( 'wpbc_get_default_custom_form', 'standard', $resource_id ); $booking_form_configuration = apply_bk_filter( 'wpdev_get_booking_form', $booking_form_configuration, $resource_default_custom_form_name ); } //MU :: if resource of "Regular User" - then GET STANDARD user form ( if ( get_bk_option( 'booking_is_custom_forms_for_regular_users' ) !== 'On' ) ) $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 } } // Language $booking_form_configuration = wpbc_lang( $booking_form_configuration ); return $booking_form_configuration; } /** * Get configuration of 'BOOKING FORM DATA' from - Booking > Settings > Form page * * - 1. <= BS : 'Booking form show' configuration from standard form in versions up to Business Small version , * - 2 >= BM : If form data has field of custom form, then from custom form configuration, * - 3 >= BM : Otherwise if resource has default custom booking form, then from this default custom booking form * - 4 = MU : specific form of specific WP User * - 5 finally : simple standard form * * @param int $resource_id * @param string $form_data Form data here, required in >= BM, because such form_data can contain fields about used custom booking form * * @return string */ function wpbc_get__booking_form_data_configuration( $resource_id = 1, $form_data = '' ) { if ( ! class_exists( 'wpdev_bk_personal' ) ) { $booking_form_show = wpbc_get_free_booking_show_form(); } else { $booking_form_show = get_bk_option( 'booking_form_show' ); $booking_form_show = wpbc_bf__replace_custom_html_shortcodes( $booking_form_show ); if ( class_exists( 'wpdev_bk_biz_m' ) ) { if ( false !== strpos( $form_data, 'wpbc_custom_booking_form' . $resource_id . '^' ) ) { //FixIn: 9.4.3.12 $custom_booking_form_name = substr( $form_data, strpos( $form_data, 'wpbc_custom_booking_form' . $resource_id . '^' ) + strlen( 'wpbc_custom_booking_form' . $resource_id . '^' ) ); if ( false !== strpos( $custom_booking_form_name, '~' ) ) { $custom_booking_form_name = substr( $custom_booking_form_name, 0, strpos( $custom_booking_form_name, '~' ) ); } $booking_form_show = apply_bk_filter( 'wpdev_get_booking_form_content', $booking_form_show, $custom_booking_form_name ); $my_booking_form_name = $custom_booking_form_name; } else { // BM :: Get default Custom Form of Resource $my_booking_form_name = apply_bk_filter( 'wpbc_get_default_custom_form', 'standard', $resource_id ); if ( ( $my_booking_form_name != 'standard' ) && ( ! empty( $my_booking_form_name ) ) ) { $booking_form_show = apply_bk_filter( 'wpdev_get_booking_form_content', $booking_form_show, $my_booking_form_name ); } } //MU :: if resource of "Regular User" - then GET STANDARD user form ( if ( get_bk_option( 'booking_is_custom_forms_for_regular_users' ) !== 'On' ) ) $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 } } // Language $booking_form_show = wpbc_lang( $booking_form_show ); return $booking_form_show; } /** * Get (in Free version) configuration of 'BOOKING FORM DATA' from - Booking > Settings > Form page * * @return false|mixed */ function wpbc_get_free_booking_show_form() { $booking_form_show = apply_bk_filter( 'wpbc_get_free_booking_show_form' ); return $booking_form_show; } // Get form function wpbc_get_free_form_fields_configuration() { $my_form = apply_bk_filter( 'wpbc_get_free_booking_form_shortcodes' ); return $my_form; } // ------------------------------------------------------------------------------------------------------------- /** * Replace resource_ID of booking in 'form_data' * Useful, when we need to save booking from one resource into another. * * @param $booking__form_data__str 'selectbox-multiple^rangetime2[]^18:00 - 20:00~checkbox^fee2[]^true~text^name2^John~text^secondname2^Smith...' * @param $new_resource_id 10 * @param $old_resource_id 2 * * @return string 'selectbox-multiple^rangetime10[]^18:00 - 20:00~checkbox^fee10[]^true~text^name10^John~text^secondname10^Smith...' */ function wpbc_get__form_data__with_replaced_id( $booking__form_data__str, $new_resource_id, $old_resource_id ) { $all_booking_data_arr = wpbc_get_parsed_booking_data_arr( $booking__form_data__str, $old_resource_id ); $new__form_data__str = wpbc_encode_booking_data_to_string( $all_booking_data_arr, $new_resource_id ); return $new__form_data__str; } /** * Get arr of all Fields Names from all booking forms (including custom) * * @return array = [ 0: [ name = "standard", num = 8, listing = [ ... ] ], 1: [ name = "minimal" num = 7 listing = [ labels = [ 0 = " adults" 1 = " children" 2 = " infants" 3 = " gender" 4 = " full_name" 5 = " email" 6 = " phone" fields = {array[7]} 0 = " adults" 1 = " children" 2 = " infants" 3 = " gender" 4 = " full_name" 5 = " email" 6 = " phone" fields_type = {array[7]} 0 = "select" 1 = "select" 2 = "select" 3 = "radio" 4 = "text" 5 = "email" 6 = "text" ] ] 2: [], ... * ] */ function wpbc_get__in_all_forms__field_names_arr() { $booking_form_fields_arr = array(); $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' ) ) ); /** * Get custom booking form configurations: [ * [ name = "minimal", * form = "[calendar]...", * content = "<div class="payment-content-form"> [name] ..." * ], * ... * ] */ $is_can = apply_bk_filter( 'multiuser_is_user_can_be_here', true, 'only_super_admin' ); if ( ( $is_can ) || ( get_bk_option( 'booking_is_custom_forms_for_regular_users' ) === 'On' ) ) { $booking_forms_extended = get_bk_option( 'booking_forms_extended' ); $booking_forms_extended = maybe_unserialize( $booking_forms_extended ); if ( false !== $booking_forms_extended ) { foreach ( $booking_forms_extended as $form_extended ) { $booking_form_fields_arr[] = $form_extended; } } } foreach ( $booking_form_fields_arr as $form_key => $booking_form_element ) { $booking_form = $booking_form_element['form']; $types = 'text[*]?|email[*]?|time[*]?|textarea[*]?|select[*]?|selectbox[*]?|checkbox[*]?|radio|acceptance|captchac|captchar|file[*]?|quiz'; $regex = '%\[\s*(' . $types . ')(\s+[a-zA-Z][0-9a-zA-Z:._-]*)([-0-9a-zA-Z:#_/|\s]*)?((?:\s*(?:"[^"]*"|\'[^\']*\'))*)?\s*\]%'; $regex2 = '%\[\s*(country[*]?|starttime[*]?|endtime[*]?)(\s*[a-zA-Z]*[0-9a-zA-Z:._-]*)([-0-9a-zA-Z:#_/|\s]*)*((?:\s*(?:"[^"]*"|\'[^\']*\'))*)?\s*\]%'; $fields_count = preg_match_all($regex, $booking_form, $fields_matches) ; $fields_count2 = preg_match_all($regex2, $booking_form, $fields_matches2) ; //Gathering Together 2 arrays $fields_matches and $fields_matches2 foreach ($fields_matches2 as $key => $value) { if ($key == 2) $value = $fields_matches2[1]; foreach ($value as $v) { $fields_matches[$key][count($fields_matches[$key])] = $v; } } $fields_count += $fields_count2; $booking_form_fields_arr[ $form_key ]['num'] = $fields_count; $booking_form_fields_arr[ $form_key ]['listing'] = array(); //$fields_matches; $fields_matches[1] = array_map( 'trim', $fields_matches[1] ); $fields_matches[2] = array_map( 'trim', $fields_matches[2] ); $booking_form_fields_arr[ $form_key ]['listing']['labels'] = array_map( 'ucfirst', $fields_matches[2] ); $booking_form_fields_arr[ $form_key ]['listing']['fields'] = $fields_matches[2] ; foreach ( $fields_matches[1] as $key_fm => $value_fm ) { $fields_matches[1][ $key_fm ] = trim( str_replace( '*', '', $value_fm ) ); } $booking_form_fields_arr[ $form_key ]['listing']['fields_type'] = $fields_matches[1]; // Reset unset( $booking_form_fields_arr[ $form_key ]['form'] ); unset( $booking_form_fields_arr[ $form_key ]['content'] ); } return $booking_form_fields_arr; } // ------------------------------------------------------------------------------------------------------------- /** * Get arr with booking form fields values, after parsing form_data. Avoid to use this function in a future. * * @param $formdata * @param $bktype * @param $booking_form_show * @param $extended_params * * @return array */ function wpbc__legacy__get_form_content_arr ( $formdata, $bktype =-1, $booking_form_show ='', $extended_params = array() ) { if ( $bktype == -1 ) { $bktype = ( function_exists( 'get__default_type' ) ) ? get__default_type() : 1; } if ( $booking_form_show === '' ) { $booking_form_show = wpbc_get__booking_form_data_configuration( $bktype, $formdata ); } $formdata_array = explode('~',$formdata); $formdata_array_count = count($formdata_array); $email_adress=''; $name_of_person = ''; $coupon_code = ''; $secondname_of_person = ''; $visitors_count = 1; $select_box_selected_items = array(); $check_box_selected_items = array(); $all_fields_array = array(); $all_fields_array_without_types = array(); $checkbox_value=array(); for ( $i=0 ; $i < $formdata_array_count ; $i++) { if ( empty( $formdata_array[$i] ) ) { continue; } $elemnts = explode('^',$formdata_array[$i]); $type = $elemnts[0]; $element_name = $elemnts[1]; $value = $elemnts[2]; //FixIn: 9.7.4.1 - escape coded html/xss $value = esc_html( $value ); $value = esc_html( html_entity_decode( $value ) ); $value = nl2br($value); // Add BR instead if /n elements //FixIn: 9.7.4.2 // Escaping for timeline popovers and for other places $value = wpbc_string__escape__then_convert__n_amp__html( $value ); $count_pos = strlen( $bktype ); $type_name = $elemnts[1]; $type_name = str_replace('[]','',$type_name); if ($bktype == substr( $type_name, -1*$count_pos ) ) $type_name = substr( $type_name, 0, -1*$count_pos ); // $type_name = str_replace($bktype,'',$elemnts[1]); if ( ( ($type_name == 'email') || ($type == 'email') ) && ( empty($email_adress) ) ) $email_adress = $value; //FixIn: 6.0.1.9 if ( ($type_name == 'coupon') || ($type == 'coupon') ) $coupon_code = $value; if ( ($type_name == 'name') || ($type == 'name') ) $name_of_person = $value; if ( ($type_name == 'secondname') || ($type == 'secondname') ) $secondname_of_person = $value; if ( ($type_name == 'visitors') || ($type == 'visitors') ) $visitors_count = $value; if ($type == 'checkbox') { if ($value == 'true') { $value = strtolower( __( 'yes', 'booking' ) ); } if ($value == 'false') { $value = strtolower( __( 'no', 'booking' ) ); } if ( $value !='' ) if ( ( isset($checkbox_value[ str_replace('[]','',(string) $element_name) ]) ) && ( is_array($checkbox_value[ str_replace('[]','',(string) $element_name) ]) ) ) { $checkbox_value[ str_replace('[]','',(string) $element_name) ][] = $value; } else { $checkbox_value[ str_replace('[]','',(string) $element_name) ] = array($value); } $value = '['. $type_name .']'; //FixIn: 6.1.1.14 } if ( ( $type == 'select-one') || ( $type == 'selectbox-one') || ( $type == 'select-multiple' ) || ( $type == 'selectbox-multiple' ) || ( $type == 'radio' ) ) { // add all select box selected items to return array $select_box_selected_items[$type_name] = $value; } if ( ($type == 'checkbox') && (isset($checkbox_value)) ) { if (isset( $checkbox_value[ str_replace('[]','',(string) $element_name) ] )) { if (is_array( $checkbox_value[ str_replace('[]','',(string) $element_name) ] )) $current_checkbox_value = implode(', ', $checkbox_value[ str_replace('[]','',(string) $element_name) ] ); else $current_checkbox_value = $checkbox_value[ str_replace('[]','',(string) $element_name) ] ; } else { $current_checkbox_value = ''; } $all_fields_array[ str_replace('[]','',(string) $element_name) ] = $current_checkbox_value; $all_fields_array_without_types[ substr( str_replace('[]','',(string) $element_name), 0 , -1*strlen( $bktype ) ) ] = $current_checkbox_value; $check_box_selected_items[$type_name] = $current_checkbox_value; } else { //FixIn: 8.4.2.11 $all_fields_array_without_types[ substr( str_replace('[]','',(string) $element_name), 0 , -1*strlen( $bktype ) ) ] = $value; /** ['_all_'] => $all_fields_array, CONVERT to " AM/PM " ['_all_fields_'] => $all_fields_array_without_types => in " 24 hour " format - for ability correct calculate Booking > Resources > Advanced cost page. */ if ( ( $type_name == 'rangetime' ) || ( $type == 'rangetime' ) ) { $value = wpbc_time_slot_in_format( $value ); } $all_fields_array[ str_replace('[]','',(string) $element_name) ] = $value; //FixIn: 8.4.2.11 } $is_skip_replace = false; //FixIn: 7.0.1.45 if ( ( $type == 'radio' ) && empty( $value ) ) $is_skip_replace = true; if ( ! $is_skip_replace ) { $booking_form_show = str_replace( '[' . $type_name . ']', $value, $booking_form_show ); } } if (! isset($all_fields_array_without_types[ 'booking_resource_id' ])) $all_fields_array_without_types[ 'booking_resource_id' ] = $bktype; if (! isset($all_fields_array_without_types[ 'resource_id' ])) $all_fields_array_without_types[ 'resource_id' ] = $bktype; if (! isset($all_fields_array_without_types[ 'type_id' ])) $all_fields_array_without_types[ 'type_id' ] = $bktype; if (! isset($all_fields_array_without_types[ 'type' ])) $all_fields_array_without_types[ 'type' ] = $bktype; if (! isset($all_fields_array_without_types[ 'resource' ])) $all_fields_array_without_types[ 'resource' ] = $bktype; foreach ($extended_params as $key_param=>$value_param) { if (! isset($all_fields_array_without_types[ $key_param ])) $all_fields_array_without_types[ $key_param ] = $value_param; } foreach ( $all_fields_array_without_types as $key_param=>$value_param) { //FixIn: 6.1.1.4 if ( ( gettype ( $value_param ) != 'array' ) && ( gettype ( $value_param ) != 'object' ) ) { $booking_form_show = str_replace( '['. $key_param .']', $value_param ,$booking_form_show); $all_fields_array_without_types[ $key_param ] = str_replace( "&", '&', $value_param ); //FixIn:7.1.2.12 } } // Remove all shortcodes, which is not replaced early. $booking_form_show = preg_replace ('/[\s]{0,}\[[a-zA-Z0-9.,-_]{0,}\][\s]{0,}/', '', $booking_form_show); //FixIn: 6.1.1.4 $booking_form_show = str_replace( "&", '&', $booking_form_show ); //FixIn:7.1.2.12 $return_array = array( 'content' => $booking_form_show, 'email' => $email_adress, 'name' => $name_of_person, 'secondname' => $secondname_of_person, 'visitors' => $visitors_count, 'coupon' => $coupon_code, '_all_' => $all_fields_array, '_all_fields_' => $all_fields_array_without_types ); foreach ( $select_box_selected_items as $key => $value ) { if ( ! isset( $return_array[ $key ] ) ) { $return_array[ $key ] = $value; } } foreach ( $check_box_selected_items as $key => $value ) { if ( ! isset( $return_array[ $key ] ) ) { $return_array[ $key ] = $value; } } return $return_array; } nonce_func.php 0000666 00000017316 15165456057 0007424 0 ustar 00 <?php /** * @version 1.0 * @package Booking Calendar * @subpackage Nonce functions - excluding from front-end * @category Functions * * @author wpdevelop * @link https://wpbookingcalendar.com/ * @email info@wpbookingcalendar.com * * @modified 2024-06-14 */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly //FixIn: 10.1.1.2 // ===================================================================================================================== // == Nonce functions == // ===================================================================================================================== /** * Is use nonce fields at Front-Edn side in king forms * If we do not use nonce, then it can prevent issues on websites with cache plugins regarding these Errors: Forbidden (403) Probably nonce for this page has been expired. * or Error: Request do not pass security check! Please refresh the page and try one more time. Please check more here https://wpbookingcalendar.com/faq/request-do-not-pass-security-check/ * Find more information at these pages: https://konstantin.blog/2012/nonces-on-the-front-end-is-a-bad-idea/ * https://contactform7.com/2017/08/18/contact-form-7-49/ * https://developer.wordpress.org/apis/security/nonces/ * * @return bool */ function wpbc_is_use_nonce_at_front_end() { return( 'On' === get_bk_option( 'booking_is_nonce_at_front_end' ) ); } // --------------------------------------------------------------------------------------------------------------------- // S u p p o r t f u n c t i o n s f o r A j a x /////////////// // --------------------------------------------------------------------------------------------------------------------- /** * Verify the nonce in Admin Panel - during Ajax request * * @param $action_check * * @return bool|void */ function wpbc_check_nonce_in_admin_panel( $action_check = 'wpbc_ajax_admin_nonce' ){ $nonce = ( isset($_REQUEST['wpbc_nonce']) ) ? $_REQUEST['wpbc_nonce'] : ''; if ( '' === $nonce ) return false; // Its was request from some other plugin //FixIn: 7.2.1.10 if ( ! wp_verify_nonce( $nonce, $action_check ) ) { // This nonce is not valid. ?> <script type="text/javascript"> if (jQuery("#ajax_respond").length > 0 ){ jQuery( "#ajax_respond" ).after( "<div class='wpdevelop'><div style='margin: 0 0 40px;' class='wpbc-general-settings-notice wpbc-settings-notice notice-error 0alert 0alert-warning 0alert-danger'><?php echo '<strong>' . esc_js( __( 'Error' , 'booking') ) . '!</strong> '; echo sprintf( esc_js( __( 'Probably nonce for this page has been expired. Please %sreload the page%s.', 'booking' ) ) ,"<a href='javascript:void(0)' onclick='javascript:location.reload();'>", "</a>"); echo '<br/>' . sprintf( esc_js( __( 'Please check more here %s', 'booking' ) ) , "<a href='https://wpbookingcalendar.com/faq/request-do-not-pass-security-check/?update=" . WP_BK_VERSION_NUM . '&ver=' . wpbc_get_version_type__and_mu(). "'>FAQ</a>" ); //FixIn: 8.8.3.6 ?></div></div>" ); } else if (jQuery(".ajax_respond_insert").length > 0 ){ jQuery( ".ajax_respond_insert" ).after( "<div class='wpdevelop'><div class='alert alert-warning alert-danger'><?php printf( __( '%sError!%s Request do not pass security check! Please refresh the page and try one more time.', 'booking' ), '<strong>', '</strong>' ); echo '<br/>' . sprintf( __( 'Please check more here %s', 'booking' ), 'https://wpbookingcalendar.com/faq/request-do-not-pass-security-check/?update=' . WP_BK_VERSION_NUM . '&ver=' . wpbc_get_version_type__and_mu() ); //FixIn: 8.8.3.6 ?></div></div>" ); } if ( jQuery( "#ajax_message" ).length ){ jQuery( "#ajax_message" ).slideUp(); } </script> <?php die; } return true; //FixIn: 7.2.1.10 } // --------------------------------------------------------------------------------------------------------------------- // For test only, where Nonce time can be adjusted // --------------------------------------------------------------------------------------------------------------------- // add_filter( 'nonce_life', 'wpbc_nonce_life_test' ); //function wpbc_nonce_life_test( $lifespan ) { // return 60; //4 * HOUR_IN_SECONDS; //} function wpbc_do_not_cache() { if ( ! defined( 'DONOTCACHEPAGE' ) ) { define( 'DONOTCACHEPAGE', true ); } if ( ! defined( 'DONOTCACHEDB' ) ) { define( 'DONOTCACHEDB', true ); } if ( ! defined( 'DONOTMINIFY' ) ) { define( 'DONOTMINIFY', true ); } if ( ! defined( 'DONOTCDN' ) ) { define( 'DONOTCDN', true ); } if ( ! defined( 'DONOTCACHEOBJECT' ) ) { define( 'DONOTCACHEOBJECT', true ); } // Set the headers to prevent caching for the different browsers. nocache_headers(); } //wpbc_do_not_cache(); // ===================================================================================================================== // Exclude from Minify and caching from different CACHE Plugins // ===================================================================================================================== /** * Add exclusion of minify JS files in 'WP-Optimize' plugin //FixIn: 10.1.3.3 * * Otherwise default rules: * *plugins/booking* * *jquery/jquery.min.js * *jquery/jquery-migrate.min.js * * @param $excluded_filter_arr * * @return mixed */ function wpbc_exclude_for_wp_optimize( $excluded_filter_arr ) { if ( is_array( $excluded_filter_arr ) ) { $excluded_filter_arr[] = '*/plugins/booking*'; $excluded_filter_arr[] = '*/jquery/jquery.min.js'; $excluded_filter_arr[] = '*/jquery/jquery-migrate.min.js'; } return $excluded_filter_arr; } add_filter( 'wp-optimize-minify-default-exclusions', 'wpbc_exclude_for_wp_optimize', 10, 1 ); /** * Exclude JS scripts from Delay JS in the WP Rocket plugin * * @param $exclusions * * @return mixed */ function wpbc_exclude_from_delay_for_wp_rocket( $exclusions ) { $plugin_path = wpbc_make_link_relative( WPBC_PLUGIN_URL ); // Exclude jQuery $exclusions[] = '/jquery(-migrate)?-?([0-9.]+)?(.min|.slim|.slim.min)?.js(\?(.*))?( |\'|"|>)'; // Exclude plugin JS files $exclusions[] = $plugin_path . '/(.*)'; /* $exclusions[] = '/wp-content/plugins/booking(.*)/_dist/all/_out/wpbc_all.js'; $exclusions[] = '/wp-content/plugins/booking(.*)/js/datepick/jquery.datepick.wpbc.9.0.js'; $exclusions[] = '/wp-content/plugins/booking(.*)/js/wpbc_time-selector.js'; $exclusions[] = '/wp-content/plugins/booking(.*)/assets/libs/tippy.js'; $exclusions[] = '/wp-content/plugins/booking(.*)/assets/libs/popper/popper.js'; $exclusions[] = '/wp-content/plugins/booking(.*)/inc/js/biz_m.js'; */ // Exclude some important plugin JS vars $exclusions[] = 'wpbc_init__head'; $exclusions[] = 'wpbc_url_ajax'; $exclusions[] = 'booking_max_monthes_in_calendar'; $exclusions[] = 'wpbc_define_tippy_popover'; $exclusions[] = 'flex_tl_table_loading'; $exclusions[] = '(.*)_wpbc.(.*)'; $exclusions[] = 'moveOptionalElementsToGarbage'; $exclusions[] = ' wpbc_(.*)'; // Old way to exclude all // $exclusions[] = '/wp-content/plugins/booking(.*)/(.*)'; // $exclusions[] = '(.*)wpbc(.*)'; return $exclusions; } add_filter( 'rocket_delay_js_exclusions', 'wpbc_exclude_from_delay_for_wp_rocket' ); regex_str.php 0000666 00000047775 15165456057 0007325 0 ustar 00 <?php /** * @version 1.0 * @package Booking Calendar * @subpackage Shortcode functions * @category Functions * * @author wpdevelop * @link https://wpbookingcalendar.com/ * @email info@wpbookingcalendar.com * * @modified 2024-05-14 */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly // ===================================================================================================================== // == String Manipulation functions == // ===================================================================================================================== /** * Insert New Line symbols after <br> tags. Usefull for the settings pages to show in redable view * * @param string $param * @return string */ function wpbc_nl_after_br($param) { $value = preg_replace( "@(<|<)br\s*/?(>|>)(\r\n)?@", "<br/>", $param ); return $value; } /** * Replace ** to <strong> and * to <em> * * @param String $text * @return string */ function wpbc_replace_to_strong_symbols( $text ){ $patterns = '/(\*\*)(\s*[^\*\*]*)(\*\*)/'; $replacement = '<strong>${2}</strong>'; $value_return = preg_replace($patterns, $replacement, $text); $patterns = '/(\*)(\s*[^\*]*)(\*)/'; $replacement = '<em>${2}</em>'; $value_return = preg_replace($patterns, $replacement, $value_return); return $value_return; } /** * Replace 'true' | 'false' to __('yes') | __('no'). E.g.: '...Fee: true...' => '...Fee: yes...' * * Replace value 'true' to localized __( 'yes', 'booking' ) in Content -- usually it's required before showing text to user for saved data of selected checkboxes, that was configured with empty value: [checkbox fee ""] * * @param $value * * @return array|string|string[] */ function wpbc_replace__true_false__to__yes_no( $value ) { //FixIn: 9.8.9.1 $checkbox_true_value = apply_filters( 'wpbc_checkbox_true_value', __( 'Y_E_S', 'booking' ) ); $value_replaced = str_replace( 'true', $checkbox_true_value, $value ); $checkbox_true_value = apply_filters( 'wpbc_checkbox_false_value', __( 'N_O', 'booking' ) ); $value_replaced = str_replace( 'false', $checkbox_true_value, $value_replaced ); return $value_replaced; } /** * Convert Strings in array to Lower case * @param $array * * @return mixed */ function wpbc_convert__strings_in_arr__to_lower( $array ){ return unserialize( strtolower( serialize( $array ) ) ); } /** * Prepare text to show as HTML, replace double encoded \\n to <br> and escape \\" and \\' . Mainly used in Ajax. * * @param $text * * @return array|string|string[]|null */ function wpbc_prepare_text_for_html( $text ){ /** * Replace <p> | <br> to ' ' * * $plain_form_data_show = preg_replace( '/<(br|p)[\t\s]*[\/]?>/i', ' ', $plain_form_data_show ); */ $text = preg_replace( '/(\\\\n)/i', '<br>', $text ); // New line in text areas replace with <br> $text = preg_replace( '/(\\\\")/i', '"', html_entity_decode( $text ) ); // escape quote symbols; $text = preg_replace( "/(\\\\')/i", ''', html_entity_decode( $text ) ); // escape quote symbols; // Replace \r \n \t $text = preg_replace( '/(\\r|\\n|\\t)/i', ' ', $text ); return $text; } // TODO: Need to check if we really need to make this. 2023-10-06 12:46 /** * Escaping text for output. * * @param string $output * * @return string */ function wpbc_escaping_text_for_output( $output ){ // Save empty spaces $original_symbols = array( ' ' ); $temporary_symbols = array( '^space^' ); $output = str_replace( $original_symbols, $temporary_symbols, $output ); // -> ^space^ // Escaping ? $output = esc_js( $output ); // it adds '\n' symbols | " into " | < -> < ... $output = html_entity_decode( $output ); // Convert back to HTML, but now we have '\n' symbols $output = str_replace( "\\n", '', $output ); // Remove '\n' symbols // Back to empty spaces. $original_symbols = array( '^space^' ); $temporary_symbols = array( ' ' ); $output = str_replace( $original_symbols, $temporary_symbols, $output); return $output; } /** * Convert text with escaped symbols like '1. Soem text here\n2. \"Quoted text\"\n3. \'Single quoted text\'\n' to HTML: * * @param $text * * @return array|string|string[] */ function wpbc_string__escape__then_convert__n_amp__html( $text ) { $is_escape_sql = false; // Do not replace % $escaped_text = wpbc_escape_any_xss_in_string($text, $is_escape_sql ); $text_html = str_replace( array( "\\r\\n", "\\r", "\\n", "\r\n", "\r","\n" ), "<br/>", $escaped_text ); //FixIn: 8.1.3.4 $text_html = str_replace( array( "\\&" ), '&', $text_html ); return $text_html; } // ===================================================================================================================== // == Regex for Shortcodes == // ===================================================================================================================== /** * Get parameters of shortcode in string '..some text [visitorbookingpayurl url='https://url.com/a/'] ...' -> [ 'url'='https://url.com.com/a/', 'start'=10, 'end'=80 ] * * @param string $shortcode - shortcode name - 'visitorbookingcancelurl' * @param string $subject - string where to search shortcode: - '<p>1 PT. [visitorbookingpayurl url='https://wpbookingcalendar.com/faq/']</p>' * @param int $pos default 0 - 0 * @param string $pattern_to_search default '%\s*([^=]*)=\s*[\'"]([^\'"]*)[\'"]\s*%' * * @return array|false [ * 'url' = "https://wpbookingcalendar.com/faq/" * 'start' = 10 * 'end' = 80 * ] * * Example: * wpbc_get_params_of_shortcode_in_string( 'visitorbookingpayurl', '<p>1 PT. [visitorbookingpayurl url = "https://wpbookingcalendar.com/faq/"]</p>...' ); * * output -> [ * 'url' = "https://wpbookingcalendar.com/faq/" * 'start' = 10 * 'end' = 80 * ] * */ function wpbc_get_params_of_shortcode_in_string( $shortcode, $subject, $pos = 0, $pattern_to_search = '%\s*([^=]*)=\s*[\'"]([^\'"]*)[\'"]\s*%' ) { //FixIn: 9.7.4.4 //FixIn: 7.0.1.8 7.0.1.52 if ( strlen( $subject ) < intval( $pos ) ) { //FixIn: (9.7.4.5) return false; } $pos = strpos( $subject, '[' . $shortcode, $pos ); //FixIn: 7.0.1.52 if ( $pos !== false ) { $pos2 = strpos( $subject, ']', ( $pos + 2 ) ); $my_params = substr( $subject, $pos + strlen( '[' . $shortcode ), ( $pos2 - $pos - strlen( '[' . $shortcode ) ) ); preg_match_all( $pattern_to_search, $my_params, $keywords, PREG_SET_ORDER ); foreach ( $keywords as $value ) { if ( count( $value ) > 1 ) { $shortcode_params[ trim( $value[1] ) ] = trim( $value[2] ); //FixIn: 9.7.4.4 } } $shortcode_params['start'] = $pos + 1; $shortcode_params['end'] = $pos2; return $shortcode_params; } else { return false; } } /** * Get shortcodes with params and text for replacing these shortcodes as new uniue shortcodes * * @param string $content_text Example: "<span class="wpbc_top_news_dismiss">[wpbc_dismiss id="wpbc_top_news__offer_2023_04_21"]</span>" * @param array $shortcode_arr Example: array( 'wpbc_dismiss' ) * * @return array * Example: array( content => "<span class="wpbc_top_news_dismiss">[wpbc_dismiss6764]</span>" shortcodes => array( 'wpbc_dismiss6764' => array( shortcode => "[wpbc_dismiss6764]", params => array( id => "wpbc_top_news__offer_2023_04_21" ) shortcode_original => "[wpbc_dismiss id="wpbc_top_news__offer_2023_04_21"]" ) ) ) */ function wpbc_get_shortcodes_in_text__as_unique_replace( $content_text, $shortcode_arr = array( 'wpbc_dismiss' ) ) { //FixIn: 9.6.1.8 $replace = array(); foreach ( $shortcode_arr as $single_shortcode ) { $pos = 0; // Loop to find if we have several such shortcodes in $content_text do { $shortcode_params = wpbc_get_params_of_shortcode_in_string( $single_shortcode, $content_text, $pos ); if ( ( ! empty( $shortcode_params ) ) && ( isset( $shortcode_params['end'] ) ) && ( $shortcode_params['end'] < strlen( $content_text ) ) ){ $exist_replace = substr( $content_text, $shortcode_params['start'], ( $shortcode_params['end'] - $shortcode_params['start'] ) ); $new_replace = $single_shortcode . rand( 1000, 9000 ); $pos = $shortcode_params['start'] + strlen( $new_replace ); $content_text = substr_replace( $content_text, $new_replace, $shortcode_params['start'], ( $shortcode_params['end'] - $shortcode_params['start'] ) ); $params_in_shortcode = $shortcode_params; unset( $params_in_shortcode['start'] ); unset( $params_in_shortcode['end'] ); $replace[ $new_replace ] = array( 'shortcode' => '[' . $new_replace . ']', 'params' => $params_in_shortcode, 'shortcode_original' => '[' . $exist_replace . ']', ); } else { $shortcode_params = false; } } while ( ! empty( $shortcode_params ) ); } return array( 'content' => $content_text, 'shortcodes' => $replace ); } // --------------------------------------------------------------------------------------------------------------------- /** * >=BS - for 'Billing fields' - Get fields from booking form at the settings page or return false if no fields * * @param string $booking_form * @return mixed false | array( $fields_count, $fields_matches ) */ function wpbc_get_fields_from_booking_form( $booking_form = '' ){ if ( empty( $booking_form ) ) { $booking_form = get_bk_option( 'booking_form' ); } $types = 'text[*]?|email[*]?|time[*]?|textarea[*]?|select[*]?|selectbox[*]?|checkbox[*]?|radio|acceptance|captchac|captchar|file[*]?|quiz'; $regex = '%\[\s*(' . $types . ')(\s+[a-zA-Z][0-9a-zA-Z:._-]*)([-0-9a-zA-Z:#_/|\s]*)?((?:\s*(?:"[^"]*"|\'[^\']*\'))*)?\s*\]%'; $regex2 = '%\[\s*(country[*]?|starttime[*]?|endtime[*]?)(\s*[a-zA-Z]*[0-9a-zA-Z:._-]*)([-0-9a-zA-Z:#_/|\s]*)*((?:\s*(?:"[^"]*"|\'[^\']*\'))*)?\s*\]%'; $fields_count = preg_match_all( $regex, $booking_form, $fields_matches ); $fields_count2 = preg_match_all( $regex2, $booking_form, $fields_matches2 ); //Gathering Together 2 arrays $fields_matches and $fields_matches2 foreach ( $fields_matches2 as $key => $value ) { if ( $key == 2 ) { $value = $fields_matches2[1]; } foreach ( $value as $v ) { $fields_matches[ $key ][ count( $fields_matches[ $key ] ) ] = $v; } } $fields_count += $fields_count2; if ( $fields_count > 0 ) { return array( $fields_count, $fields_matches ); } else { return false; } } /** * >= BM - for 'Advanced costs' -- Get only SELECT, CHECKBOX & RADIO fields from booking form at the settings page or return false if no fields * * @param string $booking_form * @return mixed false | array( $fields_count, $fields_matches ) */ function wpbc_get_select_checkbox_fields_from_booking_form( $booking_form = '' ){ if ( empty( $booking_form ) ) $booking_form = get_bk_option( 'booking_form' ); $types = 'select[*]?|selectbox[*]?|checkbox[*]?|radio[*]?'; //FixIn: 8.1.3.7 $regex = '%\[\s*(' . $types . ')(\s+[a-zA-Z][0-9a-zA-Z:._-]*)([-0-9a-zA-Z:#_/|\s]*)?((?:\s*(?:"[^"]*"|\'[^\']*\'))*)?\s*\]%'; $fields_count = preg_match_all($regex, $booking_form, $fields_matches) ; if ( $fields_count > 0 ) return array( $fields_count, $fields_matches ); else return false; } // --------------------------------------------------------------------------------------------------------------------- // Used in 'Search Availability' functionality // --------------------------------------------------------------------------------------------------------------------- /** * Parse Option Values to get Title and Value, if used @@ '10 AM - 2PM@@10:00 - 14:00' -> [ '10 AM - 2PM', '10:00 - 14:00' ] * * @param $option '10 AM - 2PM@@10:00 - 14:00' OR '10:00 - 14:00' * * @return array [ '10 AM - 2PM', '10:00 - 14:00' ] OR [ '10:00 - 14:00', '10:00 - 14:00' ] * * * Example #1: wpbc_field_option__get_tile_value( '10 AM - 2PM@@10:00 - 14:00' ) -> [ '10 AM - 2PM', '10:00 - 14:00' ] * Example #2: wpbc_field_option__get_tile_value( '10:00 - 14:00' ) -> [ '10:00 - 14:00', '10:00 - 14:00' ] */ function wpbc_shortcode_option__get_tile_value( $option ) { $option_title_value_arr = explode( '@@', $option ); $option_title = $option_title_value_arr[0]; $option_value = ( count( $option_title_value_arr ) == 2 ) ? $option_title_value_arr[1] : $option_title_value_arr[0]; return array( $option_title, $option_value ); } /** * Find shortcodes with Options: [search_quantity "---@@1" 'Title A@@value2' "3"] or [search_quantity] * * @param $content string ex.: '<a href="[search_result_url]" class="wpbc_book_now_link"> ... [search_result_button "Booking" 'other' "d'ata"] ... ' * @param $shortcode_to_search string ex.: 'search_result_url' * * @return array [ * [search_result_url] => [ * [replace] => [search_result_url] * [options] => [] * ] * [search_result_button] => [ * [replace] => [search_result_button "Booking" 'other' "d'ata"] * [options] => [ * [0] => Booking * [1] => other * [2] => d'ata * ] * ] * ] * * Example: to search one shortcode: wpbc_shortcode_options__get( $text, 'search_result_button' ); * Example: to search several shortcode: wpbc_shortcode_options__get( $text, 'search_result_button|search_result_url' ); * */ function wpbc_shortcode_with_options__find( $content, $shortcode_to_search = 'search_result_button' . '|' . 'search_result_url' ) { $shortcodes_arr = array(); $regex = '%\[\s*(' . $shortcode_to_search . ')\s*((?:\s*(?:"[^"]*"|\'[^\']*\'))*)?\s*\]%'; $fields_count = preg_match_all($regex, $content, $fields_matches, PREG_SET_ORDER ) ; if ( $fields_count > 0 ) { foreach ( $fields_matches as $found_shortcodes_arr ) { list( $full_shortcode_to_replace, $shortcode_name, $shortcode_params ) = $found_shortcodes_arr; $shortcodes_arr[$shortcode_name] = array( 'replace' => $full_shortcode_to_replace, 'options' => array() ); $pattern_to_search = '%\s*[\'"]([^\'"]*)[\'"]\s*%'; $pattern_to_search = '%\s*[\']([^\']*)[\']|[\"]([^\"]*)[\"]\s*%'; $fields_count = preg_match_all($pattern_to_search, $shortcode_params, $options_matches, PREG_SET_ORDER ) ; foreach ( $options_matches as $found_options_arr ) { $found_option_to_replace = $found_options_arr[0]; $found_option_value = $found_options_arr[ ( count( $found_options_arr ) - 1 ) ]; $shortcodes_arr[$shortcode_name]['options'][]=$found_option_value; } } } return $shortcodes_arr; } /** * Find shortcodes with Names and Options: [selectbox location "Any@@" "United States@@USA" "France" "Spain"] * * @param $content string ex.: '... text ... [selectbox search_time 'Any@@' "10 AM - 2PM@@10:00 - 14:00" '3 PM - 4PM@@15:00 - 16:00'] .... [selectbox othersearch_time] ... [selectbox location "Any@@" "Spain Country@@Spain" "France" "Singapur" "Tirana"] .... ' * @param $shortcode_to_search string ex.: 'select|selectbox' * * @return array [ * [search_time] => [ * [replace] => [selectbox search_time 'Any@@' "10 AM - 2PM@@10:00 - 14:00" '3 PM - 4PM@@15:00 - 16:00'] * [type] => selectbox * [name] => search_time * [options] => [ * [0] => Any@@ * [1] => 10 AM - 2PM@@10:00 - 14:00 * [2] => 3 PM - 4PM@@15:00 - 16:00 * ] * ], * [othersearch_time] => [ * [replace] => [selectbox othersearch_time] * [type] => select * [name] => othersearch_time * [options] => [] * ] * [location] => [ * [replace] => [selectbox location "Any@@" "Spain Country@@Spain" "France" "Singapur" "Tirana"] * [type] => select * [name] => location * [options] => [ * [0] => Any@@ * [1] => Spain Country@@Spain * [2] => France * [3] => Singapur * [4] => Tirana * ] * ] * ] * * Example: to search several shortcode types: wpbc_shortcode_with_name_and_options__find( $text, 'select|selectbox' ); * Example: to search one shortcode type: wpbc_shortcode_with_name_and_options__find( $text, 'checkbox' ); * */ function wpbc_shortcode_with_name_and_options__find( $content, $shortcode_to_search = 'select' . '|' . 'selectbox' ) { $shortcodes_arr = array(); $regex = '%\[\s*(' . $shortcode_to_search . ')\s+([^\s]+)\s*((?:\s*(?:"[^"]*"|\'[^\']*\'))*)?\s*\]%'; $fields_count = preg_match_all($regex, $content, $fields_matches, PREG_SET_ORDER ) ; if ( $fields_count > 0 ) { foreach ( $fields_matches as $found_shortcodes_arr ) { list( $full_shortcode_to_replace, $shortcode_type, $shortcode_name, $shortcode_params ) = $found_shortcodes_arr; $shortcodes_arr[$shortcode_name] = array( 'replace' => $full_shortcode_to_replace, 'type' => $shortcode_type, 'name' => $shortcode_name, 'options' => array() ); $pattern_to_search = '%\s*[\'"]([^\'"]*)[\'"]\s*%'; $pattern_to_search = '%\s*[\']([^\']*)[\']|[\"]([^\"]*)[\"]\s*%'; $fields_count = preg_match_all($pattern_to_search, $shortcode_params, $options_matches, PREG_SET_ORDER ) ; foreach ( $options_matches as $found_options_arr ) { $found_option_to_replace = $found_options_arr[0]; $found_option_value = $found_options_arr[ ( count( $found_options_arr ) - 1 ) ]; $shortcodes_arr[$shortcode_name]['options'][]=$found_option_value; } } } return $shortcodes_arr; }
| ver. 1.4 |
Github
|
.
| PHP 5.4.45 | Generation time: 0 |
proxy
|
phpinfo
|
Settings