Example #1
0
 /**
  * Generate ESI data to be encoded in URL
  *
  * @param  Mage_Core_Block_Template $blockObject
  * @param  array $esiOptions
  * @return Varien_Object
  */
 protected function _getEsiData($blockObject, $esiOptions)
 {
     Varien_Profiler::start('turpentine::observer::esi::_getEsiData');
     $esiHelper = Mage::helper('turpentine/esi');
     $cacheTypeParam = $esiHelper->getEsiCacheTypeParam();
     $scopeParam = $esiHelper->getEsiScopeParam();
     $methodParam = $esiHelper->getEsiMethodParam();
     $esiData = new Varien_Object();
     $esiData->setStoreId(Mage::app()->getStore()->getId());
     $esiData->setDesignPackage(Mage::getDesign()->getPackageName());
     $esiData->setDesignTheme(Mage::getDesign()->getTheme('layout'));
     $esiData->setNameInLayout($blockObject->getNameInLayout());
     $esiData->setBlockType(get_class($blockObject));
     $esiData->setLayoutHandles($this->_getBlockLayoutHandles($blockObject));
     $esiData->setEsiMethod($esiOptions[$methodParam]);
     if ($esiOptions[$cacheTypeParam] == 'private' || $esiOptions[$cacheTypeParam] == 'customer_group') {
         if (is_array(@$esiOptions['flush_events'])) {
             $esiData->setFlushEvents(array_merge($esiHelper->getDefaultCacheClearEvents(), array_keys($esiOptions['flush_events'])));
         } else {
             $esiData->setFlushEvents($esiHelper->getDefaultCacheClearEvents());
         }
     }
     if ($esiOptions[$scopeParam] == 'page') {
         $esiData->setParentUrl(Mage::app()->getRequest()->getRequestString());
     }
     if (is_array($esiOptions['dummy_blocks'])) {
         $dummyBlocks = array();
         foreach ($esiOptions['dummy_blocks'] as $key => $value) {
             $dummyBlocks[] = empty($value) && !is_numeric($key) ? $key : $value;
         }
         $esiData->setDummyBlocks($dummyBlocks);
     } else {
         Mage::helper('turpentine/debug')->logWarn('Invalid dummy_blocks for block: %s', $blockObject->getNameInLayout());
     }
     $simpleRegistry = array();
     $complexRegistry = array();
     if (is_array($esiOptions['registry_keys'])) {
         foreach ($esiOptions['registry_keys'] as $key => $options) {
             $value = Mage::registry($key);
             if ($value) {
                 if (is_object($value) && $value instanceof Mage_Core_Model_Abstract) {
                     $complexRegistry[$key] = $this->_getComplexRegistryData($options, $value);
                 } else {
                     $simpleRegistry[$key] = $value;
                 }
             }
         }
     } else {
         Mage::helper('turpentine/debug')->logWarn('Invalid registry_keys for block: %s', $blockObject->getNameInLayout());
     }
     $esiData->setSimpleRegistry($simpleRegistry);
     $esiData->setComplexRegistry($complexRegistry);
     Varien_Profiler::stop('turpentine::observer::esi::_getEsiData');
     return $esiData;
 }