/** * List of authors having authored at least one event * * Returned array contains following keys: user_id, display_name and * event_count, respectively referencing author ID, to use as filter * argument, his name, and number of events he had authored. * * @param bool $flush Set to true, to ignore cache [optional=false] * * @return array List of authors */ public function get_all($flush = false) { global $ai1ec_settings; if (!$ai1ec_settings->use_authors_filter) { return array(); } $persistance = Ai1ec_Strategies_Factory::create_persistence_context(__METHOD__); $list = NULL; if (false === $flush) { try { $list = $persistance->get_data_from_persistence(); } catch (Ai1ec_Cache_Not_Set_Exception $exception) { $list = NULL; } } if (NULL === $list) { $list = $this->_fetch_all(); try { $persistance->write_data_to_persistence($list); } catch (Ai1ec_Cache_Not_Set_Exception $wrt_exception) { // ignore write failures } } return $list; }
/** * In the constructor all action and filter hooks are declared as the constructor is called when the app initialize. We als handle the CROn and the DB Schema. * */ public function __construct() { // We don't use the filesystem as cache as this contains private data. $this->persistance_context = Ai1ec_Strategies_Factory::create_persistence_context(self::KEY_FOR_PERSISTANCE); // Set the AJAX action to dismiss the notice. add_action('wp_ajax_ai1ec_facebook_cron_dismiss', array($this, 'dismiss_notice_ajax')); // Set the AJAX action to refresh Facebook Graph Objects add_action('wp_ajax_ai1ec_refresh_facebook_objects', array($this, 'refresh_facebook_ajax')); // Set AJAX action to remove a subscribed user add_action('wp_ajax_ai1ec_remove_subscribed', array($this, 'remove_subscribed_ajax')); // Set AJAX action to refresh multiselect add_action('wp_ajax_ai1ec_refresh_multiselect', array($this, 'refresh_multiselect')); // Set AJAX action to refresh events add_action('wp_ajax_ai1ec_refresh_events', array($this, 'refresh_events_ajax')); // Add the "Export to facebook" widget. add_action('post_submitbox_misc_actions', array($this, 'render_export_box')); // Ad action to check if app-id / secret where changed add_action('ai1ec-Ai1ecFacebookConnectorPlugin-postsave-setting', array($this, 'if_app_id_or_secret_changed_perform_logout'), 10, 1); // Add action to perform a login to Facebook if needed add_action('ai1ec-post-save-facebook-login', array($this, 'do_facebook_login_if_app_id_and_secret_were_changed')); //allow redirection, even if my theme starts to send output to the browser add_action('init', array($this, 'start_output_buffering')); // I leave all add_action() call in one place since it's easier to understand and mantain $facebook_custom_bulk_action = Ai1ec_Facebook_Factory::get_facebook_custom_bulk_action_instance($this); // Add the select to filter events in the "All events" page add_action('restrict_manage_posts', array($facebook_custom_bulk_action, 'facebook_filter_restrict_manage_posts')); // Add action to handle export to facebook add_action('load-edit.php', array($facebook_custom_bulk_action, 'facebook_custom_bulk_action')); // Add action to filter data add_filter('posts_where', array($facebook_custom_bulk_action, 'facebook_filter_posts_where')); // Install db $this->install_schema(); // Install CRON $this->install_cron(); }
/** * Clean entire cache - get rid of all events cache entries * * @return int Count of cache entries deleted */ protected function _purge() { // purge entire cache $pattern = 'ai1ec-response'; $cache = Ai1ec_Strategies_Factory::create_blob_persistence_context($pattern, AI1EC_CACHE_PATH); return $cache->delete_matching_entries_from_persistence($pattern); }
/** * @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_Admin_Notices_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; }
/** * Returns rendered calendar page. * * @return string Rendered calendar page */ public function get_calendar_page(Ai1ec_Abstract_Query $request) { global $ai1ec_view_helper, $ai1ec_settings, $ai1ec_events_helper, $ai1ec_themes_controller; $ai1ec_calendar_helper = Ai1ec_Calendar_Helper::get_instance(); if ($notice = $ai1ec_themes_controller->frontend_outdated_themes_notice(false)) { return $notice; } // Queue any styles, scripts $this->load_css(); // Are we loading a shortcode? $shortcode = $request->get('shortcode'); $view_args = $this->get_view_args_for_view($request); $action = $view_args['action']; $type = $request->get('request_type'); $exact_date = $this->get_exact_date($request); $get_view = 'get_' . $action . '_view'; $page_hash = $this->get_cache_key($request); $cache = NULL; if (false !== $page_hash) { $cache = Ai1ec_Strategies_Factory::create_blob_persistence_context($page_hash, AI1EC_CACHE_PATH); } $generated = false; if (false !== $page_hash) { try { $generated = $cache->get_data_from_persistence(); } catch (Ai1ec_Cache_Not_Set_Exception $excpt) { // discard $generated = false; } } if (false === $generated) { $view = $this->{$get_view}($view_args); $content = ''; $categories = ''; $tags = ''; $authors = ''; $args_for_filter = array(); if (true === $ai1ec_settings->use_select2_widgets) { $categories = Ai1ec_View_Factory::create_select2_multiselect(array('name' => 'ai1ec_filter_categories', 'id' => 'ai1ec_filter_categories', 'use_id' => true, 'placeholder' => __('Filter by category', AI1EC_PLUGIN_NAME), 'type' => 'category'), get_terms('events_categories'), $view_args); $categories = $categories->render_as_html(); $tags = Ai1ec_View_Factory::create_select2_multiselect(array('name' => 'ai1ec_filter_tags', 'id' => 'ai1ec_filter_tags', 'use_id' => true, 'placeholder' => __('Filter by tag', AI1EC_PLUGIN_NAME), 'type' => 'tag'), get_terms('events_tags'), $view_args); $tags = $tags->render_as_html(); $authors = Ai1ec_Author::get_instance()->get_all_for_select2(); $authors = Ai1ec_View_Factory::create_select2_multiselect(array('name' => 'ai1ec_filter_authors', 'id' => 'ai1ec_filter_authors', 'use_id' => true, 'placeholder' => __('Filter by author', AI1EC_PLUGIN_NAME), 'type' => 'author'), $authors, $view_args); $authors = $authors->render_as_html(); } else { $categories = $ai1ec_calendar_helper->get_html_for_categories($view_args); $authors = $ai1ec_calendar_helper->get_html_for_authors($view_args); $tags = $ai1ec_calendar_helper->get_html_for_tags($view_args); } $dropdown_args = $view_args; if (isset($dropdown_args['time_limit']) && false !== $exact_date) { $dropdown_args['exact_date'] = $exact_date; } $views_dropdown = $ai1ec_calendar_helper->get_html_for_views_dropdown($dropdown_args); $subscribe_buttons = ''; if (!$ai1ec_settings->turn_off_subscription_buttons) { $subscribe_buttons = $ai1ec_calendar_helper->get_html_for_subscribe_buttons($view_args); } $save_view_btngroup = Ai1ec_View_Factory::create_save_filtered_view_buttongroup($view_args, $shortcode); if (($view_args['no_navigation'] || $type !== 'standard') && 'true' !== $shortcode) { $args_for_filter = $view_args; $are_filters_set = Ai1ec_Router::is_at_least_one_filter_set_in_request($view_args); // send data both for json and jsonp as shortcodes are jsonp $content = array('html' => $view, 'categories' => $categories, 'authors' => $authors, 'tags' => $tags, 'views_dropdown' => $views_dropdown, 'subscribe_buttons' => $subscribe_buttons, 'save_view_btngroup' => $save_view_btngroup->render_as_html(), 'are_filters_set' => $are_filters_set); } else { // Determine whether to display "Post your event" button on front-end. $contribution_buttons = $ai1ec_calendar_helper->get_html_for_contribution_buttons(); $show_dropdowns = true; $show_select2 = false; $span_for_select2 = ''; // if we use select2, calculate the span settings if (true === $ai1ec_settings->use_select2_widgets) { $show_dropdowns = false; $show_select2 = true; $count = 0; if (!empty($categories)) { $count += 1; } if (!empty($authors)) { $count += 1; } if (!empty($tags)) { $count += 1; } if (0 === $count) { $show_select2 = false; } else { $span_for_select2 = 'span' . 12 / $count; } } // Define new arguments for overall calendar view $page_args = array('current_view' => $action, 'views_dropdown' => $views_dropdown, 'view' => $view, 'contribution_buttons' => $contribution_buttons, 'categories' => $categories, 'authors' => $authors, 'tags' => $tags, 'subscribe_buttons' => $subscribe_buttons, 'data_type' => $view_args['data_type'], 'save_view_btngroup' => $save_view_btngroup, 'disable_standard_filter_menu' => $ai1ec_settings->disable_standard_filter_menu, 'show_dropdowns' => $show_dropdowns, 'show_select2' => $show_select2, 'span_for_select2' => $span_for_select2); $filter_menu = Ai1ec_Render_Entity_Utility::get_instance('Filter_Menu')->set($page_args); $page_args['filter_menu'] = $filter_menu; $content = $ai1ec_view_helper->get_theme_view('calendar.php', $page_args); $args_for_filter = $page_args; } $generated = apply_filters('ai1ec_view', $content, $args_for_filter); if ($page_hash) { try { $cache->write_data_to_persistence($generated); } catch (Ai1ec_Cache_Not_Set_Exception $exception) { // ignore write failures } } } return $generated; }