Ejemplo n.º 1
0
 /**
  * Return cache page id without application. Depends on GET super global array.
  *
  * @param Enterprise_PageCache_Model_Processor $processor
  * @return string
  */
 public function getPageIdWithoutApp(Enterprise_PageCache_Model_Processor $processor)
 {
     $this->_updateCategoryViewedCookie($processor);
     $queryParams = $_GET;
     /**
      * unset known tracking codes
      */
     unset($queryParams["trk_module"]);
     unset($queryParams["trk_msg"]);
     unset($queryParams["trk_contact"]);
     unset($queryParams["utm_source"]);
     unset($queryParams["utm_medium"]);
     unset($queryParams["utm_term"]);
     unset($queryParams["utm_campaign"]);
     unset($queryParams["utm_content"]);
     /** End Edit */
     $sessionParams = Enterprise_PageCache_Model_Cookie::getCategoryCookieValue();
     if ($sessionParams) {
         $sessionParams = (array) json_decode($sessionParams);
         foreach ($sessionParams as $key => $value) {
             if (in_array($key, $this->_paramsMap) && !isset($queryParams[$key])) {
                 $queryParams[$key] = $value;
             }
         }
     }
     ksort($queryParams);
     $queryParams = json_encode($queryParams);
     Enterprise_PageCache_Model_Cookie::setCategoryCookieValue($queryParams);
     return $processor->getRequestId() . '_' . md5($queryParams);
 }
Ejemplo n.º 2
0
 public function updateCustomerCookies()
 {
     parent::updateCustomerCookies();
     $_helper = Mage::helper('weltpixel_mobiledetect');
     $detectionSuffix = 'desktop';
     if ($_helper->isMobile() || $_helper->isTablet()) {
         $detectionSuffix = 'mobile';
     }
     setcookie(self::COOKIE_DETECTION, $detectionSuffix, 0, '/');
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * Prepare response body before caching
  *
  * @param Zend_Controller_Response_Http $response
  * @return string
  */
 public function prepareContent(Zend_Controller_Response_Http $response)
 {
     /** @var Enterprise_PageCache_Model_Processor */
     $processor = Mage::getSingleton('enterprise_pagecache/processor');
     $countLimit = Mage::getStoreConfig(Mage_Reports_Block_Product_Viewed::XML_PATH_RECENTLY_VIEWED_COUNT);
     // save recently viewed product count limit
     $cacheId = $processor->getRecentlyViewedCountCacheId();
     if (!Mage::app()->getCache()->test($cacheId)) {
         Mage::app()->saveCache($countLimit, $cacheId);
     }
     // save current product id
     $product = Mage::registry('current_product');
     if ($product) {
         $cacheId = $processor->getRequestCacheId() . '_current_product_id';
         Mage::app()->saveCache($product->getId(), $cacheId);
         Enterprise_PageCache_Model_Cookie::registerViewedProducts($product->getId(), $countLimit);
     }
     return parent::prepareContent($response);
 }
 /**
  * Prepare response body before caching
  *
  * @param Zend_Controller_Response_Http $response
  * @return string
  */
 public function prepareContent(Zend_Controller_Response_Http $response)
 {
     $cacheInstance = Enterprise_PageCache_Model_Cache::getCacheInstance();
     /** @var Enterprise_PageCache_Model_Processor */
     $processor = Mage::getSingleton('enterprise_pagecache/processor');
     $countLimit = Mage::getStoreConfig(Mage_Reports_Block_Product_Viewed::XML_PATH_RECENTLY_VIEWED_COUNT);
     // save recently viewed product count limit
     $cacheId = $processor->getRecentlyViewedCountCacheId();
     if (!$cacheInstance->getFrontend()->test($cacheId)) {
         $cacheInstance->save($countLimit, $cacheId, array(Enterprise_PageCache_Model_Processor::CACHE_TAG));
     }
     // save current product id
     $product = Mage::registry('current_product');
     if ($product) {
         $cacheId = $processor->getRequestCacheId() . '_current_product_id';
         $cacheInstance->save($product->getId(), $cacheId, array(Enterprise_PageCache_Model_Processor::CACHE_TAG));
         $processor->setMetadata(self::METADATA_PRODUCT_ID, $product->getId());
         Enterprise_PageCache_Model_Cookie::registerViewedProducts($product->getId(), $countLimit);
     }
     return parent::prepareContent($response);
 }
Ejemplo n.º 5
0
 /**
  * Update catalog session from cookies
  */
 protected function _prepareCatalogSession()
 {
     $sessionParams = Enterprise_PageCache_Model_Cookie::getCategoryCookieValue();
     if ($sessionParams) {
         $session = Mage::getSingleton('catalog/session');
         $sessionParams = (array) json_decode($sessionParams);
         foreach ($sessionParams as $key => $value) {
             if (in_array($key, $this->_paramsMap)) {
                 $session->setData($key, $value);
             }
         }
     }
 }
 /**
  * Register form key in session from cookie value
  *
  * @param Varien_Event_Observer $observer
  */
 public function registerCachedFormKey(Varien_Event_Observer $observer)
 {
     if (!$this->isCacheEnabled()) {
         return;
     }
     /** @var $session Mage_Core_Model_Session  */
     $session = Mage::getSingleton('core/session');
     $cachedFrontFormKey = Enterprise_PageCache_Model_Cookie::getFormKeyCookieValue();
     if ($cachedFrontFormKey) {
         $session->setData('_form_key', $cachedFrontFormKey);
     }
 }
Ejemplo n.º 7
0
 /**
  * Determine and process all defined containers.
  * Direct request to pagecache/request/process action if necessary for additional processing
  *
  * @param string $content
  * @return string|false
  */
 protected function _processContent($content)
 {
     $containers = $this->_processContainers($content);
     $isProcessed = empty($containers);
     // renew session cookie
     $sessionInfo = Enterprise_PageCache_Model_Cache::getCacheInstance()->load($this->getSessionInfoCacheId());
     if ($sessionInfo) {
         $sessionInfo = unserialize($sessionInfo);
         foreach ($sessionInfo as $cookieName => $cookieInfo) {
             if (isset($_COOKIE[$cookieName]) && isset($cookieInfo['lifetime']) && isset($cookieInfo['path']) && isset($cookieInfo['domain']) && isset($cookieInfo['secure']) && isset($cookieInfo['httponly'])) {
                 $lifeTime = 0 == $cookieInfo['lifetime'] ? 0 : time() + $cookieInfo['lifetime'];
                 setcookie($cookieName, $_COOKIE[$cookieName], $lifeTime, $cookieInfo['path'], $cookieInfo['domain'], $cookieInfo['secure'], $cookieInfo['httponly']);
             }
         }
     } else {
         $isProcessed = false;
     }
     if (isset($_COOKIE[Enterprise_PageCache_Model_Cookie::COOKIE_FORM_KEY])) {
         $formKey = $_COOKIE[Enterprise_PageCache_Model_Cookie::COOKIE_FORM_KEY];
     } else {
         $formKey = Enterprise_PageCache_Helper_Data::getRandomString(16);
         Enterprise_PageCache_Model_Cookie::setFormKeyCookieValue($formKey);
     }
     Enterprise_PageCache_Helper_Form_Key::restoreFormKey($content, $formKey);
     /**
      * restore session_id in content whether content is completely processed or not
      */
     $sidCookieName = $this->getMetadata('sid_cookie_name');
     $sidCookieValue = $sidCookieName && isset($_COOKIE[$sidCookieName]) ? $_COOKIE[$sidCookieName] : '';
     // XSS vulnerability protection provided by htmlspcialchars call - escape & " ' < > chars
     Enterprise_PageCache_Helper_Url::restoreSid($content, htmlspecialchars($sidCookieValue, ENT_QUOTES));
     if ($isProcessed) {
         return $content;
     } else {
         Mage::register('cached_page_content', $content);
         Mage::register('cached_page_containers', $containers);
         Mage::app()->getRequest()->setModuleName('pagecache')->setControllerName('request')->setActionName('process')->isStraight(true);
         // restore original routing info
         $routingInfo = array('aliases' => $this->getMetadata('routing_aliases'), 'requested_route' => $this->getMetadata('routing_requested_route'), 'requested_controller' => $this->getMetadata('routing_requested_controller'), 'requested_action' => $this->getMetadata('routing_requested_action'));
         Mage::app()->getRequest()->setRoutingInfo($routingInfo);
         return false;
     }
 }
Ejemplo n.º 8
0
 /**
  * Remove customer cookie
  *
  * @param Varien_Event_Observer $observer
  * @return Enterprise_PageCache_Model_Observer
  */
 public function customerLogout(Varien_Event_Observer $observer)
 {
     if (!$this->isCacheEnabled()) {
         return $this;
     }
     $this->_getCookie()->updateCustomerCookies();
     if (!$this->_getCookie()->get(Enterprise_PageCache_Model_Cookie::COOKIE_CUSTOMER)) {
         $this->_getCookie()->delete(Enterprise_PageCache_Model_Cookie::COOKIE_RECENTLY_COMPARED);
         $this->_getCookie()->delete(Enterprise_PageCache_Model_Cookie::COOKIE_COMPARE_LIST);
         Enterprise_PageCache_Model_Cookie::registerViewedProducts(array(), 0, false);
     }
     return $this;
 }
Ejemplo n.º 9
0
 /**
  * Clear request path cache by tag
  * (used for redirects invalidation)
  *
  * @param Varien_Event_Observer $observer
  * @return $this
  */
 public function fixInvalidCategoryCookie(Varien_Event_Observer $observer)
 {
     $categoryId = $observer->getCategoryId();
     if (Enterprise_PageCache_Model_Cookie::getCategoryCookieValue() != $categoryId) {
         Enterprise_PageCache_Model_Cookie::setCategoryViewedCookieValue($categoryId);
         Enterprise_PageCache_Model_Cookie::setCurrentCategoryCookieValue($categoryId);
     }
 }
Ejemplo n.º 10
0
 /**
  * Update last visited category id cookie
  *
  * @param Enterprise_PageCache_Model_Processor $processor
  * @return Enterprise_PageCache_Model_Processor_Category
  */
 protected function _updateCategoryViewedCookie(Enterprise_PageCache_Model_Processor $processor)
 {
     Enterprise_PageCache_Model_Cookie::setCategoryViewedCookieValue($processor->getMetadata(self::METADATA_CATEGORY_ID));
     return $this;
 }
Ejemplo n.º 11
0
 /**
  * Get page content from cache storage
  *
  * @param string $content
  * @return string|false
  */
 public function extractContent($content)
 {
     $cacheInstance = Enterprise_PageCache_Model_Cache::getCacheInstance();
     /*
      * Apply design change
      */
     $designChange = $cacheInstance->load($this->getRequestCacheId() . self::DESIGN_CHANGE_CACHE_SUFFIX);
     if ($designChange) {
         $designChange = unserialize($designChange);
         if (is_array($designChange) && isset($designChange['package']) && isset($designChange['theme'])) {
             $designPackage = Mage::getSingleton('core/design_package');
             $designPackage->setPackageName($designChange['package'])->setTheme($designChange['theme']);
         }
     }
     if (!$this->_designExceptionExistsInCache) {
         //no design exception value - error
         //must be at least empty value
         return false;
     }
     if (!$content && $this->isAllowed()) {
         $subprocessorClass = $this->getMetadata('cache_subprocessor');
         if (!$subprocessorClass) {
             return $content;
         }
         /*
          * @var Enterprise_PageCache_Model_Processor_Default
          */
         $subprocessor = new $subprocessorClass();
         $this->setSubprocessor($subprocessor);
         $cacheId = $this->prepareCacheId($subprocessor->getPageIdWithoutApp($this));
         $content = $cacheInstance->load($cacheId);
         if ($content) {
             if (function_exists('gzuncompress')) {
                 $content = gzuncompress($content);
             }
             $content = $this->_processContent($content);
             // restore response headers
             $responseHeaders = $this->getMetadata('response_headers');
             if (is_array($responseHeaders)) {
                 foreach ($responseHeaders as $header) {
                     Mage::app()->getResponse()->setHeader($header['name'], $header['value'], $header['replace']);
                 }
             }
             // renew recently viewed products
             $productId = $cacheInstance->load($this->getRequestCacheId() . '_current_product_id');
             $countLimit = $cacheInstance->load($this->getRecentlyViewedCountCacheId());
             if ($productId && $countLimit) {
                 Enterprise_PageCache_Model_Cookie::registerViewedProducts($productId, $countLimit);
             }
         }
     }
     return $content;
 }
Ejemplo n.º 12
0
 /**
  * Set cookie for logged in customer
  *
  * @param Varien_Event_Observer $observer
  */
 public function customerLogin(Varien_Event_Observer $observer)
 {
     if (!$this->isCacheEnabled()) {
         return $this;
     }
     $this->_getCookie()->updateCustomerCookies();
     // update customer viewed products index
     try {
         $productIds = $this->_getCookie()->get(Enterprise_PageCache_Model_Container_Viewedproducts::COOKIE_NAME);
         if ($productIds) {
             $productIds = explode(',', $productIds);
             Mage::getModel('reports/product_index_viewed')->registerIds($productIds);
         }
     } catch (Exception $e) {
         Mage::logException($e);
     }
     // renew customer viewed product ids cookie
     $countLimit = Mage::getStoreConfig(Mage_Reports_Block_Product_Viewed::XML_PATH_RECENTLY_VIEWED_COUNT);
     $collection = Mage::getResourceModel('reports/product_index_viewed_collection')->addIndexFilter()->setAddedAtOrder()->setPageSize($countLimit)->setCurPage(1);
     Mage::getSingleton('catalog/product_visibility')->addVisibleInSiteFilterToCollection($collection);
     $productIds = $collection->load()->getLoadedIds();
     $productIds = implode(',', $productIds);
     Enterprise_PageCache_Model_Cookie::registerViewedProducts($productIds, $countLimit, false);
     return $this;
 }
Ejemplo n.º 13
0
 /**
  * Get page content from cache storage
  *
  * @param string $content
  * @return string | false
  */
 public function extractContent($content)
 {
     Mage::app()->getRequest();
     if (!$content && $this->isAllowed()) {
         $subprocessorClass = $this->getMetadata('cache_subprocessor');
         if (!$subprocessorClass) {
             return $content;
         }
         /*
          * @var Enterprise_PageCache_Model_Processor_Default
          */
         $subprocessor = new $subprocessorClass();
         $cacheId = $this->prepareCacheId($subprocessor->getPageIdWithoutApp($this));
         $content = Mage::app()->loadCache($cacheId);
         if ($content) {
             if (function_exists('gzuncompress')) {
                 $content = gzuncompress($content);
             }
             $content = $this->_processContent($content);
             // renew recently viewed products
             $productId = Mage::app()->loadCache($this->getRequestCacheId() . '_current_product_id');
             $countLimit = Mage::app()->loadCache($this->getRecentlyViewedCountCacheId());
             if ($productId && $countLimit) {
                 Enterprise_PageCache_Model_Cookie::registerViewedProducts($productId, $countLimit);
             }
         }
     }
     return $content;
 }