From ab5d8d4e07bb3c8230d0285ef8902ef1979fce51 Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 18 Oct 2018 02:39:34 +0200 Subject: Updating Smarty --- .../sysplugins/smarty_internal_compile_insert.php | 86 +++++++++++++--------- 1 file changed, 50 insertions(+), 36 deletions(-) (limited to 'lib/smarty/sysplugins/smarty_internal_compile_insert.php') diff --git a/lib/smarty/sysplugins/smarty_internal_compile_insert.php b/lib/smarty/sysplugins/smarty_internal_compile_insert.php index e4d3f93..56fbc56 100644 --- a/lib/smarty/sysplugins/smarty_internal_compile_insert.php +++ b/lib/smarty/sysplugins/smarty_internal_compile_insert.php @@ -1,23 +1,21 @@ 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 = 'template->tpl_vars[trim($_attr['assign'], "'")] = new Smarty_Variable(null, true); + $_assign = $_attr[ 'assign' ]; + // 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'])) { + 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 { if (isset($compiler->smarty->security_policy)) { $_dir = $compiler->smarty->security_policy->trusted_dir; } else { - $_dir = $compiler->smarty->trusted_dir; + $_dir = $compiler->smarty instanceof SmartyBC ? $compiler->smarty->trusted_dir : null; } if (!empty($_dir)) { - foreach((array)$_dir as $_script_dir) { - $_script_dir = rtrim($_script_dir, '/\\') . DS; + foreach ((array)$_dir as $_script_dir) { + $_script_dir = rtrim($_script_dir, '/\\') . DIRECTORY_SEPARATOR; if (file_exists($_script_dir . $_script)) { $_filepath = $_script_dir . $_script; break; @@ -91,14 +101,18 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase { } } } - if ($_filepath == false) { - $compiler->trigger_template_error("{insert} missing script file '{$_script}'", $compiler->lex->taglineno); + if ($_filepath === false) { + $compiler->trigger_template_error("{insert} missing script file '{$_script}'", null, true); } // code for script file loading $_output .= "require_once '{$_filepath}' ;"; - require_once $_filepath; + include_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,12 +121,16 @@ 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 + ); } } } // delete {insert} standard attributes - unset($_attr['name'], $_attr['assign'], $_attr['script'], $_attr['nocache']); + unset($_attr[ 'name' ], $_attr[ 'assign' ], $_attr[ 'script' ], $_attr[ 'nocache' ]); // convert attributes into parameter array string $_paramsArray = array(); foreach ($_attr as $_key => $_value) { @@ -121,14 +139,13 @@ 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);?>"; @@ -136,7 +153,4 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase { } return $_output; } - } - -?> \ No newline at end of file -- cgit v1.2.3