bugfix for recent changes of {function} tag handling

This commit is contained in:
Uwe Tews
2014-11-10 23:57:30 +01:00
parent adc6091c4d
commit 460be5a5da
5 changed files with 41 additions and 27 deletions
@@ -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();