public function init() { parent::init(); try { $this->_locale = Zend_Registry::get('Zend_Locale'); } catch (Exception $e) { $this->_locale = new Zend_Locale('en'); Zend_Registry::set('Zend_Locale', $this->_locale); } $this->view->locale = $this->_locale; $this->_translate = $this->initTranslation(); $this->view->setScriptPath(array_merge($this->view->getScriptPaths(), array(PIMCORE_WEBSITE_PATH . '/views/scripts/', PIMCORE_WEBSITE_PATH . '/views/layouts/', PIMCORE_WEBSITE_PATH . '/views/scripts/blog/'))); // additional helpers $this->_helper->addPrefix('Modern_Controller_Action_Helper'); $this->view->addHelperPath('Modern/View/Helper', 'Modern_View_Helper_'); $this->_messenger = $this->_helper->getHelper('FlashMessenger'); Modern_View_Helper_FlashMessenger::setPartial('partial/messenger.php'); Zend_View_Helper_PaginationControl::setDefaultViewPartial('partial/paginator-search.php'); // fix main blog list pagination if (!Staticroute::getCurrentRoute() instanceof Staticroute) { Staticroute::setCurrentRoute(Staticroute::getByName('blog')); } }
/** * @param $path * @param bool $partial * @return array|bool */ public function match($path, $partial = false) { $matchFound = false; $config = Pimcore_Config::getSystemConfig(); $routeingDefaults = Pimcore_Tool::getRoutingDefaults(); $params = array_merge($_GET, $_POST); $params = array_merge($routeingDefaults, $params); // set the original path $originalPath = $path; // check for a registered site try { if ($config->general->domain != $_SERVER["HTTP_HOST"]) { $domain = $_SERVER["HTTP_HOST"]; $site = Site::getByDomain($domain); $site->setRootPath($site->getRootDocument()->getFullPath()); $path = $site->getRootDocument()->getFullPath() . $path; Zend_Registry::set("pimcore_site", $site); } } catch (Exception $e) { } // check for direct definition of controller/action if (!empty($_REQUEST["controller"]) && !empty($_REQUEST["action"])) { $matchFound = true; //$params["document"] = $this->getNearestDocumentByPath($path); } // you can also call a page by it's ID /?pimcore_document=XXXX if (!$matchFound) { if (!empty($params["pimcore_document"]) || !empty($params["pdid"])) { $doc = Document::getById($params["pimcore_document"] ? $params["pimcore_document"] : $params["pdid"]); if ($doc instanceof Document) { $path = $doc->getFullPath(); } } } // test if there is a suitable redirect with override = all (=> priority = 99) if (!$matchFound) { $this->checkForRedirect(true); } // test if there is a suitable page if (!$matchFound) { try { $document = Document::getByPath($path); // check for a parent hardlink with childs if (!$document instanceof Document) { $hardlinkedParentDocument = $this->getNearestDocumentByPath($path, true); if ($hardlinkedParentDocument instanceof Document_Hardlink) { if ($hardLinkedDocument = Document_Hardlink_Service::getChildByPath($hardlinkedParentDocument, $path)) { $document = $hardLinkedDocument; } } } // check for direct hardlink if ($document instanceof Document_Hardlink) { $hardlinkParentDocument = $document; $document = Document_Hardlink_Service::wrap($hardlinkParentDocument); } if ($document instanceof Document) { if (in_array($document->getType(), array("page", "snippet", "email"))) { if (!empty($params["pimcore_version"]) || !empty($params["pimcore_preview"]) || !empty($params["pimcore_admin"]) || !empty($params["pimcore_editmode"]) || $document->isPublished() || !empty($_COOKIE["pimcore_admin_sid"])) { $params["document"] = $document; if ($controller = $document->getController()) { $params["controller"] = $controller; $params["action"] = "index"; } if ($action = $document->getAction()) { $params["action"] = $action; } if ($module = $document->getModule()) { $params["module"] = $module; } // check for a trailing slash in path, if exists, redirect to this page without the slash // the only reason for this is: SEO, Analytics, ... there is no system specific reason, pimcore would work also with a trailing slash without problems // use $originalPath because of the sites if ($config->documents->allowtrailingslash) { if ($config->documents->allowtrailingslash == "no") { if (substr($originalPath, strlen($originalPath) - 1, 1) == "/" && $originalPath != "/") { $redirectUrl = rtrim($originalPath, "/"); if ($_SERVER["QUERY_STRING"]) { $redirectUrl .= "?" . $_SERVER["QUERY_STRING"]; } header("Location: " . $redirectUrl, true, 301); exit; } } } if ($config->documents->allowcapitals) { if ($config->documents->allowcapitals == "no") { if (strtolower($originalPath) != $originalPath) { $redirectUrl = strtolower($originalPath); if ($_SERVER["QUERY_STRING"]) { $redirectUrl .= "?" . $_SERVER["QUERY_STRING"]; } header("Location: " . $redirectUrl, true, 301); exit; } } } $matchFound = true; } } else { if ($document->getType() == "link") { // if the document is a link just redirect to the location/href of the link header("Location: " . $document->getHref(), true, 301); exit; } } } } catch (Exception $e) { // no suitable page found } } // test if there is a suitable static route if (!$matchFound) { try { $cacheKey = "system_route_staticroute"; if (!($routes = Pimcore_Model_Cache::load($cacheKey))) { $list = new Staticroute_List(); $list->setOrderKey("priority"); $list->setOrder("DESC"); $routes = $list->load(); Pimcore_Model_Cache::save($routes, $cacheKey, array("system", "staticroute", "route"), null, 998); } foreach ($routes as $route) { if (@preg_match($route->getPattern(), $originalPath) && !$matchFound) { $params = array_merge($route->getDefaultsArray(), $params); $variables = explode(",", $route->getVariables()); preg_match_all($route->getPattern(), $originalPath, $matches); if (is_array($matches) && count($matches) > 1) { foreach ($matches as $index => $match) { if ($variables[$index - 1]) { $params[$variables[$index - 1]] = $match[0]; } } } $controller = $route->getController(); $action = $route->getAction(); $module = trim($route->getModule()); // check for dynamic controller / action / module $dynamicRouteReplace = function ($item, $params) { if (strpos($item, "%") !== false) { foreach ($params as $key => $value) { $dynKey = "%" . $key; if (strpos($item, $dynKey) !== false) { return str_replace($dynKey, $value, $item); } } } return $item; }; $controller = $dynamicRouteReplace($controller, $params); $action = $dynamicRouteReplace($action, $params); $module = $dynamicRouteReplace($module, $params); $params["controller"] = $controller; $params["action"] = $action; if (!empty($module)) { $params["module"] = $module; } // try to get nearest document to the route $params["document"] = $this->getNearestDocumentByPath($path); $matchFound = true; Staticroute::setCurrentRoute($route); break; } } } catch (Exception $e) { // no suitable route found } } // test if there is a suitable redirect if (!$matchFound) { $this->checkForRedirect(false); } if (!$matchFound && $site instanceof Site) { if ($config->general->domain) { header("Location: http://" . $_SERVER["HTTP_HOST"], true, 301); } else { $errorMessage = "You have to specify a main domain in system-settings (Settings -> System -> Website -> Domain) if you want to use sites!"; Logger::emerg($errorMessage); die($errorMessage); } exit; } if (!$matchFound) { return false; } // remove pimcore magic parameters unset($params["pimcore_outputfilters_disabled"]); unset($params["pimcore_document"]); unset($params["nocache"]); return $params; }