- bugfix at extend resource: create unique files for compiled template and cache for each combination of template files

- update extend resource to handle appen and prepend block attributes
This commit is contained in:
Uwe.Tews
2009-06-13 20:39:56 +00:00
parent 30bd8f119b
commit 06ce127133
3 changed files with 32 additions and 20 deletions

View File

@@ -1,3 +1,7 @@
06/13/2009
- bugfix at extend resource: create unique files for compiled template and cache for each combination of template files
- update extend resource to handle appen and prepend block attributes
06/03/2009 06/03/2009
- fixed repeat at block plugins - fixed repeat at block plugins

View File

@@ -144,7 +144,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_Internal_PluginBase {
*/ */
private function buildCachedFilepath ($resource_name, $cache_id, $compile_id) private function buildCachedFilepath ($resource_name, $cache_id, $compile_id)
{ {
// $_filepath = md5($resource_name); $_files = explode('|',$resource_name);
$_filepath = (string)abs(crc32($resource_name)); $_filepath = (string)abs(crc32($resource_name));
// if use_sub_dirs, break file into directories // if use_sub_dirs, break file into directories
if ($this->smarty->use_sub_dirs) { if ($this->smarty->use_sub_dirs) {
@@ -169,7 +169,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_Internal_PluginBase {
$_cache_dir .= DIRECTORY_SEPARATOR; $_cache_dir .= DIRECTORY_SEPARATOR;
} }
return $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($resource_name) . $this->smarty->php_ext; return $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_files[0]) . $this->smarty->php_ext;
} }
} }

View File

@@ -70,31 +70,40 @@ class Smarty_Internal_Resource_Extend extends Smarty_Internal_Base {
$_template->template_source = $_content; $_template->template_source = $_content;
} }
} }
} }
protected function saveBlockData(array $matches) protected function saveBlockData(array $matches)
{ {
if (0 == preg_match('/(.?)(name=)(.*)/', $matches[2], $_match)) { if (0 == preg_match('/(.?)(name=)([^ ]*)/', $matches[2], $_match)) {
$this->compiler->trigger_template_error("\"" . $matches[0] . "\" missing name attribute"); $this->compiler->trigger_template_error("\"" . $matches[0] . "\" missing name attribute");
} else { } else {
// compile block content
$_tpl = $this->smarty->createTemplate('string:' . $matches[3]);
$_tpl->suppressHeader = true;
$_compiled_content = $_tpl->getCompiledTemplate();
unset($_tpl);
$_name = trim($_match[3], "\"'"); $_name = trim($_match[3], "\"'");
if (!isset($this->template->block_data[$_name])) {
// check for smarty possible tags if (isset($this->template->block_data[$_name])) {
if (strpos($matches[3], $this->smarty->left_delimiter) === false) { if ($this->template->block_data[$_name]['mode'] == 'prepend') {
// output as is $this->template->block_data[$_name]['compiled'] .= $_compiled_content;
$_output = $matches[3]; $this->template->block_data[$_name]['source'] .= $matches[3];
} else { } elseif ($this->template->block_data[$_name]['mode'] == 'append') {
// tags in $_content will be precompiled and compiled code is returnd $this->template->block_data[$_name]['compiled'] = $_compiled_content . $this->template->block_data[$_name]['compiled'];
$tpl = $this->smarty->createTemplate('string:' . $matches[3]); $this->template->block_data[$_name]['source'] = $matches[3] . $this->template->block_data[$_name]['source'];
$tpl->suppressHeader = true;
$_output = $tpl->getCompiledTemplate();
$tpl->suppressHeader = false;
// $_output = '<?php echo $_smarty_tpl->smarty->fetch(\'string:' . addcslashes($_content,"'") . '\', $_smarty_tpl); ? >';
} }
} else {
$this->template->block_data[$_name]['compiled'] = $_compiled_content;
$this->template->block_data[$_name]['source'] = $matches[3]; $this->template->block_data[$_name]['source'] = $matches[3];
$this->template->block_data[$_name]['compiled'] = $_output; }
if (preg_match('/(.?)(append=true)(.*)/', $matches[2], $_match) != 0) {
$this->template->block_data[$_name]['mode'] = 'append';
} elseif (preg_match('/(.?)(prepend=true)(.*)/', $matches[2], $_match) != 0) {
$this->template->block_data[$_name]['mode'] = 'prepend';
} else {
$this->template->block_data[$_name]['mode'] = 'replace';
} }
} }
} }
/** /**
* Return flag that this resource uses the compiler * Return flag that this resource uses the compiler
@@ -126,8 +135,7 @@ class Smarty_Internal_Resource_Extend extends Smarty_Internal_Base {
public function getCompiledFilepath($_template) public function getCompiledFilepath($_template)
{ {
$_files = explode('|', $_template->resource_name); $_files = explode('|', $_template->resource_name);
// $_filepath = md5($_files[0]); $_filepath = (string)abs(crc32($_template->resource_name));
$_filepath = (string)abs(crc32($_files[0]));
// if use_sub_dirs, break file into directories // if use_sub_dirs, break file into directories
if ($_template->smarty->use_sub_dirs) { if ($_template->smarty->use_sub_dirs) {
$_filepath = substr($_filepath, 0, 3) . DIRECTORY_SEPARATOR $_filepath = substr($_filepath, 0, 3) . DIRECTORY_SEPARATOR