diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index e5f96156..c07033de 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -1752,17 +1752,12 @@ class Smarty list($_modifier_name, $_map_array) = array_splice($_args, 0, 2); list($_func_name, $_tpl_file, $_tpl_line) = $this->_plugins['modifier'][$_modifier_name]; - $_var = $_args[0]; - if ($_map_array && is_array($_var)) { - foreach ($_var as $_key => $_val) { - $_args[0] = $_val; - $_var[$_key] = call_user_func_array($_func_name, $_args); - } - return $_var; - } else { - return call_user_func_array($_func_name, $_args); + foreach ($_var as $_key => $_val) { + $_args[0] = $_val; + $_var[$_key] = call_user_func_array($_func_name, $_args); } + return $_var; } /** diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php index 07b5a557..4b5699ec 100644 --- a/libs/Smarty_Compiler.class.php +++ b/libs/Smarty_Compiler.class.php @@ -1767,13 +1767,30 @@ class Smarty_Compiler extends Smarty { $_modifier_args = $_match[1]; if ($_modifier_name{0} == '@') { - $_map_array = 'false'; + $_map_array = false; $_modifier_name = substr($_modifier_name, 1); } else { - $_map_array = 'true'; + $_map_array = true; } - - $this->_add_plugin('modifier', $_modifier_name); + + if (isset($this->_plugins['modifier'][$_modifier_name]) + || (isset($this->_plugin_info['modifier']) && isset($this->_plugin_info['modifier'][$_modifier_name]))) { + /* modifier is already known */ + } elseif ($this->_get_plugin_filepath('modifier', $_modifier_name)) { + $this->_add_plugin('modifier', $_modifier_name); + } elseif (function_exists($_modifier_name)) { + if ($this->security && !in_array($_modifier_name, $this->security_settings['MODIFIER_FUNCS'])) { + $this->_trigger_fatal_error("[plugin] (secure mode) modifier '$_modifier_name' is not allowed" , $_tpl_file, $_tpl_line, __FILE__, __LINE__); + } else { + $this->_plugins['modifier'][$_modifier_name] = array($_modifier_name, null, null, false); + } + } else { + /* modifier not found */ + $this->_syntax_error("[plugin] modifier '$_modifier_name' not found", E_USER_ERROR, __FILE__, __LINE__); + return; + } + + $this->_parse_vars_props($_modifier_args); if($_modifier_name == 'default') { @@ -1790,7 +1807,14 @@ class Smarty_Compiler extends Smarty { else $_modifier_args = ''; - $output = "\$this->_run_mod_handler('$_modifier_name', $_map_array, $output$_modifier_args)"; + if ($_map_array) { + $output = "((is_array(\$_tmp=$output)) ? \$this->_run_mod_handler('$_modifier_name', true, \$_tmp$_modifier_args) : " . $this->_compile_plugin_call('modifier', $_modifier_name) . "(\$_tmp$_modifier_args))"; + + } else { + + $output = $this->_compile_plugin_call('modifier', $_modifier_name)."($output$_modifier_args)"; + + } } }