/** * @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 != Pimcore_Tool::getHostname()) { $domain = Pimcore_Tool::getHostname(); $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()) { // check for a pretty url, and if the document is called by that, otherwise redirect to pretty url if ($document instanceof Document_Page && $document->getPrettyUrl() && empty($params["pimcore_preview"]) && empty($params["pimcore_editmode"])) { if (rtrim($document->getPrettyUrl(), " /") != rtrim($path, "/")) { header("Location: " . $document->getPrettyUrl(), true, 301); exit; } } $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 // only do redirecting with GET requests if (strtolower($_SERVER["REQUEST_METHOD"]) == "get") { 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]] = urldecode($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 $document = $this->getNearestDocumentByPath($path, false, array("page", "snippet", "hardlink")); if ($document instanceof Document_Hardlink) { $document = Document_Hardlink_Service::wrap($document); } $params["document"] = $document; $matchFound = true; Staticroute::setCurrentRoute($route); // add the route object also as parameter to the request object, this is needed in // Pimcore_Controller_Action_Frontend::getRenderScript() // to determine if a call to an action was made through a staticroute or not // more on that infos see Pimcore_Controller_Action_Frontend::getRenderScript() $params["staticroute"] = $route; break; } } } catch (Exception $e) { // no suitable route found } } // test if there is a suitable redirect if (!$matchFound) { $this->checkForRedirect(false); } if (!$matchFound) { return false; } // remove pimcore magic parameters unset($params["pimcore_outputfilters_disabled"]); unset($params["pimcore_document"]); unset($params["nocache"]); return $params; }
public function routeStartup(Zend_Controller_Request_Abstract $request) { $requestUri = $request->getRequestUri(); $excludePatterns = array(); // only enable GET method if (!$request->isGet()) { return $this->disable(); } try { $conf = Pimcore_Config::getSystemConfig(); if ($conf->cache) { $conf = $conf->cache; if (!$conf->enabled) { return $this->disable(); } if ($conf->lifetime) { $this->setLifetime((int) $conf->lifetime); } if ($conf->excludePatterns) { $confExcludePatterns = explode(",", $conf->excludePatterns); if (!empty($confExcludePatterns)) { $excludePatterns = $confExcludePatterns; } } if ($conf->excludeCookie) { $cookies = explode(",", strval($conf->excludeCookie)); foreach ($cookies as $cookie) { if (isset($_COOKIE[trim($cookie)])) { return $this->disable(); } } } } else { return $this->disable(); } } catch (Exception $e) { return $this->disable(); } foreach ($excludePatterns as $pattern) { if (preg_match($pattern, $requestUri)) { return $this->disable(); } } $appendKey = ""; // this is for example for the image-data-uri plugin if ($request->getParam("pimcore_cache_tag_suffix")) { $tags = $request->getParam("pimcore_cache_tag_suffix"); if (is_array($tags)) { $appendKey = "_" . implode("_", $tags); } } $this->cacheKey = "output_" . md5(Pimcore_Tool::getHostname() . $requestUri) . $appendKey; if ($cacheItem = Pimcore_Model_Cache::load($this->cacheKey, true)) { header("X-Pimcore-Cache-Tag: " . $this->cacheKey, true, 200); header("X-Pimcore-Cache-Date: " . $cacheItem["date"]); foreach ($cacheItem["rawHeaders"] as $header) { header($header); } foreach ($cacheItem["headers"] as $header) { header($header['name'] . ': ' . $header['value'], $header['replace']); } echo $cacheItem["content"]; exit; } }
public function abSaveAction() { // source-page $sourceDoc = Document::getById($this->_getParam("documentId")); $goalDoc = Document::getByPath($this->_getParam("conversionPage")); if (!$sourceDoc || !$goalDoc) { exit; } // clean properties $sourceDoc = $this->clearProperties($sourceDoc); $goalDoc = $this->clearProperties($goalDoc); // google stuff $credentials = $this->getAnalyticsCredentials(); $config = Pimcore_Google_Analytics::getSiteConfig($site); $gdata = $this->getService(); // create new experiment $entryResult = $gdata->insertEntry("\r\n <entry xmlns='http://www.w3.org/2005/Atom'\r\n xmlns:gwo='http://schemas.google.com/analytics/websiteoptimizer/2009'\r\n xmlns:app='http://www.w3.org/2007/app'\r\n xmlns:gd='http://schemas.google.com/g/2005'>\r\n <title>" . $this->_getParam("name") . "</title>\r\n <gwo:analyticsAccountId>" . $config->accountid . "</gwo:analyticsAccountId>\r\n <gwo:experimentType>AB</gwo:experimentType>\r\n <gwo:status>Running</gwo:status>\r\n <link rel='gwo:testUrl' type='text/html' href='http://" . Pimcore_Tool::getHostname() . $sourceDoc->getFullPath() . "' />\r\n <link rel='gwo:goalUrl' type='text/html' href='http://" . Pimcore_Tool::getHostname() . $goalDoc->getFullPath() . "' />\r\n </entry>\r\n ", "https://www.google.com/analytics/feeds/websiteoptimizer/experiments"); $e = $entryResult->getExtensionElements(); $data = array(); foreach ($e as $a) { $data[$a->rootElement] = $a->getText(); } // get tracking code $d = preg_match("/_getTracker\\(\"(.*)\"\\)/", $data["trackingScript"], $matches); $trackingId = $matches[1]; // get test id $d = preg_match("/_trackPageview\\(\"\\/([0-9]+)/", $data["trackingScript"], $matches); $testId = $matches[1]; // set original page $entryResult = $gdata->insertEntry("\r\n <entry xmlns='http://www.w3.org/2005/Atom'\r\n xmlns:gwo='http://schemas.google.com/analytics/websiteoptimizer/2009'\r\n xmlns:app='http://www.w3.org/2007/app'\r\n xmlns:gd='http://schemas.google.com/g/2005'>\r\n <title>Original</title>\r\n <content>http://" . Pimcore_Tool::getHostname() . $sourceDoc->getFullPath() . "</content>\r\n </entry>\r\n ", "https://www.google.com/analytics/feeds/websiteoptimizer/experiments/" . $data["experimentId"] . "/abpagevariations"); // set testing pages for ($i = 1; $i < 100; $i++) { if ($this->_getParam("page_name_" . $i)) { $pageUrl = ""; if ($this->_getParam("page_url_" . $i)) { if ($variantDoc = Document::getByPath($this->_getParam("page_url_" . $i))) { $pageUrl = $this->getRequest()->getScheme() . "://" . Pimcore_Tool::getHostname() . $variantDoc->getFullPath(); // add properties to variant page $variantDoc = $this->clearProperties($variantDoc); $variantDoc->setProperty("google_website_optimizer_test_id", "text", $testId); $variantDoc->setProperty("google_website_optimizer_track_id", "text", $trackingId); $variantDoc->save(); } else { Logger::warn("Added a invalid URL to A/B test."); exit; } } /*if($this->_getParam("page_version_".$i)) { $pageUrl = "http://" . Pimcore_Tool::getHostname() . $sourceDoc->getFullPath() . "?v=" . $this->_getParam("page_version_".$i); } */ if ($pageUrl) { try { $entryResult = $gdata->insertEntry("\r\n <entry xmlns='http://www.w3.org/2005/Atom'\r\n xmlns:gwo='http://schemas.google.com/analytics/websiteoptimizer/2009'\r\n xmlns:app='http://www.w3.org/2007/app'\r\n xmlns:gd='http://schemas.google.com/g/2005'>\r\n <title>" . $this->_getParam("page_name_" . $i) . "</title>\r\n <content>" . $pageUrl . "</content>\r\n </entry>\r\n ", "https://www.google.com/analytics/feeds/websiteoptimizer/experiments/" . $data["experimentId"] . "/abpagevariations"); } catch (Exception $e) { Logger::err($e); } } } else { break; } } // @todo START EXPERIMENT HERE //$entryResult = $gdata->getEntry("https://www.google.com/analytics/feeds/websiteoptimizer/experiments/" . $data["experimentId"]); //$gdata->updateEntry($entryResult->getXml(),"https://www.google.com/analytics/feeds/websiteoptimizer/experiments/" . $data["experimentId"]); /*$gdata->updateEntry(" <entry xmlns='http://www.w3.org/2005/Atom' xmlns:gwo='http://schemas.google.com/analytics/websiteoptimizer/2009' xmlns:app='http://www.w3.org/2007/app' xmlns:gd='http://schemas.google.com/g/2005'> <gwo:status>Running</gwo:status> </entry> ","https://www.google.com/analytics/feeds/websiteoptimizer/experiments/" . $data["experimentId"]); */ // source-page $sourceDoc->setProperty("google_website_optimizer_test_id", "text", $testId); $sourceDoc->setProperty("google_website_optimizer_track_id", "text", $trackingId); $sourceDoc->setProperty("google_website_optimizer_original_page", "bool", true); $sourceDoc->save(); // conversion-page $goalDoc->setProperty("google_website_optimizer_test_id", "text", $testId); $goalDoc->setProperty("google_website_optimizer_track_id", "text", $trackingId); $goalDoc->setProperty("google_website_optimizer_conversion_page", "bool", true); $goalDoc->save(); // clear output cache Pimcore_Model_Cache::clearTag("output"); Pimcore_Model_Cache::clearTag("properties"); $this->_helper->json(array("success" => true)); }