diff options
author | plegall <plg@piwigo.org> | 2015-12-30 16:21:32 +0100 |
---|---|---|
committer | plegall <plg@piwigo.org> | 2015-12-30 16:21:32 +0100 |
commit | 3ec3cbe6cec5968d29cb11af139123191f4cb4ee (patch) | |
tree | 34aecd51071d63f8df1862a1a11898d8c43fe68a /include/smarty/libs/sysplugins/smarty_internal_compile_insert.php | |
parent | 6ba0148e646b2a193dc4111bb0a443d8c193e646 (diff) | |
parent | 1681b02ee98c2deb740d394280a2a685170bc72e (diff) |
Merge branch 'bug/385-php7'
Diffstat (limited to 'include/smarty/libs/sysplugins/smarty_internal_compile_insert.php')
-rw-r--r-- | include/smarty/libs/sysplugins/smarty_internal_compile_insert.php | 59 |
1 files changed, 34 insertions, 25 deletions
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_insert.php b/include/smarty/libs/sysplugins/smarty_internal_compile_insert.php index e4d3f9355..2ebde1661 100644 --- a/include/smarty/libs/sysplugins/smarty_internal_compile_insert.php +++ b/include/smarty/libs/sysplugins/smarty_internal_compile_insert.php @@ -2,22 +2,21 @@ /** * Smarty Internal Plugin Compile Insert - * * Compiles the {insert} tag * - * @package Smarty + * @package Smarty * @subpackage Compiler - * @author Uwe Tews + * @author Uwe Tews */ /** * Smarty Internal Plugin Compile Insert Class * - * @package Smarty + * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase { - +class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase +{ /** * Attribute definition: Overwrites base class. * @@ -25,6 +24,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase { * @see Smarty_Internal_CompileBase */ public $required_attributes = array('name'); + /** * Attribute definition: Overwrites base class. * @@ -32,6 +32,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase { * @see Smarty_Internal_CompileBase */ public $shorttag_order = array('name'); + /** * Attribute definition: Overwrites base class. * @@ -43,36 +44,46 @@ 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 + * @param array $args array with attributes from parser + * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object + * * @return string compiled code + * @throws \SmartyCompilerException */ - public function compile($args, $compiler) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) { // check and get attributes $_attr = $this->getAttributes($compiler, $args); - // never compile as nocache code - $compiler->suppressNocacheProcessing = true; + $nocacheParam = $compiler->template->caching && ($compiler->tag_nocache || $compiler->nocache); + if (!$nocacheParam) { + // do not compile as nocache code + $compiler->suppressNocacheProcessing = true; + } $compiler->tag_nocache = true; $_smarty_tpl = $compiler->template; $_name = null; $_script = null; $_output = '<?php '; - // save posible attributes - eval('$_name = ' . $_attr['name'] . ';'); + // save possible attributes + eval('$_name = @' . $_attr['name'] . ';'); if (isset($_attr['assign'])) { // output will be stored in a smarty variable instead of being displayed $_assign = $_attr['assign']; - // create variable to make shure that the compiler knows about its nocache status - $compiler->template->tpl_vars[trim($_attr['assign'], "'")] = new Smarty_Variable(null, true); + // create variable to make sure that the compiler knows about its nocache status + $var = trim($_attr['assign'], "'"); + if (isset($compiler->template->tpl_vars[$var])) { + $compiler->template->tpl_vars[$var]->nocache = true; + } else { + $compiler->template->tpl_vars[$var] = new Smarty_Variable(null, true); + } } if (isset($_attr['script'])) { // script which must be included $_function = "smarty_insert_{$_name}"; $_smarty_tpl = $compiler->template; $_filepath = false; - eval('$_script = ' . $_attr['script'] . ';'); + eval('$_script = @' . $_attr['script'] . ';'); if (!isset($compiler->smarty->security_policy) && file_exists($_script)) { $_filepath = $_script; } else { @@ -82,7 +93,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase { $_dir = $compiler->smarty->trusted_dir; } if (!empty($_dir)) { - foreach((array)$_dir as $_script_dir) { + foreach ((array) $_dir as $_script_dir) { $_script_dir = rtrim($_script_dir, '/\\') . DS; if (file_exists($_script_dir . $_script)) { $_filepath = $_script_dir . $_script; @@ -92,13 +103,13 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase { } } if ($_filepath == false) { - $compiler->trigger_template_error("{insert} missing script file '{$_script}'", $compiler->lex->taglineno); + $compiler->trigger_template_error("{insert} missing script file '{$_script}'", null, true); } // code for script file loading $_output .= "require_once '{$_filepath}' ;"; require_once $_filepath; if (!is_callable($_function)) { - $compiler->trigger_template_error(" {insert} function '{$_function}' is not callable in script file '{$_script}'", $compiler->lex->taglineno); + $compiler->trigger_template_error(" {insert} function '{$_function}' is not callable in script file '{$_script}'", null, true); } } else { $_filepath = 'null'; @@ -107,7 +118,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase { if (!is_callable($_function)) { // try plugin if (!$_function = $compiler->getPlugin($_name, 'insert')) { - $compiler->trigger_template_error("{insert} no function or plugin found for '{$_name}'", $compiler->lex->taglineno); + $compiler->trigger_template_error("{insert} no function or plugin found for '{$_name}'", null, true); } } } @@ -121,22 +132,20 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase { $_params = 'array(' . implode(", ", $_paramsArray) . ')'; // call insert if (isset($_assign)) { - if ($_smarty_tpl->caching) { + if ($_smarty_tpl->caching && !$nocacheParam) { $_output .= "echo Smarty_Internal_Nocache_Insert::compile ('{$_function}',{$_params}, \$_smarty_tpl, '{$_filepath}',{$_assign});?>"; } else { $_output .= "\$_smarty_tpl->assign({$_assign} , {$_function} ({$_params},\$_smarty_tpl), true);?>"; } } else { $compiler->has_output = true; - if ($_smarty_tpl->caching) { + if ($_smarty_tpl->caching && !$nocacheParam) { $_output .= "echo Smarty_Internal_Nocache_Insert::compile ('{$_function}',{$_params}, \$_smarty_tpl, '{$_filepath}');?>"; } else { $_output .= "echo {$_function}({$_params},\$_smarty_tpl);?>"; } } + return $_output; } - } - -?>
\ No newline at end of file |