Exemple #1
0
 public static function doExport()
 {
     self::$exportFile = self::getExportFilePath();
     $routeList = new Staticroute_List();
     $routeList->load();
     $routesCollection = $routeList->getRoutes();
     self::openExportFile();
     array_walk($routesCollection, 'PimPon_Routes_Export::exportRoute');
     self::closeExportFile();
     return self::$exportFile;
 }
 public function staticroutesAction()
 {
     if ($this->_getParam("data")) {
         if ($this->getUser()->isAllowed("routes")) {
             if ($this->_getParam("xaction") == "destroy") {
                 $id = Zend_Json::decode($this->_getParam("data"));
                 $route = Staticroute::getById($id);
                 $route->delete();
                 $this->_helper->json(array("success" => true, "data" => array()));
             } else {
                 if ($this->_getParam("xaction") == "update") {
                     $data = Zend_Json::decode($this->_getParam("data"));
                     // save routes
                     $route = Staticroute::getById($data["id"]);
                     $route->setValues($data);
                     $route->save();
                     $this->_helper->json(array("data" => $route, "success" => true));
                 } else {
                     if ($this->_getParam("xaction") == "create") {
                         $data = Zend_Json::decode($this->_getParam("data"));
                         unset($data["id"]);
                         // save route
                         $route = new Staticroute();
                         $route->setValues($data);
                         $route->save();
                         $this->_helper->json(array("data" => $route, "success" => true));
                     }
                 }
             }
         } else {
             Logger::err("user [" . $this->getUser()->getId() . "] attempted to modify static routes, but has no permission to do so.");
         }
     } else {
         // get list of routes
         $list = new Staticroute_List();
         $list->setLimit($this->_getParam("limit"));
         $list->setOffset($this->_getParam("start"));
         if ($this->_getParam("sort")) {
             $list->setOrderKey($this->_getParam("sort"));
             $list->setOrder($this->_getParam("dir"));
         }
         if ($this->_getParam("filter")) {
             $list->setCondition("`name` LIKE " . $list->quote("%" . $this->_getParam("filter") . "%") . " OR `pattern` LIKE " . $list->quote("%" . $this->_getParam("filter") . "%") . " OR `reverse` LIKE " . $list->quote("%" . $this->_getParam("filter") . "%") . " OR `controller` LIKE " . $list->quote("%" . $this->_getParam("filter") . "%") . " OR `action` LIKE " . $list->quote("%" . $this->_getParam("filter") . "%"));
         }
         $list->load();
         $routes = array();
         foreach ($list->getRoutes() as $route) {
             $routes[] = $route;
         }
         $this->_helper->json(array("data" => $routes, "success" => true, "total" => $list->getTotalCount()));
     }
     $this->_helper->json(false);
 }
Exemple #3
0
 /**
  * @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;
 }