PluginProbe
Booking Calendar / 10.10
Booking Calendar v10.10
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 10.10, at core/admin/page-ics-import.php

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