- bugfix {block.. hide} did not work as nested child (Forum Topic 22216)

This commit is contained in:
uwe.tews@googlemail.com
2012-06-30 15:53:22 +00:00
parent 79087f409f
commit ab1cdc8d84
2 changed files with 92 additions and 85 deletions

View File

@@ -1,4 +1,7 @@
===== trunk =====
30.06.2012
- bugfix {block.. hide} did not work as nested child (Forum Topic 22216)
25.06.2012
- bugfix the default plugin handler did not allow static class methods for modifier (issue 85)

View File

@@ -1,4 +1,5 @@
<?php
/**
* Smarty Internal Plugin Compile Block
*
@@ -24,6 +25,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
* @see Smarty_Internal_CompileBase
*/
public $required_attributes = array('name');
/**
* Attribute definition: Overwrites base class.
*
@@ -31,6 +33,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
* @see Smarty_Internal_CompileBase
*/
public $shorttag_order = array('name', 'hide');
/**
* Attribute definition: Overwrites base class.
*
@@ -46,8 +49,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
* @param object $compiler compiler object
* @return boolean true
*/
public function compile($args, $compiler)
{
public function compile($args, $compiler) {
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$save = array($_attr, $compiler->parser->current_buffer, $compiler->nocache, $compiler->smarty->merge_compiled_includes, $compiler->merged_templates, $compiler->smarty->merged_templates_func, $compiler->template->properties, $compiler->template->has_nocache_code);
@@ -73,8 +75,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
* @param object $template template object
* @param string $filepath filepath of template source
*/
public static function saveBlockData($block_content, $block_tag, $template, $filepath)
{
public static function saveBlockData($block_content, $block_tag, $template, $filepath) {
$_rdl = preg_quote($template->smarty->right_delimiter);
$_ldl = preg_quote($template->smarty->left_delimiter);
if ($template->smarty->auto_literal) {
@@ -89,10 +90,11 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
$_name = trim($_match[3], '\'"');
if ($_match[8] != 'hide' || isset($template->block_data[$_name])) { // replace {$smarty.block.child}
// do we have {$smart.block.child} in nested {block} tags?
if (0 != preg_match_all("!({$_ldl}{$al}block\s+)(name=)?(\w+|'.*'|\".*\")([\s\S]*?{$_rdl})([\s\S]*?)({$_ldl}{$al}\\\$smarty\.block\.child{$_rdl})([\s\S]*?{$_ldl}{$al}/block{$_rdl})!", $block_content, $_match2)) {
foreach($_match2[3] as $name) {
if (0 != preg_match_all("!({$_ldl}{$al}block\s+)(name=)?(\w+|'.*'|\".*\")([\s\S]*?)(hide)?(\s*{$_rdl})([\s\S]*?)({$_ldl}{$al}\\\$smarty\.block\.child{$_rdl})([\s\S]*?{$_ldl}{$al}/block{$_rdl})!", $block_content, $_match2)) {
foreach ($_match2[3] as $key => $name) {
// get it's replacement
$_name2 = trim($name, '\'"');
if ($_match2[5][$key] != 'hide' || isset($template->block_data[$_name2])) {
if (isset($template->block_data[$_name2])) {
$replacement = $template->block_data[$_name2]['source'];
} else {
@@ -102,6 +104,10 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
$search = array("%({$_ldl}{$al}block[\s\S]*?{$name}[\s\S]*?{$_rdl})([\s\S]*?)({$_ldl}{$al}\\\$smarty\.block\.child{$_rdl})([\s\S]*?)({$_ldl}{$al}/block{$_rdl})%", "/<2F><><EFBFBD>child<6C><64><EFBFBD>/");
$replace = array('\2<><32><EFBFBD>child<6C><64><EFBFBD>\4', $replacement);
$block_content = preg_replace($search, $replace, $block_content);
} else {
// remove hidden blocks
$block_content = preg_replace("%({$_ldl}{$al}block[\s\S]*?{$name}[\s\S]*?{$_rdl}[\s\S]*?{$_ldl}{$al}/block{$_rdl})%", '', $block_content);
}
}
}
// do we have not nested {$smart.block.child}
@@ -146,8 +152,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
* @param string $_name optional name of child block
* @return string compiled code of schild block
*/
public static function compileChildBlock($compiler, $_name = null)
{
public static function compileChildBlock($compiler, $_name = null) {
$_output = '';
// if called by {$smarty.block.child} we must search the name of enclosing {block}
if ($_name == null) {
@@ -231,8 +236,7 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase {
* @param object $compiler compiler object
* @return string compiled code
*/
public function compile($args, $compiler)
{
public function compile($args, $compiler) {
$compiler->has_code = true;
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);