mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-07 11:54:26 +02:00
- functions defined with the {function} tag now always have global scope
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
04/30/2009
|
||||
- functions defined with the {function} tag now always have global scope
|
||||
|
||||
04/29/2009
|
||||
- fixed problem with directory setter methodes
|
||||
- allow that cache_dir can end without directory separator
|
||||
|
@@ -126,7 +126,9 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
||||
// assigned global tpl vars
|
||||
public $global_tpl_vars = array();
|
||||
// dummy parent object
|
||||
public $parent = null;
|
||||
public $parent = null;
|
||||
// global template functions
|
||||
public $template_functions = null;
|
||||
// system plugins directory
|
||||
private $sysplugins_dir = null;
|
||||
// resource type used if none given
|
||||
|
@@ -35,6 +35,8 @@ class Smarty_Internal_Compile_FunctionClose extends Smarty_Internal_CompileBase
|
||||
}
|
||||
$_name = trim($saved_data[0]['name'], "'");
|
||||
$compiler->template->properties['function'][$_name]['compiled'] = str_replace("\n",'_%n',$compiler->template->extracted_compiled_code);
|
||||
$this->smarty->template_functions[$_name]['compiled'] = $compiler->template->extracted_compiled_code;
|
||||
$this->smarty->template_functions[$_name]['parameter'] = $compiler->template->properties['function'][$_name]['parameter'];
|
||||
$compiler->template->extracted_compiled_code = $saved_data[1];
|
||||
$compiler->template->extract_code = $saved_data[2];
|
||||
return true;
|
||||
|
@@ -36,12 +36,17 @@ class Smarty_Internal_Compile_Internal_Function_Call extends Smarty_Internal_Com
|
||||
// create template object
|
||||
$_output = "<?php \$_template = new Smarty_Template ('string:', \$_smarty_tpl);\n";
|
||||
// assign default paramter
|
||||
$_ptr = $compiler->template;
|
||||
while ($_ptr != null && !isset($_ptr->properties['function'][$_name])) {
|
||||
$_ptr = $_ptr->parent;
|
||||
if (isset($this->smarty->template_functions[$_name]['parameter'])) {
|
||||
// function is already compiled
|
||||
foreach ($this->smarty->template_functions[$_name]['parameter'] as $_key => $_value) {
|
||||
if (!isset($_attr[$_key])) {
|
||||
$_output .= "\$_template->assign('$_key',$_value);\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($_ptr != null && isset($_ptr->properties['function'][$_name]['parameter'])) {
|
||||
foreach ($_ptr->properties['function'][$_name]['parameter'] as $_key => $_value) {
|
||||
if (isset($compiler->template->properties['function'][$_name]['parameter'])) {
|
||||
// for recursive call during function compilation
|
||||
foreach ($compiler->template->properties['function'][$_name]['parameter'] as $_key => $_value) {
|
||||
if (!isset($_attr[$_key])) {
|
||||
$_output .= "\$_template->assign('$_key',$_value);\n";
|
||||
}
|
||||
@@ -56,13 +61,8 @@ class Smarty_Internal_Compile_Internal_Function_Call extends Smarty_Internal_Com
|
||||
$_output .= "\$_template->assign('$_key',$_value);\n";
|
||||
}
|
||||
}
|
||||
if (isset($_ptr->properties['function'][$_name]['compiled'])) {
|
||||
$_compiled = str_replace(array('_%n', "'"), array("\n", "\'"), $_ptr->properties['function'][$_name]['compiled']);
|
||||
$_output .= "\$_template->compiled_template = '$_compiled';\n \$_template->mustCompile = false;\n";
|
||||
} else {
|
||||
// for recursion
|
||||
$_output .= "\$_template->compiled_template = \$_smarty_tpl->compiled_template;\n \$_template->mustCompile = false;\n";
|
||||
}
|
||||
// load compiled function
|
||||
$_output .= "\$_template->compiled_template = \$this->smarty->template_functions['$_name']['compiled'];\n\$_template->mustCompile = false;\n";
|
||||
// was there an assign attribute
|
||||
if (isset($_assign)) {
|
||||
$_output .= "\$_smarty_tpl->assign($_assign,\$_smarty_tpl->smarty->fetch(\$_template)); ?>";
|
||||
|
@@ -58,7 +58,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
public $config_vars = array();
|
||||
// storage for plugin
|
||||
public $plugin_data = array();
|
||||
// files template is depending from
|
||||
// special properties
|
||||
public $properties = array();
|
||||
// storage for block data
|
||||
public $block_data = array();
|
||||
@@ -203,12 +203,18 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
// read compiled template to check file dependencies
|
||||
if ($this->compiled_template !== true && file_exists($this->getCompiledFilepath())) {
|
||||
$this->compiled_template = !$this->isEvaluated() ? file_get_contents($this->getCompiledFilepath()):'';
|
||||
$found = preg_match('~\<\?php /\*(.*)\*/ \?\>~', $this->compiled_template, $matches);
|
||||
if ($found) {
|
||||
$_properties = unserialize($matches[1]);
|
||||
if (!empty($_properties['file_dependency'])) {
|
||||
foreach ($_properties['file_dependency'] as $file_to_check) {
|
||||
If (filemtime($file_to_check[0]) != $file_to_check[1]) {
|
||||
if (preg_match('~\<\?php /\*(.*)\*/ \?\>~', $this->compiled_template, $_matches)) {
|
||||
$this->properties = unserialize($_matches[1]);
|
||||
if (!empty($this->properties['function'])) {
|
||||
foreach ($this->properties['function'] as $_name => $_data) {
|
||||
$this->smarty->template_functions[$_name]['compiled'] = str_replace(array('_%n'), array("\n"), $_data['compiled']);
|
||||
$this->smarty->template_functions[$_name]['parameter'] = $_data['parameter'];
|
||||
}
|
||||
}
|
||||
if (!empty($this->properties['file_dependency'])) {
|
||||
foreach ($this->properties['file_dependency'] as $_file_to_check) {
|
||||
If (filemtime($_file_to_check[0]) != $_file_to_check[1]) {
|
||||
$this->properties['file_dependency'] = array();
|
||||
$this->mustCompile = true;
|
||||
return $this->mustCompile;
|
||||
}
|
||||
@@ -260,6 +266,15 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
$this->compileTemplateSource();
|
||||
} else {
|
||||
$this->compiled_template = !$this->isEvaluated() && $this->usesCompiler() ? file_get_contents($this->getCompiledFilepath()) : false;
|
||||
if (preg_match('~\<\?php /\*(.*)\*/ \?\>~', $this->compiled_template, $_matches)) {
|
||||
$this->properties = unserialize($_matches[1]);
|
||||
if (!empty($this->properties['function'])) {
|
||||
foreach ($this->properties['function'] as $_name => $_data) {
|
||||
$this->smarty->template_functions[$_name]['compiled'] = str_replace(array('_%n'), array("\n"), $_data['compiled']);
|
||||
$this->smarty->template_functions[$_name]['parameter'] = $_data['parameter'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->compiled_template;
|
||||
|
@@ -113,11 +113,7 @@ class Smarty_Internal_TemplateCompilerBase extends Smarty_Internal_Base {
|
||||
$this->has_output = false;
|
||||
// compile the smarty tag (required compile classes to compile the tag are autoloaded)
|
||||
if (($_output = $this->$tag($args, $this)) === false) {
|
||||
$_ptr = $this->template;
|
||||
while ($_ptr != null && !isset($_ptr->properties['function'][$tag])) {
|
||||
$_ptr = $_ptr->parent;
|
||||
}
|
||||
if ($_ptr != null) {
|
||||
if (isset($this->smarty->template_functions[$tag])) {
|
||||
// template defined by {template} tag
|
||||
$args['name'] = $tag;
|
||||
$tag = 'internal_function_call';
|
||||
|
Reference in New Issue
Block a user