2009-03-22 16:09:05 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2010-07-23 12:53:04 +00:00
|
|
|
* Smarty Internal Plugin Debug
|
|
|
|
*
|
|
|
|
* Class to collect data for the Smarty Debugging Consol
|
|
|
|
*
|
|
|
|
* @package Smarty
|
|
|
|
* @subpackage Debug
|
|
|
|
* @author Uwe Tews
|
|
|
|
*/
|
2010-08-17 15:39:51 +00:00
|
|
|
|
2009-03-22 16:09:05 +00:00
|
|
|
/**
|
2010-07-23 12:53:04 +00:00
|
|
|
* Smarty Internal Plugin Debug Class
|
|
|
|
*/
|
2009-12-27 15:06:49 +00:00
|
|
|
class Smarty_Internal_Debug extends Smarty_Internal_Data {
|
2009-11-11 22:09:06 +00:00
|
|
|
// template data
|
|
|
|
static $template_data = array();
|
|
|
|
|
|
|
|
/**
|
2010-07-23 12:53:04 +00:00
|
|
|
* Start logging of compile time
|
|
|
|
*/
|
2009-11-11 22:09:06 +00:00
|
|
|
public static function start_compile($template)
|
|
|
|
{
|
|
|
|
$key = self::get_key($template);
|
2010-06-20 14:37:47 +00:00
|
|
|
self::$template_data[$key]['start_time'] = microtime(true);
|
2009-11-11 22:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-07-23 12:53:04 +00:00
|
|
|
* End logging of compile time
|
|
|
|
*/
|
2009-11-11 22:09:06 +00:00
|
|
|
public static function end_compile($template)
|
|
|
|
{
|
|
|
|
$key = self::get_key($template);
|
2010-06-20 14:37:47 +00:00
|
|
|
self::$template_data[$key]['compile_time'] += microtime(true) - self::$template_data[$key]['start_time'];
|
2009-11-11 22:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-07-23 12:53:04 +00:00
|
|
|
* Start logging of render time
|
|
|
|
*/
|
2009-11-11 22:09:06 +00:00
|
|
|
public static function start_render($template)
|
|
|
|
{
|
|
|
|
$key = self::get_key($template);
|
2010-06-20 14:37:47 +00:00
|
|
|
self::$template_data[$key]['start_time'] = microtime(true);
|
2009-11-11 22:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-07-23 12:53:04 +00:00
|
|
|
* End logging of compile time
|
|
|
|
*/
|
2009-11-11 22:09:06 +00:00
|
|
|
public static function end_render($template)
|
|
|
|
{
|
|
|
|
$key = self::get_key($template);
|
2010-06-20 14:37:47 +00:00
|
|
|
self::$template_data[$key]['render_time'] += microtime(true) - self::$template_data[$key]['start_time'];
|
2009-11-11 22:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-07-23 12:53:04 +00:00
|
|
|
* Start logging of cache time
|
|
|
|
*/
|
2009-11-11 22:09:06 +00:00
|
|
|
public static function start_cache($template)
|
|
|
|
{
|
|
|
|
$key = self::get_key($template);
|
2010-06-20 14:37:47 +00:00
|
|
|
self::$template_data[$key]['start_time'] = microtime(true);
|
2009-11-11 22:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-07-23 12:53:04 +00:00
|
|
|
* End logging of cache time
|
|
|
|
*/
|
2009-11-11 22:09:06 +00:00
|
|
|
public static function end_cache($template)
|
|
|
|
{
|
|
|
|
$key = self::get_key($template);
|
2010-06-20 14:37:47 +00:00
|
|
|
self::$template_data[$key]['cache_time'] += microtime(true) - self::$template_data[$key]['start_time'];
|
2009-11-11 22:09:06 +00:00
|
|
|
}
|
2009-03-22 16:09:05 +00:00
|
|
|
/**
|
2010-07-23 12:53:04 +00:00
|
|
|
* Opens a window for the Smarty Debugging Consol and display the data
|
|
|
|
*/
|
2010-11-13 01:53:38 +00:00
|
|
|
public static function display_debug($obj)
|
2009-11-11 22:09:06 +00:00
|
|
|
{
|
2009-03-22 16:09:05 +00:00
|
|
|
// prepare information of assigned variables
|
2010-11-13 01:53:38 +00:00
|
|
|
$ptr = $obj;
|
|
|
|
while (isset($ptr->parent)) {
|
|
|
|
$ptr = $ptr->parent;
|
|
|
|
}
|
|
|
|
if ($obj instanceof Smarty) {
|
|
|
|
$smarty = $obj;
|
|
|
|
} else {
|
|
|
|
$smarty = $obj->smarty;
|
|
|
|
}
|
|
|
|
$_assigned_vars = $ptr->tpl_vars;
|
2009-03-22 16:09:05 +00:00
|
|
|
ksort($_assigned_vars);
|
2010-11-13 01:53:38 +00:00
|
|
|
$_config_vars = $ptr->config_vars;
|
2009-03-22 16:09:05 +00:00
|
|
|
ksort($_config_vars);
|
2010-07-23 12:53:04 +00:00
|
|
|
$ldelim = $smarty->left_delimiter;
|
|
|
|
$rdelim = $smarty->right_delimiter;
|
|
|
|
$smarty->left_delimiter = '{';
|
|
|
|
$smarty->right_delimiter = '}';
|
2010-11-13 17:48:30 +00:00
|
|
|
$_template = new Smarty_Internal_Template ($smarty->debug_tpl, $smarty);
|
2009-03-22 16:09:05 +00:00
|
|
|
$_template->caching = false;
|
|
|
|
$_template->force_compile = false;
|
2010-11-11 21:34:36 +00:00
|
|
|
$_template->disableSecurity();
|
2009-11-28 18:48:02 +00:00
|
|
|
$_template->cache_id = null;
|
|
|
|
$_template->compile_id = null;
|
2009-11-11 22:09:06 +00:00
|
|
|
$_template->assign('template_data', self::$template_data);
|
2009-03-22 16:09:05 +00:00
|
|
|
$_template->assign('assigned_vars', $_assigned_vars);
|
|
|
|
$_template->assign('config_vars', $_config_vars);
|
2010-06-20 14:37:47 +00:00
|
|
|
$_template->assign('execution_time', microtime(true) - $smarty->start_time);
|
2010-11-27 15:05:38 +00:00
|
|
|
echo $_template->getRenderedTemplate();
|
2010-07-23 12:53:04 +00:00
|
|
|
$smarty->left_delimiter = $ldelim;
|
|
|
|
$smarty->right_delimiter = $rdelim;
|
2009-03-22 16:09:05 +00:00
|
|
|
}
|
2009-11-11 22:09:06 +00:00
|
|
|
|
|
|
|
/**
|
2010-07-23 12:53:04 +00:00
|
|
|
* get_key
|
|
|
|
*/
|
2009-11-11 22:09:06 +00:00
|
|
|
static function get_key($template)
|
2010-07-23 12:53:04 +00:00
|
|
|
{
|
2010-01-05 21:10:25 +00:00
|
|
|
// calculate Uid if not already done
|
|
|
|
if ($template->templateUid == '') {
|
|
|
|
$template->getTemplateFilepath();
|
|
|
|
}
|
|
|
|
$key = $template->templateUid;
|
2009-11-11 22:09:06 +00:00
|
|
|
if (isset(self::$template_data[$key])) {
|
|
|
|
return $key;
|
|
|
|
} else {
|
|
|
|
self::$template_data[$key]['name'] = $template->getTemplateFilepath();
|
|
|
|
self::$template_data[$key]['compile_time'] = 0;
|
|
|
|
self::$template_data[$key]['render_time'] = 0;
|
|
|
|
self::$template_data[$key]['cache_time'] = 0;
|
|
|
|
return $key;
|
|
|
|
}
|
|
|
|
}
|
2009-03-22 16:09:05 +00:00
|
|
|
}
|
|
|
|
|
2010-06-20 14:37:47 +00:00
|
|
|
?>
|