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