mirror of
https://github.com/smarty-php/smarty.git
synced 2025-12-16 02:28:31 +01:00
- optimization of generated code for doublequoted strings containing variables
- rewrite of {function} tag handling
- can now be declared in an external subtemplate
- can contain nocache sections (nocache_hash handling)
- can be called in noccache sections (nocache_hash handling)
- new {call..} tag to call template functions with a variable name {call name=$foo}
- fixed nocache_hash handling in merged compiled templates
This commit is contained in:
47
libs/sysplugins/smarty_internal_function_call_handler.php
Normal file
47
libs/sysplugins/smarty_internal_function_call_handler.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Function Call Handler
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Security
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
/**
|
||||
* This class does call function defined with the {function} tag
|
||||
*/
|
||||
class Smarty_Internal_Function_Call_Handler extends Smarty_Internal_Template {
|
||||
function __construct($name, $smarty, $parent, $nocache)
|
||||
{
|
||||
parent::__construct('string:', $smarty, $parent);
|
||||
if (!isset($this->smarty->template_functions[$name])) {
|
||||
throw new Exception("Call to undefined template function \"{$name}\" in template \"{$parent->template_resource}\"");
|
||||
}
|
||||
$this->called_nocache = $nocache;
|
||||
$this->mustCompile = false;
|
||||
if ($nocache) {
|
||||
$smarty->template_functions[$name]['called_nocache'] = true;
|
||||
$this->properties['function'][$name]['called_nocache'] = true;
|
||||
}
|
||||
$this->properties['nocache_hash'] = $smarty->template_functions[$name]['nocache_hash'];
|
||||
// load compiled function
|
||||
if ($nocache) {
|
||||
// if called in nocache mode convert nocache code to real code
|
||||
$this->compiled_template = preg_replace(array("!(<\?php echo ')?/\*/?%%SmartyNocache:{$this->smarty->template_functions[$name]['nocache_hash']}%%\*/(';\?>)?!", "!\\\'!"), array('', "'"), $smarty->template_functions[$name]['compiled']);
|
||||
} else {
|
||||
$this->compiled_template = $smarty->template_functions[$name]['compiled'];
|
||||
}
|
||||
// assign default paramter
|
||||
if (isset($smarty->template_functions[$name]['parameter'])) {
|
||||
$_smarty_tpl = $this;
|
||||
foreach ($smarty->template_functions[$name]['parameter'] as $_key => $_value) {
|
||||
$this->assign($_key, eval("return {$_value};"));
|
||||
}
|
||||
}
|
||||
// set flag if {function} contains nocache code
|
||||
if ($smarty->template_functions[$name]['has_nocache_code']) {
|
||||
$this->has_nocache_code = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user