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-export.php

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

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