From d5cb0cce11458a22859b036eeff1e5ee04398d3a Mon Sep 17 00:00:00 2001 From: andrey Date: Fri, 10 Aug 2001 20:58:15 +0000 Subject: [PATCH] Modified to pass Smarty object as second parameter to insert functions. Also moved _smarty_mod_handler() and _smarty_insert_handler() into the class. --- NEWS | 2 ++ Smarty.addons.php | 34 ---------------------------- Smarty.class.php | 41 +++++++++++++++++++++++++++++++++- Smarty_Compiler.class.php | 4 ++-- libs/Smarty.class.php | 41 +++++++++++++++++++++++++++++++++- libs/Smarty_Compiler.class.php | 4 ++-- 6 files changed, 86 insertions(+), 40 deletions(-) diff --git a/NEWS b/NEWS index 2a02eb34..401dbd79 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ + - modified Smarty to pass itself to insert functions as the second + parameter. (Andrei) - modified Smarty to pass itself to prefilter functions as the second parameter. (Andrei) - fixed syntax error when including a non-existant template with security diff --git a/Smarty.addons.php b/Smarty.addons.php index da998b4b..031dc23d 100644 --- a/Smarty.addons.php +++ b/Smarty.addons.php @@ -37,44 +37,10 @@ */ -/*============================================*\ - Inserts handler -\*============================================*/ - -function _smarty_insert_handler($args, $caching, $delimiter) -{ - if ($caching) { - $arg_string = serialize($args); - return "$delimiter{insert_cache $arg_string}$delimiter"; - } else { - $function_name = 'insert_'.$args['name']; - return $function_name($args); - } -} - - /*============================================*\ Modifiers \*============================================*/ -function _smarty_mod_handler() -{ - $args = func_get_args(); - list($func_name, $map_array) = array_splice($args, 0, 2); - $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); - } -} - - /*======================================================================*\ Function: smarty_mod_escape Purpose: Escape the string according to escapement type diff --git a/Smarty.class.php b/Smarty.class.php index c07768b5..d790fd5a 100644 --- a/Smarty.class.php +++ b/Smarty.class.php @@ -934,13 +934,52 @@ function _generate_debug_output() { unset($args['name']); $function_name = 'insert_' . $name; - $replace = $function_name($args); + $replace = $function_name($args, $this); $results = str_replace($cached_inserts[$i], $replace, $results); } return $results; } + + +/*======================================================================*\ + Function: _run_insert_handler + Purpose: Handle insert tags +\*======================================================================*/ +function _run_insert_handler($args) +{ + if ($this->caching) { + $arg_string = serialize($args); + return $this->_smarty_md5."{insert_cache $arg_string}".$this->_smarty_md5; + } else { + $function_name = 'insert_'.$args['name']; + return $function_name($args, $this); + } +} + + +/*======================================================================*\ + Function: _run_mod_handler + Purpose: Handle modifiers +\*======================================================================*/ +function _run_mod_handler() +{ + $args = func_get_args(); + list($func_name, $map_array) = array_splice($args, 0, 2); + $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); + } +} + /*======================================================================*\ Function: _dequote diff --git a/Smarty_Compiler.class.php b/Smarty_Compiler.class.php index 7a5cfa4e..51d91b78 100644 --- a/Smarty_Compiler.class.php +++ b/Smarty_Compiler.class.php @@ -336,7 +336,7 @@ class Smarty_Compiler extends Smarty { $arg_list[] = "'$arg_name' => $arg_value"; } - return "caching, \$this->_smarty_md5); ?>\n"; + return "_run_insert_handler(array(".implode(', ', (array)$arg_list).")); ?>\n"; } @@ -947,7 +947,7 @@ class Smarty_Compiler extends Smarty { else $modifier_args = ''; - $output = "_smarty_mod_handler('$mod_func_name', $map_array, $output$modifier_args)"; + $output = "\$this->_run_mod_handler('$mod_func_name', $map_array, $output$modifier_args)"; } } diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index c07768b5..d790fd5a 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -934,13 +934,52 @@ function _generate_debug_output() { unset($args['name']); $function_name = 'insert_' . $name; - $replace = $function_name($args); + $replace = $function_name($args, $this); $results = str_replace($cached_inserts[$i], $replace, $results); } return $results; } + + +/*======================================================================*\ + Function: _run_insert_handler + Purpose: Handle insert tags +\*======================================================================*/ +function _run_insert_handler($args) +{ + if ($this->caching) { + $arg_string = serialize($args); + return $this->_smarty_md5."{insert_cache $arg_string}".$this->_smarty_md5; + } else { + $function_name = 'insert_'.$args['name']; + return $function_name($args, $this); + } +} + + +/*======================================================================*\ + Function: _run_mod_handler + Purpose: Handle modifiers +\*======================================================================*/ +function _run_mod_handler() +{ + $args = func_get_args(); + list($func_name, $map_array) = array_splice($args, 0, 2); + $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); + } +} + /*======================================================================*\ Function: _dequote diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php index 7a5cfa4e..51d91b78 100644 --- a/libs/Smarty_Compiler.class.php +++ b/libs/Smarty_Compiler.class.php @@ -336,7 +336,7 @@ class Smarty_Compiler extends Smarty { $arg_list[] = "'$arg_name' => $arg_value"; } - return "caching, \$this->_smarty_md5); ?>\n"; + return "_run_insert_handler(array(".implode(', ', (array)$arg_list).")); ?>\n"; } @@ -947,7 +947,7 @@ class Smarty_Compiler extends Smarty { else $modifier_args = ''; - $output = "_smarty_mod_handler('$mod_func_name', $map_array, $output$modifier_args)"; + $output = "\$this->_run_mod_handler('$mod_func_name', $map_array, $output$modifier_args)"; } }