/** * Trigger post dispatch plugins hooks * * @param Zend_Controller_Request_Abstract $request */ public function postDispatch(Zend_Controller_Request_Abstract $request) { $this->_callPlugins(self::POSTDISPATCH_METHOD); //replace http with https for internal links if requested via https if ($request->isSecure()) { $websiteConfig = Zend_Registry::get('website'); $body = strtr($this->_response->getBody(), array(Zend_Controller_Request_Http::SCHEME_HTTP . '://' . $websiteConfig['url'] => Zend_Controller_Request_Http::SCHEME_HTTPS . '://' . $websiteConfig['url'])); $this->_response->setBody($body); } }
/** * Check the request to see if it is secure. If it isn't * rebuild a secure url, redirect and exit. * * @param Zend_Controller_Request_Abstract $request * @return void * @author Travis Boudreaux */ protected function _secureUrl(Zend_Controller_Request_Abstract $request) { $server = $request->getServer(); $hostname = $server['HTTP_HOST']; if (!$request->isSecure()) { //url scheme is not secure so we rebuild url with secureScheme $url = Zend_Controller_Request_Http::SCHEME_HTTPS . "://" . $hostname . $request->getPathInfo(); $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector'); $redirector->setGoToUrl($url); $redirector->redirectAndExit(); } }
/** * Only GET requests can be processed. * Also check headers for HTTPS and ignore caching for sessions. * * @param \Zend_Controller_Request_Abstract $request */ protected function checkRequest(\Zend_Controller_Request_Abstract $request) { if (!$request->isGet()) { $this->ignored = true; } if (!$request->isSecure()) { if (isset($_SERVER["HTTP_CACHE_CONTROL"]) && $_SERVER["HTTP_CACHE_CONTROL"] === "no-cache") { $this->ignored = true; } if (isset($_SERVER["HTTP_PRAGMA"]) && $_SERVER["HTTP_PRAGMA"] === "no-cache") { $this->ignored = true; } } if (session_id() || isset($_COOKIE['pimcore_admin_sid'])) { $this->ignored = true; } }
/** * @param \Zend_Controller_Request_Abstract $request * @return bool|void */ public function routeStartup(\Zend_Controller_Request_Abstract $request) { $requestUri = $request->getRequestUri(); $excludePatterns = array(); // only enable GET method if (!$request->isGet()) { return $this->disable(); } // disable the output-cache if browser wants the most recent version // unfortunately only Chrome + Firefox if not using SSL if (!$request->isSecure()) { if (isset($_SERVER["HTTP_CACHE_CONTROL"]) && $_SERVER["HTTP_CACHE_CONTROL"] == "no-cache") { return $this->disable("HTTP Header Cache-Control: no-cache was sent"); } if (isset($_SERVER["HTTP_PRAGMA"]) && $_SERVER["HTTP_PRAGMA"] == "no-cache") { return $this->disable("HTTP Header Pragma: no-cache was sent"); } } try { $conf = \Pimcore\Config::getSystemConfig(); if ($conf->cache) { $conf = $conf->cache; if (!$conf->enabled) { return $this->disable(); } if (\Pimcore::inDebugMode()) { return $this->disable("in debug mode"); } 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 (!empty($cookie) && isset($_COOKIE[trim($cookie)])) { return $this->disable("exclude cookie in system-settings matches"); } } } // output-cache is always disabled when logged in at the admin ui if (isset($_COOKIE["pimcore_admin_sid"])) { return $this->disable("backend user is logged in"); } } else { return $this->disable(); } } catch (\Exception $e) { \Logger::error($e); return $this->disable("ERROR: Exception (see debug.log)"); } foreach ($excludePatterns as $pattern) { if (@preg_match($pattern, $requestUri)) { return $this->disable("exclude path pattern in system-settings matches"); } } $deviceDetector = Tool\DeviceDetector::getInstance(); $device = $deviceDetector->getDevice(); $deviceDetector->setWasUsed(false); $this->defaultCacheKey = "output_" . md5($request->getHttpHost() . $requestUri); $cacheKeys = [$this->defaultCacheKey . "_" . $device, $this->defaultCacheKey]; $cacheItem = null; foreach ($cacheKeys as $cacheKey) { $cacheItem = CacheManager::load($cacheKey, true); if ($cacheItem) { break; } } if (is_array($cacheItem) && !empty($cacheItem)) { header("X-Pimcore-Output-Cache-Tag: " . $cacheKey, true, 200); header("X-Pimcore-Output-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; } else { // set headers to tell the client to not cache the contents // this can/will be overwritten in $this->dispatchLoopShutdown() if the cache is enabled $date = new \Zend_Date(1); $this->getResponse()->setHeader("Expires", $date->get(\Zend_Date::RFC_1123), true); $this->getResponse()->setHeader("Cache-Control", "max-age=0, no-cache", true); } }
/** * addMessage() - Add an current navigation on history * * @param Zend_Controller_Request_Abstract $oRequest * @param string $layout * @return ZLayer_Controller_Request_History Provides a fluent interface */ public function addHistory(Zend_Controller_Request_Abstract $oRequest, $layout) { if (!is_array(self::$_session->history)) { self::$_session->history = array(); } $params = $oRequest->getParams(); if (isset($params['__format'])) { $context = $params['__format']; } else { $context = 'default'; } $array = array("action" => $oRequest->getActionName(), "controller" => $oRequest->getControllerName(), "module" => $oRequest->getModuleName(), "layout" => $layout, "params" => $oRequest->getParams(), "method" => $oRequest->getMethod(), "context" => $context, "secure" => $oRequest->isSecure(), "xmlHttpRequest" => $oRequest->isXmlHttpRequest(), "flashRequest" => $oRequest->isFlashRequest()); self::$_session->history[] = $array; $histAr = self::$_session->history; $revAr = array_reverse($histAr); $limitRevAr = array_slice($revAr, 0, 10); $newHistAr = array_reverse($limitRevAr); self::$_session->history = $newHistAr; return $this; }