/** * This method controls the default routing. Don't be called when the * Enlight_Controller_Router_Route event canceled the default routing. * The default routing uses the dispatcher of the front controller to route * the request to the corresponding controller method. * * @param Enlight_Controller_Request_RequestHttp $request * @return array */ public function routeDefault(Enlight_Controller_Request_RequestHttp $request) { $path = $request->getPathInfo(); if (empty($path)) { return array(); } $dispatcher = $this->front->Dispatcher(); $query = array(); $params = array(); foreach (explode($this->separator, trim($path, $this->separator)) as $routePart) { $routePart = urldecode($routePart); if (empty($query[$request->getModuleKey()]) && $dispatcher->isValidModule($routePart)) { $query[$request->getModuleKey()] = $routePart; } elseif (empty($query[$request->getControllerKey()])) { $query[$request->getControllerKey()] = $routePart; } elseif (empty($query[$request->getActionKey()])) { $query[$request->getActionKey()] = $routePart; } else { $params[] = $routePart; } } if ($params) { $chunks = array_chunk($params, 2, false); foreach ($chunks as $chunk) { if (isset($chunk[1])) { $query[$chunk[0]] = $chunk[1]; } else { $query[$chunk[0]] = ''; } } } return $query; }
/** * Sets the shopware cache headers */ public function setCacheHeaders() { $controllerName = strtolower($this->request->getModuleName()) . '/' . strtolower($this->request->getControllerName()); $cacheControllers = $this->getCacheControllers(); if (!isset($cacheControllers[$controllerName])) { return false; } if (strpos($this->request->getPathInfo(), '/widgets/index/refreshStatistic') !== false) { return false; } if (strpos($this->request->getPathInfo(), '/captcha/index/rand/') !== false) { return false; } $allowNoCache = $this->getNoCacheTagsForController($controllerName); $noCacheCookies = $this->getNoCacheTagsFromCookie($this->request); $hasMatchingNoCacheCookie = $this->hasArrayIntersection($allowNoCache, $noCacheCookies); // Enable esi tag output $this->registerEsiRenderer(); if ($this->response->isRedirect()) { $this->response->setHeader('Cache-Control', 'private, no-cache'); return false; } if ($hasMatchingNoCacheCookie) { $this->response->setHeader('Cache-Control', 'private, no-cache'); return false; } $allowNoCacheControllers = $this->getAllowNoCacheControllers(); if (isset($allowNoCacheControllers[$controllerName]) && $this->request->getQuery('nocache') !== null) { $this->response->setHeader('Cache-Control', 'private, no-cache'); return false; } // NEVER cache a filled mini-basket if ($controllerName == 'widgets/checkout' && !empty(Shopware()->Session()->sBasketQuantity)) { $this->response->setHeader('Cache-Control', 'private, no-cache'); return false; } $cacheTime = (int) $cacheControllers[$controllerName]; $this->request->setParam('__cache', $cacheTime); $this->response->setHeader('Cache-Control', 'public, max-age=' . $cacheTime . ', s-maxage=' . $cacheTime, true); if (!empty($allowNoCache)) { $this->response->setHeader('x-shopware-allow-nocache', implode(', ', $allowNoCache)); } return true; }
/** * Sets the shopware cache headers */ public function setControllerOptions() { $controllerName = $this->request->getModuleName() . '/' . $this->request->getControllerName(); if(isset($this->controllerOptions[$controllerName]) && $this->request->getParam('rewriteUrl')) { $options = $this->controllerOptions[$controllerName]; $query = $this->request->getQuery(); $result = array_intersect_key($query, $options); $cookie = 'controller-options-' . $this->request->getBaseUrl() . $this->request->getPathInfo(); if(count($result) > 0) { $options = $this->request->getCookie($cookie); if($options !== null) { parse_str($options, $options); } else { $options = array(); } $options = array_merge($options, $result); ksort($options); $options = http_build_query($options, '', '&'); $this->response->setCookie( $cookie, $options, 0, null, //$this->request->getBasePath() . '/', $this->request->getHttpHost() ); $location = array_diff($query, $result); $location = $this->action->Front()->Router()->assemble($location); $this->action->redirect($location); } else { $options = $this->request->getCookie($cookie); if($options !== null) { parse_str($options, $options); $this->request->setQuery($options); } } } }
/** * @param Enlight_Controller_Request_RequestHttp $request * @param Enlight_Controller_Response_ResponseHttp $response */ protected function upgradeShop($request, $response) { $bootstrap = $this->Application()->Bootstrap(); $shop = $this->Application()->Shop(); $cookieKey = null; $cookieValue = null; switch (true) { case $request->getPost('sLanguage') !== null: $cookieKey = 'shop'; $cookieValue = $request->getPost('sLanguage'); break; case $request->getPost('sCurrency') !== null: $cookieKey = 'currency'; $cookieValue = $request->getPost('sCurrency'); break; case $request->getPost('__shop') !== null: $cookieKey = 'shop'; $cookieValue = $request->getPost('__shop'); break; case $request->getPost('__currency') !== null: $cookieKey = 'currency'; $cookieValue = $request->getPost('__currency'); break; case $request->getQuery('__template') !== null: $cookieKey = 'template'; $cookieValue = $request->getQuery('__template'); break; } // Redirect on shop change if ($cookieKey === 'shop') { /** @var $repository Shopware\Models\Shop\Repository */ $repository = Shopware()->Models()->getRepository('Shopware\Models\Shop\Shop'); $newShop = $repository->getActiveById($cookieValue); if (($newShop->getHost() !== null && $newShop->getHost() !== $shop->getHost()) || ($newShop->getBasePath() !== null && $newShop->getBasePath() !== $shop->getBasePath()) ) { $url = sprintf('%s://%s%s%s', $request->getScheme(), $request->isSecure() ? $newShop->getSecureHost() : $newShop->getHost(), $request->isSecure() ? $newShop->getSecureBasePath() : $newShop->getBasePath(), $request->getPathInfo() ); $response->setRedirect($url); return; } } // Refresh on shop change if ($cookieKey !== null && $cookieKey != 'template') { $path = rtrim($shop->getBasePath(), '/') . '/'; $response->setCookie($cookieKey, $cookieValue, 0, $path); $url = sprintf('%s://%s%s', $request->getScheme(), $request->getHttpHost(), $request->getRequestUri() ); $response->setRedirect($url); return; } // Upgrade currency if($request->getCookie('currency') !== null) { $currencyValue = $request->getCookie('currency'); foreach($shop->getCurrencies() as $currency) { if($currencyValue == $currency->getId() || $currencyValue == $currency->getCurrency()) { $shop->setCurrency($currency); break; } } } // Start session in frontend controllers $session = Shopware()->Session(); if ($cookieKey !== null) { $session->$cookieKey = $cookieValue; } // Refresh basket on currency change if(isset($session->sBasketCurrency) && $shop->getCurrency()->getId() != $session->sBasketCurrency) { Shopware()->Modules()->Basket()->sRefreshBasket(); } // Upgrade template if(isset($session->template) && !empty($session->Admin)) { $repository = 'Shopware\Models\Shop\Template'; $repository = Shopware()->Models()->getRepository($repository); $template = $session->template; $template = $repository->findOneBy(array('template' => $template)); if($template !== null) { $shop->setTemplate($template); } else { unset($session->template); } } else { unset($session->template); } // Save upgrades $shop->registerResources($bootstrap); }