diff --git a/app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php b/app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php index 56343127f..665af029b 100644 --- a/app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php +++ b/app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php @@ -21,19 +21,19 @@ class Nexcessnet_Turpentine_Block_Poll_ActivePoll extends Mage_Poll_Block_ActivePoll { - public function setTemplate($template) - { - if ((Mage::getConfig()->getModuleConfig('Mage_Poll')->is('active', 'true')) && - (!Mage::getStoreConfig('advanced/modules_disable_output/Mage_Poll'))) - { - $this->_template = $template; - $this->setPollTemplate('turpentine/ajax.phtml', 'poll'); - $this->setPollTemplate('turpentine/ajax.phtml', 'results'); - } - else - { - // Mage_Poll is disabled, so do nothing - } - return $this; - } + public function setTemplate($template) + { + if ((Mage::getConfig()->getModuleConfig('Mage_Poll')->is('active', 'true')) && + (!Mage::getStoreConfig('advanced/modules_disable_output/Mage_Poll'))) + { + $this->_template = $template; + $this->setPollTemplate('turpentine/ajax.phtml', 'poll'); + $this->setPollTemplate('turpentine/ajax.phtml', 'results'); + } + else + { + // Mage_Poll is disabled, so do nothing + } + return $this; + } } diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php b/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php index 00250a122..d9054c6fe 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php @@ -362,6 +362,32 @@ public function getFormKeyEsiUrl() { return $esiUrl; } + /** + * Grab a block node by name from the layout XML. + * + * Multiple blocks with the same name may exist in the layout, because some themes + * use 'unsetChild' to remove a block and create it with the same name somewhere + * else. For example Ultimo does this. + * + * @param Mage_Core_Model_Layout $layout + * @param string $blockName value of name= attribute in layout XML + * @return Mage_Core_Model_Layout_Element + */ + public function getEsiLayoutBlockNode($layout, $blockName) { + // first try very specific by checking for action setEsiOptions inside block + $blockNode = current($layout->getNode()->xpath( + sprintf('//block[@name=\'%s\'][action[@method=\'setEsiOptions\']]', + $blockName) + )); + // fallback: only match name + if ( ! ($blockNode instanceof Mage_Core_Model_Layout_Element)) { + $blockNode = current($layout->getNode()->xpath( + sprintf('//block[@name=\'%s\']', $blockName) + )); + } + return $blockNode; + } + /** * Load the ESI cache clear events from the layout * diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/Version.php b/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/Version.php index e88251213..0ce6b3f7b 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/Version.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/Version.php @@ -26,6 +26,7 @@ public function toOptionArray() { array('value' => '2.1', 'label' => $helper->__('2.1.x')), array('value' => '3.0', 'label' => $helper->__('3.0.x')), array('value' => '4.0', 'label' => $helper->__('4.0.x')), + array('value' => '4.1', 'label' => $helper->__('4.1.x')), array('value' => 'auto', 'label' => $helper->__('Auto')), ); } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php b/app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php index 4078fffb1..141c667b2 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php @@ -56,7 +56,7 @@ public function real_getFormKey() */ public function renewFormKey() { - $this->setData('_form_key', Mage::helper('core')->getRandomString(16)); + $this->setData('_form_key', Mage::helper('core')->getRandomString(16)); } /** diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php index 09d4a4c10..7cfc60dc0 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php @@ -227,9 +227,9 @@ public function injectEsi($eventObject) { 'Checking ESI block candidate: %s', $blockObject->getNameInLayout() ? $blockObject->getNameInLayout() : $blockObject->getModuleName() ); - $debugHelper->logInfo( "-- block testing: shouldResponseUseEsi = " . $esiHelper->shouldResponseUseEsi()); - $debugHelper->logInfo( "-- block testing: instanceof Mage_Core_Block_Template = " . $blockObject instanceof Mage_Core_Block_Template ); - $debugHelper->logInfo( "-- block testing: Esi Options = " . print_r($blockObject->getEsiOptions(), true) ); + $debugHelper->logInfo("-- block testing: shouldResponseUseEsi = ".$esiHelper->shouldResponseUseEsi()); + $debugHelper->logInfo("-- block testing: instanceof Mage_Core_Block_Template = ".$blockObject instanceof Mage_Core_Block_Template); + $debugHelper->logInfo("-- block testing: Esi Options = ".print_r($blockObject->getEsiOptions(), true)); } if ($esiHelper->shouldResponseUseEsi() && $blockObject instanceof Mage_Core_Block_Template && @@ -297,6 +297,11 @@ public function injectEsi($eventObject) { ); } + /** + * Keep params from original url + */ + $urlOptions['_query'] = Mage::app()->getRequest()->getParams(); + $esiUrl = Mage::getUrl('turpentine/esi/getBlock', $urlOptions); if ($esiOptions[$methodParam] == 'esi') { // setting [web/unsecure/base_url] can be https://... but ESI can never be HTTPS @@ -332,8 +337,8 @@ protected function _getEsiData($blockObject, $esiOptions) { $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->setDesignPackage(Mage::getDesign()->getPackageName()); + $esiData->setDesignTheme(Mage::getDesign()->getTheme('layout')); $esiData->setNameInLayout($blockObject->getNameInLayout()); $esiData->setBlockType(get_class($blockObject)); $esiData->setLayoutHandles($this->_getBlockLayoutHandles($blockObject)); @@ -415,9 +420,8 @@ protected function _getBlockLayoutHandles($block) { $activeHandles = array(); // get the xml node representing the block we're working on (from the // default handle probably) - $blockNode = current($layout->getNode()->xpath(sprintf( - '//block[@name=\'%s\']', - $block->getNameInLayout() ))); + $blockNode = Mage::helper('turpentine/esi')->getEsiLayoutBlockNode( + $layout, $block->getNameInLayout()); $childBlocks = Mage::helper('turpentine/data') ->getChildBlockNames($blockNode); foreach ($childBlocks as $blockName) { diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php index 7eb51c4e3..1fcadda7c 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php @@ -65,7 +65,8 @@ public function addProductListToolbarRewrite($eventObject) { */ public function fixCmRedisSessionLocks($eventObject) { if (Mage::helper('core')->isModuleEnabled('Cm_RedisSession')) { - if ( ! empty($_COOKIE['frontend']) && 'crawler-session' == $_COOKIE['frontend']) { + if ( ! empty($_COOKIE['frontend']) && 'crawler-session' == $_COOKIE['frontend'] && + ! defined('CM_REDISSESSION_LOCKING_ENABLED')) { define('CM_REDISSESSION_LOCKING_ENABLED', false); } } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php index 6dbb2115d..764f5dac5 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php @@ -138,7 +138,7 @@ protected function _testEsiSyntaxParam($socket) { $result = false; if ($helper->csrfFixupNeeded()) { - if ($socket->getVersion() === '4.0') { + if ($socket->getVersion() === '4.0' || $socket->getVersion() === '4.1') { $paramName = 'feature'; $value = $socket->param_show($paramName); $value = explode("\n", $value['text']); diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php index 7ae3ad6fa..ed4b92718 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php @@ -82,7 +82,7 @@ class Nexcessnet_Turpentine_Model_Varnish_Admin_Socket { // varnish default, can only be changed at Varnish startup time // if data to write is over this limit the actual run-time limit is checked // and used - const CLI_CMD_LENGTH_LIMIT = 8192; + const CLI_CMD_LENGTH_LIMIT = 16384; /** * Regexp to detect the varnish version number @@ -93,7 +93,7 @@ class Nexcessnet_Turpentine_Model_Varnish_Admin_Socket { /** * VCL config versions, should match config select values */ - static protected $_VERSIONS = array('2.1', '3.0', '4.0'); + static protected $_VERSIONS = array('2.1', '3.0', '4.0', '4.1'); /** * Varnish socket connection @@ -405,7 +405,7 @@ protected function _write($data) { if ($dataLength >= self::CLI_CMD_LENGTH_LIMIT) { $cliBufferResponse = $this->param_show('cli_buffer'); $regexp = '~^cli_buffer\s+(\d+)\s+\[bytes\]~'; - if ($this->getVersion() === '4.0') { + if ($this->getVersion() === '4.0' || $this->getVersion() === '4.1') { // Varnish4 supports "16k" style notation $regexp = '~^cli_buffer\s+Value is:\s+(\d+)([k|m|g|b]{1})?\s+\[bytes\]~'; } @@ -500,7 +500,7 @@ protected function _command($verb, $okCode = 200) { $response['code'], $response['text'] )); } else { if (Mage::getStoreConfig('turpentine_varnish/general/varnish_log_commands')) { - Mage::helper('turpentine/debug')->logDebug('VARNISH command sent: ' . $data); + Mage::helper('turpentine/debug')->logDebug('VARNISH command sent: '.$data); } return $response; } @@ -518,6 +518,7 @@ protected function _translateCommandMethod($verb) { case '2.1': $command = str_replace('ban', 'purge', $command); break; + case '4.1': case '4.0': case '3.0': $command = str_replace('purge', 'ban', $command); diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php index f539e2b41..d40efe3ea 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -40,6 +40,7 @@ static public function getFromSocket($socket) { } switch ($version) { case '4.0': + case '4.1': return Mage::getModel( 'turpentine/varnish_configurator_version4', array('socket' => $socket) ); @@ -110,8 +111,8 @@ public function save($generatedConfig) { * @return string */ protected function _getVclTemplateFilename($baseFilename) { - $extensionDir = Mage::getModuleDir('', 'Nexcessnet_Turpentine'); - return sprintf('%s/misc/%s', $extensionDir, $baseFilename); + $extensionDir = Mage::getModuleDir('', 'Nexcessnet_Turpentine'); + return sprintf('%s/misc/%s', $extensionDir, $baseFilename); } /** @@ -130,7 +131,7 @@ protected function _getVclFilename() { * * @return string */ - protected function _getCustomIncludeFilename($position='') { + protected function _getCustomIncludeFilename($position = '') { $key = 'custom_include_file'; $key .= ($position) ? '_'.$position : ''; return $this->_formatTemplate( @@ -150,8 +151,7 @@ protected function _getCustomTemplateFilename() { Mage::getStoreConfig('turpentine_varnish/servers/custom_vcl_template'), array('root_dir' => Mage::getBaseDir()) ); - if (is_file($filePath)) { return $filePath; } - else { return null; } + if (is_file($filePath)) { return $filePath; } else { return null; } } @@ -192,8 +192,8 @@ protected function _vcl_call($subroutine) { */ protected function _getAdminFrontname() { if (Mage::getStoreConfig('admin/url/use_custom_path')) { - if(Mage::getStoreConfig('web/url/use_store')) { - return Mage::getModel('core/store')->load(0)->getCode() . "/" . Mage::getStoreConfig('admin/url/custom_path'); + if (Mage::getStoreConfig('web/url/use_store')) { + return Mage::getModel('core/store')->load(0)->getCode()."/".Mage::getStoreConfig('admin/url/custom_path'); } else { return Mage::getStoreConfig('admin/url/custom_path'); } @@ -868,6 +868,7 @@ protected function _vcl_sub_maintenance_allowed_ips() { switch (Mage::getStoreConfig('turpentine_varnish/servers/version')) { case 4.0: + case 4.1: $tpl = <<_vcl_sub_synth(); - if(!$tpl){ + if ( ! $tpl) { $tpl = <<_vcl_sub_https_redirect_fix(); - if(Mage::getStoreConfig('turpentine_varnish/servers/version') == '4.0'){ + if (Mage::getStoreConfig('turpentine_varnish/servers/version') == '4.0' || Mage::getStoreConfig('turpentine_varnish/servers/version') == '4.1') { $vars['vcl_synth'] = $this->_vcl_sub_synth_https_fix(); } } - foreach (array('','top') as $position) { + foreach (array('', 'top') as $position) { $customIncludeFile = $this->_getCustomIncludeFilename($position); if (is_readable($customIncludeFile)) { $key = 'custom_vcl_include'; diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php index 2247404b0..d025b737c 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php @@ -35,8 +35,7 @@ public function generate($doClean = true) { $customTemplate = $this->_getCustomTemplateFilename(); if ($customTemplate) { $tplFile = $customTemplate; - } - else { + } else { $tplFile = $this->_getVclTemplateFilename(self::VCL_TEMPLATE_FILE); } $vcl = $this->_formatTemplate(file_get_contents($tplFile), diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php index 72512cbcf..78c44c642 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php @@ -35,8 +35,7 @@ public function generate($doClean = true) { $customTemplate = $this->_getCustomTemplateFilename(); if ($customTemplate) { $tplFile = $customTemplate; - } - else { + } else { $tplFile = $this->_getVclTemplateFilename(self::VCL_TEMPLATE_FILE); } $vcl = $this->_formatTemplate(file_get_contents($tplFile), @@ -94,13 +93,13 @@ protected function _vcl_directors() $backendNodes = Mage::helper('turpentine/data')->cleanExplode(PHP_EOL, Mage::getStoreConfig('turpentine_vcl/backend/backend_nodes')); - for($i = 0, $iMax = count($backendNodes); $i < $iMax; $i++) { + for ($i = 0, $iMax = count($backendNodes); $i < $iMax; $i++) { $tpl .= <<_vcl_director_backend($host, $port, $prefix . $number, $probeUrl, $backendOptions); + $backends .= $this->_vcl_director_backend($host, $port, $prefix.$number, $probeUrl, $backendOptions); $number++; } diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php index c7c136cdf..576e77c34 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php @@ -183,9 +183,9 @@ protected function _getEsiBlock($esiData) { } } $layout = Mage::getSingleton('core/layout'); - Mage::getSingleton( 'core/design_package' ) - ->setPackageName( $esiData->getDesignPackage() ) - ->setTheme( $esiData->getDesignTheme() ); + Mage::getSingleton('core/design_package') + ->setPackageName($esiData->getDesignPackage()) + ->setTheme($esiData->getDesignTheme()); // dispatch event for adding handles to layout update Mage::dispatchEvent( @@ -212,10 +212,8 @@ protected function _getEsiBlock($esiData) { $turpentineHelper = Mage::helper('turpentine/data') ->setLayout($layout); - $blockNode = current($layout->getNode()->xpath( - sprintf('//block[@name=\'%s\']', $esiData->getNameInLayout()) - )); - + $blockNode = Mage::helper('turpentine/esi')->getEsiLayoutBlockNode( + $layout, $esiData->getNameInLayout()); if ( ! ($blockNode instanceof Mage_Core_Model_Layout_Element)) { Mage::helper('turpentine/debug')->logWarn( 'No block node found with @name="%s"', diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index 7934d4e8e..894453a34 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -20,7 +20,7 @@ - 0.7.1 + 0.7.2 diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index 5b5758b8d..470183f62 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -127,7 +127,7 @@ sub vcl_recv { if (!{{enable_caching}} || req.http.Authorization || req.method !~ "^(GET|HEAD|OPTIONS)$" || req.http.Cookie ~ "varnish_bypass={{secret_handshake}}") { - return (pass); + return (pipe); } if({{send_unmodified_url}}) { diff --git a/contrib/tools/esi-decoder.php b/contrib/tools/esi-decoder.php index cf2bb6685..553e3f2fa 100644 --- a/contrib/tools/esi-decoder.php +++ b/contrib/tools/esi-decoder.php @@ -1,16 +1,16 @@