Exemplo n.º 1
0
 /**
  * Prepare content for saving
  *
  * @param string $content
  */
 public static function prepareContentPlaceholders(&$content)
 {
     /**
      * Replace all occurrences of session_id with unique marker
      */
     Ves_Optimize_Helper_Url::replaceSid($content);
     /**
      * Replace all occurrences of form_key with unique marker
      */
     Ves_Optimize_Helper_Form_Key::replaceFormKey($content);
 }
Exemplo n.º 2
0
 /**
  * Generate placeholder content before application was initialized and apply to page content if possible
  *
  * @param string $content
  * @return bool
  */
 public function applyWithoutApp(&$content)
 {
     $cacheId = $this->_getCacheId();
     if ($cacheId === false) {
         $this->_applyToContent($content, '');
         return true;
     }
     $block = $this->_loadCache($cacheId);
     if ($block === false) {
         return false;
     }
     $block = Ves_Optimize_Helper_Url::replaceUenc($block);
     $this->_applyToContent($content, $block);
     return true;
 }
Exemplo n.º 3
0
 /**
  * Process response body by specific request
  *
  * @param Zend_Controller_Request_Http $request
  * @param Zend_Controller_Response_Http $response
  * @return Ves_Optimize_Model_Processor
  */
 public function processRequestResponse(Zend_Controller_Request_Http $request, Zend_Controller_Response_Http $response)
 {
     $cacheInstance = Ves_Optimize_Model_Cache::getCacheInstance();
     /**
      * Basic validation for request processing
      */
     if ($this->canProcessRequest($request)) {
         $processor = $this->getRequestProcessor($request);
         if ($processor && $processor->allowCache($request)) {
             $this->setMetadata('cache_subprocessor', get_class($processor));
             $cacheId = $this->prepareCacheId($processor->getPageIdInApp($this));
             $content = $processor->prepareContent($response);
             /**
              * Replace all occurrences of session_id with unique marker
              */
             Ves_Optimize_Helper_Url::replaceSid($content);
             Ves_Optimize_Helper_Form_Key::replaceFormKey($content);
             if (function_exists('gzcompress')) {
                 $content = gzcompress($content);
             }
             $contentSize = strlen($content);
             $currentStorageSize = (int) $cacheInstance->load(self::CACHE_SIZE_KEY);
             if (Mage::getStoreConfig(Ves_Optimize_Model_Processor::XML_PATH_CACHE_DEBUG)) {
                 $response->setBody(implode(', ', $this->getRequestTags()) . $response->getBody());
             }
             $maxSizeInBytes = Mage::getStoreConfig(self::XML_PATH_CACHE_MAX_SIZE) * 1024 * 1024;
             if ($currentStorageSize >= $maxSizeInBytes) {
                 Mage::app()->getCacheInstance()->invalidateType('full_page');
                 return $this;
             }
             $cacheInstance->save($content, $cacheId, $this->getRequestTags());
             $cacheInstance->save($currentStorageSize + $contentSize, self::CACHE_SIZE_KEY, $this->getRequestTags());
             /*
              * Save design change in cache
              */
             $designChange = Mage::getSingleton('core/design');
             if ($designChange->getData()) {
                 $cacheInstance->save(serialize($designChange->getData()), $this->getRequestCacheId() . self::DESIGN_CHANGE_CACHE_SUFFIX, $this->getRequestTags());
             }
             // save response headers
             $this->setMetadata('response_headers', $response->getHeaders());
             // save original routing info
             $this->setMetadata('routing_aliases', Mage::app()->getRequest()->getAliases());
             $this->setMetadata('routing_requested_route', Mage::app()->getRequest()->getRequestedRouteName());
             $this->setMetadata('routing_requested_controller', Mage::app()->getRequest()->getRequestedControllerName());
             $this->setMetadata('routing_requested_action', Mage::app()->getRequest()->getRequestedActionName());
             $this->setMetadata('sid_cookie_name', Mage::getSingleton('core/session')->getSessionName());
             Mage::dispatchEvent('optimize_processor_metadata_before_save', array('processor' => $this));
             $this->_saveMetadata();
         }
         if (isset($_GET[Mage_Core_Model_Session_Abstract::SESSION_ID_QUERY_PARAM])) {
             Mage::getSingleton('ves_optimize/cookie')->updateCustomerCookies();
             Mage::getModel('ves_optimize/observer')->updateCustomerProductIndex();
         }
     }
     return $this;
 }