From 43ae585e5edcdba42c87810ca09b2ee655486acb Mon Sep 17 00:00:00 2001 From: "Uwe.Tews" Date: Tue, 9 Feb 2010 21:20:17 +0000 Subject: [PATCH] - added $smarty->_tag_stack for tracing block tag hierarchy --- change_log.txt | 3 +++ libs/Smarty.class.php | 2 ++ .../smarty_internal_compile_private_block_plugin.php | 9 ++++----- ...nternal_compile_private_object_block_function.php | 7 ++++--- ...rty_internal_compile_private_registered_block.php | 12 ++++++------ .../smarty_internal_templatecompilerbase.php | 8 +++++++- 6 files changed, 26 insertions(+), 15 deletions(-) diff --git a/change_log.txt b/change_log.txt index 00900040..529e8520 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,3 +1,6 @@ +09/02/2010 +- added $smarty->_tag_stack for tracing block tag hierarchy + 08/02/2010 - bugfix use template fullpath at §smarty->cache->clear(...), $smarty->clear_cache(....) - bugfix of cache filename on extended templates when force_compile=true diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 3328586f..6cf256b1 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -222,6 +222,8 @@ class Smarty extends Smarty_Internal_Data { public $smarty = null; // block data at template inheritance public $block_data = array(); + // block tag hierarchy + public $_tag_stack = array(); // generate deprecated function call notices? public $deprecation_notices = true; diff --git a/libs/sysplugins/smarty_internal_compile_private_block_plugin.php b/libs/sysplugins/smarty_internal_compile_private_block_plugin.php index 0c980e1f..01d38c21 100644 --- a/libs/sysplugins/smarty_internal_compile_private_block_plugin.php +++ b/libs/sysplugins/smarty_internal_compile_private_block_plugin.php @@ -45,9 +45,9 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi $this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache; // compile code if (is_array($function)) { - $output = 'smarty, $_block_repeat, $_smarty_tpl));while ($_block_repeat) { ob_start();?>'; + $output = "smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; call_user_func_array(array('{$function[0]}','{$function[1]}'),(array({$_params}, null, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl));while (\$_block_repeat) { ob_start();?>"; } else { - $output = 'smarty, $_block_repeat, $_smarty_tpl);while ($_block_repeat) { ob_start();?>'; + $output = "smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; {$function}({$_params}, null, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl);while (\$_block_repeat) { ob_start();?>"; } } else { // must endblock be nocache? @@ -60,10 +60,9 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi $this->compiler->has_output = true; // compile code if (is_array($function)) { - var_dump('error'); - $output = 'smarty, $_block_repeat, $_smarty_tpl)); }?>'; + $output = "smarty, \$_block_repeat, \$_smarty_tpl)); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; } else { - $output = 'smarty, $_block_repeat, $_smarty_tpl); }?>'; + $output = "smarty, \$_block_repeat, \$_smarty_tpl); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; } } return $output."\n"; diff --git a/libs/sysplugins/smarty_internal_compile_private_object_block_function.php b/libs/sysplugins/smarty_internal_compile_private_object_block_function.php index b0bd1684..69d10501 100644 --- a/libs/sysplugins/smarty_internal_compile_private_object_block_function.php +++ b/libs/sysplugins/smarty_internal_compile_private_object_block_function.php @@ -43,14 +43,15 @@ class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Inter $this->_open_tag($tag . '->' . $methode, $_params); // compile code - $output = 'smarty->registered_objects[\'' . $tag . '\'][0]->' . $methode . '(' . $_params . ', null, $_smarty_tpl->smarty, $_block_repeat, $_smarty_tpl);while ($_block_repeat) { ob_start();?>'; + $output = "smarty->_tag_stack[] = array('{$tag}->{$methode}', {$_params}); \$_block_repeat=true; \$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$methode}({$_params}, null, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl);while (\$_block_repeat) { ob_start();?>"; } else { + $base_tag = substr($tag, 0, -5); // closing tag of block plugin - $_params = $this->_close_tag(substr($tag, 0, -5) . '->' . $methode); + $_params = $this->_close_tag($base_tag . '->' . $methode); // This tag does create output $this->compiler->has_output = true; // compile code - $output = 'smarty->registered_objects[\'' . substr($tag, 0, -5) . '\'][0]->' . $methode . '(' . $_params . ', $_block_content, $_smarty_tpl->smarty, $_block_repeat, $_smarty_tpl); }?>'; + $output = "smarty->registered_objects['{$base_tag}'][0]->{$methode}({$_params}, \$_block_content, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; } return $output."\n"; } diff --git a/libs/sysplugins/smarty_internal_compile_private_registered_block.php b/libs/sysplugins/smarty_internal_compile_private_registered_block.php index 179929ac..a3a87d14 100644 --- a/libs/sysplugins/smarty_internal_compile_private_registered_block.php +++ b/libs/sysplugins/smarty_internal_compile_private_registered_block.php @@ -46,11 +46,11 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C $function = $compiler->smarty->registered_plugins['block'][$tag][0]; // compile code if (!is_array($function)) { - $output = 'smarty, $_block_repeat, $_smarty_tpl);while ($_block_repeat) { ob_start();?>'; + $output = "smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; {$function}({$_params}, null, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl);while (\$_block_repeat) { ob_start();?>"; } else if (is_object($function[0])) { - $output = 'smarty->registered_plugins[\'block\'][\'' . $tag . '\'][0],array(' . $_params . ', null, $_smarty_tpl->smarty, $_block_repeat, $_smarty_tpl));while ($_block_repeat) { ob_start();?>'; + $output = "smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; call_user_func_array(\$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0],array({$_params}, null, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl));while (\$_block_repeat) { ob_start();?>"; } else { - $output = 'smarty, $_block_repeat, $_smarty_tpl));while ($_block_repeat) { ob_start();?>'; + $output = "smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; call_user_func_array(array({$function[0]}','{$function[1]}'),array({$_params}, null, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl));while (\$_block_repeat) { ob_start();?>"; } } else { // must endblock be nocache? @@ -65,11 +65,11 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C $function = $compiler->smarty->registered_plugins['block'][$base_tag][0]; // compile code if (!is_array($function)) { - $output = 'smarty, $_block_repeat, $_smarty_tpl); }?>'; + $output = "smarty, \$_block_repeat, \$_smarty_tpl); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; } else if (is_object($function[0])) { - $output = 'smarty->registered_plugins[\'block\'][\'' . $base_tag . '\'][0],array(' . $_params . ', $_block_content, $_smarty_tpl->smarty, $_block_repeat, $_smarty_tpl)); }?>'; + $output = "smarty->registered_plugins['block']['{$base_tag}'][0],array({$_params}, \$_block_content, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl)); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; } else { - $output = 'smarty, $_block_repeat, $_smarty_tpl)); }?>'; + $output = "smarty, \$_block_repeat, \$_smarty_tpl)); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; } } return $output."\n"; diff --git a/libs/sysplugins/smarty_internal_templatecompilerbase.php b/libs/sysplugins/smarty_internal_templatecompilerbase.php index ac0ef840..f18a2d82 100644 --- a/libs/sysplugins/smarty_internal_templatecompilerbase.php +++ b/libs/sysplugins/smarty_internal_templatecompilerbase.php @@ -21,7 +21,7 @@ class Smarty_Internal_TemplateCompilerBase { // tag stack public $_tag_stack = array(); // current template - public $template = null; + public $template = null; /** * Initialize compiler @@ -175,6 +175,9 @@ class Smarty_Internal_TemplateCompilerBase { foreach ($this->smarty->plugin_search_order as $plugin_type) { if ($plugin_type == 'compiler' && $this->smarty->loadPlugin('smarty_compiler_' . $tag)) { $plugin = 'smarty_compiler_' . $tag; + if (is_callable($plugin)) { + return call_user_func_array($plugin, array($args, $this->smarty)); + } if (class_exists($plugin, false)) { $plugin = array(new $plugin, 'compile'); } @@ -212,6 +215,9 @@ class Smarty_Internal_TemplateCompilerBase { } if ($this->smarty->loadPlugin('smarty_compiler_' . $tag)) { $plugin = 'smarty_compiler_' . $tag; + if (is_callable($plugin)) { + return call_user_func_array($plugin, array($args, $this->smarty)); + } if (class_exists($plugin, false)) { $plugin = array(new $plugin, 'compile'); }