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
|
|
|
|
*/
|
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
|
|
|
|
*/
|
2009-09-19 13:22:32 +00:00
|
|
|
public static function display_debug($smarty)
|
2009-11-11 22:09:06 +00:00
|
|
|
{
|
2009-03-22 16:09:05 +00:00
|
|
|
// prepare information of assigned variables
|
2009-05-05 17:19:33 +00:00
|
|
|
$_assigned_vars = $smarty->tpl_vars;
|
2009-03-22 16:09:05 +00:00
|
|
|
ksort($_assigned_vars);
|
2009-05-05 17:19:33 +00:00
|
|
|
$_config_vars = $smarty->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 = '}';
|
2009-08-08 17:28:23 +00:00
|
|
|
$_template = new Smarty_Template ($smarty->debug_tpl, $smarty);
|
2009-03-22 16:09:05 +00:00
|
|
|
$_template->caching = false;
|
|
|
|
$_template->force_compile = false;
|
|
|
|
$_template->security = false;
|
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);
|
2009-05-05 17:19:33 +00:00
|
|
|
echo $smarty->fetch($_template);
|
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
|
|
|
?>
|