- added missing support of insert plugins

This commit is contained in:
Uwe.Tews
2010-01-11 20:22:41 +00:00
parent cdd2aae582
commit e912e731bc
2 changed files with 18 additions and 9 deletions

View File

@@ -1,5 +1,6 @@
01/11/2010 01/11/2010
- added \n to the compiled code of the {if},{else},{elseif},{/if} tags to get output of newlines as expected by the template source - added \n to the compiled code of the {if},{else},{elseif},{/if} tags to get output of newlines as expected by the template source
- added missing support of insert plugins
01/09/2010 01/09/2010
- bugfix on nocache {block} tags in parent templates - bugfix on nocache {block} tags in parent templates

View File

@@ -29,10 +29,12 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase {
$_attr = $this->_get_attributes($args); $_attr = $this->_get_attributes($args);
// this tag must not be cached // this tag must not be cached
$this->compiler->tag_nocache = true; $this->compiler->tag_nocache = true;
$_smarty_tpl = $compiler->template;
$_output = '<?php '; $_output = '<?php ';
// save posible attributes // save posible attributes
$_name = 'insert_' . trim($_attr['name'], "'\""); eval('$_name = ' . $_attr['name'] . ';');
$_function = "insert_{$_name}";
if (isset($_attr['assign'])) { if (isset($_attr['assign'])) {
// output will be stored in a smarty variable instead of beind displayed // output will be stored in a smarty variable instead of beind displayed
$_assign = $_attr['assign']; $_assign = $_attr['assign'];
@@ -44,13 +46,19 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase {
$_smarty_tpl = $compiler->template; $_smarty_tpl = $compiler->template;
eval('$_script = ' . $_attr['script'] . ';'); eval('$_script = ' . $_attr['script'] . ';');
if (!file_exists($_script)) { if (!file_exists($_script)) {
$this->compiler->trigger_template_error('missing file "' . $_script . '"'); $this->compiler->trigger_template_error("{insert} missing script file '{$_script}'");
} }
// code for script file loading // code for script file loading
$_output .= 'require once ' . $_script . ';'; $_output .= "require_once {$_script} ;";
require_once $_script;
if (!is_callable($_function)) {
$this->compiler->trigger_template_error(" {insert} function '{$_name}' is not callable");
}
} else { } else {
if (!is_callable($_name)) { if (!is_callable($_function)) {
$this->compiler->trigger_template_error('function "' . $_name . '" is not callable'); if (!$_function = $this->compiler->getPlugin($_name, 'insert')) {
$this->compiler->trigger_template_error("{insert} no function or plugin found for '{$_name}'");
}
} }
} }
// delete {insert} standard attributes // delete {insert} standard attributes
@@ -63,10 +71,10 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase {
$_params = 'array(' . implode(", ", $_paramsArray) . ')'; $_params = 'array(' . implode(", ", $_paramsArray) . ')';
// call insert // call insert
if (isset($_assign)) { if (isset($_assign)) {
$_output .= '$_smarty_tpl->assign(' . $_assign . ',' . $_name . '(' . $_params . '),true); ?>'; $_output .= "\$_smarty_tpl->assign({$_assign} , {$_function} ({$_params},\$_smarty_tpl->smarty,\$_smarty_tpl), true);?>";
} else { } else {
$this->compiler->has_output = true; $this->compiler->has_output = true;
$_output .= 'echo ' . $_name . '(' . $_params . '); ?>'; $_output .= "echo {$_function}({$_params},\$_smarty_tpl->smarty,\$_smarty_tpl);?>";
} }
return $_output; return $_output;
} }