PluginProbe
Booking Calendar / 11.1
Booking Calendar v11.1
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 10.11.3 All 202 releases
booking / core / admin / page-ics-import.php

page-ics-import.php in Booking Calendar 11.1, at core/admin/page-ics-import.php

792 lines 38.2 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 * @menu Booking > Settings > (Sync) Import page
5 * @category Settings API
6 * @author wpdevelop
7 *
8 * @web-site https://wpbookingcalendar.com/
9 * @email info@wpbookingcalendar.com
10 * @modified 2017-07-09
11 *
12 * This is COMMERCIAL SCRIPT
13 * We are not guarantee correct work and support of Booking Calendar, if some file(s) was modified by someone else then wpdevelop.
14 */
15
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit;
18 } // Exit if accessed directly
19
20 /**
21 * Show Content
22 * Update Content
23 * Define Slug
24 * Define where to show
25 */
26 class WPBC_Page_SettingsImportFeeds extends WPBC_Page_Structure {
27
28 // public $settings_api = false;
29
30 public function in_page() {
31 return 'wpbc-settings';
32 }
33
34
35 public function tabs() {
36
37 $tabs = array();
38
39 $tabs[ 'sync' ] = array(
40 'title' => __( 'Sync', 'booking') // Title of TAB
41 , 'page_title'=> __( 'Sync', 'booking') // Title of Page
42 , 'hint' => __('Import' ,'booking') . ' / ' . __('Export' ,'booking')
43 //, 'link' => '' // Can be skiped, then generated link based on Page and Tab tags. Or can be extenral link
44 //, 'position' => '' // 'left' || 'right' || ''
45 //, 'css_classes'=> '' // CSS class(es)
46 //, 'icon' => '' // Icon - link to the real PNG img
47 , 'font_icon' => 'wpbc_icn_sync_alt' // CSS definition of forn Icon
48 //, 'default' => false // Is this tab activated by default or not: true || false.
49 //, 'disabled' => false // Is this tab disbaled: true || false.
50 //, 'hided' => false // Is this tab hided: true || false.
51 , 'subtabs' => array()
52 );
53
54
55 $subtabs = array();
56
57 $subtabs[ 'import' ] = array(
58 'type' => 'subtab' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html'
59 , 'title' => __('Import' ,'booking') . ' - .ics' // Title of TAB
60 , 'page_title' => __('Import Bookings via .ics' ,'booking')
61 //. ' <span style="padding: 10px;font-size: 12px;font-style: italic;vertical-align: top;">Beta</span>' // Title of Page
62 , 'hint' => __('Set up and configure the import of events using .ics feeds.' ,'booking') // Hint
63 , 'link' => '' // link
64 , 'position' => '' // 'left' || 'right' || ''
65 , 'css_classes' => '' // CSS class(es)
66 //, 'icon' => 'http://.../icon.png' // Icon - link to the real PNG img
67 , 'font_icon' => 'wpbc-bi-box-arrow-in-down-right'
68 , 'default' => false // Is this sub tab activated by default or not: true || false. // FixIn: 8.1.1.10.
69 , 'disabled' => false // Is this sub tab deactivated: true || false.
70 , 'checkbox' => false // or definition array for specific checkbox: array( 'checked' => true, 'name' => 'feature1_active_status' ) //, 'checkbox' => array( 'checked' => $is_checked, 'name' => 'enabled_active_status' )
71 , 'content' => 'content' // Function to load as conten of this TAB
72
73 );
74
75 $tabs[ 'sync' ]['subtabs'] = $subtabs;
76
77
78 return $tabs;
79 }
80
81
82 /** Show Content of Settings page */
83 public function content() {
84
85 $this->css();
86
87 ////////////////////////////////////////////////////////////////////////
88 // Checking
89 ////////////////////////////////////////////////////////////////////////
90
91 do_action( 'wpbc_hook_settings_page_header', 'ics_import_settings'); // Define Notices Section and show some static messages, if needed
92
93 if ( ! wpbc_is_mu_user_can_be_here('activated_user') ) return false; // Check if MU user activated, otherwise show Warning message.
94
95 // if ( ! wpbc_is_mu_user_can_be_here('only_super_admin') ) return false; // User is not Super admin, so exit. Basically its was already checked at the bottom of the PHP file, just in case.
96
97
98 ////////////////////////////////////////////////////////////////////////
99 // Load Data
100 ////////////////////////////////////////////////////////////////////////
101 //$booking_gcal_events_form_fields = get_bk_option( 'booking_gcal_events_form_fields');
102 //$booking_gcal_events_form_fields = maybe_unserialize( $booking_gcal_events_form_fields );
103
104
105 ////////////////////////////////////////////////////////////////////////
106 // S u b m i t Main Form
107 ////////////////////////////////////////////////////////////////////////
108
109 $submit_form_name = 'wpbc_ics_import'; // Define form name
110
111 //$this->get_api()->validated_form_id = $submit_form_name; // Define ID of Form for ability to validate fields (like required field) before submit.
112
113 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
114 if ( isset( $_POST['is_form_sbmitted_'. $submit_form_name ] ) ) {
115
116 // Nonce checking {Return false if invalid, 1 if generated between, 0-12 hours ago, 2 if generated between 12-24 hours ago. }
117 $nonce_gen_time = check_admin_referer( 'wpbc_settings_page_' . $submit_form_name ); // Its stop show anything on submiting, if its not refear to the original page
118
119 // Save Changes
120 $this->update();
121 }
122
123
124 ////////////////////////////////////////////////////////////////////////
125 // JavaScript: Tooltips, Popover, Datepick (js & css)
126 ////////////////////////////////////////////////////////////////////////
127
128 echo '<span class="wpdevelop">';
129
130 wpbc_js_for_bookings_page();
131
132 echo '</span>';
133
134 ?><div class="clear" style="margin-bottom:0px;"></div><?php
135
136 $wpbm_version = wpbc_get_wpbm_version();
137 $wpbm_minimum_version = '2.1';
138
139 // If lower than 2, than show warning
140 if ( version_compare( $wpbm_version, $wpbm_minimum_version, '<') ) {
141 $is_bm_exist = false;
142 } else {
143 $is_bm_exist = true;
144 }
145
146
147 ////////////////////////////////////////////////////////////////////////
148 // Content ////////////////////////////////////////////////////////////
149 ?>
150 <div class="clear" style="margin-bottom:0px;"></div>
151 <span class="metabox-holder">
152 <form name="<?php echo esc_attr( $submit_form_name ); ?>" id="<?php echo esc_attr( $submit_form_name ); ?>" action="" method="post" autocomplete="off">
153 <?php
154 // N o n c e field, and key for checking S u b m i t
155 wp_nonce_field( 'wpbc_settings_page_' . $submit_form_name );
156 ?><input type="hidden" name="is_form_sbmitted_<?php echo esc_attr( $submit_form_name ); ?>" id="is_form_sbmitted_<?php echo esc_attr( $submit_form_name ); ?>" value="1" /><?php
157 ?><div class="clear"></div><?php
158
159 ?><div class="clear" style="height:10px;"></div><?php
160
161 if ( ! $is_bm_exist ) { // Not Exist
162 ?>
163 <div class="clear" style="height:15px;"></div>
164 <div class="wpbc-settings-notice notice-error" style="text-align:left;font-size: 16px;padding: 5px 20px;">
165 <strong><?php esc_html_e('Important!' ,'booking'); ?></strong> <?php
166
167 /* translators: 1: ... */
168 echo wp_kses_post( sprintf( __( 'This feature require %1$s plugin. You can install %2$s plugin from this %3$spage%4$s.', 'booking' )
169 , '<strong><a class="" href="' . esc_url( home_url() ) . '/wp-admin/plugin-install.php?s=booking+manager+by+oplugins&tab=search&type=term">' . 'Booking Manager' . '</a></strong> ' . ' <strong>' . esc_html( $wpbm_minimum_version ) . '</strong> (' . esc_html__( 'or newer', 'booking' ) . ') '
170 , '<strong>' . 'Booking Manager' . '</strong>'
171 , '<a target="_blank" href="https://wordpress.org/plugins/booking-manager/">'
172 , '</a>'
173 ) );
174 ?>
175 </div>
176 <div class="clear" style="height:25px;"></div><?php
177
178 wpbc_open_meta_box_section( 'wpbc_settings_ics_import_help_how', __('How it works', 'booking') );
179
180 wpbc_ics_import_export__show_help_info();
181
182 wpbc_close_meta_box_section();
183
184 } else { // Exist
185
186
187
188 wpbc_open_meta_box_section( 'wpbc_settings_ics_import_single', __('Import', 'booking') );
189
190 $this->show_toolbar_import_fields();
191
192 wpbc_close_meta_box_section();
193
194
195
196 wpbc_open_meta_box_section( 'wpbc_settings_ics_import_help_info', __('Help', 'booking') );
197
198 wpbc_ics_import_export__show_help_info();
199
200 wpbc_close_meta_box_section();
201 ?>
202
203 <div class="clear"></div>
204
205 <!--input type="submit" value="<?php esc_attr_e('Save Changes','booking'); ?>" class="button button-primary wpbc_submit_button" /-->
206 <?php
207 }
208 ?>
209 </form>
210 </span>
211 <?php
212
213 do_action( 'wpbc_hook_settings_page_footer', 'ics_import_settings' );
214
215 $this->enqueue_js();
216
217 wpbc_ics_import_ajax_js();
218 }
219
220
221 /** Save Chanages */
222 public function update() {
223 //debuge($_POST);
224 // Get Validated Email fields
225 // $validated_fields = $this->get_api()->validate_post();
226
227 // $validated_fields = apply_filters( 'wpbc_fields_before_saving_to_db__ics_import', $validated_fields ); //Hook for validated fields.
228
229 //debuge($validated_fields);
230
231 //$this->get_api()->save_to_db( $validated_fields );
232
233 // wpbc_show_changes_saved_message();
234 // Old way of saving:
235 // update_bk_option( 'booking_cache_expiration' , WPBC_Settings_API::validate_text_post_static( 'booking_cache_expiration' ) );
236 }
237
238 // <editor-fold defaultstate="collapsed" desc=" CSS & JS " >
239
240 /** CSS for this page */
241 private function css() {
242 ?>
243 <style type="text/css">
244 .wpbc_import_ics_bar .wpbc_import_btn,
245 .wpbc_import_ics_bar .wpbc_upload_btn{
246 float:left;
247 margin:9px 5px 10px 1px;
248
249 }
250 .wpbc_import_ics_bar .wpbc_import_div {
251 float:left;
252 width:70%;
253 }
254 .wpbc_import_ics_bar .wpbc_import_br_selection,
255 .wpbc_import_ics_bar .wpbc_import_url {
256 float:left;
257 width:28%;
258 /*height: 2em;*/
259 line-height: 1.4;
260 padding: 2px;
261 /*border-radius: 0;*/
262 margin:10px 5px 10px 1px;
263 }
264 .wpbc_import_ics_bar .wpbc_import_url {
265 width:70%;
266 padding: 2px 5px;
267 }
268 .wpbc_system_info_log {
269 font-size: 11px;
270 line-height: 1.5em;
271 border: 2px dashed #e85;
272 padding: 5px 20px;
273 display: none;
274 }
275 /**********************************************************************************************************/
276 .wpbc-help-message {
277 border:none;
278 }
279 /* toolbar fix */
280 .wpdevelop .visibility_container .control-group {
281 margin: 2px 8px 3px 0; /* margin: 0 8px 5px 0; */ /* FixIn: 9.5.4.8 */
282 }
283 /* Selectbox element in toolbar */
284 .visibility_container select optgroup{
285 color:#999;
286 vertical-align: middle;
287 font-style: italic;
288 font-weight: 400;
289 }
290 .visibility_container select option {
291 padding:5px;
292 font-weight: 600;
293 }
294 .visibility_container select optgroup option{
295 padding: 5px 20px;
296 color:#555;
297 font-weight: 600;
298 }
299 #wpbc_create_new_custom_form_name_fields {
300 width: 360px;
301 display:none;
302 }
303 @media (max-width: 782px) {
304 .wpbc_import_ics_bar .wpbc_import_br_selection,
305 .wpbc_import_ics_bar .wpbc_import_url {
306 line-height: 1.74;
307 }
308 .wpbc_import_ics_bar .wpbc_import_br_selection,
309 .wpbc_import_ics_bar .wpbc_import_div {
310 float:none;
311 width:100%;
312 }
313 }
314 @media (max-width: 399px) {
315 #wpbc_create_new_custom_form_name_fields {
316 width: 100%;
317 }
318 }
319 </style>
320 <?php
321 }
322
323
324
325 /**
326 * Add Custon JavaScript - for some specific settings options
327 * Executed After post content, after initial definition of settings, and possible definition after POST request.
328 *
329 * @param type $menu_slug
330 */
331 private function enqueue_js(){
332
333 // JavaScript //////////////////////////////////////////////////////////////
334
335 $js_script = '';
336
337
338 //Show|Hide grayed section
339 $js_script .= "
340 if ( ! jQuery('#ics_import_booking_gcal_auto_import_is_active').is(':checked') ) {
341 jQuery('.wpbc_tr_auto_import').addClass('hidden_items');
342 }
343 ";
344 // Hide|Show on Click Checkbox
345 $js_script .= " jQuery('#ics_import_booking_gcal_auto_import_is_active').on( 'change', function(){
346 if ( this.checked ) {
347 jQuery('.wpbc_tr_auto_import').removeClass('hidden_items');
348 } else {
349 jQuery('.wpbc_tr_auto_import').addClass('hidden_items');
350 }
351 } ); ";
352 // F R O M
353 $js_script .= "
354 if ( jQuery('#ics_import_booking_gcal_events_from').val() != 'date' ) {
355 jQuery('.wpbc_tr_from_offset .wpbc_offset_value').removeClass('hidden_items');
356 jQuery('.wpbc_tr_from_offset .wpbc_offset_datetime').addClass('hidden_items');
357 } else {
358 jQuery('.wpbc_tr_from_offset .wpbc_offset_value').addClass('hidden_items');
359 jQuery('.wpbc_tr_from_offset .wpbc_offset_datetime').removeClass('hidden_items');
360 }
361 ";
362 // On select option in selectbox
363 $js_script .= " jQuery('#ics_import_booking_gcal_events_from').on( 'change', function(){
364 jQuery('#ics_import_booking_gcal_events_from_offset').val('');
365 if ( jQuery(this).val() != 'date' ){
366 jQuery('.wpbc_tr_from_offset .wpbc_offset_value').removeClass('hidden_items');
367 jQuery('.wpbc_tr_from_offset .wpbc_offset_datetime').addClass('hidden_items');
368 } else {
369 jQuery('.wpbc_tr_from_offset .wpbc_offset_value').addClass('hidden_items');
370 jQuery('.wpbc_tr_from_offset .wpbc_offset_datetime').removeClass('hidden_items');
371 }
372 } ); ";
373 // U n t i l
374 $js_script .= "
375 if ( jQuery('#ics_import_booking_gcal_events_until').val() != 'date' ) {
376 jQuery('.wpbc_tr_until_offset .wpbc_offset_value').removeClass('hidden_items');
377 jQuery('.wpbc_tr_until_offset .wpbc_offset_datetime').addClass('hidden_items');
378 } else {
379 jQuery('.wpbc_tr_until_offset .wpbc_offset_value').addClass('hidden_items');
380 jQuery('.wpbc_tr_until_offset .wpbc_offset_datetime').removeClass('hidden_items');
381 }
382 ";
383 // On select option in selectbox
384 $js_script .= " jQuery('#ics_import_booking_gcal_events_until').on( 'change', function(){
385 jQuery('#ics_import_booking_gcal_events_until_offset').val('');
386 if ( jQuery(this).val() != 'date' ){
387 jQuery('.wpbc_tr_until_offset .wpbc_offset_value').removeClass('hidden_items');
388 jQuery('.wpbc_tr_until_offset .wpbc_offset_datetime').addClass('hidden_items');
389 } else {
390 jQuery('.wpbc_tr_until_offset .wpbc_offset_value').addClass('hidden_items');
391 jQuery('.wpbc_tr_until_offset .wpbc_offset_datetime').removeClass('hidden_items');
392 }
393 } ); ";
394
395
396 // // Hide|Show on Click Radion
397 // $js_script .= " jQuery('input[name=\"paypal_pro_hosted_solution\"]').on( 'change', function(){
398 // jQuery('.wpbc_sub_settings_paypal_account_type').addClass('hidden_items');
399 // if ( jQuery('#paypal_type_standard').is(':checked') ) {
400 // jQuery('.wpbc_sub_settings_paypal_standard').removeClass('hidden_items');
401 // } else {
402 // jQuery('.wpbc_sub_settings_paypal_pro_hosted').removeClass('hidden_items');
403 // }
404 // } ); ";
405
406 ////////////////////////////////////////////////////////////////////////
407
408
409 // Eneque JS to the footer of the page
410 wpbc_enqueue_js( $js_script );
411 }
412
413 // </editor-fold>
414
415
416
417 /** Show Toolbar with import fields */
418 function show_toolbar_import_fields() {
419
420 // Parameters for Ajax:
421
422 ?><div class="wpbc_import_ics_bar" id="wpbc_import_ics_bar"
423 data-nonce="<?php echo esc_attr( wp_create_nonce( $nonce_name = 'wpbc_import_ics_nonce_actn' ) ); ?>"
424 data-user-id="<?php echo esc_attr( wpbc_get_current_user_id() ); ?>"
425 ><?php
426
427 if ( function_exists( 'wpbc_get_br_as_objects' ) ) {
428
429 $bk_resources = wpbc_get_br_as_objects();
430
431 ?><select id="wpbc_import_br_selection" name="wpbc_import_br_selection" class="wpbc_import_br_selection"><?php
432
433 foreach ( $bk_resources as $res ) {
434
435 $res_title = $res->title;
436
437 if ( ( isset( $res->parent ) ) && ( $res->parent == 0 ) && ( isset( $res->count ) ) && ( $res->count > 1 ) ) {
438
439 $option_class = 'wpbc_parent_resource';
440 $res_title = $res_title. ' [' . __('parent resource', 'booking') . ']';
441
442 } elseif ( ( isset( $res->parent ) ) && ( $res->parent != 0 ) ) {
443
444 $option_class = 'wpbc_child_resource';
445 $res_title = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $res_title;
446
447 } else {
448 $option_class = 'wpbc_single_resource';
449 }
450
451 ?><option value="<?php echo esc_attr( $res->id ); ?>" class="<?php echo esc_attr( $option_class ); ?>" ><?php echo esc_html( $res_title ); ?></option><?php
452
453 }
454
455 ?></select><?php
456 }
457
458 ?>
459 <div class="wpbc_import_div">
460 <input type="text"
461 class="wpbc_import_url" name="wpbc_import_url" id="wpbc_import_url"
462 placeholder="<?php esc_attr_e( 'Enter URL to .ics feed', 'booking' ) ?>"
463 value="" wrap="off"
464 />
465 <?php if ( function_exists( 'wpbm_upload' ) ) { ?>
466 <a href="javascript:void(0)" class="button button-secondary wpbc_upload_btn"
467 data-modal_title="<?php echo esc_attr( __( 'Choose file', 'booking' ) ); ?>"
468 data-btn_title="<?php echo esc_attr( __( 'Insert file URL', 'booking' ) ); ?>"
469 ><?php esc_html_e('Upload / Select ', 'booking' ); ?> <strong>(.ics)</strong></a>
470 <?php } ?>
471 <a class="button button-primary wpbc_import_btn" href="javascript:void(0)"><?php esc_html_e('Import', 'booking'); ?></a>
472 </div>
473 <?php
474 if ( function_exists( 'wpbm_upload' ) ) { // Get WPBM_Upload obj. instance
475
476 $wpbm_upload = wpbm_upload();
477
478 $wpbm_upload->set_upload_button( '.wpbc_upload_btn' );
479
480 $wpbm_upload->set_element_insert_url( '.wpbc_import_url' );
481 }
482 ?>
483 <div class="clear"></div>
484 <div class="wpbc_system_info_log"></div>
485 <div class="clear"></div>
486 </div>
487
488 <?php
489 }
490
491 }
492 add_action('wpbc_menu_created', array( new WPBC_Page_SettingsImportFeeds() , '__construct') ); // Executed after creation of Menu
493
494
495
496 /**
497 * Show Help info about .ics import/export at Booking > Settings > Sync pages
498 *
499 * @param bool $is_import
500 */
501 function wpbc_ics_import_export__show_help_info( $is_import = true ) {
502 ?>
503 <div class="wpbc-help-message ">
504 <h4 style="margin-top:0;font-size:1.1em;">
505 <?php
506 $message_ics = sprintf( __( 'What does .ics feeds import/export mean?', 'booking' ) );
507 $message_ics = str_replace( array( '.ics', 'iCalendar' ), array( '<strong>.ics</strong>', '<strong>iCalendar</strong>' ), $message_ics );
508 echo wp_kses_post( $message_ics );
509 ?>
510 </h4>
511 <p class="code" >
512 <?php
513 $message_ics = sprintf(
514 /* translators: 1: ... */
515 __( 'Its useful, if you need to import/export bookings from/to external websites, like %s', 'booking' ),
516 ' <br/><em><strong><a href="https://www.airbnb.com/help/article/99/how-do-i-sync-my-airbnb-calendar-with-another-calendar" target="_blank">Airbnb</a></strong>, '
517 . '<strong><a href="https://partner.booking.com/en-gb/help/rates-availability/extranet-calendar/syncing-your-bookingcom-calendar-third-party-calendars" target="_blank">Booking.com</a></strong>, '
518 . '<strong><a href="https://rentalsupport.tripadvisor.com/articles/FAQ/noc-How-does-calendar-sync-work" target="_blank">TripAdvisor</a></strong>, '
519 . '<strong><a href="https://help.vrbo.com/articles/How-do-I-import-my-iCal-or-Google-calendar" target="_blank">VRBO</a></strong>, '
520 . '<strong><a href="https://helpcenter.flipkey.com/articles/FAQ/noc-How-does-calendar-sync-work" target="_blank">FlipKey</a></strong> '
521 . '<strong><a href="https://help.homeaway.com/articles/How-do-I-export-my-calendar-data-to-a-Google-calendar" target="_blank">HomeAway</a></strong>, '
522 . str_replace( array( '.ics', 'iCalendar' ), array( '<strong>.ics</strong>', '<strong>iCalendar</strong>' ),
523 __( 'and any other calendar that uses .ics format', 'booking' )
524 )
525 . '</em>.<br/>'
526 );
527 $message_ics = str_replace( array( '.ics', 'iCalendar' ), array( '<strong>.ics</strong>', '<strong>iCalendar</strong>' ), $message_ics );
528 echo wp_kses_post( $message_ics );
529 ?>
530 </p>
531 <div class="clear" style="margin:20px 0;"></div>
532 <div class="wpbc-settings-notice notice-info"
533 style="text-align:left;border-top:1px solid #f0f0f0;border-right:1px solid #f0f0f0; line-height: 2em;padding: 5px 20px;"
534 >
535 <?php
536 $message_ics = sprintf(
537 /* translators: 1: ... */
538 __( '.ics - is a file format of iCalendar standard for exchanging calendar and scheduling information between different sources %s Using a common calendar format (.ics), you can keep all your calendars updated and synchronized.', 'booking' )
539 , '<br/>' /*
540 '<br/><em>(<strong><a href="https://www.airbnb.com/help/article/99/how-do-i-sync-my-airbnb-calendar-with-another-calendar" target="_blank">Airbnb</a></strong>, '
541 . '<strong><a href="https://partnersupport.booking.com/hc/en-us/articles/213424709-How-do-I-export-my-calendar-" target="_blank">Booking.com</a></strong>, '
542 . '<strong><a href="https://help.homeaway.com/articles/How-do-I-export-my-calendar-data-to-a-Google-calendar" target="_blank">HomeAway</a></strong>, '
543 . '<strong><a href="https://rentalsupport.tripadvisor.com/articles/FAQ/noc-How-does-calendar-sync-work" target="_blank">TripAdvisor</a></strong>, '
544 . '<strong><a href="https://help.vrbo.com/articles/How-do-I-export-my-calendar-data-to-a-Google-calendar" target="_blank">VRBO</a></strong>, '
545 . '<strong><a href="https://helpcenter.flipkey.com/articles/FAQ/noc-How-does-calendar-sync-work" target="_blank">FlipKey</a></strong> '
546 . str_replace( array( '.ics', 'iCalendar' ), array( '<strong>.ics</strong>', '<strong>iCalendar</strong>' ),
547 __( 'and any other calendar that uses .ics format', 'booking' )
548 )
549 . ')</em>.<br/>' */
550 );
551 $message_ics = str_replace( array( '.ics', 'iCalendar' ), array( '<strong>.ics</strong>', '<strong>iCalendar</strong>' ), $message_ics );
552 echo wp_kses_post( $message_ics );
553 ?>
554 </div>
555 <?php if ( $is_import ) { ?>
556 <h4 style="font-size:1.1em;">
557 <?php
558 // FixIn: 8.4.2.12
559 $message_ics = sprintf( __( 'Is it automatic process?', 'booking' ) );
560 $message_ics = str_replace( array( '.ics', 'iCalendar' ), array( '<strong>.ics</strong>', '<strong>iCalendar</strong>' ), $message_ics );
561 echo wp_kses_post( $message_ics );
562 ?>
563 </h4>
564 <div class="wpbc-settings-notice notice-warning"
565 style="text-align:left;border-top:1px solid #f0f0f0;border-right:1px solid #f0f0f0; line-height: 2em;padding: 5px 20px;"
566 >
567 <?php
568 $message_ics = sprintf(
569 __( 'By default .ics import is not automatic process. You need to set up CRON script on your server to periodically access front-end page(s) with import .ics feeds shortcodes.', 'booking' )
570 , '<br/>' /*
571 '<br/><em>(<strong><a href="https://www.airbnb.com/help/article/99/how-do-i-sync-my-airbnb-calendar-with-another-calendar" target="_blank">Airbnb</a></strong>, '
572 . '<strong><a href="https://partnersupport.booking.com/hc/en-us/articles/213424709-How-do-I-export-my-calendar-" target="_blank">Booking.com</a></strong>, '
573 . '<strong><a href="https://help.homeaway.com/articles/How-do-I-export-my-calendar-data-to-a-Google-calendar" target="_blank">HomeAway</a></strong>, '
574 . '<strong><a href="https://rentalsupport.tripadvisor.com/articles/FAQ/noc-How-does-calendar-sync-work" target="_blank">TripAdvisor</a></strong>, '
575 . '<strong><a href="https://help.vrbo.com/articles/How-do-I-export-my-calendar-data-to-a-Google-calendar" target="_blank">VRBO</a></strong>, '
576 . '<strong><a href="https://helpcenter.flipkey.com/articles/FAQ/noc-How-does-calendar-sync-work" target="_blank">FlipKey</a></strong> '
577 . str_replace( array( '.ics', 'iCalendar' ), array( '<strong>.ics</strong>', '<strong>iCalendar</strong>' ),
578 __( 'and any other calendar that uses .ics format', 'booking' )
579 )
580 . ')</em>.<br/>' */
581 );
582 $message_ics = str_replace( array( '.ics', 'iCalendar' , 'CRON'), array( '<strong>.ics</strong>', '<strong>iCalendar</strong>' , '<a target="_blank" href="https://wpbookingcalendar.com/faq/cron-script/"><strong>CRON</strong></a>' ), $message_ics );
583 echo wp_kses_post( $message_ics );
584 ?>
585 </div>
586 <h4 style="font-size:1.1em;">
587 <?php
588 $message_ics = sprintf( __( 'How to start import of .ics feeds (files)?', 'booking' ) );
589 $message_ics = str_replace( array( '.ics', 'iCalendar' ), array( '<strong>.ics</strong>', '<strong>iCalendar</strong>' ), $message_ics );
590 echo wp_kses_post( $message_ics );
591 ?>
592 </h4>
593 <ol style="list-style-type: decimal !important;list-style-position: inside;margin-left: 15px;">
594 <li><?php
595 /* translators: 1: ... */
596 echo wp_kses_post( sprintf( __( 'Install %s plugin.', 'booking' ),
597 '<a target="_blank" href="https://wordpress.org/plugins/booking-manager/"><strong>Booking Manager</strong></a>' )
598 );
599 ?></li>
600 <li><?php
601 /* translators: 1: ... */
602 echo wp_kses_post( sprintf( __( 'Insert %1$s shortcode into some post(s) or page(s). Check more info about this %2$sshortcode configuration%3$s', 'booking' )
603 , '<code>[booking-manager-import ...]</code>'
604 , '<a target="_blank" href="https://oplugins.com/plugins/wp-booking-manager/booking-manager-help/#events-import">'
605 , '</a>'
606 ) );
607 ?>.
608 <div class="wpbc-settings-notice notice-info"
609 style='margin-left:25px;text-align:left;border-top:1px solid #f0f0f0;border-right:1px solid #f0f0f0;'><?php
610
611 /* translators: 1: ... */
612 $message_ics = sprintf( __( 'Using such shortcodes in pages give a great flexibility to import from different .ics feeds (sources) into the same resource.%sAlso its possible to define different CRON parameters for accessing such different pages with different time intervals.', 'booking' )
613 , '<br/>'
614 );
615 $message_ics = str_replace( array( '.ics', 'CRON' ), array( '<strong>.ics</strong>', '<a target="_blank" href="https://wpbookingcalendar.com/faq/cron-script/"><strong>CRON</strong></a>' ), $message_ics );
616 echo wp_kses_post( $message_ics );
617 ?>
618 </div>
619 <span style="padding:0 15px;">
620 <?php
621 $message_ics = sprintf( __( 'Or you can import .ics feed or file directly at current page.', 'booking' ) );
622 $message_ics = str_replace( array( '.ics', 'iCalendar' ), array( '<strong>.ics</strong>', '<strong>iCalendar</strong>' ), $message_ics );
623 echo wp_kses_post( $message_ics );
624 ?>
625 </span>
626 </li>
627 <li> <?php
628 /* translators: 1: ... */
629 $message_ics = sprintf( __( 'If you have inserted import shortcodes from %s, then you can configure your CRON for periodically access these pages and import .ics feeds.', 'booking' )
630 , '<a target="_blank" href="https://wordpress.org/plugins/booking-manager/"><strong>Booking Manager</strong></a> <code>[booking-manager-import ...]</code>'
631 );
632 $message_ics = str_replace( array( '.ics', 'CRON' ), array( '<strong>.ics</strong>', '<a target="_blank" href="https://wpbookingcalendar.com/faq/cron-script/"><strong>CRON</strong></a>' ), $message_ics );
633 echo wp_kses_post( $message_ics );
634 ?>
635 </li>
636 </ol>
637 <?php } else { ?>
638 <h4 style="font-size:1.1em;">
639 <?php
640 $message_ics = sprintf( __( 'How to start export of .ics feeds (files)?', 'booking' ) );
641 $message_ics = str_replace( array( '.ics', 'iCalendar' ), array( '<strong>.ics</strong>', '<strong>iCalendar</strong>' ), $message_ics );
642 echo wp_kses_post( $message_ics );
643 ?>
644 </h4>
645 <ol style="list-style-type: decimal !important;list-style-position: inside;margin-left: 15px;">
646 <li><?php
647 /* translators: 1: ... */
648 echo wp_kses_post( sprintf( __( 'Install %s plugin.', 'booking' ), '<a class="thickbox open-plugin-details-modal" target="_blank" href="plugin-install.php?tab=plugin-information&plugin=booking-manager&TB_iframe=true&width=772&height=435" aria-label="Booking Manager" data-title="Booking Manager"><strong>Booking Manager</strong></a>' ) );
649 echo ' ';
650 /* translators: 1: URL of Booking Manager plugin page.*/
651 echo wp_kses_post( sprintf( __( 'WordPress directory %s page.', 'booking' ), '<a target="_blank" href="https://wordpress.org/plugins/booking-manager/"><strong>Booking Manager</strong></a>' ) );
652 ?></li>
653 <li> <?php esc_html_e( 'Configure ULR feed(s) at this settings page.', 'booking' ); ?>
654 <div class="wpbc-settings-notice notice-info"
655 style='margin-left:25px;text-align:left;border-top:1px solid #f0f0f0;border-right:1px solid #f0f0f0;'>
656 <?php
657 $message_ics = sprintf(
658 /* translators: 1: ... */
659 __( 'Using such URL(s) you can import .ics feeds, from interface of other websites. %sCheck more info about how to import .ics feeds into other websites at the support pages of sepcific website.', 'booking' )
660 , '<br/>');
661 $message_ics = str_replace( array( '.ics', 'iCalendar' ), array( '<strong>.ics</strong>', '<strong>iCalendar</strong>' ), $message_ics );
662 echo wp_kses_post( $message_ics );
663 ?>
664 </div>
665 </li>
666 <li>
667 <?php
668 $message_ics = sprintf( __( 'Visit these (previously configured URL feeds) pages for downloading .ics files.', 'booking' ) );
669 $message_ics = str_replace( array( '.ics', 'iCalendar' ), array( '<strong>.ics</strong>', '<strong>iCalendar</strong>' ), $message_ics );
670 echo wp_kses_post( $message_ics );
671 ?>
672 </li>
673 </ol>
674 <?php } ?>
675 </div>
676 <?php
677 }
678
679
680
681 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
682 // AJAX Request
683 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
684
685 /** JavaScript for Ajax */
686 function wpbc_ics_import_ajax_js() {
687
688 $ajx_el_id = 'wpbc_import_ics_bar';
689
690 // "wpbc-ajax.php" having this: , 'WPBC_IMPORT_ICS_URL' => 'admin'
691
692 ?>
693 <script type="text/javascript">
694 // Ajax Request
695 jQuery( function ( $ ) { // Shortcut to jQuery(document).ready(function(){ ... });
696
697 jQuery( '.wpbc_import_ics_bar' ).on( 'click', '.wpbc_import_btn', function ( event ) { // This delegated event, can be run, when DOM element added after page loaded
698
699 wpbc_admin_show_message_processing( '' );
700
701 var jq_el = jQuery( this ).closest( '.wpbc_import_ics_bar' );
702
703 var params_obj = {};
704 params_obj.id = jq_el.attr( 'id' );
705 params_obj.nonce = jq_el.attr( 'data-nonce' );
706 params_obj.user_id = jq_el.attr( 'data-user-id' );
707
708 params_obj.wpbc_import_url = jQuery( '#wpbc_import_url' ).val();
709 params_obj.wpbc_import_br_selection = 1;
710 if ( jQuery( '#wpbc_import_br_selection option' ).length > 0 )
711 params_obj.wpbc_import_br_selection = jQuery( '#wpbc_import_br_selection option' ).filter( ':selected' ).val();
712
713 // console.log(params_obj);
714
715 jQuery.post( wpbc_url_ajax, {
716 action: 'WPBC_IMPORT_ICS_URL',
717 user_id: params_obj.user_id ,
718 nonce: params_obj.nonce,
719 params: params_obj
720 },
721 function ( response_data, textStatus, jqXHR ) { // success
722
723 var my_message = '<?php echo esc_js( __('Done' ,'booking') ); ?>';
724 wpbc_admin_show_message( my_message, 'info', 10000 , false );
725
726 //console.log( response_data ); console.log( textStatus); console.log( jqXHR ); // Debug
727 //jQuery( '.wpbc_system_info_log' ).show(); //Show Debug info
728 jQuery( '.wpbc_system_info_log' ).html( response_data ); // For ability to show response, add such DIV element to page
729 }
730 ).fail( function ( jqXHR, textStatus, errorThrown ) {
731 wpbc_admin_show_message( '<strong style="text-transform: uppercase;">' + textStatus + '</strong> ~ ' + errorThrown , 'error', 5000 );
732 if ( window.console && window.console.log ){ console.log( 'Ajax_Error', jqXHR, textStatus, errorThrown ); }
733 })
734 // .done( function ( data, textStatus, jqXHR ) { if ( window.console && window.console.log ){ console.log( 'second success', data, textStatus, jqXHR ); } })
735 // .always( function ( data_jqXHR, textStatus, jqXHR_errorThrown ) { if ( window.console && window.console.log ){ console.log( 'always finished', data_jqXHR, textStatus, jqXHR_errorThrown ); } })
736 ;
737
738 });
739
740 });
741 </script>
742 <?php
743 }
744
745
746 /** Ajax Response $ */
747 function wpbc_ajax_WPBC_IMPORT_ICS_URL() {
748
749 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
750 if ( ! isset( $_POST['params'] ) || empty( $_POST['params'] ) ) {
751 exit;
752 }
753
754 // Check Security
755 $action_nonce_name = 'wpbc_import_ics_nonce_actn';
756 $nonce_post_key = 'nonce';
757 // This action executed from Admin panel at WP Booking Calendar > Settings > Sync > "Import - .ics" page -> Section "Import", so no need to check this if ( wpbc_is_use_nonce_at_front_end() ) { ... }
758 $result = check_ajax_referer( $action_nonce_name, $nonce_post_key ); // Check Security
759
760
761 $is_show_debug_info = ( ( get_bk_option( 'booking_is_show_system_debug_log' ) == 'On' ) ? true : false );
762 if ( $is_show_debug_info )
763 add_action( 'wpbc_show_debug', 'wpbc_start_showing_debug', 10, 1 );
764
765 //////////////////////////////////////////////////////////////////////
766 // Import events from .ics feed to specific booking resource
767 //////////////////////////////////////////////////////////////////////
768 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
769 do_action( 'wpbm_ics_import_start', array(
770 'url' => esc_url_raw( $_POST['params']['wpbc_import_url'] ), // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
771 'resource_id' => intval( $_POST['params']['wpbc_import_br_selection'] ), // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
772 'import_conditions' => '',
773 // Check dates availability and process only if dates available in specific booking resource!
774 ) );
775
776 if ( $is_show_debug_info )
777 remove_action( 'wpbc_show_debug', 'wpbc_start_showing_debug', 10 );
778
779 /*
780 if ( $is_show_debug_info ) {
781 // Showingdebug log section
782 ?><script type="text/javascript"> jQuery( '.wpbc_system_info_log' ).show(); </script><?php
783 }
784 */
785
786 // send JSON
787 //FixIn: 8.0.2.1 //Fix: We need to comment this line, because previously its possible that we already sent some messages, and its does not correct json format in this case.
788 //Fix: of showing "parsererror ~ SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data"
789 //wp_send_json( array( 'response' => 'success' ) ); // Return JS OBJ: response_data = { response: "success" }
790 wp_die( '', '', array( 'response' => null ) );
791 }
792