mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 10:54:27 +02:00
Clean up template functions property structure
This commit is contained in:
@@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
/**
|
/**
|
||||||
* smarty version
|
* smarty version
|
||||||
*/
|
*/
|
||||||
const SMARTY_VERSION = '3.1.22-dev/13';
|
const SMARTY_VERSION = '3.1.22-dev/14';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* define variable scopes
|
* define variable scopes
|
||||||
|
@@ -60,13 +60,6 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase
|
|||||||
unset($_attr['name'], $_attr['assign'], $_attr['nocache']);
|
unset($_attr['name'], $_attr['assign'], $_attr['nocache']);
|
||||||
// set flag (compiled code of {function} must be included in cache file
|
// set flag (compiled code of {function} must be included in cache file
|
||||||
if (!$compiler->template->caching || $compiler->nocache || $compiler->tag_nocache) {
|
if (!$compiler->template->caching || $compiler->nocache || $compiler->tag_nocache) {
|
||||||
// variable template name ?
|
|
||||||
if (!($compiler->has_variable_string || !((substr_count($_name, '"') == 2 || substr_count($_name, "'") == 2))
|
|
||||||
|| substr_count($_name, '(') != 0 || substr_count($_name, '$_smarty_tpl->') != 0
|
|
||||||
)) {
|
|
||||||
$n = trim($_name, "'\"");
|
|
||||||
$compiler->parent_compiler->templateProperties['tpl_function']['to_cache'][$n] = true;
|
|
||||||
}
|
|
||||||
$_nocache = 'true';
|
$_nocache = 'true';
|
||||||
} else {
|
} else {
|
||||||
$_nocache = 'false';
|
$_nocache = 'false';
|
||||||
|
@@ -104,9 +104,9 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
|||||||
$_name = trim($_attr['name'], "'\"");
|
$_name = trim($_attr['name'], "'\"");
|
||||||
// reset flag that we are compiling a template function
|
// reset flag that we are compiling a template function
|
||||||
$compiler->compiles_template_function = false;
|
$compiler->compiles_template_function = false;
|
||||||
$compiler->parent_compiler->templateProperties['tpl_function']['param'][$_name]['called_functions'] = $compiler->called_functions;
|
$compiler->parent_compiler->templateProperties['tpl_function'][$_name]['called_functions'] = $compiler->called_functions;
|
||||||
$compiler->parent_compiler->templateProperties['tpl_function']['param'][$_name]['compiled_filepath'] = $compiler->parent_compiler->template->compiled->filepath;
|
$compiler->parent_compiler->templateProperties['tpl_function'][$_name]['compiled_filepath'] = $compiler->parent_compiler->template->compiled->filepath;
|
||||||
$compiler->parent_compiler->templateProperties['tpl_function']['param'][$_name]['uid'] = $compiler->template->source->uid;
|
$compiler->parent_compiler->templateProperties['tpl_function'][$_name]['uid'] = $compiler->template->source->uid;
|
||||||
$compiler->called_functions = array();
|
$compiler->called_functions = array();
|
||||||
$_parameter = $_attr;
|
$_parameter = $_attr;
|
||||||
unset($_parameter['name']);
|
unset($_parameter['name']);
|
||||||
@@ -132,7 +132,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
|||||||
$_funcName = "smarty_template_function_{$_name}_{$compiler->template->properties['nocache_hash']}";
|
$_funcName = "smarty_template_function_{$_name}_{$compiler->template->properties['nocache_hash']}";
|
||||||
$_funcNameCaching = $_funcName . '_nocache';
|
$_funcNameCaching = $_funcName . '_nocache';
|
||||||
if ($compiler->template->has_nocache_code) {
|
if ($compiler->template->has_nocache_code) {
|
||||||
$compiler->parent_compiler->templateProperties['tpl_function']['param'][$_name]['call_name_caching'] = $_funcNameCaching;
|
$compiler->parent_compiler->templateProperties['tpl_function'][$_name]['call_name_caching'] = $_funcNameCaching;
|
||||||
$output = "<?php\n";
|
$output = "<?php\n";
|
||||||
$output .= "/* {$_funcNameCaching} */\n";
|
$output .= "/* {$_funcNameCaching} */\n";
|
||||||
$output .= "if (!function_exists('{$_funcNameCaching}')) {\n";
|
$output .= "if (!function_exists('{$_funcNameCaching}')) {\n";
|
||||||
@@ -173,7 +173,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
|||||||
$compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
|
$compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
|
||||||
$_functionCode = new Smarty_Internal_ParseTree_Tag($compiler->parser, preg_replace_callback("/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%\*\/';(\?>\n)?)/", array($this, 'removeNocache'), $_functionCode->to_smarty_php()));
|
$_functionCode = new Smarty_Internal_ParseTree_Tag($compiler->parser, preg_replace_callback("/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%\*\/';(\?>\n)?)/", array($this, 'removeNocache'), $_functionCode->to_smarty_php()));
|
||||||
}
|
}
|
||||||
$compiler->parent_compiler->templateProperties['tpl_function']['param'][$_name]['call_name'] = $_funcName;
|
$compiler->parent_compiler->templateProperties['tpl_function'][$_name]['call_name'] = $_funcName;
|
||||||
$output = "<?php\n";
|
$output = "<?php\n";
|
||||||
$output .= "/* {$_funcName} */\n";
|
$output .= "/* {$_funcName} */\n";
|
||||||
$output .= "if (!function_exists('{$_funcName}')) {\n";
|
$output .= "if (!function_exists('{$_funcName}')) {\n";
|
||||||
|
@@ -32,7 +32,7 @@ class Smarty_Internal_Function_Call_Handler
|
|||||||
*/
|
*/
|
||||||
public static function call($_name, Smarty_Internal_Template $_smarty_tpl, $_function, $_params, $_nocache)
|
public static function call($_name, Smarty_Internal_Template $_smarty_tpl, $_function, $_params, $_nocache)
|
||||||
{
|
{
|
||||||
$funcParam = $_smarty_tpl->properties['tpl_function']['param'][$_name];
|
$funcParam = $_smarty_tpl->properties['tpl_function'][$_name];
|
||||||
if (is_file($funcParam['compiled_filepath'])) {
|
if (is_file($funcParam['compiled_filepath'])) {
|
||||||
// read compiled file
|
// read compiled file
|
||||||
$code = file_get_contents($funcParam['compiled_filepath']);
|
$code = file_get_contents($funcParam['compiled_filepath']);
|
||||||
|
@@ -58,7 +58,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
*/
|
*/
|
||||||
public $properties = array('file_dependency' => array(),
|
public $properties = array('file_dependency' => array(),
|
||||||
'nocache_hash' => '',
|
'nocache_hash' => '',
|
||||||
'tpl_function' => array('param' => array()),
|
'tpl_function' => array(),
|
||||||
);
|
);
|
||||||
/**
|
/**
|
||||||
* required plugins
|
* required plugins
|
||||||
@@ -229,7 +229,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
$isCacheTpl = $this->caching == Smarty::CACHING_LIFETIME_CURRENT || $this->caching == Smarty::CACHING_LIFETIME_SAVED;
|
$isCacheTpl = $this->caching == Smarty::CACHING_LIFETIME_CURRENT || $this->caching == Smarty::CACHING_LIFETIME_SAVED;
|
||||||
if (!($isCacheTpl) || !$this->cached->valid) {
|
if (!($isCacheTpl) || !$this->cached->valid) {
|
||||||
if ($isCacheTpl) {
|
if ($isCacheTpl) {
|
||||||
$this->properties['tpl_function']['param'] = array();
|
$this->properties['tpl_function'] = array();
|
||||||
}
|
}
|
||||||
// render template (not loaded and not in cache)
|
// render template (not loaded and not in cache)
|
||||||
if ($this->smarty->debugging) {
|
if ($this->smarty->debugging) {
|
||||||
@@ -550,14 +550,14 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
*/
|
*/
|
||||||
public function callTemplateFunction($name, Smarty_Internal_Template $_smarty_tpl, $params, $nocache)
|
public function callTemplateFunction($name, Smarty_Internal_Template $_smarty_tpl, $params, $nocache)
|
||||||
{
|
{
|
||||||
if (isset($_smarty_tpl->properties['tpl_function']['param'][$name])) {
|
if (isset($_smarty_tpl->properties['tpl_function'][$name])) {
|
||||||
if (!$_smarty_tpl->caching || ($_smarty_tpl->caching && $nocache)) {
|
if (!$_smarty_tpl->caching || ($_smarty_tpl->caching && $nocache)) {
|
||||||
$function = $_smarty_tpl->properties['tpl_function']['param'][$name]['call_name'];
|
$function = $_smarty_tpl->properties['tpl_function'][$name]['call_name'];
|
||||||
} else {
|
} else {
|
||||||
if (isset($_smarty_tpl->properties['tpl_function']['param'][$name]['call_name_caching'])) {
|
if (isset($_smarty_tpl->properties['tpl_function'][$name]['call_name_caching'])) {
|
||||||
$function = $_smarty_tpl->properties['tpl_function']['param'][$name]['call_name_caching'];
|
$function = $_smarty_tpl->properties['tpl_function'][$name]['call_name_caching'];
|
||||||
} else {
|
} else {
|
||||||
$function = $_smarty_tpl->properties['tpl_function']['param'][$name]['call_name'];
|
$function = $_smarty_tpl->properties['tpl_function'][$name]['call_name'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (function_exists($function)) {
|
if (function_exists($function)) {
|
||||||
@@ -636,9 +636,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
if (isset($properties['file_dependency'])) {
|
if (isset($properties['file_dependency'])) {
|
||||||
$this->properties['file_dependency'] = array_merge($this->properties['file_dependency'], $properties['file_dependency']);
|
$this->properties['file_dependency'] = array_merge($this->properties['file_dependency'], $properties['file_dependency']);
|
||||||
}
|
}
|
||||||
//$this->properties['tpl_function']['param'] = isset($this->parent->properties['tpl_function']['param']) ? $this->parent->properties['tpl_function']['param'] : array();
|
if (isset($properties['tpl_function'])) {
|
||||||
if (isset($properties['tpl_function']['param'])) {
|
$this->properties['tpl_function'] = array_merge($this->properties['tpl_function'], $properties['tpl_function']);
|
||||||
$this->properties['tpl_function']['param'] = array_merge($this->properties['tpl_function']['param'], $properties['tpl_function']['param']);
|
|
||||||
}
|
}
|
||||||
$this->properties['version'] = $properties['version'];
|
$this->properties['version'] = $properties['version'];
|
||||||
$this->properties['unifunc'] = $properties['unifunc'];
|
$this->properties['unifunc'] = $properties['unifunc'];
|
||||||
|
@@ -379,7 +379,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
}
|
}
|
||||||
// compile the smarty tag (required compile classes to compile the tag are autoloaded)
|
// compile the smarty tag (required compile classes to compile the tag are autoloaded)
|
||||||
if (($_output = $this->callTagCompiler($tag, $args, $parameter)) === false) {
|
if (($_output = $this->callTagCompiler($tag, $args, $parameter)) === false) {
|
||||||
if (isset($this->parent_compiler->templateProperties['tpl_function']['param'][$tag])) {
|
if (isset($this->parent_compiler->templateProperties['tpl_function'][$tag])) {
|
||||||
// template defined by {template} tag
|
// template defined by {template} tag
|
||||||
$args['_attr']['name'] = "'" . $tag . "'";
|
$args['_attr']['name'] = "'" . $tag . "'";
|
||||||
$_output = $this->callTagCompiler('call', $args, $parameter);
|
$_output = $this->callTagCompiler('call', $args, $parameter);
|
||||||
|
Reference in New Issue
Block a user