mirror of
https://github.com/smarty-php/smarty.git
synced 2026-05-03 19:30:49 +02:00
bugfix for recent changes of {function} tag handling
This commit is contained in:
@@ -88,6 +88,7 @@ if (SMARTY_SPL_AUTOLOAD && set_include_path(get_include_path() . PATH_SEPARATOR
|
||||
/**
|
||||
* Load always needed external class files
|
||||
*/
|
||||
/**
|
||||
include_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_data.php';
|
||||
include_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_templatebase.php';
|
||||
include_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_template.php';
|
||||
@@ -95,6 +96,7 @@ include_once SMARTY_SYSPLUGINS_DIR . 'smarty_resource.php';
|
||||
include_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_resource_file.php';
|
||||
include_once SMARTY_SYSPLUGINS_DIR . 'smarty_cacheresource.php';
|
||||
include_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_cacheresource_file.php';
|
||||
* /
|
||||
|
||||
/**
|
||||
* This is the main Smarty class
|
||||
@@ -110,7 +112,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
/**
|
||||
* smarty version
|
||||
*/
|
||||
const SMARTY_VERSION = '3.1.22-dev/2';
|
||||
const SMARTY_VERSION = '3.1.22-dev/3';
|
||||
|
||||
/**
|
||||
* define variable scopes
|
||||
|
||||
@@ -96,7 +96,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
||||
*
|
||||
* @return boolean true
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
$saved_data = $this->closeTag($compiler, array('function'));
|
||||
@@ -106,6 +106,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
||||
$compiler->compiles_template_function = false;
|
||||
$compiler->parent_compiler->templateProperties['tpl_function']['param'][$_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']['param'][$_name]['source_uid'] = $compiler->template->source->uid;
|
||||
$compiler->called_functions = array();
|
||||
$_parameter = $_attr;
|
||||
unset($_parameter['name']);
|
||||
@@ -120,11 +121,11 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
||||
}
|
||||
if (!empty($_paramsArray)) {
|
||||
$_params = 'array(' . implode(",", $_paramsArray) . ')';
|
||||
$_paramsCode = "\$params = array_merge(($_params), \$params);\n";
|
||||
$_paramsCode = "\$params = array_merge($_params, \$params);\n";
|
||||
} else {
|
||||
$_paramsCode = '';
|
||||
}
|
||||
$_functionCode = $compiler->parser->current_buffer->to_smarty_php();
|
||||
$_functionCode = $compiler->parser->current_buffer;
|
||||
// setup buffer for template function code
|
||||
$compiler->parser->current_buffer = new _smarty_template_buffer($compiler->parser);
|
||||
|
||||
@@ -153,19 +154,27 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
||||
}
|
||||
$output .= "?>/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/';\n";
|
||||
}
|
||||
$output .= "\$saved_tpl_vars = \$_smarty_tpl->tpl_vars;\n";
|
||||
$output .= $_paramsCode;
|
||||
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);\n}\n";
|
||||
$output .= "ob_start();\n?>";
|
||||
//$output .= "\$saved_tpl_vars = \$_smarty_tpl->tpl_vars;\n";
|
||||
$output .= "ob_start();\n";
|
||||
$output .= $_paramsCode;
|
||||
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);\n}";
|
||||
$output .= "\$params = var_export(\$params, true);\n";
|
||||
$output .= "echo \"/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php ";
|
||||
$output .= "\\\$saved_tpl_vars = \\\$_smarty_tpl->tpl_vars;\nforeach (\$params as \\\$key => \\\$value) {\n\\\$_smarty_tpl->tpl_vars[\\\$key] = new Smarty_variable(\\\$value);\n}\n?>";
|
||||
$output .= "/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/\n\";?>";
|
||||
// $output .= $compiler->makeNocacheCode("\$saved_tpl_vars = \$_smarty_tpl->tpl_vars;\nforeach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);\n}\n");
|
||||
// $output .= substr($compiler->processNocacheCode('<?php ' . "\$saved_tpl_vars = \$_smarty_tpl->tpl_vars;\n" . $_paramsCode . "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);\n}\n" . "? >\n", true), 6);
|
||||
$compiler->parser->current_buffer->append_subtree(new _smarty_tag($compiler->parser, $output));
|
||||
$compiler->parser->current_buffer->append_subtree(new _smarty_tag($compiler->parser, $_functionCode));
|
||||
$output = "<?php echo str_replace('{$compiler->template->properties['nocache_hash']}', \"{\$_smarty_tpl->properties['nocache_hash']}\", ob_get_clean());\n";
|
||||
$output .= "\$_smarty_tpl->tpl_vars = \$saved_tpl_vars;
|
||||
foreach (Smarty::\$global_tpl_vars as \$key => \$value) if(!isset(\$_smarty_tpl->tpl_vars[\$key])) \$_smarty_tpl->tpl_vars[\$key] = \$value;\n}\n}\n";
|
||||
$output .= "/*/ {$_funcName}_nocache */\n";
|
||||
$compiler->parser->current_buffer->append_subtree( $_functionCode);
|
||||
$output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php ";
|
||||
$output .= "\\\$_smarty_tpl->tpl_vars = \\\$saved_tpl_vars;\n";
|
||||
$output .= "foreach (Smarty::\\\$global_tpl_vars as \\\$key => \\\$value) if(!isset(\\\$_smarty_tpl->tpl_vars[\\\$key])) \\\$_smarty_tpl->tpl_vars[\\\$key] = \\\$value;?>";
|
||||
$output .= "/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/\";\n?>";
|
||||
$output .= "<?php echo str_replace('{$compiler->template->properties['nocache_hash']}', \$_smarty_tpl->properties['nocache_hash'], ob_get_clean());\n}\n}\n";
|
||||
$output .= "/*/ {$_funcName}_nocache */\n\n";
|
||||
$output .= "?>\n";
|
||||
$compiler->parser->current_buffer->append_subtree(new _smarty_tag($compiler->parser, $output));
|
||||
$_functionCode = preg_replace_callback("/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%\*\/';(\?>\n)?)/", array($this, 'removeNocache'), $_functionCode);
|
||||
$_functionCode = 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;
|
||||
$output = "<?php\n";
|
||||
@@ -188,9 +197,9 @@ foreach (Smarty::\$global_tpl_vars as \$key => \$value) if(!isset(\$_smarty_tpl-
|
||||
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);\n}?>";
|
||||
$compiler->parser->current_buffer->append_subtree(new _smarty_tag($compiler->parser, $output));
|
||||
$compiler->parser->current_buffer->append_subtree(new _smarty_tag($compiler->parser, $_functionCode));
|
||||
$output = "<?php \$_smarty_tpl->tpl_vars = \$saved_tpl_vars;
|
||||
foreach (Smarty::\$global_tpl_vars as \$key => \$value) if(!isset(\$_smarty_tpl->tpl_vars[\$key])) \$_smarty_tpl->tpl_vars[\$key] = \$value;\n}\n}\n";
|
||||
$output .= "/*/ {$_funcName} */\n";
|
||||
$output = "<?php \$_smarty_tpl->tpl_vars = \$saved_tpl_vars;\n";
|
||||
$output .= "foreach (Smarty::\$global_tpl_vars as \$key => \$value) if(!isset(\$_smarty_tpl->tpl_vars[\$key])) \$_smarty_tpl->tpl_vars[\$key] = \$value;\n}\n}\n";
|
||||
$output .= "/*/ {$_funcName} */\n\n";
|
||||
$output .= "?>\n";
|
||||
$compiler->parser->current_buffer->append_subtree(new _smarty_tag($compiler->parser, $output));
|
||||
$compiler->parent_compiler->templateFunctionCode .= $compiler->parser->current_buffer->to_smarty_php();
|
||||
|
||||
@@ -38,13 +38,12 @@ class Smarty_Internal_Function_Call_Handler
|
||||
$code = file_get_contents($funcParam['compiled_filepath']);
|
||||
// grab template function
|
||||
if (preg_match("/\/\* {$_function} \*\/([\S\s]*?)\/\*\/ {$_function} \*\//", $code, $match)) {
|
||||
$code = "\n";
|
||||
$code .= $match[0];
|
||||
$code .= "?>\n";
|
||||
unset($match);
|
||||
// grab source info from file dependency
|
||||
preg_match("/\s*'{$funcParam['source_uid']}'([\S\s]*?)\),/", $code, $match1);
|
||||
unset($code);
|
||||
$output = '';
|
||||
// make PHP function known
|
||||
eval($code);
|
||||
eval($match[0]);
|
||||
if (function_exists($_function)) {
|
||||
// call template function
|
||||
$_function ($_smarty_tpl, $_params);
|
||||
@@ -58,7 +57,11 @@ class Smarty_Internal_Function_Call_Handler
|
||||
$cache = $tplPtr->cached;
|
||||
$content = $cache->read($tplPtr);
|
||||
if ($content) {
|
||||
$cache->write($tplPtr, $content . "<?php " . $code);
|
||||
// check if we must update file dependency
|
||||
if (!preg_match("/'{$funcParam['source_uid']}'([\S\s]*?)'nocache_hash'/", $content, $match2)) {
|
||||
$content = preg_replace("/('file_dependency'([\S\s]*?)\()/", "\\1{$match1[0]}", $content);
|
||||
}
|
||||
$cache->write($tplPtr, $content . "<?php " . $match[0] . "?>\n");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -271,7 +271,9 @@ class _smarty_template_buffer extends _smarty_parsetree
|
||||
*/
|
||||
public function append_subtree(_smarty_parsetree $subtree)
|
||||
{
|
||||
if ($subtree->data !== '') {
|
||||
if (!empty($subtree->subtrees)) {
|
||||
$this->subtrees = array_merge($this->subtrees, $subtree->subtrees);
|
||||
} else if ($subtree->data !== '') {
|
||||
$this->subtrees[] = $subtree;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,9 +282,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
Smarty_Internal_Debug::start_compile($this->template);
|
||||
}
|
||||
$no_sources = count($this->sources);
|
||||
if ($loop || $no_sources) {
|
||||
$this->template->properties['file_dependency'][$this->template->source->uid] = array($this->template->source->filepath, $this->template->source->timestamp, $this->template->source->type);
|
||||
}
|
||||
$this->parent_compiler->template->properties['file_dependency'][$this->template->source->uid] = array($this->template->source->filepath, $this->template->source->timestamp, $this->template->source->type);
|
||||
$loop ++;
|
||||
if ($no_sources) {
|
||||
$this->inheritance_child = true;
|
||||
|
||||
Reference in New Issue
Block a user