/** * Initializes the URL router used by our plugin. * * @wp_hook init * * @return void */ public function initialize_router() { /* @var $cal_state Ai1ec_Calendar_State */ $cal_state = $this->_registry->get('calendar.state'); $cal_state->set_routing_initialization(true); $settings = $this->_registry->get('model.settings'); $cal_page = $settings->get('calendar_page_id'); if (!$cal_page || $cal_page < 1) { // Routing may not be affected in any way if no calendar page exists. $cal_state->set_routing_initialization(false); return null; } $router = $this->_registry->get('routing.router'); $localization_helper = $this->_registry->get('p28n.wpml'); $page_base = ''; $clang = ''; if ($localization_helper->is_wpml_active()) { $trans = $localization_helper->get_wpml_translations_of_page($cal_page, true); $clang = $localization_helper->get_language(); if (isset($trans[$clang])) { $cal_page = $trans[$clang]; } } $template_link_helper = $this->_registry->get('template.link.helper'); if (!get_post($cal_page)) { $cal_state->set_routing_initialization(false); return null; } $page_base = $template_link_helper->get_page_link($cal_page); $page_base = Ai1ec_Wp_Uri_Helper::get_pagebase($page_base); $page_link = 'index.php?page_id=' . $cal_page; $pagebase_for_href = Ai1ec_Wp_Uri_Helper::get_pagebase_for_links(get_page_link($cal_page), $clang); // save the pagebase to set up the factory later $application = $this->_registry->get('bootstrap.registry.application'); $application->set('calendar_base_page', $pagebase_for_href); $option = $this->_registry->get('model.option'); // 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 ($option->get('permalink_structure') && (int) get_option('page_on_front') !== (int) $cal_page) { $application->set('permalinks_enabled', true); } $router->asset_base($page_base)->register_rewrite($page_link); $cal_state->set_routing_initialization(false); }
private function get_sendback_page($post_id) { $sendback = wp_get_referer(); $page_base = Ai1ec_Wp_Uri_Helper::get_pagebase($sendback); //$_SERVER['REQUEST_URI'] ); if ('post.php' === $page_base) { return get_edit_post_link($post_id, 'url'); } else { return admin_url('edit.php?post_type=ai1ec_event'); } }
/** * 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); }
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); }