Example #1
0
 /**
  * Get the final block key used for caching
  *
  * @param Mage_Core_Block_Abstract $block
  * @return string
  */
 public function getBlockKey(Mage_Core_Block_Abstract $block)
 {
     $cacheKeys = array_values($block->getData('cache_keys'));
     $key = implode('|', $cacheKeys);
     $key = sha1($key);
     return $key;
 }
Example #2
0
 /**
  * Create placeholder object based on block information
  *
  * @param Mage_Core_Block_Abstract $block
  * @return Enterprise_PageCache_Model_Container_Placeholder
  */
 public function getBlockPlaceholder($block)
 {
     $this->_initPlaceholders();
     $type = $block->getType();
     if (isset($this->_placeholders[$type])) {
         $placeholderData = false;
         foreach ($this->_placeholders[$type] as $placeholderInfo) {
             if (!empty($placeholderInfo['name'])) {
                 if ($placeholderInfo['name'] == $block->getNameInLayout()) {
                     $placeholderData = $placeholderInfo;
                 }
             } else {
                 $placeholderData = $placeholderInfo;
             }
         }
         if (!$placeholderData) {
             return false;
         }
         $placeholder = $placeholderData['code'] . ' container="' . $placeholderData['container'] . '"' . ' block="' . get_class($block) . '"';
         $placeholder .= ' cache_id="' . $block->getCacheKey() . '"';
         foreach ($block->getCacheKeyInfo() as $k => $v) {
             if (is_string($k) && !empty($k)) {
                 $placeholder .= ' ' . $k . '="' . $v . '"';
             }
         }
         $placeholder = Mage::getModel('enterprise_pagecache/container_placeholder', $placeholder);
         return $placeholder;
     }
     return false;
 }
Example #3
0
 /**
  * Pull template name out of the block object
  *
  * @param  Mage_Core_Block_Abstract $block
  * @return string
  */
 protected function _getTemplateNameFromBlock($block)
 {
     $file = $block->getTemplateFile();
     $file = !preg_match('{/$}i', $file) ? $file : false;
     $file = $file ? $file : $block->getTemplate();
     return $file;
 }
 /**
  * @param Mage_Core_Block_Abstract $block
  */
 public function delayPrepareLayout($block, $sortOrder = 0)
 {
     if ($this->_delayedLayoutIsBeingProcessed || Mage::registry('m_page_is_being_rendered')) {
         $block->delayedPrepareLayout();
     } else {
         $this->_delayPrepareLayoutBlocks[$block->getNameInLayout()] = compact('block', 'sortOrder');
     }
 }
Example #5
0
 public function apply(Mage_Core_Block_Abstract $block)
 {
     $layout = $block->getLayout();
     if ($layout) {
         $keys = $block->getCacheKeys();
         $keys[] = $block->getLayout()->getUpdate()->getCacheId();
         $block->setCacheKeys($keys);
     }
 }
Example #6
0
 public function apply(Mage_Core_Block_Abstract $block)
 {
     $helper = Mage::helper('cache');
     $keys = $block->getCacheKeys();
     foreach (Mage::app()->getRequest()->getParams() as $key => $value) {
         $value = $helper->paramValueToCacheKey($value);
         $keys[] = $key . '_' . $value;
     }
     $block->setCacheKeys($keys);
 }
Example #7
0
/**
* Specified by <view>hello</view>
*
* View function should return a $block, which will be automatically
* appended to the Page Layout's content block
*
* $block is a block object and will have a data member called 
* params which  contains the matched regular expressions from 
* <url_regex/>. The $block's class is controlled by <block_class/>.
* See simplepage.xml for more information.
*
* $layout is a reference to the Magento page layout object, and
* may be used to manipulated the existing layout. (add blocks, 
* unset them, change templates, etc.)
*
* $request and $response are the standard Magento request and response
* objects, in case you want to monkey with them. 
*
* @param Mage_Core_Block_Abstract $block
* @param Mage_Core_Model_Layout   $layout
* @param Mage_Core_Controller_Request_Http $request
* @param Mage_Core_Controller_Response_Http $response
* @return Mage_Core_Block_Template $block
*/
function hello($block, $layout, $request, $response)
{
    //in this example we're just setting a template on
    //the bock on returning it. Standard Magento theme
    //rules apply for template loading
    $block->setTemplate('pulsestorm_simplepage/example.phtml');
    //$layout->getBlock('left')->getParentBlock()->unsetChild('left');
    //$layout->getBlock('root')->setTemplate('page/1column.phtml');
    return $block;
}
Example #8
0
 /**
  * @param Mana_Admin_Block_Data[] $result
  * @param Mage_Core_Block_Abstract $block
  */
 protected function _getChildDataSourcesRecursively(&$result, $block)
 {
     foreach ($block->getChild() as $child) {
         if ($child != $this) {
             if ($child instanceof Mana_Admin_Block_Data) {
                 $result[] = $child;
             } else {
                 $this->_getChildDataSourcesRecursively($result, $child);
             }
         }
     }
 }
Example #9
0
 /**
  * Get generic key array including handle etc, that all blocks use
  *
  * @param Mage_Core_Block_Abstract $block
  * @return array
  */
 protected function _getBasicKeys(Mage_Core_Block_Abstract $block)
 {
     $keys = $block->getCacheKeyInfo();
     if (!is_array($keys)) {
         $keys = array();
     }
     $keys[] = Mage::getSingleton('customer/session')->getCustomer()->getGroupId();
     $keys[] = Mage::app()->getStore()->getCurrentCurrencyCode();
     $keys[] = $block->getLayout()->getUpdate()->getCacheId();
     $keys[] = 'SSL_' . intval(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') . '_';
     return $keys;
 }
Example #10
0
 /**
  * Inject child blocks
  *
  * @param $source
  * @param Mage_Core_Block_Abstract $block
  * @return mixed
  */
 public function injectChildBlocks($source, Mage_Core_Block_Abstract $block)
 {
     $count = null;
     $source = preg_replace_callback('/<!--\\s*###(.+)###\\s*-->(.*)<!--\\s*###\\/\\1###\\s*-->/s', function ($matches) use($block) {
         //if (Mage::getIsDeveloperMode()) {
         //    Mage::log('[Aoe_TemplateImport] Injecting block: ' . $matches[1]);
         //}
         return '<!-- BEGIN BLOCK: ' . $matches[1] . ' -->' . $block->getChildHtml($matches[1]) . '<!-- END BLOCK: ' . $matches[1] . ' -->';
     }, $source, -1, $count);
     //if (Mage::getIsDeveloperMode()) {
     //    Mage::log('[Aoe_TemplateImport] Match count: ' . $count);
     //}
     return $source;
 }
Example #11
0
 /**
  * Return first found child block of specified type, return false if not found
  * @param  Mage_Core_Block_Abstract $oParentBlock
  * @param  object $vType
  * @return bool
  */
 public function getChildByType(Mage_Core_Block_Abstract $oParentBlock, $vType)
 {
     $aChildrenBlocks = $oParentBlock->getChild();
     if (count($aChildrenBlocks)) {
         foreach ($aChildrenBlocks as $oBlock) {
             if ($oBlock instanceof $vType) {
                 return $oBlock;
             } elseif ($oGrandChild = $this->getChildByType($oBlock, $vType)) {
                 return $oGrandChild;
             }
         }
     }
     return false;
 }
Example #12
0
 protected function _afterToHtml($html)
 {
     $html = parent::_afterToHtml($html);
     $transport = new Varien_Object(array('html' => $html));
     Mage::dispatchEvent('aitsys_block_abstract_to_html_after', array('block' => $this, 'transport' => $transport));
     return $transport->getHtml();
 }
Example #13
0
 /**
  * Records information about new block creation
  * (non-PHPdoc)
  * @see Mage_Core_Model_Layout::_generateBlock()
  */
 protected function _generateBlock($node, $parent)
 {
     $this->_collectedBlock = null;
     parent::_generateBlock($node, $parent);
     if ($this->_collectedBlock !== null) {
         $target = $this->_collectedBlock->getNameInLayout();
         $params = array();
         if (isset($node['as'])) {
             $params['alias'] = (string) $node['as'];
         } else {
             $params['alias'] = $target;
         }
         if (isset($node['class'])) {
             $params['type'] = (string) $node['class'];
         } elseif (isset($node['type'])) {
             $params['type'] = (string) $node['type'];
         }
         $params['class'] = get_class($this->_collectedBlock);
         $params['is_root'] = isset($node['output']);
         $this->record(self::ACTION_BLOCK_CREATED, $target, $params);
         if (isset($node['template'])) {
             $this->record(self::ACTION_BLOCK_ACTION, $target . '::setTemplate', array('template' => (string) $node['template']));
         }
     }
     return $this;
 }
Example #14
0
 protected function _toHtml()
 {
     $standard = Mage::getModel('ep/initialize');
     $code = 'payment_block_' . $standard->getCode();
     $html = parent::_toHtml();
     $html .= '<p class="redirect-payment">' . $this->__('Sunteţi redirecţionat către modulul de plată, unde veţi putea introduce detaliile cardului dvs pentru a putea finaliza tranzacţia.') . "</p>";
     $html .= '<form name="' . $code . '" id="' . $code . '" method="POST" action="' . $standard->getUrl() . ($this->getNewwindow() ? ' target="' . strtoupper($code) . '"' : '') . '">';
     $formFields = $standard->getCheckoutFormFields();
     if (is_array($formFields)) {
         foreach ($formFields as $field => $value) {
             if (is_array($value)) {
                 if (count($value)) {
                     foreach ($value as $subvalue) {
                         $html .= '<input type="hidden" name="' . $field . '[]" value="' . $subvalue . '" />' . "\n";
                     }
                 }
             } else {
                 $html .= '<input type="hidden" name="' . $field . '" value="' . $value . '" />' . "\n";
             }
         }
     }
     $html .= '<p class="redirect-payment-button"><button type="submit">' . $this->__('Finalizează comanda') . '<sup>*</sup></button></p> <p class="redirect-payment"><sup>*</sup>' . $this->__('Daca nu sunteti redirectionat automat apasati "Finalizeaza comanda" pentru a putea finaliza tranzactia.') . '</p></form>' . "\n";
     if ('www' == substr($_SERVER['HTTP_HOST'], 0, 3)) {
         $html .= '<script type="text/javascript">document.getElementById("' . $code . '").submit();</script>';
     }
     return $html;
 }
 /**
  * Add an Varien_Object, which holds the total values, to the parent block.
  *
  * @param $total Varien_Object
  * @param $after null|string
  * @return Balticode_CashOnDelivery_Block_Totals_Abstract
  */
 protected function _addTotalToParent($total, $after = null)
 {
     if (!$after) {
         $after = Mage::helper('Balticode_Cashondelivery/data')->getTotalAfterPosition();
     }
     $this->_parentBlock->addTotal($total, $after);
     return $this;
 }
Example #16
0
 /**
  * {@inheritdoc}
  */
 public function getCacheKeyInfo()
 {
     $info = parent::getCacheKeyInfo();
     $blockId = $this->getBlockId();
     if ($blockId) {
         $info[] = 'CMSBLOCK_' . $blockId;
     }
     return $info;
 }
 /**
  * Add RP link to tab if we have all rates
  *
  * @return Enterprise_Reward_Block_Customer_Account
  */
 protected function _prepareLayout()
 {
     parent::_prepareLayout();
     $navigationBlock = $this->getLayout()->getBlock('customer_account_navigation');
     if ($navigationBlock && Mage::helper('enterprise_reward')->isEnabledOnFront()) {
         $navigationBlock->addLink('enterprise_reward', 'enterprise_reward/customer/info/', Mage::helper('enterprise_reward')->__('Reward Points'));
     }
     return $this;
 }
Example #18
0
 public function __construct()
 {
     /*$this->_controller = 'adminhtml_tips';
       $this->_blockGroup = 'aitcg';
       $this->_headerText = Mage::helper('aitcg')->__('Easy Tips');
       $this->_addButtonLabel = Mage::helper('aitcg')->__('Add Color Set');*/
     $this->setTemplate('aitcg/tips/cgfile.phtml');
     parent::__construct();
 }
Example #19
0
 /**
  * App isolation is enabled, because config options object is affected
  *
  * @magentoAppIsolation enabled
  */
 public function testGetVar()
 {
     Mage::getConfig()->getOptions()->setDesignDir(dirname(__DIR__) . '/Model/_files/design');
     Mage::getDesign()->setDesignTheme('test/default/default');
     $this->assertEquals('Core Value1', $this->_block->getVar('var1'));
     $this->assertEquals('value1', $this->_block->getVar('var1', 'Namespace_Module'));
     $this->_block->setModuleName('Namespace_Module');
     $this->assertEquals('value1', $this->_block->getVar('var1'));
     $this->assertEquals(false, $this->_block->getVar('unknown_var'));
 }
Example #20
0
 /**
  * @param Mage_Core_Block_Abstract $target
  * @param string[] $handlers
  * @param array $params
  * @return mixed
  */
 public function raise($target, $handlers, $params = array())
 {
     if (!empty($handlers)) {
         $event = new Varien_Object(array_merge($params, array('target' => $target, 'result' => false, 'stop_event_handling' => false)));
         foreach ($handlers as $handler) {
             $handler = explode('::', $handler);
             if ($object = $target->getLayout()->getBlock($handler[0])) {
                 $method = $handler[1];
                 $event->setResult($object->{$method}($event));
                 if ($event->getStopEventHandling()) {
                     break;
                 }
             }
         }
         return $event->getResult();
     } else {
         return false;
     }
 }
Example #21
0
 /**
  * Retrieve values of properties that unambiguously identify unique content
  *
  * @return array
  */
 public function getCacheKeyInfo()
 {
     $blockId = $this->getBlockId();
     if ($blockId) {
         $result = array('CMS_BLOCK', $blockId, Mage::app()->getStore()->getCode());
     } else {
         $result = parent::getCacheKeyInfo();
     }
     return $result;
 }
 public function __call($method, $args)
 {
     $helpers = Mage::getSingleton('emaildesign/config')->getVariablesHelpers();
     foreach ($helpers as $helperCode) {
         $helper = Mage::helper($helperCode);
         if (method_exists($helper, $method)) {
             return call_user_func(array($helper, $method), $this, $args);
         }
     }
     return parent::__call($method, $args);
 }
Example #23
0
 protected function _prepareLayout()
 {
     $head = $this->getLayout()->getBlock('head');
     $head->addItem('js_css', 'sm/dynamicslideshow/rs-plugin/css/settings.css');
     $head->addLinkRel('stylesheet', $this->getUrl('dynamicslideshow/index/getCssCaptions'));
     if (Mage::app()->getRequest()->getActionName() == 'preview') {
         $head->addJs('sm/dynamicslideshow/js/jquery-1.11.1.min.js');
         $head->addJs('sm/dynamicslideshow/js/jquery-noconflict.js');
     }
     return parent::_prepareLayout();
 }
Example #24
0
 /**
  * App isolation is enabled, because config options object is affected
  *
  * @magentoAppIsolation enabled
  * @magentoDbIsolation enabled
  */
 public function testGetVar()
 {
     /** @var $themeUtility Mage_Core_Utility_Theme */
     $themeUtility = Mage::getModel('Mage_Core_Utility_Theme', array(dirname(__DIR__) . '/Model/_files/design/'));
     $themeUtility->registerThemes()->setDesignTheme('test/default', 'frontend');
     $this->assertEquals('Core Value1', $this->_block->getVar('var1'));
     $this->assertEquals('value1', $this->_block->getVar('var1', 'Namespace_Module'));
     $this->_block->setModuleName('Namespace_Module');
     $this->assertEquals('value1', $this->_block->getVar('var1'));
     $this->assertEquals(false, $this->_block->getVar('unknown_var'));
 }
Example #25
0
 /**
  * Add tag to block
  *
  * @param string|array $tag
  * @return Mage_Core_Block_Abstract
  */
 public function addCacheTag($tag)
 {
     if (method_exists('Mage_Core_Block_Abstract', 'addCacheTag')) {
         return parent::addCacheTag($tag);
     }
     if (!is_array($tag)) {
         $tag = array($tag);
     }
     $this->addData(array('cache_tags' => $tag));
     return $this;
 }
 /**
  * Safe method for children to overrride w/o affecting the cache.
  *
  * @return string
  */
 protected function _renderBlock()
 {
     if (!$this->_block) {
         return null;
     }
     if (($html = $this->_block->toHtml()) == '') {
         // saves at least a space to prevent additional generation for the same cache key
         $html = ' ';
     }
     return $html;
 }
 /**
  * Get Placeholder Block
  *
  * @return Mage_Core_Block_Abstract
  */
 protected function _getPlaceHolderBlock()
 {
     if (null === $this->_placeholderBlock) {
         $blockName = $this->_placeholder->getAttribute('block');
         $this->_placeholderBlock = new $blockName();
         $this->_placeholderBlock->setTemplate($this->_placeholder->getAttribute('template'));
         $this->_placeholderBlock->setLayout(Mage::app()->getLayout());
         $this->_placeholderBlock->setSkipRenderTag(true);
     }
     return $this->_placeholderBlock;
 }
Example #28
0
 /**
  * Internal constructor, that is called from real constructor
  *
  */
 protected function _construct()
 {
     parent::_construct();
     /*
      * In case template was passed through constructor
      * we assign it to block's property _template
      * Mainly for those cases when block created
      * not via Mage_Core_Model_Layout::addBlock()
      */
     if ($this->hasData('template')) {
         $this->setTemplate($this->getData('template'));
     }
 }
Example #29
0
 protected function _prepareLayout()
 {
     parent::_prepareLayout();
     $parentBlock = $this->getParentBlock();
     if (!$parentBlock) {
         #Mage::Log("block is empty!");
         return;
     }
     $parentBlock->addLink($this->_('Approve Orders'), 'corporate/quote/approve', $this->_('Approve Orders'), true, array(), 50, null);
     //public function addLink($label, $url='', $title='', $prepare=false, $urlParams=array(),
     //$position=null, $liParams=null, $aParams=null, $beforeText='', $afterText='')
     // see Mage_Page_Block_Template_Links::addLink()
     return $this;
 }
Example #30
0
 /**
  * @test
  * @dataProvider blocksProvider
  */
 public function coreTextBlock(Mage_Core_Block_Abstract $block, array $regex, array $notRegex)
 {
     $this->assertEventObserverDefined('global', 'core_block_abstract_to_html_after', 'Aoe_TemplateHints_Model_Observer', 'core_block_abstract_to_html_after');
     $observer = Mage::getModel('aoe_templatehints/observer');
     /* @var $observer Aoe_TemplateHints_Model_Observer */
     $rendererFromObserver = $observer->getRenderer();
     $this->assertInstanceOf('Aoe_TemplateHints_Model_Renderer_Abstract', $rendererFromObserver);
     $this->assertInstanceOf('Aoe_TemplateHints_Model_Renderer_Opentip', $rendererFromObserver);
     $html = $block->toHtml();
     $this->assertEventDispatchedExactly('core_block_abstract_to_html_before', 1);
     $this->assertEventDispatchedExactly('core_block_abstract_to_html_after', 1);
     $this->assertContains('id="tpl-hint-', $html);
     $this->assertContains('class="tpl-hint tpl-hint-border', $html);
     $this->assertRegExp('/<div id="tpl-hint-\\d*-title"/', $html);
     $this->assertRegExp('/<div id="tpl-hint-\\d*-infobox"/', $html);
     $this->assertContains('<dt>Class:</dt><dd>' . get_class($block) . '</dd>', $html);
     foreach ($regex as $c) {
         $this->assertRegExp($c, $html);
     }
     Mage::app()->disableEvents();
     $rawBlockHtml = $block->toHtml();
     Mage::app()->enableEvents();
     $this->assertContains($rawBlockHtml, $html);
 }