| 1 |
<?php |
| 2 |
/** |
| 3 |
* @file: wp-content/plugins/booking/core/lib/wpdev-booking-class.php |
| 4 |
*/ |
| 5 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 6 |
|
| 7 |
class wpdev_booking { |
| 8 |
|
| 9 |
public $popover_front_end_js_is_writed; //FixIn: Flex TimeLine 1.0 -- previos this was private and not public property |
| 10 |
|
| 11 |
// <editor-fold defaultstate="collapsed" desc=" C O N S T R U C T O R & P r o p e r t i e s "> |
| 12 |
|
| 13 |
var $wpdev_bk_personal; |
| 14 |
|
| 15 |
function __construct() { |
| 16 |
|
| 17 |
$this->popover_front_end_js_is_writed = false; |
| 18 |
$this->wpdev_bk_personal = false; |
| 19 |
|
| 20 |
if ( class_exists( 'wpdev_bk_personal' ) ) { |
| 21 |
$this->wpdev_bk_personal = new wpdev_bk_personal(); |
| 22 |
} |
| 23 |
|
| 24 |
add_action( 'init', array( $this, 'wpbc_shortcodes_init' ), 9999 ); // <- priority to load it last |
| 25 |
} |
| 26 |
// </editor-fold> |
| 27 |
|
| 28 |
|
| 29 |
/** |
| 30 |
* S H O R T C O D E s Init |
| 31 |
* |
| 32 |
* @return void |
| 33 |
*/ |
| 34 |
function wpbc_shortcodes_init(){ |
| 35 |
add_shortcode( 'bookingedit', array( $this, 'bookingedit_shortcode' ) ); |
| 36 |
add_shortcode( 'bookingsearch', array( $this, 'bookingsearch_shortcode' ) ); |
| 37 |
add_shortcode( 'bookingsearchresults', array( $this, 'bookingsearchresults_shortcode' ) ); |
| 38 |
add_shortcode( 'bookingselect', array( $this, 'bookingselect_shortcode' ) ); |
| 39 |
add_shortcode( 'bookingresource', array( $this, 'bookingresource_shortcode' ) ); |
| 40 |
add_shortcode( 'bookingtimeline', array( $this, 'bookingtimeline_shortcode' ) ); |
| 41 |
add_shortcode( 'bookingcustomerlisting', array( $this, 'bookingcustomerlisting_shortcode' ) ); // FixIn: 8.1.3.5. |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
// <editor-fold defaultstate="collapsed" desc=" S H O R T C O D E S "> |
| 46 |
|
| 47 |
// FixIn: 8.1.3.5. |
| 48 |
/** Listing customners bookings in timeline view |
| 49 |
* |
| 50 |
* @param $attr - The same parameters as for bookingtimeline shortcode (function) |
| 51 |
* |
| 52 |
* @return mixed|string|void |
| 53 |
*/ |
| 54 |
function bookingcustomerlisting_shortcode( $attr ){ |
| 55 |
|
| 56 |
if ( ! class_exists( 'wpdev_bk_personal' ) ) { |
| 57 |
return '<strong>' . esc_html__('This shortcode available in Pro versions, only!' ,'booking') . '</strong> '; |
| 58 |
} |
| 59 |
|
| 60 |
if ( wpbc_is_on_edit_page() ) { |
| 61 |
return wpbc_get_preview_for_shortcode( 'bookingcustomerlisting', $attr ); // FixIn: 9.9.0.39. |
| 62 |
} |
| 63 |
|
| 64 |
$attr = wpbc_escape_shortcode_params( $attr ); //FixIn: 9.7.3.6.1 |
| 65 |
|
| 66 |
// FixIn: 8.4.5.11. |
| 67 |
if (! is_array($attr)) { |
| 68 |
$attr = array(); |
| 69 |
} |
| 70 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 71 |
if ( ( isset( $_GET['booking_hash'] ) ) || ( isset( $attr['booking_hash'] ) ) ) { |
| 72 |
|
| 73 |
|
| 74 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 75 |
if ( isset( $_GET['booking_hash'] ) ) { |
| 76 |
$get_booking_hash = ( ( isset( $_GET['booking_hash'] ) ) ? sanitize_text_field( wp_unslash( $_GET['booking_hash'] ) ) : '' ); /* phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing */ /* FixIn: sanitize_unslash */ |
| 77 |
$my_booking_id_type = wpbc_hash__get_booking_id__resource_id( $get_booking_hash ); |
| 78 |
|
| 79 |
$attr['booking_hash'] = $get_booking_hash; |
| 80 |
} else { |
| 81 |
$my_booking_id_type = wpbc_hash__get_booking_id__resource_id( $attr['booking_hash'] ); |
| 82 |
} |
| 83 |
|
| 84 |
if ( $my_booking_id_type !== false ) { |
| 85 |
|
| 86 |
if ( ! isset( $attr['type' ] ) ) { // 8.1.3.5.2 |
| 87 |
|
| 88 |
$br_list = wpbc_get_all_booking_resources_list(); |
| 89 |
$br_list = array_keys( $br_list ); |
| 90 |
$br_list = implode(',',$br_list); |
| 91 |
$attr['type' ] = $br_list; //wpbc_get_default_resource(); |
| 92 |
} |
| 93 |
if ( ! isset( $attr['view_days_num' ] ) ) { |
| 94 |
$attr['view_days_num' ] = 30; |
| 95 |
} |
| 96 |
if ( ! isset( $attr['scroll_start_date' ] ) ) { |
| 97 |
$attr['scroll_start_date' ] = ''; |
| 98 |
} |
| 99 |
if ( ! isset( $attr['scroll_day' ] ) ) { |
| 100 |
$attr['scroll_day' ] = 0; |
| 101 |
} |
| 102 |
if ( ! isset( $attr['scroll_month' ] ) ) { |
| 103 |
$attr['scroll_month' ] = 0; |
| 104 |
} |
| 105 |
if ( ! isset( $attr['header_title' ] ) ) { |
| 106 |
$attr['header_title' ] = __( 'My bookings' , 'booking'); |
| 107 |
} |
| 108 |
|
| 109 |
$timeline_results = $this->bookingtimeline_shortcode( $attr ); |
| 110 |
|
| 111 |
return $timeline_results ; |
| 112 |
|
| 113 |
} else { |
| 114 |
return '<div class="wpbc_after_booking_thank_you_section"><div class="wpbc_ty__container"><div class="wpbc_ty__header"><strong>' . esc_html__('Oops!' ,'booking') . '</strong> ' . esc_html__('We could not find your booking. The link you used may be incorrect or has expired. If you need assistance, please contact our support team.' ,'booking') . '</div></div></div>'; |
| 115 |
} |
| 116 |
|
| 117 |
} else { |
| 118 |
return __( 'This page can only be accessed through links in emails related to your booking.', 'booking' ) |
| 119 |
. ' <br/><em>' |
| 120 |
/* translators: 1: ... */ |
| 121 |
. sprintf( __( 'Please check more about configuration at %1$sthis page%2$s', 'booking' ), '<a href="https://wpbookingcalendar.com/faq/configure-editing-cancel-payment-bookings-for-visitors/" target="_blank">', '</a>.' ) |
| 122 |
. '</em>'; |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
/** |
| 127 |
* TimeLine shortcode |
| 128 |
* |
| 129 |
* @param type $attr |
| 130 |
* |
| 131 |
* @return type |
| 132 |
* |
| 133 |
* Shortcodes exmaples: |
| 134 |
* |
| 135 |
* |
| 136 |
** Matrix: |
| 137 |
* 1 Month View Mode: |
| 138 |
* [bookingtimeline type="3,4,1,5,6,7,8,9,2,10,11,12,14" view_days_num=30 scroll_start_date="" scroll_month=0 header_title='All Bookings'] |
| 139 |
* 2 Months View Mode: |
| 140 |
* [bookingtimeline type="1,5,6,7,8,9,2,10,11,12,3,4,14" view_days_num=60 scroll_start_date="" scroll_month=-1 header_title='All Bookings'] |
| 141 |
* 1 Week View Mode: |
| 142 |
* [bookingtimeline type="3,4" view_days_num=7 scroll_start_date="" scroll_day=-7 header_title='All Bookings'] |
| 143 |
* 1 Day View Mode: |
| 144 |
* [bookingtimeline type="3,4" view_days_num=1 scroll_start_date="" scroll_day=0 header_title='All Bookings'] |
| 145 |
** Single: |
| 146 |
* 1 Month View Mode: |
| 147 |
* [bookingtimeline type="4" view_days_num=30 scroll_start_date="" scroll_day=-15 scroll_month=0 header_title='All Bookings'] |
| 148 |
* 3 Months View Mode: |
| 149 |
* [bookingtimeline type="4" view_days_num=90 scroll_start_date="" scroll_day=-30] |
| 150 |
* 1 Year View Mode: |
| 151 |
* [bookingtimeline type="4" view_days_num=365 scroll_start_date="" scroll_month=-3] |
| 152 |
*/ |
| 153 |
function bookingtimeline_shortcode($attr) { |
| 154 |
|
| 155 |
if ( wpbc_is_on_edit_page() ) { |
| 156 |
return wpbc_get_preview_for_shortcode( 'bookingtimeline', $attr ); // FixIn: 9.9.0.39. |
| 157 |
} |
| 158 |
|
| 159 |
$attr = wpbc_escape_shortcode_params( $attr ); //FixIn: 9.7.3.6.1 |
| 160 |
|
| 161 |
// FixIn: 8.6.1.13. |
| 162 |
$timeline_results = bookingflextimeline_shortcode($attr); |
| 163 |
return $timeline_results; |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
// Show booking form for editing |
| 168 |
function bookingedit_shortcode($attr) { |
| 169 |
|
| 170 |
if ( wpbc_is_on_edit_page() ) { |
| 171 |
return wpbc_get_preview_for_shortcode( 'bookingedit', $attr ); // FixIn: 9.9.0.39. |
| 172 |
} |
| 173 |
|
| 174 |
$attr = wpbc_escape_shortcode_params( $attr ); //FixIn: 9.7.3.6.1 |
| 175 |
|
| 176 |
|
| 177 |
//if ( function_exists( 'wpbc_br_cache' ) ) $br_cache = wpbc_br_cache(); // Init booking resources cache |
| 178 |
|
| 179 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 180 |
if ( isset( $_GET['wpbc_hash'] ) ) { |
| 181 |
|
| 182 |
if ( function_exists( 'wpbc_parse_one_way_hash' ) ) { |
| 183 |
|
| 184 |
$get_wpbc_hash = ( ( isset( $_GET['wpbc_hash'] ) ) ? sanitize_text_field( wp_unslash( $_GET['wpbc_hash'] ) ) : '' ); /* phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing */ /* FixIn: sanitize_unslash */ |
| 185 |
|
| 186 |
$one_way_hash_response = wpbc_parse_one_way_hash( $get_wpbc_hash ); |
| 187 |
|
| 188 |
return $one_way_hash_response; |
| 189 |
} |
| 190 |
} |
| 191 |
|
| 192 |
$my_boook_count = get_bk_option( 'booking_client_cal_count' ); |
| 193 |
$my_boook_type = 1; |
| 194 |
$my_booking_form = 'standard'; |
| 195 |
$shortcode_param__options = array(); |
| 196 |
if ( isset( $attr['nummonths'] ) ) { $my_boook_count = intval( $attr['nummonths'] ); } |
| 197 |
if ( isset( $attr['resource_id'] ) ) { $attr['type'] = intval( $attr['resource_id']); } |
| 198 |
if ( isset( $attr['type'] ) ) { $my_boook_type = intval( $attr['type']); } |
| 199 |
if ( isset( $attr['form_type'] ) ) { $my_booking_form = $attr['form_type']; } |
| 200 |
if ( isset( $attr['agregate'] ) && ( ! empty( $attr['agregate'] ) ) ) { // FixIn: 7.0.1.26. |
| 201 |
$my_boook_type .= ';' . $attr['agregate']; |
| 202 |
} |
| 203 |
if ( isset( $attr['aggregate'] ) && ( ! empty( $attr['aggregate'] ) ) ) { |
| 204 |
$my_boook_type .= ';' . $attr['aggregate']; |
| 205 |
} |
| 206 |
// Escape any XSS in aggregate parameter. |
| 207 |
$my_boook_type = str_replace( ',', ';', wpbc_clean_digit_or_csd( $my_boook_type ) ); |
| 208 |
|
| 209 |
if ( isset( $attr['options'] ) ) { $shortcode_param__options = $attr['options']; } |
| 210 |
|
| 211 |
|
| 212 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 213 |
if (isset($_GET['booking_hash'])) { |
| 214 |
$get_booking_hash = ( ( isset( $_GET['booking_hash'] ) ) ? sanitize_text_field( wp_unslash( $_GET['booking_hash'] ) ) : '' ); /* phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing */ /* FixIn: sanitize_unslash */ |
| 215 |
$my_booking_id_type = wpbc_hash__get_booking_id__resource_id( $get_booking_hash ); |
| 216 |
if ($my_booking_id_type !== false) { |
| 217 |
$my_edited_bk_id = $my_booking_id_type[0]; |
| 218 |
$my_boook_type = $my_booking_id_type[1]; |
| 219 |
if ($my_boook_type == '') return '<div class="wpbc_after_booking_thank_you_section"><div class="wpbc_ty__container"><div class="wpbc_ty__header"><strong>' . esc_html__('Oops!' ,'booking') . '</strong> ' . esc_html__('We could not find your booking. The link you used may be incorrect or has expired. If you need assistance, please contact our support team.' ,'booking') . '</div></div></div>'; |
| 220 |
} else { |
| 221 |
return '<div class="wpbc_after_booking_thank_you_section"><div class="wpbc_ty__container"><div class="wpbc_ty__header"><strong>' . esc_html__('Oops!' ,'booking') . '</strong> ' . esc_html__('We could not find your booking. The link you used may be incorrect or has expired. If you need assistance, please contact our support team.' ,'booking') . '</div></div></div>'; |
| 222 |
} |
| 223 |
|
| 224 |
} else { |
| 225 |
return __('This page can only be accessed through links in emails related to your booking.' ,'booking') |
| 226 |
. ' <br/><em>' |
| 227 |
/* translators: 1: ... */ |
| 228 |
. sprintf( __( 'Please check more about configuration at %1$sthis page%2$s', 'booking' ) |
| 229 |
, '<a href="https://wpbookingcalendar.com/faq/configure-editing-cancel-payment-bookings-for-visitors/" target="_blank">' , '</a>.') |
| 230 |
. '</em>'; |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
$res = wpbc_get_rendered_booking_form_html($my_boook_type,$my_boook_count, 0 , $my_booking_form, '', false, $shortcode_param__options ); |
| 235 |
|
| 236 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 237 |
if (isset($_GET['booking_pay'])) { |
| 238 |
// Payment form |
| 239 |
if ( 'On' == get_bk_option( 'booking_super_admin_receive_regular_user_payments' ) ){ // FixIn: 9.2.3.8. |
| 240 |
make_bk_action('make_force_using_this_user', -999 ); // '-999' - This ID "by default" is the ID of super booking admin user |
| 241 |
} |
| 242 |
|
| 243 |
$get_booking_hash = ( ( isset( $_GET['booking_hash'] ) ) ? sanitize_text_field( wp_unslash( $_GET['booking_hash'] ) ) : '' ); /* phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing */ /* FixIn: sanitize_unslash */ |
| 244 |
$res = wpbc_do_shortcode__booking_confirm( array( |
| 245 |
'booking_hash' => $get_booking_hash |
| 246 |
) ); |
| 247 |
|
| 248 |
if ( 'On' == get_bk_option( 'booking_super_admin_receive_regular_user_payments' ) ){ // FixIn: 9.2.3.8. |
| 249 |
make_bk_action( 'finish_force_using_this_user' ); |
| 250 |
} |
| 251 |
|
| 252 |
} |
| 253 |
|
| 254 |
return $res; |
| 255 |
} |
| 256 |
|
| 257 |
// Search form |
| 258 |
function bookingsearch_shortcode($attr) { |
| 259 |
|
| 260 |
if ( ! class_exists( 'wpdev_bk_personal' ) ) { |
| 261 |
return '<strong>' . esc_html__( 'This shortcode available in Pro versions, only!', 'booking' ) . '</strong> '; |
| 262 |
} |
| 263 |
|
| 264 |
if ( wpbc_is_on_edit_page() ) { |
| 265 |
return wpbc_get_preview_for_shortcode( 'bookingsearch', $attr ); // FixIn: 9.9.0.39. |
| 266 |
} |
| 267 |
|
| 268 |
$attr = wpbc_escape_shortcode_params( $attr ); //FixIn: 9.7.3.6.1 |
| 269 |
|
| 270 |
$search_form = ''; |
| 271 |
|
| 272 |
if ( function_exists( 'wpbc_search_avy__show_search_form' ) ) { |
| 273 |
|
| 274 |
ob_start(); |
| 275 |
|
| 276 |
$search_form_content = wpbc_search_avy__show_search_form( $attr ); |
| 277 |
|
| 278 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 279 |
echo $search_form_content; |
| 280 |
|
| 281 |
$search_form = ob_get_clean(); |
| 282 |
} |
| 283 |
|
| 284 |
return $search_form ; |
| 285 |
} |
| 286 |
|
| 287 |
/** |
| 288 |
* Search Results Shortcode -- Show 'Search Results' at New Page |
| 289 |
* |
| 290 |
* @param $attr |
| 291 |
* |
| 292 |
* @return string |
| 293 |
*/ |
| 294 |
function bookingsearchresults_shortcode($attr) { |
| 295 |
|
| 296 |
if ( ! class_exists( 'wpdev_bk_personal' ) ) { |
| 297 |
return '<strong>' . esc_html__('This shortcode available in Pro versions, only!' ,'booking') . '</strong> '; |
| 298 |
} |
| 299 |
|
| 300 |
if ( wpbc_is_on_edit_page() ) { |
| 301 |
return wpbc_get_preview_for_shortcode( 'bookingsearchresults', $attr ); // FixIn: 9.9.0.39. |
| 302 |
} |
| 303 |
|
| 304 |
$attr = wpbc_escape_shortcode_params( $attr ); //FixIn: 9.7.3.6.1 |
| 305 |
|
| 306 |
//if ( function_exists( 'wpbc_br_cache' ) ) $br_cache = wpbc_br_cache(); // Init booking resources cache |
| 307 |
|
| 308 |
$search_results_to_show = ''; |
| 309 |
if ( function_exists( 'wpbc_search_avy__show_search_results' ) ) { |
| 310 |
|
| 311 |
ob_start(); |
| 312 |
|
| 313 |
wpbc_search_avy__show_search_results( $attr ); // FixIn: 10.0.0.37. |
| 314 |
|
| 315 |
$search_results_to_show .= ob_get_clean(); |
| 316 |
} |
| 317 |
|
| 318 |
return $search_results_to_show; |
| 319 |
} |
| 320 |
|
| 321 |
// Select Booking form using the selectbox |
| 322 |
function bookingselect_shortcode($attr) { |
| 323 |
|
| 324 |
if ( ! class_exists( 'wpdev_bk_personal' ) ) { |
| 325 |
return '<strong>' . esc_html__('This shortcode available in Pro versions, only!' ,'booking') . '</strong> '; |
| 326 |
} |
| 327 |
|
| 328 |
if ( wpbc_is_on_edit_page() ) { |
| 329 |
return wpbc_get_preview_for_shortcode( 'bookingselect', $attr ); // FixIn: 9.9.0.39. |
| 330 |
} |
| 331 |
|
| 332 |
$attr = wpbc_escape_shortcode_params( $attr ); //FixIn: 9.7.3.6.1 |
| 333 |
|
| 334 |
//if ( function_exists( 'wpbc_br_cache' ) ) $br_cache = wpbc_br_cache(); // Init booking resources cache |
| 335 |
|
| 336 |
$search_form = apply_bk_filter('wpdev_get_booking_select_form','', $attr ); |
| 337 |
|
| 338 |
return $search_form ; |
| 339 |
} |
| 340 |
|
| 341 |
// Select Booking form using the selectbox |
| 342 |
function bookingresource_shortcode($attr) { |
| 343 |
|
| 344 |
if ( ! class_exists( 'wpdev_bk_personal' ) ) { |
| 345 |
return '<strong>' . esc_html__('This shortcode available in Pro versions, only!' ,'booking') . '</strong> '; |
| 346 |
} |
| 347 |
|
| 348 |
if ( wpbc_is_on_edit_page() ) { |
| 349 |
return wpbc_get_preview_for_shortcode( 'bookingresource', $attr ); // FixIn: 9.9.0.39. |
| 350 |
} |
| 351 |
|
| 352 |
$attr = wpbc_escape_shortcode_params( $attr ); //FixIn: 9.7.3.6.1 |
| 353 |
|
| 354 |
//if ( function_exists( 'wpbc_br_cache' ) ) $br_cache = wpbc_br_cache(); // Init booking resources cache |
| 355 |
|
| 356 |
$search_form = apply_bk_filter('wpbc_booking_resource_info','', $attr ); |
| 357 |
|
| 358 |
return $search_form ; |
| 359 |
} |
| 360 |
|
| 361 |
// </editor-fold> |
| 362 |
} |