PluginProbe
Booking Calendar / 11.8.4
Booking Calendar v11.8.4
11.8.4 11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 All 204 releases
← All changes | includes/page-availability/availability__resource.php +44 -24 10.1.311.8.4 View file →
@@ -57,9 +57,9 @@
57 57 Example:
58 58 array( 1 => array( "2023-08-03" , "2023-08-04" ),
59 59 8 => array( "2023-08-03" ), ...
60 60 */
61 -function wpbc_for_resources_arr__get_unavailable_dates( $resource_id_arr, $search_dates = 'CURDATE' ) { //FixIn: 9.7.3.11
61 +function wpbc_for_resources_arr__get_unavailable_dates( $resource_id_arr, $search_dates = 'CURDATE' ) { // FixIn: 9.7.3.11.
62 62
63 63 // Booking resources -----------------------------------------------------------------------------------------------
64 64 $resource_id_csd = implode( ',', $resource_id_arr ); // '9,13,5,6,7,1,2,10,11,12,3,4,8'
65 65
@@ -68,10 +68,21 @@
68 68
69 69 foreach ( $search_dates as $date_ymd ) {
70 70 $search_dates_arr[] = $date_ymd . ' 00:00:00';
71 71 }
72 - $search_dates_formated = implode( ',', $search_dates_arr );
73 72
73 + /**
74 + * // FixIn: 10.14.17.1.
75 + * If we have only one date param,eter, it is means that we defined only one parameter in shortcode: calendar_dates_start or calendar_dates_end
76 + * and in this case we need to search >= or <= (but because in this function, we do not know what exactly it was parameter, start or end), we will search for all dates.
77 + */
78 + if ( count( $search_dates_arr ) === 1 ) {
79 + $search_dates_formated = 'ALL';
80 + } else {
81 + $search_dates_formated = implode( ',', $search_dates_arr );
82 + }
83 +
84 +
74 85 } else { // Probably 'CURDATE' | 'ALL'
75 86
76 87 $search_dates_formated = ( in_array( $search_dates, array( 'ALL', 'CURDATE' ) ) )
77 88 ? $search_dates
@@ -133,9 +144,9 @@
133 144 ) );
134 145 */
135 146 function wpbc_availability__get_dates_status__sql( $params ){
136 147
137 - // CACHE - GET :: check if such request was cached and get it ----------------------------------------------- //FixIn: 9.7.3.14
148 + // CACHE - GET :: check if such request was cached and get it ----------------------------------------------- // FixIn: 9.7.3.14.
138 149 $params_for_cache_key = $params;
139 150 if ( isset( $params_for_cache_key['resource_id'] ) ) {
140 151 $params_for_cache_key['resource_id'] = (string) $params_for_cache_key['resource_id'];
141 152 }
@@ -147,9 +158,9 @@
147 158 // -----------------------------------------------------------------------------------------------------------------
148 159
149 160
150 161 $defaults = array(
151 - 'calendar_date' => 'CURDATE', // 'CURDATE' | 'ALL' | '2023-07-15 00:00:00,2023-07-21 00:00:00' //FixIn: 9.7.3.11
162 + 'calendar_date' => 'CURDATE', // 'CURDATE' | 'ALL' | '2023-07-15 00:00:00,2023-07-21 00:00:00' // FixIn: 9.7.3.11.
152 163 'prop_name' => 'date_status', // 'rate', 'allow_start_day_selection', 'allow_days_number_to_select', 'availability_count', ...
153 164 'prop_value' => 'unavailable', // 'unavailable', 'available', 'pending', 'approved'
154 165 'resource_id' => 1 // int or dcv
155 166 );
@@ -185,14 +196,14 @@
185 196 $sql['where'] .= " AND resource_id IN ( {$params['resource_id']} ) ";
186 197
187 198 if ( '' != $params['calendar_date'] ) {
188 199
189 - //FixIn: 9.7.3.11
200 + // FixIn: 9.7.3.11.
190 201 if ( 'ALL' == $params['calendar_date'] ) {
191 202 // All dates
192 203 } else if ( 'CURDATE' == $params['calendar_date'] ) {
193 204
194 - $sql['where'] .= " AND calendar_date >= CURDATE() "; // Current dates
205 + $sql['where'] .= " AND calendar_date >= " . wpbc_sql_date_math_expr_explicit('', 'curdate') . " "; // Current dates
195 206
196 207 } else { // Specific Date(s)
197 208
198 209 if ( false === strpos( $params['calendar_date'], ',' ) ) { // One date: - '2023-07-15 00:00:00'
@@ -206,10 +217,22 @@
206 217 foreach ( $dates_arr as $date_ymd ) {
207 218 $in_search_arr[] = '%s';
208 219 $sql_args[] = $date_ymd;
209 220 }
210 - $in_search_dates_csv = implode( ',', $in_search_arr );
211 - $sql['where'] .= " AND calendar_date IN ( {$in_search_dates_csv} ) ";
221 + // FixIn: 10.14.17.1.
222 + $sql_args = wpbc_sanitize_date_ymdhis_to_check( $sql_args );
223 + /**
224 + * If we have onbly 2 dates, then we understand such dates as from - to.
225 + * usually such situation in shortcodes with these parameters calendar_dates_start / calendar_dates_end.
226 + * E.g.: [bookingcalendar resource_id=2 nummonths=2 calendar_dates_start='2026-02-01' calendar_dates_end='2026-03-31']
227 + */
228 + if ( 2 === count( $sql_args ) ) {
229 + $sql['where'] .= " AND calendar_date >= %s ";
230 + $sql['where'] .= " AND calendar_date <= %s ";
231 + } else {
232 + $in_search_dates_csv = implode( ',', $in_search_arr );
233 + $sql['where'] .= " AND calendar_date IN ( {$in_search_dates_csv} ) ";
234 + }
212 235 }
213 236 }
214 237 }
215 238
@@ -247,19 +270,13 @@
247 270 $sql_args[] = intval( $params['keyword'] );
248 271 }
249 272 *
250 273 */
251 - $sql_prepared = $wpdb->prepare(
252 - $sql['start_select']
253 - . $sql['from']
254 - . $sql['where']
255 - . $sql['order']
256 - . $sql['limit']
257 - , $sql_args
258 - );
274 + /* phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare */
275 + $sql_prepared = $wpdb->prepare( $sql['start_select'] . $sql['from'] . $sql['where'] . $sql['order'] . $sql['limit'], $sql_args );
276 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
277 + $bookings_sql_obj = $wpdb->get_results( $sql_prepared );
259 278
260 - $bookings_sql_obj = $wpdb->get_results($sql_prepared);
261 -
262 279 // CACHE - SAVE :: ------------------------------------------------------------------------------------------------
263 280 $cache_result = wpbc_cache__save( 'wpbc_availability__get_dates_status__sql', $params_for_cache, $bookings_sql_obj );
264 281
265 282 return $bookings_sql_obj;
@@ -350,11 +367,12 @@
350 367 $sub_sql = implode( ' OR ', $sub_sql );
351 368 $sql .= $sub_sql;
352 369 $sql .= " )";
353 370 }
354 -
371 + /* phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare */
355 372 $sql_prepared = $wpdb->prepare( $sql, $sql_args );
356 - $row_number = $wpdb->query( $sql_prepared );
373 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
374 + $row_number = $wpdb->query( $sql_prepared );
357 375
358 376
359 377 // If we set the dates as 'available', then we skip INSERT into DB, because previously we have already deleted all 'unavailable' dates status for such dates
360 378 if ( ( 'date_status' == $params['prop_name'] ) && ( 'available' == $params['prop_value'] ) ) {
@@ -377,11 +395,12 @@
377 395 }
378 396
379 397 $sub_sql = implode( ',', $sub_sql );
380 398 $sql .= $sub_sql;
381 -
399 + /* phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare */
382 400 $sql_prepared = $wpdb->prepare( $sql, $sql_args );
383 - $row_number = $wpdb->query( $sql_prepared );
401 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
402 + $row_number = $wpdb->query( $sql_prepared );
384 403 }
385 404
386 405 return $row_number;
387 406 }
@@ -474,10 +493,11 @@
474 493 $sql .= $sub_sql;
475 494 $sql .= " )";
476 495 }
477 496 }
478 -
497 + /* phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare */
479 498 $sql_prepared = $wpdb->prepare( $sql, $sql_args );
480 - $row_number = $wpdb->query( $sql_prepared );
499 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
500 + $row_number = $wpdb->query( $sql_prepared );
481 501
482 502 return $row_number;
483 503 }