- added support of nested {bock} tags

This commit is contained in:
Uwe.Tews
2010-02-12 01:14:34 +00:00
parent cb0ba1908a
commit 99ab6e96a5
3 changed files with 81 additions and 64 deletions

View File

@@ -1,3 +1,6 @@
12/02/2010
- added support of nested {bock} tags
10/02/2010 10/02/2010
- avoid possible notice on $smarty->cache->clear(...), $smarty->clear_cache(....) - avoid possible notice on $smarty->cache->clear(...), $smarty->clear_cache(....)
- allow Smarty tags inside <? ... ?> tags in SMARTY_PHP_QUOTE and SMARTY_PHP_PASSTHRU mode - allow Smarty tags inside <? ... ?> tags in SMARTY_PHP_QUOTE and SMARTY_PHP_PASSTHRU mode

View File

@@ -41,11 +41,18 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase {
preg_match_all("!({$this->_ldl}/block(.*?){$this->_rdl})!", $_old_source, $c, PREG_OFFSET_CAPTURE)) { preg_match_all("!({$this->_ldl}/block(.*?){$this->_rdl})!", $_old_source, $c, PREG_OFFSET_CAPTURE)) {
$this->compiler->trigger_template_error('unmatched {block} {/block} pairs'); $this->compiler->trigger_template_error('unmatched {block} {/block} pairs');
} }
$block_count = count($s[0]); preg_match_all("!{$this->_ldl}block(.+?){$this->_rdl}|{$this->_ldl}/block.*{$this->_rdl}!", $_old_source, $_result, PREG_OFFSET_CAPTURE);
for ($i = 0; $i < $block_count; $i++) { $_result_count = count($_result[0]);
$block_content = str_replace($this->smarty->left_delimiter . '$smarty.parent' . $this->smarty->right_delimiter, '%%%%SMARTY_PARENT%%%%', $_i = 0;
substr($_old_source, $s[0][$i][1] + strlen($s[0][$i][0]), $c[0][$i][1] - $s[0][$i][1] - strlen($s[0][$i][0]))); while ($_i < $_result_count) {
$this->saveBlockData($block_content, $s[0][$i][0], $compiler->template); $_ii = 1;
while (!strpos($_result[0][$_i + $_ii][0], '/')) {
$_ii++;
}
$_block_content = str_replace($this->smarty->left_delimiter . '$smarty.parent' . $this->smarty->right_delimiter, '%%%%SMARTY_PARENT%%%%',
substr($_old_source, $_result[0][$_i][1] + strlen($_result[0][$_i][0]), $_result[0][$_i-1 + 2 * $_ii][1] - $_result[0][$_i][1] - + strlen($_result[0][$_i][0])));
$this->saveBlockData($_block_content, $_result[0][$_i][0], $compiler->template);
$_i = $_i + 2 * $_ii;
} }
$compiler->template->template_source = $_template->getTemplateSource(); $compiler->template->template_source = $_template->getTemplateSource();
$compiler->template->template_filepath = $_template->getTemplateFilepath(); $compiler->template->template_filepath = $_template->getTemplateFilepath();

View File

@@ -100,13 +100,20 @@ class Smarty_Internal_Resource_Extends {
if ($_filepath != $_files[count($_files)-1]) { if ($_filepath != $_files[count($_files)-1]) {
if (preg_match_all("!({$this->_ldl}block(.+?){$this->_rdl})!", $_content, $_open, PREG_OFFSET_CAPTURE) != if (preg_match_all("!({$this->_ldl}block(.+?){$this->_rdl})!", $_content, $_open, PREG_OFFSET_CAPTURE) !=
preg_match_all("!({$this->_ldl}/block(.*?){$this->_rdl})!", $_content, $_close, PREG_OFFSET_CAPTURE)) { preg_match_all("!({$this->_ldl}/block(.*?){$this->_rdl})!", $_content, $_close, PREG_OFFSET_CAPTURE)) {
$this->smarty->trigger_error('unmatched {block} {/block} pairs'); $this->smarty->trigger_error("unmatched {block} {/block} pairs in file '$_filepath'");
}
preg_match_all("!{$this->_ldl}block(.+?){$this->_rdl}|{$this->_ldl}/block.*{$this->_rdl}!", $_content, $_result, PREG_OFFSET_CAPTURE);
$_result_count = count($_result[0]);
$_i = 0;
while ($_i < $_result_count) {
$_ii = 1;
while (!strpos($_result[0][$_i + $_ii][0], '/')) {
$_ii++;
} }
$_block_count = count($_open[0]);
for ($_i = 0; $_i < $_block_count; $_i++) {
$_block_content = str_replace($this->smarty->left_delimiter . '$smarty.parent' . $this->smarty->right_delimiter, '%%%%SMARTY_PARENT%%%%', $_block_content = str_replace($this->smarty->left_delimiter . '$smarty.parent' . $this->smarty->right_delimiter, '%%%%SMARTY_PARENT%%%%',
substr($_content, $_open[0][$_i][1] + strlen($_open[0][$_i][0]), $_close[0][$_i][1] - $_open[0][$_i][1] - strlen($_open[0][$_i][0]))); substr($_content, $_result[0][$_i][1]+strlen($_result[0][$_i][0]), $_result[0][$_i-1 + 2 * $_ii][1] - $_result[0][$_i][1] - +strlen($_result[0][$_i][0])));
$this->saveBlockData($_block_content, $_open[0][$_i][0], $_filepath); $this->saveBlockData($_block_content, $_result[0][$_i][0], $_filepath);
$_i = $_i + 2 * $_ii;
} }
} else { } else {
$_template->template_source = $_content; $_template->template_source = $_content;
@@ -118,7 +125,7 @@ class Smarty_Internal_Resource_Extends {
protected function saveBlockData($block_content, $block_tag, $_filepath) protected function saveBlockData($block_content, $block_tag, $_filepath)
{ {
if (0 == preg_match("!(.?)(name=)(.*?)(?=(\s|{$this->_rdl}))!", $block_tag, $_match)) { if (0 == preg_match("!(.?)(name=)(.*?)(?=(\s|{$this->_rdl}))!", $block_tag, $_match)) {
$this->smarty->trigger_error("'{$block_tag}' missing name attribute"); $this->smarty->trigger_error("'{$block_tag}' missing name attribute in file '$_filepath'");
} else { } else {
$_name = trim($_match[3], '\'"'); $_name = trim($_match[3], '\'"');
if (isset($this->smarty->block_data[$_name])) { if (isset($this->smarty->block_data[$_name])) {