/**
  * Get singletonian instance of this object
  *
  * @return Ai1ec_Scheduling_Utility Singletonian instance
  */
 public static function instance()
 {
     if (!self::$_instance instanceof self) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 /**
  * install_notification_cron function
  *
  * This function sets up the cron job for collecting stats
  *
  * @return void
  **/
 function install_n_cron()
 {
     global $ai1ec_settings;
     $hook_name = 'ai1ec_n_cron';
     $scheduler = Ai1ec_Scheduling_Utility::instance();
     // if stats are disabled, cancel the cron
     if (false === $ai1ec_settings->allow_statistics) {
         return $scheduler->delete($hook_name);
     }
     return $scheduler->reschedule($hook_name, AI1EC_N_CRON_FREQ, AI1EC_N_CRON_VERSION);
 }
 /**
  * update_settings method
  *
  * Handle settings page submit.
  *
  * @param array $params User supplied settings options
  *
  * @return bool Success
  */
 public function update_settings(array $params)
 {
     global $ai1ec_app_helper;
     // Default values to use for fields if none provided.
     $field_defaults = array('default_categories' => array(), 'default_tags' => array());
     $field_names = array('default_categories', 'default_tags', 'default_calendar_view', 'calendar_css_selector', 'week_start_day', 'exact_date', 'posterboard_events_per_page', 'posterboard_tile_min_width', 'stream_events_per_page', 'week_view_ends_at', 'week_view_starts_at', 'agenda_events_per_page', 'input_date_format', 'allow_events_posting_facebook', 'facebook_credentials', 'user_role_can_create_event', 'timezone', 'recaptcha_public_key', 'recaptcha_private_key', 'admin_mail_subject', 'admin_mail_body', 'user_mail_subject', 'user_mail_body', 'view_cache_refresh_interval', 'admin_add_new_event_mail_body', 'admin_add_new_event_mail_subject', 'user_upcoming_event_mail_body', 'user_upcoming_event_mail_subject', 'license_key', 'oauth_twitter_id', 'oauth_twitter_pass', 'twitter_notice_interval', 'disclaimer');
     $checkboxes = array('disable_standard_filter_menu', 'view_posterboard_enabled', 'view_stream_enabled', 'view_month_enabled', 'view_week_enabled', 'view_oneday_enabled', 'view_agenda_enabled', 'agenda_include_entire_last_day', 'agenda_events_expanded', 'include_events_in_rss', 'show_publish_button', 'hide_maps_until_clicked', 'exclude_from_search', 'show_create_event_button', 'show_front_end_create_form', 'allow_anonymous_submissions', 'allow_anonymous_uploads', 'show_add_calendar_button', 'turn_off_subscription_buttons', 'inject_categories', 'input_24h_time', 'geo_region_biasing', 'disable_autocompletion', 'show_location_in_title', 'show_year_in_agenda_dates', 'skip_in_the_loop_check', 'ajaxify_events_in_web_widget', 'calendar_base_url_for_permalinks', 'enable_user_event_notifications', 'use_select2_widgets', 'require_disclaimer', 'use_authors_filter', 'disable_gzip_compression');
     // Save the Buy Tickets Button setting. Since it's a boolean we just set the
     // key so that later we can use isset() instead of in_array(), which is much
     // slower.
     $this->views_enabled_ticket_button = array();
     foreach ($ai1ec_app_helper->view_names() as $key => $name) {
         $checkbox_name = "buy_ticket_{$key}_enabled";
         $this->views_enabled_ticket_button[$key] = isset($params[$checkbox_name]);
     }
     // Only super-admins have the power to change Event Platform mode.
     if (is_super_admin()) {
         $checkboxes[] = 'event_platform';
         $checkboxes[] = 'event_platform_strict';
     }
     // =====================================
     // = Save the settings for the plugins =
     // =====================================
     global $ai1ec_importer_plugin_helper;
     $ai1ec_importer_plugin_helper->save_plugins_settings($params);
     // =================================
     // = Assign parameters to settings =
     // =================================
     foreach ($field_names as $field_name) {
         if (isset($params[$field_name])) {
             $this->{$field_name} = stripslashes_deep($params[$field_name]);
         } elseif (isset($field_defaults[$field_name])) {
             $this->{$field_name} = $field_defaults[$field_name];
         }
     }
     foreach ($checkboxes as $checkbox) {
         $this->{$checkbox} = isset($params[$checkbox]) ? true : false;
     }
     $frequency = new Ai1ec_Frequency_Utility();
     $frequency->parse($this->twitter_notice_interval);
     $this->twitter_notice_interval = $frequency->to_string();
     unset($frequency);
     Ai1ec_Scheduling_Utility::instance()->reschedule('ai1ec_purge_events_cache', $this->view_cache_refresh_interval);
     // ================================
     // = Validate specific parameters =
     // ================================
     // Posterboard events per page
     $this->posterboard_events_per_page = intval($this->posterboard_events_per_page);
     if ($this->posterboard_events_per_page <= 0) {
         $this->posterboard_events_per_page = 1;
     }
     // Stream events per page
     $this->stream_events_per_page = intval($this->stream_events_per_page);
     if ($this->stream_events_per_page <= 0) {
         $this->stream_events_per_page = 1;
     }
     // Starting time to show in the week view
     $this->week_view_starts_at = intval($this->week_view_starts_at);
     if ($this->week_view_starts_at < 0 || $this->week_view_starts_at > 24) {
         $this->week_view_starts_at = self::WEEK_VIEW_STARTS_AT;
     }
     // Starting time to show in the week view
     $this->week_view_ends_at = intval($this->week_view_ends_at);
     if ($this->week_view_ends_at < 0 || $this->week_view_ends_at > 24) {
         $this->week_view_ends_at = self::WEEK_VIEW_ENDS_AT;
     }
     // Posterboard tile minimum width
     $this->posterboard_tile_min_width = intval($this->posterboard_tile_min_width);
     if ($this->posterboard_tile_min_width <= 0) {
         $this->posterboard_tile_min_width = 1;
     }
     // Agenda events per page
     $this->agenda_events_per_page = intval($this->agenda_events_per_page);
     if ($this->agenda_events_per_page <= 0) {
         $this->agenda_events_per_page = 1;
     }
     // Calendar default start date
     $exact_date_valid = Ai1ec_Validation_Utility::validate_date($this->exact_date, $this->input_date_format);
     if (false === $exact_date_valid) {
         $this->exact_date = '';
     }
     // =============================
     // = Update special parameters =
     // =============================
     $this->update_page('calendar_page_id', $params);
     // Flush rewrite rules to regenerate them.
     // Needed for the
     // Base permalinks of single event pages on the calendar page URL
     // setting
     flush_rewrite_rules();
     return true;
 }
// ================================================
function ai1ec_disable_updates($r, $url)
{
    if (0 !== strpos($url, 'http://api.wordpress.org/plugins/update-check')) {
        return $r;
    }
    // Not a plugin update request.
    $plugins = unserialize($r['body']['plugins']);
    unset($plugins->plugins[plugin_basename(__FILE__)]);
    unset($plugins->active[array_search(plugin_basename(__FILE__), $plugins->active)]);
    $r['body']['plugins'] = serialize($plugins);
    return $r;
}
add_filter('http_request_args', 'ai1ec_disable_updates', 5, 2);
// Instantiate scheduling utility early, to get all schedules set-up
Ai1ec_Scheduling_Utility::instance();
// ===============================
// = Initialize and setup MODELS =
// ===============================
global $ai1ec_settings;
$ai1ec_settings = Ai1ec_Settings::get_instance();
// If GZIP is causing JavaScript failure following query
// parameter disable compression, until reversing change
// is made. Causative issue: AIOEC-1192.
if (isset($_REQUEST['ai1ec_disable_gzip_compression'])) {
    $ai1ec_settings->disable_gzip_compression = true;
    $ai1ec_settings->save();
}
// This is a fix for AIOEC-73. I need to set those values as soon as possible so that
// the platofrom controller has the fresh data and can act accordingly
// I do not trigger the save action at this point because there are too many things going on