- improvement of {debug} tag output

This commit is contained in:
uwe.tews@googlemail.com
2010-12-01 21:19:20 +00:00
parent e80dd75958
commit 176c3d625c
3 changed files with 171 additions and 124 deletions

View File

@@ -1,4 +1,7 @@
===== SVN trunk =====
01/12/2010
- improvement of {debug} tag output
27/11/2010
-change run output filter before cache file is written. (same as in Smarty2)

View File

@@ -86,8 +86,9 @@ td {
</head>
<body>
<h1>Smarty Debug Console - Total Time {$execution_time|string_format:"%.5f"}</h1>
<h1>Smarty Debug Console - {if isset($template_name)}{$template_name|debug_print_var}{else}Total Time {$execution_time|string_format:"%.5f"}{/if}</h1>
{if !empty($template_data)}
<h2>included templates &amp; config files (load time in seconds)</h2>
<div>
@@ -99,6 +100,7 @@ td {
<br>
{/foreach}
</div>
{/if}
<h2>assigned template variables</h2>
@@ -124,13 +126,14 @@ td {
</html>
{/capture}
<script type="text/javascript">
{literal} if ( self.name == '' ) {
var title = 'Console';
{$id = $template_name|default:''|md5}
if ( self.name == '' ) {
var title = 'Console{$id}';
}
else {
var title = 'Console_' + self.name;
}{/literal}
_smarty_console = window.open("",title.value,"width=680,height=600,resizable,scrollbars=yes");
var title = 'Console_{$id}' + self.name;
}
_smarty_console = window.open("","console{$id}","width=680,height=600,resizable,scrollbars=yes");
_smarty_console.document.write("{$debug_output|escape:'javascript'}");
_smarty_console.document.close();
</script>

View File

@@ -1,18 +1,18 @@
<?php
/**
* Smarty Internal Plugin Debug
*
* Class to collect data for the Smarty Debugging Consol
*
* @package Smarty
* @subpackage Debug
* @author Uwe Tews
*/
* Smarty Internal Plugin Debug
*
* Class to collect data for the Smarty Debugging Consol
*
* @package Smarty
* @subpackage Debug
* @author Uwe Tews
*/
/**
* Smarty Internal Plugin Debug Class
*/
* Smarty Internal Plugin Debug Class
*/
class Smarty_Internal_Debug extends Smarty_Internal_Data {
// template data
static $template_data = array();
@@ -76,10 +76,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data {
public static function display_debug($obj)
{
// prepare information of assigned variables
$ptr = $obj;
while (isset($ptr->parent)) {
$ptr = $ptr->parent;
}
$ptr = self::get_debug_vars($obj);
if ($obj instanceof Smarty) {
$smarty = $obj;
} else {
@@ -99,7 +96,14 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data {
$_template->disableSecurity();
$_template->cache_id = null;
$_template->compile_id = null;
if ($obj instanceof Smarty_Internal_Template) {
$_template->assign('template_name',$obj->resource_type.':'.$obj->resource_name);
}
if ($obj instanceof Smarty) {
$_template->assign('template_data', self::$template_data);
} else {
$_template->assign('template_data', null);
}
$_template->assign('assigned_vars', $_assigned_vars);
$_template->assign('config_vars', $_config_vars);
$_template->assign('execution_time', microtime(true) - $smarty->start_time);
@@ -107,6 +111,43 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data {
$smarty->left_delimiter = $ldelim;
$smarty->right_delimiter = $rdelim;
}
/*
* Recursively gets variables from all template/data scopes
*/
public static function get_debug_vars($obj, $is_parent = false)
{
$config_vars = $obj->config_vars;
$tpl_vars = array();
foreach ($obj->tpl_vars as $key => $var) {
$tpl_vars[$key] = clone $var;
if (true) {
if ($obj instanceof Smarty_Internal_Template) {
$tpl_vars[$key]->scope = $obj->resource_type.':'.$obj->resource_name;
} elseif ($obj instanceof Smarty_Data) {
$tpl_vars[$key]->scope = 'Data object';
} else {
$tpl_vars[$key]->scope = 'Smarty root';
}
} else {
$tpl_vars[$key]->scope = 'local';
}
}
if (isset($obj->parent)) {
$parent = self::get_debug_vars($obj->parent, true);
$tpl_vars = array_merge($parent->tpl_vars, $tpl_vars);
$config_vars = array_merge($parent->config_vars, $config_vars);
} else {
foreach (Smarty::$global_tpl_vars as $name => $var) {
if (!array_key_exists($name, $tpl_vars)) {
$clone = clone $var;
$clone->scope = 'Global';
$tpl_vars[$name] = $clone;
}
}
}
return (object) array('tpl_vars' => $tpl_vars, 'config_vars' => $config_vars);
}
/**
* get_key