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-import-gcal.php

page-import-gcal.php in Booking Calendar 10.10, at core/admin/page-import-gcal.php

848 lines 52.4 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 * @package Booking > Settings > Import page
5 * @category Settings API
6 * @author wpdevelop
7 *
8 * @web-site https://wpbookingcalendar.com/
9 * @email info@wpbookingcalendar.com
10 * @modified 2016-08-07
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
19 /** API for Settings Page */
20 class WPBC_API_SettingsImportGCal extends WPBC_Settings_API {
21
22 /**
23 * Settings API Constructor
24 * During creation, system try to load values from DB, if exist.
25 *
26 * @param type $id - "Pure Name"
27 */
28 public function __construct( $id, $init_fields_values = array(), $options = array() ) {
29
30 $default_options = array(
31 'db_prefix_option' => ''
32 , 'db_saving_type' => 'separate'
33 );
34 // separate_prefix: update_bk_option( $this->options['db_prefix_option'] . $settings_id . '_' . $field_name , $value );
35 $options = wp_parse_args( $options, $default_options );
36
37 /**
38 * Activation and deactivation of these options already done at the wpbc-gcal.php file
39 //
40 // add_bk_action( 'wpbc_other_versions_activation', array( $this, 'activate' ) ); // Activate
41 // add_bk_action( 'wpbc_other_versions_deactivation', array( $this, 'deactivate' ) ); // Deactivate
42 */
43
44 parent::__construct( $id, $options, $init_fields_values ); // Define ID of Setting page and options
45 }
46
47
48 /** Define settings Fields */
49 public function init_settings_fields() {
50
51 $this->fields = array();
52
53
54 // Auto import
55 if ( wpbc_is_mu_user_can_be_here('only_super_admin') ){
56
57 $this->fields['booking_gcal_auto_import_is_active'] = array(
58 'type' => 'checkbox'
59 , 'default' => 'Off'
60 , 'title' => __( 'Activate auto import', 'booking' )
61 /* translators: 1: ... */
62 , 'label' => sprintf( __( 'Check this box to %1$sactivate%2$s auto import events and creation bookings from them', 'booking' ),'<b>','</b>')
63 , 'description' => ''
64 , 'group' => 'auto_import'
65
66 );
67 // $options = array();
68 // $options[1] = '1 ' . __( 'hour', 'booking' );
69 // for ( $i = 2; $i < 24; $i++ ) {
70 // $options[$i] = $i . ' ' . __( 'hours', 'booking' );
71 // }
72 // $options[24] = '1 ' . __( 'day', 'booking' );
73 // for ( $i = 2; $i < 32; $i++ ) {
74 // $options[( $i * 24)] = $i . ' ' . __( 'days', 'booking' );
75 // }
76
77 // Fix for legacy code (previously) was only integer value here in hours
78 $legacy_booking_gcal_auto_import_time = get_bk_option( 'booking_gcal_auto_import_time' );
79 if ( ( false === strpos( $legacy_booking_gcal_auto_import_time, 'm' ) ) && ( false === strpos( $legacy_booking_gcal_auto_import_time, 'd' ) ) ) {
80 update_bk_option( 'booking_gcal_auto_import_time', strval( intval( $legacy_booking_gcal_auto_import_time ) * 60 ) . 'm' );
81 }
82
83 // Options
84 $extra_time = array();
85 foreach ( range( 15, 55, 15 ) as $extra_num ) { // Each 5 minutes
86 $extra_time[ $extra_num . 'm' ] = $extra_num . ' ' . __( 'minutes', 'booking' );
87 }
88 $extra_time[ '60' . 'm' ] = '1 ' . __( 'hour', 'booking' );
89 foreach ( range( 75, 115, 15 ) as $extra_num ) { // 1 hour + Each 5 minutes
90 $extra_time[ $extra_num . 'm' ] = '1 ' . __( 'hour', 'booking' ) . ' ' . ( $extra_num - 60 ) . ' ' . __( 'minutes', 'booking' );
91 }
92 foreach ( range( 120, 1380, 60 ) as $extra_num ) { // Each Hour based on minutes
93 $extra_time[ $extra_num . 'm' ] = ( $extra_num / 60 ) . ' ' . __( 'hours', 'booking' );
94 }
95 foreach ( range( 1, 30, 1 ) as $extra_num ) { // Each Day
96 $extra_time[ $extra_num . 'd' ] = $extra_num . ' ' . __( 'day(s)', 'booking' );
97 }
98
99 $cron_info = '';
100 $readable_time_of_next_run = WPBC()->cron->get_readable_time_of_last_run( 'wpbc_import_gcal' );
101 if ( ! empty( $readable_time_of_next_run ) ) {
102 $cron_info .= '<br/><strong>' . esc_html__( 'Last import', 'booking' ) . '</strong>: ' . $readable_time_of_next_run;
103 }
104 $readable_time_of_next_run = WPBC()->cron->get_readable_time_of_next_run( 'wpbc_import_gcal', '<strong>'.__( 'during', 'booking' ).'</strong> <code>' ) . '</code>';
105 if ( ! empty( $readable_time_of_next_run ) ) {
106 $cron_info .= '<br/><strong>' . esc_html__( 'Next import', 'booking' ) . '</strong>: ' . $readable_time_of_next_run;
107 }
108
109 // $active_tasks_arr = WPBC()->cron->get_active_tasks_info();
110 // if ( ! empty( $active_tasks_arr['wpbc_import_gcal'] ) ) {
111 // $cron_info .= '<br/><strong>' . esc_html__( 'Last import', 'booking' ) . '</strong>: ' . $active_tasks_arr['wpbc_import_gcal']['last_time__run__local'];
112 // $cron_info .= '<br/><strong>' . esc_html__( 'Next import', 'booking' ) . '</strong>: ' . $active_tasks_arr['wpbc_import_gcal']['next_time__run__local'];
113 // $cron_info .= ' ' . __( 'during', 'booking' ) . ': <strong>' . wpbc_get_readable_time_interval( $active_tasks_arr['wpbc_import_gcal']['next_run_after_seconds'] ) . '</strong> ';
114 // }
115
116 $this->fields['booking_gcal_auto_import_time'] = array(
117 'type' => 'select'
118 , 'default' => '24'
119 , 'title' => __('Import events every' ,'booking')
120 , 'description' => __('Select time duration of import requests.' ,'booking') . $cron_info
121 , 'description_tag' => 'span'
122 , 'css' => ''
123 , 'options' => $extra_time
124 , 'tr_class' => 'wpbc_sub_settings_grayed wpbc_tr_auto_import'
125 , 'group' => 'auto_import'
126 );
127 }
128 ////////////////////////////////////////////////////////////////////////
129
130
131 // General Google Calendar Settings
132 $this->fields['booking_gcal_api_key'] = array(
133 'type' => 'text'
134 , 'default' => ''
135 //, 'placeholder' => ''
136 , 'title' => __('Google API Key', 'booking')
137 , 'description' => __('Please enter your Google API key. This field required to import events.' ,'booking')
138 . '<div class="wpbc-settings-notice notice-info" style="text-align:left;"><strong>'
139 . __('Note:' ,'booking') . '</strong> '
140 /* translators: 1: ... */
141 . sprintf( __( 'You can check in this %1$sinstruction how to generate and use your Google API key%2$s.', 'booking' )
142 , '<a href="https://wpbookingcalendar.com/faq/import-gc-events/">'
143 ,'</a>'
144 )
145 . '</div>'
146 . ( ( wpbc_is_this_demo() ) ? wpbc_get_warning_text_in_demo_mode() : '' )
147 , 'description_tag' => 'p'
148 , 'css' => ''//'width:100%'
149 , 'group' => 'general'
150 , 'tr_class' => '' // 'wpbc_sub_settings_grayed'
151 //, 'validate_as' => array( 'required' )
152 , 'is_demo_safe' => wpbc_is_this_demo()
153 );
154
155
156 // General Google ID for Free version
157 if ( ! class_exists('wpdev_bk_personal') )
158 $this->fields['booking_gcal_feed'] = array(
159 'type' => 'text'
160 , 'default' => ''
161 //, 'placeholder' => ''
162 , 'title' => __('Google Calendar ID', 'booking')
163 , 'description' => ( ( wpbc_is_this_demo() ) ? wpbc_get_warning_text_in_demo_mode() : '' )
164 , 'description_tag' => 'span'
165 , 'css' => 'width:100%'
166 , 'group' => 'general'
167 , 'tr_class' => '' // 'wpbc_sub_settings_grayed'
168 //, 'validate_as' => array( 'required' )
169 , 'is_demo_safe' => wpbc_is_this_demo()
170 );
171
172 ////////////////////////////////////////////////////////////////////////
173
174
175 // M A X num - Default Settings
176 $this->fields['booking_gcal_events_max'] = array(
177 'type' => 'text'
178 , 'default' => '25'
179 //, 'placeholder' => ''
180 , 'title' => __('Maximum number', 'booking')
181 , 'description' => __('You can specify the maximum number of events to import during one session.' ,'booking')
182 , 'description_tag' => 'span'
183 , 'css' => 'width:4em'
184 , 'group' => 'default_settings'
185 , 'tr_class' => '' // 'wpbc_sub_settings_grayed'
186 //, 'validate_as' => array( 'required' )
187 );
188 // F R O M /////////////////////////////////////////////////////////
189 $options = array(
190 "now" => __('Now' ,'booking')
191 , "today" => __('00:00 today' ,'booking')
192 , "week" => __('Start of current week' ,'booking')
193 , "month-start" => __('Start of current month' ,'booking')
194 , "month-end" => __('End of current month' ,'booking')
195 , "any" => __('The start of time' ,'booking')
196 , "date" => __('Specific date / time' ,'booking')
197 );
198 $this->fields['booking_gcal_events_from'] = array(
199 'type' => 'select'
200 , 'default' => 'month-start'
201 , 'title' => __('From', 'booking')
202 , 'description' => __('Select option, when to start retrieving events.' ,'booking')
203 , 'description_tag' => 'span'
204 , 'css' => ''
205 , 'options' => $options
206 , 'group' => 'default_settings'
207 );
208 /////////////
209 $this->fields['booking_gcal_events_from_offset_html_prefix'] = array(
210 'type' => 'pure_html'
211 , 'group' => 'default_settings'
212 , 'html' => '<tr valign="top" class="wpbc_tr_import_gcal_booking_gcal_events_from_offset wpbc_sub_settings_grayed wpbc_tr_from_offset">
213 <th scope="row">
214 <label class="wpbc-form-text" for="'
215 . esc_attr( 'import_gcal_booking_gcal_events_from_offset' )
216 . '">'
217 . '<span class="wpbc_offset_value">' . wp_kses_post( __('Offset' ,'booking') ) . '</span>'
218 . '<span class="wpbc_offset_datetime">' . wp_kses_post( __('Enter date / time' ,'booking') ) . '</span>'
219 . '</label>
220 </th>
221 <td><fieldset>'
222 );
223 $this->fields['booking_gcal_events_from_offset'] = array(
224 'type' => 'text'
225 , 'default' => ''
226 //, 'placeholder' => ''
227 , 'title' => ''
228 , 'description' => ''
229 , 'description_tag' => 'span'
230 , 'css' => 'width:6em;height:28px;margin:0;vertical-align:middle;'
231 , 'group' => 'default_settings'
232 , 'tr_class' => 'wpbc_sub_settings_grayed wpbc_tr_from_offset'
233 , 'only_field' => true
234 );
235 $option_types = array(
236 'second' => __('seconds' ,'booking')
237 , 'minute' => __('minutes' ,'booking')
238 , 'hour' => __('hours' ,'booking')
239 , 'day' => __('days' ,'booking')
240 );
241 $this->fields['booking_gcal_events_from_offset_type'] = array(
242 'type' => 'select'
243 , 'default' => ''
244 , 'title' => ''
245 , 'description' => ''
246 , 'description_tag' => 'span'
247 , 'css' => ''
248 , 'options' => $option_types
249 , 'group' => 'default_settings'
250 , 'class' => 'wpbc_offset_value'
251 , 'tr_class' => 'wpbc_sub_settings_grayed'
252 , 'only_field' => true
253 );
254 $this->fields['booking_gcal_events_from_offset_html_sufix'] = array(
255 'type' => 'pure_html'
256 , 'group' => 'default_settings'
257 , 'html' => ' <span class="description wpbc_offset_value">'
258 . __('You can specify an additional offset from you chosen start point. The offset can be negative.' ,'booking')
259 . '</span>
260 <span class="description wpbc_offset_datetime">'
261 /* translators: 1: ... */
262 . sprintf( __( 'Type your date in format %1$s. Example: %2$s', 'booking' ), '<code>Y-m-d</code>', '<code>' . date_i18n( 'Y-m-d' ) . '</code>' )
263 . '</span>
264 </fieldset>
265 </td>
266 </tr>'
267 );
268 /////////////
269
270
271 // U N T I L /////////////////////////////////////////////////////
272 $options = array(
273 "now" => __('Now' ,'booking')
274 , "today" => __('00:00 today' ,'booking')
275 , "week" => __('Start of current week' ,'booking')
276 , "month-start" => __('Start of current month' ,'booking')
277 , "month-end" => __('End of current month' ,'booking')
278 , "any" => __('The end of time' ,'booking')
279 , "date" => __('Specific date / time' ,'booking')
280 );
281 $this->fields['booking_gcal_events_until'] = array(
282 'type' => 'select'
283 , 'default' => 'any'
284 , 'title' => __('Until', 'booking')
285 , 'description' => __('Select option, when to stop retrieving events.' ,'booking')
286 , 'description_tag' => 'span'
287 , 'css' => ''
288 , 'options' => $options
289 , 'group' => 'default_settings'
290 );
291 /////////////
292 $this->fields['booking_gcal_events_until_offset_html_prefix'] = array(
293 'type' => 'pure_html'
294 , 'group' => 'default_settings'
295 , 'html' => '<tr valign="top" class="wpbc_tr_import_gcal_booking_gcal_events_until_offset wpbc_sub_settings_grayed wpbc_tr_until_offset">
296 <th scope="row">
297 <label class="wpbc-form-text" for="'
298 . esc_attr( 'import_gcal_booking_gcal_events_until_offset' )
299 . '">'
300 . '<span class="wpbc_offset_value">' . wp_kses_post( __('Offset' ,'booking') ) . '</span>'
301 . '<span class="wpbc_offset_datetime">' . wp_kses_post( __('Enter date / time' ,'booking') ) . '</span>'
302 . '</label>
303 </th>
304 <td><fieldset>'
305 );
306 $this->fields['booking_gcal_events_until_offset'] = array(
307 'type' => 'text'
308 , 'default' => ''
309 //, 'placeholder' => ''
310 , 'title' => ''
311 , 'description' => ''
312 , 'description_tag' => 'span'
313 , 'css' => 'width:6em;height:28px;margin:0;vertical-align:middle;'
314 , 'group' => 'default_settings'
315 , 'tr_class' => 'wpbc_sub_settings_grayed wpbc_tr_until_offset'
316 , 'only_field' => true
317 );
318 $option_types = array(
319 'second' => __('seconds' ,'booking')
320 , 'minute' => __('minutes' ,'booking')
321 , 'hour' => __('hours' ,'booking')
322 , 'day' => __('days' ,'booking')
323 );
324 $this->fields['booking_gcal_events_until_offset_type'] = array(
325 'type' => 'select'
326 , 'default' => ''
327 , 'title' => ''
328 , 'description' => ''
329 , 'description_tag' => 'span'
330 , 'css' => ''
331 , 'options' => $option_types
332 , 'group' => 'default_settings'
333 , 'class' => 'wpbc_offset_value'
334 , 'tr_class' => 'wpbc_sub_settings_grayed'
335 , 'only_field' => true
336 );
337 $this->fields['booking_gcal_events_until_offset_html_sufix'] = array(
338 'type' => 'pure_html'
339 , 'group' => 'default_settings'
340 , 'html' => ' <span class="description wpbc_offset_value">'
341 . __('You can specify an additional offset from you chosen start point. The offset can be negative.' ,'booking')
342 . '</span>
343 <span class="description wpbc_offset_datetime">'
344 /* translators: 1: ... */
345 . sprintf( __( 'Type your date in format %1$s. Example: %2$s', 'booking' ), '<code>Y-m-d</code>', '<code>' . date_i18n( 'Y-m-d' ) . '</code>' )
346 . '</span>
347 </fieldset>
348 </td>
349 </tr>'
350 );
351 /////////////
352
353 ////////////////////////////////////////////////////////////////////////
354
355 // Help
356 $this->fields['booking_gcal_events_help'] = array(
357 'type' => 'help'
358 , 'value' => array()
359 , 'cols' => 2
360 , 'group' => 'help'
361 );
362 $this->fields['booking_gcal_events_help']['value'][] = '<h4 style="margin-top:-20px;">01. ' . __('To get Google Calendar API key please follow this instruction' ,'booking') . ':</h4>';
363 $this->fields['booking_gcal_events_help']['value'][] = '<ol style="list-style-type: decimal !important;margin-left: 15px;font-size:0.86em;">';
364 /* translators: 1: ... */
365 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf(__( 'Go to Google Developer Console: %s.' ,'booking'),'<a href="https://console.developers.google.com" target="_blank">https://console.developers.google.com</a>') . '</li>';
366 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf(__('Give your project a name and click "Create".' ,'booking')) . '</li>';
367 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf(__('In the sidebar click on "APIs & auth".' ,'booking')) . '</li>';
368 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf(__('Click APIs and make sure "Calendar API" is set to ON.' ,'booking')) . '</li>';
369 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf(__('Now click on "Credentials" in the sidebar.' ,'booking')) . '</li>';
370 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf(__('Under the section "Public API access" click the button "Create new Key".' ,'booking')) . '</li>';
371 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf(__('On the popup click the button "Server Key" and click "Create".' ,'booking')) . '</li>';
372 /* translators: 1: ... */
373 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf( __( 'You will now see a table loaded with the top item being the API Key. Copy this and paste it into %1$sGoogle API Key%2$s field at this page.', 'booking' ),'<strong>','</strong>') . '</li>';
374 $this->fields['booking_gcal_events_help']['value'][] = '</ol>';
375
376 $this->fields['booking_gcal_events_help']['value'][] = '<h4>02. ' . __('Set Your Calendar to Public' ,'booking') . ':</h4>';
377 $this->fields['booking_gcal_events_help']['value'][] = '<ol style="list-style-type: decimal !important;margin-left: 15px;font-size:0.86em;">';
378 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf(__('Navigate to your Google calendars.' ,'booking'),'<a href="https://console.developers.google.com" target="_blank">https://console.developers.google.com</a>') . '</li>';
379 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf(__('Open the settings for the calendar.' ,'booking')) . '</li>';
380 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf(__('Click the "Share this Calendar" link.' ,'booking')) . '</li>';
381 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf(__('Click the checkbox to make calendar public. Do not check the other option.' ,'booking')) . '</li>';
382 $this->fields['booking_gcal_events_help']['value'][] = '</ol>';
383
384 $this->fields['booking_gcal_events_help']['value'][] = '<h4>03. ' . __('Find Your Calendar ID' ,'booking') . ':</h4>';
385 $this->fields['booking_gcal_events_help']['value'][] = '<ol style="list-style-type: decimal !important;margin-left: 15px;font-size:0.86em;">';
386 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf(__('Navigate to your Google calendars.' ,'booking'),'<a href="https://console.developers.google.com" target="_blank">https://console.developers.google.com</a>') . '</li>';
387 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf(__('Open the settings for the calendar.' ,'booking')) . '</li>';
388 /* translators: 1: ... */
389 $this->fields['booking_gcal_events_help']['value'][] = '<li>' . sprintf( __( 'Now copy the Calendar ID to use in the plugin settings in your WordPress admin. Make sure to %1$suse the Calendar ID only, not the entire XML feed URL%2$s.', 'booking' ),'<strong>','</strong>') . '</li>';
390 $this->fields['booking_gcal_events_help']['value'][] = '</ol>';
391
392 ////////////////////////////////////////////////////////////////////////
393 }
394
395 }
396
397
398
399 /**
400 * Show Content
401 * Update Content
402 * Define Slug
403 * Define where to show
404 */
405 class WPBC_Page_SettingsImportGCal extends WPBC_Page_Structure {
406
407
408 public $settings_api = false;
409
410 /**
411 * API - for Fields of this Settings Page
412 *
413 * @param array $init_fields_values - array of init form fields data - this array can ovveride "default" fields and loaded data.
414 * @return object API
415 */
416 public function get_api( $init_fields_values = array() ){
417
418 if ( $this->settings_api === false ) {
419 $this->settings_api = new WPBC_API_SettingsImportGCal( 'import_gcal' , $init_fields_values );
420 }
421 return $this->settings_api;
422 }
423
424
425 public function in_page() {
426 return 'wpbc-settings';
427 }
428
429
430 public function tabs() {
431
432 $tabs = array();
433
434 $tabs[ 'sync' ] = array(
435 'title' => __( 'Sync', 'booking') // Title of TAB
436 , 'page_title'=> __( 'Sync', 'booking') // Title of Page
437 , 'hint' => __('Import' ,'booking') . ' / ' . __('Export' ,'booking')
438 //, 'link' => '' // Can be skiped, then generated link based on Page and Tab tags. Or can be extenral link
439 //, 'position' => '' // 'left' || 'right' || ''
440 //, 'css_classes'=> '' // CSS class(es)
441 //, 'icon' => '' // Icon - link to the real PNG img
442 , 'font_icon' => 'wpbc_icn_sync_alt' // CSS definition of forn Icon
443 //, 'default' => false // Is this tab activated by default or not: true || false.
444 //, 'disabled' => false // Is this tab disbaled: true || false.
445 //, 'hided' => false // Is this tab hided: true || false.
446 , 'subtabs' => array()
447 );
448
449
450 $subtabs = array();
451
452 $subtabs[ 'gcal' ] = array(
453 'type' => 'subtab' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html'
454 , 'title' => __('Import Google Calendar Events', 'booking') //__('Google Calendar' ,'booking') . ' - ' . __('Events Import' ,'booking') // Title of TAB
455 , 'page_title' => __('Import Google Calendar Events', 'booking') //__('Import Settings' ,'booking') // Title of Page
456 , 'hint' => __('Import Google Calendar Events' ,'booking') // Hint
457 , 'link' => '' // link
458 , 'position' => '' // 'left' || 'right' || ''
459 , 'css_classes' => '' // CSS class(es)
460 //, 'icon' => 'http://.../icon.png' // Icon - link to the real PNG img
461 //, 'font_icon' => 'wpbc_icn_mail_outline' // CSS definition of Font Icon
462 , 'header_font_icon' => 'wpbc_icn_sync_alt' // CSS definition of Font Icon // FixIn: 9.6.1.4.
463 , 'default' => false // Is this sub tab activated by default or not: true || false.
464 , 'disabled' => false // Is this sub tab deactivated: true || false.
465 , 'checkbox' => false // or definition array for specific checkbox: array( 'checked' => true, 'name' => 'feature1_active_status' ) //, 'checkbox' => array( 'checked' => $is_checked, 'name' => 'enabled_active_status' )
466 , 'content' => 'content' // Function to load as conten of this TAB
467 //, 'is_use_left_navigation' => true // We commented this line to have the vertical subline of menu
468 );
469
470 $tabs[ 'sync' ]['subtabs'] = $subtabs;
471
472
473 return $tabs;
474 }
475
476
477 /** Show Content of Settings page */
478 public function content() {
479
480 //$active_tasks_arr = WPBC()->cron->get_active_tasks_info();
481 //debuge( $active_tasks_arr );
482
483 $this->css();
484
485 ////////////////////////////////////////////////////////////////////////
486 // Checking
487 ////////////////////////////////////////////////////////////////////////
488
489 do_action( 'wpbc_hook_settings_page_header', 'import_gcal_settings'); // Define Notices Section and show some static messages, if needed
490
491 if ( ! wpbc_is_mu_user_can_be_here('activated_user') ) return false; // Check if MU user activated, otherwise show Warning message.
492
493 // 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.
494
495
496 ////////////////////////////////////////////////////////////////////////
497 // Load Data
498 ////////////////////////////////////////////////////////////////////////
499
500 $this->get_api(); // Load fields Data from DB
501
502
503 ////////////////////////////////////////////////////////////////////////
504 // S u b m i t Main Form
505 ////////////////////////////////////////////////////////////////////////
506
507 $submit_form_name = 'wpbc_import_gcal'; // Define form name
508
509 // $this->get_api()->validated_form_id = $submit_form_name; // Define ID of Form for ability to validate fields (like required field) before submit.
510
511 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
512 if ( isset( $_POST['is_form_sbmitted_'. $submit_form_name ] ) ) {
513
514 // Nonce checking {Return false if invalid, 1 if generated between, 0-12 hours ago, 2 if generated between 12-24 hours ago. }
515 $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
516
517 // Save Changes
518 $this->update();
519 }
520
521
522 ////////////////////////////////////////////////////////////////////////
523 // JavaScript: Tooltips, Popover, Datepick (js & css)
524 ////////////////////////////////////////////////////////////////////////
525
526 echo '<span class="wpdevelop">';
527
528 wpbc_js_for_bookings_page();
529
530 echo '</span>';
531
532 ?><div class="clear" style="margin-bottom:0px;"></div><?php
533
534
535 // Scroll links ////////////////////////////////////////////////////////
536 ?>
537 <div class="wpdvlp-sub-tabs" style="background:none;border:none;box-shadow: none;padding:0;"><span class="nav-tabs" style="text-align:right;">
538 <a href="javascript:void(0);" onclick="javascript:wpbc_scroll_to('#wpbc_settings_import_gcal_events_general_metabox' );" original-title="" class="nav-tab go-to-link"><span><?php esc_html_e('General Settings', 'booking'); ?></span></a>
539 <?php if ( wpbc_is_mu_user_can_be_here('only_super_admin') ) { ?>
540 <a href="javascript:void(0);" onclick="javascript:wpbc_scroll_to('#wpbc_settings_import_gcal_events_auto_import_metabox' );" original-title="" class="nav-tab go-to-link"><span><?php esc_html_e('Auto import events' ,'booking'); ?></span></a>
541 <?php } ?>
542 <a href="javascript:void(0);" onclick="javascript:wpbc_scroll_to('#wpbc_settings_import_gcal_events_default_settings_metabox' );" original-title="" class="nav-tab go-to-link"><span><?php esc_html_e('Default settings for retrieving events' ,'booking'); ?></span></a>
543 <?php if ( class_exists('wpdev_bk_personal') ) { ?>
544 <a href="javascript:void(0);" onclick="javascript:wpbc_scroll_to('#wpbc_resource_table_gcal_id' );" original-title="" class="nav-tab go-to-link"><span><?php esc_html_e('Resources' ,'booking'); ?></span></a>
545 <?php } ?>
546 </span></div>
547 <?php
548
549 if ( class_exists('wpdev_bk_personal') )
550 wpbc_toolbar_search_by_id__top_form( array(
551 'search_form_id' => 'wpbc_booking_resources_search_form'
552 , 'search_get_key' => 'wh_resource_id'
553 , 'is_pseudo' => false
554 ) );
555
556
557 ////////////////////////////////////////////////////////////////////////
558 // Content ////////////////////////////////////////////////////////////
559 ?>
560 <div class="clear" style="margin-bottom:0px;"></div>
561 <span class="metabox-holder">
562 <form name="<?php echo esc_attr( $submit_form_name ); ?>" id="<?php echo esc_attr( $submit_form_name ); ?>" action="" method="post" autocomplete="off">
563 <?php
564 // N o n c e field, and key for checking S u b m i t
565 wp_nonce_field( 'wpbc_settings_page_' . $submit_form_name );
566 ?><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
567 ?><div class="clear"></div><?php
568
569 // Add hidden input SEARCH KEY field into main form, if previosly was searching by ID or Title
570 if ( class_exists('wpdev_bk_personal') )
571 wpbc_hidden_search_by_id_field_in_main_form( array( 'search_get_key' => 'wh_resource_id' ) ); // FixIn: 8.0.1.12.
572
573 ?><div class="clear" style="height:10px;"></div><?php
574
575 ?><div class="wpbc_settings_row wpbc_settings_row_left"><?php
576
577
578 wpbc_open_meta_box_section( 'wpbc_settings_import_gcal_events_general', __('Google Calendar - General Settings' ,'booking') );
579
580 $this->get_api()->show( 'general' );
581
582 wpbc_close_meta_box_section();
583
584
585 if ( wpbc_is_mu_user_can_be_here('only_super_admin') ){
586
587 wpbc_open_meta_box_section( 'wpbc_settings_import_gcal_events_auto_import', __('Auto import events' ,'booking') );
588
589 $this->get_api()->show( 'auto_import' );
590
591 wpbc_close_meta_box_section();
592 }
593
594
595 wpbc_open_meta_box_section( 'wpbc_settings_import_gcal_events_default_settings', __('Default settings for retrieving events' ,'booking') );
596
597 $this->get_api()->show( 'default_settings' );
598
599 wpbc_close_meta_box_section();
600
601 ?>
602 </div>
603 <div class="wpbc_settings_row wpbc_settings_row_right"><?php
604
605 wpbc_open_meta_box_section( 'wpbc_settings_import_gcal_form_help', __('Help', 'booking') );
606 $this->get_api()->show( 'help' );
607 wpbc_close_meta_box_section();
608 ?>
609 </div>
610 <div id="wpbc_resources_link" class="clear"></div>
611 <?php if ( class_exists('wpdev_bk_personal') ) { ?>
612 <div id="wpbc_resource_table_gcal_id" class="wpbc_settings_row wpbc_settings_row_rightNO"><?php
613
614 //wpbc_open_meta_box_section( 'wpbc_settings_import_gcal_resources', __('Resources', 'booking') );
615
616 wpbc_import_gcal__show_table();
617
618 //wpbc_close_meta_box_section();
619 ?>
620 </div>
621 <div class="clear"></div>
622 <?php } ?>
623 <input type="submit" value="<?php esc_attr_e('Save Changes','booking'); ?>" class="button button-primary wpbc_submit_button" />
624 </form>
625 </span>
626 <?php
627
628 do_action( 'wpbc_hook_settings_page_footer', 'import_gcal_settings' );
629
630 $this->enqueue_js();
631 }
632
633
634 /** Save Chanages */
635 public function update() {
636 //debuge($_POST);
637 if ( function_exists( 'wpbc_import_gcal__update') )
638 wpbc_import_gcal__update();
639
640 // Get Validated Email fields
641 $validated_fields = $this->get_api()->validate_post();
642
643 $validated_fields = apply_filters( 'wpbc_fields_before_saving_to_db__import_gcal', $validated_fields ); //Hook for validated fields.
644
645 //debuge($validated_fields);
646
647 $this->get_api()->save_to_db( $validated_fields );
648
649 wpbc_show_changes_saved_message();
650
651 // Old way of saving:
652 // update_bk_option( 'booking_cache_expiration' , WPBC_Settings_API::validate_text_post_static( 'booking_cache_expiration' ) );
653 }
654
655 //TODO: clear unused CSS here
656
657 // <editor-fold defaultstate="collapsed" desc=" CSS & JS " >
658
659 /** CSS for this page */
660 private function css() {
661 ?>
662 <style type="text/css">
663 .wpbc-help-message {
664 border:none;
665 }
666 /* toolbar fix */
667 .wpdevelop .visibility_container .control-group {
668 margin: 2px 8px 3px 0; /* margin: 0 8px 5px 0; */ /* FixIn: 9.5.4.8 */
669 }
670 /* Selectbox element in toolbar */
671 .visibility_container select optgroup{
672 color:#999;
673 vertical-align: middle;
674 font-style: italic;
675 font-weight: 400;
676 }
677 .visibility_container select option {
678 padding:5px;
679 font-weight: 600;
680 }
681 .visibility_container select optgroup option{
682 padding: 5px 20px;
683 color:#555;
684 font-weight: 600;
685 }
686 #wpbc_create_new_custom_form_name_fields {
687 width: 360px;
688 display:none;
689 }
690 @media (max-width: 399px) {
691 #wpbc_create_new_custom_form_name_fields {
692 width: 100%;
693 }
694 }
695 </style>
696 <?php
697 }
698
699
700
701 /**
702 * Add Custon JavaScript - for some specific settings options
703 * Executed After post content, after initial definition of settings, and possible definition after POST request.
704 *
705 * @param type $menu_slug
706 */
707 private function enqueue_js(){
708
709 // JavaScript //////////////////////////////////////////////////////////////
710
711 $js_script = '';
712
713
714 //Show|Hide grayed section
715 $js_script .= "
716 if ( ! jQuery('#import_gcal_booking_gcal_auto_import_is_active').is(':checked') ) {
717 jQuery('.wpbc_tr_auto_import').addClass('hidden_items');
718 }
719 ";
720 // Hide|Show on Click Checkbox
721 $js_script .= " jQuery('#import_gcal_booking_gcal_auto_import_is_active').on( 'change', function(){
722 if ( this.checked ) {
723 jQuery('.wpbc_tr_auto_import').removeClass('hidden_items');
724 } else {
725 jQuery('.wpbc_tr_auto_import').addClass('hidden_items');
726 }
727 } ); ";
728 // F R O M
729 $js_script .= "
730 if ( jQuery('#import_gcal_booking_gcal_events_from').val() != 'date' ) {
731 jQuery('.wpbc_tr_from_offset .wpbc_offset_value').removeClass('hidden_items');
732 jQuery('.wpbc_tr_from_offset .wpbc_offset_datetime').addClass('hidden_items');
733 } else {
734 jQuery('.wpbc_tr_from_offset .wpbc_offset_value').addClass('hidden_items');
735 jQuery('.wpbc_tr_from_offset .wpbc_offset_datetime').removeClass('hidden_items');
736 }
737 ";
738 // On select option in selectbox
739 $js_script .= " jQuery('#import_gcal_booking_gcal_events_from').on( 'change', function(){
740 jQuery('#import_gcal_booking_gcal_events_from_offset').val('');
741 if ( jQuery(this).val() != 'date' ){
742 jQuery('.wpbc_tr_from_offset .wpbc_offset_value').removeClass('hidden_items');
743 jQuery('.wpbc_tr_from_offset .wpbc_offset_datetime').addClass('hidden_items');
744 } else {
745 jQuery('.wpbc_tr_from_offset .wpbc_offset_value').addClass('hidden_items');
746 jQuery('.wpbc_tr_from_offset .wpbc_offset_datetime').removeClass('hidden_items');
747 }
748 } ); ";
749 // U n t i l
750 $js_script .= "
751 if ( jQuery('#import_gcal_booking_gcal_events_until').val() != 'date' ) {
752 jQuery('.wpbc_tr_until_offset .wpbc_offset_value').removeClass('hidden_items');
753 jQuery('.wpbc_tr_until_offset .wpbc_offset_datetime').addClass('hidden_items');
754 } else {
755 jQuery('.wpbc_tr_until_offset .wpbc_offset_value').addClass('hidden_items');
756 jQuery('.wpbc_tr_until_offset .wpbc_offset_datetime').removeClass('hidden_items');
757 }
758 ";
759 // On select option in selectbox
760 $js_script .= " jQuery('#import_gcal_booking_gcal_events_until').on( 'change', function(){
761 jQuery('#import_gcal_booking_gcal_events_until_offset').val('');
762 if ( jQuery(this).val() != 'date' ){
763 jQuery('.wpbc_tr_until_offset .wpbc_offset_value').removeClass('hidden_items');
764 jQuery('.wpbc_tr_until_offset .wpbc_offset_datetime').addClass('hidden_items');
765 } else {
766 jQuery('.wpbc_tr_until_offset .wpbc_offset_value').addClass('hidden_items');
767 jQuery('.wpbc_tr_until_offset .wpbc_offset_datetime').removeClass('hidden_items');
768 }
769 } ); ";
770
771
772 // // Hide|Show on Click Radion
773 // $js_script .= " jQuery('input[name=\"paypal_pro_hosted_solution\"]').on( 'change', function(){
774 // jQuery('.wpbc_sub_settings_paypal_account_type').addClass('hidden_items');
775 // if ( jQuery('#paypal_type_standard').is(':checked') ) {
776 // jQuery('.wpbc_sub_settings_paypal_standard').removeClass('hidden_items');
777 // } else {
778 // jQuery('.wpbc_sub_settings_paypal_pro_hosted').removeClass('hidden_items');
779 // }
780 // } ); ";
781
782 ////////////////////////////////////////////////////////////////////////
783
784
785 // Eneque JS to the footer of the page
786 wpbc_enqueue_js( $js_script );
787 }
788
789 // </editor-fold>
790
791 }
792 add_action('wpbc_menu_created', array( new WPBC_Page_SettingsImportGCal() , '__construct') ); // Executed after creation of Menu
793
794
795 /**
796 * Override fields array of Settings page, AFTER saving to DB. Some fields have to have different Values.
797 * Set here values for our pseudo-options, after saving to DB
798 * Because they was not overloading during this saving
799 *
800 * @param array $fields
801 * @param string $page_id
802 * @return array - fields
803 */
804 function wpbc_fields_after_saving_to_db__import_gcal( $fields, $page_id ) {
805
806 if ( $page_id == 'import_gcal' ) { // Check our API ID relative saving of this settings page
807
808 // Update Cron // FixIn: 7.0.1.9.
809 if ( $fields['booking_gcal_auto_import_is_active']['value'] == 'On' ) {
810
811 $booking_gcal_auto_import_time = $fields['booking_gcal_auto_import_time']['value'];
812
813 if ( false !== strpos( $booking_gcal_auto_import_time, 'm' ) ) {
814
815 $booking_gcal_auto_import_time = str_replace( array( 'm', 'd' ), '', $booking_gcal_auto_import_time );
816 $booking_gcal_auto_import_time = intval( $booking_gcal_auto_import_time );
817 $time_dimension = 'm';
818
819 } else if ( false !== strpos( $booking_gcal_auto_import_time, 'd' ) ) {
820 $booking_gcal_auto_import_time = str_replace( array( 'm', 'd' ), '', $booking_gcal_auto_import_time );
821 $booking_gcal_auto_import_time = intval( $booking_gcal_auto_import_time );
822 $time_dimension = 'd';
823
824 } else { // Old hours
825
826 $booking_gcal_auto_import_time = intval( $booking_gcal_auto_import_time );
827 $time_dimension = 'h';
828 }
829
830
831 update_bk_option( 'booking_gcal_auto_import_time', $fields['booking_gcal_auto_import_time']['value'] );
832
833 // add
834 WPBC()->cron->update( 'wpbc_import_gcal' , array(
835 'action' => array( 'wpbc_silent_import_all_events' ) // Action and parameters
836 , 'start_time' => (time()-1) // Now
837 , 'last_execution' => time() // Set last time execution
838 , 'recurrence' => intval( $booking_gcal_auto_import_time ) // Set time value
839 , 'time_dimension' => $time_dimension // 'h' - hours, 'm' - minutes, 'd' - days
840 ) );
841 } else {
842 WPBC()->cron->delete( 'wpbc_import_gcal' ); // delete
843 }
844
845 }
846 return $fields;
847 }
848 add_filter('wpbc_fields_after_saving_to_db', 'wpbc_fields_after_saving_to_db__import_gcal', 10, 2);