| 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', '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' => __('Set up and configure the import of Google Calendar events using the API.' ,'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-bi-google' // CSS definition of Font Icon |
| 462 |
, 'default' => false // Is this sub tab activated by default or not: true || false. |
| 463 |
, 'disabled' => false // Is this sub tab deactivated: true || false. |
| 464 |
, 'checkbox' => false // or definition array for specific checkbox: array( 'checked' => true, 'name' => 'feature1_active_status' ) //, 'checkbox' => array( 'checked' => $is_checked, 'name' => 'enabled_active_status' ) |
| 465 |
, 'content' => 'content' // Function to load as conten of this TAB |
| 466 |
|
| 467 |
); |
| 468 |
|
| 469 |
$tabs[ 'sync' ]['subtabs'] = $subtabs; |
| 470 |
|
| 471 |
|
| 472 |
return $tabs; |
| 473 |
} |
| 474 |
|
| 475 |
|
| 476 |
/** Show Content of Settings page */ |
| 477 |
public function content() { |
| 478 |
|
| 479 |
//$active_tasks_arr = WPBC()->cron->get_active_tasks_info(); |
| 480 |
//debuge( $active_tasks_arr ); |
| 481 |
|
| 482 |
$this->css(); |
| 483 |
|
| 484 |
//////////////////////////////////////////////////////////////////////// |
| 485 |
// Checking |
| 486 |
//////////////////////////////////////////////////////////////////////// |
| 487 |
|
| 488 |
do_action( 'wpbc_hook_settings_page_header', 'import_gcal_settings'); // Define Notices Section and show some static messages, if needed |
| 489 |
|
| 490 |
if ( ! wpbc_is_mu_user_can_be_here('activated_user') ) return false; // Check if MU user activated, otherwise show Warning message. |
| 491 |
|
| 492 |
// 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. |
| 493 |
|
| 494 |
|
| 495 |
//////////////////////////////////////////////////////////////////////// |
| 496 |
// Load Data |
| 497 |
//////////////////////////////////////////////////////////////////////// |
| 498 |
|
| 499 |
$this->get_api(); // Load fields Data from DB |
| 500 |
|
| 501 |
|
| 502 |
//////////////////////////////////////////////////////////////////////// |
| 503 |
// S u b m i t Main Form |
| 504 |
//////////////////////////////////////////////////////////////////////// |
| 505 |
|
| 506 |
$submit_form_name = 'wpbc_import_gcal'; // Define form name |
| 507 |
|
| 508 |
// $this->get_api()->validated_form_id = $submit_form_name; // Define ID of Form for ability to validate fields (like required field) before submit. |
| 509 |
|
| 510 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 511 |
if ( isset( $_POST['is_form_sbmitted_'. $submit_form_name ] ) ) { |
| 512 |
|
| 513 |
// Nonce checking {Return false if invalid, 1 if generated between, 0-12 hours ago, 2 if generated between 12-24 hours ago. } |
| 514 |
$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 |
| 515 |
|
| 516 |
// Save Changes |
| 517 |
$this->update(); |
| 518 |
} |
| 519 |
|
| 520 |
|
| 521 |
//////////////////////////////////////////////////////////////////////// |
| 522 |
// JavaScript: Tooltips, Popover, Datepick (js & css) |
| 523 |
//////////////////////////////////////////////////////////////////////// |
| 524 |
|
| 525 |
echo '<span class="wpdevelop">'; |
| 526 |
|
| 527 |
wpbc_js_for_bookings_page(); |
| 528 |
|
| 529 |
echo '</span>'; |
| 530 |
|
| 531 |
?><div class="clear" style="margin-bottom:0px;"></div><?php |
| 532 |
|
| 533 |
|
| 534 |
// Scroll links //////////////////////////////////////////////////////// |
| 535 |
?> |
| 536 |
<div class="wpdvlp-sub-tabs" style="background:none;border:none;box-shadow: none;padding:0;"><span class="nav-tabs" style="text-align:right;"> |
| 537 |
<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> |
| 538 |
<?php if ( wpbc_is_mu_user_can_be_here('only_super_admin') ) { ?> |
| 539 |
<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> |
| 540 |
<?php } ?> |
| 541 |
<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> |
| 542 |
<?php if ( class_exists('wpdev_bk_personal') ) { ?> |
| 543 |
<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> |
| 544 |
<?php } ?> |
| 545 |
</span></div> |
| 546 |
<?php |
| 547 |
|
| 548 |
if ( class_exists('wpdev_bk_personal') ) |
| 549 |
wpbc_toolbar_search_by_id__top_form( array( |
| 550 |
'search_form_id' => 'wpbc_booking_resources_search_form' |
| 551 |
, 'search_get_key' => 'wh_resource_id' |
| 552 |
, 'is_pseudo' => false |
| 553 |
) ); |
| 554 |
|
| 555 |
|
| 556 |
//////////////////////////////////////////////////////////////////////// |
| 557 |
// Content //////////////////////////////////////////////////////////// |
| 558 |
?> |
| 559 |
<div class="clear" style="margin-bottom:0px;"></div> |
| 560 |
<span class="metabox-holder"> |
| 561 |
<form name="<?php echo esc_attr( $submit_form_name ); ?>" id="<?php echo esc_attr( $submit_form_name ); ?>" action="" method="post" autocomplete="off"> |
| 562 |
<?php |
| 563 |
// N o n c e field, and key for checking S u b m i t |
| 564 |
wp_nonce_field( 'wpbc_settings_page_' . $submit_form_name ); |
| 565 |
?><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 |
| 566 |
?><div class="clear"></div><?php |
| 567 |
|
| 568 |
// Add hidden input SEARCH KEY field into main form, if previosly was searching by ID or Title |
| 569 |
if ( class_exists('wpdev_bk_personal') ) |
| 570 |
wpbc_hidden_search_by_id_field_in_main_form( array( 'search_get_key' => 'wh_resource_id' ) ); // FixIn: 8.0.1.12. |
| 571 |
|
| 572 |
?><div class="clear" style="height:10px;"></div><?php |
| 573 |
|
| 574 |
?><div class="wpbc_settings_row wpbc_settings_row_left"><?php |
| 575 |
|
| 576 |
|
| 577 |
wpbc_open_meta_box_section( 'wpbc_settings_import_gcal_events_general', __('Google Calendar - General Settings' ,'booking') ); |
| 578 |
|
| 579 |
$this->get_api()->show( 'general' ); |
| 580 |
|
| 581 |
wpbc_close_meta_box_section(); |
| 582 |
|
| 583 |
|
| 584 |
if ( wpbc_is_mu_user_can_be_here('only_super_admin') ){ |
| 585 |
|
| 586 |
wpbc_open_meta_box_section( 'wpbc_settings_import_gcal_events_auto_import', __('Auto import events' ,'booking') ); |
| 587 |
|
| 588 |
$this->get_api()->show( 'auto_import' ); |
| 589 |
|
| 590 |
wpbc_close_meta_box_section(); |
| 591 |
} |
| 592 |
|
| 593 |
|
| 594 |
wpbc_open_meta_box_section( 'wpbc_settings_import_gcal_events_default_settings', __('Default settings for retrieving events' ,'booking') ); |
| 595 |
|
| 596 |
$this->get_api()->show( 'default_settings' ); |
| 597 |
|
| 598 |
wpbc_close_meta_box_section(); |
| 599 |
|
| 600 |
?> |
| 601 |
</div> |
| 602 |
<div class="wpbc_settings_row wpbc_settings_row_right"><?php |
| 603 |
|
| 604 |
wpbc_open_meta_box_section( 'wpbc_settings_import_gcal_form_help', __('Help', 'booking') ); |
| 605 |
$this->get_api()->show( 'help' ); |
| 606 |
wpbc_close_meta_box_section(); |
| 607 |
?> |
| 608 |
</div> |
| 609 |
<div id="wpbc_resources_link" class="clear"></div> |
| 610 |
<?php if ( class_exists('wpdev_bk_personal') ) { ?> |
| 611 |
<div id="wpbc_resource_table_gcal_id" class="wpbc_settings_row wpbc_settings_row_rightNO"><?php |
| 612 |
|
| 613 |
//wpbc_open_meta_box_section( 'wpbc_settings_import_gcal_resources', __('Resources', 'booking') ); |
| 614 |
|
| 615 |
wpbc_import_gcal__show_table(); |
| 616 |
|
| 617 |
//wpbc_close_meta_box_section(); |
| 618 |
?> |
| 619 |
</div> |
| 620 |
<div class="clear"></div> |
| 621 |
<?php } ?> |
| 622 |
<input type="submit" value="<?php esc_attr_e('Save Changes','booking'); ?>" class="button button-primary wpbc_submit_button" /> |
| 623 |
</form> |
| 624 |
</span> |
| 625 |
<?php |
| 626 |
|
| 627 |
do_action( 'wpbc_hook_settings_page_footer', 'import_gcal_settings' ); |
| 628 |
|
| 629 |
$this->enqueue_js(); |
| 630 |
} |
| 631 |
|
| 632 |
|
| 633 |
/** Save Chanages */ |
| 634 |
public function update() { |
| 635 |
//debuge($_POST); |
| 636 |
if ( function_exists( 'wpbc_import_gcal__update') ) |
| 637 |
wpbc_import_gcal__update(); |
| 638 |
|
| 639 |
// Get Validated Email fields |
| 640 |
$validated_fields = $this->get_api()->validate_post(); |
| 641 |
|
| 642 |
$validated_fields = apply_filters( 'wpbc_fields_before_saving_to_db__import_gcal', $validated_fields ); //Hook for validated fields. |
| 643 |
|
| 644 |
//debuge($validated_fields); |
| 645 |
|
| 646 |
$this->get_api()->save_to_db( $validated_fields ); |
| 647 |
|
| 648 |
wpbc_show_changes_saved_message(); |
| 649 |
|
| 650 |
// Old way of saving: |
| 651 |
// update_bk_option( 'booking_cache_expiration' , WPBC_Settings_API::validate_text_post_static( 'booking_cache_expiration' ) ); |
| 652 |
} |
| 653 |
|
| 654 |
//TODO: clear unused CSS here |
| 655 |
|
| 656 |
// <editor-fold defaultstate="collapsed" desc=" CSS & JS " > |
| 657 |
|
| 658 |
/** CSS for this page */ |
| 659 |
private function css() { |
| 660 |
?> |
| 661 |
<style type="text/css"> |
| 662 |
.wpbc-help-message { |
| 663 |
border:none; |
| 664 |
} |
| 665 |
/* toolbar fix */ |
| 666 |
.wpdevelop .visibility_container .control-group { |
| 667 |
margin: 2px 8px 3px 0; /* margin: 0 8px 5px 0; */ /* FixIn: 9.5.4.8 */ |
| 668 |
} |
| 669 |
/* Selectbox element in toolbar */ |
| 670 |
.visibility_container select optgroup{ |
| 671 |
color:#999; |
| 672 |
vertical-align: middle; |
| 673 |
font-style: italic; |
| 674 |
font-weight: 400; |
| 675 |
} |
| 676 |
.visibility_container select option { |
| 677 |
padding:5px; |
| 678 |
font-weight: 600; |
| 679 |
} |
| 680 |
.visibility_container select optgroup option{ |
| 681 |
padding: 5px 20px; |
| 682 |
color:#555; |
| 683 |
font-weight: 600; |
| 684 |
} |
| 685 |
#wpbc_create_new_custom_form_name_fields { |
| 686 |
width: 360px; |
| 687 |
display:none; |
| 688 |
} |
| 689 |
@media (max-width: 399px) { |
| 690 |
#wpbc_create_new_custom_form_name_fields { |
| 691 |
width: 100%; |
| 692 |
} |
| 693 |
} |
| 694 |
</style> |
| 695 |
<?php |
| 696 |
} |
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
/** |
| 701 |
* Add Custon JavaScript - for some specific settings options |
| 702 |
* Executed After post content, after initial definition of settings, and possible definition after POST request. |
| 703 |
* |
| 704 |
* @param type $menu_slug |
| 705 |
*/ |
| 706 |
private function enqueue_js(){ |
| 707 |
|
| 708 |
// JavaScript ////////////////////////////////////////////////////////////// |
| 709 |
|
| 710 |
$js_script = ''; |
| 711 |
|
| 712 |
|
| 713 |
//Show|Hide grayed section |
| 714 |
$js_script .= " |
| 715 |
if ( ! jQuery('#import_gcal_booking_gcal_auto_import_is_active').is(':checked') ) { |
| 716 |
jQuery('.wpbc_tr_auto_import').addClass('hidden_items'); |
| 717 |
} |
| 718 |
"; |
| 719 |
// Hide|Show on Click Checkbox |
| 720 |
$js_script .= " jQuery('#import_gcal_booking_gcal_auto_import_is_active').on( 'change', function(){ |
| 721 |
if ( this.checked ) { |
| 722 |
jQuery('.wpbc_tr_auto_import').removeClass('hidden_items'); |
| 723 |
} else { |
| 724 |
jQuery('.wpbc_tr_auto_import').addClass('hidden_items'); |
| 725 |
} |
| 726 |
} ); "; |
| 727 |
// F R O M |
| 728 |
$js_script .= " |
| 729 |
if ( jQuery('#import_gcal_booking_gcal_events_from').val() != 'date' ) { |
| 730 |
jQuery('.wpbc_tr_from_offset .wpbc_offset_value').removeClass('hidden_items'); |
| 731 |
jQuery('.wpbc_tr_from_offset .wpbc_offset_datetime').addClass('hidden_items'); |
| 732 |
} else { |
| 733 |
jQuery('.wpbc_tr_from_offset .wpbc_offset_value').addClass('hidden_items'); |
| 734 |
jQuery('.wpbc_tr_from_offset .wpbc_offset_datetime').removeClass('hidden_items'); |
| 735 |
} |
| 736 |
"; |
| 737 |
// On select option in selectbox |
| 738 |
$js_script .= " jQuery('#import_gcal_booking_gcal_events_from').on( 'change', function(){ |
| 739 |
jQuery('#import_gcal_booking_gcal_events_from_offset').val(''); |
| 740 |
if ( jQuery(this).val() != 'date' ){ |
| 741 |
jQuery('.wpbc_tr_from_offset .wpbc_offset_value').removeClass('hidden_items'); |
| 742 |
jQuery('.wpbc_tr_from_offset .wpbc_offset_datetime').addClass('hidden_items'); |
| 743 |
} else { |
| 744 |
jQuery('.wpbc_tr_from_offset .wpbc_offset_value').addClass('hidden_items'); |
| 745 |
jQuery('.wpbc_tr_from_offset .wpbc_offset_datetime').removeClass('hidden_items'); |
| 746 |
} |
| 747 |
} ); "; |
| 748 |
// U n t i l |
| 749 |
$js_script .= " |
| 750 |
if ( jQuery('#import_gcal_booking_gcal_events_until').val() != 'date' ) { |
| 751 |
jQuery('.wpbc_tr_until_offset .wpbc_offset_value').removeClass('hidden_items'); |
| 752 |
jQuery('.wpbc_tr_until_offset .wpbc_offset_datetime').addClass('hidden_items'); |
| 753 |
} else { |
| 754 |
jQuery('.wpbc_tr_until_offset .wpbc_offset_value').addClass('hidden_items'); |
| 755 |
jQuery('.wpbc_tr_until_offset .wpbc_offset_datetime').removeClass('hidden_items'); |
| 756 |
} |
| 757 |
"; |
| 758 |
// On select option in selectbox |
| 759 |
$js_script .= " jQuery('#import_gcal_booking_gcal_events_until').on( 'change', function(){ |
| 760 |
jQuery('#import_gcal_booking_gcal_events_until_offset').val(''); |
| 761 |
if ( jQuery(this).val() != 'date' ){ |
| 762 |
jQuery('.wpbc_tr_until_offset .wpbc_offset_value').removeClass('hidden_items'); |
| 763 |
jQuery('.wpbc_tr_until_offset .wpbc_offset_datetime').addClass('hidden_items'); |
| 764 |
} else { |
| 765 |
jQuery('.wpbc_tr_until_offset .wpbc_offset_value').addClass('hidden_items'); |
| 766 |
jQuery('.wpbc_tr_until_offset .wpbc_offset_datetime').removeClass('hidden_items'); |
| 767 |
} |
| 768 |
} ); "; |
| 769 |
|
| 770 |
|
| 771 |
// // Hide|Show on Click Radion |
| 772 |
// $js_script .= " jQuery('input[name=\"paypal_pro_hosted_solution\"]').on( 'change', function(){ |
| 773 |
// jQuery('.wpbc_sub_settings_paypal_account_type').addClass('hidden_items'); |
| 774 |
// if ( jQuery('#paypal_type_standard').is(':checked') ) { |
| 775 |
// jQuery('.wpbc_sub_settings_paypal_standard').removeClass('hidden_items'); |
| 776 |
// } else { |
| 777 |
// jQuery('.wpbc_sub_settings_paypal_pro_hosted').removeClass('hidden_items'); |
| 778 |
// } |
| 779 |
// } ); "; |
| 780 |
|
| 781 |
//////////////////////////////////////////////////////////////////////// |
| 782 |
|
| 783 |
|
| 784 |
// Eneque JS to the footer of the page |
| 785 |
wpbc_enqueue_js( $js_script ); |
| 786 |
} |
| 787 |
|
| 788 |
// </editor-fold> |
| 789 |
|
| 790 |
} |
| 791 |
add_action('wpbc_menu_created', array( new WPBC_Page_SettingsImportGCal() , '__construct') ); // Executed after creation of Menu |
| 792 |
|
| 793 |
|
| 794 |
/** |
| 795 |
* Override fields array of Settings page, AFTER saving to DB. Some fields have to have different Values. |
| 796 |
* Set here values for our pseudo-options, after saving to DB |
| 797 |
* Because they was not overloading during this saving |
| 798 |
* |
| 799 |
* @param array $fields |
| 800 |
* @param string $page_id |
| 801 |
* @return array - fields |
| 802 |
*/ |
| 803 |
function wpbc_fields_after_saving_to_db__import_gcal( $fields, $page_id ) { |
| 804 |
|
| 805 |
if ( $page_id == 'import_gcal' ) { // Check our API ID relative saving of this settings page |
| 806 |
|
| 807 |
// Update Cron // FixIn: 7.0.1.9. |
| 808 |
if ( $fields['booking_gcal_auto_import_is_active']['value'] == 'On' ) { |
| 809 |
|
| 810 |
$booking_gcal_auto_import_time = $fields['booking_gcal_auto_import_time']['value']; |
| 811 |
|
| 812 |
if ( false !== strpos( $booking_gcal_auto_import_time, 'm' ) ) { |
| 813 |
|
| 814 |
$booking_gcal_auto_import_time = str_replace( array( 'm', 'd' ), '', $booking_gcal_auto_import_time ); |
| 815 |
$booking_gcal_auto_import_time = intval( $booking_gcal_auto_import_time ); |
| 816 |
$time_dimension = 'm'; |
| 817 |
|
| 818 |
} else if ( false !== strpos( $booking_gcal_auto_import_time, 'd' ) ) { |
| 819 |
$booking_gcal_auto_import_time = str_replace( array( 'm', 'd' ), '', $booking_gcal_auto_import_time ); |
| 820 |
$booking_gcal_auto_import_time = intval( $booking_gcal_auto_import_time ); |
| 821 |
$time_dimension = 'd'; |
| 822 |
|
| 823 |
} else { // Old hours |
| 824 |
|
| 825 |
$booking_gcal_auto_import_time = intval( $booking_gcal_auto_import_time ); |
| 826 |
$time_dimension = 'h'; |
| 827 |
} |
| 828 |
|
| 829 |
|
| 830 |
update_bk_option( 'booking_gcal_auto_import_time', $fields['booking_gcal_auto_import_time']['value'] ); |
| 831 |
|
| 832 |
// add |
| 833 |
WPBC()->cron->update( 'wpbc_import_gcal' , array( |
| 834 |
'action' => array( 'wpbc_silent_import_all_events' ) // Action and parameters |
| 835 |
, 'start_time' => (time()-1) // Now |
| 836 |
, 'last_execution' => time() // Set last time execution |
| 837 |
, 'recurrence' => intval( $booking_gcal_auto_import_time ) // Set time value |
| 838 |
, 'time_dimension' => $time_dimension // 'h' - hours, 'm' - minutes, 'd' - days |
| 839 |
) ); |
| 840 |
} else { |
| 841 |
WPBC()->cron->delete( 'wpbc_import_gcal' ); // delete |
| 842 |
} |
| 843 |
|
| 844 |
} |
| 845 |
return $fields; |
| 846 |
} |
| 847 |
add_filter('wpbc_fields_after_saving_to_db', 'wpbc_fields_after_saving_to_db__import_gcal', 10, 2); |