PluginProbe
Booking Calendar / 11.8
Booking Calendar v11.8
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 10.11.4 All 201 releases
booking / core / admin / page-ics-export.php

page-ics-export.php in Booking Calendar 11.8, at core/admin/page-ics-export.php

510 lines 22.8 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) Export 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 // Exit if accessed directly.
17 if ( ! defined( 'ABSPATH' ) ) {exit;}
18
19
20
21 /**
22 * Show Content
23 * Update Content
24 * Define Slug
25 * Define where to show
26 */
27 class WPBC_Page_SettingsExportFeeds extends WPBC_Page_Structure {
28
29
30 public $settings_api = false;
31
32
33 public function in_page() {
34 return 'wpbc-settings';
35 }
36
37 public function tabs() {
38
39 $tabs = array();
40
41 $tabs[ 'sync' ] = array(
42 'title' => __( 'Sync', 'booking') // Title of TAB
43 , 'page_title'=> __( 'Sync', 'booking') // Title of Page
44 , 'hint' => __('Import' ,'booking') . ' / ' . __('Export' ,'booking')
45 //, 'link' => '' // Can be skiped, then generated link based on Page and Tab tags. Or can be extenral link
46 //, 'position' => '' // 'left' || 'right' || ''
47 //, 'css_classes'=> '' // CSS class(es)
48 //, 'icon' => '' // Icon - link to the real PNG img
49 , 'font_icon' => 'wpbc_icn_get_import_export' // CSS definition of forn Icon
50 //, 'default' => false // Is this tab activated by default or not: true || false.
51 //, 'disabled' => false // Is this tab disbaled: true || false.
52 //, 'hided' => false // Is this tab hided: true || false.
53 , 'subtabs' => array()
54 );
55
56
57 $subtabs = array();
58
59 $subtabs[ 'export' ] = array(
60 'type' => 'subtab' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html'
61 , 'title' => __('Export' ,'booking') . ' - .ics' // Title of TAB
62 , 'page_title' => __('Export Bookings via .ics' ,'booking')
63 //. ' <span style="padding: 10px;font-size: 12px;font-style: italic;vertical-align: top;">Beta</span>' // Title of Page
64 , 'hint' => __('Set up and configure the export of bookings into .ics feeds.' ,'booking') // Hint
65 , 'link' => '' // link
66 , 'position' => '' // 'left' || 'right' || ''
67 , 'css_classes' => '' // CSS class(es)
68 //, 'icon' => 'http://.../icon.png' // Icon - link to the real PNG img
69 , 'font_icon' => 'wpbc-bi-box-arrow-up-right' // CSS definition of Font Icon
70 , 'default' => false // Is this sub tab activated by default or not: true || false.
71 , 'disabled' => false // Is this sub tab deactivated: true || false.
72 , 'checkbox' => false // or definition array for specific checkbox: array( 'checked' => true, 'name' => 'feature1_active_status' ) //, 'checkbox' => array( 'checked' => $is_checked, 'name' => 'enabled_active_status' )
73 , 'content' => 'content' // Function to load as conten of this TAB
74
75 );
76
77 $tabs[ 'sync' ]['subtabs'] = $subtabs;
78
79
80 return $tabs;
81 }
82
83
84 /** Show Content of Settings page */
85 public function content() {
86
87 $this->css();
88
89 ////////////////////////////////////////////////////////////////////////
90 // Checking
91 ////////////////////////////////////////////////////////////////////////
92
93 do_action( 'wpbc_hook_settings_page_header', 'export_feeds_settings'); // Define Notices Section and show some static messages, if needed
94
95 if ( ! wpbc_is_mu_user_can_be_here('activated_user') ) return false; // Check if MU user activated, otherwise show Warning message.
96
97 // 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.
98
99 ////////////////////////////////////////////////////////////////////////
100 // Load Data
101 ////////////////////////////////////////////////////////////////////////
102
103
104 ////////////////////////////////////////////////////////////////////////
105 // S u b m i t Main Form
106 ////////////////////////////////////////////////////////////////////////
107
108 $submit_form_name = 'wpbc_export_feeds'; // Define form name
109
110 // $this->get_api()->validated_form_id = $submit_form_name; // Define ID of Form for ability to validate fields (like required field) before submit.
111
112 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
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
136 if ( ! function_exists( 'mb_detect_encoding' ) ) { //FixIn: 2.0.5.3 // FixIn: 8.1.3.25.
137 ?>
138 <span class="metabox-holder">
139 <div class="clear" style="height:15px;"></div>
140 <div class="wpbc-settings-notice notice-error" style="text-align:left;font-size: 16px;padding: 5px 20px;">
141 <strong><?php esc_html_e('Warning!' ,'booking'); ?></strong> <?php
142 /* translators: 1: PHP function description. */
143 printf( esc_attr__( 'This feature require %s', 'booking' ), 'PHP <strong>mbstring</strong> extension.' );
144 ?>
145 </div>
146 <div class="clear" style="height:25px;"></div><?php
147 }
148
149
150 $wpbm_version = wpbc_get_wpbm_version();
151
152 $wpbm_minimum_version = '2.1';
153
154 // If lower than 2, than show warning
155 if ( version_compare( $wpbm_version, $wpbm_minimum_version, '<') ) {
156 $is_bm_exist = false;
157 } else {
158 $is_bm_exist = true;
159 }
160
161 if ( ! $is_bm_exist ) { // Not Exist
162 ?>
163 <span class="metabox-holder">
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 href="'. esc_attr( home_url() .'/wp-admin/plugin-install.php?s=booking+manager+by+oplugins&tab=search&type=term' ). '">'
171 // , '<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">'
172 . 'Booking Manager' . '</a></strong> ' . ' <strong>' .esc_attr($wpbm_minimum_version).'</strong> ('. esc_attr__('or newer','booking') . ') '
173 , '<strong>' . 'Booking Manager' . '</strong>'
174 , '<a target="_blank" href="https://wordpress.org/plugins/booking-manager/">'
175 , '</a>'
176 ) );
177 ?>
178 </div>
179 <div class="clear" style="height:25px;"></div><?php
180
181 wpbc_open_meta_box_section( 'wpbc_settings_ics_import_help_how', __('How it works', 'booking') );
182
183 wpbc_ics_import_export__show_help_info( false );
184
185 wpbc_close_meta_box_section();
186 ?></span><?php
187
188 } else { // Exist
189
190 if ( class_exists('wpdev_bk_personal') )
191 wpbc_toolbar_search_by_id__top_form( array(
192 'search_form_id' => 'wpbc_booking_resources_search_form'
193 , 'search_get_key' => 'wh_resource_id'
194 , 'is_pseudo' => false
195 ) );
196
197 ////////////////////////////////////////////////////////////////////////
198 // Content
199 ////////////////////////////////////////////////////////////////////////
200 ?>
201 <div class="clear" style="margin-bottom:0px;"></div>
202 <span class="metabox-holder">
203 <form name="<?php echo esc_attr( $submit_form_name ); ?>" id="<?php echo esc_attr( $submit_form_name ); ?>" action="" method="post" autocomplete="off">
204 <?php
205 // N o n c e field, and key for checking S u b m i t
206 wp_nonce_field( 'wpbc_settings_page_' . $submit_form_name );
207 ?><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
208 ?>
209 <div class="clear" style="margin-top:10px;"></div>
210 <?php
211 // Add hidden input SEARCH KEY field into main form, if previosly was searching by ID or Title
212 if ( class_exists('wpdev_bk_personal') )
213 wpbc_hidden_search_by_id_field_in_main_form( array( 'search_get_key' => 'wh_resource_id' ) ); // FixIn: 8.0.1.12.
214 ?>
215 <div id="wpbc_resources_link" class="clear"></div>
216 <?php if ( class_exists('wpdev_bk_personal') ) { ?>
217 <div id="wpbc_resource_table_gcal_id" class="wpbc_settings_row wpbc_settings_row_rightNO"><?php
218
219 //wpbc_open_meta_box_section( 'wpbc_settings_export_feeds_resources', __('Resources', 'booking') );
220
221 wpbc_export_feeds__show_table();
222
223 //wpbc_close_meta_box_section();
224 ?>
225 </div>
226 <div class="clear"></div>
227 <?php } else {
228
229
230 // Booking Calendar Free version
231
232 wpbc_open_meta_box_section( 'wpbc_settings_export_feeds_resources', __('Export' ,'booking') . ' .ics/ical ' . __('feed', 'booking') );
233
234 wpbc_export_ics_feed__table();
235
236 wpbc_close_meta_box_section();
237
238
239 }
240 ?>
241 <input type="submit" value="<?php esc_attr_e( 'Save Changes', 'booking' ); ?>" class="button button-primary wpbc_submit_button" />
242 <div class="clear" style="height:25px;"></div>
243 <?php
244
245 wpbc_open_meta_box_section( 'wpbc_settings_ics_import_help_how', __( 'How it works', 'booking' ) );
246
247 wpbc_ics_import_export__show_help_info( false );
248
249 wpbc_close_meta_box_section();
250 ?><div class="clear"></div>
251
252
253 </form>
254 </span>
255 <?php
256
257 }
258 do_action( 'wpbc_hook_settings_page_footer', 'export_feeds_settings' );
259
260 $this->enqueue_js();
261 }
262
263
264 /** Save Chanages */
265 public function update() {
266
267 if ( function_exists( 'wpbc_export_feeds__update') )
268 wpbc_export_feeds__update();
269 else
270 wpbc_export_ics_feed__update(); // Free version
271
272 // Get Validated Email fields
273 //$validated_fields = $this->get_api()->validate_post();
274 //$validated_fields = apply_filters( 'wpbc_fields_before_saving_to_db__export_feeds', $validated_fields ); //Hook for validated fields.
275 //$this->get_api()->save_to_db( $validated_fields );
276
277 // Old way of saving:
278 // update_bk_option( 'booking_cache_expiration' , WPBC_Settings_API::validate_text_post_static( 'booking_cache_expiration' ) );
279
280 wpbc_show_changes_saved_message();
281 }
282
283 //TODO: claer unused CSS here
284
285 // <editor-fold defaultstate="collapsed" desc=" CSS & JS " >
286
287 /** CSS for this page */
288 private function css() {
289 ?>
290 <style type="text/css">
291 .wpbc-help-message {
292 border:none;
293 }
294 /* toolbar fix */
295 .wpdevelop .visibility_container .control-group {
296 margin: 2px 8px 3px 0; /* margin: 0 8px 5px 0; */ /* FixIn: 9.5.4.8 */
297 }
298 /* Selectbox element in toolbar */
299 .visibility_container select optgroup{
300 color:#999;
301 vertical-align: middle;
302 font-style: italic;
303 font-weight: 400;
304 }
305 .visibility_container select option {
306 padding:5px;
307 font-weight: 600;
308 }
309 .visibility_container select optgroup option{
310 padding: 5px 20px;
311 color:#555;
312 font-weight: 600;
313 }
314 #wpbc_create_new_custom_form_name_fields {
315 width: 360px;
316 display:none;
317 }
318 .wpbc_tr_booking_export_feed_free input[type="text"].regular-text {
319 margin-right:10px;
320 }
321 @media (max-width: 782px) {
322 #wpbc_create_new_custom_form_name_fields {
323 width: 100%;
324 }
325 .wpbc_tr_booking_export_feed_free code {
326 display: inline;
327 line-height: 2.7em;
328 vertical-align: top;
329 padding: 7px 10px;
330 margin: 0;
331 }
332 .wpbc_tr_booking_export_feed_free input[type="text"].regular-text {
333 width:65%;
334 display: inline;
335 }
336 }
337 </style>
338 <?php
339 }
340
341
342
343 /**
344 * Add Custon JavaScript - for some specific settings options
345 * Executed After post content, after initial definition of settings, and possible definition after POST request.
346 *
347 * @param type $menu_slug
348 */
349 private function enqueue_js(){
350
351 // JavaScript //////////////////////////////////////////////////////////////
352
353 $js_script = '';
354
355
356 //Show|Hide grayed section
357 $js_script .= "
358 if ( ! jQuery('#export_feeds_booking_gcal_auto_import_is_active').is(':checked') ) {
359 jQuery('.wpbc_tr_auto_import').addClass('hidden_items');
360 }
361 ";
362 // Hide|Show on Click Checkbox
363 $js_script .= " jQuery('#export_feeds_booking_gcal_auto_import_is_active').on( 'change', function(){
364 if ( this.checked ) {
365 jQuery('.wpbc_tr_auto_import').removeClass('hidden_items');
366 } else {
367 jQuery('.wpbc_tr_auto_import').addClass('hidden_items');
368 }
369 } ); ";
370 // F R O M
371 $js_script .= "
372 if ( jQuery('#export_feeds_booking_gcal_events_from').val() != 'date' ) {
373 jQuery('.wpbc_tr_from_offset .wpbc_offset_value').removeClass('hidden_items');
374 jQuery('.wpbc_tr_from_offset .wpbc_offset_datetime').addClass('hidden_items');
375 } else {
376 jQuery('.wpbc_tr_from_offset .wpbc_offset_value').addClass('hidden_items');
377 jQuery('.wpbc_tr_from_offset .wpbc_offset_datetime').removeClass('hidden_items');
378 }
379 ";
380 // On select option in selectbox
381 $js_script .= " jQuery('#export_feeds_booking_gcal_events_from').on( 'change', function(){
382 jQuery('#export_feeds_booking_gcal_events_from_offset').val('');
383 if ( jQuery(this).val() != 'date' ){
384 jQuery('.wpbc_tr_from_offset .wpbc_offset_value').removeClass('hidden_items');
385 jQuery('.wpbc_tr_from_offset .wpbc_offset_datetime').addClass('hidden_items');
386 } else {
387 jQuery('.wpbc_tr_from_offset .wpbc_offset_value').addClass('hidden_items');
388 jQuery('.wpbc_tr_from_offset .wpbc_offset_datetime').removeClass('hidden_items');
389 }
390 } ); ";
391 // U n t i l
392 $js_script .= "
393 if ( jQuery('#export_feeds_booking_gcal_events_until').val() != 'date' ) {
394 jQuery('.wpbc_tr_until_offset .wpbc_offset_value').removeClass('hidden_items');
395 jQuery('.wpbc_tr_until_offset .wpbc_offset_datetime').addClass('hidden_items');
396 } else {
397 jQuery('.wpbc_tr_until_offset .wpbc_offset_value').addClass('hidden_items');
398 jQuery('.wpbc_tr_until_offset .wpbc_offset_datetime').removeClass('hidden_items');
399 }
400 ";
401 // On select option in selectbox
402 $js_script .= " jQuery('#export_feeds_booking_gcal_events_until').on( 'change', function(){
403 jQuery('#export_feeds_booking_gcal_events_until_offset').val('');
404 if ( jQuery(this).val() != 'date' ){
405 jQuery('.wpbc_tr_until_offset .wpbc_offset_value').removeClass('hidden_items');
406 jQuery('.wpbc_tr_until_offset .wpbc_offset_datetime').addClass('hidden_items');
407 } else {
408 jQuery('.wpbc_tr_until_offset .wpbc_offset_value').addClass('hidden_items');
409 jQuery('.wpbc_tr_until_offset .wpbc_offset_datetime').removeClass('hidden_items');
410 }
411 } ); ";
412
413
414 // // Hide|Show on Click Radion
415 // $js_script .= " jQuery('input[name=\"paypal_pro_hosted_solution\"]').on( 'change', function(){
416 // jQuery('.wpbc_sub_settings_paypal_account_type').addClass('hidden_items');
417 // if ( jQuery('#paypal_type_standard').is(':checked') ) {
418 // jQuery('.wpbc_sub_settings_paypal_standard').removeClass('hidden_items');
419 // } else {
420 // jQuery('.wpbc_sub_settings_paypal_pro_hosted').removeClass('hidden_items');
421 // }
422 // } ); ";
423
424 ////////////////////////////////////////////////////////////////////////
425
426
427 // Eneque JS to the footer of the page
428 wpbc_enqueue_js( $js_script );
429 }
430
431 // </editor-fold>
432
433 }
434 add_action('wpbc_menu_created', array( new WPBC_Page_SettingsExportFeeds() , '__construct') ); // Executed after creation of Menu
435
436
437
438 /** Show .ics ULR section for Free version */
439 function wpbc_export_ics_feed__table() {
440
441 $resource_export = get_bk_option( 'booking_resource_export_ics_url' );
442 ?>
443 <table class="form-table">
444 <tbody><tr class="wpbc_tr_booking_export_feed_free" valign="top">
445 <th scope="row">
446 <label for="booking_export_feed1" class="wpbc-form-text"><?php esc_html_e( '.ics feed URL', 'booking' ); ?></label>
447 </th>
448 <td><fieldset class="wpdevelop">
449 <legend class="screen-reader-text"><span><?php esc_html_e( '.ics feed URL', 'booking' ); ?></span></legend>
450 <code style="font-size:12px;line-height: 2.4em;background: #ddd;color:#000;"><a
451 href="<?php echo esc_url( trim( home_url(), '/' ) . '/' . trim( $resource_export, '/' ) ); ?>"
452 target="_blank"><?php
453 $wpbc_h_u = home_url(); // FixIn: 8.1.3.6.
454 if (strlen( $wpbc_h_u ) > 23 ) {
455 echo esc_attr( substr( $wpbc_h_u, 0, 10 ) . '...' . substr( $wpbc_h_u, -10 ) );
456 } else {
457 echo esc_attr( $wpbc_h_u );
458 }?></a></code>
459 <input id="booking_export_feed1"
460 name="booking_export_feed1"
461 value="<?php echo esc_attr( $resource_export ); ?>"
462 placeholder=""
463 autocomplete="off"
464 type="text"
465 class="regular-text"
466 />
467 <a href="<?php echo esc_url( trim( home_url(), '/' ) . '/' . trim( $resource_export, '/') ); ?>"
468 title="<?php esc_attr_e( 'Open in new window', 'booking' ); ?>"
469 target="_blank"><i class="wpbc_icn_open_in_new"></i></a>
470 <p class="description"><?php esc_html_e( 'Please enter URL for generating .ics feed', 'booking' ); ?></p>
471 <div class="wpbc-settings-notice notice-info" style="text-align:left;border-top:1px solid #f0f0f0;border-right:1px solid #f0f0f0;">
472 <strong><?php esc_html_e( 'Note', 'booking' ); ?></strong>. <?php
473 esc_html_e( 'This .ics feed of bookings starting from today for 1 year', 'booking' );
474 ?>
475 </div>
476 </fieldset></td>
477 </tr></tbody>
478 </table>
479 <?php
480 }
481
482
483 /**
484 * Save changes to URL in Free version
485 *
486 * @return string - validated value
487 */
488 function wpbc_export_ics_feed__update() {
489
490 $validated_value = WPBC_Settings_API::validate_text_post_static( 'booking_export_feed1' );
491
492 $validated_value = explode( '/', $validated_value );
493 foreach ( $validated_value as $v_i => $v_val ) { // FixIn: 8.1.1.9.
494 if ( strpos( $v_val, '.') !== false ) {
495 $v_val = sanitize_file_name( $v_val );
496 }
497 $validated_value[ $v_i ] = $v_val;
498 }
499 // $validated_value = array_map( 'sanitize_file_name', $validated_value );
500 $validated_value = implode( '/', $validated_value );
501 $validated_value = strtolower( $validated_value );
502 $validated_value = wpbc_make_link_relative( $validated_value );
503
504 if ( empty( $validated_value ) )
505 $validated_value = '/ics/' . wpbc_get_slug_format( 'default' );
506
507 update_bk_option( 'booking_resource_export_ics_url', $validated_value );
508
509 return $validated_value;
510 }