/** * get_instance function * * Return singleton instance * * @return Ai1ec_Notification_Controller **/ static function get_instance() { if (self::$_instance === NULL) { self::$_instance = new self(); } return self::$_instance; }
/** * 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(); }
/** * Check if e-mail subscription button should be displayed * * @param Ai1ec_Event $event Event being checked * * @return bool True to display e-mail subscription button */ protected function _show_email_subscribe(Ai1ec_Event $event) { global $ai1ec_settings; if (!$ai1ec_settings->enable_user_event_notifications) { return false; } if (isset($_COOKIE['ai1ec_event_subscribed']) && in_array($event->instance_id, (array) json_decode($_COOKIE['ai1ec_event_subscribed']))) { return false; } $notification_controller = Ai1ec_Notification_Controller::get_instance(); if ($notification_controller->check_if_notification_should_be_sent_for_event($event)) { return false; } return true; }