- bugfix on {insert} to cache parameter

This commit is contained in:
Uwe.Tews
2010-05-05 19:48:42 +00:00
parent e71c82ff1d
commit df1ddc31fc
3 changed files with 77 additions and 21 deletions

View File

@@ -1,3 +1,6 @@
05/05/2010
- bugfix on {insert} to cache parameter
01/05/2010
- bugfix on handling of variable method names at object chaning

View File

@@ -1,25 +1,25 @@
<?php
/**
* Smarty Internal Plugin Compile Insert
*
* Compiles the {insert} tag
*
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
*/
* Smarty Internal Plugin Compile Insert
*
* Compiles the {insert} tag
*
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Insert Class
*/
* Smarty Internal Plugin Compile Insert Class
*/
class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase {
/**
* Compiles code for the {insert} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @return string compiled code
*/
* Compiles code for the {insert} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @return string compiled code
*/
public function compile($args, $compiler)
{
$this->compiler = $compiler;
@@ -27,7 +27,8 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase {
$this->optional_attributes = array('_any');
// check and get attributes
$_attr = $this->_get_attributes($args);
// this tag must not be cached
// never compile as nocache code
$this->compiler->suppressNocacheProcessing = true;
$this->compiler->tag_nocache = true;
$_smarty_tpl = $compiler->template;
@@ -49,12 +50,13 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase {
$this->compiler->trigger_template_error("{insert} missing script file '{$_script}'");
}
// 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 {
$_script = 'null';
if (!is_callable($_function)) {
if (!$_function = $this->compiler->getPlugin($_name, 'insert')) {
$this->compiler->trigger_template_error("{insert} no function or plugin found for '{$_name}'");
@@ -71,13 +73,21 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase {
$_params = 'array(' . implode(", ", $_paramsArray) . ')';
// call insert
if (isset($_assign)) {
$_output .= "\$_smarty_tpl->assign({$_assign} , {$_function} ({$_params},\$_smarty_tpl->smarty,\$_smarty_tpl), true);?>";
if ($_smarty_tpl->caching) {
$_output .= "echo Smarty_Internal_Nocache_Insert::compile ('{$_function}',{$_params}, \$_smarty_tpl, '{$_script}',{$_assign});?>";
} else {
$_output .= "\$_smarty_tpl->assign({$_assign} , {$_function} ({$_params},\$_smarty_tpl->smarty,\$_smarty_tpl), true);?>";
}
} else {
$this->compiler->has_output = true;
$_output .= "echo {$_function}({$_params},\$_smarty_tpl->smarty,\$_smarty_tpl);?>";
if ($_smarty_tpl->caching) {
$_output .= "echo Smarty_Internal_Nocache_Insert::compile ('{$_function}',{$_params}, \$_smarty_tpl, '{$_script}');?>";
} else {
$_output .= "echo {$_function}({$_params},\$_smarty_tpl->smarty,\$_smarty_tpl);?>";
}
}
return $_output;
}
}
?>
?>

View File

@@ -0,0 +1,43 @@
<?php
/**
* Smarty Internal Plugin Nocache Insert
*
* Compiles the {insert} tag into the cache file
*
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Compile Insert Class
*/
class Smarty_Internal_Nocache_Insert {
/**
* Compiles code for the {insert} tag into cache file
*
* @param string $_function insert function name
* @param array $_attr array with paramter
* @param object $template template object
* @param string $_script script name to load or 'null'
* @param string $_assign soptinal variable name
* @return string compiled code
*/
static function compile($_function, $_attr, $_template, $_script, $_assign = null)
{
$_output = '<?php ';
if ($_script != 'null') {
// script which must be included
// code for script file loading
$_output .= "require_once '{$_script}';";
}
// call insert
if (isset($_assign)) {
$_output .= "\$_smarty_tpl->assign('{$_assign}' , {$_function} (" . var_export($_attr, true) . ",\$_smarty_tpl->smarty,\$_smarty_tpl), true);?>";
} else {
$_output .= "echo {$_function}(" . var_export($_attr, true) . ",\$_smarty_tpl->smarty,\$_smarty_tpl);?>";
}
return "/*%%SmartyNocache:{$_template->properties['nocache_hash']}%%*/" . $_output . "/*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%*/";
}
}
?>