mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
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:
2
NEWS
2
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
|
- modified Smarty to pass itself to prefilter functions as the second
|
||||||
parameter. (Andrei)
|
parameter. (Andrei)
|
||||||
- fixed syntax error when including a non-existant template with security
|
- fixed syntax error when including a non-existant template with security
|
||||||
|
@@ -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
|
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
|
Function: smarty_mod_escape
|
||||||
Purpose: Escape the string according to escapement type
|
Purpose: Escape the string according to escapement type
|
||||||
|
@@ -934,13 +934,52 @@ function _generate_debug_output() {
|
|||||||
unset($args['name']);
|
unset($args['name']);
|
||||||
|
|
||||||
$function_name = 'insert_' . $name;
|
$function_name = 'insert_' . $name;
|
||||||
$replace = $function_name($args);
|
$replace = $function_name($args, $this);
|
||||||
|
|
||||||
$results = str_replace($cached_inserts[$i], $replace, $results);
|
$results = str_replace($cached_inserts[$i], $replace, $results);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $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
|
Function: _dequote
|
||||||
|
@@ -336,7 +336,7 @@ class Smarty_Compiler extends Smarty {
|
|||||||
$arg_list[] = "'$arg_name' => $arg_value";
|
$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
|
else
|
||||||
$modifier_args = '';
|
$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)";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -934,13 +934,52 @@ function _generate_debug_output() {
|
|||||||
unset($args['name']);
|
unset($args['name']);
|
||||||
|
|
||||||
$function_name = 'insert_' . $name;
|
$function_name = 'insert_' . $name;
|
||||||
$replace = $function_name($args);
|
$replace = $function_name($args, $this);
|
||||||
|
|
||||||
$results = str_replace($cached_inserts[$i], $replace, $results);
|
$results = str_replace($cached_inserts[$i], $replace, $results);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $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
|
Function: _dequote
|
||||||
|
@@ -336,7 +336,7 @@ class Smarty_Compiler extends Smarty {
|
|||||||
$arg_list[] = "'$arg_name' => $arg_value";
|
$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
|
else
|
||||||
$modifier_args = '';
|
$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)";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user