Modified to pass Smarty object as second parameter to insert functions.

Also moved _smarty_mod_handler() and _smarty_insert_handler() into the class.
This commit is contained in:
andrey
2001-08-10 20:58:15 +00:00
parent 0c64d1694d
commit d5cb0cce11
6 changed files with 86 additions and 40 deletions

2
NEWS
View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -336,7 +336,7 @@ class Smarty_Compiler extends Smarty {
$arg_list[] = "'$arg_name' => $arg_value";
}
return "<?php echo _smarty_insert_handler(array(".implode(', ', (array)$arg_list)."), \$this->caching, \$this->_smarty_md5); ?>\n";
return "<?php echo \$this->_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)";
}
}

View File

@@ -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

View File

@@ -336,7 +336,7 @@ class Smarty_Compiler extends Smarty {
$arg_list[] = "'$arg_name' => $arg_value";
}
return "<?php echo _smarty_insert_handler(array(".implode(', ', (array)$arg_list)."), \$this->caching, \$this->_smarty_md5); ?>\n";
return "<?php echo \$this->_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)";
}
}