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 / admin / page-ics-import.php

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

782 lines 37.0 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' ) ) exit; // Exit if accessed directly
17
18 //FixIn: 8.0
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 );
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 if ( isset( $_POST['is_form_sbmitted_'. $submit_form_name ] ) ) {
114
115 // Nonce checking {Return false if invalid, 1 if generated between, 0-12 hours ago, 2 if generated between 12-24 hours ago. }
116 $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
117
118 // Save Changes
119 $this->update();
120 }
121
122
123 ////////////////////////////////////////////////////////////////////////
124 // JavaScript: Tooltips, Popover, Datepick (js & css)
125 ////////////////////////////////////////////////////////////////////////
126
127 echo '<span class="wpdevelop">';
128
129 wpbc_js_for_bookings_page();
130
131 echo '</span>';
132
133 ?><div class="clear" style="margin-bottom:0px;"></div><?php
134
135 $wpbm_version = wpbc_get_wpbm_version();
136 $wpbm_minimum_version = '2.1';
137
138 // If lower than 2, than show warning
139 if ( version_compare( $wpbm_version, $wpbm_minimum_version, '<') ) {
140 $is_bm_exist = false;
141 } else {
142 $is_bm_exist = true;
143 }
144
145
146 ////////////////////////////////////////////////////////////////////////
147 // Content ////////////////////////////////////////////////////////////
148 ?>
149 <div class="clear" style="margin-bottom:0px;"></div>
150 <span class="metabox-holder">
151 <form name="<?php echo $submit_form_name; ?>" id="<?php echo $submit_form_name; ?>" action="" method="post" autocomplete="off">
152 <?php
153 // N o n c e field, and key for checking S u b m i t
154 wp_nonce_field( 'wpbc_settings_page_' . $submit_form_name );
155 ?><input type="hidden" name="is_form_sbmitted_<?php echo $submit_form_name; ?>" id="is_form_sbmitted_<?php echo $submit_form_name; ?>" value="1" /><?php
156 ?><div class="clear"></div><?php
157
158 ?><div class="clear" style="height:10px;"></div><?php
159
160 if ( ! $is_bm_exist ) { // Not Exist
161 ?>
162 <div class="clear" style="height:15px;"></div>
163 <div class="wpbc-settings-notice notice-error" style="text-align:left;font-size: 16px;padding: 5px 20px;">
164 <strong><?php _e('Important!' ,'booking'); ?></strong> <?php
165
166 printf( __( 'This feature require %s plugin. You can install %s plugin from this %spage%s.', 'booking' )
167 , '<strong><a class="" href="'. home_url() .'/wp-admin/plugin-install.php?s=booking+manager+by+oplugins&tab=search&type=term">'
168 // , '<strong><a class="thickbox open-plugin-details-modal" href="'. home_url() .'/wp-admin/plugin-install.php?tab=plugin-information&plugin=booking-manager&TB_iframe=true&width=772&height=741" target="_blank">'
169 . 'Booking Manager' . '</a></strong> ' . ' <strong>' .$wpbm_minimum_version.'</strong> ('. __('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 _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 wp_create_nonce( $nonce_name = 'wpbc_import_ics_nonce_actn' ); ?>"
424 data-user-id="<?php echo 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 $res->id; ?>" class="<?php echo $option_class; ?>" ><?php echo $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 _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 _e('Upload / Select ', 'booking' ); ?> <strong>(.ics)</strong></a>
470 <?php } ?>
471 <a class="button button-primary wpbc_import_btn" href="javascript:void(0)"><?php _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 $message_ics;
509 ?>
510 </h4>
511 <p class="code" >
512 <?php
513 $message_ics = sprintf(
514 __( 'Its useful, if you need to import/export bookings from/to external websites, like %s', 'booking' ),
515 ' <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>, '
516 . '<strong><a href="https://partnersupport.booking.com/hc/en-us/articles/213424709-How-do-I-export-my-calendar-" target="_blank">Booking.com</a></strong>, '
517 . '<strong><a href="https://help.homeaway.com/articles/How-do-I-export-my-calendar-data-to-a-Google-calendar" target="_blank">HomeAway</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-export-my-calendar-data-to-a-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 . str_replace( array( '.ics', 'iCalendar' ), array( '<strong>.ics</strong>', '<strong>iCalendar</strong>' ),
522 __( 'and any other calendar that uses .ics format', 'booking' )
523 )
524 . '</em>.<br/>'
525 );
526 $message_ics = str_replace( array( '.ics', 'iCalendar' ), array( '<strong>.ics</strong>', '<strong>iCalendar</strong>' ), $message_ics );
527 echo $message_ics;
528 ?>
529 </p>
530 <div class="clear" style="margin:20px 0;"></div>
531 <div class="wpbc-settings-notice notice-info"
532 style="text-align:left;border-top:1px solid #f0f0f0;border-right:1px solid #f0f0f0; line-height: 2em;padding: 5px 20px;"
533 >
534 <?php
535 $message_ics = sprintf(
536 __( '.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' )
537 , '<br/>' /*
538 '<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>, '
539 . '<strong><a href="https://partnersupport.booking.com/hc/en-us/articles/213424709-How-do-I-export-my-calendar-" target="_blank">Booking.com</a></strong>, '
540 . '<strong><a href="https://help.homeaway.com/articles/How-do-I-export-my-calendar-data-to-a-Google-calendar" target="_blank">HomeAway</a></strong>, '
541 . '<strong><a href="https://rentalsupport.tripadvisor.com/articles/FAQ/noc-How-does-calendar-sync-work" target="_blank">TripAdvisor</a></strong>, '
542 . '<strong><a href="https://help.vrbo.com/articles/How-do-I-export-my-calendar-data-to-a-Google-calendar" target="_blank">VRBO</a></strong>, '
543 . '<strong><a href="https://helpcenter.flipkey.com/articles/FAQ/noc-How-does-calendar-sync-work" target="_blank">FlipKey</a></strong> '
544 . str_replace( array( '.ics', 'iCalendar' ), array( '<strong>.ics</strong>', '<strong>iCalendar</strong>' ),
545 __( 'and any other calendar that uses .ics format', 'booking' )
546 )
547 . ')</em>.<br/>' */
548 );
549 $message_ics = str_replace( array( '.ics', 'iCalendar' ), array( '<strong>.ics</strong>', '<strong>iCalendar</strong>' ), $message_ics );
550 echo $message_ics;
551 ?>
552 </div>
553 <?php if ( $is_import ) { ?>
554 <h4 style="font-size:1.1em;">
555 <?php
556 // FixIn: 8.4.2.12
557 $message_ics = sprintf( __( 'Is it automatic process?', 'booking' ) );
558 $message_ics = str_replace( array( '.ics', 'iCalendar' ), array( '<strong>.ics</strong>', '<strong>iCalendar</strong>' ), $message_ics );
559 echo $message_ics;
560 ?>
561 </h4>
562 <div class="wpbc-settings-notice notice-warning"
563 style="text-align:left;border-top:1px solid #f0f0f0;border-right:1px solid #f0f0f0; line-height: 2em;padding: 5px 20px;"
564 >
565 <?php
566 $message_ics = sprintf(
567 __( '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' )
568 , '<br/>' /*
569 '<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>, '
570 . '<strong><a href="https://partnersupport.booking.com/hc/en-us/articles/213424709-How-do-I-export-my-calendar-" target="_blank">Booking.com</a></strong>, '
571 . '<strong><a href="https://help.homeaway.com/articles/How-do-I-export-my-calendar-data-to-a-Google-calendar" target="_blank">HomeAway</a></strong>, '
572 . '<strong><a href="https://rentalsupport.tripadvisor.com/articles/FAQ/noc-How-does-calendar-sync-work" target="_blank">TripAdvisor</a></strong>, '
573 . '<strong><a href="https://help.vrbo.com/articles/How-do-I-export-my-calendar-data-to-a-Google-calendar" target="_blank">VRBO</a></strong>, '
574 . '<strong><a href="https://helpcenter.flipkey.com/articles/FAQ/noc-How-does-calendar-sync-work" target="_blank">FlipKey</a></strong> '
575 . str_replace( array( '.ics', 'iCalendar' ), array( '<strong>.ics</strong>', '<strong>iCalendar</strong>' ),
576 __( 'and any other calendar that uses .ics format', 'booking' )
577 )
578 . ')</em>.<br/>' */
579 );
580 $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 );
581 echo $message_ics;
582 ?>
583 </div>
584 <h4 style="font-size:1.1em;">
585 <?php
586 $message_ics = sprintf( __( 'How to start import of .ics feeds (files)?', 'booking' ) );
587 $message_ics = str_replace( array( '.ics', 'iCalendar' ), array( '<strong>.ics</strong>', '<strong>iCalendar</strong>' ), $message_ics );
588 echo $message_ics;
589 ?>
590 </h4>
591 <ol style="list-style-type: decimal !important;list-style-position: inside;margin-left: 15px;">
592 <li><?php
593 printf( __( 'Install %s plugin.', 'booking' )
594 , '<a target="_blank" href="https://wordpress.org/plugins/booking-manager/"><strong>Booking Manager</strong></a>' );
595 ?></li>
596 <li><?php
597 printf( __( 'Insert %s shortcode into some post(s) or page(s). Check more info about this %sshortcode configuration%s', 'booking' )
598 , '<code>[booking-manager-import ...]</code>'
599 , '<a target="_blank" href="https://oplugins.com/plugins/wp-booking-manager/booking-manager-help/#events-import">'
600 , '</a>'
601 );
602 ?>.
603 <div class="wpbc-settings-notice notice-info"
604 style='margin-left:25px;text-align:left;border-top:1px solid #f0f0f0;border-right:1px solid #f0f0f0;'><?php
605
606 $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' )
607 , '<br/>'
608 );
609 $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 );
610 echo $message_ics;
611 ?>
612 </div>
613 <span style="padding:0 15px;">
614 <?php
615 $message_ics = sprintf( __( 'Or you can import .ics feed or file directly at current page.', 'booking' ) );
616 $message_ics = str_replace( array( '.ics', 'iCalendar' ), array( '<strong>.ics</strong>', '<strong>iCalendar</strong>' ), $message_ics );
617 echo $message_ics;
618 ?>
619 </span>
620 </li>
621 <li> <?php
622 $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' )
623 , '<a target="_blank" href="https://wordpress.org/plugins/booking-manager/"><strong>Booking Manager</strong></a> <code>[booking-manager-import ...]</code>'
624 );
625 $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 );
626 echo $message_ics;
627 ?>
628 </li>
629 </ol>
630 <?php } else { ?>
631 <h4 style="font-size:1.1em;">
632 <?php
633 $message_ics = sprintf( __( 'How to start export of .ics feeds (files)?', 'booking' ) );
634 $message_ics = str_replace( array( '.ics', 'iCalendar' ), array( '<strong>.ics</strong>', '<strong>iCalendar</strong>' ), $message_ics );
635 echo $message_ics;
636 ?>
637 </h4>
638 <ol style="list-style-type: decimal !important;list-style-position: inside;margin-left: 15px;">
639 <li><?php
640 printf( __( 'Install %s plugin.', 'booking' )
641 , '<a target="_blank" href="https://wordpress.org/plugins/booking-manager/"><strong>Booking Manager</strong></a>' );
642 ?></li>
643 <li>
644 <?php _e( 'Configure ULR feed(s) at this settings page.', 'booking' ); ?>
645 <div class="wpbc-settings-notice notice-info"
646 style='margin-left:25px;text-align:left;border-top:1px solid #f0f0f0;border-right:1px solid #f0f0f0;'>
647 <?php
648 $message_ics = sprintf(
649 __( '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' )
650 , '<br/>');
651 $message_ics = str_replace( array( '.ics', 'iCalendar' ), array( '<strong>.ics</strong>', '<strong>iCalendar</strong>' ), $message_ics );
652 echo $message_ics;
653 ?>
654 </div>
655 </li>
656 <li>
657 <?php
658 $message_ics = sprintf( __( 'Visit these (previously configured URL feeds) pages for downloading .ics files.', 'booking' ) );
659 $message_ics = str_replace( array( '.ics', 'iCalendar' ), array( '<strong>.ics</strong>', '<strong>iCalendar</strong>' ), $message_ics );
660 echo $message_ics;
661 ?>
662 </li>
663 </ol>
664 <?php } ?>
665 </div>
666 <?php
667 }
668
669
670
671 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
672 // AJAX Request
673 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
674
675 /** JavaScript for Ajax */
676 function wpbc_ics_import_ajax_js() {
677
678 $ajx_el_id = 'wpbc_import_ics_bar';
679
680 // "wpbc-ajax.php" having this: , 'WPBC_IMPORT_ICS_URL' => 'admin'
681
682 ?>
683 <script type="text/javascript">
684 // Ajax Request
685 jQuery( function ( $ ) { // Shortcut to jQuery(document).ready(function(){ ... });
686
687 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
688
689 wpbc_admin_show_message_processing( '' );
690
691 var jq_el = jQuery( this ).closest( '.wpbc_import_ics_bar' );
692
693 var params_obj = {};
694 params_obj.id = jq_el.attr( 'id' );
695 params_obj.nonce = jq_el.attr( 'data-nonce' );
696 params_obj.user_id = jq_el.attr( 'data-user-id' );
697
698 params_obj.wpbc_import_url = jQuery( '#wpbc_import_url' ).val();
699 params_obj.wpbc_import_br_selection = 1;
700 if ( jQuery( '#wpbc_import_br_selection option' ).length > 0 )
701 params_obj.wpbc_import_br_selection = jQuery( '#wpbc_import_br_selection option' ).filter( ':selected' ).val();
702
703 // console.log(params_obj);
704
705 jQuery.post( wpbc_url_ajax, {
706 action: 'WPBC_IMPORT_ICS_URL',
707 user_id: params_obj.user_id ,
708 nonce: params_obj.nonce,
709 params: params_obj
710 },
711 function ( response_data, textStatus, jqXHR ) { // success
712
713 var my_message = '<?php echo html_entity_decode( esc_js( __('Done' ,'booking') ),ENT_QUOTES) ; ?>';
714 wpbc_admin_show_message( my_message, 'info', 10000 , false );
715
716 //console.log( response_data ); console.log( textStatus); console.log( jqXHR ); // Debug
717 //jQuery( '.wpbc_system_info_log' ).show(); //Show Debug info
718 jQuery( '.wpbc_system_info_log' ).html( response_data ); // For ability to show response, add such DIV element to page
719 }
720 ).fail( function ( jqXHR, textStatus, errorThrown ) {
721 wpbc_admin_show_message( '<strong style="text-transform: uppercase;">' + textStatus + '</strong> ~ ' + errorThrown , 'error', 5000 );
722 if ( window.console && window.console.log ){ console.log( 'Ajax_Error', jqXHR, textStatus, errorThrown ); }
723 })
724 // .done( function ( data, textStatus, jqXHR ) { if ( window.console && window.console.log ){ console.log( 'second success', data, textStatus, jqXHR ); } })
725 // .always( function ( data_jqXHR, textStatus, jqXHR_errorThrown ) { if ( window.console && window.console.log ){ console.log( 'always finished', data_jqXHR, textStatus, jqXHR_errorThrown ); } })
726 ;
727
728 });
729
730 });
731 </script>
732 <?php
733 }
734
735
736 /** Ajax Response */
737 function wpbc_ajax_WPBC_IMPORT_ICS_URL() {
738
739 if ( ! isset( $_POST['params'] ) || empty( $_POST['params'] ) ) {
740 exit;
741 }
742
743 // Check Security
744 $action_nonce_name = 'wpbc_import_ics_nonce_actn';
745 $nonce_post_key = 'nonce';
746 // 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() ) { ... }
747 $result = check_ajax_referer( $action_nonce_name, $nonce_post_key ); // Check Security
748
749
750 $is_show_debug_info = ( ( get_bk_option( 'booking_is_show_system_debug_log' ) == 'On' ) ? true : false );
751 if ( $is_show_debug_info )
752 add_action( 'wpbc_show_debug', 'wpbc_start_showing_debug', 10, 1 );
753
754 //////////////////////////////////////////////////////////////////////
755 // Import events from .ics feed to specific booking resource
756 //////////////////////////////////////////////////////////////////////
757 do_action( 'wpbm_ics_import_start'
758 , array(
759 'url' => esc_url_raw( $_POST['params']['wpbc_import_url'] )
760 , 'resource_id' => intval( $_POST['params']['wpbc_import_br_selection'] )
761 , 'import_conditions' => '' // Check dates availability and process only
762 // if dates available in specific booking resource!
763 )
764 );
765
766 if ( $is_show_debug_info )
767 remove_action( 'wpbc_show_debug', 'wpbc_start_showing_debug', 10 );
768
769 /*
770 if ( $is_show_debug_info ) {
771 // Showingdebug log section
772 ?><script type="text/javascript"> jQuery( '.wpbc_system_info_log' ).show(); </script><?php
773 }
774 */
775
776 // send JSON
777 //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.
778 //Fix: of showing "parsererror ~ SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data"
779 //wp_send_json( array( 'response' => 'success' ) ); // Return JS OBJ: response_data = { response: "success" }
780 wp_die( '', '', array( 'response' => null ) );
781 }
782