| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | <?php /** |
| 2 | 2 | * @version 1.0 |
| 3 | 3 | * @description Bookings Listing SQL |
| 4 | 4 | * @category Booking Listing |
| @@ -7,8 +7,9 @@ | ||
| 7 | 7 | * @web-site http://oplugins.com/ |
| 8 | 8 | * @email [email protected] |
| 9 | 9 | * |
| 10 | 10 | * @modified 2022-04-07 |
| 11 | + * @file ../includes/page-bookings/bookings__sql.php | |
| 11 | 12 | */ |
| 12 | 13 | |
| 13 | 14 | if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 14 | 15 | |
| @@ -29,9 +30,9 @@ | ||
| 29 | 30 | */ |
| 30 | 31 | function wpbc_ajx_get__request_params__names_default( $structure_type = 'validate_and_default' ){ |
| 31 | 32 | |
| 32 | 33 | // Clean specific $_REQUEST params, if param is NOT set then return "default" |
| 33 | - $params_for_cleaning = array( | |
| 34 | + $params_for_cleaning = array( | |
| 34 | 35 | // 'wh_booking_id' => array( 'validate' => 'digit_or_date', 'default' => '' ), |
| 35 | 36 | |
| 36 | 37 | // 'digit_or_csd' can check about 'digit_or_csd' in arrays, as well |
| 37 | 38 | 'wh_booking_type' => array( 'validate' => 'digit_or_csd', 'default' => array( '0' ) ) // if ['0'] - All booking resources, ['-1'] - lost bookings in deleted resources |
| @@ -84,17 +85,28 @@ | ||
| 84 | 85 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 85 | 86 | , 'ui_reset' => array( 'validate' => 's', 'default' => '' ) // string |
| 86 | 87 | , 'ui_usr__dates_short_wide' => array( 'validate' => array( 'short', 'wide' ), 'default' => 'short' ) |
| 87 | 88 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 88 | - , 'view_days_num' => array( 'validate' => 'd', 'default' => 30 ) // '1' | '' //FixIn: 8.9.2.1 | |
| 89 | + , 'view_days_num' => array( 'validate' => 'd', 'default' => 30 ) // '1' | '' // FixIn: 8.9.2.1. | |
| 89 | 90 | , 'scroll_start_date' => array( 'validate' => 'digit_or_date', 'default' => '' ) // number | date 2016-07-20 |
| 90 | 91 | , 'scroll_day' => array( 'validate' => 'd', 'default' => 0 ) // '1' | '' |
| 91 | 92 | , 'scroll_month' => array( 'validate' => 'd', 'default' => 0 ) // '1' | '' |
| 92 | 93 | , 'limit_hours' => array( 'validate' => 'digit_or_csd', 'default' => '' ) // |
| 93 | - , 'only_booked_resources' => array( 'validate' => 'd', 'default' => 0 ) // '1' | '' | |
| 94 | + , 'only_booked_resources' => array( 'validate' => 'd', 'default' => 0 ) // '1' | '' | |
| 95 | + | |
| 96 | + ); | |
| 97 | + | |
| 98 | + /** | |
| 99 | + * Filter the Booking Listing request schema before values are sanitized. | |
| 100 | + * | |
| 101 | + * Extensions may add narrowly scoped listing filters without duplicating the | |
| 102 | + * saved-user-request or AJAX sanitization pipeline. | |
| 103 | + * | |
| 104 | + * @param array<string,array<string,mixed>> $params_for_cleaning Request validation and default definitions. | |
| 105 | + * @param string $structure_type Requested schema representation. | |
| 106 | + */ | |
| 107 | + $params_for_cleaning = apply_filters( 'wpbc_booking_listing_request_params_schema', $params_for_cleaning, $structure_type ); | |
| 94 | 108 | |
| 95 | - ); | |
| 96 | - | |
| 97 | 109 | if ( 'validate_and_default' == $structure_type ) { |
| 98 | 110 | return $params_for_cleaning; |
| 99 | 111 | } |
| 100 | 112 | |
| @@ -378,9 +390,9 @@ | ||
| 378 | 390 | */ |
| 379 | 391 | |
| 380 | 392 | |
| 381 | 393 | // 4. Include dates into bookings (Wide and Short dates view) |
| 382 | - $bookings_with_dates = wpbc_ajx_include_bookingdates_in_bookings( $bookings_obj, $booking_dates_obj ); | |
| 394 | + $bookings_with_dates = wpbc_ajx_include_bookingdates_in_the_bookings( $bookings_obj, $booking_dates_obj ); | |
| 383 | 395 | /** |
| 384 | 396 | Array ( [182] => stdClass Object ( |
| 385 | 397 | |
| 386 | 398 | [booking_db] => stdClass Object ( |
| @@ -562,10 +574,11 @@ | ||
| 562 | 574 | $sql['where'] = " WHERE ( 1 = 1 )"; |
| 563 | 575 | |
| 564 | 576 | if ( class_exists( 'wpdev_bk_multiuser' ) ) { // MultiUser - only specific booking resources for specific Regular User in Admin panel. |
| 565 | 577 | |
| 578 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing | |
| 566 | 579 | if ( isset( $_REQUEST['wpbc_ajx_user_id'] ) ) { |
| 567 | - $user_bk_id = intval( $_REQUEST['wpbc_ajx_user_id'] ); | |
| 580 | + $user_bk_id = intval( $_REQUEST['wpbc_ajx_user_id'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing | |
| 568 | 581 | } else { |
| 569 | 582 | $user_bk_id = wpbc_get_current_user_id(); |
| 570 | 583 | } |
| 571 | 584 | $is_user_super_admin = apply_bk_filter( 'is_user_super_admin', $user_bk_id ); |
| @@ -574,9 +587,9 @@ | ||
| 574 | 587 | $sql['where'] .= 'AND users = ' . $user_bk_id . ' '; |
| 575 | 588 | } |
| 576 | 589 | } |
| 577 | 590 | |
| 578 | - // Order depends from version //FixIn: 9.9.0.23 | |
| 591 | + // Order depends from version // FixIn: 9.9.0.23. | |
| 579 | 592 | if ( class_exists( 'wpdev_bk_biz_l' ) ) { |
| 580 | 593 | $sql['order'] = " ORDER BY parent, prioritet, title, booking_type_id"; |
| 581 | 594 | } else { |
| 582 | 595 | $sql['order'] = " ORDER BY title, booking_type_id"; |
| @@ -588,9 +601,9 @@ | ||
| 588 | 601 | . $sql['where'] |
| 589 | 602 | . $sql['order']; |
| 590 | 603 | // , $sql['sql_args'] |
| 591 | 604 | // ); |
| 592 | - | |
| 605 | + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 593 | 606 | $resources = $wpdb->get_results( $sql_prepared ); |
| 594 | 607 | |
| 595 | 608 | $resources_arr = array(); |
| 596 | 609 | |
| @@ -895,9 +908,9 @@ | ||
| 895 | 908 | |
| 896 | 909 | $sql['where'] .= " )"; |
| 897 | 910 | |
| 898 | 911 | |
| 899 | - // W H E R E : booking ID //FixIn: 9.4.3.9 | |
| 912 | + // W H E R E : booking ID // FixIn: 9.4.3.9. | |
| 900 | 913 | $is_id = strpos( trim( strtolower( $params['keyword'] ) ) , 'id:' ); // Keyword, like 'id:200' OR 'id:100,105' |
| 901 | 914 | if ( 0 === $is_id ){ |
| 902 | 915 | |
| 903 | 916 | $search_booking_id = substr( trim( $params['keyword'] ), 3 ); |
| @@ -917,12 +930,36 @@ | ||
| 917 | 930 | $sql['where'] = apply_bk_filter('update_where_sql_for_getting_bookings_in_multiuser', $sql['where'] ); // Add 'AND bk.booking_type IN ( $user_resources )' to the end of Where |
| 918 | 931 | } |
| 919 | 932 | } |
| 920 | 933 | |
| 921 | - //////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 922 | - | |
| 923 | - | |
| 924 | - switch ( $params['wh_sort'] ) { | |
| 934 | + //////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 935 | + | |
| 936 | + /** | |
| 937 | + * Filter the prepared Booking Listing WHERE fragment and its placeholders. | |
| 938 | + * | |
| 939 | + * The base query has already applied dates, resources, MultiUser ownership, | |
| 940 | + * status, cost, and keyword rules. Additions must return the same two keys. | |
| 941 | + * | |
| 942 | + * @param array{where:string,args:array<int,mixed>} $query_parts WHERE SQL and prepare arguments. | |
| 943 | + * @param array<string,mixed> $request_params Sanitized listing request. | |
| 944 | + * @param array<string,mixed> $params Request merged with defaults. | |
| 945 | + */ | |
| 946 | + $query_parts = apply_filters( | |
| 947 | + 'wpbc_booking_listing_sql_query_parts', | |
| 948 | + array( | |
| 949 | + 'where' => $sql['where'], | |
| 950 | + 'args' => $sql_args, | |
| 951 | + ), | |
| 952 | + $request_params, | |
| 953 | + $params | |
| 954 | + ); | |
| 955 | + if ( is_array( $query_parts ) && isset( $query_parts['where'], $query_parts['args'] ) && is_string( $query_parts['where'] ) && is_array( $query_parts['args'] ) ) { | |
| 956 | + $sql['where'] = $query_parts['where']; | |
| 957 | + $sql_args = $query_parts['args']; | |
| 958 | + } | |
| 959 | + | |
| 960 | + | |
| 961 | + switch ( $params['wh_sort'] ) { | |
| 925 | 962 | case 'booking_id__asc': |
| 926 | 963 | $order_by = 'booking_id ASC '; |
| 927 | 964 | break; |
| 928 | 965 | case 'booking_id__desc': |
| @@ -974,20 +1011,14 @@ | ||
| 974 | 1011 | |
| 975 | 1012 | //////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 976 | 1013 | // SELECT at this specific PAGE ///////////////////////////////////////////////////////////////// |
| 977 | 1014 | //////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 978 | - $sql_prepared = $wpdb->prepare( | |
| 979 | - $sql['start_select'] | |
| 980 | - . $sql['from'] | |
| 981 | - . $sql['where'] | |
| 982 | - . $sql['order'] | |
| 983 | - . $sql['limit'] | |
| 984 | - , $sql_args | |
| 985 | - ); | |
| 1015 | + /* phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare */ | |
| 1016 | + $sql_prepared = $wpdb->prepare( $sql['start_select'] . $sql['from'] . $sql['where'] . $sql['order'] . $sql['limit'], $sql_args ); | |
| 1017 | + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 1018 | + $bookings_sql_obj = $wpdb->get_results( $sql_prepared ); | |
| 986 | 1019 | |
| 987 | - $bookings_sql_obj = $wpdb->get_results($sql_prepared); | |
| 988 | 1020 | |
| 989 | - | |
| 990 | 1021 | //////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 991 | 1022 | // COUNT of items with this WHERE /////////////////////////////////////////////////////////////////// |
| 992 | 1023 | //////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 993 | 1024 | $sql_for_listing_count = $sql['start_count'] |
| @@ -998,14 +1029,13 @@ | ||
| 998 | 1029 | |
| 999 | 1030 | $sql_prepared = $sql_for_listing_count; |
| 1000 | 1031 | |
| 1001 | 1032 | } else { |
| 1002 | - $sql_prepared = $wpdb->prepare( | |
| 1003 | - $sql_for_listing_count | |
| 1004 | - , $sql_args_count | |
| 1005 | - ); | |
| 1033 | + /* phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare */ | |
| 1034 | + $sql_prepared = $wpdb->prepare( $sql_for_listing_count, $sql_args_count ); | |
| 1006 | 1035 | } |
| 1007 | - $bookings_count = $wpdb->get_results( $sql_prepared ); | |
| 1036 | + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 1037 | + $bookings_count = $wpdb->get_results( $sql_prepared ); | |
| 1008 | 1038 | $bookings_count = ( ( count( $bookings_count ) > 0 ) ? $bookings_count[0]->count : 0 ); |
| 1009 | 1039 | |
| 1010 | 1040 | return array( |
| 1011 | 1041 | 'count' => $bookings_count |
| @@ -1033,44 +1063,44 @@ | ||
| 1033 | 1063 | else { $and_pre = ''; $and_suf = ' AND '; } |
| 1034 | 1064 | |
| 1035 | 1065 | // Actual |
| 1036 | 1066 | if ( ( ( $wh_booking_date === '' ) && ( $wh_booking_date2 === '' ) ) || ($wh_booking_date === '0') ) { |
| 1037 | - $sql_where = $and_pre."( ".$pref."booking_date >= ( CURDATE() - INTERVAL '00:00:01' HOUR_SECOND ) ) ".$and_suf ; //FixIn: 8.5.2.14 | |
| 1067 | + $sql_where = $and_pre."( ".$pref."booking_date >= (" . wpbc_sql_date_math_expr_explicit( "- INTERVAL '00:00:01' HOUR_SECOND", 'curdate' ) . ") ) ".$and_suf ; // FixIn: 8.5.2.14. | |
| 1038 | 1068 | |
| 1039 | - } else if ($wh_booking_date === '1') { // Today //FixIn: 7.1.2.8 | |
| 1040 | - $sql_where = $and_pre."( ".$pref."booking_date <= ( CURDATE() + INTERVAL '23:59:59' HOUR_SECOND ) ) ".$and_suf ; | |
| 1041 | - $sql_where .= $and_pre."( ".$pref."booking_date >= ( CURDATE() - INTERVAL '00:00:01' HOUR_SECOND ) ) ".$and_suf ; //FixIn: 8.4.7.21 | |
| 1069 | + } else if ($wh_booking_date === '1') { // Today // FixIn: 7.1.2.8. | |
| 1070 | + $sql_where = $and_pre."( ".$pref."booking_date <= (" . wpbc_sql_date_math_expr_explicit( "+ INTERVAL '23:59:59' HOUR_SECOND", 'curdate' ) . ") ) ".$and_suf ; | |
| 1071 | + $sql_where .= $and_pre."( ".$pref."booking_date >= (" . wpbc_sql_date_math_expr_explicit( "- INTERVAL '00:00:01' HOUR_SECOND", 'curdate' ) . ") ) ".$and_suf ; // FixIn: 8.4.7.21. | |
| 1042 | 1072 | |
| 1043 | 1073 | |
| 1044 | 1074 | } else if ($wh_booking_date === '2') { // Previous |
| 1045 | - $sql_where = $and_pre."( ".$pref."booking_date <= ( CURDATE() - INTERVAL '00:00:01' HOUR_SECOND ) ) ".$and_suf ; //FixIn: 8.5.2.16 | |
| 1075 | + $sql_where = $and_pre."( ".$pref."booking_date <= (" . wpbc_sql_date_math_expr_explicit( "- INTERVAL '00:00:01' HOUR_SECOND", 'curdate' ) . ") ) ".$and_suf ; // FixIn: 8.5.2.16. | |
| 1046 | 1076 | |
| 1047 | 1077 | } else if ($wh_booking_date === '3') { // All |
| 1048 | 1078 | $sql_where = ''; |
| 1049 | 1079 | |
| 1050 | 1080 | } else if ($wh_booking_date === '4') { // Next |
| 1051 | - $sql_where = $and_pre."( ".$pref."booking_date <= ( CURDATE() + INTERVAL ". $wh_booking_date2 . " DAY ) ) ".$and_suf ; | |
| 1052 | - // $sql_where .= $and_pre."( ".$pref."booking_date >= ( CURDATE() - INTERVAL 1 DAY ) ) ".$and_suf ; | |
| 1053 | - $sql_where .= $and_pre."( ".$pref."booking_date > ( CURDATE() ) ) ".$and_suf ; //FixIn: 8.0.1.1 | |
| 1081 | + $wh_booking_date2 = intval( $wh_booking_date2 ); // FixIn: 10.14.16.1. | |
| 1082 | + $sql_where = $and_pre."( ".$pref."booking_date <= (" . wpbc_sql_date_math_expr_explicit( "+ INTERVAL ". $wh_booking_date2 . " DAY", 'curdate' ) . ") ) ".$and_suf ; | |
| 1083 | + // $sql_where .= $and_pre."( ".$pref."booking_date >= (" . wpbc_sql_date_math_expr_explicit( "- INTERVAL 1 DAY", 'curdate' ) . ") ) ".$and_suf ; | |
| 1084 | + $sql_where .= $and_pre."( ".$pref."booking_date > ( " . wpbc_sql_date_math_expr_explicit('', 'curdate') . " ) ) ".$and_suf ; // FixIn: 8.0.1.1. | |
| 1054 | 1085 | |
| 1055 | 1086 | } else if ($wh_booking_date === '5') { // Prior |
| 1056 | 1087 | $wh_booking_date2 = str_replace('-', '', $wh_booking_date2); |
| 1057 | - $sql_where = $and_pre."( ".$pref."booking_date >= ( CURDATE() - INTERVAL ". $wh_booking_date2 . " DAY ) ) ".$and_suf ; | |
| 1058 | - $sql_where .= $and_pre."( ".$pref."booking_date <= ( CURDATE() + INTERVAL 1 DAY ) ) ".$and_suf ; | |
| 1088 | + $wh_booking_date2 = intval( $wh_booking_date2 ); // FixIn: 10.14.16.1. | |
| 1089 | + $sql_where = $and_pre."( ".$pref."booking_date >= (" . wpbc_sql_date_math_expr_explicit( "- INTERVAL ". $wh_booking_date2 . " DAY", 'curdate' ) . ") ) ".$and_suf ; | |
| 1090 | + $sql_where .= $and_pre."( ".$pref."booking_date <= (" . wpbc_sql_date_math_expr_explicit( "+ INTERVAL 1 DAY", 'curdate' ) . ") ) ".$and_suf ; | |
| 1059 | 1091 | |
| 1060 | 1092 | } else if ($wh_booking_date === '7') { // Check In date - Today/Tomorrow |
| 1061 | - // $sql_where = $and_pre."( ".$pref."booking_date <= ( CURDATE() + INTERVAL '23:59:59' HOUR_SECOND ) ) ".$and_suf ; | |
| 1062 | - // $sql_where .= $and_pre."( ".$pref."booking_date >= ( CURDATE() ) ) ".$and_suf ; | |
| 1063 | - $sql_where = $and_pre."( ".$pref."booking_date <= ( CURDATE() + INTERVAL '1 23:59:59' DAY_SECOND ) ) ".$and_suf ; | |
| 1064 | - $sql_where .= $and_pre."( ".$pref."booking_date >= ( CURDATE() + INTERVAL 1 DAY ) ) ".$and_suf ; | |
| 1093 | + $sql_where = $and_pre."( ".$pref."booking_date <= (" . wpbc_sql_date_math_expr_explicit( "+ INTERVAL '47:59:59' HOUR_SECOND", 'curdate' ) . ") ) ".$and_suf ; | |
| 1094 | + $sql_where .= $and_pre."( ".$pref."booking_date >= (" . wpbc_sql_date_math_expr_explicit( "+ INTERVAL 1 DAY", 'curdate' ) . ") ) ".$and_suf ; | |
| 1065 | 1095 | |
| 1066 | 1096 | } else if ($wh_booking_date === '8') { // Check Out date - Tomorrow |
| 1067 | - $sql_where = $and_pre."( ".$pref."booking_date <= ( CURDATE() + INTERVAL '1 23:59:59' DAY_SECOND ) ) ".$and_suf ; | |
| 1068 | - $sql_where .= $and_pre."( ".$pref."booking_date >= ( CURDATE() + INTERVAL 1 DAY ) ) ".$and_suf ; | |
| 1097 | + $sql_where = $and_pre."( ".$pref."booking_date <= (" . wpbc_sql_date_math_expr_explicit( "+ INTERVAL '47:59:59' HOUR_SECOND", 'curdate' ) . ") ) ".$and_suf ; | |
| 1098 | + $sql_where .= $and_pre."( ".$pref."booking_date >= (" . wpbc_sql_date_math_expr_explicit( "+ INTERVAL 1 DAY", 'curdate' ) . ") ) ".$and_suf ; | |
| 1069 | 1099 | |
| 1070 | 1100 | } else if ( ( $wh_booking_date === '9' ) || ( $wh_booking_date === '10' ) || ( $wh_booking_date === '11' ) ) { // Today check in/out |
| 1071 | - $sql_where = $and_pre."( ".$pref."booking_date <= ( CURDATE() + INTERVAL 1 DAY ) ) ".$and_suf ; | |
| 1072 | - $sql_where .= $and_pre."( ".$pref."booking_date >= ( CURDATE() - INTERVAL 1 DAY ) ) ".$and_suf ; | |
| 1101 | + $sql_where = $and_pre."( ".$pref."booking_date <= (" . wpbc_sql_date_math_expr_explicit( "+ INTERVAL 1 DAY", 'curdate' ) . ") ) ".$and_suf ; | |
| 1102 | + $sql_where .= $and_pre."( ".$pref."booking_date >= (" . wpbc_sql_date_math_expr_explicit( "- INTERVAL 1 DAY", 'curdate' ) . ") ) ".$and_suf ; | |
| 1073 | 1103 | |
| 1074 | 1104 | } else { // Fixed |
| 1075 | 1105 | |
| 1076 | 1106 | $wh_booking_date = wpbc_sanitize_date( $wh_booking_date ); |
| @@ -1123,10 +1153,10 @@ | ||
| 1123 | 1153 | if ($pref == 'bk.') { $and_pre = ' AND '; $and_suf = ''; } |
| 1124 | 1154 | else { $and_pre = ''; $and_suf = ' AND '; } |
| 1125 | 1155 | |
| 1126 | 1156 | if ($wh_modification_date === '1') { // Today |
| 1127 | - $sql_where = $and_pre."( ".$pref."modification_date <= ( CURDATE() + INTERVAL '23:59:59' HOUR_SECOND ) ) ".$and_suf ; //FixIn: 8.4.7.22 | |
| 1128 | - $sql_where .= $and_pre."( ".$pref."modification_date >= ( CURDATE() - INTERVAL '00:00:01' HOUR_SECOND ) ) ".$and_suf ; //FixIn: 8.4.7.22 | |
| 1157 | + $sql_where = $and_pre."( ".$pref."modification_date <= (" . wpbc_sql_date_math_expr_explicit( "+ INTERVAL '23:59:59' HOUR_SECOND", 'curdate' ) . ") ) ".$and_suf ; // FixIn: 8.4.7.22. | |
| 1158 | + $sql_where .= $and_pre."( ".$pref."modification_date >= (" . wpbc_sql_date_math_expr_explicit( "- INTERVAL '00:00:01' HOUR_SECOND", 'curdate' ) . ") ) ".$and_suf ; // FixIn: 8.4.7.22. | |
| 1129 | 1159 | |
| 1130 | 1160 | } else if ($wh_modification_date === '3') { // All |
| 1131 | 1161 | $sql_where = ''; |
| 1132 | 1162 | |
| @@ -1131,14 +1161,15 @@ | ||
| 1131 | 1161 | $sql_where = ''; |
| 1132 | 1162 | |
| 1133 | 1163 | } else if ($wh_modification_date === '5') { // Prior |
| 1134 | 1164 | $wh_modification_date2 = str_replace('-', '', $wh_modification_date2); |
| 1135 | - $sql_where = $and_pre."( ".$pref."modification_date >= ( CURDATE() - INTERVAL ". $wh_modification_date2 . " DAY ) ) ".$and_suf ; | |
| 1136 | - $sql_where .= $and_pre."( ".$pref."modification_date <= ( CURDATE() + INTERVAL 1 DAY ) ) ".$and_suf ; | |
| 1165 | + $wh_modification_date2 = intval( $wh_modification_date2 ); // FixIn: 10.14.16.1. | |
| 1166 | + $sql_where = $and_pre."( ".$pref."modification_date >= (" . wpbc_sql_date_math_expr_explicit( "- INTERVAL ". $wh_modification_date2 . " DAY", 'curdate' ) . ") ) ".$and_suf ; | |
| 1167 | + $sql_where .= $and_pre."( ".$pref."modification_date <= (" . wpbc_sql_date_math_expr_explicit( "+ INTERVAL 1 DAY", 'curdate' ) . ") ) ".$and_suf ; | |
| 1137 | 1168 | |
| 1138 | 1169 | } else { // Fixed |
| 1139 | 1170 | |
| 1140 | - $wh_modification_date = wpbc_sanitize_date( $wh_modification_date ); //FixIn: 9.4.4.1 | |
| 1171 | + $wh_modification_date = wpbc_sanitize_date( $wh_modification_date ); // FixIn: 9.4.4.1. | |
| 1141 | 1172 | $wh_modification_date2 = wpbc_sanitize_date( $wh_modification_date2 ); |
| 1142 | 1173 | |
| 1143 | 1174 | if ( $wh_modification_date !== '' ) |
| 1144 | 1175 | $sql_where.= $and_pre."( ".$pref."modification_date >= ( '" . $wh_modification_date . "' - INTERVAL '00:00:01' HOUR_SECOND ) ) ".$and_suf; |
| @@ -1186,9 +1217,9 @@ | ||
| 1186 | 1217 | $is_show_lost = true; |
| 1187 | 1218 | |
| 1188 | 1219 | if ( class_exists( 'wpdev_bk_multiuser' ) ) { // MultiUser - Only for super booking admin user |
| 1189 | 1220 | |
| 1190 | - $user_bk_id = ( isset( $_REQUEST['wpbc_ajx_user_id'] ) ) ? intval( $_REQUEST['wpbc_ajx_user_id'] ) : wpbc_get_current_user_id(); | |
| 1221 | + $user_bk_id = ( isset( $_REQUEST['wpbc_ajx_user_id'] ) ) ? intval( $_REQUEST['wpbc_ajx_user_id'] ) : wpbc_get_current_user_id(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing | |
| 1191 | 1222 | |
| 1192 | 1223 | $is_user_super_admin = apply_bk_filter( 'is_user_super_admin', $user_bk_id ); |
| 1193 | 1224 | |
| 1194 | 1225 | if ( ! $is_user_super_admin ) { |
| @@ -1262,9 +1293,10 @@ | ||
| 1262 | 1293 | ) |
| 1263 | 1294 | ) |
| 1264 | 1295 | ) " ; |
| 1265 | 1296 | |
| 1266 | - if ( ( isset($_REQUEST['view_mode']) ) && ( $_REQUEST['view_mode']== 'vm_calendar' ) ) { | |
| 1297 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing | |
| 1298 | + if ( ( isset($_REQUEST['tab']) ) && ( $_REQUEST['tab']== 'vm_calendar' ) ) { | |
| 1267 | 1299 | |
| 1268 | 1300 | // Skip the bookings from the children resources, if we are in the Calendar view mode at the admin panel |
| 1269 | 1301 | |
| 1270 | 1302 | } else { |
| @@ -1419,9 +1451,9 @@ | ||
| 1419 | 1451 | $sql .= " ORDER BY booking_id, type_id, booking_date "; |
| 1420 | 1452 | } else { |
| 1421 | 1453 | $sql .= " ORDER BY booking_id, booking_date "; |
| 1422 | 1454 | } |
| 1423 | - | |
| 1455 | + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 1424 | 1456 | $booking_dates_sql_obj = $wpdb->get_results( $sql ); |
| 1425 | 1457 | } else { |
| 1426 | 1458 | $booking_dates_sql_obj = array(); |
| 1427 | 1459 | } |
| @@ -1527,9 +1559,9 @@ | ||
| 1527 | 1559 | unset( $bookings_obj[ $bc_id ] ); |
| 1528 | 1560 | $bookings_count --; |
| 1529 | 1561 | } |
| 1530 | 1562 | } |
| 1531 | - // Check In | Check out //FixIn: 9.6.3.12 | |
| 1563 | + // Check In | Check out // FixIn: 9.6.3.12. | |
| 1532 | 1564 | if ( $wh_booking_date === '9' ) { |
| 1533 | 1565 | if ( ( $today_mysql_format != $check_in_date ) && ( $today_mysql_format != $check_out_date ) ) { |
| 1534 | 1566 | unset( $bookings_obj[ $bc_id ] ); |
| 1535 | 1567 | $bookings_count --; |
| @@ -1606,9 +1638,9 @@ | ||
| 1606 | 1638 | * ) |
| 1607 | 1639 | * [181] => stdClass Object ( |
| 1608 | 1640 | * .... |
| 1609 | 1641 | */ |
| 1610 | - function wpbc_ajx_include_bookingdates_in_bookings( $bookings_obj, $booking_dates_obj ){ | |
| 1642 | + function wpbc_ajx_include_bookingdates_in_the_bookings( $bookings_obj, $booking_dates_obj ){ | |
| 1611 | 1643 | |
| 1612 | 1644 | $bookings_arr = array(); |
| 1613 | 1645 | foreach ( $bookings_obj as $booking ) { |
| 1614 | 1646 | |
| @@ -1712,16 +1744,378 @@ | ||
| 1712 | 1744 | } |
| 1713 | 1745 | |
| 1714 | 1746 | } // bookings loop: $booking_id => $booking |
| 1715 | 1747 | |
| 1716 | - return $bookings_arr; | |
| 1717 | - } | |
| 1748 | + return $bookings_arr; | |
| 1749 | + } | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + /** | |
| 1753 | + * Build an empty Booking Listing Resource-allocation DTO. | |
| 1754 | + * | |
| 1755 | + * A stable empty shape keeps the browser template data-only and avoids | |
| 1756 | + * edition-specific checks in the presentation layer. | |
| 1757 | + * | |
| 1758 | + * @return array<string,mixed> Empty Resource-allocation DTO. | |
| 1759 | + */ | |
| 1760 | + function wpbc_booking_listing_get_empty_resource_allocation() { | |
| 1761 | + | |
| 1762 | + return array( | |
| 1763 | + 'is_multiple_resources' => false, | |
| 1764 | + 'resource_count' => 0, | |
| 1765 | + 'resource_count_label' => '', | |
| 1766 | + 'date_summary_label' => '', | |
| 1767 | + 'segment_count' => 0, | |
| 1768 | + 'segments' => array(), | |
| 1769 | + ); | |
| 1770 | + } | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + /** | |
| 1774 | + * Return a localized time label for one allocation day. | |
| 1775 | + * | |
| 1776 | + * Duplicate timestamps are expected when a quantity booking reserves | |
| 1777 | + * several Resources. Midnight represents a full day and is omitted. When | |
| 1778 | + * two or more non-midnight values exist, the first and last values describe | |
| 1779 | + * the booked time interval without repeating it for every Resource. | |
| 1780 | + * | |
| 1781 | + * @param array<string,mixed> $allocation_day Normalized day record. | |
| 1782 | + * | |
| 1783 | + * @return string Localized time or time-range label. Empty for full days. | |
| 1784 | + */ | |
| 1785 | + function wpbc_booking_listing_get_allocation_day_time_label( $allocation_day ) { | |
| 1786 | + | |
| 1787 | + if ( empty( $allocation_day['times'] ) || ! is_array( $allocation_day['times'] ) ) { | |
| 1788 | + return ''; | |
| 1789 | + } | |
| 1790 | + | |
| 1791 | + $sql_times = array_values( array_unique( array_filter( array_map( 'strval', $allocation_day['times'] ) ) ) ); | |
| 1792 | + sort( $sql_times, SORT_STRING ); | |
| 1793 | + | |
| 1794 | + $formatted_times = array(); | |
| 1795 | + foreach ( $sql_times as $sql_time ) { | |
| 1796 | + if ( '00:00:00' === $sql_time ) { | |
| 1797 | + continue; | |
| 1798 | + } | |
| 1799 | + | |
| 1800 | + list( , $formatted_time ) = wpbc_get_date_in_correct_format( $allocation_day['date'] . ' ' . $sql_time ); | |
| 1801 | + $formatted_time = trim( $formatted_time ); | |
| 1802 | + if ( '' !== $formatted_time ) { | |
| 1803 | + $formatted_times[] = $formatted_time; | |
| 1804 | + } | |
| 1805 | + } | |
| 1806 | + | |
| 1807 | + $formatted_times = array_values( array_unique( $formatted_times ) ); | |
| 1808 | + if ( empty( $formatted_times ) ) { | |
| 1809 | + return ''; | |
| 1810 | + } | |
| 1811 | + | |
| 1812 | + if ( 1 === count( $formatted_times ) ) { | |
| 1813 | + return $formatted_times[0]; | |
| 1814 | + } | |
| 1815 | + | |
| 1816 | + return $formatted_times[0] . ' – ' . $formatted_times[ count( $formatted_times ) - 1 ]; | |
| 1817 | + } | |
| 1818 | + | |
| 1819 | + | |
| 1820 | + /** | |
| 1821 | + * Format one chronological Resource-allocation period. | |
| 1822 | + * | |
| 1823 | + * Common recurrent times are shown once after the date range. Check-in and | |
| 1824 | + * check-out times that differ between the first and final day stay attached | |
| 1825 | + * to their respective dates. Full-day periods contain dates only. | |
| 1826 | + * | |
| 1827 | + * @param string $start_date First date in Y-m-d format. | |
| 1828 | + * @param string $end_date Final date in Y-m-d format. | |
| 1829 | + * @param array<string,array> $allocation_days Normalized days keyed by Y-m-d. | |
| 1830 | + * | |
| 1831 | + * @return string Localized period label. | |
| 1832 | + */ | |
| 1833 | + function wpbc_booking_listing_format_allocation_period_label( $start_date, $end_date, $allocation_days ) { | |
| 1834 | + | |
| 1835 | + list( $start_date_label ) = wpbc_get_date_in_correct_format( $start_date . ' 00:00:00' ); | |
| 1836 | + list( $end_date_label ) = wpbc_get_date_in_correct_format( $end_date . ' 00:00:00' ); | |
| 1837 | + | |
| 1838 | + $period_days = array(); | |
| 1839 | + foreach ( $allocation_days as $date_key => $allocation_day ) { | |
| 1840 | + if ( $date_key >= $start_date && $date_key <= $end_date ) { | |
| 1841 | + $period_days[ $date_key ] = $allocation_day; | |
| 1842 | + } | |
| 1843 | + } | |
| 1844 | + | |
| 1845 | + $day_time_labels = array(); | |
| 1846 | + foreach ( $period_days as $date_key => $allocation_day ) { | |
| 1847 | + $day_time_labels[ $date_key ] = wpbc_booking_listing_get_allocation_day_time_label( $allocation_day ); | |
| 1848 | + } | |
| 1849 | + | |
| 1850 | + if ( $start_date === $end_date ) { | |
| 1851 | + $time_label = isset( $day_time_labels[ $start_date ] ) ? $day_time_labels[ $start_date ] : ''; | |
| 1852 | + | |
| 1853 | + return '' !== $time_label ? $start_date_label . ', ' . $time_label : $start_date_label; | |
| 1854 | + } | |
| 1855 | + | |
| 1856 | + $non_empty_time_labels = array_values( array_filter( $day_time_labels ) ); | |
| 1857 | + $unique_time_labels = array_values( array_unique( $non_empty_time_labels ) ); | |
| 1858 | + if ( count( $non_empty_time_labels ) === count( $period_days ) && 1 === count( $unique_time_labels ) ) { | |
| 1859 | + return $start_date_label . ' – ' . $end_date_label . ', ' . $unique_time_labels[0]; | |
| 1860 | + } | |
| 1861 | + | |
| 1862 | + $start_time_label = isset( $day_time_labels[ $start_date ] ) ? $day_time_labels[ $start_date ] : ''; | |
| 1863 | + $end_time_label = isset( $day_time_labels[ $end_date ] ) ? $day_time_labels[ $end_date ] : ''; | |
| 1864 | + if ( '' !== $start_time_label ) { | |
| 1865 | + $start_date_label .= ', ' . $start_time_label; | |
| 1866 | + } | |
| 1867 | + if ( '' !== $end_time_label ) { | |
| 1868 | + $end_date_label .= ', ' . $end_time_label; | |
| 1869 | + } | |
| 1870 | + | |
| 1871 | + return $start_date_label . ' – ' . $end_date_label; | |
| 1872 | + } | |
| 1873 | + | |
| 1874 | + | |
| 1875 | + /** | |
| 1876 | + * Resolve authorized Resource presentation records for an allocation set. | |
| 1877 | + * | |
| 1878 | + * Only titles already present in the owner-filtered Booking Listing Resource | |
| 1879 | + * collection are exposed. Missing or deleted Resources receive the existing | |
| 1880 | + * neutral fallback instead of leaking an unavailable title. | |
| 1881 | + * | |
| 1882 | + * @param array<int> $resource_ids Resource IDs in display order. | |
| 1883 | + * @param array<int,array> $booking_resources_arr Owner-filtered Resource records. | |
| 1884 | + * | |
| 1885 | + * @return array<int,array<string,mixed>> JSON-safe Resource presentation records. | |
| 1886 | + */ | |
| 1887 | + function wpbc_booking_listing_get_allocation_resource_records( $resource_ids, $booking_resources_arr ) { | |
| 1888 | + | |
| 1889 | + $resource_records = array(); | |
| 1890 | + foreach ( $resource_ids as $resource_id ) { | |
| 1891 | + $resource_id = absint( $resource_id ); | |
| 1892 | + $resource_title = isset( $booking_resources_arr[ $resource_id ]['title'] ) | |
| 1893 | + ? wp_strip_all_tags( wpbc_lang( $booking_resources_arr[ $resource_id ]['title'] ) ) | |
| 1894 | + : __( 'Resource not exist', 'booking' ); | |
| 1895 | + | |
| 1896 | + $resource_records[] = array( | |
| 1897 | + 'resource_id' => $resource_id, | |
| 1898 | + 'resource_title' => $resource_title, | |
| 1899 | + 'is_missing' => ! isset( $booking_resources_arr[ $resource_id ] ), | |
| 1900 | + ); | |
| 1901 | + } | |
| 1902 | + | |
| 1903 | + return $resource_records; | |
| 1904 | + } | |
| 1905 | + | |
| 1906 | + | |
| 1907 | + /** | |
| 1908 | + * Group normalized allocation days into chronological Resource-set segments. | |
| 1909 | + * | |
| 1910 | + * Consecutive dates are merged only while their complete Resource set stays | |
| 1911 | + * identical. This represents both a booking that moves between Resources and | |
| 1912 | + * a quantity booking that reserves several Resources for the same period. | |
| 1913 | + * | |
| 1914 | + * @param array<string,array> $allocation_days Normalized days keyed by Y-m-d. | |
| 1915 | + * @param array<int,array> $booking_resources_arr Owner-filtered Resource records. | |
| 1916 | + * | |
| 1917 | + * @return array<int,array<string,mixed>> Ordered allocation segments. | |
| 1918 | + */ | |
| 1919 | + function wpbc_booking_listing_group_allocation_days( $allocation_days, $booking_resources_arr ) { | |
| 1920 | + | |
| 1921 | + $segments = array(); | |
| 1922 | + $current_segment = array(); | |
| 1923 | + | |
| 1924 | + foreach ( $allocation_days as $date_key => $allocation_day ) { | |
| 1925 | + $resource_ids = array_values( array_unique( array_map( 'absint', array_keys( $allocation_day['resources'] ) ) ) ); | |
| 1926 | + sort( $resource_ids, SORT_NUMERIC ); | |
| 1927 | + $resource_signature = implode( ',', $resource_ids ); | |
| 1928 | + | |
| 1929 | + $is_same_segment = ! empty( $current_segment ) | |
| 1930 | + && $resource_signature === $current_segment['resource_signature'] | |
| 1931 | + && wpbc_is_next_day( $date_key, $current_segment['end_date'] ); | |
| 1932 | + | |
| 1933 | + if ( ! $is_same_segment ) { | |
| 1934 | + if ( ! empty( $current_segment ) ) { | |
| 1935 | + $current_segment['period_label'] = wpbc_booking_listing_format_allocation_period_label( | |
| 1936 | + $current_segment['start_date'], | |
| 1937 | + $current_segment['end_date'], | |
| 1938 | + $allocation_days | |
| 1939 | + ); | |
| 1940 | + $current_segment['resources'] = wpbc_booking_listing_get_allocation_resource_records( $current_segment['resource_ids'], $booking_resources_arr ); | |
| 1941 | + unset( $current_segment['resource_signature'], $current_segment['resource_ids'] ); | |
| 1942 | + $segments[] = $current_segment; | |
| 1943 | + } | |
| 1944 | + | |
| 1945 | + $current_segment = array( | |
| 1946 | + 'start_date' => $date_key, | |
| 1947 | + 'end_date' => $date_key, | |
| 1948 | + 'day_count' => 1, | |
| 1949 | + 'resource_signature' => $resource_signature, | |
| 1950 | + 'resource_ids' => $resource_ids, | |
| 1951 | + ); | |
| 1952 | + continue; | |
| 1953 | + } | |
| 1954 | + | |
| 1955 | + $current_segment['end_date'] = $date_key; | |
| 1956 | + ++$current_segment['day_count']; | |
| 1957 | + } | |
| 1958 | + | |
| 1959 | + if ( ! empty( $current_segment ) ) { | |
| 1960 | + $current_segment['period_label'] = wpbc_booking_listing_format_allocation_period_label( | |
| 1961 | + $current_segment['start_date'], | |
| 1962 | + $current_segment['end_date'], | |
| 1963 | + $allocation_days | |
| 1964 | + ); | |
| 1965 | + $current_segment['resources'] = wpbc_booking_listing_get_allocation_resource_records( $current_segment['resource_ids'], $booking_resources_arr ); | |
| 1966 | + unset( $current_segment['resource_signature'], $current_segment['resource_ids'] ); | |
| 1967 | + $segments[] = $current_segment; | |
| 1968 | + } | |
| 1969 | + | |
| 1970 | + return $segments; | |
| 1971 | + } | |
| 1972 | + | |
| 1973 | + | |
| 1974 | + /** | |
| 1975 | + * Build compact chronological date periods independently of Resource changes. | |
| 1976 | + * | |
| 1977 | + * This summary is used in the narrow date column. It avoids repeating dates | |
| 1978 | + * for quantity bookings while preserving gaps between non-consecutive dates. | |
| 1979 | + * | |
| 1980 | + * @param array<string,array> $allocation_days Normalized days keyed by Y-m-d. | |
| 1981 | + * | |
| 1982 | + * @return array<int,string> Localized date-period labels. | |
| 1983 | + */ | |
| 1984 | + function wpbc_booking_listing_get_allocation_date_period_labels( $allocation_days ) { | |
| 1985 | + | |
| 1986 | + $period_labels = array(); | |
| 1987 | + $start_date = ''; | |
| 1988 | + $end_date = ''; | |
| 1989 | + | |
| 1990 | + foreach ( array_keys( $allocation_days ) as $date_key ) { | |
| 1991 | + if ( '' === $start_date ) { | |
| 1992 | + $start_date = $date_key; | |
| 1993 | + $end_date = $date_key; | |
| 1994 | + continue; | |
| 1995 | + } | |
| 1996 | + | |
| 1997 | + if ( wpbc_is_next_day( $date_key, $end_date ) ) { | |
| 1998 | + $end_date = $date_key; | |
| 1999 | + continue; | |
| 2000 | + } | |
| 2001 | + | |
| 2002 | + $period_labels[] = wpbc_booking_listing_format_allocation_period_label( $start_date, $end_date, $allocation_days ); | |
| 2003 | + $start_date = $date_key; | |
| 2004 | + $end_date = $date_key; | |
| 2005 | + } | |
| 2006 | + | |
| 2007 | + if ( '' !== $start_date ) { | |
| 2008 | + $period_labels[] = wpbc_booking_listing_format_allocation_period_label( $start_date, $end_date, $allocation_days ); | |
| 2009 | + } | |
| 2010 | + | |
| 2011 | + return $period_labels; | |
| 2012 | + } | |
| 2013 | + | |
| 2014 | + | |
| 2015 | + /** | |
| 2016 | + * Build the Booking Listing Resource-allocation DTO from saved date rows. | |
| 2017 | + * | |
| 2018 | + * Business Large stores the booking's main Resource in `booking.booking_type`. | |
| 2019 | + * A date on that Resource has an empty `bookingdates.type_id`; only dates on | |
| 2020 | + * another Resource contain `type_id`. Normalizing that fallback before | |
| 2021 | + * counting or grouping prevents both missing labels and repeated per-date | |
| 2022 | + * child labels. | |
| 2023 | + * | |
| 2024 | + * @param object $booking Booking with `booking_db`, `dates`, and `child_id` values. | |
| 2025 | + * @param array<int,array> $booking_resources_arr Owner-filtered Resource records. | |
| 2026 | + * | |
| 2027 | + * @return array<string,mixed> JSON-safe Resource-allocation DTO. | |
| 2028 | + */ | |
| 2029 | + function wpbc_booking_listing_build_resource_allocation( $booking, $booking_resources_arr ) { | |
| 2030 | + | |
| 2031 | + $resource_allocation = wpbc_booking_listing_get_empty_resource_allocation(); | |
| 2032 | + if ( | |
| 2033 | + empty( $booking->booking_db->booking_type ) | |
| 2034 | + || empty( $booking->dates ) | |
| 2035 | + || ! is_array( $booking->dates ) | |
| 2036 | + ) { | |
| 2037 | + return $resource_allocation; | |
| 2038 | + } | |
| 2039 | + | |
| 2040 | + $main_resource_id = absint( $booking->booking_db->booking_type ); | |
| 2041 | + $allocation_days = array(); | |
| 2042 | + $all_resource_ids = array(); | |
| 2043 | + | |
| 2044 | + foreach ( $booking->dates as $date_index => $sql_booking_date ) { | |
| 2045 | + $sql_booking_date = is_scalar( $sql_booking_date ) ? trim( (string) $sql_booking_date ) : ''; | |
| 2046 | + if ( ! preg_match( '/^(\d{4})-(\d{2})-(\d{2})(?:\s+(\d{2}):(\d{2}):(\d{2}))?$/', $sql_booking_date, $date_parts ) ) { | |
| 2047 | + continue; | |
| 2048 | + } | |
| 2049 | + | |
| 2050 | + $year = (int) $date_parts[1]; | |
| 2051 | + $month = (int) $date_parts[2]; | |
| 2052 | + $day = (int) $date_parts[3]; | |
| 2053 | + $hour = isset( $date_parts[4] ) ? (int) $date_parts[4] : 0; | |
| 2054 | + $minute = isset( $date_parts[5] ) ? (int) $date_parts[5] : 0; | |
| 2055 | + $second = isset( $date_parts[6] ) ? (int) $date_parts[6] : 0; | |
| 2056 | + if ( | |
| 2057 | + ! checkdate( $month, $day, $year ) | |
| 2058 | + || $hour > 23 | |
| 2059 | + || $minute > 59 | |
| 2060 | + || $second > 59 | |
| 2061 | + ) { | |
| 2062 | + continue; | |
| 2063 | + } | |
| 2064 | + | |
| 2065 | + $date_key = sprintf( '%04d-%02d-%02d', $year, $month, $day ); | |
| 2066 | + $sql_time = isset( $date_parts[4], $date_parts[5], $date_parts[6] ) | |
| 2067 | + ? sprintf( '%02d:%02d:%02d', $hour, $minute, $second ) | |
| 2068 | + : '00:00:00'; | |
| 2069 | + $date_resource_id = isset( $booking->child_id[ $date_index ] ) && ! empty( $booking->child_id[ $date_index ] ) | |
| 2070 | + ? absint( $booking->child_id[ $date_index ] ) | |
| 2071 | + : $main_resource_id; | |
| 2072 | + | |
| 2073 | + if ( empty( $date_resource_id ) ) { | |
| 2074 | + continue; | |
| 2075 | + } | |
| 2076 | + | |
| 2077 | + if ( ! isset( $allocation_days[ $date_key ] ) ) { | |
| 2078 | + $allocation_days[ $date_key ] = array( | |
| 2079 | + 'date' => $date_key, | |
| 2080 | + 'times' => array(), | |
| 2081 | + 'resources' => array(), | |
| 2082 | + ); | |
| 2083 | + } | |
| 2084 | + | |
| 2085 | + $allocation_days[ $date_key ]['times'][] = $sql_time; | |
| 2086 | + $allocation_days[ $date_key ]['resources'][ $date_resource_id ] = true; | |
| 2087 | + $all_resource_ids[ $date_resource_id ] = true; | |
| 2088 | + } | |
| 2089 | + | |
| 2090 | + if ( empty( $allocation_days ) ) { | |
| 2091 | + return $resource_allocation; | |
| 2092 | + } | |
| 2093 | + | |
| 2094 | + ksort( $allocation_days, SORT_STRING ); | |
| 2095 | + $resource_count = count( $all_resource_ids ); | |
| 2096 | + $period_labels = wpbc_booking_listing_get_allocation_date_period_labels( $allocation_days ); | |
| 2097 | + $segments = wpbc_booking_listing_group_allocation_days( $allocation_days, $booking_resources_arr ); | |
| 2098 | + | |
| 2099 | + $resource_allocation['is_multiple_resources'] = ( $resource_count > 1 ); | |
| 2100 | + $resource_allocation['resource_count'] = $resource_count; | |
| 2101 | + $resource_allocation['resource_count_label'] = sprintf( | |
| 2102 | + /* translators: %d: Number of booking Resources reserved by one booking. */ | |
| 2103 | + _n( '%d booking resource', '%d booking resources', $resource_count, 'booking' ), | |
| 2104 | + $resource_count | |
| 2105 | + ); | |
| 2106 | + $resource_allocation['date_summary_label'] = implode( ', ', $period_labels ); | |
| 2107 | + $resource_allocation['segment_count'] = count( $segments ); | |
| 2108 | + $resource_allocation['segments'] = $segments; | |
| 2109 | + | |
| 2110 | + return $resource_allocation; | |
| 2111 | + } | |
| 2112 | + | |
| 2113 | + | |
| 2114 | + function wpbc_ajx_parse_bookings( $bookings_arr, $resources_arr ) { | |
| 1718 | 2115 | |
| 2116 | + $user_id = ( isset( $_REQUEST['wpbc_ajx_user_id'] ) ) ? intval( $_REQUEST['wpbc_ajx_user_id'] ) : wpbc_get_current_user_id(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing | |
| 1719 | 2117 | |
| 1720 | - function wpbc_ajx_parse_bookings( $bookings_arr, $resources_arr ) { | |
| 1721 | - | |
| 1722 | - $user_id = ( isset( $_REQUEST['wpbc_ajx_user_id'] ) ) ? intval( $_REQUEST['wpbc_ajx_user_id'] ) : wpbc_get_current_user_id(); | |
| 1723 | - | |
| 1724 | 2118 | foreach ( $bookings_arr as $booking_id => $booking ) { |
| 1725 | 2119 | |
| 1726 | 2120 | // Booking resource ------------------------------------------------------------------------------------ |
| 1727 | 2121 | $resource_id = ( isset( $booking->booking_db->booking_type ) ) ? $booking->booking_db->booking_type : '1'; |
| @@ -1735,8 +2129,28 @@ | ||
| 1735 | 2129 | if ( class_exists( 'wpdev_bk_multiuser' ) ) { |
| 1736 | 2130 | $resource_owner_user = ( isset( $resources_arr[ $resource_id ] ) ) ? $resources_arr[ $resource_id ]['users'] : $user_id; |
| 1737 | 2131 | } |
| 1738 | 2132 | |
| 2133 | + $resource_title_listing = $resource_title; | |
| 2134 | + $resource_id_listing = $resource_id; | |
| 2135 | + $child_resource_id_arr = array(); | |
| 2136 | + if ( ( class_exists( 'wpdev_bk_biz_l' ) ) && ( ! empty( $booking->child_id ) ) && ( is_array( $booking->child_id ) ) ) { | |
| 2137 | + foreach ( $booking->child_id as $child_resource_id ) { | |
| 2138 | + if ( ! empty( $child_resource_id ) ) { | |
| 2139 | + $child_resource_id_arr[] = (int) $child_resource_id; | |
| 2140 | + } | |
| 2141 | + } | |
| 2142 | + $child_resource_id_arr = array_values( array_unique( $child_resource_id_arr ) ); | |
| 2143 | + | |
| 2144 | + if ( ( 1 === count( $child_resource_id_arr ) ) && ( isset( $resources_arr[ $child_resource_id_arr[0] ] ) ) ) { | |
| 2145 | + $resource_id_listing = $child_resource_id_arr[0]; | |
| 2146 | + $resource_title_listing = wpbc_lang( $resources_arr[ $child_resource_id_arr[0] ]['title'] ); | |
| 2147 | + } | |
| 2148 | + } | |
| 2149 | + $resource_allocation = class_exists( 'wpdev_bk_biz_l' ) | |
| 2150 | + ? wpbc_booking_listing_build_resource_allocation( $booking, $resources_arr ) | |
| 2151 | + : wpbc_booking_listing_get_empty_resource_allocation(); | |
| 2152 | + | |
| 1739 | 2153 | // Parse form fields only from $booking->booking_db->form ------------------------------------------ |
| 1740 | 2154 | $booking_data_arr = wpbc_parse_booking_data_fields( $booking->booking_db->form, |
| 1741 | 2155 | array( 'resource_id' => $resource_id ) |
| 1742 | 2156 | ); |
| @@ -1753,9 +2167,9 @@ | ||
| 1753 | 2167 | array_merge( |
| 1754 | 2168 | get_object_vars( $booking->booking_db ), |
| 1755 | 2169 | array( 'id' => $booking->id, |
| 1756 | 2170 | 'approved' => $booking->approved, |
| 1757 | - 'wpbc_custom_booking_form' => '' //FixIn: 9.4.3.12 //FixIn: 9.4.4.9 | |
| 2171 | + 'wpbc_custom_booking_form' => '' //FixIn: 9.4.3.12 // FixIn: 9.4.4.9. | |
| 1758 | 2172 | ) |
| 1759 | 2173 | ) |
| 1760 | 2174 | , array( |
| 1761 | 2175 | 'booking_id', |
| @@ -1774,9 +2188,9 @@ | ||
| 1774 | 2188 | 'pay_request', |
| 1775 | 2189 | 'id', |
| 1776 | 2190 | 'approved', |
| 1777 | 2191 | 'booking_options', |
| 1778 | - 'wpbc_custom_booking_form', //FixIn: 9.4.3.12 | |
| 2192 | + 'wpbc_custom_booking_form', // FixIn: 9.4.3.12. | |
| 1779 | 2193 | ) |
| 1780 | 2194 | ); |
| 1781 | 2195 | |
| 1782 | 2196 | // Set dates and times in correct format --------------------------------------------------------------- |
| @@ -1782,10 +2196,14 @@ | ||
| 1782 | 2196 | // Set dates and times in correct format --------------------------------------------------------------- |
| 1783 | 2197 | $booking_data_arr = wpbc_parse_booking_data_fields_formats( $booking_data_arr ); |
| 1784 | 2198 | |
| 1785 | 2199 | // Get SHORT / WIDE Dates showing data ----------------------------------------------------------------- |
| 1786 | - $short_dates_content = wpbc_get_formated_dates__short( $booking->short_dates, (boolean) $booking->approved, $booking->short_dates_child_id, $resources_arr ); | |
| 1787 | - $wide_dates_content = wpbc_get_formated_dates__wide( $booking->dates, (boolean) $booking->approved, $booking->child_id, $resources_arr ); | |
| 2200 | + $dates_attr = array( | |
| 2201 | + 'date_html_tag' => 'span', | |
| 2202 | + 'show_child_resource_in_dates' => false, | |
| 2203 | + ); | |
| 2204 | + $short_dates_content = wpbc_get_formated_dates__short( $booking->short_dates, (bool) $booking->approved, $booking->short_dates_child_id, $resources_arr, $dates_attr ); | |
| 2205 | + $wide_dates_content = wpbc_get_formated_dates__wide( $booking->dates, (bool) $booking->approved, $booking->child_id, $resources_arr, $dates_attr ); | |
| 1788 | 2206 | |
| 1789 | 2207 | //------------------------------------------------------------------------------------------------------ |
| 1790 | 2208 | // Payment Status |
| 1791 | 2209 | //------------------------------------------------------------------------------------------------------ |
| @@ -1819,13 +2237,13 @@ | ||
| 1819 | 2237 | $booking_data_arr['pay_print_status'] = $current_payment_status_title; |
| 1820 | 2238 | } |
| 1821 | 2239 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 1822 | 2240 | |
| 1823 | - if ( $booking_data_arr['pay_print_status'] == 'Completed' ) { //FixIn: 8.4.7.11 | |
| 2241 | + if ( $booking_data_arr['pay_print_status'] == 'Completed' ) { // FixIn: 8.4.7.11. | |
| 1824 | 2242 | $booking_data_arr['pay_print_status'] = __( 'Completed', 'booking' ); |
| 1825 | 2243 | } |
| 1826 | - $real_payment_css = empty( $booking_data_arr['pay_status'] ) ? $current_payment_status_title : $booking_data_arr['pay_status']; //FixIn: 8.7.7.13 | |
| 1827 | - $css_payment_label = 'wpbc_label_payment_status_' . wpbc_check_payment_status( $real_payment_css ); // 'success' | 'pending' | 'unknown' | 'error' //FixIn: 8.7.7.13 | |
| 2244 | + $real_payment_css = empty( $booking_data_arr['pay_status'] ) ? $current_payment_status_title : $booking_data_arr['pay_status']; // FixIn: 8.7.7.13. | |
| 2245 | + $css_payment_label = 'wpbc_label_payment_status_' . wpbc_check_payment_status( $real_payment_css ); // 'success' | 'pending' | 'unknown' | 'error' // FixIn: 8.7.7.13. | |
| 1828 | 2246 | |
| 1829 | 2247 | if ( $booking_data_arr['is_paid'] ) { |
| 1830 | 2248 | $css_payment_label .= ' wpbc_label_payment_status_success'; |
| 1831 | 2249 | } |
| @@ -1854,8 +2272,10 @@ | ||
| 1854 | 2272 | // Add some fields to [ 'parsed_fields' ] |
| 1855 | 2273 | //------------------------------------------------------------------------------------------------------ |
| 1856 | 2274 | $booking_data_arr['resource_title'] = $resource_title; |
| 1857 | 2275 | $booking_data_arr['resource_id'] = $resource_id; |
| 2276 | + $booking_data_arr['resource_title_listing'] = $resource_title_listing; | |
| 2277 | + $booking_data_arr['resource_id_listing'] = $resource_id_listing; | |
| 1858 | 2278 | $booking_data_arr['resource_owner_user'] = $resource_owner_user; |
| 1859 | 2279 | //$booking_data_arr['short_dates_content'] = $short_dates_content; |
| 1860 | 2280 | //$booking_data_arr['wide_dates_content'] = $wide_dates_content; |
| 1861 | 2281 | |
| @@ -1862,10 +2282,15 @@ | ||
| 1862 | 2282 | //------------------------------------------------------------------------------------------------------ |
| 1863 | 2283 | // Form Show - "Content of booking fields data" form |
| 1864 | 2284 | //------------------------------------------------------------------------------------------------------ |
| 1865 | 2285 | |
| 1866 | - $custom_booking_form_name = ( ! empty( $booking_data_arr['wpbc_custom_booking_form'] ) ) ? $booking_data_arr['wpbc_custom_booking_form'] : ''; //FixIn: 9.4.3.12 | |
| 1867 | - $form_show_template = wpbc_get_content_booking_form_show( $resource_id , $custom_booking_form_name ); // <strong>First Name</strong>:<span class="fieldvalue">[name]</span> ... | |
| 2286 | + $custom_booking_form_name = ( ! empty( $booking_data_arr['wpbc_custom_booking_form'] ) ) ? $booking_data_arr['wpbc_custom_booking_form'] : ''; // FixIn: 9.4.3.12. | |
| 2287 | + $booking_data_arr['admin_edit_url'] = wpbc_get_booking_admin_edit_url( | |
| 2288 | + $resource_id, | |
| 2289 | + isset( $booking_data_arr['hash'] ) ? $booking_data_arr['hash'] : '', | |
| 2290 | + $custom_booking_form_name | |
| 2291 | + ); | |
| 2292 | + $form_show_template = wpbc_get_content_booking_form_show( $resource_id , $custom_booking_form_name ); // <strong>First Name</strong>:<span class="fieldvalue">[name]</span> ... | |
| 1868 | 2293 | $parsed_form_show = wpbc_get_parsed_content_booking_form_show( $booking_data_arr, $form_show_template ); // <strong>First Name</strong>:<span class="fieldvalue">John</span> ... |
| 1869 | 2294 | |
| 1870 | 2295 | //------------------------------------------------------------------------------------------------------ |
| 1871 | 2296 | // Google Calendar link |
| @@ -1871,20 +2296,36 @@ | ||
| 1871 | 2296 | // Google Calendar link |
| 1872 | 2297 | //------------------------------------------------------------------------------------------------------ |
| 1873 | 2298 | $booking_data_arr['google_calendar_link'] = wpbc_booking_do_action__get_google_calendar_link( array( |
| 1874 | 2299 | 'form_data' => $booking_data_arr, |
| 1875 | - 'form_show' => $parsed_form_show, //strip_tags( $parsed_form_show ), | |
| 2300 | + 'form_show' => $parsed_form_show, //wp_strip_all_tags( $parsed_form_show ), | |
| 1876 | 2301 | 'dates_short' => $booking->short_dates |
| 1877 | 2302 | ) ); |
| 1878 | - | |
| 2303 | + $booking_data_arr['visitorbookingpayurl'] = ( class_exists( 'wpdev_bk_biz_s' ) ) | |
| 2304 | + ? apply_bk_filter( 'wpdev_booking_set_booking_edit_link_at_email', '[visitorbookingpayurl]', $booking_id ) | |
| 2305 | + : ''; | |
| 1879 | 2306 | // ===================================================================================================== |
| 1880 | - $bookings_arr[ $booking_id ]->parsed_fields = $booking_data_arr; | |
| 2307 | + $booking_data_arr = apply_filters( 'wpbc_booking_listing_parsed_fields', $booking_data_arr, $booking_id, $booking ); | |
| 2308 | + $bookings_arr[ $booking_id ]->parsed_fields = $booking_data_arr; | |
| 2309 | + $bookings_arr[ $booking_id ]->resource_allocation = $resource_allocation; | |
| 1881 | 2310 | |
| 1882 | 2311 | |
| 1883 | 2312 | // ===================================================================================================== |
| 1884 | 2313 | $bookings_arr[ $booking_id ]->templates = array( |
| 1885 | 2314 | 'form_show' => $parsed_form_show, |
| 1886 | - 'form_show_nohtml' => strip_tags( $parsed_form_show ), | |
| 2315 | + 'form_show_simple' => wp_kses( trim( stripslashes( $parsed_form_show ) ), | |
| 2316 | + // array_merge( | |
| 2317 | + array( | |
| 2318 | + 'span' => array( 'style'=>true , 'class'=>true , 'id'=>true ), | |
| 2319 | + 'b' => array( 'style'=>true , 'class'=>true , 'id'=>true ), | |
| 2320 | + 'strong' => array( 'style'=>true , 'class'=>true , 'id'=>true ), | |
| 2321 | + 'i' => array( 'style'=>true , 'class'=>true , 'id'=>true ), | |
| 2322 | + 'class' => array(), | |
| 2323 | + 'style' => array() | |
| 2324 | + ) | |
| 2325 | + // , wp_kses_allowed_html( 'post' ) ) | |
| 2326 | + ), | |
| 2327 | + 'form_show_nohtml' => wp_strip_all_tags( $parsed_form_show ), | |
| 1887 | 2328 | 'short_dates_content' => $short_dates_content, |
| 1888 | 2329 | 'wide_dates_content' => $wide_dates_content, |
| 1889 | 2330 | 'payment_label_template' => $payment_label_template |
| 1890 | 2331 | ); |
| @@ -1893,45 +2334,96 @@ | ||
| 1893 | 2334 | return $bookings_arr; |
| 1894 | 2335 | } |
| 1895 | 2336 | |
| 1896 | 2337 | |
| 2338 | + //TODO: Refactor this function to make this simpler, for prevent of issues in future. | |
| 1897 | 2339 | /** |
| 1898 | 2340 | * Get SHORT Dates showing data |
| 1899 | 2341 | * |
| 1900 | - * @param array $short_dates_arr - Array of dates | |
| 1901 | - * @param bool $is_approved - is dates approved or not | |
| 1902 | - * @param type $dates_type_id_arr | |
| 1903 | - * @param type $booking_resources_arr | |
| 2342 | + * @param array $short_dates_arr - Array of dates. | |
| 2343 | + * @param bool $is_approved - true or false | |
| 2344 | + * @param $dates_type_id_arr | |
| 2345 | + * @param $booking_resources_arr | |
| 2346 | + * @param array $attr - [ 'date_html_tag' => 'a' ] . | |
| 1904 | 2347 | * |
| 1905 | 2348 | * @return string |
| 1906 | 2349 | */ |
| 1907 | - function wpbc_get_formated_dates__short( $short_dates_arr, $is_approved = false, $dates_type_id_arr = array() , $booking_resources_arr = array() ){ | |
| 2350 | + function wpbc_get_formated_dates__short( $short_dates_arr, $is_approved = false, $dates_type_id_arr = array(), $booking_resources_arr = array(), $attr = array() ) { | |
| 1908 | 2351 | |
| 1909 | - $css_class_approved = ( $is_approved ) ? 'approved' : ''; | |
| 1910 | - $short_dates_content = ''; | |
| 1911 | - $date_number = 0; | |
| 2352 | + $defaults = array( | |
| 2353 | + 'date_html_tag' => 'a', | |
| 2354 | + 'show_child_resource_in_dates' => true, | |
| 2355 | + ); | |
| 2356 | + $params = wp_parse_args( $attr, $defaults ); | |
| 1912 | 2357 | |
| 1913 | - foreach ( $short_dates_arr as $dt ) { | |
| 2358 | + $css_class_approved = ( $is_approved ) ? 'approved' : ''; | |
| 2359 | + $short_dates_content = ''; | |
| 2360 | + $short_dates_content_arr = array(); | |
| 2361 | + $date_number = 0; | |
| 2362 | + $previous_formatted_date = ''; | |
| 2363 | + $previous_short_dates_content_sup; | |
| 2364 | + $previous_sql_date = ''; | |
| 2365 | + $previous_short_date_item = ''; | |
| 2366 | + foreach ( $short_dates_arr as $dt ) { | |
| 1914 | 2367 | |
| 1915 | - if ( $dt == '-' ) { | |
| 2368 | + if ( '-' === $dt ) { | |
| 2369 | + $short_dates_content_arr[] = '<span class="date_tire"> - </span>'; | |
| 2370 | + } elseif ( ',' === $dt ) { | |
| 2371 | + $short_dates_content_arr[] = '<span class="date_tire date_comma">, </span>'; | |
| 2372 | + } else { | |
| 2373 | + | |
| 2374 | + // Separate recurrent time slots: previous end (...02) followed by the next start (...01). | |
| 2375 | + $is_next_time_slot = ( | |
| 2376 | + ( ! empty( $previous_sql_date ) ) | |
| 2377 | + && ( '02' === substr( trim( $previous_sql_date ), -2 ) ) | |
| 2378 | + && ( '01' === substr( trim( $dt ), -2 ) ) | |
| 2379 | + ); | |
| 2380 | + if ( $is_next_time_slot && ( ',' !== $previous_short_date_item ) ) { | |
| 2381 | + if ( '-' === $previous_short_date_item ) { | |
| 2382 | + array_pop( $short_dates_content_arr ); | |
| 2383 | + } | |
| 2384 | + $short_dates_content_arr[] = '<span class="date_tire date_comma">, </span>'; // FixIn: 11.4.2. | |
| 2385 | + } | |
| 2386 | + | |
| 2387 | + list( $formatted_date, $formatted_time ) = wpbc_get_date_in_correct_format( $dt ); | |
| 1916 | 2388 | |
| 1917 | - $short_dates_content .= '<span class="date_tire"> - </span>'; | |
| 2389 | + $short_dates_content = ''; | |
| 2390 | + $short_dates_content_sup = ''; // Times and booking resources. | |
| 1918 | 2391 | |
| 1919 | - } elseif ( $dt == ',' ) { | |
| 2392 | + if ( 'a' === $params['date_html_tag'] ) { | |
| 2393 | + $short_dates_content .= '<a href="javascript:void(0)" onclick="javascript:wpbc_ajx_click_on_dates_toggle(this);" '; | |
| 2394 | + } else { | |
| 2395 | + $short_dates_content .= '<' . $params['date_html_tag']; | |
| 2396 | + } | |
| 2397 | + $short_dates_content .= ' class="wpbc_label wpbc_label_booking_dates ' . $css_class_approved . '">'; | |
| 1920 | 2398 | |
| 1921 | - $short_dates_content .= '<span class="date_tire">, </span>'; | |
| 2399 | + $short_dates_content .= '<span>'; | |
| 1922 | 2400 | |
| 1923 | - } else { | |
| 2401 | + if ( $previous_formatted_date !== $formatted_date ) { | |
| 2402 | + $short_dates_content .= $formatted_date; | |
| 2403 | + $short_dates_content_sup .= '<sup class="field-booking-time">' . $formatted_time . '</sup>'; | |
| 2404 | + } else { | |
| 2405 | + // same date (probaly it is one date) ! | |
| 2406 | + if ( count( $short_dates_content_arr ) > 0 ) { | |
| 2407 | + // Unset tire: '-'. | |
| 2408 | + array_pop( $short_dates_content_arr ); | |
| 2409 | + if ( ! empty( wp_strip_all_tags( $previous_short_dates_content_sup ) ) ) { | |
| 2410 | + $tag_closed_span_and_a = array_pop( $short_dates_content_arr ); | |
| 2411 | + array_pop( $short_dates_content_arr ); // Unset time_sup. | |
| 2412 | + $short_dates_content_arr[] = $tag_closed_span_and_a; // FixIn: 11.4.2. | |
| 2413 | + } | |
| 2414 | + $short_dates_content_sup .= '<sup class="field-booking-time"> ' | |
| 2415 | + . trim( wp_strip_all_tags( $previous_short_dates_content_sup ) ) | |
| 2416 | + . ' - ' | |
| 2417 | + . trim( $formatted_time ) | |
| 2418 | + . '</sup>'; // FixIn: 11.4.2. | |
| 2419 | + } | |
| 2420 | + } | |
| 1924 | 2421 | |
| 1925 | - list( $formatted_date, $formatted_time ) = wpbc_get_date_in_correct_format( $dt ); | |
| 1926 | - | |
| 1927 | - $short_dates_content .= '<a href="javascript:void(0)" onclick="javascript:wpbc_ajx_click_on_dates_toggle(this);" class="wpbc_label wpbc_label_booking_dates ' . $css_class_approved . '"><span>'; | |
| 1928 | - $short_dates_content .= $formatted_date; | |
| 1929 | - $short_dates_content .= '<sup class="field-booking-time">' . $formatted_time . '</sup>'; | |
| 1930 | - | |
| 1931 | - // BL | |
| 2422 | + // BL. | |
| 1932 | 2423 | if ( |
| 1933 | 2424 | ( class_exists( 'wpdev_bk_biz_l' ) ) |
| 2425 | + && ( $params['show_child_resource_in_dates'] ) | |
| 1934 | 2426 | && ( ! empty( $dates_type_id_arr[ $date_number ] ) ) |
| 1935 | 2427 | && ( isset( $booking_resources_arr[ $dates_type_id_arr[ $date_number ] ] ) ) |
| 1936 | 2428 | ){ |
| 1937 | 2429 | |
| @@ -1943,16 +2435,27 @@ | ||
| 1943 | 2435 | if ( strlen( $resource_title ) > 19 ) { |
| 1944 | 2436 | $resource_title = substr( $resource_title, 0, 13 ) . '...' . substr( $resource_title, - 3 ); |
| 1945 | 2437 | } |
| 1946 | 2438 | |
| 1947 | - $short_dates_content .= '<sup class="field-booking-time date_from_dif_type"> ' . $resource_title . '</sup>'; | |
| 2439 | + $short_dates_content_sup .= '<sup class="field-booking-time date_from_dif_type"> ' . $resource_title . '</sup>'; | |
| 1948 | 2440 | } |
| 1949 | 2441 | |
| 1950 | - $short_dates_content .= '</span></a>'; | |
| 1951 | - } | |
| 1952 | - $date_number++; | |
| 2442 | + $short_dates_content_arr[] = $short_dates_content; | |
| 2443 | + $short_dates_content_arr[] = $short_dates_content_sup; | |
| 2444 | + $short_dates_content_arr[] = '</span></' . $params['date_html_tag'] . '>'; | |
| 2445 | + | |
| 2446 | + | |
| 2447 | + | |
| 2448 | + $previous_short_dates_content_sup = $short_dates_content_sup; | |
| 2449 | + $previous_formatted_date = $formatted_date; | |
| 2450 | + $previous_sql_date = $dt; | |
| 2451 | + } | |
| 2452 | + $previous_short_date_item = $dt; | |
| 2453 | + $date_number++; | |
| 1953 | 2454 | } |
| 1954 | 2455 | |
| 2456 | + $short_dates_content = implode( '', $short_dates_content_arr ); | |
| 2457 | + | |
| 1955 | 2458 | return $short_dates_content; |
| 1956 | 2459 | } |
| 1957 | 2460 | |
| 1958 | 2461 | |
| @@ -1965,10 +2468,16 @@ | ||
| 1965 | 2468 | * @param type $booking_resources_arr - array of booking resources objects |
| 1966 | 2469 | * |
| 1967 | 2470 | * @return string |
| 1968 | 2471 | */ |
| 1969 | - function wpbc_get_formated_dates__wide( $dates_arr, $is_approved = false, $dates_type_id_arr = array(), $booking_resources_arr = array() ){ | |
| 2472 | + function wpbc_get_formated_dates__wide( $dates_arr, $is_approved = false, $dates_type_id_arr = array(), $booking_resources_arr = array(), $attr = array() ) { | |
| 1970 | 2473 | |
| 2474 | + $defaults = array( | |
| 2475 | + 'date_html_tag' => 'a', | |
| 2476 | + 'show_child_resource_in_dates' => true, | |
| 2477 | + ); | |
| 2478 | + $params = wp_parse_args( $attr, $defaults ); | |
| 2479 | + | |
| 1971 | 2480 | $wide_dates_arr = array(); |
| 1972 | 2481 | |
| 1973 | 2482 | $css_class_approved = ( $is_approved ) ? 'approved' : ''; |
| 1974 | 2483 | |
| @@ -1975,9 +2484,17 @@ | ||
| 1975 | 2484 | foreach ( $dates_arr as $date_number => $sql_booking_date ) { |
| 1976 | 2485 | |
| 1977 | 2486 | list( $formatted_date, $formatted_time ) = wpbc_get_date_in_correct_format( $sql_booking_date ); |
| 1978 | 2487 | |
| 1979 | - $wide_date = '<a href="javascript:void(0)" onclick="javascript:wpbc_ajx_click_on_dates_toggle(this);" class="wpbc_label wpbc_label_booking_dates ' . $css_class_approved . '"><span>'; | |
| 2488 | + $wide_date = ''; | |
| 2489 | + if ( 'a' === $params['date_html_tag'] ) { | |
| 2490 | + $wide_date .= '<a href="javascript:void(0)" onclick="javascript:wpbc_ajx_click_on_dates_toggle(this);" '; | |
| 2491 | + } else { | |
| 2492 | + $wide_date .= '<' . $params['date_html_tag']; | |
| 2493 | + } | |
| 2494 | + $wide_date .= ' class="wpbc_label wpbc_label_booking_dates ' . $css_class_approved . '">'; | |
| 2495 | + $wide_date .= '<span>'; | |
| 2496 | + | |
| 1980 | 2497 | $wide_date .= $formatted_date; |
| 1981 | 2498 | $wide_date .= '<sup class="field-booking-time">' . $formatted_time . '</sup>'; |
| 1982 | 2499 | |
| 1983 | 2500 | // BL |
| @@ -1982,8 +2499,9 @@ | ||
| 1982 | 2499 | |
| 1983 | 2500 | // BL |
| 1984 | 2501 | if ( |
| 1985 | 2502 | ( class_exists( 'wpdev_bk_biz_l' ) ) |
| 2503 | + && ( $params['show_child_resource_in_dates'] ) | |
| 1986 | 2504 | && ( '' != $dates_type_id_arr[ $date_number ] ) |
| 1987 | 2505 | && ( isset( $booking_resources_arr[ $dates_type_id_arr[ $date_number ] ] ) ) |
| 1988 | 2506 | ){ |
| 1989 | 2507 | $resource_title = ( isset( $booking_resources_arr[ $dates_type_id_arr[ $date_number ] ] ) ) |
| @@ -1996,14 +2514,14 @@ | ||
| 1996 | 2514 | } |
| 1997 | 2515 | $wide_date .= '<sup class="field-booking-time date_from_dif_type"> ' . $resource_title . '</sup>'; |
| 1998 | 2516 | } |
| 1999 | 2517 | |
| 2000 | - $wide_date .= '</span></a>'; | |
| 2518 | + $wide_date .= '</span></' . $params['date_html_tag'] . '>'; | |
| 2001 | 2519 | |
| 2002 | 2520 | $wide_dates_arr[] = $wide_date; |
| 2003 | 2521 | } |
| 2004 | 2522 | |
| 2005 | - $wide_dates_content = implode( '<span class="date_tire">, </span>' , $wide_dates_arr ); | |
| 2523 | + $wide_dates_content = implode( '<span class="date_tire date_comma">, </span>' , $wide_dates_arr ); | |
| 2006 | 2524 | |
| 2007 | 2525 | return $wide_dates_content; |
| 2008 | 2526 | } |
| 2009 | 2527 | |
| @@ -2116,9 +2634,9 @@ | ||
| 2116 | 2634 | [cost_hint] => &#36;95 |
| 2117 | 2635 | [rangetime] => 10:00 AM - 12:00 PM |
| 2118 | 2636 | [name] => test |
| 2119 | 2637 | [email] => [email protected] |
| 2120 | - ... | |
| 2638 | + ... | |
| 2121 | 2639 | ) |
| 2122 | 2640 | |
| 2123 | 2641 | * @param array $booking_system_arr array of system fields from DB |
| 2124 | 2642 | Array ( [booking_id] => 188 |
| @@ -2129,9 +2647,9 @@ | ||
| 2129 | 2647 | [pay_request] => 0 |
| 2130 | 2648 | [id] => 188 |
| 2131 | 2649 | [approved] => 0 |
| 2132 | 2650 | ) |
| 2133 | - | |
| 2651 | + | |
| 2134 | 2652 | * @param array $system_keys_arr system fields keys that need to be added, like this: |
| 2135 | 2653 | Array ( booking_id, trash, sync_gid, is_new, status |
| 2136 | 2654 | , sort_date, modification_date, hash, booking_type |
| 2137 | 2655 | , remark, cost, pay_status, pay_request, id, approved ) |
| @@ -2174,14 +2692,14 @@ | ||
| 2174 | 2692 | foreach ( $data_arr as $key => $value ) { |
| 2175 | 2693 | |
| 2176 | 2694 | if ( 'rangetime' == $key ) { |
| 2177 | 2695 | $data_arr[$key] = wpbc_time_slot_in_format( $value ); |
| 2178 | - $data_arr[ $key . '_in_24_hour' ] = $value; //FixIn: 10.0.0.52 | |
| 2696 | + $data_arr[ $key . '_in_24_hour' ] = $value; // FixIn: 10.0.0.52. | |
| 2179 | 2697 | } |
| 2180 | 2698 | |
| 2181 | 2699 | if ( in_array( $key, array( 'starttime', 'endtime' ) ) ) { |
| 2182 | 2700 | $data_arr[$key] = wpbc_time_in_format( $value ); |
| 2183 | - $data_arr[ $key . '_in_24_hour' ] = $value; //FixIn: 10.0.0.52 | |
| 2701 | + $data_arr[ $key . '_in_24_hour' ] = $value; // FixIn: 10.0.0.52. | |
| 2184 | 2702 | } |
| 2185 | 2703 | |
| 2186 | 2704 | if ( in_array( $key, array( 'modification_date', 'creation_date' ) ) ) { |
| 2187 | 2705 | |
| @@ -2191,12 +2709,12 @@ | ||
| 2191 | 2709 | // This date $values in GMT date/Time format. So we need to switch to WordPress locale with TIME sum of actual GMT date/time value + shift of timezone from WordPress. |
| 2192 | 2710 | $is_add_wp_timezone = true; |
| 2193 | 2711 | $its_for_default_datetime_format = ''; |
| 2194 | 2712 | $data_arr[ $key ] = wpbc_datetime_localized( $value, $its_for_default_datetime_format, $is_add_wp_timezone ); |
| 2195 | - $data_arr[ $key . '_in_24_hour' ] = $value; //FixIn: 10.0.0.52 | |
| 2713 | + $data_arr[ $key . '_in_24_hour' ] = $value; // FixIn: 10.0.0.52. | |
| 2196 | 2714 | } |
| 2197 | 2715 | |
| 2198 | - if ( ( 'hash' === $key ) && ( empty( $value ) ) ) { //FixIn: 9.2.3.4 //FixIn: 9.4.3.10 | |
| 2716 | + if ( ( 'hash' === $key ) && ( empty( $value ) ) ) { //FixIn: 9.2.3.4 // FixIn: 9.4.3.10. | |
| 2199 | 2717 | // Update booking Hash if it was empty |
| 2200 | 2718 | wpbc_hash__update_booking_hash( $data_arr['id'], $data_arr['booking_type'] ); |
| 2201 | 2719 | // Get new booking hash |
| 2202 | 2720 | $hash__arr = wpbc_hash__get_booking_hash__resource_id( $data_arr['id'] ); |
| @@ -2210,63 +2728,124 @@ | ||
| 2210 | 2728 | |
| 2211 | 2729 | |
| 2212 | 2730 | /** |
| 2213 | 2731 | * Get pure "Content of booking fields data" with shortcodes inside. |
| 2214 | - * it can depend on specific booking resource in Business Medium version or User in MultiUser version | |
| 2732 | + * Can depend on booking resource (BM) or resource owner (MU). | |
| 2733 | + * Now also supports BFB DB resolver (published/preview-aware). | |
| 2215 | 2734 | * |
| 2216 | - * @param int $resource_id | |
| 2217 | - * @param sting $custom_booking_form_name - use this custom booking form, if possible | |
| 2735 | + * @param int $resource_id | |
| 2736 | + * @param string $custom_booking_form_name Optional. Force this custom form if possible. | |
| 2218 | 2737 | * |
| 2219 | 2738 | * @return string |
| 2220 | 2739 | */ |
| 2221 | - function wpbc_get_content_booking_form_show( $resource_id , $custom_booking_form_name = '' ){ //FixIn: 9.4.3.12 | |
| 2740 | + function wpbc_get_content_booking_form_show( $resource_id, $custom_booking_form_name = '' ) { // FixIn: 9.4.3.12. | |
| 2222 | 2741 | |
| 2223 | - if ( $resource_id == -1 ) { | |
| 2224 | - if ( function_exists('get__default_type') ) | |
| 2225 | - $resource_id = get__default_type(); | |
| 2226 | - else | |
| 2227 | - $resource_id = 1; | |
| 2228 | - } | |
| 2742 | + static $wpbc__form_show_cache = array(); | |
| 2229 | 2743 | |
| 2230 | - if ( ! class_exists('wpdev_bk_personal') ) { | |
| 2744 | + $resource_id = (int) $resource_id; | |
| 2745 | + $custom_booking_form_name = (string) $custom_booking_form_name; | |
| 2231 | 2746 | |
| 2232 | - $booking_form_show = wpbc_get_free_booking_show_form(); | |
| 2747 | + if ( - 1 === $resource_id ) { | |
| 2748 | + if ( function_exists( 'get__default_type' ) ) { | |
| 2749 | + $resource_id = (int) get__default_type(); | |
| 2750 | + } else { | |
| 2751 | + $resource_id = 1; | |
| 2752 | + } | |
| 2753 | + } | |
| 2233 | 2754 | |
| 2234 | - } else { | |
| 2755 | + // ------------------------------------------------------------ | |
| 2756 | + // Determine a stable form slug early (avoid undefined var). | |
| 2757 | + // This is used for cache key and for resolver path. | |
| 2758 | + // ------------------------------------------------------------ | |
| 2759 | + $my_booking_form_name = ( '' !== $custom_booking_form_name ) ? $custom_booking_form_name : 'standard'; | |
| 2235 | 2760 | |
| 2236 | - $booking_form_show = get_bk_option( 'booking_form_show' ); | |
| 2237 | - $booking_form_show = wpbc_bf__replace_custom_html_shortcodes( $booking_form_show ); | |
| 2761 | + // Preview-aware context (optional; usually "published" in Booking Listing). | |
| 2762 | + $ctx = array(); | |
| 2763 | + if ( function_exists( 'wpbc_get_request_form_context' ) ) { | |
| 2764 | + $ctx = wpbc_get_request_form_context(); | |
| 2765 | + } | |
| 2766 | + $form_status = ( isset( $ctx['form_status'] ) ) ? sanitize_key( $ctx['form_status'] ) : 'published'; | |
| 2767 | + if ( in_array( $form_status, array( 'publish', 'published' ), true ) ) { | |
| 2768 | + $form_status = 'published'; | |
| 2769 | + } | |
| 2770 | + if ( 'preview' !== $form_status ) { | |
| 2771 | + $form_status = 'published'; | |
| 2772 | + } | |
| 2238 | 2773 | |
| 2239 | - if ( class_exists('wpdev_bk_biz_m') ) { | |
| 2774 | + // Cache key (important: this function is called per booking row). | |
| 2775 | + $cache_key = get_locale() . '|' . $form_status . '|' . $resource_id . '|' . $my_booking_form_name; | |
| 2776 | + if ( isset( $wpbc__form_show_cache[ $cache_key ] ) ) { | |
| 2777 | + return $wpbc__form_show_cache[ $cache_key ]; | |
| 2778 | + } | |
| 2240 | 2779 | |
| 2241 | - if ( ! empty( $custom_booking_form_name ) ) { //FixIn: 9.4.3.12 | |
| 2780 | + if ( '' === $custom_booking_form_name ) { | |
| 2781 | + $default_form_name = apply_bk_filter( 'wpbc_get_default_custom_form', 'standard', $resource_id ); | |
| 2782 | + if ( ! empty( $default_form_name ) ) { | |
| 2783 | + $my_booking_form_name = $default_form_name; | |
| 2784 | + } | |
| 2785 | + } | |
| 2786 | + | |
| 2787 | + $booking_form_show = ''; | |
| 2788 | + | |
| 2789 | + if ( class_exists( 'WPBC_FE_Form_Source_Resolver' ) && class_exists( 'WPBC_BFB_Form_Loader' ) ) { | |
| 2242 | 2790 | |
| 2243 | - $booking_form_show = apply_bk_filter( 'wpdev_get_booking_form_content', $booking_form_show, $custom_booking_form_name ); | |
| 2244 | - $my_booking_form_name = $custom_booking_form_name; | |
| 2245 | - } else { | |
| 2246 | - // BM :: Get default Custom Form of Resource | |
| 2247 | - $my_booking_form_name = apply_bk_filter( 'wpbc_get_default_custom_form', 'standard', $resource_id ); | |
| 2248 | - if ( ( $my_booking_form_name != 'standard' ) && ( ! empty( $my_booking_form_name ) ) ) { | |
| 2249 | - $booking_form_show = apply_bk_filter( 'wpdev_get_booking_form_content', $booking_form_show, $my_booking_form_name ); | |
| 2250 | - } | |
| 2251 | - } | |
| 2252 | - //MU :: if resource of "Regular User" - then GET STANDARD user form ( if ( get_bk_option( 'booking_is_custom_forms_for_regular_users' ) !== 'On' ) ) | |
| 2253 | - $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 | |
| 2791 | + $req = array( | |
| 2792 | + 'resource_id' => (int) $resource_id, | |
| 2793 | + 'form_slug' => (string) $my_booking_form_name, | |
| 2794 | + 'form_status' => $form_status, | |
| 2795 | + 'custom_params' => array(), | |
| 2796 | + 'ctx' => ( is_array( $ctx ) ? $ctx : array() ), | |
| 2797 | + ); | |
| 2254 | 2798 | |
| 2255 | - } | |
| 2256 | - } | |
| 2799 | + $resolved = WPBC_FE_Form_Source_Resolver::resolve( $req ); | |
| 2257 | 2800 | |
| 2258 | - // Language | |
| 2259 | - $booking_form_show = wpbc_lang( $booking_form_show ); | |
| 2801 | + // If preview requested but not found, try published as fallback. | |
| 2802 | + if ( ( empty( $resolved['engine'] ) || ( 'bfb_db' !== $resolved['engine'] ) ) && ( 'preview' === $form_status ) ) { | |
| 2803 | + $req['form_status'] = 'published'; | |
| 2804 | + $resolved = WPBC_FE_Form_Source_Resolver::resolve( $req ); | |
| 2805 | + } | |
| 2260 | 2806 | |
| 2261 | - $search = array( "'(<br[ ]?[/]?>)+'si", "'(<[/]?p[ ]?>)+'si" ); | |
| 2262 | - $replace = array( " ", " ", " " ); | |
| 2263 | - $booking_form_show = preg_replace( $search, $replace, $booking_form_show ); | |
| 2807 | + if ( ! empty( $resolved['engine'] ) && ( 'bfb_db' === $resolved['engine'] ) ) { | |
| 2264 | 2808 | |
| 2809 | + $bfb_loader_args = array(); | |
| 2810 | + if ( ! empty( $resolved['bfb_loader_args'] ) && is_array( $resolved['bfb_loader_args'] ) ) { | |
| 2811 | + $bfb_loader_args = $resolved['bfb_loader_args']; | |
| 2812 | + } | |
| 2813 | + | |
| 2814 | + // We need "content_form" template for booking fields output. | |
| 2815 | + $bfb_loader_args['return'] = 'content_form'; | |
| 2816 | + | |
| 2817 | + $bfb_pair = wpbc_bfb_get_booking_form_pair( $bfb_loader_args ); | |
| 2818 | + | |
| 2819 | + $content_form = ''; | |
| 2820 | + if ( is_array( $bfb_pair ) && isset( $bfb_pair['content'] ) ) { | |
| 2821 | + $content_form = (string) $bfb_pair['content']; | |
| 2822 | + } | |
| 2823 | + | |
| 2824 | + if ( '' !== trim( $content_form ) ) { | |
| 2825 | + $booking_form_show = wpbc_bf__replace_custom_html_shortcodes( $content_form ); | |
| 2826 | + } | |
| 2827 | + } | |
| 2828 | + } | |
| 2829 | + | |
| 2830 | + // ------------------------------------------------------------ | |
| 2831 | + // Language + cleanup (keep old behavior). | |
| 2832 | + // ------------------------------------------------------------ | |
| 2833 | + $booking_form_show = wpbc_lang( $booking_form_show ); | |
| 2834 | + | |
| 2835 | + $search = array( "'(<br[ ]?[/]?>)+'si", "'(<[/]?p[ ]?>)+'si" ); | |
| 2836 | + $replace = array( " ", " ", " " ); | |
| 2837 | + $booking_form_show = preg_replace( $search, $replace, $booking_form_show ); | |
| 2838 | + | |
| 2839 | + // Store cache by final slug (slug may have changed in BM branch). | |
| 2840 | + $final_cache_key = get_locale() . '|' . $form_status . '|' . $resource_id . '|' . $my_booking_form_name; | |
| 2841 | + $wpbc__form_show_cache[ $final_cache_key ] = $booking_form_show; | |
| 2842 | + | |
| 2265 | 2843 | return $booking_form_show; |
| 2266 | 2844 | } |
| 2267 | 2845 | |
| 2268 | 2846 | |
| 2847 | + | |
| 2269 | 2848 | /** |
| 2270 | 2849 | * Get parsed "Content of booking fields data" - Shortcodes replaced by Values |
| 2271 | 2850 | * |
| 2272 | 2851 | * @param array $booking_data_arr |
| @@ -2306,9 +2885,11 @@ | ||
| 2306 | 2885 | * plus removing \n in the code |
| 2307 | 2886 | * and back converting escaped single quotes from \' to ' |
| 2308 | 2887 | * |
| 2309 | 2888 | * This function has to be used in the code marked with double quote symbols, not single. |
| 2310 | - * Example: onclick="javascript:<?php echo wpbc_esc_js( $item_params['action'] ); ?>" | |
| 2889 | + * Example: onclick="javascript:<?php | |
| 2890 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 2891 | + echo wpbc_esc_js( $item_params['action'] ); ?>" | |
| 2311 | 2892 | * |
| 2312 | 2893 | * @param $text |
| 2313 | 2894 | * |
| 2314 | 2895 | * @return string |
| @@ -2348,13 +2929,13 @@ | ||
| 2348 | 2929 | |
| 2349 | 2930 | $value = preg_replace( '/<[^>]*>/', '', $value ); // clean any tags |
| 2350 | 2931 | $value = str_replace( '<', ' ', $value ); |
| 2351 | 2932 | $value = str_replace( '>', ' ', $value ); |
| 2352 | - $value = strip_tags( $value ); // Strip HTML and PHP tags from a string | |
| 2933 | + $value = wp_strip_all_tags( $value ); // Strip HTML and PHP tags from a string | |
| 2353 | 2934 | |
| 2354 | 2935 | // Clean SQL injection |
| 2355 | 2936 | $value = esc_sql( $value ); |
| 2356 | - $value = esc_textarea( $value ); //FixIn: 7.1.1.2 | |
| 2937 | + $value = esc_textarea( $value ); // FixIn: 7.1.1.2. | |
| 2357 | 2938 | |
| 2358 | 2939 | return $value; |
| 2359 | 2940 | } |
| 2360 | 2941 | |
| @@ -2391,8 +2972,10 @@ | ||
| 2391 | 2972 | $value_trimmed = trim( stripslashes( $value ) ); |
| 2392 | 2973 | |
| 2393 | 2974 | $wild = '%'; |
| 2394 | 2975 | $like = $wild . wpbc_esc_sql_like( $value_trimmed ) . $wild; |
| 2976 | + | |
| 2977 | + /* phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.QuotedSimplePlaceholder */ | |
| 2395 | 2978 | $sql = $wpdb->prepare( "'%s'", $like ); |
| 2396 | 2979 | |
| 2397 | 2980 | return $sql; |
| 2398 | 2981 | |
| @@ -2439,8 +3022,9 @@ | ||
| 2439 | 3022 | $value_trimmed = trim( stripslashes( $value ) ); |
| 2440 | 3023 | |
| 2441 | 3024 | $value_trimmed = wpbc_esc_sql_like( $value_trimmed ); |
| 2442 | 3025 | |
| 3026 | + /* phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.QuotedSimplePlaceholder */ | |
| 2443 | 3027 | $value = trim( $wpdb->prepare( "'%s'", $value_trimmed ) , "'" ); |
| 2444 | 3028 | |
| 2445 | 3029 | return $value; |
| 2446 | 3030 | |
| @@ -2502,17 +3086,19 @@ | ||
| 2502 | 3086 | */ |
| 2503 | 3087 | function wpbc_php_error_message( $message, $error ) { |
| 2504 | 3088 | |
| 2505 | 3089 | // Check to show this error, only from Booking Listing page, checking secure parameters from wpbc_ajx_booking_listing in ..{Booking Calendar Folder}/includes/page-bookings/_src/ajx_booking_listing.js |
| 3090 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing | |
| 2506 | 3091 | if ( ! ( ! isset( $_POST['search_params'] ) || empty( $_POST['search_params'] ) ) ) { |
| 2507 | 3092 | // Security ----------------------------------------------------------------------------------------------- // in Ajax Post: 'nonce': wpbc_ajx_booking_listing.get_secure_param( 'nonce' ), |
| 2508 | 3093 | $action_name = 'wpbc_ajx_booking_listing_ajx' . '_wpbcnonce'; |
| 2509 | 3094 | $nonce_post_key = 'nonce'; |
| 2510 | 3095 | // $result_check = check_ajax_referer( $action_name, $nonce_post_key ); |
| 3096 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing | |
| 2511 | 3097 | if ( isset( $_REQUEST[ $nonce_post_key ] ) ) { |
| 3098 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 3099 | + $nonce_request = $_REQUEST[ $nonce_post_key ]; | |
| 2512 | 3100 | |
| 2513 | - $nonce_request = $_REQUEST[ $nonce_post_key ]; | |
| 2514 | - | |
| 2515 | 3101 | $result_verify_nonce = wp_verify_nonce( $nonce_request, $action_name ); |
| 2516 | 3102 | |
| 2517 | 3103 | if ( false !== $result_verify_nonce ) { |
| 2518 | 3104 | if ( ( ! empty( $error ) ) && ( ! empty( $error['message'] ) ) ) { |
| @@ -2543,5 +3129,5 @@ | ||
| 2543 | 3129 | die( '<strong>Error!</strong> Probably nonce for this page has been expired. Please <a href="javascript:void(0)" onclick="javascript:location.reload();">reload the page</a>.' ); |
| 2544 | 3130 | } |
| 2545 | 3131 | } |
| 2546 | 3132 | add_action( 'check_ajax_referer', 'wpbc_check_ajax_referer__for_booking_listing', 2, 10 ); |
| 2547 | -// </editor-fold> | |
| 3133 | +// </editor-fold> | |