/**
  * 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);
 }
 /**
  * @return Ai1ec_Generic_Html_Tag
  */
 public static function create_save_filtered_view_buttongroup(array $view_args, $shortcode)
 {
     $btn_group = Ai1ec_Helper_Factory::create_generic_html_tag('div');
     $btn_group->add_class('btn-group');
     $btn = Ai1ec_Helper_Factory::create_bootstrap_button_instance();
     $btn->add_class('btn-mini ai1ec-tooltip-trigger');
     $btn->set_id('save_filtered_views');
     $icon = Ai1ec_Helper_Factory::create_generic_html_tag('icon');
     $icon->add_class('icon-pushpin');
     $btn->add_renderable_children($icon);
     $ai1ec_router = Ai1ec_Router::instance();
     $cookie_dto = $ai1ec_router->get_cookie_set_dto();
     $cookie_set = $cookie_dto->get_is_a_cookie_set_for_this_page();
     // if there are no filter set, but the cookie is set i need to show the button so that the cookie can be removed
     if (false === Ai1ec_Router::is_at_least_one_filter_set_in_request($view_args) && !$cookie_set) {
         $btn->add_class('hide');
     }
     $cookie = false;
     if (true === $cookie_set) {
         $cookie = 'true' === $shortcode ? $cookie_dto->get_shortcode_cookie() : $cookie_dto->get_calendar_cookie();
     }
     // If we have a cookie and the filters are in the same state of the cookie, show the remove version
     // Saving the same state again would not make sense
     // if we have a cookie and no filters are set, show the remove button, the user can't save the
     // standard calendar view
     if ($cookie_set && (self::check_if_saved_cookie_and_requested_page_match($view_args, $cookie) || false === Ai1ec_Router::is_at_least_one_filter_set_in_request($view_args))) {
         $btn->add_class('active');
         $text = __("Remove default filter", AI1EC_PLUGIN_NAME);
     } else {
         $text = __("Save this filter as default", AI1EC_PLUGIN_NAME);
     }
     // Add a span to hold text
     $btn->set_attribute('title', $text);
     $btn_group->add_renderable_children($btn);
     return $btn_group;
 }
 /**
  * _get_view_and_restore_globals method
  *
  * Set global request ($_REQUEST) variables, call rendering routines
  * and reset $_REQUEST afterwards.
  *
  * @uses do_action				To launch
  *	'ai1ec_load_frontend_js' action
  *
  * @param array $arguments Arguments to set for rendering
  *
  * @return string Rendered view
  */
 protected function _get_view_and_restore_globals($arguments)
 {
     global $ai1ec_calendar_controller, $ai1ec_app_controller, $ai1ec_settings;
     $ai1ec_router = Ai1ec_Router::instance();
     $cookie_dto = $ai1ec_router->get_cookie_set_dto();
     if (true === $cookie_dto->get_is_cookie_set_for_shortcode()) {
         $cookie = $cookie_dto->get_shortcode_cookie();
         $cookie_for_shortcode = array();
         foreach (Ai1ec_Cookie_Utility::$types as $type) {
             $cookie_for_shortcode[$type] = implode(',', $cookie[$type]);
         }
         // in the cookie i save an array with action. tag_ids and cat_ids.
         // if something is saved, we use that
         $arguments = $cookie_for_shortcode + $arguments;
     }
     $request = Ai1ec_Routing_Factory::create_argument_parser_instance($arguments);
     $page_content = $ai1ec_calendar_controller->get_calendar_page($request);
     // Load requirejs for the calendar
     do_action('ai1ec_load_frontend_js', true, true);
     return $page_content;
 }
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);
}