- allow {function} tags within {block} tags

This commit is contained in:
Uwe.Tews
2009-11-30 19:56:17 +00:00
parent 319f0c88fb
commit 89e53f6372
4 changed files with 23 additions and 9 deletions

View File

@@ -1,5 +1,6 @@
11/30/2009
- map 'true' to SMARTY_CACHING_LIFETIME_CURRENT for the $smarty->caching parameter
- allow {function} tags within {block} tags
11/28/2009
- ignore compile_id at debug template

View File

@@ -72,6 +72,13 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase {
} elseif (!empty($this->smarty->block_data[$_name])) {
$_output = $this->smarty->block_data[$_name]['compiled'];
}
if (isset($this->smarty->block_data[$_name]['function'])) {
if (isset($compiler->template->properties['function'])) {
$compiler->template->properties['function'] = array_merge ($compiler->template->properties['function'], $this->smarty->block_data[$_name]['function']);
} else {
$compiler->template->properties['function'] = $this->smarty->block_data[$_name]['function'];
}
}
} else {
$_output = $compiler->template->extracted_compiled_code;
}
@@ -79,7 +86,7 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase {
$compiler->template->extract_code = $saved_data[2];
// check for includes in block tags
preg_match('/(\<\?php \$_smarty_tpl-\>decodeProperties\(\')(.*)(\'.*\?\>)/', $_output, $matches);
$_output = preg_replace(array('/(\<\?php \$_smarty_tpl-\>decodeProperties\(\')(.*)(\'.*\?\>.*\n)/', '/(\<\?php if\(\!defined\(\'SMARTY_DIR\'\)\))(.*)(\?\>.*\n)/'), '', $_output);
$_output = preg_replace(array('/(\<\?php \$_smarty_tpl-\>decodeProperties\(\')(.*)(\'.*\?\>.*\n)/', '/(\<\?php if\(\!defined\(\'SMARTY_DIR\'\)\))(.*)(\?\>.*\n)/'), '', $_output);
if (isset($matches[2])) {
$prop = unserialize($matches[2]);
$compiler->template->properties['file_dependency'] = array_merge($compiler->template->properties['file_dependency'], $prop['file_dependency']);

View File

@@ -23,7 +23,7 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase {
public function compile($args, $compiler)
{
$this->compiler = $compiler;
$this->smarty =$compiler->smarty;
$this->smarty = $compiler->smarty;
$this->required_attributes = array('file');
// check and get attributes
$_attr = $this->_get_attributes($args);
@@ -33,7 +33,7 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase {
// create template object
$_template = new Smarty_Template ($include_file, $this->smarty, $compiler->template);
// save file dependency
$compiler->template->properties['file_dependency']['F'.abs(crc32($_template->getTemplateFilepath()))] = array($_template->getTemplateFilepath(), $_template->getTemplateTimestamp());
$compiler->template->properties['file_dependency']['F' . abs(crc32($_template->getTemplateFilepath()))] = array($_template->getTemplateFilepath(), $_template->getTemplateTimestamp());
$_old_source = $compiler->template->template_source;
if (preg_match_all('/(' . $this->smarty->left_delimiter . 'block(.+?)' . $this->smarty->right_delimiter . ')/', $_old_source, $s, PREG_OFFSET_CAPTURE) !=
preg_match_all('/(' . $this->smarty->left_delimiter . '\/block(.*?)' . $this->smarty->right_delimiter . ')/', $_old_source, $c, PREG_OFFSET_CAPTURE)) {
@@ -43,24 +43,23 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase {
for ($i = 0; $i < $block_count; $i++) {
$block_content = str_replace($this->smarty->left_delimiter . '$smarty.parent' . $this->smarty->right_delimiter, '%%%%SMARTY_PARENT%%%%',
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])));
$this->saveBlockData($block_content, $s[0][$i][0],$compiler->template);
$this->saveBlockData($block_content, $s[0][$i][0], $compiler->template);
}
$compiler->template->template_source = $_template->getTemplateSource();
$compiler->abort_and_recompile = true;
return ' ';
}
protected function saveBlockData($block_content, $block_tag,$template)
protected function saveBlockData($block_content, $block_tag, $template)
{
if (0 == preg_match('/(.?)(name=)([^ ]*)/', $block_tag, $_match)) {
$this->compiler->trigger_template_error("\"" . $block_tag . "\" missing name attribute");
} else {
// compile block content
$_tpl = $this->smarty->createTemplate('string:' . $block_content,null,null,$template);
$_tpl = $this->smarty->createTemplate('string:' . $block_content, null, null, $template);
$_tpl->template_filepath = $this->compiler->template->getTemplateFilepath();
$_tpl->forceNocache= true;
$_tpl->forceNocache = true;
$_compiled_content = $_tpl->getCompiledTemplate();
unset($_tpl);
$_name = trim($_match[3], "\"'}");
if (isset($this->smarty->block_data[$_name])) {
@@ -82,6 +81,10 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase {
} else {
$this->smarty->block_data[$_name]['mode'] = 'replace';
}
if (isset($_tpl->properties['function'])) {
$this->smarty->block_data[$_name]['function'] = $_tpl->properties['function'];
}
unset($_tpl);
}
}
}

View File

@@ -113,7 +113,6 @@ class Smarty_Internal_Resource_Extends {
$_tpl->template_filepath = $this->template->getTemplateFilepath();
$_tpl->forceNocache= true;
$_compiled_content = $_tpl->getCompiledTemplate();
unset($_tpl);
$_name = trim($_match[3], "\"'}");
if (isset($this->smarty->block_data[$_name])) {
@@ -135,6 +134,10 @@ class Smarty_Internal_Resource_Extends {
} else {
$this->smarty->block_data[$_name]['mode'] = 'replace';
}
if (isset($_tpl->properties['function'])) {
$this->smarty->block_data[$_name]['function'] = $_tpl->properties['function'];
}
unset($_tpl);
}
}