/**
  *
  * @see Ai1ec_Connector_Plugin::render_tab_content()
  *
  */
 public function render_tab_content()
 {
     global $ai1ec_view_helper;
     $this->render_opening_div_of_tab();
     $file_input = Ai1ec_Helper_Factory::create_input_instance();
     $file_input->set_type('file');
     $file_input->set_id(self::NAME_OF_FILE_INPUT);
     $file_input->set_name(self::NAME_OF_FILE_INPUT);
     $submit = Ai1ec_Helper_Factory::create_input_instance();
     $submit->set_type('submit');
     $submit->add_class('button-primary');
     $submit->set_name(self::NAME_OF_SUBMIT);
     $submit->set_id(self::NAME_OF_SUBMIT);
     $submit->set_value(__('Submit Events', AI1EC_PLUGIN_NAME));
     $textarea = Ai1ec_Helper_Factory::create_generic_html_tag('textarea');
     $textarea->set_attribute('name', self::NAME_OF_TEXTAREA);
     $textarea->set_attribute('rows', 6);
     $textarea->set_id(self::NAME_OF_TEXTAREA);
     $facebook_tab = Ai1ec_Facebook_Factory::get_facebook_tab_instance();
     $category_select = Ai1ec_View_Factory::create_select2_multiselect(array('name' => 'ai1ec_file_upload_feed_category[]', 'id' => 'ai1ec_file_upload_feed_category', 'use_id' => true, 'type' => 'category', 'placeholder' => __('Categories (optional)', AI1EC_PLUGIN_NAME)), get_terms('events_categories', array('hide_empty' => false)));
     $select2_tags = Ai1ec_View_Factory::create_select2_tags(array('id' => 'ai1ec_file_upload_feed_tags'));
     $message = false;
     if (isset($this->count)) {
         $text = __('No events were found', AI1EC_PLUGIN_NAME);
         if ($this->count > 0) {
             $text = sprintf(_n('Imported %s event', 'Imported %s events', $this->count, AI1EC_PLUGIN_NAME), $this->count);
         }
         $message = Ai1ec_Helper_Factory::create_bootstrap_message_instance($text);
     }
     $args = array("category_select" => $category_select, "tags" => $select2_tags, "submit" => $submit, "file_input" => $file_input, "textarea" => $textarea);
     if (false !== $message) {
         $args['message'] = $message;
     }
     $ai1ec_view_helper->display_admin('plugins/file_upload/file_upload.php', $args);
     $this->render_closing_div_of_tab();
 }
 /**
  * Returns a link to a calendar page without the given arguments; does not
  * otherwise disturb current page state.
  *
  * @param array $args           Current arguments to the calendar
  * @param array $args_to_remove Names of arguments to remove from current args
  *
  * @return string
  */
 private function generate_href_without_arguments(array $args, array $args_to_remove)
 {
     $args_to_remove = array_flip($args_to_remove);
     $args = array_diff_key($args, $args_to_remove);
     $href = Ai1ec_View_Factory::create_href_helper_instance($args);
     return $href->generate_href();
 }
 /**
  * @param string $page
  */
 public static function set_page($page)
 {
     Ai1ec_View_Factory::$page = $page;
 }
    /**
     * Renders the HTML for the Multiselect of the specified types
     *
     * @param array $types The type of Facebook Graph Object to render
     *
     * @param $current_id The id of the currently logged on user which must be excluded from subscribers and multiselects
     *
     * @return the HTML
     */
    private function render_multiselects(array $types, $current_id)
    {
        $multiselects = $this->render_all_elements($types, TRUE, $current_id);
        $category_select = Ai1ec_View_Factory::create_select2_multiselect(array('id' => 'ai1ec_facebook_feed_category', 'name' => 'ai1ec_facebook_feed_category[]', 'use_id' => true, 'type' => 'category', 'placeholder' => __('Categories (optional)', AI1EC_PLUGIN_NAME), 'class' => 'categories'), get_terms('events_categories', array('hide_empty' => false)));
        $tags = Ai1ec_View_Factory::create_select2_tags(array('id' => 'ai1ec_facebook_feed_tags'));
        $label_category = esc_html__('Event category', AI1EC_PLUGIN_NAME);
        $label_tag = esc_html__('Tag with', AI1EC_PLUGIN_NAME);
        $label_refresh = esc_html__('Refresh list', AI1EC_PLUGIN_NAME);
        $html = '<h1>' . esc_html__('Subscribe to more events', AI1EC_PLUGIN_NAME) . '</h1>';
        $html .= '<p>';
        $html .= esc_html__("You can subscribe to the shared calendars of friends, pages, and groups you are connected with. Select those calendars you're interested in below.", AI1EC_PLUGIN_NAME);
        $html .= '</p>';
        $html .= '<div class="row-fluid">';
        foreach ($types as $type) {
            // Get the correct text for the type.
            $text = Ai1ec_Facebook_Graph_Object_Collection::get_type_printable_text($type);
            $html .= <<<HTML
<div class="span4 ai1ec-facebook-multiselect-container" data-type="{$type}">
\t<div class="ai1ec-facebook-multiselect-title-wrapper">
\t\t<h2 class="ai1ec-facebook-header pull-left">{$text}</h2>
\t\t<a class="ai1ec-facebook-refresh-multiselect btn btn-small">
\t\t\t<i class="icon-refresh">
\t\t\t</i>
\t\t\t{$label_refresh}
\t\t</a>
\t\t<img src="images/wpspin_light.gif" class="ajax-loading pull-right" alt="" />
\t</div>
\t<div class="clear"></div>
\t{$multiselects[$type]}
</div>
HTML;
        }
        $html .= "</div>";
        $submit_subscribe_value = __('Subscribe to selected', AI1EC_PLUGIN_NAME);
        $comments_label = __('Allow comments on imported events', AI1EC_PLUGIN_NAME);
        $map_display_label = __('Show map on imported events', AI1EC_PLUGIN_NAME);
        $category_html = $category_select->render_as_html();
        $tags_html = $tags->render_as_html();
        $html .= <<<HTML
<div class="row-fluid ai1ec_submit_wrapper">
\t<div class="span6">
\t\t{$category_html}
\t</div>
\t<div class="span6">
\t\t{$tags_html}
\t</div>
</div>
<div class="row-fluid ai1ec_facebook_comments_enabled_wrapper">
\t<label for="ai1ec_facebook_comments_enabled">
\t\t<input type="checkbox" name="ai1ec_facebook_comments_enabled"
\t\t       id="ai1ec_facebook_comments_enabled" value="1" />
\t\t{$comments_label}
\t</label>
</div>
<div class="row-fluid ai1ec_facebook_map_display_enabled_wrapper">
\t<label for="ai1ec_facebook_map_display_enabled">
\t\t<input type="checkbox" name="ai1ec_facebook_map_display_enabled"
\t\t       id="ai1ec_facebook_map_display_enabled" value="1" />
\t\t{$map_display_label}
\t</label>
</div>
<div class="row-fluid ai1ec_submit_wrapper">
\t<div class="span12">
\t\t<button type="submit" id="ai1ec_subscribe_users" class="btn btn-primary"
\t\t\tname="ai1ec_subscribe_users">
\t\t\t<i class="icon-plus"></i> {$submit_subscribe_value}
\t\t</button>
\t</div>
</div>
HTML;
        return $html;
    }
    /**
     * Generate the html for the "Back to calendar" button for this event.
     *
     * @return string
     */
    public function get_back_to_calendar_button_html()
    {
        global $ai1ec_calendar_controller;
        $class = '';
        $data_type = "";
        $href = Ai1ec_View_Factory::create_href_helper_instance(array());
        $text = __('Back to Calendar', AI1EC_PLUGIN_NAME);
        if (isset($this->request)) {
            $data_type = "data-type='jsonp'";
            $class = "ai1ec-load-view";
            $view_args = $ai1ec_calendar_controller->get_view_args_for_view($this->request);
            $href = Ai1ec_View_Factory::create_href_helper_instance($view_args);
        }
        $href = $href->generate_href();
        $html = <<<HTML
<a class="ai1ec-calendar-link btn btn-small pull-right {$class}"
\t href="{$href}"
\t {$data_type}>
\t<i class="icon-arrow-left"></i> {$text}
</a>
HTML;
        return apply_filters('ai1ec_get_back_to_calendar_html', $html, $href);
    }
 /**
  * Initializes the URL router used by our plugin.
  *
  * @return void Method is not intended to return anything
  */
 public function initialize_router()
 {
     global $ai1ec_settings, $ai1ec_router, $ai1ec_localization_helper;
     if (!isset($ai1ec_settings->calendar_page_id) || $ai1ec_settings->calendar_page_id < 1) {
         // Routing may not be affected in any way if no calendar page exists.
         return NULL;
     }
     $ai1ec_router = Ai1ec_Router::instance();
     $page_base = '';
     $clang = '';
     if ($ai1ec_localization_helper->is_wpml_active()) {
         $trans = $ai1ec_localization_helper->get_wpml_translations_of_page($ai1ec_settings->calendar_page_id, true);
         $clang = $ai1ec_localization_helper->get_language();
         if (isset($trans[$clang])) {
             $ai1ec_settings->calendar_page_id = $trans[$clang];
         }
     }
     $page_base = get_page_link($ai1ec_settings->calendar_page_id);
     $page_base = Ai1ec_Wp_Uri_Helper::get_pagebase($page_base);
     $page_link = 'index.php?page_id=' . $ai1ec_settings->calendar_page_id;
     $pagebase_for_href = Ai1ec_Wp_Uri_Helper::get_pagebase_for_links(get_page_link($ai1ec_settings->calendar_page_id), $clang);
     // Add a trailing slash if it is missing and we are using permalinks.
     if (Ai1ec_Meta::get_option('permalink_structure')) {
         $pagebase_for_href = trailingslashit($pagebase_for_href);
     }
     // Set up the view factory.
     Ai1ec_View_Factory::set_page($pagebase_for_href);
     // If the calendar is set as the front page, disable permalinks.
     // They would not be legal under a Windows server. See:
     // https://issues.apache.org/bugzilla/show_bug.cgi?id=41441
     if (Ai1ec_Meta::get_option('permalink_structure') && (int) get_option('page_on_front') !== (int) $ai1ec_settings->calendar_page_id) {
         Ai1ec_View_Factory::set_pretty_permalinks_enabled(true);
     }
     // If we are requesting the calendar page and we have a saved cookie,
     // redirect the user. Do not redirect if the user saved the home page,
     // otherwise we enter a loop.
     $cookie_dto = $ai1ec_router->get_cookie_set_dto();
     if (true === $cookie_dto->get_is_cookie_set_for_calendar_page()) {
         $cookie = $cookie_dto->get_calendar_cookie();
         $href = Ai1ec_View_Factory::create_href_helper_instance($cookie);
         // wp_redirect sanitizes the url which strips out the |
         header('Location: ' . $href->generate_href(), true, '302');
         exit(0);
     }
     // We need to reset the cookie, it's to early for the is_page() call
     $ai1ec_router->set_cookie_set_dto();
     // Initialize SEO helper.
     Ai1ec_Seo_Helper::get_instance();
     $ai1ec_router = Ai1ec_Router::instance()->asset_base($page_base)->register_rewrite($page_link);
 }
 /**
  * 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;
 }
 /**
  * (non-PHPdoc)
  * @see Ai1ec_Connector_Plugin::render_tab_content()
  */
 public function render_tab_content()
 {
     // Render the opening div
     $this->render_opening_div_of_tab();
     // Render the body of the tab
     global $ai1ec_view_helper, $ai1ec_settings_helper, $ai1ec_settings;
     $select2_cats = Ai1ec_View_Factory::create_select2_multiselect(array('name' => 'ai1ec_feed_category[]', 'id' => 'ai1ec_feed_category', 'use_id' => true, 'type' => 'category', 'placeholder' => __('Categories (optional)', AI1EC_PLUGIN_NAME)), get_terms('events_categories', array('hide_empty' => false)));
     $select2_tags = Ai1ec_View_Factory::create_select2_tags(array('id' => 'ai1ec_feed_tags'));
     $modal = Ai1ec_Helper_Factory::create_bootstrap_modal_instance(esc_html__("Do you want to keep the events imported from the calendar or remove them?", AI1EC_PLUGIN_NAME));
     $modal->set_header_text(esc_html__("Removing ICS Feed", AI1EC_PLUGIN_NAME));
     $modal->set_keep_button_text(esc_html__("Keep Events", AI1EC_PLUGIN_NAME));
     $modal->set_delete_button_text(esc_html__("Remove Events", AI1EC_PLUGIN_NAME));
     $modal->set_id('ai1ec-ics-modal');
     $args = array('cron_freq' => $ai1ec_settings_helper->get_cron_freq_dropdown($ai1ec_settings->cron_freq), 'event_categories' => $select2_cats, 'event_tags' => $select2_tags, 'feed_rows' => $ai1ec_settings_helper->get_feed_rows(), 'modal' => $modal);
     $ai1ec_view_helper->display_admin('plugins/ics/display_feeds.php', $args);
     $this->render_closing_div_of_tab();
 }
function ai1ec_initialize_router()
{
    global $ai1ec_settings, $ai1ec_router, $ai1ec_localization_helper;
    $page_base = '';
    $clang = '';
    if ($ai1ec_settings->calendar_page_id > 0) {
        if ($ai1ec_localization_helper->is_wpml_active()) {
            $trans = $ai1ec_localization_helper->get_wpml_translations_of_page($ai1ec_settings->calendar_page_id, true);
            $clang = $ai1ec_localization_helper->get_language();
            if (isset($trans[$clang])) {
                $ai1ec_settings->calendar_page_id = $trans[$clang];
            }
        }
        $page_base = get_page_link($ai1ec_settings->calendar_page_id);
    }
    $page_base = Ai1ec_Wp_Uri_Helper::get_pagebase($page_base);
    $page_link = 'index.php?page_id=' . $ai1ec_settings->calendar_page_id;
    $pagebase_for_href = Ai1ec_Wp_Uri_Helper::get_pagebase_for_links(get_page_link($ai1ec_settings->calendar_page_id), $clang);
    // add a trailing slash if it's missing and we are using permalinks
    if (get_option('permalink_structure')) {
        $pagebase_for_href = trailingslashit($pagebase_for_href);
    }
    // Set up the view factory
    Ai1ec_View_Factory::set_page($pagebase_for_href);
    // if the calendar is set as the front page, disable permalinks.
    // They would not be legal under windows
    // https://issues.apache.org/bugzilla/show_bug.cgi?id=41441
    if (get_option('permalink_structure') && (int) get_option('page_on_front') !== (int) $ai1ec_settings->calendar_page_id) {
        Ai1ec_View_Factory::set_pretty_permalinks_enabled(true);
    }
    $ai1ec_router = Ai1ec_Router::instance()->asset_base($page_base)->register_rewrite($page_link);
}