Esempio n. 1
0
 /**
  * Get Place Holder Block
  *
  * @return Mage_Core_Block_Abstract
  */
 protected function _getPlaceHolderBlock()
 {
     $blockName = $this->_placeholder->getAttribute('block');
     $block = new $blockName();
     $block->setTemplate($this->_placeholder->getAttribute('template'));
     $block->setLayout(Mage::app()->getLayout());
     $block->setSkipRenderTag(true);
     return $block;
 }
Esempio n. 2
0
 /**
  * Save data to cache storage
  *
  * @param string $data
  * @param string $id
  * @param array $tags
  */
 protected function _saveCache($data, $id, $tags = array(), $lifetime = null)
 {
     $tags[] = Enterprise_PageCache_Model_Processor::CACHE_TAG;
     if (is_null($lifetime)) {
         $lifetime = $this->_placeholder->getAttribute('cache_lifetime') ? $this->_placeholder->getAttribute('cache_lifetime') : false;
     }
     /**
      * Replace all occurrences of session_id with unique marker
      */
     Enterprise_PageCache_Helper_Url::replaceSid($data);
     Mage::app()->getCache()->save($data, $id, $tags, $lifetime);
     return $this;
 }
Esempio n. 3
0
 /**
  * Retrieve placeholder replacer
  *
  * @param array $matches Matches by preg_replace_callback
  * @return string
  */
 protected function _getPlaceholderReplacer($matches)
 {
     $container = $this->_placeholder->getContainerClass();
     /**
      * In developer mode blocks will be rendered separately
      * This should simplify debugging _renderBlock()
      */
     if ($container && !Mage::getIsDeveloperMode()) {
         $container = new $container($this->_placeholder);
         $blockContent = $matches[1];
         $container->saveCache($blockContent);
     }
     return $this->_placeholder->getReplacer();
 }
Esempio n. 4
0
 /**
  * Process Containers
  *
  * @param $content
  * @return array
  */
 protected function _processContainers(&$content)
 {
     $placeholders = array();
     preg_match_all(Enterprise_PageCache_Model_Container_Placeholder::HTML_NAME_PATTERN, $content, $placeholders, PREG_PATTERN_ORDER);
     $placeholders = array_unique($placeholders[1]);
     $containers = array();
     foreach ($placeholders as $definition) {
         $placeholder = new Enterprise_PageCache_Model_Container_Placeholder($definition);
         $container = $placeholder->getContainerClass();
         if (!$container) {
             continue;
         }
         $container = new $container($placeholder);
         $container->setProcessor($this);
         if (!$container->applyWithoutApp($content)) {
             $containers[] = $container;
         } else {
             preg_match($placeholder->getPattern(), $content, $matches);
             if (array_key_exists(1, $matches)) {
                 $containers = array_merge($this->_processContainers($matches[1]), $containers);
                 $content = preg_replace($placeholder->getPattern(), str_replace('$', '\\$', $matches[1]), $content);
             }
         }
     }
     return $containers;
 }
 /**
  * Retrieve placeholder replacer
  *
  * @param array $matches Matches by preg_replace_callback
  * @return string
  */
 protected function _getPlaceholderReplacer($matches)
 {
     return $this->_placeholder->getReplacer();
 }
Esempio n. 6
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)
 {
     $placeholders = array();
     preg_match_all(Enterprise_PageCache_Model_Container_Placeholder::HTML_NAME_PATTERN, $content, $placeholders, PREG_PATTERN_ORDER);
     $placeholders = array_unique($placeholders[1]);
     $containers = array();
     foreach ($placeholders as $definition) {
         $placeholder = new Enterprise_PageCache_Model_Container_Placeholder($definition);
         $container = $placeholder->getContainerClass();
         if (!$container) {
             continue;
         }
         $container = new $container($placeholder);
         if (!$container->applyWithoutApp($content)) {
             $containers[] = $container;
         }
     }
     $isProcessed = empty($containers);
     // renew session cookie
     $sessionInfo = Mage::app()->loadCache($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;
     }
     /**
      * 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] : '';
     Enterprise_PageCache_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('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;
     }
 }