/** * 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(); }
/** * 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; }
/** * 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; } }