PluginProbe
Booking Calendar / 10.1.3
Booking Calendar v10.1.3
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 10.11.2 All 203 releases
booking / core / wpbc_functions.php

wpbc_functions.php in Booking Calendar 10.1.3, at core/wpbc_functions.php

4,361 lines 151.3 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 Support Functions
6 * @category Functions
7 *
8 * @author wpdevelop
9 * @link https://wpbookingcalendar.com/
10 * @email info@wpbookingcalendar.com
11 *
12 * @modified 29.09.2015
13 */
14
15 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
16
17
18
19
20 // <editor-fold defaultstate="collapsed" desc=" == Booking details | replace / fields functions == " >
21
22 /**
23 * Get booking resource title (translated/localized)
24 *
25 * @param $resource_id
26 *
27 * @return string
28 */
29 function wpbc_get_resource_title( $resource_id = 1 ) {
30
31 $resource_title = '';
32
33 if ( function_exists( 'wpbc_db__get_resource_title' ) ) {
34
35 $resource_title = wpbc_db__get_resource_title( $resource_id );
36
37 if (! empty($resource_title)) {
38 $resource_title = wpbc_lang( $resource_title );
39 }
40 }
41
42 return $resource_title;
43 }
44
45
46 /**
47 * Check, if exist booking for this hash. If existed, get Email of this booking
48 *
49 * @param string $booking_hash - booking hash.
50 * @param string $booking_data_key - booking field key - default 'email'.
51 *
52 * @return bool - booking data field
53 */
54 function wpbc_get__booking_data_field__by_booking_hash( $booking_hash, $booking_data_key = 'email' ){ //FixIn: 8.1.3.5
55
56 $return_val = false;
57
58 // $booking_hash = '0d55671fd055fd64423294f89d6b58e6'; // debugging
59
60 if ( ! empty( $booking_hash ) ) {
61
62 $my_booking_id_type = wpbc_hash__get_booking_id__resource_id( $booking_hash );
63
64 if ( ! empty( $my_booking_id_type ) ) {
65
66 list( $booking_id, $resource_id ) = $my_booking_id_type;
67
68 $booking_data = wpbc_db_get_booking_details( $booking_id );
69
70 if ( ! empty( $booking_data ) ) {
71
72 $booking_details = wpbc_get_booking_different_params_arr( $booking_id, $booking_data->form, $resource_id );
73
74 if ( isset( $booking_details[ $booking_data_key ] ) ) {
75
76 $return_val = $booking_details[ $booking_data_key ];
77 }
78 }
79 }
80 }
81 return $return_val;
82 }
83
84
85 /**
86 * Get booking details object from DB
87 *
88 * @param $booking_id - int
89 *
90 * @return mixed - booking details or false if not found
91 * Example:
92 * stdClass Object
93 * (
94 * [booking_id] => 26
95 * [trash] => 0
96 * [sync_gid] =>
97 * [is_new] => 0
98 * [status] =>
99 * [sort_date] => 2018-02-27 00:00:00
100 * [modification_date] => 2018-02-18 12:49:30
101 * [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
102 * [hash] => 0d55671fd055fd64423294f89d6b58e6
103 * [booking_type] => 3
104 * [remark] =>
105 * [cost] => 40.25
106 * [pay_status] => 151895097121.16
107 * [pay_request] => 0
108 * )
109 */
110 function wpbc_db_get_booking_details( $booking_id ){ //FixIn: 8.1.3.5
111
112 global $wpdb;
113
114 $slct_sql = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}booking WHERE booking_id = %d LIMIT 0,1", $booking_id );
115
116 $sql_results = $wpdb->get_row( $slct_sql );
117
118 if ( ! empty( $sql_results ) ) {
119 return $sql_results;
120 } else {
121 return false;
122 }
123 }
124
125
126 /**
127 * Get booking D a t e s from DB - array of objects
128 *
129 * @param $booking_id - int
130 *
131 * @return mixed - booking dates array or false if not found
132 *
133 */
134 function wpbc_db_get_booking_dates( $booking_id ){
135
136 global $wpdb;
137
138 $sql = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}bookingdates as dt WHERE dt.booking_id = %d ", $booking_id );
139
140 if ( class_exists( 'wpdev_bk_biz_l' ) ) {
141 $sql .= " ORDER BY booking_id, type_id, booking_date ";
142 } else {
143 $sql .= " ORDER BY booking_id, booking_date ";
144 }
145
146 $sql_results = $wpdb->get_results( $sql );
147
148 if ( ! empty( $sql_results ) ) {
149 return $sql_results;
150 } else {
151 return false;
152 }
153 }
154
155
156 /**
157 * Get booking modification date from DB
158 * @param $booking_id
159 *
160 * @return string
161 */
162 function wpbc_db_get_booking_modification_date( $booking_id ){ //FixIn: 8.0.1.7
163 global $wpdb;
164 $modification_date = ' ' . $wpdb->get_var( $wpdb->prepare( "SELECT modification_date FROM {$wpdb->prefix}booking WHERE booking_id = %d " , $booking_id ) );
165 return $modification_date;
166 }
167
168
169 /**
170 * Get user IP
171 *
172 * @return mixed|string
173 */
174 function wpbc_get_user_ip() {
175
176 if ( isset( $_SERVER['HTTP_CLIENT_IP'] ) ) {
177 $userIP = $_SERVER['HTTP_CLIENT_IP'];
178 } elseif ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
179 $userIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
180 } elseif ( isset( $_SERVER['HTTP_X_FORWARDED'] ) ) {
181 $userIP = $_SERVER['HTTP_X_FORWARDED'];
182 } elseif ( isset( $_SERVER['HTTP_FORWARDED_FOR'] ) ) {
183 $userIP = $_SERVER['HTTP_FORWARDED_FOR'];
184 } elseif ( isset( $_SERVER['HTTP_FORWARDED'] ) ) {
185 $userIP = $_SERVER['HTTP_FORWARDED'];
186 } elseif ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
187 $userIP = $_SERVER['REMOTE_ADDR'];
188 } else {
189 $userIP = "";
190 }
191 return $userIP;
192 }
193
194 /**
195 * Get IP of Server
196 *
197 * @return string
198 */
199 function wpbc_get_server_ip() { //FixIn: 9.8.14.3
200
201 $ip_address = '';
202 if ( array_key_exists( 'SERVER_ADDR', $_SERVER ) ) {
203 $ip_address = $_SERVER['SERVER_ADDR'];
204 } else if ( array_key_exists( 'LOCAL_ADDR', $_SERVER ) ) {
205 $ip_address = $_SERVER['LOCAL_ADDR'];
206 }
207
208 return $ip_address;
209 }
210
211 /**
212 * Get different Booking Fields as array for replace
213 *
214 * @param int $booking_id - ID of booking // 999
215 * @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~...
216 * @param int $booking_resource_id - booking resource type // 4
217 *
218 * @return array
219 *
220 * Example:
221 * [
222 * [booking_id] => 26
223 * [id] => 26
224 * [days_input_format] => 01.03.2018,02.03.2018,27.02.2018,28.02.2018
225 * [days_only_sql] => 2018-02-27,2018-02-28,2018-03-01,2018-03-02
226 * [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
227 * [check_in_date_sql] => 2018-02-27 00:00:00
228 * [check_out_date_sql] => 2018-03-02 00:00:00
229 * [dates] => 02/27/2018 - 03/02/2018
230 * [check_in_date] => 02/27/2018
231 * [check_out_date] => 03/02/2018
232 * [check_out_plus1day] => 03/03/2018
233 * [dates_count] => 4
234 * [days_count] => 4
235 * [nights_count] => 3
236 * [check_in_date_hint] => 02/27/2018
237 * [check_out_date_hint] => 03/02/2018
238 * [start_time_hint] => 00:00
239 * [end_time_hint] => 00:00
240 * [selected_dates_hint] => 02/27/2018, 02/28/2018, 03/01/2018, 03/02/2018
241 * [selected_timedates_hint] => 02/27/2018, 02/28/2018, 03/01/2018, 03/02/2018
242 * [selected_short_dates_hint] => 02/27/2018 - 03/02/2018
243 * [selected_short_timedates_hint] => 02/27/2018 - 03/02/2018
244 * [days_number_hint] => 4
245 * [nights_number_hint] => 3
246 * [siteurl] => http://beta
247 * [resource_title] => Apartment A
248 * [bookingtype] => Apartment A
249 * [remote_ip] => 127.0.0.1
250 * [user_agent] => Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0
251 * [request_url] => http://beta/wp-admin/post.php?post=1473&action=edit
252 * [current_date] => 02/18/2018
253 * [current_time] => 14:11
254 * [cost_hint] => 40.250 $
255 * [name] => Victoria
256 * [secondname] => vica
257 * [email] => vica@wpbookingcalendar.com
258 * [phone] => test booking
259 * [visitors] => 1
260 * [booking_resource_id] => 3
261 * [resource_id] => 3
262 * [type_id] => 3
263 * [type] => 3
264 * [resource] => 3
265 * [content] => '........'
266 * [moderatelink] => http://beta/wp-admin/admin.php?page=wpbc&view_mode=vm_listing&tab=actions&wh_booking_id=26
267 * [visitorbookingediturl] => http://beta/?booking_hash=0d55671fd055fd64423294f89d6b58e6
268 * [visitorbookingcancelurl] => http://beta/?booking_hash=0d55671fd055fd64423294f89d6b58e6&booking_cancel=1
269 * [visitorbookingpayurl] => http://beta/?booking_hash=0d55671fd055fd64423294f89d6b58e6&booking_pay=1
270 * [bookinghash] => 0d55671fd055fd64423294f89d6b58e6
271 * [db_cost] => 40.25
272 * [db_cost_hint] => 40.250 $
273 * [modification_date] => 2018-02-18 12:49:30
274 * [modification_year] => 2018
275 * [modification_month] => 02
276 * [modification_day] => 18
277 * [modification_hour] => 12
278 * [modification_minutes] => 49
279 * [modification_seconds] => 30
280 * ]
281 */
282 function wpbc_get_booking_different_params_arr( $booking_id, $formdata, $booking_resource_id = 1 ) {
283
284 $replace = array();
285
286 // Resources ///////////////////////////////////////////////////////////////
287 $bk_title = wpbc_get_resource_title( $booking_resource_id );
288
289
290 ////////////////////////////////////////////////////////////////////////////
291 // Dates Dif. Formats
292 ////////////////////////////////////////////////////////////////////////////
293
294 // -> '2023-10-09 12:00:01, 2023-10-09 20:00:02'
295 $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
296
297 $sql_dates_only = explode(',',$sql_dates_format);
298 $sql_days_only_array = array();
299 $days_as_in_form_array = array();
300 foreach ( $sql_dates_only as $sql_day_only ) {
301 $sql_days_only_array[] = trim( substr($sql_day_only, 0, 11 ) );
302 $days_as_in_form_array[] = date_i18n( "d.m.Y", strtotime( trim( substr($sql_day_only, 0, 11 ) ) ) );
303 }
304 $sql_days_only_array = array_unique( $sql_days_only_array );
305 sort( $sql_days_only_array );
306 $sql_days_only = implode( ',', $sql_days_only_array );
307
308 $days_as_in_form_array = array_unique( $days_as_in_form_array );
309 sort( $days_as_in_form_array );
310 $days_as_in_form = implode( ',', $days_as_in_form_array );
311
312 $sql_days_only_with_full_times = array();
313 foreach ( $sql_days_only_array as $sql_day ) {
314 $sql_days_only_with_full_times[] = $sql_day . ' 00:00:00';
315 }
316 $sql_days_only_with_full_times = implode(',', $sql_days_only_with_full_times );
317
318
319 if ( get_bk_option( 'booking_date_view_type' ) == 'short' ) {
320 $formated_booking_dates = wpbc_get_dates_short_format( $sql_dates_format );
321 } else {
322 $formated_booking_dates = wpbc_get_dates_comma_string_localized( $sql_dates_format );
323 }
324
325 $sql_dates_format_check_in_out = explode(',', $sql_dates_format );
326
327 $my_check_in_date = wpbc_get_dates_comma_string_localized( $sql_dates_format_check_in_out[0] );
328 $my_check_out_date = wpbc_get_dates_comma_string_localized( $sql_dates_format_check_in_out[ count( $sql_dates_format_check_in_out ) - 1 ] );
329
330 $my_check_out_plus1day = wpbc_datetime_localized( date( 'Y-m-d H:i:s'
331 , strtotime( $sql_dates_format_check_in_out[ count( $sql_dates_format_check_in_out ) - 1 ]
332 . " +1 day" )
333 ) );
334
335 $date_format = get_bk_option( 'booking_date_format');
336 $check_in_date_hint = wpbc_date_localized( $sql_days_only_array[0] );
337 $check_out_date_hint = wpbc_date_localized( $sql_days_only_array[ ( count( $sql_days_only_array ) - 1 ) ] );
338
339 //FixIn: 9.7.3.16
340 $cancel_date_hint = wpbc_datetime_localized( date( 'Y-m-d H:i:s'
341 , strtotime( '-14 days', strtotime( $sql_days_only_array[0] ) )
342 ) );
343 //FixIn: 10.0.0.31
344 $pre_checkin_date_hint = wpbc_datetime_localized( date( 'Y-m-d H:i:s'
345 , strtotime( '-' . intval( get_bk_option( 'booking_number_for_pre_checkin_date_hint' ) ) . ' days', strtotime( $sql_days_only_array[0] ) )
346 ) );
347
348 // Booking Times -------------------------------------------------------------------------------------------
349 $start_end_time = wpbc_get_times_in_form( $formdata, $booking_resource_id ); // false ||
350
351 if ( $start_end_time !== false ) {
352 $start_time = $start_end_time[0]; // array('00','00','01');
353 $end_time = $start_end_time[1]; // array('00','00','01');
354 } else {
355 $start_time = array('00','00','00');
356 $end_time = array('00','00','00');
357 }
358
359 //TODO: continue here with replacing date_i18n to wpbc_loc_ ...
360
361 $start_time_hint = wpbc_time_localized( implode( ':', $start_time ) );
362 $end_time_hint = wpbc_time_localized( implode( ':', $end_time ) );
363
364 //FixIn: 9.5.1.3
365 $check_in_date_sql = wpbc_date_localized( $sql_days_only_array[0], 'Y-m-d' );
366 $check_out_date_sql = wpbc_date_localized( $sql_days_only_array[ ( count( $sql_days_only_array ) - 1 ) ], 'Y-m-d' );
367
368 $start_time_sql = wpbc_time_localized( implode( ':', $start_time ), 'H:i' );
369 $end_time_sql = wpbc_time_localized( implode( ':', $end_time ) , 'H:i' );
370
371 ////////////////////////////////////////////////////////////////////////////
372
373
374 // Other ///////////////////////////////////////////////////////////////////
375 $replace[ 'booking_id' ] = $booking_id;
376 $replace[ 'id' ] = $replace[ 'booking_id' ];
377
378 $replace[ 'days_input_format' ] = $days_as_in_form; // 15.11.2023,16.11.2023,17.11.2023
379 $replace[ 'days_only_sql' ] = $sql_days_only; // 2023-11-15,2023-11-16,2023-11-17
380 $replace[ 'dates_sql' ] = $sql_dates_format; // 2016-07-28 16:00:01, 2016-07-28 18:00:02
381 $replace[ 'check_in_date_sql' ] = $sql_dates_format_check_in_out[0]; // 2016-07-28 16:00:01
382 $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
383 $replace[ 'dates' ] = $formated_booking_dates; // July 28, 2016 16:00 - July 28, 2016 18:00
384 $replace[ 'check_in_date' ] = $my_check_in_date; // July 28, 2016 16:00
385 $replace[ 'check_out_date' ] = $my_check_out_date; // July 28, 2016 18:00
386 $replace[ 'check_out_plus1day'] = $my_check_out_plus1day; // July 29, 2016 18:00
387 $replace[ 'dates_count' ] = count( $sql_days_only_array ); // 1
388 $replace[ 'days_count' ] = count( $sql_days_only_array ); // 1
389 $replace[ 'nights_count' ] = ( $replace[ 'days_count' ] > 1 ) ? ( $replace[ 'days_count' ] - 1 ) : $replace[ 'days_count' ]; // 1
390
391 //FixIn: 9.7.3.16
392 $replace[ 'cancel_date_hint' ] = $cancel_date_hint; // 11/11/2013
393 //FixIn: 10.0.0.31
394 $replace[ 'pre_checkin_date_hint' ] = $pre_checkin_date_hint; // 11/11/2013
395
396 $replace[ 'check_in_date_hint' ] = $check_in_date_hint; // 11/25/2013
397 $replace[ 'check_out_date_hint' ] = $check_out_date_hint; // 11/27/2013
398 $replace[ 'start_time_hint' ] = $start_time_hint; // 10:00
399 $replace[ 'end_time_hint' ] = $end_time_hint; // 12:00
400
401 //FixIn: 9.5.1.3
402 $replace['check_in_date_hint_sql'] = $check_in_date_sql; // 2023-03-04
403 $replace['check_out_date_hint_sql'] = $check_out_date_sql; // 2023-03-12
404 $replace['start_time_hint_sql'] = $start_time_sql; // 10:00
405 $replace['end_time_hint_sql'] = $end_time_sql; // 12:00
406
407 $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
408 $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
409 $replace['selected_short_dates_hint'] = wpbc_get_dates_short_format( $sql_days_only_with_full_times ); // 11/25/2013 - 11/27/2013
410 $replace['selected_short_timedates_hint'] = wpbc_get_dates_short_format( $sql_dates_format ); // 11/25/2013 10:00 - 11/27/2013 12:00
411 $replace[ 'days_number_hint' ] = $replace[ 'days_count' ]; // 3
412 $replace[ 'nights_number_hint' ] = $replace[ 'nights_count' ]; // 2
413 $replace[ 'siteurl' ] = htmlspecialchars_decode( '<a href="' . home_url() . '">' . home_url() . '</a>' );
414 $replace[ 'resource_title'] = wpbc_lang( $bk_title );
415 $replace[ 'bookingtype' ] = $replace[ 'resource_title'];
416 $replace[ 'remote_ip' ] = wpbc_get_user_ip(); // The IP address from which the user is viewing the current page.
417 $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.
418 $replace[ 'request_url' ] = (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : ''; // 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
419 $replace[ 'current_date' ] = date_i18n( get_bk_option( 'booking_date_format' ) );
420 $replace[ 'current_time' ] = date_i18n( get_bk_option( 'booking_time_format' ) );
421
422
423 // Form Fields /////////////////////////////////////////////////////////////
424 $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
425
426 foreach ( $booking_form_show_array['_all_fields_'] as $shortcode_name => $shortcode_value ) {
427
428 if ( ! isset( $replace[ $shortcode_name ] ) )
429 $replace[ $shortcode_name ] = $shortcode_value;
430 }
431 $replace[ 'content' ] = $booking_form_show_array['content'];
432
433 // Links ///////////////////////////////////////////////////////////////////
434 $replace[ 'moderatelink' ] = htmlspecialchars_decode(
435 // '<a href="' .
436 esc_url( wpbc_get_bookings_url() . '&view_mode=vm_listing&tab=actions&wh_booking_id=' . $booking_id )
437 // . '">' . __('here', 'booking') . '</a>'
438 );
439 $replace[ 'visitorbookingediturl' ] = apply_bk_filter( 'wpdev_booking_set_booking_edit_link_at_email', '[visitorbookingediturl]', $booking_id );
440 $replace[ 'visitorbookingslisting' ] = apply_bk_filter( 'wpdev_booking_set_booking_edit_link_at_email', '[visitorbookingslisting]', $booking_id ); //FixIn: 8.1.3.5.1
441 $replace[ 'visitorbookingcancelurl' ] = apply_bk_filter( 'wpdev_booking_set_booking_edit_link_at_email', '[visitorbookingcancelurl]', $booking_id );
442 $replace[ 'visitorbookingpayurl' ] = apply_bk_filter( 'wpdev_booking_set_booking_edit_link_at_email', '[visitorbookingpayurl]', $booking_id );
443 $replace[ 'bookinghash' ] = apply_bk_filter( 'wpdev_booking_set_booking_edit_link_at_email', '[bookinghash]', $booking_id );
444
445 // Cost ////////////////////////////////////////////////////////////////////
446 $replace[ 'db_cost' ] = apply_bk_filter( 'get_booking_cost_from_db', '', $booking_id );
447 $replace[ 'db_cost_hint' ] = wpbc_get_cost_with_currency_for_user( $replace[ 'db_cost' ], $booking_resource_id );
448
449 ////////////////////////////////////////////////////////////////////////////
450
451 //FixIn: 8.0.1.7
452 $modification_date = wpbc_db_get_booking_modification_date( $booking_id );
453
454 // 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.
455 $is_add_wp_timezone = true;
456 $modification_date = wpbc_datetime_localized( trim( $modification_date ), 'Y-m-d H:i:s', $is_add_wp_timezone );
457 $replace['modification_date'] = ' ' . $modification_date;
458 $modification_date = explode( ' ', $modification_date );
459 list( $replace['modification_year'], $replace['modification_month'], $replace['modification_day'] ) = explode( '-', $modification_date[0] );
460 list( $replace['modification_hour'], $replace['modification_minutes'], $replace['modification_seconds'] ) = explode( ':', $modification_date[1] );
461
462 //FixIn: 10.0.0.34
463 if ( ! empty( $replace['creation_date'] ) ) {
464
465 // 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.
466 $creation_date = wpbc_datetime_localized( trim( $replace['creation_date'] ), 'Y-m-d H:i:s', $is_add_wp_timezone );
467
468 $replace['creation_date'] = ' ' . $creation_date;
469 $creation_date = explode( ' ', $creation_date );
470 list( $replace['creation_year'], $replace['creation_month'], $replace['creation_day'] ) = explode( '-', $creation_date[0] );
471 list( $replace['creation_hour'], $replace['creation_minutes'], $replace['creation_seconds'] ) = explode( ':', $creation_date[1] );
472 }
473
474 return $replace;
475 }
476
477
478 /**
479 * Get additional parameters to the replace array for specific booking
480 *
481 * @param $replace
482 * @param $booking_id
483 * @param $bktype
484 * @param $formdata
485 *
486 * @return mixed
487 */
488 function wpbc_replace_params_for_booking_func( $replace, $booking_id, $bktype, $formdata ){
489 /*
490 $modification_date = wpbc_db_get_booking_modification_date( $booking_id );
491
492 // 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.
493 $is_add_wp_timezone = true;
494 $modification_date = wpbc_datetime_localized( trim( $modification_date ), 'Y-m-d H:i:s', $is_add_wp_timezone );
495
496 $replace['modification_date'] = ' ' . $modification_date;
497
498 $modification_date = explode( ' ', $modification_date );
499 list( $replace['modification_year'], $replace['modification_month'], $replace['modification_day'] ) = explode( '-', $modification_date[0] );
500 list( $replace['modification_hour'], $replace['modification_minutes'], $replace['modification_seconds'] ) = explode( ':', $modification_date[1] );
501 */
502
503 //FixIn: 8.4.2.11
504 if ( isset( $replace['rangetime'] ) ) {
505 $replace['rangetime'] = wpbc_time_slot_in_format( $replace['rangetime'] );
506 }
507 if ( isset( $replace['starttime'] ) ) {
508 $replace['starttime'] = wpbc_time_in_format( $replace['starttime'] );
509 }
510 if ( isset( $replace['endtime'] ) ) {
511 $replace['endtime'] = wpbc_time_in_format( $replace['endtime'] );
512 }
513
514 //FixIn: 8.2.1.25
515 $booking_data = wpbc_db_get_booking_details( $booking_id );
516
517 if ( ! empty( $booking_data ) ) {
518 foreach ( $booking_data as $booking_key => $booking_data ) {
519 if ( ! isset( $replace[ $booking_key ] ) ) {
520 $replace[ $booking_key ] = $booking_data;
521 }
522 }
523 }
524
525 // Set dates and times in correct format ---------------------------------------------------------------
526
527 $is_add_wp_timezone = true;
528
529 if ( ! empty( $replace['modification_date'] ) ) {
530
531 // 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.
532 $modification_date = wpbc_datetime_localized( trim( $replace['modification_date'] ), 'Y-m-d H:i:s', $is_add_wp_timezone );
533
534 $replace['modification_date'] = ' ' . $modification_date;
535 $modification_date = explode( ' ', $modification_date );
536 list( $replace['modification_year'], $replace['modification_month'], $replace['modification_day'] ) = explode( '-', $modification_date[0] );
537 list( $replace['modification_hour'], $replace['modification_minutes'], $replace['modification_seconds'] ) = explode( ':', $modification_date[1] );
538 }
539 //FixIn: 10.0.0.34
540 if ( ! empty( $replace['creation_date'] ) ) {
541
542 // 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.
543 $creation_date = wpbc_datetime_localized( trim( $replace['creation_date'] ), 'Y-m-d H:i:s', $is_add_wp_timezone );
544
545 $replace['creation_date'] = ' ' . $creation_date;
546 $creation_date = explode( ' ', $creation_date );
547 list( $replace['creation_year'], $replace['creation_month'], $replace['creation_day'] ) = explode( '-', $creation_date[0] );
548 list( $replace['creation_hour'], $replace['creation_minutes'], $replace['creation_seconds'] ) = explode( ':', $creation_date[1] );
549 }
550
551 return $replace;
552 }
553 add_filter( 'wpbc_replace_params_for_booking', 'wpbc_replace_params_for_booking_func', 10, 4 );
554
555
556 /**
557 * Replace shortcodes in string
558 *
559 * @param string $subject - string to manipulate
560 * @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, .... )
561 * @param mixed $replace_unknown_shortcodes - replace unknown params, if false, then no replace unknown params
562 * @return string
563 */
564 function wpbc_replace_booking_shortcodes( $subject, $replace_array , $replace_unknown_shortcodes = ' ' ) {
565
566 $defaults = array(
567 'ip' => wpbc_get_user_ip()
568 , 'blogname' => wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES )
569 , 'siteurl' => get_site_url()
570 );
571
572 $replace = wp_parse_args( $replace_array, $defaults );
573
574 foreach ( $replace as $replace_shortcode => $replace_value ) {
575
576 $subject = str_replace( array( '[' . $replace_shortcode . ']'
577 , '{' . $replace_shortcode . '}' )
578 , $replace_value
579 , $subject );
580 }
581
582 // Remove all shortcodes, which is not replaced early.
583 if ( $replace_unknown_shortcodes !== false )
584 $subject = preg_replace( '/[\s]{0,}[\[\{]{1}[a-zA-Z0-9.,-_]{0,}[\]\}]{1}[\s]{0,}/', $replace_unknown_shortcodes, $subject );
585
586
587 return $subject;
588 }
589
590
591
592 // </editor-fold>
593
594
595 // <editor-fold defaultstate="collapsed" desc=" == Get html preview of shortcode for Edit pages == " >
596
597 /**
598 * Get html preview of shortcode for Edit pages in Elementor and at Block editors
599 *
600 * @param $shortcode_type
601 * @param $attr
602 *
603 * @return string
604 */
605 function wpbc_get_preview_for_shortcode( $shortcode_type, $attr ) {
606
607 //FixIn: 9.9.0.39
608
609 return '<div style="border:2px dashed #ccc;text-align: center; padding:10px;display:flex;flex-flow:column wrap;justify-content: center;align-content: center;">
610 <div>WP Booking Calendar Shortcode</div>
611 <code>['.$shortcode_type.' ...]</code>
612 <div style="font-size:0.8em;">This is not a real preview. Publish the page to see it in action.</div>
613 </div>';
614 }
615 // </editor-fold>
616
617
618 // <editor-fold defaultstate="collapsed" desc=" == Get version Nums or Types == " >
619
620 /**
621 * Check if this demo website
622 *
623 * @return bool
624 */
625 function wpbc_is_this_demo() {
626
627 // return !true;
628 if ( ! class_exists( 'wpdev_bk_personal' ) ) {
629 return false; // If this is Booking Calendar Free version, then it's not the demo.
630 }
631
632 //FixIn: 7.2.1.17
633 if (
634 ( ( isset( $_SERVER['SCRIPT_FILENAME'] ) ) && ( strpos( $_SERVER['SCRIPT_FILENAME'], 'wpbookingcalendar.com' ) !== false ) )
635 || ( ( isset( $_SERVER['HTTP_HOST'] ) ) && ( strpos( $_SERVER['HTTP_HOST'], 'wpbookingcalendar.com' ) !== false ) )
636 ) {
637 return true;
638 } else {
639 return false;
640 }
641 }
642
643
644 /**
645 * Check if this Beta Demo website
646 *
647 * @return bool
648 */
649 function wpbc_is_this_beta() {
650
651 $is_beta = ( $_SERVER['HTTP_HOST'] === 'beta' );
652
653 return $is_beta;
654 }
655
656
657 /** Get Warning Text for Demo websites */
658 function wpbc_get_warning_text_in_demo_mode() {
659 // return '<div class="wpbc-error-message wpbc_demo_test_version_warning"><strong>Warning!</strong> Demo test version does not allow changes to these items.</div>'; //Old Style
660 return '<div class="wpbc-settings-notice notice-warning"><strong>Warning!</strong> Demo test version does not allow changes to these items.</div>';
661 }
662
663
664
665 function wpbc_get_version_type__and_mu(){
666 $version = 'free';
667 if ( class_exists( 'wpdev_bk_personal' ) ) $version = 'personal';
668 if ( class_exists( 'wpdev_bk_biz_s' ) ) $version = 'biz_s';
669 if ( class_exists( 'wpdev_bk_biz_m' ) ) $version = 'biz_m';
670 if ( class_exists( 'wpdev_bk_biz_l' ) ) $version = 'biz_l';
671 if ( class_exists('wpdev_bk_multiuser') ) $version = 'multiuser';
672 return $version;
673 }
674
675
676 function wpbc_get_plugin_version_type(){
677 $version = 'free';
678 if ( class_exists( 'wpdev_bk_personal' ) ) $version = 'personal';
679 if ( class_exists( 'wpdev_bk_biz_s' ) ) $version = 'biz_s';
680 if ( class_exists( 'wpdev_bk_biz_m' ) ) $version = 'biz_m';
681 if ( class_exists( 'wpdev_bk_biz_l' ) ) $version = 'biz_l';
682 return $version;
683 }
684
685
686 /**
687 * Check if user accidentially update Booking Calendar Paid version to Free
688 *
689 * @return bool
690 */
691 function wpbc_is_updated_paid_to_free() {
692
693 if ( ( wpbc_is_table_exists('bookingtypes') ) && ( ! class_exists('wpdev_bk_personal') ) )
694 return true;
695 else
696 return false;
697 }
698
699
700 function wpbc_get_ver_sufix() {
701 if( strpos( strtolower(WPDEV_BK_VERSION) , 'multisite') !== false ) {
702 $v_type = '-multi';
703 } else if( strpos( strtolower(WPDEV_BK_VERSION) , 'develop') !== false ) {
704 $v_type = '-dev';
705 } else {
706 $v_type = '';
707 }
708 $v = '';
709 if (class_exists('wpdev_bk_personal')) $v = 'ps'. $v_type;
710 if (class_exists('wpdev_bk_biz_s')) $v = 'bs'. $v_type;
711 if (class_exists('wpdev_bk_biz_m')) $v = 'bm'. $v_type;
712 if (class_exists('wpdev_bk_biz_l')) $v = 'bl'. $v_type;
713 if (class_exists('wpdev_bk_multiuser')) $v = '';
714 return $v ;
715 }
716
717
718 function wpbc_up_link() {
719 if ( ! wpbc_is_this_demo() )
720 $v = wpbc_get_ver_sufix();
721 else $v = '';
722 return 'https://wpbookingcalendar.com/' . ( ( empty($v) ) ? '' : 'upgrade-' . $v . '/' ) ;
723 }
724
725
726 /**
727 * Check if "Booking Manager" installed/activated and return version number
728 *
729 * @return string - 0 if not installed, otherwise version num
730 */
731 function wpbc_get_wpbm_version() {
732
733 if ( ! defined( 'WPBM_VERSION_NUM' ) ) {
734 return 0;
735 } else {
736 return WPBM_VERSION_NUM;
737 }
738 }
739
740
741 /**
742 * Get header info from this file, just for compatibility with WordPress 2.8 and older versions
743 *
744 * @param $file = WPBC_FILE
745 * @param $default_headers = array( 'Name' => 'Plugin Name', 'PluginURI' => 'Plugin URI', 'Version' => 'Version', 'Description' => 'Description', 'Author' => 'Author', 'AuthorURI' => 'Author URI', 'TextDomain' => 'Text Domain', 'DomainPath' => 'Domain Path' )
746 * @param $context = 'plugin'
747 *
748 * @return array
749 *
750 * Example:
751 * $plugin_data = wpbc_file__read_header_info( WPBC_FILE , array( 'Name' => 'Plugin Name', 'PluginURI' => 'Plugin URI', 'Version' => 'Version', 'Description' => 'Description', 'Author' => 'Author', 'AuthorURI' => 'Author URI', 'TextDomain' => 'Text Domain', 'DomainPath' => 'Domain Path' ) , 'plugin' );
752 */
753 function wpbc_file__read_header_info( $file, $default_headers, $context = '' ) {
754
755 $fp = fopen( $file, 'r' ); // We don't need to write to the file, so just open for reading.
756
757 $file_data = fread( $fp, 8192 ); // Pull only the first 8kiB of the file in.
758
759 fclose( $fp ); // PHP will close file handle, but we are good citizens.
760
761 if ( $context != '' ) {
762 $extra_headers = array(); //apply_filters( "extra_$context".'_headers', array() );
763
764 $extra_headers = array_flip( $extra_headers );
765 foreach ( $extra_headers as $key => $value ) {
766 $extra_headers[ $key ] = $key;
767 }
768 $all_headers = array_merge( $extra_headers, $default_headers );
769 } else {
770 $all_headers = $default_headers;
771 }
772
773 foreach ( $all_headers as $field => $regex ) {
774 preg_match( '/' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, ${$field});
775 if ( !empty( ${$field} ) )
776 ${$field} = trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', ${$field}[1] ));
777 else
778 ${$field} = '';
779 }
780
781 $file_data = compact( array_keys( $all_headers ) );
782
783 return $file_data;
784 }
785
786
787
788 /**
789 * Check if we need BLUR this section -- add CSS Class for specific versions
790 *
791 * Example: $is_blured = wpbc_is_blured( array( 'free', 'ps' ) ); // true in Free and Personal versions.
792 *
793 * @param $versions_arr
794 *
795 * @return void
796 */
797 function wpbc_is_blured( $versions_arr ){
798
799 $ver = wpbc_get_version_type__and_mu();
800
801 $is_blured = false;
802
803 switch ( $ver ) {
804 case 'free':
805 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'f', $versions_arr ) ) ) ? true : $is_blured;
806 break;
807 case 'personal':
808 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'ps', $versions_arr ) ) ) ? true : $is_blured;
809 break;
810 case 'biz_s':
811 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'bs', $versions_arr ) ) ) ? true : $is_blured;
812 break;
813 case 'biz_m':
814 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'bm', $versions_arr ) ) ) ? true : $is_blured;
815 break;
816 case 'biz_l':
817 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'bl', $versions_arr ) ) ) ? true : $is_blured;
818 break;
819 case 'multiuser':
820 $is_blured = ( ( in_array( $ver, $versions_arr ) ) || ( in_array( 'mu', $versions_arr ) ) ) ? true : $is_blured;
821 break;
822 default:
823 // Default
824 }
825 return $is_blured;
826 }
827
828
829 /**
830 * Echo Blur CSS Class for specific versions
831 *
832 * Example: wpbc_echo_blur(array('free','ps')); // Echo blur in Free and Personal versions.
833 *
834 * @param $versions_arr
835 *
836 * @return void
837 */
838 function wpbc_echo_blur( $versions_arr ){
839
840 $is_blured = wpbc_is_blured( $versions_arr );
841
842 if ( $is_blured ) {
843 echo 'wpbc_blur';
844 }
845 }
846
847
848 /**
849 * Show Upgrade Widget
850 *
851 * @param $id
852 * @param $params
853 *
854 * @return string if upgrade panel hided than returned ''
855 *
856 *
857 * Example:
858 * wpbc_get_up_notice('booking_weekdays_conditions', array(
859 * 'feature_link' => array( 'title' => 'feature', 'relative_url' => 'overview/#capacity' ),
860 * 'upgrade_link' => array( 'title' => 'Upgrade to Pro', 'relative_url' => 'features/#bk_news_section' ),
861 * 'versions' => 'Business Large, MultiUser versions',
862 * 'css' => 'transform: translate(0) translateY(120px);'
863 * ));
864 */
865 function wpbc_get__upgrade_notice__html_content( $id, $params ){
866
867 $defaults = array(
868 'feature_link' => array( 'title' => 'feature', 'relative_url' => 'overview/#capacity' ),
869 'upgrade_link' => array( 'title' => 'Upgrade to Pro', 'relative_url' => 'features/#bk_news_section' ),
870 'versions' => 'Business Large, MultiUser versions',
871 'css' => 'transform: translate(0) translateY(120px);',
872 'dismiss_css_class' => '',
873 'html_dismiss_btn' => ''
874 );
875 $params = wp_parse_args( $params, $defaults );
876
877 ob_start();
878
879 ?><div id="upgrade_notice_<?php echo esc_attr( $id ); ?>"
880 class="wpbc_widget_content wpbc_upgrade_widget <?php echo esc_attr( str_replace( array('.','#'), '', $params['dismiss_css_class'] ) ); ?>"
881 style="<?php echo esc_attr( $params['css'] ); ?>">
882 <div class="ui_container ui_container_toolbar ui_container_small wpbc_upgrade_widget_container">
883 <div class="ui_group ui_group__upgrade">
884 <div class="wpbc_upgrade_note wpbc_upgrade_theme_green">
885 <div>
886 <?php
887 printf( 'This %s is available in the %s. %s'
888 , '<a target="_blank" href="https://wpbookingcalendar.com/' . $params['feature_link']['relative_url'] . '">' . $params['feature_link']['title'] . '</a>'
889 , '<strong>' . $params['versions'] . '</strong>'
890 , '<a target="_blank" href="https://wpbookingcalendar.com/' . $params['upgrade_link']['relative_url'] . '">' . $params['upgrade_link']['title'] . '</a>'
891 );
892 ?>
893 </div>
894 <?php
895 // Dismiss button
896 echo $params['html_dismiss_btn'];
897 ?>
898 </div>
899 </div>
900 </div>
901 </div><?php
902
903 $html = ob_get_clean();
904
905 return $html ;
906 }
907
908
909
910 /**
911 * Get for showing Upgrade Widget Content and CSS class if needed to blur real content. If
912 *
913 * @param $params = array(
914 * 'id' => $id . '_' . 'weekdays_conditions',
915 * 'dismiss_css_class' => '.wpbc_dismiss_weekdays_conditions',
916 * 'blured_in_versions' => array( 'free', 'ps', 'bs', 'mu' ),
917 * 'feature_link' => array( 'title' => 'feature', 'relative_url' => 'overview/#advanced-days-selection' ),
918 * 'upgrade_link' => array( 'title' => 'Upgrade to Pro', 'relative_url' => 'features/#bk_news_section' ),
919 * 'versions' => 'Business Medium / Large, MultiUser versions',
920 * 'css' => 'transform: translate(0) translateY(120px);'
921 * )
922 *
923 * @return array(
924 * 'content' => $upgrade_panel_html,
925 * 'maybe_blur_css_class' => $blur_css_class
926 * )
927 *
928 * Example of usage:
929 *
930 * $upgrade_content_arr = wpbc_get_upgrade_widget( array(
931 * 'id' => $id . '_' . 'weekdays_conditions',
932 * 'dismiss_css_class' => '.wpbc_dismiss_weekdays_conditions',
933 * 'blured_in_versions' => array( 'free', 'ps', 'bs', 'mu' ),
934 * 'feature_link' => array( 'title' => 'feature', 'relative_url' => 'overview/#advanced-days-selection' ),
935 * 'upgrade_link' => array( 'title' => 'Upgrade to Pro', 'relative_url' => 'features/#bk_news_section' ),
936 * 'versions' => 'Business Medium / Large, MultiUser versions',
937 * 'css' => 'transform: translate(0) translateY(120px);'
938 * ) );
939 *
940 * echo $upgrade_content_arr['content'];
941 *
942 * // ... In real content ...
943 * <div class=" wpbc_dismiss_weekdays_conditions <?php echo esc_attr( $upgrade_content_arr['maybe_blur_css_class'] ); ?>">
944 * ...
945 * </div>
946 */
947 function wpbc_get_upgrade_widget( $params ) {
948
949 $defaults = array(
950 'id' => 'wpbc_random_' . round( microtime( true ) * 1000 ), //$id . '_' . 'weekdays_conditions',
951 'blured_in_versions' => array( 'free', 'ps', 'bs', 'bm', 'bl', 'mu' ),
952 'feature_link' => array( 'title' => 'feature', 'relative_url' => 'overview/#capacity' ),
953 'upgrade_link' => array( 'title' => 'Upgrade to Pro', 'relative_url' => 'features/#bk_news_section' ),
954 'versions' => 'Business Large, MultiUser versions',
955 'css' => 'transform: translate(0) translateY(120px);',
956 'dismiss_css_class' => '' //'.wpbc_random_' . round( microtime( true ) * 1000 ), //'.'.$id . '_' . 'weekdays_conditions'
957 );
958 $params = wp_parse_args( $params, $defaults );
959 $up_id = $params['id'];
960
961
962 $is_blured = wpbc_is_blured( $params['blured_in_versions'] );
963
964 $upgrade_panel_html = '';
965 $blur_css_class = '';
966
967 if ( $is_blured ) {
968
969 // ---------------------------------------------------------------------------------------------------------
970 // Is dismissed ?
971 // ---------------------------------------------------------------------------------------------------------
972 ob_start();
973 $is_upgrade_panel_visible = wpbc_is_dismissed( $up_id , array(
974 'title' => '<span aria-hidden="true" style="font-size: 28px;">&times;</span>',
975 'hint' => __( 'Dismiss', 'booking' ),
976 'class' => 'wpbc_panel_get_started_dismiss',
977 'css' => '',
978 'dismiss_css_class' => $params['dismiss_css_class']
979 ) );
980 $html_dismiss_btn = ob_get_clean();
981
982 // ---------------------------------------------------------------------------------------------------------
983 // Upgrade Widget
984 // ---------------------------------------------------------------------------------------------------------
985 if ( $is_upgrade_panel_visible ) {
986
987 $upgrade_panel_html = wpbc_get__upgrade_notice__html_content( $up_id, array(
988 'feature_link' => $params['feature_link'],
989 'upgrade_link' => $params['upgrade_link'],
990 'versions' => $params['versions'],
991 'css' => $params['css'],
992 'dismiss_css_class' => $params['dismiss_css_class'],
993 'html_dismiss_btn'=> $html_dismiss_btn
994 ) );
995 $blur_css_class = 'wpbc_blur';
996 } else {
997
998 ob_start();
999
1000 ?><script type="text/javascript">
1001 jQuery(document).ready(function(){
1002 setTimeout(function(){
1003 jQuery( '<?php echo esc_attr( $params['dismiss_css_class'] ); ?>' ).hide() ;
1004 }, 100);
1005 });
1006 </script><?php
1007
1008 $upgrade_panel_html = ob_get_clean();
1009 }
1010 }
1011
1012 $upgrade_content_arr = array(
1013 'content' => $upgrade_panel_html,
1014 'maybe_blur_css_class' => $blur_css_class
1015 );
1016
1017 return $upgrade_content_arr;
1018
1019 }
1020 // </editor-fold>
1021
1022
1023 // <editor-fold defaultstate="collapsed" desc=" == Calendar functions == " >
1024
1025 /**
1026 * Get maximum visible days in calendar
1027 *
1028 * @return int
1029 */
1030 function wpbc_get_max_visible_days_in_calendar(){
1031
1032 // Number of months to scroll
1033 $max_visible_days_in_calendar = get_bk_option( 'booking_max_monthes_in_calendar');
1034
1035 if ( false !== strpos( $max_visible_days_in_calendar, 'm' ) ) {
1036 //$max_visible_days_in_calendar = intval( str_replace( 'm', '', $max_visible_days_in_calendar ) ) * 31 ; //FixIn: 9.6.1.1
1037 //FixIn: 10.0.0.26
1038 $diff_days = strtotime( '+' . intval( str_replace( 'm', '', $max_visible_days_in_calendar ) ) . ' months', strtotime( 'now' ) ) - strtotime( 'now' );
1039 $max_visible_days_in_calendar = round( $diff_days / ( 60 * 60 * 24 ) ) + 1;
1040 } else {
1041 $max_visible_days_in_calendar = intval( str_replace( 'y', '', $max_visible_days_in_calendar ) ) * 365 + 15; //FixIn: 9.6.1.1
1042 }
1043
1044 return $max_visible_days_in_calendar;
1045 }
1046
1047
1048 /**
1049 * Parse {calendar ....} option parameter in Calendar | Booking form shortcode
1050 *
1051 * @param $bk_options
1052 *
1053 * @return array|false
1054 */
1055 function wpbc_parse_calendar_options( $bk_options ) {
1056
1057 if ( empty( $bk_options ) ) {
1058 return false;
1059 }
1060 /* $matches structure:
1061 * Array
1062 (
1063 [0] => Array
1064 (
1065 [0] => {calendar months="6" months_num_in_row="2" width="341px" cell_height="48px"},
1066 [1] => calendar
1067 [2] => months="6" months_num_in_row="2" width="341px" cell_height="48px"
1068 )
1069
1070 [1] => Array
1071 (
1072 [0] => {select-day condition="weekday" for="5" value="3"},
1073 [1] => select-day
1074 [2] => condition="weekday" for="5" value="3"
1075 )
1076 .....
1077 )
1078 */
1079
1080 $pattern_to_search='%\s*{([^\s]+)\s*([^}]+)\s*}\s*[,]?\s*%';
1081
1082 preg_match_all( $pattern_to_search, $bk_options, $matches, PREG_SET_ORDER );
1083
1084 foreach ( $matches as $value ) {
1085 if ( $value[1] == 'calendar' ) {
1086 $paramas = $value[2];
1087 $paramas = trim( $paramas );
1088 $paramas = explode( ' ', $paramas );
1089 $options = array();
1090 foreach ( $paramas as $vv ) {
1091 if ( ! empty( $vv ) ) {
1092 $vv = trim( $vv );
1093 $vv = explode( '=', $vv );
1094 if ( ( isset( $vv[0] ) ) && ( isset( $vv[1] ) ) ) {
1095 $options[ $vv[0] ] = trim( $vv[1] );
1096 }
1097 }
1098 }
1099 if ( count( $options ) == 0 ) {
1100 return false;
1101 } else {
1102 return $options;
1103 }
1104 }
1105 }
1106
1107 return false; // We are not have the "calendar" options in the shortcode
1108 }
1109
1110
1111
1112 /**
1113 * Parse {calendar ....} option parameter in Calendar | Booking form shortcode
1114 *
1115 * @param $bk_options
1116 *
1117 * @return array|false
1118 */
1119 function wpbc_parse_calendar_options__aggregate_param( $bk_options ) { //FixIn: 9.8.15.10
1120
1121 if ( empty( $bk_options ) ) {
1122 return false;
1123 }
1124 /* $matches structure:
1125 $matches = [
1126 0 = [
1127 0 = "{aggregate type=bookings_only}"
1128 1 = "aggregate"
1129 2 = "type=bookings_only"
1130 ]
1131 ]
1132 */
1133
1134 $pattern_to_search='%\s*{([^\s]+)\s*([^}]+)\s*}\s*[,]?\s*%';
1135
1136 preg_match_all( $pattern_to_search, $bk_options, $matches, PREG_SET_ORDER );
1137
1138 foreach ( $matches as $value ) {
1139 if ( $value[1] == 'aggregate' ) {
1140 $paramas = $value[2];
1141 $paramas = trim( $paramas );
1142 $paramas = explode( ' ', $paramas );
1143 $options = array();
1144 foreach ( $paramas as $vv ) {
1145 if ( ! empty( $vv ) ) {
1146 $vv = trim( $vv );
1147 $vv = explode( '=', $vv );
1148 if ( ( isset( $vv[0] ) ) && ( isset( $vv[1] ) ) ) {
1149 $options[ $vv[0] ] = trim( $vv[1] );
1150 }
1151 }
1152 }
1153 if ( count( $options ) == 0 ) {
1154 return false;
1155 } else {
1156 return $options;
1157 }
1158 }
1159 }
1160
1161 return false; // We are not have the "calendar" options in the shortcode
1162 }
1163
1164 // </editor-fold>
1165
1166
1167 // <editor-fold defaultstate="collapsed" desc=" == Files functions == " >
1168
1169 // Get array of images - icons inside of this directory
1170 function wpbc_dir_list ($directories) {
1171
1172 // create an array to hold directory list
1173 $results = array();
1174
1175 if (is_string($directories)) $directories = array($directories);
1176 foreach ($directories as $dir) {
1177 if ( is_dir( $dir ) ) {
1178 $directory = $dir;
1179 } else {
1180 $directory = WPBC_PLUGIN_DIR . $dir;
1181 }
1182
1183 if ( file_exists( $directory ) ) { //FixIn: 5.4.5
1184 // create a handler for the directory
1185 $handler = @opendir($directory);
1186 if ($handler !== false) {
1187 // keep going until all files in directory have been read
1188 while ($file = readdir($handler)) {
1189
1190 // if $file isn't this directory or its parent,
1191 // add it to the results array
1192 if ($file != '.' && $file != '..' && ( strpos($file, '.css' ) !== false ) )
1193 $results[] = array($file, /* WPBC_PLUGIN_URL .*/ $dir . $file, ucfirst(strtolower( str_replace('.css', '', $file))) );
1194 }
1195
1196 // tidy up: close the handler
1197 closedir($handler);
1198 }
1199 }
1200 }
1201 // done!
1202 return $results;
1203 }
1204
1205
1206 /**
1207 * Check if such file exist or not.
1208 *
1209 * @param string $path - relative path to file (relative to plugin folder).
1210 * @return boolean true | false
1211 */
1212 function wpbc_is_file_exist( $path ) {
1213
1214 if ( file_exists( trailingslashit( WPBC_PLUGIN_DIR ) . ltrim( $path, '/\\' ) ) ) // check if this file exist
1215 return true;
1216 else
1217 return false;
1218 }
1219
1220
1221 /**
1222 * Count the number of bytes of a given string.
1223 * Input string is expected to be ASCII or UTF-8 encoded.
1224 * Warning: the function doesn't return the number of chars
1225 * in the string, but the number of bytes.
1226 * See http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
1227 * for information on UTF-8.
1228 *
1229 * @param string $str The string to compute number of bytes
1230 *
1231 * @return The length in bytes of the given string.
1232 */
1233 function wpbc_get_bytes_from_str( $str ) {
1234 // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
1235 // Number of characters in string
1236 $strlen_var = strlen( $str );
1237
1238 $d = 0; // string bytes counter
1239
1240 // Iterate over every character in the string, escaping with a slash or encoding to UTF-8 where necessary
1241 for ( $c = 0; $c < $strlen_var; ++ $c ) {
1242 $ord_var_c = ord( $str[$c] ); //FixIn: 2.0.17.1
1243 switch ( true ) {
1244 case(($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)): // characters U-00000000 - U-0000007F (same as ASCII)
1245 $d ++;
1246 break;
1247 case(($ord_var_c & 0xE0) == 0xC0): // characters U-00000080 - U-000007FF, mask 110XXXXX
1248 $d += 2;
1249 break;
1250 case(($ord_var_c & 0xF0) == 0xE0): // characters U-00000800 - U-0000FFFF, mask 1110XXXX
1251 $d += 3;
1252 break;
1253 case(($ord_var_c & 0xF8) == 0xF0): // characters U-00010000 - U-001FFFFF, mask 11110XXX
1254 $d += 4;
1255 break;
1256 case(($ord_var_c & 0xFC) == 0xF8): // characters U-00200000 - U-03FFFFFF, mask 111110XX
1257 $d += 5;
1258 break;
1259 case(($ord_var_c & 0xFE) == 0xFC): // characters U-04000000 - U-7FFFFFFF, mask 1111110X
1260 $d += 6;
1261 break;
1262 default:
1263 $d ++;
1264 }
1265 }
1266 return $d;
1267 }
1268
1269
1270 // </editor-fold>
1271
1272
1273 // <editor-fold defaultstate="collapsed" desc=" == URL functions == " >
1274
1275 /**
1276 * Get absolute URL to relative plugin path.
1277 * Possibly to load minified version of file, if its exist
1278 * @param string $path - path
1279 * @return string
1280 */
1281 function wpbc_plugin_url( $path ) {
1282
1283 return trailingslashit( WPBC_PLUGIN_URL ) . ltrim( $path, '/\\' );
1284
1285 }
1286
1287 // Set URL from absolute to relative (starting from /)
1288 function wpbc_set_relative_url( $url ){
1289
1290 $url = esc_url_raw($url);
1291
1292 $url_path = parse_url($url, PHP_URL_PATH);
1293 $url_path = ( empty($url_path) ? $url : $url_path );
1294
1295 $url = trim($url_path, '/');
1296 return '/' . $url;
1297 }
1298
1299 /**
1300 * Get Relative URL
1301 *
1302 * @param $maybe_absolute_link
1303 *
1304 * @return string
1305 */
1306 function wpbc_make_link_relative( $maybe_absolute_link ) {
1307
1308 if ( $maybe_absolute_link == get_option( 'siteurl' ) ) {
1309 $maybe_absolute_link = '/';
1310 }
1311
1312 $maybe_absolute_link = '/' . trim( wp_make_link_relative( $maybe_absolute_link ), '/' );
1313
1314 return $maybe_absolute_link;
1315 }
1316
1317 /**
1318 * Get Absolute URL (check for languages)
1319 *
1320 * @param $maybe_relative_link
1321 *
1322 * @return string
1323 */
1324 function wpbc_make_link_absolute( $maybe_relative_link ){
1325
1326 if ( ( $maybe_relative_link != home_url() ) && ( strpos( $maybe_relative_link, 'http' ) !== 0 ) ) {
1327
1328 $maybe_relative_link = wpbc_lang( $maybe_relative_link ); //FixIn: 8.4.5.1
1329
1330 $maybe_relative_link = home_url() . '/' . trim( wp_make_link_relative( $maybe_relative_link ), '/' ); //FixIn: 7.0.1.20
1331 }
1332
1333 return esc_js( $maybe_relative_link );
1334 }
1335
1336
1337 /**
1338 * Redirect browser to a specific page
1339 *
1340 * @param string $url - URL of page to redirect
1341 */
1342 function wpbc_redirect( $url ) {
1343
1344 $url = wpbc_make_link_absolute( $url );
1345
1346 $url = html_entity_decode( esc_url( $url ) );
1347
1348 echo '<script type="text/javascript">';
1349 echo 'window.location.href="'.$url.'";';
1350 echo '</script>';
1351 echo '<noscript>';
1352 echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
1353 echo '</noscript>';
1354 }
1355
1356 // </editor-fold>
1357
1358
1359 // <editor-fold defaultstate="collapsed" desc=" == Get Admin Menu URLs == " >
1360
1361 /**
1362 * Check if we edit or create a new page in WordPress ?
1363 * @return bool
1364 */
1365 function wpbc_is_on_edit_page() {
1366
1367 //FixIn: 9.9.0.39
1368
1369 if ( ( ! empty( $GLOBALS['pagenow'] ) ) && ( is_admin() ) ) {
1370 if (
1371 ( 'post.php' === $GLOBALS['pagenow'] ) // Edit - Post / Page
1372 || ( 'post-new.php' === $GLOBALS['pagenow'] ) // Add New - Post / Page
1373 || ( ( 'admin-ajax.php' === $GLOBALS['pagenow'] ) && ( ! empty( $_REQUEST['action'] ) ) && ( 'elementor_ajax' === $_REQUEST['action'] ) ) // Elementor Edit page - Ajax
1374 ) {
1375 return true;
1376 }
1377 }
1378
1379 return false;
1380 }
1381
1382
1383 /**
1384 * Get URL to specific Admin Menu page
1385 *
1386 * @param string $menu_type - { booking | add | resources | settings }
1387 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
1388 * @param boolean $is_old - { default: true }
1389 * @return string - URL to menu
1390 */
1391 function wpbc_get_menu_url( $menu_type, $is_absolute_url = true, $is_old = true) {
1392
1393 $is_old = false;
1394
1395 switch ( $menu_type) {
1396
1397 case 'booking': // Bookings
1398 case 'bookings':
1399 case 'booking-listing':
1400 case 'bookings-listing':
1401 case 'listing':
1402 case 'overview':
1403 case 'calendar-overview':
1404 case 'timeline':
1405 $link = 'wpbc';
1406 break;
1407
1408 case 'add': // Add New Booking
1409 case 'add-bookings':
1410 case 'add-booking':
1411 case 'new':
1412 case 'new-bookings':
1413 case 'new-booking':
1414 $link = 'wpbc-new';
1415 break;
1416
1417 case 'availability':
1418 $link = 'wpbc-availability';
1419 break;
1420
1421 case 'price':
1422 $link = 'wpbc-prices';
1423 break;
1424
1425 case 'resources': // Resources
1426 case 'booking-resources':
1427 $link = 'wpbc-resources';
1428 break;
1429
1430 case 'settings': // Settings
1431 case 'options':
1432 $link = 'wpbc-settings';
1433 break;
1434
1435 default: // Bookings
1436 $link = 'wpbc';
1437 break;
1438 }
1439
1440 if ( $is_absolute_url ) {
1441 $link = admin_url( 'admin.php' ) . '?page=' . $link ;
1442 }
1443
1444 return $link;
1445 }
1446
1447 // -----------------------------------------------------------------------------------------------------------------
1448
1449 /**
1450 * Get URL of Booking Listing or Calendar Overview page
1451 *
1452 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
1453 * @param boolean $is_old - { default: true }
1454 * @return string - URL to menu
1455 */
1456 function wpbc_get_bookings_url( $is_absolute_url = true, $is_old = true ) {
1457 return wpbc_get_menu_url( 'booking', $is_absolute_url, $is_old );
1458 }
1459
1460 /**
1461 * Get URL of Booking > Availability page
1462 *
1463 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
1464 * @param boolean $is_old - { default: true }
1465 * @return string - URL to menu
1466 */
1467 function wpbc_get_availability_url( $is_absolute_url = true, $is_old = true ) {
1468 return wpbc_get_menu_url( 'availability', $is_absolute_url, $is_old );
1469 }
1470
1471 /**
1472 * Get URL of Booking > Availability page
1473 *
1474 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
1475 * @param boolean $is_old - { default: true }
1476 * @return string - URL to menu
1477 */
1478 function wpbc_get_price_url( $is_absolute_url = true, $is_old = true ) {
1479 return wpbc_get_menu_url( 'price', $is_absolute_url, $is_old );
1480 }
1481
1482 /**
1483 * Get URL of Booking > Add booking page
1484 *
1485 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
1486 * @param boolean $is_old - { default: true }
1487 * @return string - URL to menu
1488 */
1489 function wpbc_get_new_booking_url( $is_absolute_url = true, $is_old = true ) {
1490 return wpbc_get_menu_url( 'add', $is_absolute_url, $is_old );
1491 }
1492
1493 /**
1494 * Get URL of Booking > Resources page
1495 *
1496 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
1497 * @param boolean $is_old - { default: true }
1498 * @return string - URL to menu
1499 */
1500 function wpbc_get_resources_url( $is_absolute_url = true, $is_old = true ) {
1501 return wpbc_get_menu_url( 'resources', $is_absolute_url, $is_old );
1502 }
1503
1504 /**
1505 * Get URL of Booking > Settings page
1506 *
1507 * @param boolean $is_absolute_url - Absolute or relative url { default: true }
1508 * @param boolean $is_old - { default: true }
1509 * @return string - URL to menu
1510 */
1511 function wpbc_get_settings_url( $is_absolute_url = true, $is_old = true ) {
1512 return wpbc_get_menu_url( 'settings', $is_absolute_url, $is_old );
1513 }
1514
1515 // -----------------------------------------------------------------------------------------------------------------
1516
1517 /**
1518 * Check if this Booking Listing or Calendar Overview page
1519 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
1520 * @return boolean true | false
1521 */
1522 function wpbc_is_bookings_page( $server_param = 'REQUEST_URI' ) {
1523 // Old
1524 if ( ( is_admin() ) &&
1525 ( strpos($_SERVER[ $server_param ],'wpdev-booking.phpwpdev-booking') !== false ) &&
1526 ( strpos($_SERVER[ $server_param ],'wpdev-booking.phpwpdev-booking-reservation') === false )
1527 ) {
1528 return true;
1529 }
1530 // New
1531 if ( ( is_admin() ) &&
1532 ( strpos($_SERVER[ $server_param ],'page=wpbc') !== false ) &&
1533 ( strpos($_SERVER[ $server_param ],'page=wpbc-') === false )
1534 ) {
1535 return true;
1536 }
1537 return false;
1538 }
1539
1540 /**
1541 * Check if this Booking > Add booking page
1542 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
1543 * @return boolean true | false
1544 */
1545 function wpbc_is_new_booking_page( $server_param = 'REQUEST_URI' ) {
1546 // Old
1547 if ( ( is_admin() ) &&
1548 ( strpos($_SERVER[ $server_param ],'wpdev-booking.phpwpdev-booking-reservation') !== false )
1549 ) {
1550 return true;
1551 }
1552 // New
1553 if ( ( is_admin() ) &&
1554 ( strpos($_SERVER[ $server_param ],'page=wpbc-new') !== false )
1555 ) {
1556 return true;
1557 }
1558 return false;
1559 }
1560
1561 /**
1562 * Check if this WP Booking Calendar > Settings > Booking Form page
1563 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
1564 * @return boolean true | false
1565 */
1566 function wpbc_is_settings_form_page( $server_param = 'REQUEST_URI' ) {
1567
1568 if ( ( is_admin() ) &&
1569 ( strpos($_SERVER[ $server_param ],'page=wpbc-settings') !== false ) &&
1570 (
1571 ( strpos($_SERVER[ $server_param ],'&tab=form') !== false )
1572 || ( ( class_exists( 'wpdev_bk_multiuser' ) ) && ( ! empty( $_REQUEST['tab'] ) ) && ( 'form' === $_REQUEST['tab'] ) ) // Regular user overwrite settings
1573 )
1574 ) {
1575 return true;
1576 }
1577 return false;
1578 }
1579
1580 /**
1581 * Check if this Booking > Availability page
1582 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
1583 * @return boolean true | false
1584 */
1585 function wpbc_is_availability_page( $server_param = 'REQUEST_URI' ) {
1586
1587 // New
1588 if ( ( is_admin() ) &&
1589 ( strpos($_SERVER[ $server_param ],'page=wpbc-availability') !== false )
1590 ) {
1591 return true;
1592 }
1593 return false;
1594 }
1595
1596
1597 /**
1598 * Check if this Booking > Customize page
1599 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
1600 * @return boolean true | false
1601 */
1602 function wpbc_is_customize_plugin_page( $server_param = 'REQUEST_URI' ) { //FixIn: 9.8.0.1
1603
1604 // New
1605 if ( ( is_admin() ) &&
1606 ( strpos($_SERVER[ $server_param ],'page=wpbc-customize_plugin') !== false )
1607 ) {
1608 return true;
1609 }
1610 return false;
1611 }
1612
1613
1614 // -----------------------------------------------------------------------------------------------------------------
1615
1616 /**
1617 * Check if this Booking > Resources page
1618 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
1619 * @return boolean true | false
1620 */
1621 function wpbc_is_resources_page( $server_param = 'REQUEST_URI' ) {
1622
1623 // Old
1624 if ( ( is_admin() ) &&
1625 ( strpos($_SERVER[ $server_param ],'wpdev-booking.phpwpdev-booking-resources') !== false )
1626 ) {
1627 return true;
1628 }
1629 // New
1630 if ( ( is_admin() ) &&
1631 ( strpos($_SERVER[ $server_param ],'page=wpbc-resources') !== false )
1632 ) {
1633 return true;
1634 }
1635 return false;
1636 }
1637
1638 /**
1639 * Check if this Booking > Settings page
1640 * @param string $server_param - 'REQUEST_URI' | 'HTTP_REFERER' Default: 'REQUEST_URI'
1641 * @return boolean true | false
1642 */
1643 function wpbc_is_settings_page( $server_param = 'REQUEST_URI' ) {
1644
1645 // Old
1646 if ( ( is_admin() ) &&
1647 ( strpos($_SERVER[ $server_param ],'wpdev-booking.phpwpdev-booking-option') !== false )
1648 ) {
1649 return true;
1650 }
1651 // New
1652 if ( ( is_admin() ) &&
1653 ( strpos($_SERVER[ $server_param ],'page=wpbc-settings') !== false )
1654 ) {
1655 return true;
1656 }
1657 return false;
1658 }
1659
1660
1661 // -----------------------------------------------------------------------------------------------------------------
1662
1663
1664 /**
1665 * Transform the REQESTS parameters (GET and POST) into URL
1666 *
1667 * @param $page_param
1668 * @param array $exclude_params
1669 * @param $only_these_parameters
1670 * @return
1671 */
1672 function wpbc_get_params_in_url( $page_param , $exclude_params = array(), $only_these_parameters = false, $is_escape_url = true, $only_get = false ){ //FixIn: 8.0.1.101 //Fix: $is_escape_url = false
1673
1674 $exclude_params[] = 'page';
1675 $exclude_params[] = 'post_type';
1676
1677 if ( isset( $_GET['page'] ) )
1678 $page_param = $_GET['page'];
1679
1680 $get_paramaters = array( 'page' => $page_param );
1681
1682 if ( $only_get )
1683 $check_params = $_GET;
1684 else
1685 $check_params = $_REQUEST;
1686 //debuge($check_params);
1687 foreach ( $check_params as $prm_key => $prm_value ) {
1688
1689 // Skip parameters arrays, like $_GET['rvaluation_to'] = Array ( [0] => 6, [1] => 14, [2] => 14 )
1690 if (
1691 ( is_string( $prm_value ) )
1692 || ( is_numeric( $prm_value ) )
1693 ) {
1694
1695 if ( strlen( $prm_value ) > 1000 ) { // Check about TOOO long parameters, if it exist then reset it.
1696 $prm_value = '';
1697 }
1698
1699 if ( ! in_array( $prm_key, $exclude_params ) )
1700 if ( ( $only_these_parameters === false ) || ( in_array( $prm_key, $only_these_parameters ) ) )
1701 $get_paramaters[ $prm_key ] = $prm_value;
1702 }
1703 }
1704 //debuge($exclude_params);
1705 $url = admin_url( add_query_arg( $get_paramaters , 'admin.php' ) );
1706
1707 if ( $is_escape_url )
1708 $url = esc_url_raw( $url ); //FixIn: 8.1.1.7
1709 // $url = esc_url( $url );
1710
1711 return $url;
1712
1713 /* // Old variant:
1714 if ( isset( $_GET['page'] ) ) $page_param = $_GET['page'];
1715
1716 $url_start = 'admin.php?page=' . $page_param . '&';
1717 $exclude_params[] = 'page';
1718 foreach ( $_REQUEST as $prm_key => $prm_value ) {
1719
1720 if ( !in_array( $prm_key, $exclude_params ) )
1721 if ( ($only_these_parameters === false) || ( in_array( $prm_key, $only_these_parameters ) ) )
1722
1723 $url_start .= $prm_key . '=' . $prm_value . '&';
1724
1725 }
1726 $url_start = substr( $url_start, 0, -1 );
1727
1728 return $url_start;
1729 */
1730 }
1731
1732
1733 // </editor-fold>
1734
1735
1736 // <editor-fold defaultstate="collapsed" desc=" == Can I Load JavaScript Files == " >
1737
1738 function wpbc_can_i_load_on__edit_new_post_page() {
1739
1740 if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
1741 return false;
1742 }
1743
1744
1745 $pages_where_load = array( 'post-new.php', 'page-new.php', 'post.php', 'page.php', 'widgets.php', 'customize.php' );
1746
1747 if ( in_array( basename( $_SERVER['PHP_SELF'] ), $pages_where_load ) ) {
1748 return true;
1749 }
1750
1751 return false;
1752 }
1753
1754
1755 function wpbc_can_i_load_on__searchable_resources_page() {
1756
1757 if (
1758 ( isset( $_REQUEST['page'] ) ) && ( $_REQUEST['page'] == 'wpbc-resources' )
1759 && ( isset( $_REQUEST['tab'] ) ) && ( $_REQUEST['tab'] == 'searchable_resources' )
1760 ) {
1761 return true;
1762 }
1763
1764 return false;
1765 }
1766
1767
1768 function wpbc_can_i_load_on__resources_page() {
1769
1770 if (
1771 ( isset( $_REQUEST['page'] ) ) && ( $_REQUEST['page'] == 'wpbc-resources' )
1772 ) {
1773 return true;
1774 }
1775
1776 return false;
1777 }
1778
1779
1780 /**
1781 * Can I load scripts on this page for 'shortcode_config'
1782 *
1783 * @return bool
1784 */
1785 function wpbc_can_i_load_on_this_page__shortcode_config() {
1786
1787 if (
1788 wpbc_can_i_load_on__edit_new_post_page()
1789 || (
1790 wpbc_can_i_load_on__resources_page()
1791 && ( ! wpbc_can_i_load_on__searchable_resources_page() )
1792 )
1793 ){
1794 return true;
1795 } else {
1796 return false;
1797 }
1798 }
1799
1800 /**
1801 * Can I load scripts on this page? Loaded only at ../admin.php?page=wpbc-resources&tab=searchable_resources
1802 *
1803 * @return bool
1804 */
1805 function wpbc_can_i_load_on_this_page__modal_search_options() {
1806
1807 if ( wpbc_can_i_load_on__searchable_resources_page() ){
1808 return true;
1809 } else {
1810 return false;
1811 }
1812 }
1813
1814 // </editor-fold>
1815
1816
1817 // <editor-fold defaultstate="collapsed" desc=" == Admin Top Bar == " >
1818
1819 function wpbc_add__booking_menu__in__admin_top_bar(){
1820 global $wp_admin_bar;
1821
1822 $current_user = wpbc_get_current_user();
1823
1824 $curr_user_role = get_bk_option( 'booking_user_role_booking' );
1825 $level = 10;
1826 if ($curr_user_role == 'administrator') $level = 10;
1827 else if ($curr_user_role == 'editor') $level = 7;
1828 else if ($curr_user_role == 'author') $level = 2;
1829 else if ($curr_user_role == 'contributor') $level = 1;
1830 else if ($curr_user_role == 'subscriber') $level = 0;
1831
1832 $is_super_admin = apply_bk_filter('multiuser_is_user_can_be_here', false, 'only_super_admin');
1833 if ( ( ($current_user->user_level < $level) && (! $is_super_admin) ) || !is_admin_bar_showing() ) return;
1834
1835
1836 $update_count = wpbc_db_get_number_new_bookings();
1837
1838 $title = 'Booking Calendar';//__('Booking Calendar' ,'booking'); //FixIn: 9.1.3.3
1839 $update_title = ''// '<img src="'.WPBC_PLUGIN_URL .'/assets/img/icon-16x16.png" style="height: 16px;vertical-align: sub;" />&nbsp;'
1840 . $title;
1841
1842
1843
1844 $is_user_activated = apply_bk_filter('multiuser_is_current_user_active', true ); //FixIn: 6.0.1.17
1845 if ( ( $update_count > 0) && ( $is_user_activated ) ) {
1846 $update_count_title = "&nbsp;<span class='booking-count bk-update-count' style='background: #f0f0f1;color: #2c3338;display: inline;padding: 2px 5px;font-weight: 600;border-radius: 10px;'>"
1847 . number_format_i18n($update_count)
1848 . "</span>" ; //id='booking-count'
1849 $update_title .= $update_count_title;
1850 }
1851
1852 $link_bookings = wpbc_get_bookings_url();
1853 $link_res = wpbc_get_resources_url();
1854 $link_settings = wpbc_get_settings_url();
1855
1856 //FixIn: 9.8.15.9
1857 $wp_admin_bar->add_menu(
1858 array(
1859 'id' => 'bar_wpbc',
1860 'title' => $update_title ,
1861 'href' => wpbc_get_bookings_url()
1862 )
1863 );
1864
1865 $wp_admin_bar->add_menu(
1866 array(
1867 'id' => 'bar_wpbc_bookings',
1868 'title' => __( 'Bookings', 'booking' ),
1869 'href' => wpbc_get_bookings_url(),
1870 'parent' => 'bar_wpbc',
1871 )
1872 );
1873 $wp_admin_bar->add_menu(
1874 array(
1875 'id' => 'bar_wpbc_booking_listing',
1876 'title' => __( 'Booking Listing', 'booking' ),
1877 'href' => wpbc_get_bookings_url() . '&view_mode=vm_listing',
1878 'parent' => 'bar_wpbc_bookings',
1879 )
1880 );
1881 $wp_admin_bar->add_menu(
1882 array(
1883 'id' => 'bar_wpbc_calendar_overview',
1884 'title' => __( 'Calendar Overview', 'booking' ),
1885 'href' => wpbc_get_bookings_url() . '&view_mode=vm_calendar',
1886 'parent' => 'bar_wpbc_bookings',
1887 )
1888 );
1889
1890
1891 $curr_user_role_settings = get_bk_option( 'booking_user_role_settings' );
1892 $level = 10;
1893 if ($curr_user_role_settings == 'administrator') $level = 10;
1894 else if ($curr_user_role_settings == 'editor') $level = 7;
1895 else if ($curr_user_role_settings == 'author') $level = 2;
1896 else if ($curr_user_role_settings == 'contributor') $level = 1;
1897 else if ($curr_user_role_settings == 'subscriber') $level = 0;
1898
1899 if ( ( ($current_user->user_level < $level) && (! $is_super_admin) ) || !is_admin_bar_showing() ) return;
1900
1901 // Booking > Add booking page
1902 $wp_admin_bar->add_menu(
1903 array(
1904 'id' => 'bar_wpbc_new',
1905 'title' => __( 'Add booking', 'booking' ),
1906 'href' => wpbc_get_new_booking_url(),
1907 'parent' => 'bar_wpbc',
1908 )
1909 );
1910
1911 // Booking > Availability page
1912 $wp_admin_bar->add_menu(
1913 array(
1914 'id' => 'bar_wpbc_availability',
1915 'title' => __( 'Availability', 'booking' ),
1916 'href' => wpbc_get_availability_url(),
1917 'parent' => 'bar_wpbc',
1918 )
1919 );
1920 $wp_admin_bar->add_menu(
1921 array(
1922 'id' => 'bar_wpbc_days_availability',
1923 'title' => __( 'Days Availability', 'booking' ),
1924 'href' => wpbc_get_availability_url() ,
1925 'parent' => 'bar_wpbc_availability'
1926 )
1927 );
1928 if ( class_exists( 'wpdev_bk_biz_m' ) ){
1929 $wp_admin_bar->add_menu(
1930 array(
1931 'id' => 'bar_wpbc_seasons_availability',
1932 'title' => __( 'Season Availability', 'booking' ),
1933 'href' => wpbc_get_availability_url() . '&tab=season_availability',
1934 'parent' => 'bar_wpbc_availability'
1935 )
1936 );
1937
1938 $wp_admin_bar->add_menu(
1939 array(
1940 'id' => 'bar_wpbc_seasons_filters',
1941 'title' => __( 'Seasons', 'booking' ),
1942 'href' => wpbc_get_availability_url() . '&tab=filter',
1943 'parent' => 'bar_wpbc_availability'
1944 )
1945 );
1946 }
1947 if ( wpbc_is_mu_user_can_be_here( 'only_super_admin' ) )
1948 $wp_admin_bar->add_menu(
1949 array(
1950 'id' => 'bar_wpbc_general_availability',
1951 'title' => __( 'General Availability', 'booking' ),
1952 'href' => wpbc_get_settings_url() . '&scroll_to_section=wpbc_general_settings_availability_tab',
1953 'parent' => 'bar_wpbc_availability'
1954 )
1955 );
1956
1957 // Booking > Prices page
1958 if ( class_exists( 'wpdev_bk_biz_m' ) ){
1959
1960 $wp_admin_bar->add_menu(
1961 array(
1962 'id' => 'bar_wpbc_prices',
1963 'title' => __( 'Prices', 'booking' ),
1964 'href' => wpbc_get_price_url(),
1965 'parent' => 'bar_wpbc',
1966 )
1967 );
1968 $wp_admin_bar->add_menu(
1969 array(
1970 'id' => 'bar_wpbc_daily_costs',
1971 'title' => __('Daily Costs','booking'),
1972 'href' => wpbc_get_price_url() . '&tab=cost',
1973 'parent' => 'bar_wpbc_prices',
1974 )
1975 );
1976 $wp_admin_bar->add_menu(
1977 array(
1978 'id' => 'bar_wpbc_cost_advanced',
1979 'title' => __('Form Options Costs','booking'),
1980 'href' => wpbc_get_price_url() . '&tab=cost_advanced',
1981 'parent' => 'bar_wpbc_prices',
1982 )
1983 );
1984 if ( class_exists( 'wpdev_bk_biz_l' ) ){
1985 $wp_admin_bar->add_menu(
1986 array(
1987 'id' => 'bar_wpbc_coupons',
1988 'title' => __('Discount Coupons','booking'),
1989 'href' => wpbc_get_price_url() . '&tab=coupons',
1990 'parent' => 'bar_wpbc_prices',
1991 )
1992 );
1993 }
1994 $wp_admin_bar->add_menu(
1995 array(
1996 'id' => 'bar_wpbc_seasons_costs',
1997 'title' => __( 'Seasons', 'booking' ),
1998 'href' => wpbc_get_price_url() . '&tab=filter',
1999 'parent' => 'bar_wpbc_prices'
2000 )
2001 );
2002 $wp_admin_bar->add_menu(
2003 array(
2004 'id' => 'bar_wpbc_costs_payment_gateways',
2005 'title' => __( 'Payment Setup', 'booking' ),
2006 'href' => wpbc_get_settings_url() . '&tab=payment',
2007 'parent' => 'bar_wpbc_prices'
2008 )
2009 );
2010
2011 }
2012
2013 //Booking > Resources page
2014 $wp_admin_bar->add_menu(
2015 array(
2016 'id' => 'bar_wpbc_resources',
2017 'title' => ( ( class_exists( 'wpdev_bk_personal' ) ) ? __( 'Resources', 'booking' ) : __( 'Resource', 'booking' ) ),
2018 'href' => $link_res,
2019 'parent' => 'bar_wpbc',
2020 )
2021 );
2022 $wp_admin_bar->add_menu(
2023 array(
2024 'id' => 'bar_wpbc_resources_general',
2025 'title' => ( ( class_exists( 'wpdev_bk_personal' ) ) ? __( 'Resources', 'booking' ) : __( 'Resource', 'booking' ) ),
2026 'href' => $link_res,
2027 'parent' => 'bar_wpbc_resources',
2028 )
2029 );
2030
2031 if ( class_exists( 'wpdev_bk_biz_l' ) )
2032 $wp_admin_bar->add_menu(
2033 array(
2034 'id' => 'bar_wpbc_resources_searchable',
2035 'title' => __( 'Search Resources Setup', 'booking' ),//__( 'Searchable Resources', 'booking' ),//__( 'Search Availability', 'booking' ),
2036 'href' => $link_res . '&tab=searchable_resources',
2037 'parent' => 'bar_wpbc_resources'
2038 )
2039 );
2040
2041 // if ($is_super_admin)
2042 // if ( class_exists( 'wpdev_bk_biz_l' ) )
2043 // $wp_admin_bar->add_menu(
2044 // array(
2045 // 'id' => 'bar_wpbc_resources_search',
2046 // 'title' => __( 'Search Form / Results', 'booking' ),
2047 // 'href' => $link_settings . '&tab=search',
2048 // 'parent' => 'bar_wpbc_resources'
2049 // )
2050 // );
2051
2052
2053 //Booking > Settings General page
2054
2055 $wp_admin_bar->add_menu(
2056 array(
2057 'id' => 'bar_wpbc_settings',
2058 'title' => __( 'Settings', 'booking' ),
2059 'href' => wpbc_get_settings_url(),
2060 'parent' => 'bar_wpbc',
2061 )
2062 );
2063
2064 if ($is_super_admin)
2065 $wp_admin_bar->add_menu(
2066 array(
2067 'id' => 'bar_wpbc_settings_general',
2068 'title' => __( 'General', 'booking' ),
2069 'href' => $link_settings,
2070 'parent' => 'bar_wpbc_settings'
2071 )
2072 );
2073 $wp_admin_bar->add_menu(
2074 array(
2075 'id' => 'bar_wpbc_settings_form',
2076 'title' => __( 'Booking Form', 'booking' ),
2077 'href' => $link_settings . '&tab=form',
2078 'parent' => 'bar_wpbc_settings'
2079 )
2080 );
2081 $wp_admin_bar->add_menu(
2082 array(
2083 'id' => 'bar_wpbc_settings_email',
2084 'title' => __( 'Emails', 'booking' ),
2085 'href' => $link_settings . '&tab=email',
2086 'parent' => 'bar_wpbc_settings'
2087 )
2088 );
2089 $wp_admin_bar->add_menu(
2090 array(
2091 'id' => 'bar_wpbc_settings_sync',
2092 'title' => __( 'Sync', 'booking' ), //FixIn: 8.0
2093 'href' => $link_settings . '&tab=sync',
2094 'parent' => 'bar_wpbc_settings'
2095 )
2096 );
2097 if ( class_exists( 'wpdev_bk_biz_s' ) )
2098 $wp_admin_bar->add_menu(
2099 array(
2100 'id' => 'bar_wpbc_settings_payment',
2101 'title' => __( 'Payment Setup', 'booking' ),
2102 'href' => $link_settings . '&tab=payment',
2103 'parent' => 'bar_wpbc_settings'
2104 )
2105 );
2106
2107 if ( ( class_exists( 'wpdev_bk_biz_l' ) ) && ( wpbc_is_mu_user_can_be_here( 'only_super_admin' ) ) )
2108 $wp_admin_bar->add_menu(
2109 array(
2110 'id' => 'bar_wpbc_settings_search',
2111 'title' => __( 'Search Form / Results', 'booking' ),
2112 'href' => $link_settings . '&tab=search',
2113 'parent' => 'bar_wpbc_settings'
2114 )
2115 );
2116 if ( class_exists( 'wpdev_bk_multiuser' ) )
2117 if ($is_super_admin)
2118 $wp_admin_bar->add_menu(
2119 array(
2120 'id' => 'bar_wpbc_settings_users',
2121 'title' => __( 'Users', 'booking' ),
2122 'href' => $link_settings . '&tab=users',
2123 'parent' => 'bar_wpbc_settings'
2124 )
2125 );
2126 }
2127 add_action( 'admin_bar_menu', 'wpbc_add__booking_menu__in__admin_top_bar', 70 ); // Add - TOP Bar - in admin menu
2128
2129
2130 // </editor-fold>
2131
2132
2133 // <editor-fold defaultstate="collapsed" desc=" == Footer == " >
2134
2135 function wpbc_show_booking_footer(){
2136
2137 $wpdev_copyright_adminpanel = get_bk_option( 'booking_wpdev_copyright_adminpanel' ); // check
2138
2139 $message = '';
2140
2141
2142
2143 if ( ( 'Off' !== $wpdev_copyright_adminpanel ) && ( ! wpbc_is_this_demo() ) ) {
2144
2145 /*
2146 $message .= '<a target="_blank" href="https://wpbookingcalendar.com/">Booking Calendar</a> ' . __('version' ,'booking') . ' ' . WP_BK_VERSION_NUM ;
2147
2148 $message .= ' | '. sprintf(__('Add your %s on %swordpress.org%s, if you enjoyed by this plugin.' ,'booking'),
2149 '<a target="_blank" href="http://goo.gl/tcrrpK" >&#9733;&#9733;&#9733;&#9733;&#9733;</a>',
2150 '<a target="_blank" href="http://goo.gl/tcrrpK" >',
2151 '</a>' );
2152 */
2153 $message .= sprintf( __( 'If you like %s please leave us a %s rating. A huge thank you in advance!', 'booking' )
2154 , '<strong>Booking Calendar</strong> ' . WP_BK_VERSION_NUM
2155 , '<a href="https://wordpress.org/support/plugin/booking/reviews/#new-post" target="_blank" title="' . esc_attr__( 'Thanks :)', 'booking' ) . '">'
2156 . '&#9733;&#9733;&#9733;&#9733;&#9733;'
2157 . '</a>'
2158 );
2159 }
2160
2161
2162 if ( ! empty( $message ) ) {
2163
2164 echo '<div id="wpbc-footer" style="position:absolute;bottom:40px;text-align:left;width:95%;font-size:0.9em;text-shadow:0 1px 0 #fff;margin:0;color:#888;">' . $message . '</div>';
2165
2166 ?><script type="text/javascript">
2167 jQuery( document ).ready( function (){
2168 jQuery( '#wpfooter' ).append( jQuery( '#wpbc-footer' ) );
2169 } );
2170 </script><?php
2171 }
2172 }
2173
2174 // </editor-fold>
2175
2176
2177 // <editor-fold defaultstate="collapsed" desc=" == P a g i n a t i o n o f T a b l e L i s t i n g == " >
2178
2179 /**
2180 * Show P a g i n a t i o n
2181 *
2182 * @param int $summ_number_of_items - total number of items
2183 * @param int $active_page_num - number of activated page
2184 * @param int $num_items_per_page - number of items per page
2185 * @param array $only_these_parameters - array of keys to exclude from links
2186 * @param string $url_sufix - usefule for anchor to HTML section with specific ID, Example: '#my_section'
2187 */
2188 function wpbc_show_pagination( $summ_number_of_items, $active_page_num, $num_items_per_page , $only_these_parameters = false, $url_sufix = '' ) {
2189
2190 if ( empty( $num_items_per_page ) ) {
2191 $num_items_per_page = '10';
2192 }
2193
2194 $pages_number = ceil( $summ_number_of_items / $num_items_per_page );
2195 if ( $pages_number < 2 )
2196 return;
2197
2198 //Fix: 5.1.4 - Just in case we are having tooo much resources, then we need to show all resources - and its empty string
2199 if ( ( isset($_REQUEST['wh_booking_type'] ) ) && ( strlen($_REQUEST['wh_booking_type']) > 1000 ) ) {
2200 $_REQUEST['wh_booking_type'] = '';
2201 }
2202
2203 // First parameter will overwriten by $_GET['page'] parameter
2204 $bk_admin_url = wpbc_get_params_in_url( wpbc_get_bookings_url( false, false ), array('page_num'), $only_these_parameters );
2205
2206
2207 ?>
2208 <span class="wpdevelop wpbc-pagination">
2209 <div class="container-fluid">
2210 <div class="row">
2211 <div class="col-sm-12 text-center control-group0">
2212 <nav class="btn-toolbar">
2213 <div class="btn-group wpbc-no-margin" style="float:none;">
2214
2215 <?php if ( $pages_number > 1 ) { ?>
2216 <a class="button button-secondary <?php echo ( $active_page_num == 1 ) ? ' disabled' : ''; ?>"
2217 href="<?php echo $bk_admin_url; ?>&page_num=<?php if ($active_page_num == 1) { echo $active_page_num; } else { echo ($active_page_num-1); } echo $url_sufix; ?>">
2218 <?php _e('Prev', 'booking'); ?>
2219 </a>
2220 <?php }
2221
2222 /** Number visible pages (links) that linked to active page, other pages skipped by "..." */
2223 $num_closed_steps = 3;
2224
2225 for ( $pg_num = 1; $pg_num <= $pages_number; $pg_num++ ) {
2226
2227 if ( ! (
2228 ( $pages_number > ( $num_closed_steps * 4) )
2229 && ( $pg_num > $num_closed_steps )
2230 && ( ( $pages_number - $pg_num + 1 ) > $num_closed_steps )
2231 && ( abs( $active_page_num - $pg_num ) > $num_closed_steps )
2232 ) ) {
2233 ?> <a class="button button-secondary <?php if ($pg_num == $active_page_num ) echo ' active'; ?>"
2234 href="<?php echo $bk_admin_url; ?>&page_num=<?php echo $pg_num; echo $url_sufix; ?>">
2235 <?php echo $pg_num; ?>
2236 </a><?php
2237
2238 if ( ( $pages_number > ( $num_closed_steps * 4) )
2239 && ( ($pg_num+1) > $num_closed_steps )
2240 && ( ( $pages_number - ( $pg_num + 1 ) ) > $num_closed_steps )
2241 && ( abs($active_page_num - ( $pg_num + 1 ) ) > $num_closed_steps )
2242 ) {
2243 echo ' <a class="button button-secondary disabled" href="javascript:void(0);">...</a> ';
2244 }
2245 }
2246 }
2247
2248 if ( $pages_number > 1 ) { ?>
2249 <a class="button button-secondary <?php echo ( $active_page_num == $pages_number ) ? ' disabled' : ''; ?>"
2250 href="<?php echo $bk_admin_url; ?>&page_num=<?php if ($active_page_num == $pages_number) { echo $active_page_num; } else { echo ($active_page_num+1); } echo $url_sufix; ?>">
2251 <?php _e('Next', 'booking'); ?>
2252 </a>
2253 <?php } ?>
2254
2255 </div>
2256 </nav>
2257 </div>
2258 </div>
2259 </div>
2260 </span>
2261 <?php
2262 }
2263
2264 // </editor-fold>
2265
2266
2267 // <editor-fold defaultstate="collapsed" desc=" == DB - cheking if table, field or index exists == " >
2268
2269 /**
2270 * Check if table exist
2271 *
2272 * @global $wpdb
2273 * @param string $tablename
2274 * @return 0|1
2275 */
2276 function wpbc_is_table_exists( $tablename ) {
2277
2278 global $wpdb;
2279
2280 if (
2281 ( ( ! empty( $wpdb->prefix ) ) && ( strpos( $tablename, $wpdb->prefix ) === false ) )
2282 || ( '_' == $wpdb->prefix ) //FixIn: 8.7.3.16
2283 ) {
2284 $tablename = $wpdb->prefix . $tablename;
2285 }
2286
2287 if ( 0 ) {
2288 $sql_check_table = $wpdb->prepare( "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE (TABLE_SCHEMA = '{$wpdb->dbname}') AND (TABLE_NAME = %s);", $tablename );
2289
2290 $res = $wpdb->get_results( $sql_check_table );
2291
2292 return count( $res );
2293
2294 } else {
2295
2296 $sql_check_table = $wpdb->prepare("SHOW TABLES LIKE %s" , $tablename ); //FixIn: 5.4.3
2297
2298 $res = $wpdb->get_results( $sql_check_table );
2299
2300 return count( $res );
2301 }
2302
2303 }
2304
2305
2306 //FixIn: 10.0.0.1
2307 /**
2308 * Check if we are in playground.wordpress.net , where used 'sqlite' DB
2309 *
2310 * @return bool
2311 */
2312 function wpbc_is_this_wp_playground_db(){
2313
2314 return false;
2315
2316 if (
2317 ( ( function_exists( 'sqlite_open' ) ) || ( class_exists( 'SQLite3' ) ) )
2318 && ( ! class_exists( 'wpdev_bk_personal' ) )
2319 ){
2320 return true;
2321 } else {
2322 return false;
2323 }
2324 }
2325
2326
2327 /**
2328 * Check if table exist
2329 *
2330 * @global $wpdb
2331 * @param string $tablename
2332 * @param $fieldname
2333 * @return 0|1
2334 */
2335 function wpbc_is_field_in_table_exists( $tablename , $fieldname) {
2336
2337 if ( wpbc_is_this_wp_playground_db() ) {
2338 return 1; // Probably we are in playground.wordpress.net --> So then all such fields already was created //FixIn: 10.0.0.1
2339 }
2340
2341 global $wpdb;
2342
2343 if (
2344 ( ( ! empty( $wpdb->prefix ) ) && ( strpos( $tablename, $wpdb->prefix ) === false ) )
2345 || ( '_' == $wpdb->prefix ) //FixIn: 8.7.3.16
2346 ) {
2347 $tablename = $wpdb->prefix . $tablename;
2348 }
2349
2350 if ( 0 ) {
2351
2352 $sql_check_table = "SELECT * FROM INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='{$tablename}' AND TABLE_SCHEMA='{$wpdb->dbname}' ";
2353
2354 $res = $wpdb->get_results( $sql_check_table );
2355
2356 foreach ( $res as $fld ) {
2357 if ( $fieldname === $fld->COLUMN_NAME ) {
2358 return 1;
2359 }
2360 }
2361
2362 } else {
2363
2364 $sql_check_table = "SHOW COLUMNS FROM {$tablename}";
2365
2366 $res = $wpdb->get_results( $sql_check_table );
2367
2368 foreach ( $res as $fld ) {
2369 if ( $fld->Field == $fieldname ) {
2370 return 1;
2371 }
2372 }
2373 }
2374
2375 return 0;
2376 }
2377
2378
2379 /**
2380 * Check if index exist
2381 *
2382 * @global $wpdb
2383 * @param string $tablename
2384 * @param $fieldindex
2385 * @return 0|1
2386 */
2387 function wpbc_is_index_in_table_exists( $tablename , $fieldindex) {
2388 global $wpdb;
2389 if ( (! empty($wpdb->prefix) ) && ( strpos($tablename, $wpdb->prefix) === false ) ) $tablename = $wpdb->prefix . $tablename ;
2390 $sql_check_table = $wpdb->prepare("SHOW INDEX FROM {$tablename} WHERE Key_name = %s", $fieldindex );
2391 $res = $wpdb->get_results( $sql_check_table );
2392 if (count($res)>0) return 1;
2393 else return 0;
2394 }
2395
2396 // </editor-fold>
2397
2398
2399 // <editor-fold defaultstate="collapsed" desc=" == Security: Escaping & Sanitizing == " >
2400
2401
2402 /**
2403 * Sanitize $_GET, $_POST, $_REQUEST text parameters //FixIn: 10.0.0.12
2404 *
2405 * @param $value
2406 * @param $keep_newlines bool
2407 *
2408 * @return string
2409 */
2410 function wpbc_clean_text_value( $value , $keep_newlines = false ){
2411
2412 if ( $keep_newlines ) {
2413 $value_cleaned = sanitize_textarea_field( $value );
2414 } else {
2415 $value_cleaned = sanitize_text_field( $value );
2416 }
2417
2418 return $value_cleaned;
2419 }
2420
2421
2422 // check $value for injection here
2423 function wpbc_clean_parameter( $value, $is_escape_sql = true ) {
2424
2425 $value = preg_replace( '/<[^>]*>/', '', $value ); // clean any tags
2426 $value = str_replace( '<', ' ', $value );
2427 $value = str_replace( '>', ' ', $value );
2428 $value = strip_tags( $value );
2429
2430 //FixIn: 9.7.4.1 - escape coded html/xss // Escape any XSS injection
2431 $value = sanitize_textarea_field( $value );
2432 $value = sanitize_textarea_field( html_entity_decode( $value ) ); // If we have field converted to 'Unicode Hex Character Code', then we make HTML decode firstly (html_entity_decode) and then make sanitizing
2433
2434 if ( $is_escape_sql ) {
2435 $value = esc_sql( $value ); // Clean SQL injection //FixIn: 9.7.4.2
2436 }
2437
2438 $value = esc_textarea( $value ); //FixIn: 7.1.1.2
2439
2440 return $value;
2441 }
2442
2443
2444 /**
2445 * Check paramter if it number or comma separated list of numbers
2446 *
2447 * @global type $wpdb
2448 * @param string $value
2449 * @return string
2450 *
2451 * Exmaple:
2452 wpbc_clean_digit_or_csd( '12,a,45,9' ) => '12,0,45,9'
2453 * or
2454 wpbc_clean_digit_or_csd( '10a' ) => '10
2455 * or
2456 wpbc_clean_digit_or_csd( array( '12,a,45,9', '10a' ) ) => array ( '12,0,45,9', '10' )
2457 */
2458 function wpbc_clean_digit_or_csd( $value ) { //FixIn:6.2.1.4
2459
2460 if ( $value === '' ) return $value;
2461
2462
2463 if ( is_array( $value ) ) {
2464 foreach ( $value as $key => $check_value ) {
2465 $value[ $key ] = wpbc_clean_digit_or_csd( $check_value );
2466 }
2467 return $value;
2468 }
2469
2470 $value = str_replace( ';', ',', $value );
2471
2472 $array_of_nums = explode(',', $value);
2473
2474 $result = array();
2475 foreach ($array_of_nums as $check_element) {
2476
2477 $result[] = intval( $check_element ); //FixIn: 8.0.2.10
2478 }
2479 $result = implode(',', $result );
2480 return $result;
2481 }
2482
2483
2484 /**
2485 * Cehck about Valid date, like 2016-07-20 or digit
2486 *
2487 * @param string $value
2488 * @return string or int
2489 */
2490 function wpbc_clean_digit_or_date( $value ) { //FixIn:6.2.1.4
2491
2492 if ( $value === '' ) return $value;
2493
2494 if ( preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $value ) ) {
2495
2496 return $value; // Date is valid in format: 2016-07-20
2497 } else {
2498 return intval( $value );
2499 }
2500
2501 }
2502
2503
2504 /**
2505 * Check about Valid dat in format '2024-05-08' otherwise return ''
2506 *
2507 * @param string $value
2508 *
2509 * @return string date or '' if date was not valie
2510 */
2511 function wpbc_clean_date( $value ) {
2512
2513 if (
2514 ( ! empty( $value ) )
2515 && ( preg_match( "/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $value ) )
2516 ){
2517 return $value; // Date is valid in format: 2024-05-08
2518 }
2519
2520 return ''; // Date not Valid
2521 }
2522
2523
2524 /**
2525 * Escape any XSS injection from values in booking form
2526 *
2527 * @param array $structured_booking_data_arr [...]
2528 *
2529 * @return array [...]
2530 */
2531 function wpbc_escape_any_xss_in_arr( $structured_booking_data_arr ) {
2532
2533 foreach ( $structured_booking_data_arr as $field_name => $field_value ) {
2534
2535 if ( is_array( $field_value ) ) {
2536
2537 $structured_booking_data_arr[ $field_name ] = wpbc_escape_any_xss_in_arr( $field_value );
2538
2539 } else {
2540 $is_escape_sql = false; // Do not replace %
2541 $field_value_cleaned = wpbc_escape_any_xss_in_string( $field_value, $is_escape_sql );
2542 $structured_booking_data_arr[ $field_name ] = $field_value_cleaned;
2543 }
2544 }
2545
2546 return $structured_booking_data_arr;
2547 }
2548
2549
2550 /**
2551 * Escape any XSS injection from string values
2552 *
2553 * @param string $field_value
2554 *
2555 * @return string
2556 */
2557 function wpbc_escape_any_xss_in_string( $field_value, $is_escape_sql = true ) {
2558
2559 $field_value_cleaned = wpbc_clean_parameter( $field_value, $is_escape_sql );
2560 $field_value_cleaned = str_replace( '%', '&#37;', $field_value_cleaned ); // clean % in form, because can be problems with SQL prepare function
2561
2562 return $field_value_cleaned;
2563 }
2564
2565
2566 function wpbc_esc_like( $value_trimmed ) {
2567
2568 global $wpdb;
2569 if ( method_exists( $wpdb ,'esc_like' ) )
2570 return $wpdb->esc_like( $value_trimmed ); // Its require minimum WP 4.0.0
2571 else
2572 return addcslashes( $value_trimmed, '_%\\' ); // Direct implementation from $wpdb->esc_like(
2573 }
2574
2575
2576 /**
2577 * Sanitize term to Slug format (no spaces, lowercase).
2578 * urldecode - reverse munging of UTF8 characters.
2579 *
2580 * @param mixed $value
2581 * @return string
2582 */
2583 function wpbc_get_slug_format( $value ) {
2584 return urldecode( sanitize_title( $value ) );
2585 }
2586
2587
2588 /**
2589 * Clean user string for using in SQL LIKE statement - append to LIKE sql
2590 *
2591 * @param string $value - to clean
2592 * @return string - escaped
2593 * Exmaple:
2594 * $search_escaped_like_title = wpbc_clean_like_string_for_append_in_sql_for_db( $input_var );
2595 *
2596 * $where_sql = " WHERE title LIKE ". $search_escaped_like_title ." ";
2597 */
2598 function wpbc_clean_like_string_for_append_in_sql_for_db( $value ) {
2599 global $wpdb;
2600
2601 $value_trimmed = trim( stripslashes( $value ) );
2602 $wild = '%';
2603 $like = $wild . wpbc_esc_like( $value_trimmed ) . $wild;
2604 $sql = $wpdb->prepare( "'%s'", $like );
2605
2606 return $sql;
2607
2608
2609 /* Help:
2610 * First half of escaping for LIKE special characters % and _ before preparing for MySQL.
2611 * Use this only before wpdb::prepare() or esc_sql(). Reversing the order is very bad for security.
2612 *
2613 * Example Prepared Statement:
2614 *
2615 * $wild = '%';
2616 * $find = 'only 43% of planets';
2617 * $like = $wild . wpbc_esc_like( $find ) . $wild;
2618 * $sql = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_content LIKE '%s'", $like );
2619 *
2620 * Example Escape Chain:
2621 *
2622 * $sql = esc_sql( wpbc_esc_like( $input ) );
2623 */
2624
2625 }
2626
2627
2628 /**
2629 * Clean string for using in SQL LIKE requests inside single quotes: WHERE title LIKE '%". $escaped_search_title ."%'
2630 * Replaced _ to \_ % to \% \ to \\
2631 * @param string $value - to clean
2632 * @return string - escaped
2633 * Exmaple:
2634 * $search_escaped_like_title = wpbc_clean_like_string_for_db( $input_var );
2635 *
2636 * $where_sql = " WHERE title LIKE '%". $search_escaped_like_title ."%' ";
2637 *
2638 * Important! Use SINGLE quotes after in SQL query: LIKE '%".$data."%'
2639 */
2640 function wpbc_clean_like_string_for_db( $value ){
2641
2642 global $wpdb;
2643
2644 $value_trimmed = trim( stripslashes( $value ) );
2645
2646 $value_trimmed = wpbc_esc_like( $value_trimmed );
2647
2648 $value = trim( $wpdb->prepare( "'%s'", $value_trimmed ) , "'" );
2649
2650 return $value;
2651
2652 /* Help:
2653 * First half of escaping for LIKE special characters % and _ before preparing for MySQL.
2654 * Use this only before wpdb::prepare() or esc_sql(). Reversing the order is very bad for security.
2655 *
2656 * Example Prepared Statement:
2657 *
2658 * $wild = '%';
2659 * $find = 'only 43% of planets';
2660 * $like = $wild . wpbc_esc_like( $find ) . $wild;
2661 * $sql = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_content LIKE '%s'", $like );
2662 *
2663 * Example Escape Chain:
2664 *
2665 * $sql = esc_sql( wpbc_esc_like( $input ) );
2666 */
2667 }
2668
2669
2670 /**
2671 * Escape string from SQL for the HTML form field
2672 *
2673 * @param string $value
2674 * @return string
2675 *
2676 * Used: esc_sql function.
2677 *
2678 * https://codex.wordpress.org/Function_Reference/esc_sql
2679 * Note: Be careful to use this function correctly. It will only escape values to be used in strings in the query.
2680 * That is, it only provides escaping for values that will be within quotes in the SQL (as in field = '{$escaped_value}').
2681 * If your value is not going to be within quotes, your code will still be vulnerable to SQL injection.
2682 * For example, this is vulnerable, because the escaped value is not surrounded by quotes in the SQL query:
2683 * ORDER BY {$escaped_value}. As such, this function does not escape unquoted numeric values, field names, or SQL keywords.
2684 *
2685 */
2686 function wpbc_clean_string_for_form( $value ){
2687
2688 global $wpdb;
2689
2690 $value_trimmed = trim( stripslashes( $value ) );
2691
2692 //FixIn: 8.0.2.10 //Fix for update of WP 4.8.3
2693 if ( method_exists( $wpdb, 'remove_placeholder_escape' ) )
2694 $esc_sql_value = $wpdb->remove_placeholder_escape( esc_sql( $value_trimmed ) );
2695 else
2696 $esc_sql_value = esc_sql( $value_trimmed );
2697
2698 //$value = trim( $wpdb->prepare( "'%s'", $esc_sql_value ) , "'" );
2699
2700 $esc_sql_value = trim( stripslashes( $esc_sql_value ) );
2701
2702 return $esc_sql_value;
2703
2704 }
2705
2706
2707 /**
2708 * Escape shortcode parameters
2709 *
2710 * @param array $attr
2711 *
2712 * @return array
2713 */
2714 function wpbc_escape_shortcode_params( $attr ) { //FixIn: 9.7.3.6.1
2715
2716 if ( is_array( $attr ) ) {
2717
2718 $scaped_attr = array();
2719
2720 foreach ( $attr as $attr_key => $attr_val ) {
2721 $attr_key = esc_attr( $attr_key );
2722 $attr_val = esc_attr( $attr_val );
2723 $scaped_attr[ $attr_key ] = $attr_val;
2724 }
2725 return $scaped_attr;
2726 }
2727
2728 if ( is_string( $attr ) ) { //FixIn: 9.7.3.6.2
2729
2730 $scaped_attr = esc_attr( $attr );
2731
2732 return $scaped_attr;
2733 }
2734
2735 return $attr;
2736 }
2737
2738
2739 // </editor-fold>
2740
2741
2742 // <editor-fold defaultstate="collapsed" desc=" == Number of New Bookings == " >
2743
2744 /**
2745 * Reset Cache for getting Number of new bookings. After this operation, system will get number of new bookings from the DB.
2746 *
2747 * @return void
2748 */
2749 function wpbc_booking_cache__new_bookings__reset(){
2750 update_bk_option( 'booking_cache__new_bookings__saved_date', '' );
2751 }
2752 add_action( 'wpbc_track_new_booking', 'wpbc_booking_cache__new_bookings__reset' );
2753 add_action( 'wpbc_set_booking_pending', 'wpbc_booking_cache__new_bookings__reset' );
2754 add_action( 'wpbc_set_booking_approved', 'wpbc_booking_cache__new_bookings__reset' );
2755 add_action( 'wpbc_move_booking_to_trash', 'wpbc_booking_cache__new_bookings__reset' );
2756 add_action( 'wpbc_restore_booking_from_trash', 'wpbc_booking_cache__new_bookings__reset' );
2757 add_action( 'wpbc_delete_booking_completely', 'wpbc_booking_cache__new_bookings__reset' );
2758 add_action( 'wpbc_set_booking_as_read', 'wpbc_booking_cache__new_bookings__reset' );
2759 add_action( 'wpbc_set_booking_as_unread', 'wpbc_booking_cache__new_bookings__reset' );
2760
2761
2762 /**
2763 * Get number of new bookings
2764 * @return false|int|mixed|null
2765 */
2766 function wpbc_db_get_number_new_bookings(){
2767
2768 $new_bookings__number = get_bk_option( 'booking_cache__new_bookings__number' );
2769 $new_bookings__saved_date = get_bk_option( 'booking_cache__new_bookings__saved_date' );
2770
2771 $nowdate_str_ymdhis = date( 'Y-m-d H:i:s', strtotime( 'now' ) );
2772
2773 if ( ! empty( $new_bookings__saved_date ) ) {
2774
2775 $is_expired = ( strtotime( $new_bookings__saved_date ) <= strtotime( '-10 minutes', strtotime( $nowdate_str_ymdhis ) ) );
2776
2777 if ( ! $is_expired ) {
2778 return $new_bookings__number;
2779 }
2780 }
2781
2782 if ( 1 ) {
2783 global $wpdb;
2784
2785 //if ( wpbc_is_field_in_table_exists('booking','is_new') == 0 ) return 0; // do not created this field, so return 0
2786
2787 $trash_bookings = ' AND bk.trash != 1 '; //FixIn: 6.1.1.10 - check also below usage of {$trash_bookings}
2788 $sql_req = "SELECT bk.booking_id FROM {$wpdb->prefix}booking as bk WHERE bk.is_new = 1 {$trash_bookings} ";
2789
2790 $sql_req = apply_bk_filter( 'get_sql_for_checking_new_bookings', $sql_req );
2791 $sql_req = apply_bk_filter( 'get_sql_for_checking_new_bookings_multiuser', $sql_req );
2792
2793 $bookings = $wpdb->get_results( $sql_req );
2794 $bookings_count = count( $bookings );
2795 }
2796
2797
2798 update_bk_option( 'booking_cache__new_bookings__number', $bookings_count );
2799 update_bk_option( 'booking_cache__new_bookings__saved_date', $nowdate_str_ymdhis );
2800
2801 return $bookings_count;
2802 }
2803
2804
2805 /**
2806 * Update 'is_new' status of bookings in Database
2807 *
2808 * @param $id_of_new_bookings inr or comma seperated ID of bookings. Example: '1' | '3,5,7,9'
2809 * @param $is_new '0' | '1'
2810 * @param $user_id 'user_id'
2811 *
2812 */
2813 function wpbc_db_update_number_new_bookings( $id_of_new_bookings, $is_new = '0' , $user_id = 1 ){
2814 global $wpdb;
2815
2816 if (count($id_of_new_bookings) > 0 ) {
2817
2818 //if (wpbc_is_field_in_table_exists('booking','is_new') == 0) return 0; // do not created this field, so return 0
2819
2820 $id_of_new_bookings = implode(',', $id_of_new_bookings);
2821 $id_of_new_bookings = wpbc_clean_like_string_for_db( $id_of_new_bookings );
2822
2823
2824 //debuge($id_of_new_bookings);
2825 if ($id_of_new_bookings == 'all') {
2826 $update_sql = "UPDATE {$wpdb->prefix}booking AS bk SET bk.is_new = {$is_new} WHERE bk.is_new != {$is_new} "; //FixIn: 8.2.1.18
2827 //debuge($update_sql);
2828 $update_sql = apply_bk_filter('update_sql_for_checking_new_bookings', $update_sql, 0 , $user_id );
2829 } else
2830 $update_sql = "UPDATE {$wpdb->prefix}booking AS bk SET bk.is_new = {$is_new} WHERE bk.booking_id IN ( {$id_of_new_bookings} ) ";
2831
2832 if ( false === $wpdb->query( $update_sql ) ) {
2833 debuge_error('Error during updating status of bookings at DB',__FILE__,__LINE__);
2834 die();
2835 }
2836 }
2837 }
2838
2839 // </editor-fold>
2840
2841
2842 // <editor-fold defaultstate="collapsed" desc=" == Requests: News , Version == " >
2843
2844 define ('OBC_CHECK_URL', 'https://wpbookingcalendar.com/');
2845
2846
2847 function wpdev_ajax_check_bk_news( $sub_url = '' ){
2848
2849 $v=array();
2850 if (class_exists('wpdev_bk_personal')) $v[] = 'wpdev_bk_personal';
2851 if (class_exists('wpdev_bk_biz_s')) $v[] = 'wpdev_bk_biz_s';
2852 if (class_exists('wpdev_bk_biz_m')) $v[] = 'wpdev_bk_biz_m';
2853 if (class_exists('wpdev_bk_biz_l')) $v[] = 'wpdev_bk_biz_l';
2854 if (class_exists('wpdev_bk_multiuser')) $v[] = 'wpdev_bk_multiuser';
2855
2856 $obc_settings = array();
2857 $ver = get_bk_option('bk_version_data');
2858 if ( $ver !== false ) { $obc_settings = array( 'subscription_key'=>wp_json_encode($ver) ); }
2859
2860 $params = array(
2861 'action' => 'get_news',
2862 'subscription_email' => isset($obc_settings['subscription_email'])?$obc_settings['subscription_email']:false,
2863 'subscription_key' => isset($obc_settings['subscription_key'])?$obc_settings['subscription_key']:false,
2864 'bk' => array('bk_ver'=>WPDEV_BK_VERSION, 'bk_url'=>WPBC_PLUGIN_URL,'bk_dir'=>WPBC_PLUGIN_DIR, 'bk_clss'=>$v),
2865 'siteurl' => get_option('siteurl'),
2866 'siteip' => wpbc_get_server_ip(), //FixIn: 9.8.14.3
2867 'admin_email' => get_option('admin_email')
2868 );
2869
2870 $request = new WP_Http();
2871 if (empty($sub_url)) $sub_url = 'info/';
2872 $result = $request->request( OBC_CHECK_URL . $sub_url, array(
2873 'method' => 'POST',
2874 'timeout' => 15,
2875 'body' => $params
2876 ));
2877
2878 if (!is_wp_error($result) && ($result['response']['code']=='200') && (true) ) {
2879
2880 $string = ($result['body']); //$string = str_replace( "'", '&#039;', $string );
2881 echo $string;
2882 echo ' <script type="text/javascript"> ';
2883 echo ' jQuery("#ajax_bk_respond").after( jQuery("#ajax_bk_respond #bk_news_loaded") );';
2884 echo ' jQuery("#bk_news_loaded").slideUp(1).slideDown(1500);';
2885 echo ' </script> ';
2886
2887 } else /**/
2888 { // Some error appear
2889 echo '<div id="bk_errror_loading">';
2890 if (is_wp_error($result)) echo $result->get_error_message();
2891 else echo $result['response']['message'];
2892 echo '</div>';
2893 echo ' <script type="text/javascript"> ';
2894 echo ' document.getElementById("bk_news").style.display="none";';
2895 echo ' jQuery("#ajax_bk_respond").after( jQuery("#ajax_bk_respond #bk_errror_loading") );';
2896 echo ' jQuery("#bk_errror_loading").slideUp(1).slideDown(1500);';
2897 echo ' jQuery("#bk_news_section").animate({opacity:1},3000).slideUp(1500);';
2898 echo ' </script> ';
2899 }
2900
2901 }
2902
2903
2904 /**
2905 * Check if user defined to not show up_news section.
2906 *
2907 */
2908 function wpbc_is_show_up_news(){ //FixIn: 8.1.3.9
2909
2910 $wpdev_copyright_adminpanel = get_bk_option( 'booking_wpdev_copyright_adminpanel' ); // check
2911 if ( ( $wpdev_copyright_adminpanel === 'Off' )
2912 && ( ! wpbc_is_this_demo() )
2913 && ( class_exists('wpdev_bk_personal') )
2914 ) {
2915 return false;
2916 } else {
2917 return true;
2918 }
2919 }
2920
2921
2922 function wpdev_ajax_check_bk_version(){
2923 $v=array();
2924 if (class_exists('wpdev_bk_personal')) $v[] = 'wpdev_bk_personal';
2925 if (class_exists('wpdev_bk_biz_s')) $v[] = 'wpdev_bk_biz_s';
2926 if (class_exists('wpdev_bk_biz_m')) $v[] = 'wpdev_bk_biz_m';
2927 if (class_exists('wpdev_bk_biz_l')) $v[] = 'wpdev_bk_biz_l';
2928 if (class_exists('wpdev_bk_multiuser')) $v[] = 'wpdev_bk_multiuser';
2929
2930 $obc_settings = array();
2931 $params = array(
2932 'action' => 'set_register',
2933 'order_number' => isset($_POST['order_num'])?$_POST['order_num']:false,
2934 'bk' => array('bk_ver'=>WPDEV_BK_VERSION, 'bk_url'=>WPBC_PLUGIN_URL,'bk_dir'=>WPBC_PLUGIN_DIR, 'bk_clss'=>$v),
2935 'siteurl' => get_option('siteurl'),
2936 'siteip' => wpbc_get_server_ip(), //FixIn: 9.8.14.3
2937 'admin_email' => get_option('admin_email')
2938 );
2939
2940 update_bk_option( 'bk_version_data' , serialize($params) );
2941
2942 $request = new WP_Http();
2943 $result = $request->request( OBC_CHECK_URL . 'register/', array(
2944 'method' => 'POST',
2945 'timeout' => 15,
2946 'body' => $params
2947 ));
2948
2949 if ( ! is_wp_error($result)
2950 && ( $result['response']['code']=='200' )
2951 && ( true ) ) {
2952
2953 $string = ($result['body']); //$string = str_replace( "'", '&#039;', $string );
2954 echo $string ;
2955 echo ' <script type="text/javascript"> ';
2956 echo ' jQuery("#ajax_message").append( jQuery("#ajax_respond #bk_registration_info") );';
2957 echo ' jQuery("#ajax_message").append( "<div id=\'bk_registration_info_reload\'>If page will not reload automatically, please refresh page after 60 seconds...</div>" );';
2958 echo ' </script> ';
2959
2960 } else /**/
2961 { // Some error appear
2962 echo '<div id="bk_errror_loading" class="warning_message" >';
2963 echo '<div class="info_message">'; _e('Warning! Some error occur, during sending registration request.' ,'booking'); echo '</div>';
2964
2965 if (is_wp_error($result)) echo $result->get_error_message();
2966 else echo $result['response']['message'];
2967 echo '<br /><br />';
2968 _e('Please refresh this page and if the same error appear again contact support by email (with info about order number and website) for finishing the registrations' ,'booking'); echo ' <a href="mailto:activate@wpbookingcalendar.com">activate@wpbookingcalendar.com</a>';
2969 echo '</strong></div>';
2970 echo ' <script type="text/javascript"> ';
2971 echo ' jQuery( "#ajax_message" ).html( "" );';
2972
2973 echo ' jQuery("#ajax_message").append( jQuery("#ajax_respond #bk_errror_loading") );';
2974 echo ' jQuery("#bk_errror_loading").slideUp(1).slideDown(1500);';
2975
2976 echo ' jQuery("#recheck_version").animate({opacity:1},3000).slideUp(1500);';
2977 echo ' </script> ';
2978 }
2979
2980
2981 }
2982
2983 // </editor-fold>
2984
2985
2986 // <editor-fold defaultstate="collapsed" desc=" == User ID | Role - functions == " >
2987
2988 /**
2989 * Check if Current User have specific Role
2990 *
2991 * @return bool Whether the current user has the given capability.
2992 */
2993 function wpbc_is_current_user_have_this_role( $user_role ) {
2994
2995 if ( $user_role == 'administrator' ) $user_role = 'activate_plugins';
2996 if ( $user_role == 'editor' ) $user_role = 'publish_pages';
2997 if ( $user_role == 'author' ) $user_role = 'publish_posts';
2998 if ( $user_role == 'contributor' ) $user_role = 'edit_posts';
2999 if ( $user_role == 'subscriber') $user_role = 'read';
3000
3001 return current_user_can( $user_role );
3002 }
3003
3004
3005 /**
3006 * Get Current ID of user or get user ID of Forced log in user in Booking Calendar MultiUser version.
3007 *
3008 * @return int
3009 */
3010 function wpbc_get_current_user_id() { //FixIn: 9.2.4.1
3011
3012 if ( function_exists( 'wpbc_mu__wp_get_current_user' ) ) {
3013 $user = wpbc_mu__wp_get_current_user();
3014 $user_bk_id = $user->ID;
3015 } else {
3016 $user_bk_id = get_current_user_id();
3017 }
3018
3019 return $user_bk_id;
3020 }
3021
3022
3023 /**
3024 * Get Current User Object or get User object of Forced log in user in Booking Calendar MultiUser version.
3025 *
3026 * @return stdClass|WP_User|null
3027 */
3028 function wpbc_get_current_user() { //FixIn: 9.2.4.1
3029
3030 if ( function_exists( 'wpbc_mu__wp_get_current_user' ) ) {
3031 $user = wpbc_mu__wp_get_current_user();
3032 } else {
3033 $user = wp_get_current_user();
3034 }
3035
3036 return $user;
3037 }
3038
3039 // </editor-fold>
3040
3041
3042 // <editor-fold defaultstate="collapsed" desc=" == Messages for Admin panel == " >
3043
3044
3045 /**
3046 * Show "Saved Changes" message at the top of settings page.
3047 *
3048 */
3049 function wpbc_show_changes_saved_message() {
3050 wpbc_show_message ( __('Changes saved.','booking'), 5 );
3051 }
3052
3053
3054 /**
3055 * Show Message at Top of Admin Pages
3056 *
3057 * @param type $message - mesage to show
3058 * @param type $time_to_show - number of seconds to show, if 0 or skiped, then unlimited time.
3059 * @param type $message_type - Default: updated { updated | error | notice }
3060 */
3061 function wpbc_show_message ( $message, $time_to_show , $message_type = 'updated') {
3062
3063 // Generate unique HTML ID for the message
3064 $inner_message_id = intval( time() * rand(10, 100) );
3065
3066 // Get formated HTML message
3067 $notice = wpbc_get_formated_message( $message, $message_type, $inner_message_id );
3068
3069 // Get the time of message showing
3070 $time_to_show = intval( $time_to_show ) * 1000;
3071
3072 // Show this Message
3073 ?> <script type="text/javascript">
3074 if ( jQuery('.wpbc_admin_message').length ) {
3075 jQuery('.wpbc_admin_message').append( '<?php echo $notice; ?>' );
3076 <?php if ( $time_to_show > 0 ) { ?>
3077 jQuery('#wpbc_inner_message_<?php echo $inner_message_id; ?>').animate({opacity: 1},<?php echo $time_to_show; ?>).fadeOut( 2000 );
3078 <?php } ?>
3079 }
3080 </script> <?php
3081 }
3082
3083
3084 /**
3085 * Escape and prepare message to show it
3086 *
3087 * @param type $message - message
3088 * @param type $message_type - Default: updated { updated | error | notice }
3089 * @param string $inner_message_id - ID of message DIV, can be skipped
3090 * @return string
3091 */
3092 function wpbc_get_formated_message ( $message, $message_type = 'updated', $inner_message_id = '') {
3093
3094
3095 // Recheck for any "lang" shortcodes for replacing to correct language
3096 $message = wpbc_lang( $message );
3097
3098 // Escape any JavaScript from message
3099 $notice = html_entity_decode( esc_js( $message ) ,ENT_QUOTES) ;
3100
3101 $notice .= '<a class="close tooltip_left" rel="tooltip" title="'. esc_js(__("Hide",'booking')). '" data-dismiss="alert" href="javascript:void(0)" onclick="javascript:jQuery(this).parent().hide();">&times;</a>';
3102
3103 if (! empty( $inner_message_id ))
3104 $inner_message_id = 'id="wpbc_inner_message_'. $inner_message_id .'"';
3105
3106 $notice = '<div '.$inner_message_id.' class="wpbc_inner_message '. $message_type . '">' . $notice . '</div>';
3107
3108 return $notice;
3109 }
3110
3111
3112 /**
3113 * Show system info in settings page
3114 *
3115 * @param string $message ...
3116 * @param string $message_type 'info' | 'warning' | 'error'
3117 * @param string $title __('Important!' ,'booking') | __('Note' ,'booking')
3118 *
3119 * Exmaple: wpbc_show_message_in_settings( __( 'Nothing Found', 'booking' ), 'warning', __('Important!' ,'booking') );
3120 */
3121 function wpbc_show_message_in_settings( $message, $message_type = 'info', $title = '' , $is_echo = true ) {
3122
3123 $message_content = '';
3124
3125 $message_content .= '<div class="clear"></div>';
3126
3127 $message_content .= '<div class="wpbc-settings-notice notice-' . $message_type . '" style="text-align:left;">';
3128
3129 if ( ! empty( $title ) )
3130 $message_content .= '<strong>' . esc_js( $title ) . '</strong> ';
3131
3132 $message_content .= html_entity_decode( esc_js( $message ) ,ENT_QUOTES) ;
3133
3134 $message_content .= '</div>';
3135
3136 $message_content .= '<div class="clear"></div>';
3137
3138 if ( $is_echo )
3139 echo $message_content;
3140 else
3141 return $message_content;
3142
3143 }
3144
3145 // </editor-fold>
3146
3147
3148 // <editor-fold defaultstate="collapsed" desc=" == Meta Boxes - Open/Close == " >
3149
3150 /**
3151 * Meta box section open tag
3152 *
3153 * @param string $metabox_id HTML ID of section
3154 * @param string $title Title in section
3155 * @param array $params [
3156 'is_section_visible_after_load' => true, // Default true - is this section Visible, after page loading or hidden - useful for Booking > Settings General page LEFT column sections
3157 'is_show_minimize' => true // Default true - is show minimize button at top right section
3158 ]
3159 *
3160 * @return void
3161 */
3162 function wpbc_open_meta_box_section( $metabox_id, $title, $params = array() ) {
3163
3164 $defaults = array(
3165 'is_section_visible_after_load' => true,
3166 'is_show_minimize' => true,
3167 'dismiss_button' => '',
3168 'css_class' => 'postbox'
3169 );
3170 $params = wp_parse_args( $params, $defaults );
3171
3172 $my_close_open_win_id = $metabox_id . '_metabox';
3173
3174 ?>
3175 <div class='meta-box'>
3176 <div id="<?php echo $my_close_open_win_id; ?>"
3177 class="<?php echo esc_attr( $params['css_class'] ); ?> <?php
3178 if ( $params['is_show_minimize'] ) {
3179 if ( '1' == get_user_option( 'booking_win_' . $my_close_open_win_id ) ) {
3180 echo 'closed';
3181 }
3182 }
3183 ?>"
3184 style="<?php if ( ! $params['is_section_visible_after_load'] ) {
3185 echo 'display:none';
3186 }
3187 ?>"
3188 ><div class="postbox-header" style="display: flex;flex-flow: row nowrap;border-bottom: 1px solid #ccd0d4;">
3189 <h3 class='hndle' style="flex: 1 1 auto;border: none;">
3190 <span><?php echo wp_kses_post( $title ); ?></span>
3191 <?php echo $params['dismiss_button']; ?>
3192 </h3>
3193 <?php if ( $params['is_show_minimize'] ) { ?>
3194 <div title="<?php _e('Click to toggle','booking'); ?>" class="handlediv"
3195 onclick="javascript:wpbc_verify_window_opening(<?php echo wpbc_get_current_user_id(); ?>, '<?php echo $my_close_open_win_id; ?>');"
3196 ><br/></div>
3197 <?php } ?>
3198 </div>
3199 <div class="inside">
3200 <?php
3201 }
3202
3203
3204 function wpbc_close_meta_box_section() {
3205 ?>
3206 </div>
3207 </div>
3208 </div>
3209 <?php
3210 }
3211
3212 // </editor-fold>
3213
3214
3215 // <editor-fold defaultstate="collapsed" desc=" == Is Dismissed == " >
3216
3217 /**
3218 * Only check if Dismised or visible this section
3219 *
3220 * @param $element_html_id
3221 *
3222 * @return bool
3223 */
3224 function wpbc_is_dismissed_panel_visible( $element_html_id ) {
3225 return ( '1' != get_user_option( 'booking_win_' . $element_html_id ) );
3226
3227 }
3228
3229 /**
3230 * Show dismiss close button for specific HTML section
3231 *
3232 * @param string $element_html_id - ID of HTML selection to dismiss
3233 * @param array $params - array( 'title' => 'Dismiss', 'is_apply_in_demo' => false ) )
3234 *
3235 * @return bool
3236 *
3237 * Examples:
3238 * $is_dismissed = wpbc_is_dismissed( 'wpbc_dashboard_section_video_f' );
3239 *
3240 * $is_dismissed = wpbc_is_dismissed( 'html_id', array( 'is_apply_in_demo' => $is_apply_in_demo ) );
3241 *
3242 * $is_panel_visible = wpbc_is_dismissed( 'wpbc-panel-get-started', array(
3243 * 'title' => '<i class="menu_icon icon-1x wpbc_icn_close"></i> ',
3244 * 'hint' => __( 'Dismiss', 'booking' ),
3245 * 'class' => 'wpbc_panel_get_started_dismiss',
3246 * 'css' => ''
3247 * ));
3248 */
3249 function wpbc_is_dismissed( $element_html_id, $params = array() ){ //FixIn: 8.1.3.10
3250
3251 $defaults = array(
3252 'title' => '&times;'
3253 , 'hint' => __( 'Dismiss' ,'booking')
3254 , 'is_apply_in_demo' => ! wpbc_is_this_demo()
3255 , 'class' => '' // CSS class of close X element
3256 , 'css' => '' // Style class of close X element
3257 , 'dismiss_css_class' => '' //'.'.$id . '_' . 'weekdays_conditions'
3258 );
3259 $params = wp_parse_args( $params, $defaults );
3260
3261
3262 $params['css'] = 'text-decoration: none;font-weight: 600;float:right;' . $params['css']; // Append CSS instead of replace it
3263
3264 if ( ( class_exists( 'WPBC_Dismiss' )) && ( $params[ 'is_apply_in_demo' ] ) ) {
3265
3266 global $wpbc_Dismiss;
3267
3268 $is_panel_visible = $wpbc_Dismiss->render( array(
3269 'id' => $element_html_id,
3270 'title' => $params['title'],
3271 'hint' => $params['hint'],
3272 'class' => $params['class'],
3273 'css' => $params['css'],
3274 'dismiss_css_class' => $params['dismiss_css_class']
3275 ) );
3276 } else {
3277 $is_panel_visible = false;
3278 }
3279
3280 return $is_panel_visible;
3281 }
3282
3283 // </editor-fold>
3284
3285
3286 // <editor-fold defaultstate="collapsed" desc=" == Inline JavaScript to Footer page == " >
3287
3288 /**
3289 * Queue JavaScript for later output at footer
3290 *
3291 * @param string $code
3292 */
3293 function wpbc_enqueue_js( $code ) {
3294 global $wpbc_queued_js;
3295
3296 if ( empty( $wpbc_queued_js ) ) {
3297 $wpbc_queued_js = '';
3298 }
3299
3300 $wpbc_queued_js .= "\n" . $code . "\n";
3301 }
3302
3303
3304 /**
3305 * Output any queued javascript code in the footer.
3306 */
3307 function wpbc_print_js() {
3308
3309 global $wpbc_queued_js;
3310
3311 if ( ! empty( $wpbc_queued_js ) ) {
3312
3313 $wpbc_queued_js = wp_check_invalid_utf8( $wpbc_queued_js );
3314
3315 $wpbc_queued_js = wp_specialchars_decode( $wpbc_queued_js , ENT_COMPAT); // Converts double quotes '&quot;' => '"'
3316
3317 $wpbc_queued_js = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", $wpbc_queued_js );
3318 $wpbc_queued_js = str_replace( "\r", '', $wpbc_queued_js );
3319
3320 echo "<!-- WPBC JavaScript -->\n<script type=\"text/javascript\">\njQuery(function($) {" . $wpbc_queued_js . "});\n</script>\n<!-- End WPBC JavaScript -->\n";
3321
3322 $wpbc_queued_js = '';
3323 unset( $wpbc_queued_js );
3324 }
3325 }
3326
3327 // </editor-fold>
3328
3329
3330 // <editor-fold defaultstate="collapsed" desc=" == Support functions for MU version == " >
3331
3332 /**
3333 * Set active User Environment in MultiUser version, depend from owner of booking resource
3334 *
3335 * @param int $previous_active_user (default=-1) - blank parameter
3336 * @param int $bktype - booking resource ID for checking
3337 * @return int - ID of Previous Active User
3338 *
3339 * Usage:
3340 $previous_active_user = apply_bk_filter('wpbc_mu_set_environment_for_owner_of_resource', -1, $bktype );
3341
3342 */
3343 function wpbc_mu_set_environment_for_owner_of_resource( $previous_active_user = -1, $bktype = 1 ) {
3344
3345 if ( class_exists( 'wpdev_bk_multiuser' ) ) {
3346 // Get the owner of this booking resource
3347 $user_bk_id = apply_bk_filter( 'get_user_of_this_bk_resource', false, $bktype );
3348
3349 $user = wpbc_get_current_user();
3350
3351 // Get possible other active user settings
3352 $previous_active_user = apply_bk_filter( 'get_client_side_active_params_of_user' );
3353
3354 // Set active user of that specific booking resource
3355 make_bk_action( 'check_multiuser_params_for_client_side_by_user_id', $user_bk_id );
3356 }
3357
3358 return $previous_active_user;
3359 }
3360 add_bk_filter('wpbc_mu_set_environment_for_owner_of_resource', 'wpbc_mu_set_environment_for_owner_of_resource');
3361
3362
3363 /**
3364 * Set environment for this user in MU version
3365 *
3366 * @param int $previous_active_user - ID of user
3367 * Usage:
3368 make_bk_action('wpbc_mu_set_environment_for_user', $previous_active_user );
3369
3370 */
3371 function wpbc_mu_set_environment_for_user( $previous_active_user ) {
3372
3373 if ( $previous_active_user !== -1 ) {
3374
3375 // Reactivate the previous active user
3376 make_bk_action('check_multiuser_params_for_client_side_by_user_id', $previous_active_user );
3377 }
3378 }
3379 add_bk_action('wpbc_mu_set_environment_for_user', 'wpbc_mu_set_environment_for_user');
3380
3381 // </editor-fold>
3382
3383
3384 // <editor-fold defaultstate="collapsed" desc=" == Currency functions (>=BS) == " >
3385
3386 /**
3387 * Format booking cost with a currency symbol.
3388 * In MultiUser version also checking about specific currency that belong to specific WordPress user.
3389 * This checking based on belonging specific booking resource to specific user.
3390 *
3391 * @param float $cost
3392 * @param int $booking_resource_id
3393 * @return string - $cost_to_show_with_currency
3394 */
3395 function wpbc_get_cost_with_currency_for_user( $cost, $booking_resource_id = 0 ){
3396
3397 if ( ( $cost === '' ) || ( ! class_exists( 'wpdev_bk_biz_s' ) ) ) {
3398 return '';
3399 }
3400
3401 if ( ! empty( $booking_resource_id ) ) {
3402 $previous_active_user = apply_bk_filter( 'wpbc_mu_set_environment_for_owner_of_resource', - 1, $booking_resource_id );
3403 } // MU
3404
3405 $cost_to_show_with_currency = wpbc_cost_show( $cost, array( 'currency' => wpbc_get_currency() ) );
3406
3407 if ( ! empty( $booking_resource_id ) ) {
3408 make_bk_action( 'wpbc_mu_set_environment_for_user', $previous_active_user );
3409 } // MU
3410
3411 return $cost_to_show_with_currency;
3412 }
3413
3414
3415 /**
3416 * Get currency Symbol.
3417 * In MultiUser version also checking about specific currency that belong to specific WordPress user.
3418 * This checking based on belonging specific booking resource to specific user.
3419 *
3420 * @param int $booking_resource_id - ID of specific booking resource
3421 * @return string - currency symbol
3422 */
3423 function wpbc_get_currency_symbol_for_user( $booking_resource_id = 0 ){
3424
3425 if ( ! class_exists( 'wpdev_bk_biz_s' ) ) {
3426 return '';
3427 }
3428
3429 if ( ! empty( $booking_resource_id ) ) {
3430 $previous_active_user = apply_bk_filter( 'wpbc_mu_set_environment_for_owner_of_resource', - 1, $booking_resource_id );
3431 } // MU
3432
3433 $currency_symbol = wpbc_get_currency_symbol();
3434
3435 if ( ! empty( $booking_resource_id ) ) {
3436 make_bk_action( 'wpbc_mu_set_environment_for_user', $previous_active_user );
3437 } // MU
3438
3439 return $currency_symbol;
3440 }
3441
3442 /**
3443 * Get Cost per period: DAY / NIGHT / FIXED / HOUR
3444 * In MultiUser version This checking based on belonging specific booking resource to specific user.
3445 *
3446 * @param int $booking_resource_id - ID of specific booking resource
3447 * @return string - cost per period
3448 */
3449 function wpbc_get_cost_per_period_for_user( $booking_resource_id = 0 ){ //FixIn: 10.0.0.14
3450
3451 if ( ! class_exists( 'wpdev_bk_biz_s' ) ) {
3452 return '';
3453 }
3454
3455 if ( ! empty( $booking_resource_id ) ) {
3456 $previous_active_user = apply_bk_filter( 'wpbc_mu_set_environment_for_owner_of_resource', - 1, $booking_resource_id );
3457 } // MU
3458
3459 $cost_period = get_bk_option( 'booking_paypal_price_period' );
3460
3461 if ( ! empty( $booking_resource_id ) ) {
3462 make_bk_action( 'wpbc_mu_set_environment_for_user', $previous_active_user );
3463 } // MU
3464
3465 return $cost_period;
3466 }
3467 // </editor-fold>
3468
3469
3470 // <editor-fold defaultstate="collapsed" desc=" == Approve | Pending functions == " >
3471
3472 /**
3473 * Check is this booking approved -- get booking dates in DB and check status
3474 *
3475 * @param $booking_id
3476 *
3477 * @return bool
3478 */
3479 function wpbc_is_booking_approved( $booking_id ){ //FixIn: 8.1.2.8
3480
3481 $is_booking_approved = false;
3482
3483 global $wpdb;
3484
3485 $sql = $wpdb->prepare( "SELECT DISTINCT approved FROM {$wpdb->prefix}bookingdates WHERE booking_id = %d ORDER BY booking_date", $booking_id );
3486
3487 $dates_result = $wpdb->get_results( $sql );
3488
3489 foreach ( $dates_result as $my_date ) {
3490
3491 if ( '1' == $my_date->approved ) {
3492 $is_booking_approved = true; //FixIn: 8.3.1.2
3493 }
3494 }
3495
3496 return $is_booking_approved;
3497 }
3498
3499
3500 /**
3501 * Approve booking in DB (update booking dates in DB like approved = '1')
3502 *
3503 * @param $booking_id int | CSD e.g. 100 | '1,5,10'
3504 *
3505 * @return bool
3506 */
3507 function wpbc_db__booking_approve( $booking_id ) {
3508
3509 $booking_id = wpbc_clean_digit_or_csd( $booking_id ); // Check paramter if it number or comma separated list of numbers
3510
3511 global $wpdb;
3512
3513 $update_sql = "UPDATE {$wpdb->prefix}bookingdates SET approved = '1' WHERE booking_id IN ({$booking_id});";
3514
3515 if ( false === $wpdb->query( $update_sql ) ) {
3516 return false;
3517 }
3518
3519 return true;
3520 }
3521
3522
3523 /**
3524 * Approve specific booking and send email about this.
3525 *
3526 * @param int $booking_id - ID of booking
3527 * @param string $email_reason
3528 */
3529 function wpbc_auto_approve_booking( $booking_id , $email_reason = '' ) {
3530
3531 $booking_id = wpbc_clean_digit_or_csd( $booking_id ); // Check paramter if it number or comma separated list of numbers
3532
3533 if ( is_numeric( $booking_id ) ) { //FixIn: 8.1.2.8
3534 if ( ! wpbc_is_booking_approved( $booking_id ) ) {
3535 do_action( 'wpbc_booking_approved', $booking_id, 1 ); //FixIn: 8.7.6.1
3536
3537 wpbc_send_email_approved( $booking_id, 1, $email_reason );
3538 }
3539 } else {
3540 $booking_id_arr = explode( ',',$booking_id );
3541 foreach ( $booking_id_arr as $bk_id ) {
3542 if ( ! wpbc_is_booking_approved( $bk_id ) ) {
3543 do_action( 'wpbc_booking_approved', $bk_id, 1 ); //FixIn: 8.7.6.1
3544 wpbc_send_email_approved( $bk_id, 1, $email_reason );
3545 }
3546 }
3547 }
3548
3549 $db_result = wpbc_db__booking_approve( $booking_id );
3550
3551 if ( false === $db_result ){
3552
3553 wpbc_redirect( site_url() );
3554 }
3555 }
3556
3557
3558 /**
3559 * Set as Pending specific booking and send email about this.
3560 *
3561 * @param int $booking_id - ID of booking
3562 * @param string $denyreason
3563 */
3564 function wpbc_auto_pending_booking( $booking_id, $denyreason = '' ) { //FixIn: 8.4.7.25
3565
3566 global $wpdb;
3567
3568 $booking_id = wpbc_clean_digit_or_csd( $booking_id ); // Check paramter if it number or comma separated list of numbers
3569
3570 if ( is_numeric( $booking_id ) ) { //FixIn: 8.1.2.8
3571 if ( wpbc_is_booking_approved( $booking_id ) ) {
3572 wpbc_send_email_deny( $booking_id, 1, $denyreason );
3573 }
3574 } else {
3575 $booking_id_arr = explode( ',',$booking_id );
3576 foreach ( $booking_id_arr as $bk_id ) {
3577 if ( wpbc_is_booking_approved( $bk_id ) ) {
3578 wpbc_send_email_deny( $bk_id, 1, $denyreason );
3579 }
3580
3581 }
3582 }
3583
3584 $update_sql = "UPDATE {$wpdb->prefix}bookingdates SET approved = '0' WHERE booking_id IN ({$booking_id});";
3585
3586 if ( false === $wpdb->query( $update_sql ) ){
3587
3588 wpbc_redirect( site_url() );
3589 }
3590 }
3591
3592
3593 /**
3594 * Cancel (move to Trash) specific booking.
3595 *
3596 * @param int $booking_id - ID of booking
3597 * @param string $email_reason - reason of cancellation
3598 */
3599 function wpbc_auto_cancel_booking( $booking_id , $email_reason = '' ) { //FixIn: 8.4.7.25
3600
3601 global $wpdb;
3602
3603 $booking_id = wpbc_clean_digit_or_csd( $booking_id ); // Check paramter if it number or comma separated list of numbers
3604
3605 if ( empty( $email_reason ) ) { //FixIn: 8.4.7.25
3606 // Get the reason of cancellation.
3607 $email_reason = __( 'Payment rejected', 'booking' );
3608 $auto_cancel_pending_unpaid_bk_is_send_email = get_bk_option( 'booking_auto_cancel_pending_unpaid_bk_is_send_email' );
3609 if ( $auto_cancel_pending_unpaid_bk_is_send_email == 'On' ) {
3610 $email_reason = get_bk_option( 'booking_auto_cancel_pending_unpaid_bk_email_reason' );
3611 }
3612 }
3613 // Send decline emails
3614 wpbc_send_email_trash( $booking_id, 1, $email_reason );
3615
3616 if ( false === $wpdb->query( "UPDATE {$wpdb->prefix}booking AS bk SET bk.trash = 1 WHERE booking_id IN ({$booking_id})" ) ){
3617
3618 wpbc_redirect( site_url() );
3619 }
3620 }
3621
3622
3623 //FixIn: 9.9.0.43
3624
3625 /**
3626 * Auto approve booking and send email, after successful payment process
3627 *
3628 * It resolves issue in Booking Calendar MultiUser version for sending "regular email" to visitors, if was made booking for booking resource, that belong to regular user,
3629 * and was activated this option "Receive all payments only to Super Booking Admin account" at the WP Booking Calendar > Settings General page in "Multiuser Options" section
3630 *
3631 * @param $booking_id
3632 *
3633 * @return void
3634 */
3635 function wpbc_auto_approve_booking__after_payment( $booking_id ) {
3636 //-------------------------------------------------------------------------------------------------- //FixIn: 9.9.0.43
3637 $is_force_again = false;
3638 if ( class_exists( 'wpdev_bk_multiuser' ) ) {
3639
3640 list( $booking_hash, $booking_resource_id ) = wpbc_hash__get_booking_hash__resource_id( $booking_id );
3641
3642 $user_id = apply_bk_filter( 'get_user_of_this_bk_resource', false, $booking_resource_id );
3643
3644 $is_booking_resource_user_super_admin = apply_bk_filter( 'is_user_super_admin', $user_id );
3645
3646 if (
3647 ( 'On' == get_bk_option( 'booking_super_admin_receive_regular_user_payments' ) )
3648 && ( ! $is_booking_resource_user_super_admin )
3649 ) {
3650 // Finish "Super-User" forcing
3651 make_bk_action( 'finish_force_using_this_user' );
3652 //Reactivate data for "regular user
3653 make_bk_action( 'check_multiuser_params_for_client_side_by_user_id', $user_id );
3654
3655 $is_force_again = true;
3656 }
3657 }
3658 // -------------------------------------------------------------------------------------------------
3659
3660 wpbc_auto_approve_booking( $booking_id );
3661
3662 if ( $is_force_again ) { //FixIn: 9.9.0.43
3663 make_bk_action( 'make_force_using_this_user', - 999 ); // '-999' - This ID "by default" is the ID of super booking admin user
3664 }
3665 }
3666
3667
3668 /**
3669 * Auto cancel booking and send email, after successful payment process
3670 *
3671 * It resolves issue in Booking Calendar MultiUser version for sending "regular email" to visitors, if was made booking for booking resource, that belong to regular user,
3672 * and was activated this option "Receive all payments only to Super Booking Admin account" at the WP Booking Calendar > Settings General page in "Multiuser Options" section
3673 *
3674 * @param $booking_id
3675 *
3676 * @return void
3677 */
3678 function wpbc_auto_cancel_booking__after_payment( $booking_id ) {
3679 //-------------------------------------------------------------------------------------------------- //FixIn: 9.9.0.43
3680 $is_force_again = false;
3681 if ( class_exists( 'wpdev_bk_multiuser' ) ) {
3682
3683 list( $booking_hash, $booking_resource_id ) = wpbc_hash__get_booking_hash__resource_id( $booking_id );
3684
3685 $user_id = apply_bk_filter( 'get_user_of_this_bk_resource', false, $booking_resource_id );
3686
3687 $is_booking_resource_user_super_admin = apply_bk_filter( 'is_user_super_admin', $user_id );
3688
3689 if (
3690 ( 'On' == get_bk_option( 'booking_super_admin_receive_regular_user_payments' ) )
3691 && ( ! $is_booking_resource_user_super_admin )
3692 ) {
3693 // Finish "Super-User" forcing
3694 make_bk_action( 'finish_force_using_this_user' );
3695 //Reactivate data for "regular user
3696 make_bk_action( 'check_multiuser_params_for_client_side_by_user_id', $user_id );
3697
3698 $is_force_again = true;
3699 }
3700 }
3701 // -------------------------------------------------------------------------------------------------
3702
3703 wpbc_auto_cancel_booking( $booking_id );
3704
3705 if ( $is_force_again ) { //FixIn: 9.9.0.43
3706 make_bk_action( 'make_force_using_this_user', - 999 ); // '-999' - This ID "by default" is the ID of super booking admin user
3707 }
3708 }
3709 // </editor-fold>
3710
3711
3712 // <editor-fold defaultstate="collapsed" desc=" == REGION CITIES LIST - Support functions Timezone in .ICS & Google Calendar == " >
3713
3714 /**
3715 * Get list of cities for timezone usage in format like: $city["Europe"]["Kiev"] = "Kiev";
3716 *
3717 * @return array|array[]
3718 */
3719 function wpbc_get_booking_region_cities_list(){ //FixIn: 8.9.4.9
3720
3721 $city = array(
3722 'Africa' => array()
3723 , 'America' => array()
3724 , 'Antarctica' => array()
3725 , 'Arctic' => array()
3726 , 'Asia' => array()
3727 , 'Atlantic' => array()
3728 , 'Australia' => array()
3729 , 'Europe' => array()
3730 , 'Indian' => array()
3731 , 'Pacific' => array()
3732 );
3733 $city["Africa"]["Abidjan"] = "Abidjan";
3734 $city["Africa"]["Accra"] = "Accra";
3735 $city["Africa"]["Addis_Ababa"] = "Addis Ababa";
3736 $city["Africa"]["Algiers"] = "Algiers";
3737 $city["Africa"]["Asmara"] = "Asmara";
3738 $city["Africa"]["Bamako"] = "Bamako";
3739 $city["Africa"]["Bangui"] = "Bangui";
3740 $city["Africa"]["Banjul"] = "Banjul";
3741 $city["Africa"]["Bissau"] = "Bissau";
3742 $city["Africa"]["Blantyre"] = "Blantyre";
3743 $city["Africa"]["Brazzaville"] = "Brazzaville";
3744 $city["Africa"]["Bujumbura"] = "Bujumbura";
3745 $city["Africa"]["Cairo"] = "Cairo";
3746 $city["Africa"]["Casablanca"] = "Casablanca";
3747 $city["Africa"]["Ceuta"] = "Ceuta";
3748 $city["Africa"]["Conakry"] = "Conakry";
3749 $city["Africa"]["Dakar"] = "Dakar";
3750 $city["Africa"]["Dar_es_Salaam"] = "Dar es Salaam";
3751 $city["Africa"]["Djibouti"] = "Djibouti";
3752 $city["Africa"]["Douala"] = "Douala";
3753 $city["Africa"]["El_Aaiun"] = "El Aaiun";
3754 $city["Africa"]["Freetown"] = "Freetown";
3755 $city["Africa"]["Gaborone"] = "Gaborone";
3756 $city["Africa"]["Harare"] = "Harare";
3757 $city["Africa"]["Johannesburg"] = "Johannesburg";
3758 $city["Africa"]["Kampala"] = "Kampala";
3759 $city["Africa"]["Khartoum"] = "Khartoum";
3760 $city["Africa"]["Kigali"] = "Kigali";
3761 $city["Africa"]["Kinshasa"] = "Kinshasa";
3762 $city["Africa"]["Lagos"] = "Lagos";
3763 $city["Africa"]["Libreville"] = "Libreville";
3764 $city["Africa"]["Lome"] = "Lome";
3765 $city["Africa"]["Luanda"] = "Luanda";
3766 $city["Africa"]["Lubumbashi"] = "Lubumbashi";
3767 $city["Africa"]["Lusaka"] = "Lusaka";
3768 $city["Africa"]["Malabo"] = "Malabo";
3769 $city["Africa"]["Maputo"] = "Maputo";
3770 $city["Africa"]["Maseru"] = "Maseru";
3771 $city["Africa"]["Mbabane"] = "Mbabane";
3772 $city["Africa"]["Mogadishu"] = "Mogadishu";
3773 $city["Africa"]["Monrovia"] = "Monrovia";
3774 $city["Africa"]["Nairobi"] = "Nairobi";
3775 $city["Africa"]["Ndjamena"] = "Ndjamena";
3776 $city["Africa"]["Niamey"] = "Niamey";
3777 $city["Africa"]["Nouakchott"] = "Nouakchott";
3778 $city["Africa"]["Ouagadougou"] = "Ouagadougou";
3779 $city["Africa"]["Porto-Novo"] = "Porto-Novo";
3780 $city["Africa"]["Sao_Tome"] = "Sao Tome";
3781 $city["Africa"]["Tripoli"] = "Tripoli";
3782 $city["Africa"]["Tunis"] = "Tunis";
3783 $city["Africa"]["Windhoek"] = "Windhoek";
3784
3785 $city["America"]["Adak"] = "Adak";
3786 $city["America"]["Anchorage"] = "Anchorage";
3787 $city["America"]["Anguilla"] = "Anguilla";
3788 $city["America"]["Antigua"] = "Antigua";
3789 $city["America"]["Araguaina"] = "Araguaina";
3790 $city["America"]["Argentina/Buenos_Aires"] = "Argentina - Buenos Aires";
3791 $city["America"]["Argentina/Catamarca"] = "Argentina - Catamarca";
3792 $city["America"]["Argentina/Cordoba"] = "Argentina - Cordoba";
3793 $city["America"]["Argentina/Jujuy"] = "Argentina - Jujuy";
3794 $city["America"]["Argentina/La_Rioja"] = "Argentina - La Rioja";
3795 $city["America"]["Argentina/Mendoza"] = "Argentina - Mendoza";
3796 $city["America"]["Argentina/Rio_Gallegos"] = "Argentina - Rio Gallegos";
3797 $city["America"]["Argentina/Salta"] = "Argentina - Salta";
3798 $city["America"]["Argentina/San_Juan"] = "Argentina - San Juan";
3799 $city["America"]["Argentina/San_Luis"] = "Argentina - San Luis";
3800 $city["America"]["Argentina/Tucuman"] = "Argentina - Tucuman";
3801 $city["America"]["Argentina/Ushuaia"] = "Argentina - Ushuaia";
3802 $city["America"]["Aruba"] = "Aruba";
3803 $city["America"]["Asuncion"] = "Asuncion";
3804 $city["America"]["Atikokan"] = "Atikokan";
3805 $city["America"]["Bahia"] = "Bahia";
3806 $city["America"]["Barbados"] = "Barbados";
3807 $city["America"]["Belem"] = "Belem";
3808 $city["America"]["Belize"] = "Belize";
3809 $city["America"]["Blanc-Sablon"] = "Blanc-Sablon";
3810 $city["America"]["Boa_Vista"] = "Boa Vista";
3811 $city["America"]["Bogota"] = "Bogota";
3812 $city["America"]["Boise"] = "Boise";
3813 $city["America"]["Cambridge_Bay"] = "Cambridge Bay";
3814 $city["America"]["Campo_Grande"] = "Campo Grande";
3815 $city["America"]["Cancun"] = "Cancun";
3816 $city["America"]["Caracas"] = "Caracas";
3817 $city["America"]["Cayenne"] = "Cayenne";
3818 $city["America"]["Cayman"] = "Cayman";
3819 $city["America"]["Chicago"] = "Chicago";
3820 $city["America"]["Chihuahua"] = "Chihuahua";
3821 $city["America"]["Costa_Rica"] = "Costa Rica";
3822 $city["America"]["Cuiaba"] = "Cuiaba";
3823 $city["America"]["Curacao"] = "Curacao";
3824 $city["America"]["Danmarkshavn"] = "Danmarkshavn";
3825 $city["America"]["Dawson"] = "Dawson";
3826 $city["America"]["Dawson_Creek"] = "Dawson Creek";
3827 $city["America"]["Denver"] = "Denver";
3828 $city["America"]["Detroit"] = "Detroit";
3829 $city["America"]["Dominica"] = "Dominica";
3830 $city["America"]["Edmonton"] = "Edmonton";
3831 $city["America"]["Eirunepe"] = "Eirunepe";
3832 $city["America"]["El_Salvador"] = "El Salvador";
3833 $city["America"]["Fortaleza"] = "Fortaleza";
3834 $city["America"]["Glace_Bay"] = "Glace Bay";
3835 $city["America"]["Godthab"] = "Godthab";
3836 $city["America"]["Goose_Bay"] = "Goose Bay";
3837 $city["America"]["Grand_Turk"] = "Grand Turk";
3838 $city["America"]["Grenada"] = "Grenada";
3839 $city["America"]["Guadeloupe"] = "Guadeloupe";
3840 $city["America"]["Guatemala"] = "Guatemala";
3841 $city["America"]["Guayaquil"] = "Guayaquil";
3842 $city["America"]["Guyana"] = "Guyana";
3843 $city["America"]["Halifax"] = "Halifax";
3844 $city["America"]["Havana"] = "Havana";
3845 $city["America"]["Hermosillo"] = "Hermosillo";
3846 $city["America"]["Indiana/Indianapolis"] = "Indiana - Indianapolis";
3847 $city["America"]["Indiana/Knox"] = "Indiana - Knox";
3848 $city["America"]["Indiana/Marengo"] = "Indiana - Marengo";
3849 $city["America"]["Indiana/Petersburg"] = "Indiana - Petersburg";
3850 $city["America"]["Indiana/Tell_City"] = "Indiana - Tell City";
3851 $city["America"]["Indiana/Vevay"] = "Indiana - Vevay";
3852 $city["America"]["Indiana/Vincennes"] = "Indiana - Vincennes";
3853 $city["America"]["Indiana/Winamac"] = "Indiana - Winamac";
3854 $city["America"]["Inuvik"] = "Inuvik";
3855 $city["America"]["Iqaluit"] = "Iqaluit";
3856 $city["America"]["Jamaica"] = "Jamaica";
3857 $city["America"]["Juneau"] = "Juneau";
3858 $city["America"]["Kentucky/Louisville"] = "Kentucky - Louisville";
3859 $city["America"]["Kentucky/Monticello"] = "Kentucky - Monticello";
3860 $city["America"]["La_Paz"] = "La Paz";
3861 $city["America"]["Lima"] = "Lima";
3862 $city["America"]["Los_Angeles"] = "Los Angeles";
3863 $city["America"]["Maceio"] = "Maceio";
3864 $city["America"]["Managua"] = "Managua";
3865 $city["America"]["Manaus"] = "Manaus";
3866 $city["America"]["Marigot"] = "Marigot";
3867 $city["America"]["Martinique"] = "Martinique";
3868 $city["America"]["Mazatlan"] = "Mazatlan";
3869 $city["America"]["Menominee"] = "Menominee";
3870 $city["America"]["Merida"] = "Merida";
3871 $city["America"]["Mexico_City"] = "Mexico City";
3872 $city["America"]["Miquelon"] = "Miquelon";
3873 $city["America"]["Moncton"] = "Moncton";
3874 $city["America"]["Monterrey"] = "Monterrey";
3875 $city["America"]["Montevideo"] = "Montevideo";
3876 $city["America"]["Montreal"] = "Montreal";
3877 $city["America"]["Montserrat"] = "Montserrat";
3878 $city["America"]["Nassau"] = "Nassau";
3879 $city["America"]["New_York"] = "New York";
3880 $city["America"]["Nipigon"] = "Nipigon";
3881 $city["America"]["Nome"] = "Nome";
3882 $city["America"]["Noronha"] = "Noronha";
3883 $city["America"]["North_Dakota/Center"] = "North Dakota - Center";
3884 $city["America"]["North_Dakota/New_Salem"] = "North Dakota - New Salem";
3885 $city["America"]["Panama"] = "Panama";
3886 $city["America"]["Pangnirtung"] = "Pangnirtung";
3887 $city["America"]["Paramaribo"] = "Paramaribo";
3888 $city["America"]["Phoenix"] = "Phoenix";
3889 $city["America"]["Port-au-Prince"] = "Port-au-Prince";
3890 $city["America"]["Port_of_Spain"] = "Port of Spain";
3891 $city["America"]["Porto_Velho"] = "Porto Velho";
3892 $city["America"]["Puerto_Rico"] = "Puerto Rico";
3893 $city["America"]["Rainy_River"] = "Rainy River";
3894 $city["America"]["Rankin_Inlet"] = "Rankin Inlet";
3895 $city["America"]["Recife"] = "Recife";
3896 $city["America"]["Regina"] = "Regina";
3897 $city["America"]["Resolute"] = "Resolute";
3898 $city["America"]["Rio_Branco"] = "Rio Branco";
3899 $city["America"]["Santarem"] = "Santarem";
3900 $city["America"]["Santiago"] = "Santiago";
3901 $city["America"]["Santo_Domingo"] = "Santo Domingo";
3902 $city["America"]["Sao_Paulo"] = "Sao Paulo";
3903 $city["America"]["Scoresbysund"] = "Scoresbysund";
3904 $city["America"]["Shiprock"] = "Shiprock";
3905 $city["America"]["St_Barthelemy"] = "St Barthelemy";
3906 $city["America"]["St_Johns"] = "St Johns";
3907 $city["America"]["St_Kitts"] = "St Kitts";
3908 $city["America"]["St_Lucia"] = "St Lucia";
3909 $city["America"]["St_Thomas"] = "St Thomas";
3910 $city["America"]["St_Vincent"] = "St Vincent";
3911 $city["America"]["Swift_Current"] = "Swift Current";
3912 $city["America"]["Tegucigalpa"] = "Tegucigalpa";
3913 $city["America"]["Thule"] = "Thule";
3914 $city["America"]["Thunder_Bay"] = "Thunder Bay";
3915 $city["America"]["Tijuana"] = "Tijuana";
3916 $city["America"]["Toronto"] = "Toronto";
3917 $city["America"]["Tortola"] = "Tortola";
3918 $city["America"]["Vancouver"] = "Vancouver";
3919 $city["America"]["Whitehorse"] = "Whitehorse";
3920 $city["America"]["Winnipeg"] = "Winnipeg";
3921 $city["America"]["Yakutat"] = "Yakutat";
3922 $city["America"]["Yellowknife"] = "Yellowknife";
3923
3924 $city["Antarctica"]["Casey"] = "Casey";
3925 $city["Antarctica"]["Davis"] = "Davis";
3926 $city["Antarctica"]["DumontDUrville"] = "DumontDUrville";
3927 $city["Antarctica"]["Mawson"] = "Mawson";
3928 $city["Antarctica"]["McMurdo"] = "McMurdo";
3929 $city["Antarctica"]["Palmer"] = "Palmer";
3930 $city["Antarctica"]["Rothera"] = "Rothera";
3931 $city["Antarctica"]["South_Pole"] = "South Pole";
3932 $city["Antarctica"]["Syowa"] = "Syowa";
3933 $city["Antarctica"]["Vostok"] = "Vostok";
3934
3935 $city["Arctic"]["Longyearbyen"] = "Longyearbyen";
3936
3937 $city["Asia"]["Aden"] = "Aden";
3938 $city["Asia"]["Almaty"] = "Almaty";
3939 $city["Asia"]["Amman"] = "Amman";
3940 $city["Asia"]["Anadyr"] = "Anadyr";
3941 $city["Asia"]["Aqtau"] = "Aqtau";
3942 $city["Asia"]["Aqtobe"] = "Aqtobe";
3943 $city["Asia"]["Ashgabat"] = "Ashgabat";
3944 $city["Asia"]["Baghdad"] = "Baghdad";
3945 $city["Asia"]["Bahrain"] = "Bahrain";
3946 $city["Asia"]["Baku"] = "Baku";
3947 $city["Asia"]["Bangkok"] = "Bangkok";
3948 $city["Asia"]["Beirut"] = "Beirut";
3949 $city["Asia"]["Bishkek"] = "Bishkek";
3950 $city["Asia"]["Brunei"] = "Brunei";
3951 $city["Asia"]["Choibalsan"] = "Choibalsan";
3952 $city["Asia"]["Chongqing"] = "Chongqing";
3953 $city["Asia"]["Colombo"] = "Colombo";
3954 $city["Asia"]["Damascus"] = "Damascus";
3955 $city["Asia"]["Dhaka"] = "Dhaka";
3956 $city["Asia"]["Dili"] = "Dili";
3957 $city["Asia"]["Dubai"] = "Dubai";
3958 $city["Asia"]["Dushanbe"] = "Dushanbe";
3959 $city["Asia"]["Gaza"] = "Gaza";
3960 $city["Asia"]["Harbin"] = "Harbin";
3961 $city["Asia"]["Ho_Chi_Minh"] = "Ho Chi Minh";
3962 $city["Asia"]["Hong_Kong"] = "Hong Kong";
3963 $city["Asia"]["Hovd"] = "Hovd";
3964 $city["Asia"]["Irkutsk"] = "Irkutsk";
3965 $city["Asia"]["Jakarta"] = "Jakarta";
3966 $city["Asia"]["Jayapura"] = "Jayapura";
3967 $city["Asia"]["Jerusalem"] = "Jerusalem";
3968 $city["Asia"]["Kabul"] = "Kabul";
3969 $city["Asia"]["Kamchatka"] = "Kamchatka";
3970 $city["Asia"]["Karachi"] = "Karachi";
3971 $city["Asia"]["Kashgar"] = "Kashgar";
3972 $city["Asia"]["Kathmandu"] = "Kathmandu";
3973 $city["Asia"]["Kolkata"] = "Kolkata";
3974 $city["Asia"]["Krasnoyarsk"] = "Krasnoyarsk";
3975 $city["Asia"]["Kuala_Lumpur"] = "Kuala Lumpur";
3976 $city["Asia"]["Kuching"] = "Kuching";
3977 $city["Asia"]["Kuwait"] = "Kuwait";
3978 $city["Asia"]["Macau"] = "Macau";
3979 $city["Asia"]["Magadan"] = "Magadan";
3980 $city["Asia"]["Makassar"] = "Makassar";
3981 $city["Asia"]["Manila"] = "Manila";
3982 $city["Asia"]["Muscat"] = "Muscat";
3983 $city["Asia"]["Nicosia"] = "Nicosia";
3984 $city["Asia"]["Novosibirsk"] = "Novosibirsk";
3985 $city["Asia"]["Omsk"] = "Omsk";
3986 $city["Asia"]["Oral"] = "Oral";
3987 $city["Asia"]["Phnom_Penh"] = "Phnom Penh";
3988 $city["Asia"]["Pontianak"] = "Pontianak";
3989 $city["Asia"]["Pyongyang"] = "Pyongyang";
3990 $city["Asia"]["Qatar"] = "Qatar";
3991 $city["Asia"]["Qyzylorda"] = "Qyzylorda";
3992 $city["Asia"]["Rangoon"] = "Rangoon";
3993 $city["Asia"]["Riyadh"] = "Riyadh";
3994 $city["Asia"]["Sakhalin"] = "Sakhalin";
3995 $city["Asia"]["Samarkand"] = "Samarkand";
3996 $city["Asia"]["Seoul"] = "Seoul";
3997 $city["Asia"]["Shanghai"] = "Shanghai";
3998 $city["Asia"]["Singapore"] = "Singapore";
3999 $city["Asia"]["Taipei"] = "Taipei";
4000 $city["Asia"]["Tashkent"] = "Tashkent";
4001 $city["Asia"]["Tbilisi"] = "Tbilisi";
4002 $city["Asia"]["Tehran"] = "Tehran";
4003 $city["Asia"]["Thimphu"] = "Thimphu";
4004 $city["Asia"]["Tokyo"] = "Tokyo";
4005 $city["Asia"]["Ulaanbaatar"] = "Ulaanbaatar";
4006 $city["Asia"]["Urumqi"] = "Urumqi";
4007 $city["Asia"]["Vientiane"] = "Vientiane";
4008 $city["Asia"]["Vladivostok"] = "Vladivostok";
4009 $city["Asia"]["Yakutsk"] = "Yakutsk";
4010 $city["Asia"]["Yekaterinburg"] = "Yekaterinburg";
4011 $city["Asia"]["Yerevan"] = "Yerevan";
4012
4013 $city["Atlantic"]["Azores"] = "Azores";
4014 $city["Atlantic"]["Bermuda"] = "Bermuda";
4015 $city["Atlantic"]["Canary"] = "Canary";
4016 $city["Atlantic"]["Cape_Verde"] = "Cape Verde";
4017 $city["Atlantic"]["Faroe"] = "Faroe";
4018 $city["Atlantic"]["Madeira"] = "Madeira";
4019 $city["Atlantic"]["Reykjavik"] = "Reykjavik";
4020 $city["Atlantic"]["South_Georgia"] = "South Georgia";
4021 $city["Atlantic"]["Stanley"] = "Stanley";
4022 $city["Atlantic"]["St_Helena"] = "St Helena";
4023
4024 $city["Australia"]["Adelaide"] = "Adelaide";
4025 $city["Australia"]["Brisbane"] = "Brisbane";
4026 $city["Australia"]["Broken_Hill"] = "Broken Hill";
4027 $city["Australia"]["Currie"] = "Currie";
4028 $city["Australia"]["Darwin"] = "Darwin";
4029 $city["Australia"]["Eucla"] = "Eucla";
4030 $city["Australia"]["Hobart"] = "Hobart";
4031 $city["Australia"]["Lindeman"] = "Lindeman";
4032 $city["Australia"]["Lord_Howe"] = "Lord Howe";
4033 $city["Australia"]["Melbourne"] = "Melbourne";
4034 $city["Australia"]["Perth"] = "Perth";
4035 $city["Australia"]["Sydney"] = "Sydney";
4036
4037 $city["Europe"]["Amsterdam"] = "Amsterdam";
4038 $city["Europe"]["Andorra"] = "Andorra";
4039 $city["Europe"]["Athens"] = "Athens";
4040 $city["Europe"]["Belgrade"] = "Belgrade";
4041 $city["Europe"]["Berlin"] = "Berlin";
4042 $city["Europe"]["Bratislava"] = "Bratislava";
4043 $city["Europe"]["Brussels"] = "Brussels";
4044 $city["Europe"]["Bucharest"] = "Bucharest";
4045 $city["Europe"]["Budapest"] = "Budapest";
4046 $city["Europe"]["Chisinau"] = "Chisinau";
4047 $city["Europe"]["Copenhagen"] = "Copenhagen";
4048 $city["Europe"]["Dublin"] = "Dublin";
4049 $city["Europe"]["Gibraltar"] = "Gibraltar";
4050 $city["Europe"]["Guernsey"] = "Guernsey";
4051 $city["Europe"]["Helsinki"] = "Helsinki";
4052 $city["Europe"]["Isle_of_Man"] = "Isle of Man";
4053 $city["Europe"]["Istanbul"] = "Istanbul";
4054 $city["Europe"]["Jersey"] = "Jersey";
4055 $city["Europe"]["Kaliningrad"] = "Kaliningrad";
4056 $city["Europe"]["Kiev"] = "Kiev";
4057 $city["Europe"]["Lisbon"] = "Lisbon";
4058 $city["Europe"]["Ljubljana"] = "Ljubljana";
4059 $city["Europe"]["London"] = "London";
4060 $city["Europe"]["Luxembourg"] = "Luxembourg";
4061 $city["Europe"]["Madrid"] = "Madrid";
4062 $city["Europe"]["Malta"] = "Malta";
4063 $city["Europe"]["Mariehamn"] = "Mariehamn";
4064 $city["Europe"]["Minsk"] = "Minsk";
4065 $city["Europe"]["Monaco"] = "Monaco";
4066 $city["Europe"]["Moscow"] = "Moscow";
4067 $city["Europe"]["Oslo"] = "Oslo";
4068 $city["Europe"]["Paris"] = "Paris";
4069 $city["Europe"]["Podgorica"] = "Podgorica";
4070 $city["Europe"]["Prague"] = "Prague";
4071 $city["Europe"]["Riga"] = "Riga";
4072 $city["Europe"]["Rome"] = "Rome";
4073 $city["Europe"]["Samara"] = "Samara";
4074 $city["Europe"]["San_Marino"] = "San Marino";
4075 $city["Europe"]["Sarajevo"] = "Sarajevo";
4076 $city["Europe"]["Simferopol"] = "Simferopol";
4077 $city["Europe"]["Skopje"] = "Skopje";
4078 $city["Europe"]["Sofia"] = "Sofia";
4079 $city["Europe"]["Stockholm"] = "Stockholm";
4080 $city["Europe"]["Tallinn"] = "Tallinn";
4081 $city["Europe"]["Tirane"] = "Tirane";
4082 $city["Europe"]["Uzhgorod"] = "Uzhgorod";
4083 $city["Europe"]["Vaduz"] = "Vaduz";
4084 $city["Europe"]["Vatican"] = "Vatican";
4085 $city["Europe"]["Vienna"] = "Vienna";
4086 $city["Europe"]["Vilnius"] = "Vilnius";
4087 $city["Europe"]["Volgograd"] = "Volgograd";
4088 $city["Europe"]["Warsaw"] = "Warsaw";
4089 $city["Europe"]["Zagreb"] = "Zagreb";
4090 $city["Europe"]["Zaporozhye"] = "Zaporozhye";
4091 $city["Europe"]["Zurich"] = "Zurich";
4092
4093 $city["Indian"]["Antananarivo"] = "Antananarivo";
4094 $city["Indian"]["Chagos"] = "Chagos";
4095 $city["Indian"]["Christmas"] = "Christmas";
4096 $city["Indian"]["Cocos"] = "Cocos";
4097 $city["Indian"]["Comoro"] = "Comoro";
4098 $city["Indian"]["Kerguelen"] = "Kerguelen";
4099 $city["Indian"]["Mahe"] = "Mahe";
4100 $city["Indian"]["Maldives"] = "Maldives";
4101 $city["Indian"]["Mauritius"] = "Mauritius";
4102 $city["Indian"]["Mayotte"] = "Mayotte";
4103 $city["Indian"]["Reunion"] = "Reunion";
4104
4105 $city["Pacific"]["Apia"] = "Apia";
4106 $city["Pacific"]["Auckland"] = "Auckland";
4107 $city["Pacific"]["Chatham"] = "Chatham";
4108 $city["Pacific"]["Easter"] = "Easter";
4109 $city["Pacific"]["Efate"] = "Efate";
4110 $city["Pacific"]["Enderbury"] = "Enderbury";
4111 $city["Pacific"]["Fakaofo"] = "Fakaofo";
4112 $city["Pacific"]["Fiji"] = "Fiji";
4113 $city["Pacific"]["Funafuti"] = "Funafuti";
4114 $city["Pacific"]["Galapagos"] = "Galapagos";
4115 $city["Pacific"]["Gambier"] = "Gambier";
4116 $city["Pacific"]["Guadalcanal"] = "Guadalcanal";
4117 $city["Pacific"]["Guam"] = "Guam";
4118 $city["Pacific"]["Honolulu"] = "Honolulu";
4119 $city["Pacific"]["Johnston"] = "Johnston";
4120 $city["Pacific"]["Kiritimati"] = "Kiritimati";
4121 $city["Pacific"]["Kosrae"] = "Kosrae";
4122 $city["Pacific"]["Kwajalein"] = "Kwajalein";
4123 $city["Pacific"]["Majuro"] = "Majuro";
4124 $city["Pacific"]["Marquesas"] = "Marquesas";
4125 $city["Pacific"]["Midway"] = "Midway";
4126 $city["Pacific"]["Nauru"] = "Nauru";
4127 $city["Pacific"]["Niue"] = "Niue";
4128 $city["Pacific"]["Norfolk"] = "Norfolk";
4129 $city["Pacific"]["Noumea"] = "Noumea";
4130 $city["Pacific"]["Pago_Pago"] = "Pago Pago";
4131 $city["Pacific"]["Palau"] = "Palau";
4132 $city["Pacific"]["Pitcairn"] = "Pitcairn";
4133 $city["Pacific"]["Ponape"] = "Ponape";
4134 $city["Pacific"]["Port_Moresby"] = "Port Moresby";
4135 $city["Pacific"]["Rarotonga"] = "Rarotonga";
4136 $city["Pacific"]["Saipan"] = "Saipan";
4137 $city["Pacific"]["Tahiti"] = "Tahiti";
4138 $city["Pacific"]["Tarawa"] = "Tarawa";
4139 $city["Pacific"]["Tongatapu"] = "Tongatapu";
4140 $city["Pacific"]["Truk"] = "Truk";
4141 $city["Pacific"]["Wake"] = "Wake";
4142 $city["Pacific"]["Wallis"] = "Wallis";
4143
4144 return $city;
4145 }
4146
4147 // </editor-fold>
4148
4149
4150 // <editor-fold defaultstate="collapsed" desc=" == Logs for Notes / remarks == " >
4151
4152 /**
4153 * Add Log info to Notes of bookings
4154 *
4155 * @param array | int $booking_id_arr
4156 * @param string $message
4157 */
4158 function wpbc_db__add_log_info( $booking_id_arr, $message ) {
4159
4160 if ( get_bk_option( 'booking_log_booking_actions' ) !== 'On' ) {
4161 return;
4162 }
4163
4164 $booking_id_arr = (array) $booking_id_arr;
4165
4166 $is_append = true;
4167 foreach ( $booking_id_arr as $booking_id ) {
4168 $date_time = date_i18n( '[Y-m-d H:i] ' );
4169 make_bk_action('wpdev_make_update_of_remark' , $booking_id , $date_time . $message , $is_append ); //FixIn: 9.1.2.14
4170 }
4171 }
4172
4173 // </editor-fold>
4174
4175
4176 // <editor-fold defaultstate="collapsed" desc=" == CSV export support function == " >
4177
4178 /**
4179 * Get Path from request URL. E.g. 'my-category/file.csv' from url, like https://server.com/my-category/file.csv
4180 *
4181 * It can detect internal sub folder or WordPress, like http://server.com/my-website/
4182 *
4183 * @return false|string
4184 */
4185 function wpbc_get_request_url_path(){
4186
4187 if ( function_exists( 'wp_parse_url' ) ) {
4188 $my_parsed_url = wp_parse_url( $_SERVER['REQUEST_URI'] );
4189 } else {
4190 $my_parsed_url = @parse_url( $_SERVER['REQUEST_URI'] );
4191 }
4192
4193 if ( false === $my_parsed_url ) { // seriously malformed URLs, parse_url() may return FALSE.
4194 return false;
4195 }
4196
4197 $my_parsed_url_path = trim( $my_parsed_url['path'] );
4198 $my_parsed_url_path = trim( $my_parsed_url_path, '/' );
4199
4200
4201 // Check internal sub folder of WP, like http://server.com/my-website/[ ... LINK ...] //FixIn: 2.0.5.4
4202 if ( function_exists( 'wp_parse_url' ) ) {
4203 $wp_home_server_url = wp_parse_url( home_url() );
4204 } else {
4205 $wp_home_server_url = @parse_url( home_url() );
4206 }
4207
4208 if ( ( false !== $wp_home_server_url ) && ( ! empty( $wp_home_server_url['path'] ) ) ) { // seriously malformed URLs, parse_url() may return FALSE.
4209
4210 $server_url_sufix = trim( $wp_home_server_url[ 'path' ] ); // [path] => /my-website
4211 $server_url_sufix = trim( $server_url_sufix, '/' ); // my-website
4212
4213 if ( ! empty( $server_url_sufix ) ) {
4214
4215 $check_sufix = substr( $my_parsed_url_path, 0, strlen( $server_url_sufix ) );
4216
4217 if ( $check_sufix === $server_url_sufix ) {
4218
4219 $my_parsed_url_path = substr( $my_parsed_url_path, strlen( $server_url_sufix ) );
4220
4221 $my_parsed_url_path = trim( $my_parsed_url_path, '/' );
4222 }
4223 }
4224 } //End FixIn: 2.0.5.4
4225
4226 return $my_parsed_url_path;
4227 }
4228
4229 // </editor-fold>
4230
4231
4232 // <editor-fold defaultstate="collapsed" desc=" == SKIP BLANK EMAIL == " >
4233
4234
4235 /**
4236 * Check if this email is NOT blank email to SKIP email sending -- from autofill fast booking creation at Booking > Add booking page.
4237 *
4238 * Currently, plugin use 'blank@wpbookingmanager.com' for all blank bookings, previously it was used 'admin@blank.com'
4239 *
4240 * @param $email_address
4241 * @param $email_content
4242 *
4243 * @return bool
4244 */
4245 function wpbc_is_not_blank_email( $email_address, $email_content ) {
4246
4247 // Previously: if ( ( strpos( $to, '@blank.com' ) === false ) && ( strpos( $replace['content'], 'admin@blank.com' ) === false ) ) { ->send(...) }
4248
4249 if (
4250 ( false === strpos( $email_address, '@blank.com' ) )
4251 && ( false === strpos( $email_content, 'admin@blank.com' ) )
4252 && ( false === strpos( $email_address, '@wpbookingmanager.com' ) )
4253 && ( false === strpos( $email_content, 'blank@wpbookingmanager.com' ) )
4254 ) {
4255 return true;
4256 }
4257
4258 return false;
4259 }
4260
4261 // </editor-fold>
4262
4263
4264 // <editor-fold defaultstate="collapsed" desc=" == PHP PERFORMANCE == " >
4265
4266
4267 /**
4268 * Start calculation of time for execution of specific part of CODE
4269 *
4270 * @param string $name name of section
4271 * @param array $php_performance
4272 *
4273 * @return array
4274 *
4275 * Example:
4276 *
4277 * $php_performance = php_performance_START( 'emails_sending' , $php_performance );
4278 *
4279 * ... some code here ...
4280 *
4281 * $php_performance = php_performance_END( 'emails_sending' , $php_performance );
4282 *
4283 * echo 'Time of execution: ' . $php_performancep['emails_sending']
4284 *
4285 */
4286 function php_performance_START( $name, $php_performance ) {
4287
4288 if ( empty( $php_performance ) ) {
4289 $php_performance = array();
4290 }
4291
4292 $php_performance[ $name ] = microtime( true );
4293
4294 return $php_performance;
4295 }
4296
4297 /**
4298 * End calculation of time for execution of specific part of CODE
4299 *
4300 * @param string $name name of section
4301 * @param array $php_performance
4302 *
4303 * @return array
4304 *
4305 * Example:
4306 *
4307 * $php_performance = php_performance_START( 'emails_sending' , $php_performance );
4308 *
4309 * ... some code here ...
4310 *
4311 * $php_performance = php_performance_END( 'emails_sending' , $php_performance );
4312 *
4313 * echo 'Time of execution: ' . $php_performancep['emails_sending']
4314 *
4315 */
4316 function php_performance_END( $name, $php_performance ) {
4317
4318 if ( empty( $php_performance ) ) {
4319 $php_performance = array();
4320 }
4321 if ( empty( $php_performance[ $name ] ) ) {
4322 $php_performance[ $name ] = microtime( true );
4323 }
4324
4325 $php_performance[ $name ] = microtime( true ) - $php_performance[ $name ];
4326
4327 return $php_performance;
4328 }
4329
4330 /**
4331 * Set maximum number of seconds for execution.
4332 *
4333 * @param $limit_in_seconds_int
4334 *
4335 * @return void
4336 */
4337 function wpbc_set_limit_php( $limit_in_seconds_int = 300 ){
4338
4339 $is_win = ( 'WIN' === strtoupper( substr( PHP_OS, 0, 3 ) ) );
4340
4341 // Windows does not have support for this timeout function
4342 if ( ! $is_win ) {
4343
4344 $max = (int) ini_get( 'max_execution_time' );
4345
4346 // If unlimited, or if set_time_limit is disabled, then skip.
4347 if (
4348 ( 0 !== $max )
4349 && ( $limit_in_seconds_int > $max )
4350 && ( function_exists( 'set_time_limit' ) )
4351 && ( false === strpos( ini_get( 'disable_functions' ), 'set_time_limit' ) )
4352 && ( ! ini_get( 'safe_mode' ) )
4353 ) {
4354 @set_time_limit( $limit_in_seconds_int );
4355 @ini_set( 'memory_limit', '512M' );
4356 }
4357 }
4358 }
4359
4360
4361 // </editor-fold>