From 3ad446bb2140d888adde4b195b948cd057e61ebf Mon Sep 17 00:00:00 2001 From: "Uwe.Tews" Date: Fri, 5 Feb 2010 17:03:22 +0000 Subject: [PATCH] - bugfix on modifier and block plugins with same name --- change_log.txt | 3 + .../smarty_internal_compile_block.php | 9 ++- .../smarty_internal_compile_function.php | 19 ++--- libs/sysplugins/smarty_internal_template.php | 27 ++++--- .../smarty_internal_templatecompilerbase.php | 80 +++++++++++++------ 5 files changed, 92 insertions(+), 46 deletions(-) diff --git a/change_log.txt b/change_log.txt index 6094767a..8e1bd260 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,3 +1,6 @@ +05/02/2010 +- bugfix on modifier and block plugins with same name + 02/02/2010 - retaining newlines at registered functions and function plugins diff --git a/libs/sysplugins/smarty_internal_compile_block.php b/libs/sysplugins/smarty_internal_compile_block.php index 45bca204..7956bc48 100644 --- a/libs/sysplugins/smarty_internal_compile_block.php +++ b/libs/sysplugins/smarty_internal_compile_block.php @@ -90,8 +90,13 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase { } $compiler->template->properties['file_dependency'] = array_merge($compiler->template->properties['file_dependency'], $_tpl->properties['file_dependency']); $compiler->template->properties['function'] = array_merge($compiler->template->properties['function'], $_tpl->properties['function']); - $compiler->template->required_plugins['compiled'] = array_merge($compiler->template->required_plugins['compiled'], $_tpl->required_plugins['compiled']); - $compiler->template->required_plugins['cache'] = array_merge($compiler->template->required_plugins['cache'], $_tpl->required_plugins['cache']); + foreach($_tpl->required_plugins as $code => $tmp1) { + foreach($tmp1 as $name => $tmp) { + foreach($tmp as $type => $data) { + $compiler->template->required_plugins[$code][$name][$type] = $data; + } + } + } unset($_tpl); } else { $_output = $compiler->template->extracted_compiled_code; diff --git a/libs/sysplugins/smarty_internal_compile_function.php b/libs/sysplugins/smarty_internal_compile_function.php index 23fc27d6..56c58648 100644 --- a/libs/sysplugins/smarty_internal_compile_function.php +++ b/libs/sysplugins/smarty_internal_compile_function.php @@ -68,25 +68,26 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase $plugins_string = ''; if (!empty($compiler->template->required_plugins['compiled'])) { $plugins_string = 'template->required_plugins['compiled'] as $plugin_name => $data) { - $plugin = 'smarty_' . $data['type'] . '_' . $plugin_name; - $plugins_string .= "if (!is_callable('{$plugin}')) include '{$data['file']}';\n"; + foreach($compiler->template->required_plugins['compiled'] as $tmp) { + foreach($tmp as $data) { + $plugins_string .= "if (!is_callable('{$data['function']}')) include '{$data['file']}';\n"; + } } $plugins_string .= '?>'; } if (!empty($compiler->template->required_plugins['cache'])) { $plugins_string .= "template->properties['nocache_hash']}%%*/template->required_plugins['cache'] as $plugin_name => $data) { - $plugin = 'smarty_' . $data['type'] . '_' . $plugin_name; - $plugins_string .= "if (!is_callable(\'{$plugin}\')) include \'{$data['file']}\';\n"; + foreach($compiler->template->required_plugins['nocache'] as $tmp) { + foreach($tmp as $data) { + $plugins_string .= "if (!is_callable('{$data['function']}')) include '{$data['file']}';\n"; + } } $plugins_string .= "?>/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/';?>\n"; } $compiler->template->properties['function'][$_name]['compiled'] = $plugins_string . $compiler->template->extracted_compiled_code; $compiler->template->properties['function'][$_name]['nocache_hash'] = $compiler->template->properties['nocache_hash']; - $compiler->template->properties['function'][$_name]['has_nocache_code'] = $compiler->template->has_nocache_code; -// $compiler->template->properties['function'][$_name]['plugins'] = $compiler->template->required_plugins; - $this->compiler->smarty->template_functions[$_name] = $compiler->template->properties['function'][$_name]; + $compiler->template->properties['function'][$_name]['has_nocache_code'] = $compiler->template->has_nocache_code; + $this->compiler->smarty->template_functions[$_name] = $compiler->template->properties['function'][$_name]; // restore old compiler status $compiler->template->extracted_compiled_code = $saved_data[1]; $compiler->template->extract_code = $saved_data[2]; diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index e6c5ac55..18c0e5f2 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -68,7 +68,7 @@ class Smarty_Internal_Template extends Smarty_Internal_Data { // storage for block data public $block_data = array(); // required plugins - public $required_plugins = array('compiled' => array(), 'cache' => array()); + public $required_plugins = array('compiled' => array(), 'nocache' => array()); /** * Create template data object @@ -451,8 +451,13 @@ class Smarty_Internal_Template extends Smarty_Internal_Data { } if ($this->parent instanceof Smarty_Template or $this->parent instanceof Smarty_Internal_Template) { $this->parent->properties['file_dependency'] = array_merge($this->parent->properties['file_dependency'], $this->properties['file_dependency']); - $this->parent->required_plugins['compiled'] = array_merge($this->parent->required_plugins['compiled'], $this->required_plugins['compiled']); - $this->parent->required_plugins['cache'] = array_merge($this->parent->required_plugins['cache'], $this->required_plugins['cache']); + foreach($this->required_plugins as $code => $tmp1) { + foreach($tmp1 as $name => $tmp) { + foreach($tmp as $type => $data) { + $this->parent->required_plugins[$code][$name][$type] = $data; + } + } + } } if ($this->smarty->debugging) { Smarty_Internal_Debug::end_render($this); @@ -722,18 +727,20 @@ class Smarty_Internal_Template extends Smarty_Internal_Data { if (!$cache) { if (!empty($this->required_plugins['compiled'])) { $plugins_string = 'required_plugins['compiled'] as $plugin_name => $data) { - $plugin = 'smarty_' . $data['type'] . '_' . $plugin_name; - $plugins_string .= "if (!is_callable('{$plugin}')) include '{$data['file']}';\n"; + foreach($this->required_plugins['compiled'] as $tmp) { + foreach($tmp as $data) { + $plugins_string .= "if (!is_callable('{$data['function']}')) include '{$data['file']}';\n"; + } } $plugins_string .= '?>'; } - if (!empty($this->required_plugins['cache'])) { + if (!empty($this->required_plugins['nocache'])) { $this->has_nocache_code = true; $plugins_string .= "properties['nocache_hash']}%%*/required_plugins['cache'] as $plugin_name => $data) { - $plugin = 'smarty_' . $data['type'] . '_' . $plugin_name; - $plugins_string .= "if (!is_callable(\'{$plugin}\')) include \'{$data['file']}\';\n"; + foreach($this->required_plugins['nocache'] as $tmp) { + foreach($tmp as $data) { + $plugins_string .= "if (!is_callable('{$data['function']}')) include '{$data['file']}';\n"; + } } $plugins_string .= "?>/*/%%SmartyNocache:{$this->properties['nocache_hash']}%%*/';?>\n"; } diff --git a/libs/sysplugins/smarty_internal_templatecompilerbase.php b/libs/sysplugins/smarty_internal_templatecompilerbase.php index e6e169ad..ac0ef840 100644 --- a/libs/sysplugins/smarty_internal_templatecompilerbase.php +++ b/libs/sysplugins/smarty_internal_templatecompilerbase.php @@ -15,15 +15,13 @@ class Smarty_Internal_TemplateCompilerBase { // hash for nocache sections private $nocache_hash = null; // suppress generation of nocache code - public $suppressNocacheProcessing = false; + public $suppressNocacheProcessing = false; // compile tag objects static $_tag_objects = array(); // tag stack public $_tag_stack = array(); // current template public $template = null; - // required plugins - public $required_plugins_call = array(); /** * Initialize compiler @@ -270,23 +268,47 @@ class Smarty_Internal_TemplateCompilerBase { */ public function getPlugin($plugin_name, $type) { - if (isset($this->template->required_plugins_call[$plugin_name][$type])) { - if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { - if (isset($this->template->required_plugins['compiled'][$plugin_name])) { - $this->template->required_plugins['cache'][$plugin_name] = $this->template->required_plugins['compiled'][$plugin_name]; - } - } else { - if (isset($this->template->required_plugins['cache'][$plugin_name])) { - $this->template->required_plugins['compiled'][$plugin_name] = $this->template->required_plugins['cache'][$plugin_name]; - } + $function = null; + if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { + if (isset($this->template->required_plugins['nocache'][$plugin_name][$type])) { + $function = $this->template->required_plugins['nocache'][$plugin_name][$type]['function']; + } else if (isset($this->template->required_plugins['compiled'][$plugin_name][$type])) { + $this->template->required_plugins['nocache'][$plugin_name][$type] = $this->template->required_plugins['compiled'][$plugin_name][$type]; + $function = $this->template->required_plugins['nocache'][$plugin_name][$type]['function']; } + } else { + if (isset($this->template->required_plugins['compiled'][$plugin_name][$type])) { + $function = $this->template->required_plugins['compiled'][$plugin_name][$type]['function']; + } else if (isset($this->template->required_plugins['compiled'][$plugin_name][$type])) { + $this->template->required_plugins['compiled'][$plugin_name][$type] = $this->template->required_plugins['nocache'][$plugin_name][$type]; + $function = $this->template->required_plugins['compiled'][$plugin_name][$type]['function']; + } + } + if (isset($function)) { if ($type == 'modifier') { $this->template->saved_modifer[$plugin_name] = true; } - return $this->template->required_plugins_call[$plugin_name][$type]; + return $function; } + /** + * if (isset($this->template->required_plugins_call[$plugin_name][$type])) { + * if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { + * if (isset($this->template->required_plugins['compiled'][$plugin_name])) { + * $this->template->required_plugins['cache'][$plugin_name] = $this->template->required_plugins['compiled'][$plugin_name]; + * } + * } else { + * if (isset($this->template->required_plugins['cache'][$plugin_name])) { + * $this->template->required_plugins['compiled'][$plugin_name] = $this->template->required_plugins['cache'][$plugin_name]; + * } + * } + * if ($type == 'modifier') { + * $this->template->saved_modifer[$plugin_name] = true; + * } + * return $this->template->required_plugins_call[$plugin_name][$type]; + * } + */ // loop through plugin dirs and find the plugin - $plugin = 'smarty_' . $type . '_' . $plugin_name; + $function = 'smarty_' . $type . '_' . $plugin_name; $found = false; foreach((array)$this->smarty->plugins_dir as $_plugin_dir) { $file = rtrim($_plugin_dir, '/\\') . DS . $type . '.' . $plugin_name . '.php'; @@ -298,23 +320,31 @@ class Smarty_Internal_TemplateCompilerBase { } if ($found) { // if (is_callable($plugin)) { - $this->template->required_plugins_call[$plugin_name][$type] = $plugin; if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { - $this->template->required_plugins['cache'][$plugin_name]['file'] = $file; - $this->template->required_plugins['cache'][$plugin_name]['type'] = $type; + $this->template->required_plugins['nocache'][$plugin_name][$type]['file'] = $file; + $this->template->required_plugins['nocache'][$plugin_name][$type]['function'] = $function; } else { - $this->template->required_plugins['compiled'][$plugin_name]['file'] = $file; - $this->template->required_plugins['compiled'][$plugin_name]['type'] = $type; + $this->template->required_plugins['compiled'][$plugin_name][$type]['file'] = $file; + $this->template->required_plugins['compiled'][$plugin_name][$type]['function'] = $function; } + /** + * $this->template->required_plugins_call[$plugin_name][$type] = $plugin; + * if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { + * $this->template->required_plugins['cache'][$plugin_name]['file'] = $file; + * $this->template->required_plugins['cache'][$plugin_name]['type'] = $type; + * } else { + * $this->template->required_plugins['compiled'][$plugin_name]['file'] = $file; + * $this->template->required_plugins['compiled'][$plugin_name]['type'] = $type; + * } + */ if ($type == 'modifier') { $this->template->saved_modifer[$plugin_name] = true; } - - return $plugin; + return $function; } - if (is_callable($plugin)) { + if (is_callable($function)) { // plugin function is defined in the script - return $plugin; + return $function; } return false; } @@ -344,8 +374,8 @@ class Smarty_Internal_TemplateCompilerBase { // make sure we include modifer plugins for nocache code if (isset($this->template->saved_modifer)) { foreach ($this->template->saved_modifer as $plugin_name => $dummy) { - if (isset($this->template->required_plugins['compiled'][$plugin_name])) { - $this->template->required_plugins['cache'][$plugin_name] = $this->template->required_plugins['compiled'][$plugin_name]; + if (isset($this->template->required_plugins['compiled'][$plugin_name]['modifier'])) { + $this->template->required_plugins['nocache'][$plugin_name]['modifier'] = $this->template->required_plugins['compiled'][$plugin_name]['modifier']; } } unset($this->template->saved_modifer);