Exemple #1
0
 protected function fetch()
 {
     $key = $this->getCacheKey();
     if ($data = $this->getCache()->load($key)) {
         $this->regenerate($key);
         $boostRobots = $this->_boostRobots();
         if (!isset($_COOKIE[$this->_sessionName]) && !$boostRobots && (bool) (string) Mage::app()->getConfig()->getNode('global/amfpc/miss_on_first_view')) {
             return false;
         }
         $sessionRequired = $this->_isSessionRequired() && !$boostRobots;
         $data = unserialize($data);
         $page = $data['content'];
         $this->removeDiscardedBlocks($page);
         if (!$sessionRequired) {
             $page = str_replace('AMFPC_FORM_KEY', $this->_formKey, $page);
         } else {
             Mage::register('amfpc_new_session', true, true);
         }
         if ($this->isDynamicBlocksEnabled()) {
             $requiredBlocks = $this->getRequiredBlocks($page);
             $ajaxBlocks = $this->getRequiredAjaxBlocks($page);
             $referer = $this->getFullUrl();
             $referer = strtr(base64_encode($referer), '+/=', '-_,');
             $validBlocks = array();
             $invalidBlocks = array();
             foreach ($requiredBlocks as $name) {
                 $blockConfig = (array) Mage::app()->getConfig()->getNode('global/amfpc/blocks/' . $name);
                 $cookieBlock = Amasty_Fpc_Model_Config::getCookieNoticeBlockName();
                 if ($name == $cookieBlock && self::$_cookieUpdated) {
                     $content = '';
                 } else {
                     if ($boostRobots && isset($blockConfig['@attributes']['store_switcher'])) {
                         $content = '';
                     } else {
                         $id = $this->getBlockCacheId($name);
                         $content = $this->getCache()->load($id);
                     }
                 }
                 if ($content !== false) {
                     $content = preg_replace('#/referer/[A-Za-z0-9\\-_,]+/#', "/referer/{$referer}/", $content);
                     if (!$sessionRequired) {
                         $content = str_replace('AMFPC_FORM_KEY', $this->_formKey, $content);
                     }
                     $validBlocks[$name] = $content;
                 } else {
                     $invalidBlocks[] = $name;
                 }
             }
             foreach ($validBlocks as $name => $content) {
                 $blockNode = Mage::app()->getConfig()->getNode('global/amfpc/blocks/' . $name);
                 $debugName = $name;
                 if (isset($blockNode['parent'])) {
                     $debugName .= "[{$blockNode['parent']}]";
                 }
                 $this->debug($content, $debugName);
                 $page = str_replace("<amfpc name=\"{$name}\" />", $content, $page);
             }
             if (!empty($invalidBlocks)) {
                 $cmsBlocks = (bool) (string) Mage::app()->getConfig()->getNode('global/amfpc/cms_blocks');
                 if ($cmsBlocks) {
                     Mage::register('amfpc_cms_blocks', true, true);
                 } else {
                     $info = array('page' => $page, 'blocks' => array_merge($ajaxBlocks, $invalidBlocks));
                     Mage::register('amfpc_blocks', $info, true);
                 }
                 return false;
             } else {
                 if (!empty($ajaxBlocks)) {
                     $page = $this->addAjaxLoad($page, $ajaxBlocks);
                 }
             }
         }
         $page = preg_replace('#<amfpc_ajax name="([^"]+)" />#s', '<div id="amfpc-\\1"></div>', $page);
         if ($sessionRequired) {
             Mage::register('amfpc_page', $page, true);
             return false;
         }
         if (isset($_GET['___store'])) {
             setcookie('store', $this->getStoreCode(), 0, '/', '.' . $_SERVER['HTTP_HOST']);
         }
         $this->debug($page, 'Early page load');
         $this->addLoadTimeInfo($page);
         $this->_processPageActions($data);
         header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
         header('Pragma: no-cache');
         header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
         return $page;
     } else {
         Mage::register('amfpc_preserve', true, true);
         return false;
     }
 }
Exemple #2
0
 public function saveBlockCache($name, $content, $tags)
 {
     if (in_array($name, array('global_messages', 'messages'))) {
         return;
     }
     if ($name == Amasty_Fpc_Model_Config::getCookieNoticeBlockName()) {
         if (!trim($content)) {
             return;
         }
     }
     if (FALSE !== stripos($this->_backendType, 'database') && $this->getMaxStorageSize() > 0) {
         if ($this->getStorageSize() >= $this->getMaxStorageSize()) {
             return;
         }
     }
     if (!$tags) {
         $tags = array();
     }
     $id = Mage::getSingleton('amfpc/fpc_front')->getBlockCacheId($name);
     $blockTag = Mage::getSingleton('amfpc/fpc_front')->getBlockCacheTag($name);
     $tags[] = Mage_Core_Block_Abstract::CACHE_GROUP;
     $tags[] = $blockTag;
     $lifetime = +Mage::getStoreConfig('amfpc/general/block_lifetime');
     $lifetime *= 3600;
     $content = $this->removeSid($content);
     if ($formKey = Mage::getSingleton('core/session')->getFormKey()) {
         $content = str_replace($formKey, 'AMFPC_FORM_KEY', $content);
     }
     if (Mage::helper('amfpc')->isBlockCompressionEnabled()) {
         $content = gzcompress($content, +Mage::getStoreConfig('amfpc/compression/level'));
         $content = base64_encode($content);
         $content = self::COMPRESSION_PREFIX . $content;
     }
     if (self::STATS_MODE) {
         Mage::getModel('amfpc/stats')->load($id, 'cache_id')->addData(array('cache_id' => $id, 'url' => $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'size' => strlen($content), 'type' => 'block', 'block_name' => $name, 'customer_group' => Mage::getSingleton('amfpc/fpc_front')->getCustomerGroupId(), 'session' => isset($_COOKIE['frontend']) ? $_COOKIE['frontend'] : ''))->save();
     }
     $this->save($content, $id, $tags, $lifetime);
 }