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

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

508 lines 22.5 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 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_SettingsExportFeeds extends WPBC_Page_Structure {
27
28
29 public $settings_api = false;
30
31
32 public function in_page() {
33 return 'wpbc-settings';
34 }
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 );
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 if ( isset( $_POST['is_form_sbmitted_'. $submit_form_name ] ) ) {
113
114 // Nonce checking {Return false if invalid, 1 if generated between, 0-12 hours ago, 2 if generated between 12-24 hours ago. }
115 $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
116
117 // Save Changes
118 $this->update();
119 }
120
121
122 ////////////////////////////////////////////////////////////////////////
123 // JavaScript: Tooltips, Popover, Datepick (js & css)
124 ////////////////////////////////////////////////////////////////////////
125
126 echo '<span class="wpdevelop">';
127
128 wpbc_js_for_bookings_page();
129
130 echo '</span>';
131
132 ?><div class="clear" style="margin-bottom:0px;"></div><?php
133
134
135 if ( ! function_exists( 'mb_detect_encoding' ) ) { //FixIn: 2.0.5.3 //FixIn: 8.1.3.25
136 ?>
137 <span class="metabox-holder">
138 <div class="clear" style="height:15px;"></div>
139 <div class="wpbc-settings-notice notice-error" style="text-align:left;font-size: 16px;padding: 5px 20px;">
140 <strong><?php _e('Warning!' ,'booking'); ?></strong> <?php
141
142 printf( __( 'This feature require %s', 'booking' ), 'PHP <strong>mbstring</strong> extension.'
143 );
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 _e('Important!' ,'booking'); ?></strong> <?php
167
168 printf( __( 'This feature require %s plugin. You can install %s plugin from this %spage%s.', 'booking' )
169 , '<strong><a class="" href="'. home_url() .'/wp-admin/plugin-install.php?s=booking+manager+by+oplugins&tab=search&type=term">'
170 // , '<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">'
171 . 'Booking Manager' . '</a></strong> ' . ' <strong>' .$wpbm_minimum_version.'</strong> ('. __('or newer','booking') . ') '
172 , '<strong>' . 'Booking Manager' . '</strong>'
173 , '<a target="_blank" href="https://wordpress.org/plugins/booking-manager/">'
174 , '</a>'
175 );
176 ?>
177 </div>
178 <div class="clear" style="height:25px;"></div><?php
179
180 wpbc_open_meta_box_section( 'wpbc_settings_ics_import_help_how', __('How it works', 'booking') );
181
182 wpbc_ics_import_export__show_help_info( false );
183
184 wpbc_close_meta_box_section();
185 ?></span><?php
186
187 } else { // Exist
188
189 if ( class_exists('wpdev_bk_personal') )
190 wpbc_toolbar_search_by_id__top_form( array(
191 'search_form_id' => 'wpbc_booking_resources_search_form'
192 , 'search_get_key' => 'wh_resource_id'
193 , 'is_pseudo' => false
194 ) );
195
196 ////////////////////////////////////////////////////////////////////////
197 // Content
198 ////////////////////////////////////////////////////////////////////////
199 ?>
200 <div class="clear" style="margin-bottom:0px;"></div>
201 <span class="metabox-holder">
202 <form name="<?php echo $submit_form_name; ?>" id="<?php echo $submit_form_name; ?>" action="" method="post" autocomplete="off">
203 <?php
204 // N o n c e field, and key for checking S u b m i t
205 wp_nonce_field( 'wpbc_settings_page_' . $submit_form_name );
206 ?><input type="hidden" name="is_form_sbmitted_<?php echo $submit_form_name; ?>" id="is_form_sbmitted_<?php echo $submit_form_name; ?>" value="1" /><?php
207 ?>
208 <div class="clear" style="margin-top:10px;"></div>
209 <?php
210 // Add hidden input SEARCH KEY field into main form, if previosly was searching by ID or Title
211 if ( class_exists('wpdev_bk_personal') )
212 wpbc_hidden_search_by_id_field_in_main_form( array( 'search_get_key' => 'wh_resource_id' ) ); //FixIn: 8.0.1.12
213 ?>
214 <div id="wpbc_resources_link" class="clear"></div>
215 <?php if ( class_exists('wpdev_bk_personal') ) { ?>
216 <div id="wpbc_resource_table_gcal_id" class="wpbc_settings_row wpbc_settings_row_rightNO"><?php
217
218 //wpbc_open_meta_box_section( 'wpbc_settings_export_feeds_resources', __('Resources', 'booking') );
219
220 wpbc_export_feeds__show_table();
221
222 //wpbc_close_meta_box_section();
223 ?>
224 </div>
225 <div class="clear"></div>
226 <?php } else {
227
228
229 // Booking Calendar Free version
230
231 wpbc_open_meta_box_section( 'wpbc_settings_export_feeds_resources', __('Export' ,'booking') . ' .ics/ical ' . __('feed', 'booking') );
232
233 wpbc_export_ics_feed__table();
234
235 wpbc_close_meta_box_section();
236
237
238 } ?>
239 <input type="submit" value="<?php _e('Save Changes','booking'); ?>" class="button button-primary wpbc_submit_button" />
240
241 <div class="clear" style="height:25px;"></div><?php
242
243 wpbc_open_meta_box_section( 'wpbc_settings_ics_import_help_how', __('How it works', 'booking') );
244
245 wpbc_ics_import_export__show_help_info( false );
246
247 wpbc_close_meta_box_section();
248 ?><div class="clear"></div>
249
250
251 </form>
252 </span>
253 <?php
254
255 }
256 do_action( 'wpbc_hook_settings_page_footer', 'export_feeds_settings' );
257
258 $this->enqueue_js();
259 }
260
261
262 /** Save Chanages */
263 public function update() {
264
265 if ( function_exists( 'wpbc_export_feeds__update') )
266 wpbc_export_feeds__update();
267 else
268 wpbc_export_ics_feed__update(); // Free version
269
270 // Get Validated Email fields
271 //$validated_fields = $this->get_api()->validate_post();
272 //$validated_fields = apply_filters( 'wpbc_fields_before_saving_to_db__export_feeds', $validated_fields ); //Hook for validated fields.
273 //$this->get_api()->save_to_db( $validated_fields );
274
275 // Old way of saving:
276 // update_bk_option( 'booking_cache_expiration' , WPBC_Settings_API::validate_text_post_static( 'booking_cache_expiration' ) );
277
278 wpbc_show_changes_saved_message();
279 }
280
281 //TODO: claer unused CSS here
282
283 // <editor-fold defaultstate="collapsed" desc=" CSS & JS " >
284
285 /** CSS for this page */
286 private function css() {
287 ?>
288 <style type="text/css">
289 .wpbc-help-message {
290 border:none;
291 }
292 /* toolbar fix */
293 .wpdevelop .visibility_container .control-group {
294 margin: 2px 8px 3px 0; /* margin: 0 8px 5px 0; */ /* FixIn: 9.5.4.8 */
295 }
296 /* Selectbox element in toolbar */
297 .visibility_container select optgroup{
298 color:#999;
299 vertical-align: middle;
300 font-style: italic;
301 font-weight: 400;
302 }
303 .visibility_container select option {
304 padding:5px;
305 font-weight: 600;
306 }
307 .visibility_container select optgroup option{
308 padding: 5px 20px;
309 color:#555;
310 font-weight: 600;
311 }
312 #wpbc_create_new_custom_form_name_fields {
313 width: 360px;
314 display:none;
315 }
316 .wpbc_tr_booking_export_feed_free input[type="text"].regular-text {
317 margin-right:10px;
318 }
319 @media (max-width: 782px) {
320 #wpbc_create_new_custom_form_name_fields {
321 width: 100%;
322 }
323 .wpbc_tr_booking_export_feed_free code {
324 display: inline;
325 line-height: 2.7em;
326 vertical-align: top;
327 padding: 7px 10px;
328 margin: 0;
329 }
330 .wpbc_tr_booking_export_feed_free input[type="text"].regular-text {
331 width:65%;
332 display: inline;
333 }
334 }
335 </style>
336 <?php
337 }
338
339
340
341 /**
342 * Add Custon JavaScript - for some specific settings options
343 * Executed After post content, after initial definition of settings, and possible definition after POST request.
344 *
345 * @param type $menu_slug
346 */
347 private function enqueue_js(){
348
349 // JavaScript //////////////////////////////////////////////////////////////
350
351 $js_script = '';
352
353
354 //Show|Hide grayed section
355 $js_script .= "
356 if ( ! jQuery('#export_feeds_booking_gcal_auto_import_is_active').is(':checked') ) {
357 jQuery('.wpbc_tr_auto_import').addClass('hidden_items');
358 }
359 ";
360 // Hide|Show on Click Checkbox
361 $js_script .= " jQuery('#export_feeds_booking_gcal_auto_import_is_active').on( 'change', function(){
362 if ( this.checked ) {
363 jQuery('.wpbc_tr_auto_import').removeClass('hidden_items');
364 } else {
365 jQuery('.wpbc_tr_auto_import').addClass('hidden_items');
366 }
367 } ); ";
368 // F R O M
369 $js_script .= "
370 if ( jQuery('#export_feeds_booking_gcal_events_from').val() != 'date' ) {
371 jQuery('.wpbc_tr_from_offset .wpbc_offset_value').removeClass('hidden_items');
372 jQuery('.wpbc_tr_from_offset .wpbc_offset_datetime').addClass('hidden_items');
373 } else {
374 jQuery('.wpbc_tr_from_offset .wpbc_offset_value').addClass('hidden_items');
375 jQuery('.wpbc_tr_from_offset .wpbc_offset_datetime').removeClass('hidden_items');
376 }
377 ";
378 // On select option in selectbox
379 $js_script .= " jQuery('#export_feeds_booking_gcal_events_from').on( 'change', function(){
380 jQuery('#export_feeds_booking_gcal_events_from_offset').val('');
381 if ( jQuery(this).val() != 'date' ){
382 jQuery('.wpbc_tr_from_offset .wpbc_offset_value').removeClass('hidden_items');
383 jQuery('.wpbc_tr_from_offset .wpbc_offset_datetime').addClass('hidden_items');
384 } else {
385 jQuery('.wpbc_tr_from_offset .wpbc_offset_value').addClass('hidden_items');
386 jQuery('.wpbc_tr_from_offset .wpbc_offset_datetime').removeClass('hidden_items');
387 }
388 } ); ";
389 // U n t i l
390 $js_script .= "
391 if ( jQuery('#export_feeds_booking_gcal_events_until').val() != 'date' ) {
392 jQuery('.wpbc_tr_until_offset .wpbc_offset_value').removeClass('hidden_items');
393 jQuery('.wpbc_tr_until_offset .wpbc_offset_datetime').addClass('hidden_items');
394 } else {
395 jQuery('.wpbc_tr_until_offset .wpbc_offset_value').addClass('hidden_items');
396 jQuery('.wpbc_tr_until_offset .wpbc_offset_datetime').removeClass('hidden_items');
397 }
398 ";
399 // On select option in selectbox
400 $js_script .= " jQuery('#export_feeds_booking_gcal_events_until').on( 'change', function(){
401 jQuery('#export_feeds_booking_gcal_events_until_offset').val('');
402 if ( jQuery(this).val() != 'date' ){
403 jQuery('.wpbc_tr_until_offset .wpbc_offset_value').removeClass('hidden_items');
404 jQuery('.wpbc_tr_until_offset .wpbc_offset_datetime').addClass('hidden_items');
405 } else {
406 jQuery('.wpbc_tr_until_offset .wpbc_offset_value').addClass('hidden_items');
407 jQuery('.wpbc_tr_until_offset .wpbc_offset_datetime').removeClass('hidden_items');
408 }
409 } ); ";
410
411
412 // // Hide|Show on Click Radion
413 // $js_script .= " jQuery('input[name=\"paypal_pro_hosted_solution\"]').on( 'change', function(){
414 // jQuery('.wpbc_sub_settings_paypal_account_type').addClass('hidden_items');
415 // if ( jQuery('#paypal_type_standard').is(':checked') ) {
416 // jQuery('.wpbc_sub_settings_paypal_standard').removeClass('hidden_items');
417 // } else {
418 // jQuery('.wpbc_sub_settings_paypal_pro_hosted').removeClass('hidden_items');
419 // }
420 // } ); ";
421
422 ////////////////////////////////////////////////////////////////////////
423
424
425 // Eneque JS to the footer of the page
426 wpbc_enqueue_js( $js_script );
427 }
428
429 // </editor-fold>
430
431 }
432 add_action('wpbc_menu_created', array( new WPBC_Page_SettingsExportFeeds() , '__construct') ); // Executed after creation of Menu
433
434
435
436 /** Show .ics ULR section for Free version */
437 function wpbc_export_ics_feed__table() {
438
439 $resource_export = get_bk_option( 'booking_resource_export_ics_url' );
440 ?>
441 <table class="form-table">
442 <tbody><tr class="wpbc_tr_booking_export_feed_free" valign="top">
443 <th scope="row">
444 <label for="booking_export_feed1" class="wpbc-form-text"><?php _e( '.ics feed URL', 'booking' ); ?></label>
445 </th>
446 <td><fieldset class="wpdevelop">
447 <legend class="screen-reader-text"><span><?php _e( '.ics feed URL', 'booking' ); ?></span></legend>
448 <code style="font-size:12px;line-height: 2.4em;background: #ddd;color:#000;"><a
449 href="<?php echo trim( home_url(), '/' ) . '/' . trim( $resource_export, '/'); ?>"
450 target="_blank"><?php
451 $wpbc_h_u = home_url(); //FixIn: 8.1.3.6
452 if (strlen( $wpbc_h_u ) > 23 ) {
453 echo substr( $wpbc_h_u, 0, 10 ) . '...' . substr( $wpbc_h_u, -10 );
454 } else {
455 echo $wpbc_h_u;
456 }?></a></code>
457 <input id="booking_export_feed1"
458 name="booking_export_feed1"
459 value="<?php echo $resource_export; ?>"
460 placeholder=""
461 autocomplete="off"
462 type="text"
463 class="regular-text"
464 />
465 <a href="<?php echo trim( home_url(), '/' ) . '/' . trim( $resource_export, '/'); ?>"
466 title="<?php _e( 'Open in new window', 'booking' ); ?>"
467 target="_blank"><i class="wpbc_icn_open_in_new"></i></a>
468 <p class="description"><?php _e( 'Please enter URL for generating .ics feed', 'booking' ); ?></p>
469 <div class="wpbc-settings-notice notice-info" style="text-align:left;border-top:1px solid #f0f0f0;border-right:1px solid #f0f0f0;">
470 <strong><?php _e( 'Note', 'booking' ) ?></strong>. <?php
471 printf( __( 'This .ics feed of bookings starting from today for 1 year', 'booking' ) );
472 ?>
473 </div>
474 </fieldset></td>
475 </tr></tbody>
476 </table>
477 <?php
478 }
479
480
481 /**
482 * Save changes to URL in Free version
483 *
484 * @return string - validated value
485 */
486 function wpbc_export_ics_feed__update() {
487
488 $validated_value = WPBC_Settings_API::validate_text_post_static( 'booking_export_feed1' );
489
490 $validated_value = explode( '/', $validated_value );
491 foreach ( $validated_value as $v_i => $v_val ) { //FixIn: 8.1.1.9
492 if ( strpos( $v_val, '.') !== false ) {
493 $v_val = sanitize_file_name( $v_val );
494 }
495 $validated_value[ $v_i ] = $v_val;
496 }
497 // $validated_value = array_map( 'sanitize_file_name', $validated_value );
498 $validated_value = implode( '/', $validated_value );
499 $validated_value = strtolower( $validated_value );
500 $validated_value = wpbc_make_link_relative( $validated_value );
501
502 if ( empty( $validated_value ) )
503 $validated_value = '/ics/' . wpbc_get_slug_format( 'default' );
504
505 update_bk_option( 'booking_resource_export_ics_url', $validated_value );
506
507 return $validated_value;
508 }