/** * Set or remove given $noCacheTag from cookie * * @param $noCacheTag * @param bool $remove * @return void */ public function setNoCacheTag($noCacheTag, $remove = false) { static $noCacheTags, $shopId; if (!isset($noCacheTags)) { if ($this->request->getCookie('nocache')) { $noCacheTags = $this->request->getCookie('nocache'); $noCacheTags = explode(', ', $noCacheTags); } else { $noCacheTags = array(); } $shopId = Shopware()->Shop()->getId(); } if (!empty($noCacheTag)) { $noCacheTag .= '-' . $shopId; } if (empty($noCacheTag)) { $newCacheTags = array(); } elseif ($remove && in_array($noCacheTag, $noCacheTags)) { // remove $noCacheTag from $newCacheTags $newCacheTags = array_diff($noCacheTags, array($noCacheTag)); } elseif (!$remove && !in_array($noCacheTag, $noCacheTags)) { // add $noCacheTag to $newCacheTags $newCacheTags = $noCacheTags; $newCacheTags[] = $noCacheTag; } if (isset($newCacheTags)) { $this->response->setCookie('nocache', implode(', ', $newCacheTags), 0, $this->request->getBasePath() . '/', $this->request->getHttpHost() == 'localhost' ? null : $this->request->getHttpHost()); } }
/** * Refresh partner log * * @param \Enlight_Controller_Request_Request $request * @param \Enlight_Controller_Response_ResponseHttp $response */ public function refreshPartner($request, $response) { $partner = $request->getParam('partner', $request->getParam('sPartner')); if ($partner !== null) { if (strpos($partner, 'sCampaign') === 0) { $campaignID = (int) str_replace('sCampaign', '', $partner); if (!empty($campaignID)) { Shopware()->Session()->sPartner = 'sCampaign' . $campaignID; $sql = ' UPDATE s_campaigns_mailings SET clicked = clicked + 1 WHERE id = ? '; Shopware()->Db()->query($sql, array($campaignID)); } } else { $sql = 'SELECT * FROM s_emarketing_partner WHERE active=1 AND idcode=?'; $row = Shopware()->Db()->fetchRow($sql, array($partner)); if (!empty($row)) { if ($row['cookielifetime']) { $valid = time() + $row['cookielifetime']; } else { $valid = 0; } $response->setCookie('partner', $row['idcode'], $valid, '/'); } Shopware()->Session()->sPartner = $partner; } } elseif ($request->getCookie('partner') !== null) { $sql = 'SELECT idcode FROM s_emarketing_partner WHERE active=1 AND idcode=?'; $partner = Shopware()->Db()->fetchOne($sql, array($request->getCookie('partner'))); if (empty($partner)) { unset(Shopware()->Session()->sPartner); } else { Shopware()->Session()->sPartner = $partner; } } }
/** * Add context cookie * * @param Request $request * @param Response $response */ private function addContextCookie(Request $request, Response $response) { /** @var $session Enlight_Components_Session_Namespace */ $session = $this->get('session'); if ($session->offsetGet('sCountry')) { /** @var ProductContextInterface $productContext */ $productContext = $this->get('shopware_storefront.context_service')->getProductContext(); $userContext = sha1(json_encode($productContext->getTaxRules()) . json_encode($productContext->getCurrentCustomerGroup())); $response->setCookie('x-cache-context-hash', $userContext, 0, $request->getBasePath() . '/', $request->getHttpHost() == 'localhost' ? null : $request->getHttpHost()); } else { if ($request->getCookie('x-cache-context-hash')) { $response->setCookie('x-cache-context-hash', null, strtotime('-1 Year', time()), $request->getBasePath() . '/', $request->getHttpHost() == 'localhost' ? null : $request->getHttpHost()); } } }
/** * @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->getQuery('__shop') !== null: $cookieKey = 'shop'; $cookieValue = $request->getQuery('__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 !== null) { if ($newShop->getHost() !== null && $newShop->getHost() !== $shop->getHost() || $newShop->getBaseUrl() !== null && $newShop->getBaseUrl() !== $shop->getBaseUrl()) { $url = sprintf('%s://%s%s%s', $request::SCHEME_HTTP, $newShop->getHost(), $newShop->getBaseUrl(), '/'); $path = rtrim($newShop->getBasePath(), '/') . '/'; $response->setCookie($cookieKey, $cookieValue, 0, $path); $response->setRedirect($url); return; } } } // Refresh on shop change if ($cookieKey !== null && $cookieKey != 'template') { $path = rtrim($shop->getBasePath(), '/') . '/'; $response->setCookie($cookieKey, $cookieValue, 0, $path); if ($request->isPost() && $request->getQuery('__shop') === null) { $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); if ($request->isSecure()) { $template = $bootstrap->getResource('Template'); $template->setCompileId($template->getCompileId() . '_secure'); } }
/** * Returns not upgraded plugins, "hacked" plugins, plugins, after do some check secret and cookie * @param Response $response * @param Request $request * @return SubscriptionStateStruct|bool */ public function getPluginsSubscription(Response $response, Request $request) { if ($this->isPluginsSubscriptionCookieValid($request) == false) { return false; } try { $secret = $this->getShopSecret(); if (empty($secret)) { return false; } $pluginStates = $this->getPluginsSubscriptionState($secret); $response->setCookie('lastCheckSubscriptionDate', date('dmY'), time() + 60 * 60 * 24); return $pluginStates; } catch (ShopSecretException $e) { $this->resetShopSecret(); return false; } catch (\Exception $e) { return false; } }