/**
  * Get singletonian instance of this class
  *
  * @return Ai1ec_Deferred_Rendering_Helper Instance of self
  */
 public static function get_instance()
 {
     if (self::$_instance === NULL) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 /**
  * Update the less variables on the DB and recompile the CSS
  *
  * @param array $variables
  * @param boolean $resetting are we resetting or updating variables?
  */
 private function update_variables_and_compile_css(array $variables, $resetting)
 {
     $no_parse_errors = $this->invalidate_cache($variables, true);
     if ($no_parse_errors) {
         $this->db_adapter->write_data_to_config(Ai1ec_Lessphp_Controller::DB_KEY_FOR_LESS_VARIABLES, $variables);
         $message = Ai1ec_Helper_Factory::create_admin_message_instance(sprintf('<p>' . __("Theme options were updated successfully. <a href='%s'>Visit site</a>", AI1EC_PLUGIN_NAME) . '</p>', get_site_url()));
         if (true === $resetting) {
             $message = Ai1ec_Helper_Factory::create_admin_message_instance(sprintf('<p>' . __("Theme options were successfully reset to their default values. <a href='%s'>Visit site</a>", AI1EC_PLUGIN_NAME) . '</p>', get_site_url()));
         }
         $message->set_message_type('updated');
         $this->admin_notices_helper->add_renderable_children($message);
     }
 }
 /**
  * Create a duplicate from a posts' instance
  */
 function duplicate_post_create_duplicate($post, $status = '')
 {
     $new_post_author = $this->duplicate_post_get_current_user();
     $new_post_status = $status;
     if (empty($new_post_status)) {
         $new_post_status = $post->post_status;
     }
     $new_post_status = $this->get_new_post_status($new_post_status);
     $new_post = array('menu_order' => $post->menu_order, 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'pinged' => $post->pinged, 'post_author' => $new_post_author->ID, 'post_content' => $post->post_content, 'post_date' => $post->post_date, 'post_date_gmt' => get_gmt_from_date($post->post_date), 'post_excerpt' => $post->post_excerpt, 'post_parent' => $post->post_parent, 'post_password' => $post->post_password, 'post_status' => $new_post_status, 'post_title' => $post->post_title, 'post_type' => $post->post_type, 'to_ping' => $post->to_ping);
     $new_post_id = wp_insert_post($new_post);
     $edit_event_url = esc_attr(admin_url("post.php?post={$new_post_id}&action=edit"));
     $message = Ai1ec_Helper_Factory::create_admin_message_instance(sprintf(__('<p>The event <strong>%s</strong> was cloned succesfully. <a href="%s">Edit cloned event</a></p>', AI1EC_PLUGIN_NAME), $post->post_title, $edit_event_url));
     $message->set_message_type('updated');
     $this->admin_notice_helper->add_renderable_children($message);
     // If you have written a plugin which uses non-WP database tables to save
     // information about a post you can hook this action to dupe that data.
     if ($post->post_type == 'page' || function_exists('is_post_type_hierarchical') && is_post_type_hierarchical($post->post_type)) {
         do_action('dp_duplicate_page', $new_post_id, $post);
     } else {
         do_action('dp_duplicate_post', $new_post_id, $post);
     }
     if ('ai1ec_event' === $post->post_type) {
         try {
             $old_event = new Ai1ec_Event($post->ID);
             $old_event->post_id = $new_post_id;
             unset($old_event->post);
             $old_event->save();
         } catch (Ai1ec_Event_Not_Found $exception) {
             /* ignore */
         }
     }
     delete_post_meta($new_post_id, '_dp_original');
     add_post_meta($new_post_id, '_dp_original', $post->ID);
     // If the copy gets immediately published, we have to set a proper slug.
     if ($new_post_status == 'publish' || $new_post_status == 'future') {
         $post_name = wp_unique_post_slug($post->post_name, $new_post_id, $new_post_status, $post->post_type, $post->post_parent);
         $new_post = array();
         $new_post['ID'] = $new_post_id;
         $new_post['post_name'] = $post_name;
         // Update the post into the database
         wp_update_post($new_post);
     }
     return $new_post_id;
 }
 /**
  * get_notices_helper method
  *
  * DIP implementing method, to give access to Ai1ec_Deferred_Rendering_Helper.
  *
  * @param Ai1ec_Deferred_Rendering_Helper $replacement Notices implementor
  *
  * @return Ai1ec_Deferred_Rendering_Helper Instance of notices implementor
  */
 public function get_notices_helper(Ai1ec_Deferred_Rendering_Helper $replacement = NULL)
 {
     static $helper = NULL;
     if (NULL !== $replacement) {
         $helper = $replacement;
     }
     if (NULL === $helper) {
         $helper = Ai1ec_Deferred_Rendering_Helper::get_instance();
     }
     return $helper;
 }
 /**
  * Constructor
  *
  * Default constructor - application initialization
  **/
 private function __construct($preview_mode)
 {
     global $wpdb, $wp_locale, $wp_scripts, $ai1ec_app_helper, $ai1ec_view_helper, $ai1ec_events_controller, $ai1ec_events_helper, $ai1ec_importer_controller, $ai1ec_exporter_controller, $ai1ec_settings_controller, $ai1ec_settings, $ai1ec_themes_controller, $ai1ec_calendar_controller, $ai1ec_calendar_helper, $ai1ec_importer_plugin_helper, $ai1ec_requirejs_controller, $ai1ec_rss_feed, $ai1ec_duplicate_controller, $ai1ec_events_list_helper, $ai1ec_oauth_controller;
     $aie1c_deferred_rendering_helper = Ai1ec_Deferred_Rendering_Helper::get_instance();
     $ai1ec_duplicate_controller->set_admin_notice_helper($aie1c_deferred_rendering_helper);
     $css_controller = Ai1ec_Less_Factory::create_css_controller_instance();
     $notification_controller = Ai1ec_Notification_Controller::get_instance();
     // register_activation_hook
     register_activation_hook(AI1EC_PLUGIN_NAME . '/' . AI1EC_PLUGIN_NAME . '.php', array(&$this, 'activation_hook'));
     // Configure MySQL to operate in GMT time
     $wpdb->query("SET time_zone = '+0:00'");
     // Load plugin text domain
     $this->load_textdomain();
     // Install/update database schema as necessary
     $this->install_schema();
     // Enable stats collection
     $this->install_n_cron();
     // Enable plugins for importing events from external sources
     $this->install_plugins();
     $lessphp_controller = Ai1ec_Less_Factory::create_lessphp_controller();
     // Update less variables in the db
     if (isset($_POST[Ai1ec_Less_Variables_Editing_Page::FORM_SUBMIT_NAME]) || isset($_POST[Ai1ec_Less_Variables_Editing_Page::FORM_SUBMIT_RESET_THEME])) {
         $css_controller->handle_less_variables_page_form_post();
     }
     // Adds the image field only if we are on event categories page
     $this->add_image_field_to_event_categories();
     // Enable checking for cron updates
     $this->install_u_cron();
     // Continue loading hooks only if themes are installed. Otherwise display a
     // notification on the backend with instructions how to install themes.
     if (!$ai1ec_themes_controller->are_themes_available()) {
         // Enables the hidden themes installer page
         add_action('admin_menu', array(&$ai1ec_themes_controller, 'register_theme_installer'), 10);
         // Redirects the user to install theme page
         add_action('admin_menu', array(&$this, 'check_themes'), 2);
         return;
     }
     if (false === $preview_mode && !$ai1ec_themes_controller->are_themes_outdated()) {
         // Create the less variables if they are not set, but only if we are not in preview mode.
         // this is because there is an edge case when you activate a theme and then you preview another
         // the variables of the other theme are set.
         $lessphp_controller->initialize_less_variables_if_not_set(Ai1ec_Less_Factory::create_less_file_instance(Ai1ec_Less_File::USER_VARIABLES_FILE));
     }
     // Check for legacy format themes when viewing WP dashboard; do not perform
     // the check when switching themes or if current theme files are outdated.
     if (is_admin() && !isset($_GET['ai1ec_template']) && !$ai1ec_themes_controller->are_themes_outdated()) {
         $ai1ec_themes_controller->generate_notice_if_legacy_theme_installed();
     }
     // Install and configure events regeneration schedule
     $ai1ec_events_helper->register_regeneration_hook();
     // ===========
     // = ACTIONS =
     // ===========
     // Very early on in WP bootstrap, prepare to do any requested theme preview.
     add_action('setup_theme', array($ai1ec_themes_controller, 'preview_theme'));
     // Calendar theme initialization
     add_action('after_setup_theme', array($ai1ec_themes_controller, 'setup_theme'));
     // Create custom post type
     add_action('init', array($ai1ec_app_helper, 'create_post_type'));
     // Handle ICS export requests
     add_action('init', array($this, 'parse_standalone_request'));
     // Regenerate events on timezone change
     add_action('update_option_timezone_string', array($ai1ec_events_helper, 'regenerate_events_cache_on_tz'), 10, 2);
     // RSS Feed
     add_action('init', array($ai1ec_rss_feed, 'add_feed'));
     // Add the link for CSS generation
     if (!is_admin()) {
         add_action('init', array($css_controller, 'add_link_to_html_for_frontend'), 1);
     }
     // Load plugin text domain
     add_action('init', array($this, 'load_textdomain'));
     // Load back-end javascript files
     add_action('init', array($ai1ec_requirejs_controller, 'load_admin_js'));
     // Initialize router
     add_action('init', array($this, 'initialize_router'), PHP_INT_MAX - 1);
     add_action('cron_schedules', array(Ai1ec_Scheduling_Utility::instance(), 'cron_schedules'));
     // Load the scripts for the backend for wordpress version < 3.3
     add_action('admin_footer', array($ai1ec_requirejs_controller, 'print_admin_script_footer_for_wordpress_32'));
     // Load the scripts for the frontend for wordpress version < 3.3
     add_action('wp_footer', array($ai1ec_requirejs_controller, 'print_frontend_script_footer_for_wordpress_32'));
     // Set an action to load front-end javascript
     add_action('ai1ec_load_frontend_js', array($ai1ec_requirejs_controller, 'load_frontend_js'), 10, 2);
     // Check if themes are installed
     add_action('init', array($ai1ec_themes_controller, 'check_themes'));
     // Register The Event Calendar importer
     add_action('admin_init', array($ai1ec_importer_controller, 'register_importer'));
     // Install admin menu items.
     add_action('admin_menu', array($this, 'admin_menu'), 9);
     // Enable theme updater page if last version of core themes is older than
     // current version.
     if ($ai1ec_themes_controller->are_themes_outdated()) {
         add_action('admin_menu', array($ai1ec_themes_controller, 'register_theme_updater'), 10);
     }
     // Add Event counts to dashboard.
     add_action('right_now_content_table_end', array($ai1ec_app_helper, 'right_now_content_table_end'));
     // add content for our custom columns
     add_action('manage_ai1ec_event_posts_custom_column', array($ai1ec_app_helper, 'custom_columns'), 10, 2);
     // Add filtering dropdowns for event categories and tags
     add_action('restrict_manage_posts', array($ai1ec_app_helper, 'taxonomy_filter_restrict_manage_posts'));
     // Trigger display of page in front-end depending on request
     add_action('template_redirect', array($this, 'route_request'));
     // Add meta boxes to event creation/edit form.
     add_action('add_meta_boxes', array($ai1ec_app_helper, 'add_meta_boxes'));
     add_action('show_user_profile', array($ai1ec_app_helper, 'add_profile_boxes'));
     add_action('personal_options_update', array($ai1ec_app_helper, 'save_user_profile'), 10, 1);
     add_action('post_submitbox_misc_actions', array($ai1ec_oauth_controller, 'post_meta_box'), 10, 2);
     // Save event data when post is saved
     add_action('save_post', array($ai1ec_events_controller, 'save_post'), 10, 2);
     add_action('save_post', array($ai1ec_events_list_helper, 'handle_post_save_purge'), 10, 2);
     // Delete event data when post is deleted
     add_action('delete_post', array($ai1ec_events_controller, 'delete_post'));
     add_action('trashed_post', array($ai1ec_events_controller, 'trashed_post'));
     add_action('untrashed_post', array($ai1ec_events_controller, 'untrashed_post'));
     add_action('trashed_post', array($ai1ec_events_list_helper, 'purge'));
     add_action('delete_post', array($ai1ec_events_list_helper, 'purge'));
     add_action('delete_term', array($ai1ec_events_list_helper, 'purge'));
     add_action('delete_term', array($ai1ec_settings, 'term_deletion'), 10, 3);
     // Notification cron job hook
     add_action('ai1ec_n_cron', array($ai1ec_exporter_controller, 'n_cron'));
     // Updates cron job hook
     add_action('ai1ec_u_cron', array($ai1ec_settings_controller, 'u_cron'));
     // Category colors
     add_action('events_categories_add_form_fields', array($ai1ec_events_controller, 'events_categories_add_form_fields'));
     add_action('events_categories_edit_form_fields', array($ai1ec_events_controller, 'events_categories_edit_form_fields'));
     add_action('created_events_categories', array($ai1ec_events_controller, 'created_events_categories'));
     add_action('edited_events_categories', array($ai1ec_events_controller, 'edited_events_categories'));
     add_action('admin_notices', array($ai1ec_app_helper, 'admin_notices'));
     add_action('created_events_tags', array($ai1ec_events_list_helper, 'purge'));
     add_action('edited_events_tags', array($ai1ec_events_list_helper, 'purge'));
     // specific action available to network admin, while in networked
     //  installation, or site admin otherwise
     $network_action = 'admin_notices';
     if (is_multisite()) {
         $network_action = 'network_admin_notices';
     }
     add_action($network_action, array($ai1ec_app_helper, 'network_admin_notices'));
     // The new object that handles notices.
     add_action(Ai1ec_Deferred_Rendering_Helper::ADMIN_MESSAGES_ACTION, array($aie1c_deferred_rendering_helper, 'render'));
     // Render modals in the footer
     add_action(Ai1ec_Deferred_Rendering_Helper::BOOTSTRAP_MODALS_ACTION, array($aie1c_deferred_rendering_helper, 'render'));
     // Scripts/styles for settings and widget admin screens.
     add_action('admin_enqueue_scripts', array($ai1ec_app_helper, 'admin_enqueue_scripts'));
     // Widgets
     add_action('widgets_init', create_function('', "return register_widget( 'Ai1ec_Agenda_Widget' );"));
     // Modify WP admin bar
     add_action('admin_bar_menu', array($ai1ec_app_helper, 'modify_admin_bar'));
     // ===========
     // = FILTERS =
     // ===========
     if (is_admin() && 'admin-ajax.php' !== basename($_SERVER['SCRIPT_NAME'])) {
         add_filter('the_title', array($ai1ec_view_helper, 'the_title_admin'), 1, 2);
     }
     add_filter('post_row_actions', array($ai1ec_view_helper, 'post_row_actions'), 10, 2);
     add_filter('posts_orderby', array($ai1ec_app_helper, 'orderby'), 10, 2);
     // add custom column names and change existing columns
     add_filter('manage_ai1ec_event_posts_columns', array($ai1ec_app_helper, 'change_columns'));
     // filter the post lists by custom filters
     add_filter('parse_query', array($ai1ec_app_helper, 'taxonomy_filter_post_type_request'));
     // Override excerpt filters for proper event display in excerpt form
     add_filter('get_the_excerpt', array($ai1ec_events_controller, 'event_excerpt'), 11);
     add_filter('the_excerpt', array($ai1ec_events_controller, 'event_excerpt_noautop'), 11);
     remove_filter('the_excerpt', 'wpautop', 10);
     // Update event post update messages
     add_filter('post_updated_messages', array($ai1ec_events_controller, 'post_updated_messages'));
     // Sort the custom columns
     add_filter('manage_edit-ai1ec_event_sortable_columns', array($ai1ec_app_helper, 'sortable_columns'));
     add_filter('map_meta_cap', array($ai1ec_app_helper, 'map_meta_cap'), 10, 4);
     // Inject event categories, only in front-end, depending on setting
     if ($ai1ec_settings->inject_categories && !is_admin()) {
         add_filter('get_terms', array($ai1ec_app_helper, 'inject_categories'), 10, 3);
         add_filter('wp_list_categories', array($ai1ec_app_helper, 'selected_category_link'), 10, 2);
     }
     // Rewrite event category URLs to point to calendar page.
     add_filter('term_link', array($ai1ec_app_helper, 'calendar_term_link'), 10, 3);
     // Add a link to settings page on the plugin list page.
     add_filter('plugin_action_links_' . AI1EC_PLUGIN_BASENAME, array($ai1ec_settings_controller, 'plugin_action_links'));
     // Add a link to donate page on plugin list page.
     add_filter('plugin_row_meta', array($ai1ec_settings_controller, 'plugin_row_meta'), 10, 2);
     add_filter('post_type_link', array($ai1ec_events_helper, 'post_type_link'), 10, 3);
     add_filter('ai1ec_template_root_path', array($ai1ec_themes_controller, 'template_root_path'));
     add_filter('ai1ec_template_root_url', array($ai1ec_themes_controller, 'template_root_url'));
     add_filter('option_ai1ec_update_available', array($this, 'limit_update_notice'));
     add_filter('manage_edit-events_categories_columns', array($this, 'manage_event_categories_columns'));
     add_filter('manage_events_categories_custom_column', array($this, 'manage_events_categories_custom_column'), 10, 3);
     // ========
     // = AJAX =
     // ========
     // RRule to Text
     add_action('wp_ajax_ai1ec_rrule_to_text', array($ai1ec_events_helper, 'convert_rrule_to_text'));
     // Display Repeat Box
     add_action('wp_ajax_ai1ec_get_repeat_box', array($ai1ec_events_helper, 'get_repeat_box'));
     add_action('wp_ajax_ai1ec_get_date_picker_box', array($ai1ec_events_helper, 'get_date_picker_box'));
     // Disable notifications
     add_action('wp_ajax_ai1ec_disable_notification', array($ai1ec_settings_controller, 'disable_notification'));
     add_action('wp_ajax_ai1ec_disable_intro_video', array($ai1ec_settings_controller, 'disable_intro_video'));
     // subscribe to event
     add_action('wp_ajax_nopriv_ai1ec_subscribe_to_event', array($notification_controller, 'subscribe_to_event'));
     add_action('wp_ajax_ai1ec_subscribe_to_event', array($notification_controller, 'subscribe_to_event'));
     // Front-end event creation
     add_action('wp_ajax_ai1ec_front_end_create_event_form', array($ai1ec_events_helper, 'get_front_end_create_event_form'));
     add_action('wp_ajax_ai1ec_front_end_submit_event', array($ai1ec_events_helper, 'submit_front_end_create_event_form'));
     if ($ai1ec_settings->allow_anonymous_submissions) {
         add_action('wp_ajax_nopriv_ai1ec_front_end_create_event_form', array($ai1ec_events_helper, 'get_front_end_create_event_form'));
         add_action('wp_ajax_nopriv_ai1ec_front_end_submit_event', array($ai1ec_events_helper, 'submit_front_end_create_event_form'));
     }
     // remove entries from DB cache, if any
     add_action('ai1ec_upgrade', array($ai1ec_calendar_controller, 'clear_db_cache'));
     // Make checks on `pre_http_request`, to filter HTTP requests
     add_filter('pre_http_request', array(Ai1ec_Http_Utility::instance(), 'pre_http_request'), 10, 3);
     // set-up Twitter notifications cron
     add_action('ai1ec_send_twitter_messages', array($notification_controller, 'send_twitter_messages'));
     Ai1ec_Scheduling_Utility::instance()->reschedule('ai1ec_send_twitter_messages', '1h');
     // Invalid license status warning.
     add_action('wp_ajax_ai1ec_set_license_warning', array($ai1ec_settings_controller, 'set_license_warning'));
     // ==============
     // = Shortcodes =
     // ==============
     add_shortcode('ai1ec', array($ai1ec_events_helper, 'shortcode'));
     // ===============
     // = Ai1EC hooks =
     // ===============
     add_action('ai1ec_purge_events_cache', array($ai1ec_events_list_helper, 'purge'));
     $this->upgrade_actions();
 }
 /**
  * @param string $active_theme_path
  * @param string $default_theme_path
  * @return Ai1ec_Css_Controller
  */
 public static function create_css_controller_instance()
 {
     $aie1c_admin_notices_helper = Ai1ec_Deferred_Rendering_Helper::get_instance();
     $db_adapter = Ai1ec_Adapters_Factory::create_db_adapter_instance();
     $persistence_context = Ai1ec_Strategies_Factory::create_persistence_context(Ai1ec_Css_Controller::KEY_FOR_PERSISTANCE, AI1EC_CACHE_PATH);
     $lessphp_controller = self::create_lessphp_controller();
     $controller = new Ai1ec_Css_Controller($persistence_context, $lessphp_controller, $db_adapter, self::$preview_mode, Ai1ec_Adapters_Factory::create_template_adapter_instance());
     $controller->set_admin_notices_helper($aie1c_admin_notices_helper);
     return $controller;
 }
 /**
  * Create the modal for the event subscription
  *
  * @param $event Ai1ec_Event
  */
 private function add_modal_for_email_subscription(Ai1ec_Event $event)
 {
     $current_user = wp_get_current_user();
     $user_email = $current_user->user_email;
     unset($current_user);
     // Create containing div
     $div = Ai1ec_Helper_Factory::create_generic_html_tag('div');
     $div->add_class('ai1ec_email_container form-horizontal');
     $div->set_attribute('data-event_id', $event->post_id);
     $div->set_attribute('data-event_instance', $event->instance_id);
     // Add alert container to containing div
     $div_alerts = Ai1ec_Helper_Factory::create_generic_html_tag('div');
     $div_alerts->add_class('alerts');
     // Add paragraph to containing div
     $paragraph = Ai1ec_Helper_Factory::create_generic_html_tag('p');
     $paragraph->set_text(__('Enter your email address below to receive a notification about the event 6 hours before it starts.', AI1EC_PLUGIN_NAME));
     $div->add_renderable_children($paragraph);
     // Add div.control-group to containing div
     $control_group = Ai1ec_Helper_Factory::create_generic_html_tag('div');
     $control_group->add_class('control-group');
     $div->add_renderable_children($control_group);
     // Add label to div.control-group
     $label = Ai1ec_Helper_Factory::create_generic_html_tag('label');
     $label->add_class('control-label');
     $label->set_attribute('for', 'ai1ec_email_subscribe');
     $label->set_text(__('Email:', AI1EC_PLUGIN_NAME));
     $control_group->add_renderable_children($label);
     // Add div.controls to div.control-group
     $controls = Ai1ec_Helper_Factory::create_generic_html_tag('div');
     $controls->add_class('controls');
     $control_group->add_renderable_children($controls);
     // Add input to div.controls
     $input = Ai1ec_Helper_Factory::create_input_instance();
     $input->set_id('ai1ec_email_subscribe');
     $input->set_name('ai1ec_email_subscribe');
     if (!empty($user_email)) {
         $input->set_value($user_email);
     }
     $input->set_attribute('placeholder', __('Email', AI1EC_PLUGIN_NAME));
     $controls->add_renderable_children($input);
     // Create modal and add our enclosing div to it
     $bootstrap_modal = Ai1ec_Helper_Factory::create_bootstrap_modal_instance($div_alerts->render_as_html() . $div->render_as_html());
     $bootstrap_modal->set_header_text(__('Get notified about this event', AI1EC_PLUGIN_NAME));
     $bootstrap_modal->set_id('ai1ec_subscribe_email_modal');
     $bootstrap_modal->add_class('fade');
     $bootstrap_modal->set_keep_button_text('<i class="icon-ok"></i> ' . __('Subscribe', AI1EC_PLUGIN_NAME));
     $bootstrap_modal->set_delete_button_text('<i class="icon-remove"></i> ' . __('Close', AI1EC_PLUGIN_NAME));
     $ai1ec_deferred_helper = Ai1ec_Deferred_Rendering_Helper::get_instance();
     $ai1ec_deferred_helper->add_renderable_children($bootstrap_modal);
 }
 /**
  * If it is detected that current theme is in legacy format, generate a
  * dashboard notice.
  */
 public function generate_notice_if_legacy_theme_installed($display_now = false)
 {
     $theme = Ai1ec_Meta::get_option('ai1ec_template', AI1EC_DEFAULT_THEME_NAME);
     // Save directory separator to more concise variable name.
     $slash = DIRECTORY_SEPARATOR;
     $errors = array();
     // ==========================
     // = Wrong style.css format =
     // ==========================
     // Check if a theme has a style.css file containing something besides a CSS
     // comment.
     try {
         $style = Ai1ec_Less_Factory::create_less_file_instance('..' . $slash . 'style');
         $css = file_get_contents($style->locate_exact_file_to_load_in_theme_folders());
     } catch (Ai1ec_File_Not_Found $e) {
         // File not found; no legacy theme code available to detect, so return.
         return;
     }
     $css = $this->remove_comments_and_space($css);
     if ($css) {
         $errors[] = sprintf(__('In your theme folder, <code>%s</code>, the file <code>%sstyle.css</code> should now be used only for metadata information (name, author, etc.).', AI1EC_PLUGIN_NAME) . ' ' . __('We detected custom CSS rules in that file. Those should be removed from <code>%sstyle.css</code> and placed in the file <code>%scss%soverride.css</code>.', AI1EC_PLUGIN_NAME), $theme, $slash, $slash, $slash, $slash);
     }
     // ==========================
     // = Required files missing =
     // ==========================
     // Check if the theme is missing any of the files that are in Gamma (which
     // includes the minimum files).
     $gamma_files = $this->_get_file_listing(AI1EC_THEMES_ROOT . $slash . 'gamma', '#' . $slash . '\\.|^' . $slash . 'functions\\.php$#i');
     $theme_files = $this->_get_file_listing($this->active_template_path());
     $diff = array_diff($gamma_files, $theme_files);
     if ($diff) {
         $errors[] = sprintf(__('Your theme folder <code>%s</code> is missing one or more required files: <code>%s</code>. Please copy these files from the skeleton theme folder, <code>gamma</code>, into the same relative location under <code>%s</code>.', AI1EC_PLUGIN_NAME), $theme, implode('</code>, <code>', $diff), $theme);
     }
     if ($errors) {
         // ===============================================================
         // = Additional checks for modified page templates and other CSS =
         // ===============================================================
         // Now that we've established that the theme is outdated, make certain
         // recommendations to the user based on the below checks.
         // If they also have overridden page templates. These *must* be updated.
         $vortex_php = $this->_get_file_listing(AI1EC_THEMES_ROOT . '/' . AI1EC_DEFAULT_THEME_NAME, '#^' . $slash . '(functions|index)\\.php$#i', '#\\.php$#i');
         $theme_php = $this->_get_file_listing($this->active_template_path(), '#^' . $slash . '(functions|index)\\.php$#i', '#\\.php$#i');
         $php_in_common = array_intersect($vortex_php, $theme_php);
         if ($php_in_common) {
             $errors[] = sprintf(__('We detected one or more custom templates files in your theme folder, <code>%s</code>:', AI1EC_PLUGIN_NAME) . ' ' . '<blockquote><code>' . implode('</code>, <code>', $php_in_common) . '</code></blockquote>' . __('These templates’ originals have changed significantly since these were copied from <code>%s</code>, and the new versions include numerous enhancements. <strong>Your theme’s outdated templates will likely cause your calendar to malfunction.</strong>', AI1EC_PLUGIN_NAME) . ' ' . __('We recommend you back up your templates and remove them from <code>%s</code>. Try using your calendar, and if changes are needed, copy the latest version of the template from <code>%s</code> to <code>%s</code> and then make your revisions.', AI1EC_PLUGIN_NAME), $theme, AI1EC_DEFAULT_THEME_NAME, $theme, AI1EC_DEFAULT_THEME_NAME, $theme);
         }
         // Check for overridden CSS. These must also be updated.
         $vortex_css = array($slash . 'less' . $slash . 'style.less', $slash . 'less' . $slash . 'calendar.less', $slash . 'less' . $slash . 'event.less', $slash . 'css' . $slash . 'style.css', $slash . 'css' . $slash . 'calendar.css', $slash . 'css' . $slash . 'event.css');
         $theme_css = $this->_get_file_listing($this->active_template_path(), '#^' . $slash . 'style\\.css$#i', '#\\.(css|less)$#i');
         $css_in_common = array_intersect($vortex_css, $theme_css);
         if ($css_in_common) {
             $errors[] = sprintf(__('We detected one or more custom CSS or LESS files in your theme folder, <code>%s</code>, that will override the corresponding original in %s:', AI1EC_PLUGIN_NAME) . '<blockquote><code>' . implode('</code>, <code>', $css_in_common) . '</code></blockquote>' . __('The originals have changed significantly since these were copied from <code>%s</code>, and the new versions include numerous enhancements. <strong>Your theme’s outdated CSS/LESS files will likely cause your calendar to be displayed incorrectly.</strong>', AI1EC_PLUGIN_NAME) . ' ' . __('We recommend you back up the affected CSS/LESS files and remove them from <code>%s</code>. Try using your calendar and if changes are needed, place your custom CSS rules in <code>%scss%soverride.css</code> (or custom LESS rules in <code>%sless%soverride.less</code>).', AI1EC_PLUGIN_NAME), $theme, AI1EC_DEFAULT_THEME_NAME, AI1EC_DEFAULT_THEME_NAME, $theme, $slash, $slash, $slash, $slash);
         }
         // Display final report.
         $message = Ai1ec_Helper_Factory::create_admin_message_instance('<p>' . __("You are using a calendar theme that should be updated to the new conventions:", AI1EC_PLUGIN_NAME) . '</p><ol><li>' . implode('</li><li>', $errors) . '</li></ol><p>' . sprintf(__('<strong>Note:</strong> After modifying any of your theme’s CSS or LESS files, you <em>must</em> click <strong>Events</strong> &gt; <strong>Theme Options</strong> &gt; <strong>Save Options</strong> to refresh the compiled CSS used in the front-end.', AI1EC_PLUGIN_NAME) . '</p><p>' . __('You can learn more from our <a href="%s" target="_blank">Help Desk article</a>.', AI1EC_PLUGIN_NAME), 'http://support.time.ly/creating-a-child-theme/') . '</p>', __("All-in-One Event Calendar Warning: Calendar theme is in legacy format", AI1EC_PLUGIN_NAME));
         if (true === $display_now) {
             $message->render();
         } else {
             $aie1c_admin_notices_helper = Ai1ec_Deferred_Rendering_Helper::get_instance();
             $aie1c_admin_notices_helper->add_renderable_children($message);
         }
     }
 }
 /**
  * Handle request - perform variables initialization and inner routing
  *
  * @return bool OAuth success status
  */
 public function handle_request()
 {
     $result = false;
     $message = NULL;
     try {
         $this->_provider = $this->get_provider();
         $result = $this->authorize();
     } catch (Ai1ec_Oauth_Exception $exception) {
         // @RELEASE $this->_log->error( 'OAuth failure: ' . $exception->getMessage() );
         $result = false;
         $message = $exception->getMessage();
     }
     $renderable = NULL;
     if ($result) {
         $renderable = Ai1ec_Helper_Factory::create_admin_message_instance(sprintf(__('You have successfully linked your account with <strong>%s</strong>.', AI1EC_PLUGIN_NAME), $this->_provider->get_name()), __('External Service linked', AI1EC_PLUGIN_NAME));
         $renderable->set_message_type('updated');
     } else {
         $renderable = Ai1ec_Helper_Factory::create_admin_message_instance(sprintf(__('There was a failure linking your account with <strong>%s</strong>: %s.', AI1EC_PLUGIN_NAME), $this->_provider->get_name(), $message), __('External Service linking error', AI1EC_PLUGIN_NAME));
         $renderable->set_message_type('error');
     }
     Ai1ec_Deferred_Rendering_Helper::get_instance()->add_renderable_children($renderable);
     return ai1ec_redirect(admin_url(AI1EC_SETTINGS_BASE_URL));
 }