- bugfix on modifier and block plugins with same name

This commit is contained in:
Uwe.Tews
2010-02-05 17:03:22 +00:00
parent fde7a592f4
commit 3ad446bb21
5 changed files with 92 additions and 46 deletions

View File

@@ -1,3 +1,6 @@
05/02/2010
- bugfix on modifier and block plugins with same name
02/02/2010 02/02/2010
- retaining newlines at registered functions and function plugins - retaining newlines at registered functions and function plugins

View File

@@ -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['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->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']); foreach($_tpl->required_plugins as $code => $tmp1) {
$compiler->template->required_plugins['cache'] = array_merge($compiler->template->required_plugins['cache'], $_tpl->required_plugins['cache']); foreach($tmp1 as $name => $tmp) {
foreach($tmp as $type => $data) {
$compiler->template->required_plugins[$code][$name][$type] = $data;
}
}
}
unset($_tpl); unset($_tpl);
} else { } else {
$_output = $compiler->template->extracted_compiled_code; $_output = $compiler->template->extracted_compiled_code;

View File

@@ -68,24 +68,25 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$plugins_string = ''; $plugins_string = '';
if (!empty($compiler->template->required_plugins['compiled'])) { if (!empty($compiler->template->required_plugins['compiled'])) {
$plugins_string = '<?php '; $plugins_string = '<?php ';
foreach($compiler->template->required_plugins['compiled'] as $plugin_name => $data) { foreach($compiler->template->required_plugins['compiled'] as $tmp) {
$plugin = 'smarty_' . $data['type'] . '_' . $plugin_name; foreach($tmp as $data) {
$plugins_string .= "if (!is_callable('{$plugin}')) include '{$data['file']}';\n"; $plugins_string .= "if (!is_callable('{$data['function']}')) include '{$data['file']}';\n";
}
} }
$plugins_string .= '?>'; $plugins_string .= '?>';
} }
if (!empty($compiler->template->required_plugins['cache'])) { if (!empty($compiler->template->required_plugins['cache'])) {
$plugins_string .= "<?php echo '/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php "; $plugins_string .= "<?php echo '/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php ";
foreach($compiler->template->required_plugins['cache'] as $plugin_name => $data) { foreach($compiler->template->required_plugins['nocache'] as $tmp) {
$plugin = 'smarty_' . $data['type'] . '_' . $plugin_name; foreach($tmp as $data) {
$plugins_string .= "if (!is_callable(\'{$plugin}\')) include \'{$data['file']}\';\n"; $plugins_string .= "if (!is_callable('{$data['function']}')) include '{$data['file']}';\n";
}
} }
$plugins_string .= "?>/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/';?>\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]['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]['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]['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]; $this->compiler->smarty->template_functions[$_name] = $compiler->template->properties['function'][$_name];
// restore old compiler status // restore old compiler status
$compiler->template->extracted_compiled_code = $saved_data[1]; $compiler->template->extracted_compiled_code = $saved_data[1];

View File

@@ -68,7 +68,7 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
// storage for block data // storage for block data
public $block_data = array(); public $block_data = array();
// required plugins // required plugins
public $required_plugins = array('compiled' => array(), 'cache' => array()); public $required_plugins = array('compiled' => array(), 'nocache' => array());
/** /**
* Create template data object * 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) { 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->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']); foreach($this->required_plugins as $code => $tmp1) {
$this->parent->required_plugins['cache'] = array_merge($this->parent->required_plugins['cache'], $this->required_plugins['cache']); foreach($tmp1 as $name => $tmp) {
foreach($tmp as $type => $data) {
$this->parent->required_plugins[$code][$name][$type] = $data;
}
}
}
} }
if ($this->smarty->debugging) { if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_render($this); Smarty_Internal_Debug::end_render($this);
@@ -722,18 +727,20 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
if (!$cache) { if (!$cache) {
if (!empty($this->required_plugins['compiled'])) { if (!empty($this->required_plugins['compiled'])) {
$plugins_string = '<?php '; $plugins_string = '<?php ';
foreach($this->required_plugins['compiled'] as $plugin_name => $data) { foreach($this->required_plugins['compiled'] as $tmp) {
$plugin = 'smarty_' . $data['type'] . '_' . $plugin_name; foreach($tmp as $data) {
$plugins_string .= "if (!is_callable('{$plugin}')) include '{$data['file']}';\n"; $plugins_string .= "if (!is_callable('{$data['function']}')) include '{$data['file']}';\n";
}
} }
$plugins_string .= '?>'; $plugins_string .= '?>';
} }
if (!empty($this->required_plugins['cache'])) { if (!empty($this->required_plugins['nocache'])) {
$this->has_nocache_code = true; $this->has_nocache_code = true;
$plugins_string .= "<?php echo '/*%%SmartyNocache:{$this->properties['nocache_hash']}%%*/<?php "; $plugins_string .= "<?php echo '/*%%SmartyNocache:{$this->properties['nocache_hash']}%%*/<?php ";
foreach($this->required_plugins['cache'] as $plugin_name => $data) { foreach($this->required_plugins['nocache'] as $tmp) {
$plugin = 'smarty_' . $data['type'] . '_' . $plugin_name; foreach($tmp as $data) {
$plugins_string .= "if (!is_callable(\'{$plugin}\')) include \'{$data['file']}\';\n"; $plugins_string .= "if (!is_callable('{$data['function']}')) include '{$data['file']}';\n";
}
} }
$plugins_string .= "?>/*/%%SmartyNocache:{$this->properties['nocache_hash']}%%*/';?>\n"; $plugins_string .= "?>/*/%%SmartyNocache:{$this->properties['nocache_hash']}%%*/';?>\n";
} }

View File

@@ -22,8 +22,6 @@ class Smarty_Internal_TemplateCompilerBase {
public $_tag_stack = array(); public $_tag_stack = array();
// current template // current template
public $template = null; public $template = null;
// required plugins
public $required_plugins_call = array();
/** /**
* Initialize compiler * Initialize compiler
@@ -270,23 +268,47 @@ class Smarty_Internal_TemplateCompilerBase {
*/ */
public function getPlugin($plugin_name, $type) public function getPlugin($plugin_name, $type)
{ {
if (isset($this->template->required_plugins_call[$plugin_name][$type])) { $function = null;
if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
if (isset($this->template->required_plugins['compiled'][$plugin_name])) { if (isset($this->template->required_plugins['nocache'][$plugin_name][$type])) {
$this->template->required_plugins['cache'][$plugin_name] = $this->template->required_plugins['compiled'][$plugin_name]; $function = $this->template->required_plugins['nocache'][$plugin_name][$type]['function'];
} } else if (isset($this->template->required_plugins['compiled'][$plugin_name][$type])) {
} else { $this->template->required_plugins['nocache'][$plugin_name][$type] = $this->template->required_plugins['compiled'][$plugin_name][$type];
if (isset($this->template->required_plugins['cache'][$plugin_name])) { $function = $this->template->required_plugins['nocache'][$plugin_name][$type]['function'];
$this->template->required_plugins['compiled'][$plugin_name] = $this->template->required_plugins['cache'][$plugin_name];
}
} }
} 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') { if ($type == 'modifier') {
$this->template->saved_modifer[$plugin_name] = true; $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 // loop through plugin dirs and find the plugin
$plugin = 'smarty_' . $type . '_' . $plugin_name; $function = 'smarty_' . $type . '_' . $plugin_name;
$found = false; $found = false;
foreach((array)$this->smarty->plugins_dir as $_plugin_dir) { foreach((array)$this->smarty->plugins_dir as $_plugin_dir) {
$file = rtrim($_plugin_dir, '/\\') . DS . $type . '.' . $plugin_name . '.php'; $file = rtrim($_plugin_dir, '/\\') . DS . $type . '.' . $plugin_name . '.php';
@@ -298,23 +320,31 @@ class Smarty_Internal_TemplateCompilerBase {
} }
if ($found) { if ($found) {
// if (is_callable($plugin)) { // if (is_callable($plugin)) {
$this->template->required_plugins_call[$plugin_name][$type] = $plugin;
if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
$this->template->required_plugins['cache'][$plugin_name]['file'] = $file; $this->template->required_plugins['nocache'][$plugin_name][$type]['file'] = $file;
$this->template->required_plugins['cache'][$plugin_name]['type'] = $type; $this->template->required_plugins['nocache'][$plugin_name][$type]['function'] = $function;
} else { } else {
$this->template->required_plugins['compiled'][$plugin_name]['file'] = $file; $this->template->required_plugins['compiled'][$plugin_name][$type]['file'] = $file;
$this->template->required_plugins['compiled'][$plugin_name]['type'] = $type; $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') { if ($type == 'modifier') {
$this->template->saved_modifer[$plugin_name] = true; $this->template->saved_modifer[$plugin_name] = true;
} }
return $function;
return $plugin;
} }
if (is_callable($plugin)) { if (is_callable($function)) {
// plugin function is defined in the script // plugin function is defined in the script
return $plugin; return $function;
} }
return false; return false;
} }
@@ -344,8 +374,8 @@ class Smarty_Internal_TemplateCompilerBase {
// make sure we include modifer plugins for nocache code // make sure we include modifer plugins for nocache code
if (isset($this->template->saved_modifer)) { if (isset($this->template->saved_modifer)) {
foreach ($this->template->saved_modifer as $plugin_name => $dummy) { foreach ($this->template->saved_modifer as $plugin_name => $dummy) {
if (isset($this->template->required_plugins['compiled'][$plugin_name])) { if (isset($this->template->required_plugins['compiled'][$plugin_name]['modifier'])) {
$this->template->required_plugins['cache'][$plugin_name] = $this->template->required_plugins['compiled'][$plugin_name]; $this->template->required_plugins['nocache'][$plugin_name]['modifier'] = $this->template->required_plugins['compiled'][$plugin_name]['modifier'];
} }
} }
unset($this->template->saved_modifer); unset($this->template->saved_modifer);