PluginProbe
Booking Calendar / 11.7
Booking Calendar v11.7
11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 10.11.2 10.11.3 10.11.4 All 201 releases
booking / includes / _functions / booking_data__get.php

booking_data__get.php in Booking Calendar 11.7, at includes/_functions/booking_data__get.php

626 lines 28.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @version 1.0
4 * @package Booking Calendar
5 * @subpackage Booking details | replace / fields functions
6 * @category Functions
7 *
8 * @author wpdevelop
9 * @link https://wpbookingcalendar.com/
10 * @email info@wpbookingcalendar.com
11 *
12 * @modified 2024-09-03
13 */
14
15 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
16
17 // =====================================================================================================================
18 // == Booking details | replace / fields functions ==
19 // =====================================================================================================================
20
21 /**
22 * Get booking resource title (translated/localized)
23 *
24 * @param $resource_id
25 *
26 * @return string
27 */
28 function wpbc_get_resource_title( $resource_id = 1 ) {
29
30 $resource_title = '';
31
32 if ( function_exists( 'wpbc_db__get_resource_title' ) ) {
33
34 $resource_title = wpbc_db__get_resource_title( $resource_id );
35
36 if (! empty($resource_title)) {
37 $resource_title = wpbc_lang( $resource_title );
38 }
39 }
40 if ( '' === $resource_title && function_exists( 'wpbc_booking_resource_content_repository' ) ) {
41 $resource_content = wpbc_booking_resource_content_repository()->get( $resource_id );
42 $resource_title = ! empty( $resource_content['title'] ) ? wpbc_lang( $resource_content['title'] ) : '';
43 }
44
45 return $resource_title;
46 }
47
48
49 /**
50 * Get parent booking resource title (translated/localized)
51 *
52 * @param $resource_id
53 *
54 * @return string
55 */
56 function wpbc_get_parent_resource_title( $resource_id = 1 ) { // FixIn: 10.9.2.4.
57
58 $resource_title = '';
59
60 if ( ( function_exists( 'wpbc_is_this_child_resource' ) ) && ( wpbc_is_this_child_resource( $resource_id ) ) ) {
61 $resource_id = wpbc_get_parent_resource( $resource_id );
62 }
63
64 if ( function_exists( 'wpbc_db__get_resource_title' ) ) {
65
66 $resource_title = wpbc_db__get_resource_title( $resource_id );
67
68 if (! empty($resource_title)) {
69 $resource_title = wpbc_lang( $resource_title );
70 }
71 }
72
73 return $resource_title;
74 }
75
76 /**
77 * Check, if exist booking for this hash. If existed, get Email of this booking
78 *
79 * @param string $booking_hash - booking hash.
80 * @param string $booking_data_key - booking field key - default 'email'.
81 *
82 * @return bool - booking data field
83 */
84 function wpbc_get__booking_data_field__by_booking_hash( $booking_hash, $booking_data_key = 'email' ){ // FixIn: 8.1.3.5.
85
86 $return_val = false;
87
88 // $booking_hash = '0d55671fd055fd64423294f89d6b58e6'; // debugging
89
90 if ( ! empty( $booking_hash ) ) {
91
92 $my_booking_id_type = wpbc_hash__get_booking_id__resource_id( $booking_hash );
93
94 if ( ! empty( $my_booking_id_type ) ) {
95
96 list( $booking_id, $resource_id ) = $my_booking_id_type;
97
98 $booking_data = wpbc_db_get_booking_details( $booking_id );
99
100 if ( ! empty( $booking_data ) ) {
101
102 $booking_details = wpbc_get_booking_different_params_arr( $booking_id, $booking_data->form, $resource_id );
103
104 if ( isset( $booking_details[ $booking_data_key ] ) ) {
105
106 $return_val = $booking_details[ $booking_data_key ];
107 }
108 }
109 }
110 }
111 return $return_val;
112 }
113
114 /**
115 * Get booking details object from DB
116 *
117 * @param $booking_id - int
118 *
119 * @return mixed - booking details or false if not found
120 * Example:
121 * stdClass Object
122 * (
123 * [booking_id] => 26
124 * [trash] => 0
125 * [sync_gid] =>
126 * [is_new] => 0
127 * [status] =>
128 * [sort_date] => 2018-02-27 00:00:00
129 * [modification_date] => 2018-02-18 12:49:30
130 * [form] => text^selected_short_dates_hint3^02/27/2018 - 03/02/2018~text^days_number_hint3^4~text^cost_hint3^40.250&nbsp;&#36;~text^name3^Victoria~text^secondname3^vica~email^email3^vica@wpbookingcalendar.com~text^phone3^test booking ~selectbox-one^visitors3^1
131 * [hash] => 0d55671fd055fd64423294f89d6b58e6
132 * [booking_type] => 3
133 * [remark] =>
134 * [cost] => 40.25
135 * [pay_status] => 151895097121.16
136 * [pay_request] => 0
137 * )
138 */
139 function wpbc_db_get_booking_details( $booking_id ) { // FixIn: 8.1.3.5.
140
141 global $wpdb;
142
143 $slct_sql = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}booking WHERE booking_id = %d LIMIT 0,1", $booking_id );
144 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
145 $sql_results = $wpdb->get_row( $slct_sql );
146
147 if ( ! empty( $sql_results ) ) {
148 return $sql_results;
149 } else {
150 return false;
151 }
152 }
153
154 /**
155 * Get booking D a t e s from DB - array of objects
156 *
157 * @param $booking_id - int
158 *
159 * @return mixed - booking dates array or false if not found
160 *
161 */
162 function wpbc_db_get_booking_dates( $booking_id ) {
163
164 global $wpdb;
165
166 $sql = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}bookingdates as dt WHERE dt.booking_id = %d ", $booking_id );
167
168 if ( class_exists( 'wpdev_bk_biz_l' ) ) {
169 $sql .= " ORDER BY booking_id, type_id, booking_date ";
170 } else {
171 $sql .= " ORDER BY booking_id, booking_date ";
172 }
173 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
174 $sql_results = $wpdb->get_results( $sql );
175
176 if ( ! empty( $sql_results ) ) {
177 return $sql_results;
178 } else {
179 return false;
180 }
181 }
182
183 /**
184 * Get booking modification date from DB
185 *
186 * @param $booking_id
187 *
188 * @return string
189 */
190 function wpbc_db_get_booking_modification_date( $booking_id ) {
191 // FixIn: 8.0.1.7.
192 global $wpdb;
193 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
194 $modification_date = ' ' . $wpdb->get_var( $wpdb->prepare( "SELECT modification_date FROM {$wpdb->prefix}booking WHERE booking_id = %d ", $booking_id ) );
195
196 return $modification_date;
197 }
198
199 /**
200 * Get user IP
201 *
202 * @return mixed|string
203 */
204 function wpbc_get_user_ip() {
205
206 if ( isset( $_SERVER['HTTP_CLIENT_IP'] ) ) {
207 $userIP = ( ( isset( $_SERVER['HTTP_CLIENT_IP'] ) ) ? sanitize_text_field( $_SERVER['HTTP_CLIENT_IP'] ) : '' ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
208 } elseif ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
209 $userIP = ( ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) ? sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_FOR'] ) : '' ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
210 } elseif ( isset( $_SERVER['HTTP_X_FORWARDED'] ) ) {
211 $userIP = ( ( isset( $_SERVER['HTTP_X_FORWARDED'] ) ) ? sanitize_text_field( $_SERVER['HTTP_X_FORWARDED'] ) : '' ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
212 } elseif ( isset( $_SERVER['HTTP_FORWARDED_FOR'] ) ) {
213 $userIP = ( ( isset( $_SERVER['HTTP_FORWARDED_FOR'] ) ) ? sanitize_text_field( $_SERVER['HTTP_FORWARDED_FOR'] ) : '' ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
214 } elseif ( isset( $_SERVER['HTTP_FORWARDED'] ) ) {
215 $userIP = ( ( isset( $_SERVER['HTTP_FORWARDED'] ) ) ? sanitize_text_field( $_SERVER['HTTP_FORWARDED'] ) : '' ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
216 } elseif ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
217 $userIP = ( ( isset( $_SERVER['REMOTE_ADDR'] ) ) ? sanitize_text_field( $_SERVER['REMOTE_ADDR'] ) : '' ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
218 } else {
219 $userIP = "";
220 }
221 return $userIP;
222 }
223
224 /**
225 * Get IP of Server
226 *
227 * @return string
228 */
229 function wpbc_get_server_ip() { // FixIn: 9.8.14.3.
230
231 $ip_address = '';
232 if ( array_key_exists( 'SERVER_ADDR', $_SERVER ) ) {
233 $ip_address = ( ( isset( $_SERVER['SERVER_ADDR'] ) ) ? sanitize_text_field( $_SERVER['SERVER_ADDR'] ) : '' ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
234 } else if ( array_key_exists( 'LOCAL_ADDR', $_SERVER ) ) {
235 $ip_address = ( ( isset( $_SERVER['LOCAL_ADDR'] ) ) ? sanitize_text_field( $_SERVER['LOCAL_ADDR'] ) : '' ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
236 }
237
238 return $ip_address;
239 }
240
241 /**
242 * Get different Booking Fields as array for replace
243 *
244 * @param int $booking_id - ID of booking // 999
245 * @param string $formdata - booking form data content // selectbox-one^rangetime4^10:00 - 12:00~text^name4^Jo~text^secondname4^Smith~email^email4^smith@wpbookingcalendar.com~...
246 * @param int $booking_resource_id - booking resource type // 4
247 *
248 * @return array
249 *
250 * Example:
251 * [
252 * [booking_id] => 26
253 * [id] => 26
254 * [days_input_format] => 01.03.2018,02.03.2018,27.02.2018,28.02.2018
255 * [days_only_sql] => 2018-02-27,2018-02-28,2018-03-01,2018-03-02
256 * [dates_sql] => 2018-02-27 00:00:00, 2018-02-28 00:00:00, 2018-03-01 00:00:00, 2018-03-02 00:00:00
257 * [check_in_date_sql] => 2018-02-27 00:00:00
258 * [check_out_date_sql] => 2018-03-02 00:00:00
259 * [dates] => 02/27/2018 - 03/02/2018
260 * [check_in_date] => 02/27/2018
261 * [check_out_date] => 03/02/2018
262 * [check_out_plus1day] => 03/03/2018
263 * [dates_count] => 4
264 * [days_count] => 4
265 * [nights_count] => 3
266 * [check_in_date_hint] => 02/27/2018
267 * [check_out_date_hint] => 03/02/2018
268 * [start_time_hint] => 00:00
269 * [end_time_hint] => 00:00
270 * [selected_dates_hint] => 02/27/2018, 02/28/2018, 03/01/2018, 03/02/2018
271 * [selected_timedates_hint] => 02/27/2018, 02/28/2018, 03/01/2018, 03/02/2018
272 * [selected_short_dates_hint] => 02/27/2018 - 03/02/2018
273 * [selected_short_timedates_hint] => 02/27/2018 - 03/02/2018
274 * [days_number_hint] => 4
275 * [nights_number_hint] => 3
276 * [siteurl] => http://beta
277 * [resource_title] => Apartment A
278 * [bookingtype] => Apartment A
279 * [remote_ip] => 127.0.0.1
280 * [user_agent] => Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0
281 * [request_url] => http://beta/wp-admin/post.php?post=1473&action=edit
282 * [current_date] => 02/18/2018
283 * [current_time] => 14:11
284 * [cost_hint] => 40.250 $
285 * [name] => Victoria
286 * [secondname] => vica
287 * [email] => vica@wpbookingcalendar.com
288 * [phone] => test booking
289 * [visitors] => 1
290 * [booking_resource_id] => 3
291 * [resource_id] => 3
292 * [type_id] => 3
293 * [type] => 3
294 * [resource] => 3
295 * [content] => '........'
296 * [moderatelink] => http://beta/wp-admin/admin.php?page=wpbc&tab=vm_booking_listing&wh_booking_id=26
297 * [visitorbookingediturl] => http://beta/?booking_hash=0d55671fd055fd64423294f89d6b58e6
298 * [visitorbookingcancelurl] => http://beta/?booking_hash=0d55671fd055fd64423294f89d6b58e6&booking_cancel=1
299 * [visitorbookingpayurl] => http://beta/?booking_hash=0d55671fd055fd64423294f89d6b58e6&booking_pay=1
300 * [bookinghash] => 0d55671fd055fd64423294f89d6b58e6
301 * [db_cost] => 40.25
302 * [db_cost_hint] => 40.250 $
303 * [modification_date] => 2018-02-18 12:49:30
304 * [modification_year] => 2018
305 * [modification_month] => 02
306 * [modification_day] => 18
307 * [modification_hour] => 12
308 * [modification_minutes] => 49
309 * [modification_seconds] => 30
310 * ]
311 */
312 function wpbc_get_booking_different_params_arr( $booking_id, $formdata, $booking_resource_id = 1 ) {
313
314 $replace = array();
315
316 // Resources ///////////////////////////////////////////////////////////////
317 $bk_title = wpbc_get_resource_title( $booking_resource_id );
318
319
320 ////////////////////////////////////////////////////////////////////////////
321 // Dates Dif. Formats
322 ////////////////////////////////////////////////////////////////////////////
323
324 // -> '2023-10-09 12:00:01, 2023-10-09 20:00:02'
325 $sql_dates_format = wpbc_db__get_sql_dates__in_booking__as_str( $booking_id ); // 2016-08-03 16:00:01, 2016-08-03 18:00:02
326
327 $sql_dates_only = explode(',',$sql_dates_format);
328 $sql_days_only_array = array();
329 $days_as_in_form_array = array();
330 foreach ( $sql_dates_only as $sql_day_only ) {
331 $sql_days_only_array[] = trim( substr($sql_day_only, 0, 11 ) );
332 $days_as_in_form_array[] = date_i18n( "d.m.Y", strtotime( trim( substr($sql_day_only, 0, 11 ) ) ) );
333 }
334 $sql_days_only_array = array_unique( $sql_days_only_array );
335 sort( $sql_days_only_array );
336 $sql_days_only = implode( ',', $sql_days_only_array );
337
338 $days_as_in_form_array = array_unique( $days_as_in_form_array );
339 sort( $days_as_in_form_array );
340 $days_as_in_form = implode( ',', $days_as_in_form_array );
341
342 $sql_days_only_with_full_times = array();
343 foreach ( $sql_days_only_array as $sql_day ) {
344 $sql_days_only_with_full_times[] = $sql_day . ' 00:00:00';
345 }
346 $sql_days_only_with_full_times = implode(',', $sql_days_only_with_full_times );
347
348
349 if ( get_bk_option( 'booking_date_view_type' ) == 'short' ) {
350 $formated_booking_dates = wpbc_get_dates_short_format( $sql_dates_format );
351 } else {
352 $formated_booking_dates = wpbc_get_dates_comma_string_localized( $sql_dates_format );
353 }
354
355 $sql_dates_format_check_in_out = explode(',', $sql_dates_format );
356
357 $my_check_in_date = wpbc_get_dates_comma_string_localized( $sql_dates_format_check_in_out[0] );
358 $my_check_out_date = wpbc_get_dates_comma_string_localized( $sql_dates_format_check_in_out[ count( $sql_dates_format_check_in_out ) - 1 ] );
359
360 $my_check_out_plus1day = wpbc_datetime_localized( gmdate( 'Y-m-d H:i:s'
361 , strtotime( $sql_dates_format_check_in_out[ count( $sql_dates_format_check_in_out ) - 1 ]
362 . " +1 day" )
363 ) );
364
365 $date_format = get_bk_option( 'booking_date_format');
366 $check_in_date_hint = wpbc_date_localized( $sql_days_only_array[0] );
367 $check_out_date_hint = wpbc_date_localized( $sql_days_only_array[ ( count( $sql_days_only_array ) - 1 ) ] );
368
369 // FixIn: 9.7.3.16.
370 $cancel_date_hint = wpbc_datetime_localized( gmdate( 'Y-m-d H:i:s'
371 , strtotime( '-14 days', strtotime( $sql_days_only_array[0] ) )
372 ) );
373 // FixIn: 10.0.0.31.
374 $pre_checkin_date_hint = wpbc_datetime_localized( gmdate( 'Y-m-d H:i:s'
375 , strtotime( '-' . intval( get_bk_option( 'booking_number_for_pre_checkin_date_hint' ) ) . ' days', strtotime( $sql_days_only_array[0] ) )
376 ) );
377
378 // Booking Times -------------------------------------------------------------------------------------------
379 $start_end_time = wpbc_get_times_in_form( $formdata, $booking_resource_id ); // false ||
380
381 if ( $start_end_time !== false ) {
382 $start_time = $start_end_time[0]; // array('00','00','01');
383 $end_time = $start_end_time[1]; // array('00','00','01');
384 } else {
385 $start_time = array('00','00','00');
386 $end_time = array('00','00','00');
387 }
388
389 //TODO: continue here with replacing date_i18n to wpbc_loc_ ...
390
391 $start_time_hint = wpbc_time_localized( implode( ':', $start_time ) );
392 $end_time_hint = wpbc_time_localized( implode( ':', $end_time ) );
393
394 // FixIn: 9.5.1.3.
395 $check_in_date_sql = wpbc_date_localized( $sql_days_only_array[0], 'Y-m-d' );
396 $check_out_date_sql = wpbc_date_localized( $sql_days_only_array[ ( count( $sql_days_only_array ) - 1 ) ], 'Y-m-d' );
397
398 $start_time_sql = wpbc_time_localized( implode( ':', $start_time ), 'H:i' );
399 $end_time_sql = wpbc_time_localized( implode( ':', $end_time ) , 'H:i' );
400
401 ////////////////////////////////////////////////////////////////////////////
402
403
404 // Other ///////////////////////////////////////////////////////////////////
405 $replace[ 'booking_id' ] = $booking_id;
406 $replace[ 'id' ] = $replace[ 'booking_id' ];
407
408 $replace[ 'days_input_format' ] = $days_as_in_form; // 15.11.2023,16.11.2023,17.11.2023
409 $replace[ 'days_only_sql' ] = $sql_days_only; // 2023-11-15,2023-11-16,2023-11-17
410 $replace[ 'dates_sql' ] = $sql_dates_format; // 2016-07-28 16:00:01, 2016-07-28 18:00:02
411 $replace[ 'check_in_date_sql' ] = $sql_dates_format_check_in_out[0]; // 2016-07-28 16:00:01
412 $replace[ 'check_out_date_sql' ] = $sql_dates_format_check_in_out[ count( $sql_dates_format_check_in_out ) - 1 ]; // 2016-07-28 18:00:02
413 $replace[ 'dates' ] = $formated_booking_dates; // July 28, 2016 16:00 - July 28, 2016 18:00
414 $replace[ 'check_in_date' ] = $my_check_in_date; // July 28, 2016 16:00
415 $replace[ 'check_out_date' ] = $my_check_out_date; // July 28, 2016 18:00
416 $replace[ 'check_out_plus1day'] = $my_check_out_plus1day; // July 29, 2016 18:00
417
418 $replace['dates_count'] = count( $sql_days_only_array ); // 1
419 $replace['days_count'] = intval( $replace['dates_count'] ); // FixIn: 10.15.1.3.
420 $replace['nights_count'] = ( $replace['days_count'] > 1 ) ? intval( $replace['days_count'] - 1 ) : 1;
421 $replace['days_count_plus1day'] = intval( $replace['days_count'] + 1 );
422
423 // FixIn: 9.7.3.16.
424 $replace[ 'cancel_date_hint' ] = $cancel_date_hint; // 11/11/2013
425 // FixIn: 10.0.0.31.
426 $replace[ 'pre_checkin_date_hint' ] = $pre_checkin_date_hint; // 11/11/2013
427
428 $replace[ 'check_in_date_hint' ] = $check_in_date_hint; // 11/25/2013
429 $replace[ 'check_out_date_hint' ] = $check_out_date_hint; // 11/27/2013
430 $replace[ 'start_time_hint' ] = $start_time_hint; // 10:00
431 $replace[ 'end_time_hint' ] = $end_time_hint; // 12:00
432
433 // FixIn: 9.5.1.3.
434 $replace['check_in_date_hint_sql'] = $check_in_date_sql; // 2023-03-04
435 $replace['check_out_date_hint_sql'] = $check_out_date_sql; // 2023-03-12
436 $replace['start_time_hint_sql'] = $start_time_sql; // 10:00
437 $replace['end_time_hint_sql'] = $end_time_sql; // 12:00
438
439 $replace['selected_dates_hint'] = wpbc_get_dates_comma_string_localized( $sql_days_only_with_full_times ); // 11/25/2013, 11/26/2013, 11/27/2013
440 $replace['selected_timedates_hint'] = wpbc_get_dates_comma_string_localized( $sql_dates_format ); // 11/25/2013 10:00, 11/26/2013, 11/27/2013 12:00
441 $replace['selected_short_dates_hint'] = wpbc_get_dates_short_format( $sql_days_only_with_full_times ); // 11/25/2013 - 11/27/2013
442 $replace['selected_short_timedates_hint'] = wpbc_get_dates_short_format( $sql_dates_format ); // 11/25/2013 10:00 - 11/27/2013 12:00
443 $replace[ 'days_number_hint' ] = $replace[ 'days_count' ]; // 3
444 $replace[ 'nights_number_hint' ] = $replace[ 'nights_count' ]; // 2
445 $replace[ 'siteurl' ] = htmlspecialchars_decode( '<a href="' . esc_url( home_url() ) . '">' . home_url() . '</a>' );
446 $replace[ 'resource_title'] = wpbc_lang( $bk_title );
447 $replace[ 'bookingtype' ] = $replace[ 'resource_title'];
448 $replace[ 'remote_ip' ] = wpbc_get_user_ip(); // The IP address from which the user is viewing the current page.
449 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
450 $replace[ 'user_agent' ] = (isset($_SERVER['HTTP_USER_AGENT'])) ? $_SERVER['HTTP_USER_AGENT'] : ''; // Contents of the User-Agent: header from the current request, if there is one.
451 $server_http_referer_uri = ( ( isset( $_SERVER['HTTP_REFERER'] ) ) ? sanitize_text_field( $_SERVER['HTTP_REFERER'] ) : '' ); /* phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash */ /* FixIn: sanitize_unslash */
452 $replace[ 'request_url' ] = $server_http_referer_uri; // The address of the page (if any) where action was occured. Because we are sending it in Ajax request, we need to use the REFERER HTTP
453 $replace[ 'current_date' ] = date_i18n( get_bk_option( 'booking_date_format' ) );
454 $replace[ 'current_time' ] = date_i18n( get_bk_option( 'booking_time_format' ) );
455
456
457 // Form Fields /////////////////////////////////////////////////////////////
458 $booking_form_show_array = wpbc__legacy__get_form_content_arr( $formdata, $booking_resource_id, '', $replace ); // We use here $replace array, becaise in "Content of booking filds data" form can be shortcodes from above definition
459
460 foreach ( $booking_form_show_array['_all_fields_'] as $shortcode_name => $shortcode_value ) {
461
462 if ( ! isset( $replace[ $shortcode_name ] ) )
463 $replace[ $shortcode_name ] = $shortcode_value;
464 }
465 $replace[ 'content' ] = $booking_form_show_array['content'];
466
467 // Links ///////////////////////////////////////////////////////////////////
468 $replace[ 'moderatelink' ] = htmlspecialchars_decode(
469 // '<a href="' .
470 esc_url( wpbc_get_bookings_url() . '&tab=vm_booking_listing&wh_booking_id=' . $booking_id )
471 // . '">' . esc_html__('here', 'booking') . '</a>'
472 );
473 $replace[ 'visitorbookingediturl' ] = apply_bk_filter( 'wpdev_booking_set_booking_edit_link_at_email', '[visitorbookingediturl]', $booking_id );
474 $replace[ 'visitorbookingslisting' ] = apply_bk_filter( 'wpdev_booking_set_booking_edit_link_at_email', '[visitorbookingslisting]', $booking_id ); //FixIn: 8.1.3.5.1
475 $replace[ 'visitorbookingcancelurl' ] = apply_bk_filter( 'wpdev_booking_set_booking_edit_link_at_email', '[visitorbookingcancelurl]', $booking_id );
476 $replace[ 'visitorbookingpayurl' ] = apply_bk_filter( 'wpdev_booking_set_booking_edit_link_at_email', '[visitorbookingpayurl]', $booking_id );
477 $replace[ 'bookinghash' ] = apply_bk_filter( 'wpdev_booking_set_booking_edit_link_at_email', '[bookinghash]', $booking_id );
478
479 // Cost ////////////////////////////////////////////////////////////////////
480 $replace[ 'db_cost' ] = apply_bk_filter( 'get_booking_cost_from_db', '', $booking_id );
481 $replace[ 'db_cost_hint' ] = wpbc_get_cost_with_currency_for_user( $replace[ 'db_cost' ], $booking_resource_id );
482
483 ////////////////////////////////////////////////////////////////////////////
484
485 // FixIn: 8.0.1.7.
486 $modification_date = wpbc_db_get_booking_modification_date( $booking_id );
487
488 // 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.
489 $is_add_wp_timezone = true;
490 $modification_date = wpbc_datetime_localized( trim( $modification_date ), 'Y-m-d H:i:s', $is_add_wp_timezone );
491 $replace['modification_date'] = ' ' . $modification_date;
492 $modification_date = explode( ' ', $modification_date );
493 list( $replace['modification_year'], $replace['modification_month'], $replace['modification_day'] ) = explode( '-', $modification_date[0] );
494 list( $replace['modification_hour'], $replace['modification_minutes'], $replace['modification_seconds'] ) = explode( ':', $modification_date[1] );
495
496 // FixIn: 10.0.0.34.
497 if ( ! empty( $replace['creation_date'] ) ) {
498
499 // 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.
500 $creation_date = wpbc_datetime_localized( trim( $replace['creation_date'] ), 'Y-m-d H:i:s', $is_add_wp_timezone );
501
502 $replace['creation_date'] = ' ' . $creation_date;
503 $creation_date = explode( ' ', $creation_date );
504 list( $replace['creation_year'], $replace['creation_month'], $replace['creation_day'] ) = explode( '-', $creation_date[0] );
505 list( $replace['creation_hour'], $replace['creation_minutes'], $replace['creation_seconds'] ) = explode( ':', $creation_date[1] );
506 }
507
508 return $replace;
509 }
510
511 /**
512 * Get additional parameters to the replace array for specific booking
513 *
514 * @param $replace
515 * @param $booking_id
516 * @param $bktype
517 * @param $formdata
518 *
519 * @return mixed
520 */
521 function wpbc_replace_params_for_booking_func( $replace, $booking_id, $bktype, $formdata ){
522 /*
523 $modification_date = wpbc_db_get_booking_modification_date( $booking_id );
524
525 // 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.
526 $is_add_wp_timezone = true;
527 $modification_date = wpbc_datetime_localized( trim( $modification_date ), 'Y-m-d H:i:s', $is_add_wp_timezone );
528
529 $replace['modification_date'] = ' ' . $modification_date;
530
531 $modification_date = explode( ' ', $modification_date );
532 list( $replace['modification_year'], $replace['modification_month'], $replace['modification_day'] ) = explode( '-', $modification_date[0] );
533 list( $replace['modification_hour'], $replace['modification_minutes'], $replace['modification_seconds'] ) = explode( ':', $modification_date[1] );
534 */
535
536 // FixIn: 8.4.2.11.
537 if ( isset( $replace['rangetime'] ) ) {
538 $replace['rangetime'] = wpbc_time_slot_in_format( $replace['rangetime'] );
539 }
540 if ( isset( $replace['starttime'] ) ) {
541 $replace['starttime'] = wpbc_time_in_format( $replace['starttime'] );
542 }
543 if ( isset( $replace['endtime'] ) ) {
544 $replace['endtime'] = wpbc_time_in_format( $replace['endtime'] );
545 }
546
547 // FixIn: 8.2.1.25.
548 $booking_data = wpbc_db_get_booking_details( $booking_id );
549
550 if ( ! empty( $booking_data ) ) {
551 foreach ( $booking_data as $booking_key => $booking_data ) {
552 if ( ! isset( $replace[ $booking_key ] ) ) {
553 $replace[ $booking_key ] = $booking_data;
554 }
555 }
556 }
557
558 // Set dates and times in correct format ---------------------------------------------------------------
559
560 $is_add_wp_timezone = true;
561
562 if ( ! empty( $replace['modification_date'] ) ) {
563
564 // 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.
565 $modification_date = wpbc_datetime_localized( trim( $replace['modification_date'] ), 'Y-m-d H:i:s', $is_add_wp_timezone );
566
567 $replace['modification_date'] = ' ' . $modification_date;
568 $modification_date = explode( ' ', $modification_date );
569 list( $replace['modification_year'], $replace['modification_month'], $replace['modification_day'] ) = explode( '-', $modification_date[0] );
570 list( $replace['modification_hour'], $replace['modification_minutes'], $replace['modification_seconds'] ) = explode( ':', $modification_date[1] );
571 }
572 // FixIn: 10.0.0.34.
573 if ( ! empty( $replace['creation_date'] ) ) {
574
575 // 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.
576 $creation_date = wpbc_datetime_localized( trim( $replace['creation_date'] ), 'Y-m-d H:i:s', $is_add_wp_timezone );
577
578 $replace['creation_date'] = ' ' . $creation_date;
579 $creation_date = explode( ' ', $creation_date );
580 list( $replace['creation_year'], $replace['creation_month'], $replace['creation_day'] ) = explode( '-', $creation_date[0] );
581 list( $replace['creation_hour'], $replace['creation_minutes'], $replace['creation_seconds'] ) = explode( ':', $creation_date[1] );
582 }
583
584 return $replace;
585 }
586 add_filter( 'wpbc_replace_params_for_booking', 'wpbc_replace_params_for_booking_func', 10, 4 );
587
588
589 /**
590 * Replace shortcodes in string
591 *
592 * @param string $subject - string to manipulate
593 * @param array $replace_array - array with values to replace // array( [booking_id] => 9, [id] => 9, [dates] => July 3, 2016 14:00 - July 4, 2016 16:00, .... )
594 * @param mixed $replace_unknown_shortcodes - replace unknown params, if false, then no replace unknown params
595 * @return string
596 */
597 function wpbc_replace_booking_shortcodes( $subject, $replace_array , $replace_unknown_shortcodes = ' ' ) {
598
599 $defaults = array(
600 'ip' => wpbc_get_user_ip()
601 , 'blogname' => wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES )
602 , 'siteurl' => get_site_url()
603 );
604
605 $replace = wp_parse_args( $replace_array, $defaults );
606
607 foreach ( $replace as $replace_shortcode => $replace_value ) {
608
609 if ( is_null( $replace_value ) ) {
610 $replace_value = '';
611 };
612
613 $subject = str_replace( array( '[' . $replace_shortcode . ']'
614 , '{' . $replace_shortcode . '}' )
615 , $replace_value
616 , $subject );
617 }
618
619 // Remove all shortcodes, which is not replaced early.
620 if ( $replace_unknown_shortcodes !== false )
621 $subject = preg_replace( '/[\s]{0,}[\[\{]{1}[a-zA-Z0-9.,-_]{0,}[\]\}]{1}[\s]{0,}/', $replace_unknown_shortcodes, $subject );
622
623
624 return $subject;
625 }
626