Пример #1
0
 /**
  * Save data to cache storage. Store many block instances in one cache record depending on additional cache ids.
  *
  * @param string $data
  * @param string $id
  * @param array $tags
  * @param null|int $lifetime
  * @return Ves_Optimize_Model_Container_Advanced_Abstract
  */
 protected function _saveCache($data, $id, $tags = array(), $lifetime = null)
 {
     $additionalCacheId = $this->_getAdditionalCacheId();
     if (!$additionalCacheId) {
         Mage::throwException(Mage::helper('ves_optimize')->__('Additional id should not be empty'));
     }
     $tags[] = Ves_Optimize_Model_Processor::CACHE_TAG;
     $tags = array_merge($tags, $this->_getPlaceHolderBlock()->getCacheTags());
     if (is_null($lifetime)) {
         $lifetime = $this->_placeholder->getAttribute('cache_lifetime') ? $this->_placeholder->getAttribute('cache_lifetime') : false;
     }
     Ves_Optimize_Helper_Data::prepareContentPlaceholders($data);
     $result = array();
     $cacheRecord = parent::_loadCache($id);
     if ($cacheRecord) {
         $cacheRecord = json_decode($cacheRecord, true);
         if ($cacheRecord) {
             $result = $cacheRecord;
         }
     }
     $result[$additionalCacheId] = $data;
     Ves_Optimize_Model_Cache::getCacheInstance()->save(json_encode($result), $id, $tags, $lifetime);
     return $this;
 }
Пример #2
0
 /**
  * Save data to cache storage
  *
  * @param string $data
  * @param string $id
  * @param array $tags
  * @param null|int $lifetime
  * @return Ves_Optimize_Model_Container_Abstract
  */
 protected function _saveCache($data, $id, $tags = array(), $lifetime = null)
 {
     $tags[] = Ves_Optimize_Model_Processor::CACHE_TAG;
     $tags = array_merge($tags, $this->_getPlaceHolderBlock()->getCacheTags());
     if (is_null($lifetime)) {
         $lifetime = $this->_placeholder->getAttribute('cache_lifetime') ? $this->_placeholder->getAttribute('cache_lifetime') : false;
     }
     Ves_Optimize_Helper_Data::prepareContentPlaceholders($data);
     Ves_Optimize_Model_Cache::getCacheInstance()->save($data, $id, $tags, $lifetime);
     return $this;
 }
Пример #3
0
 /**
  * Retrieve unique marker value
  *
  * @return string
  */
 protected static function _getSidMarker()
 {
     return Ves_Optimize_Helper_Data::wrapPlaceholderString('_SID_MARKER_');
 }
Пример #4
0
 /**
  * Retrieve unique marker value
  *
  * @return string
  */
 protected static function _getFormKeyMarker()
 {
     return Ves_Optimize_Helper_Data::wrapPlaceholderString('_FORM_KEY_MARKER_');
 }
Пример #5
0
 /**
  * Determine and process all defined containers.
  * Direct request to optimize/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 = Ves_Optimize_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[Ves_Optimize_Model_Cookie::COOKIE_FORM_KEY])) {
         $formKey = $_COOKIE[Ves_Optimize_Model_Cookie::COOKIE_FORM_KEY];
     } else {
         $formKey = Ves_Optimize_Helper_Data::getRandomString(16);
         Ves_Optimize_Model_Cookie::setFormKeyCookieValue($formKey);
     }
     Ves_Optimize_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] : '';
     Ves_Optimize_Helper_Url::restoreSid($content, $sidCookieValue);
     if ($isProcessed) {
         return $content;
     } else {
         Mage::register('cached_page_content', $content);
         Mage::register('cached_page_containers', $containers);
         Mage::app()->getRequest()->setModuleName('optimize')->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;
     }
 }