2009-03-22 16:09:05 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2011-09-16 14:19:56 +00:00
|
|
|
* Smarty Internal Plugin Debug
|
|
|
|
* Class to collect data for the Smarty Debugging Consol
|
|
|
|
*
|
2014-06-06 02:40:04 +00:00
|
|
|
* @package Smarty
|
2011-09-16 14:19:56 +00:00
|
|
|
* @subpackage Debug
|
2014-06-06 02:40:04 +00:00
|
|
|
* @author Uwe Tews
|
2011-09-16 14:19:56 +00:00
|
|
|
*/
|
2010-08-17 15:39:51 +00:00
|
|
|
|
2009-03-22 16:09:05 +00:00
|
|
|
/**
|
2011-09-16 14:19:56 +00:00
|
|
|
* Smarty Internal Plugin Debug Class
|
|
|
|
*
|
2014-06-06 02:40:04 +00:00
|
|
|
* @package Smarty
|
2011-09-16 14:19:56 +00:00
|
|
|
* @subpackage Debug
|
|
|
|
*/
|
2013-07-14 22:15:45 +00:00
|
|
|
class Smarty_Internal_Debug extends Smarty_Internal_Data
|
|
|
|
{
|
2011-09-16 14:19:56 +00:00
|
|
|
/**
|
|
|
|
* template data
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2013-07-15 18:18:28 +00:00
|
|
|
public static $template_data = array();
|
2011-09-16 14:19:56 +00:00
|
|
|
|
2013-08-24 18:46:31 +00:00
|
|
|
/**
|
|
|
|
* List of uid's which shall be ignored
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public static $ignore_uid = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ignore template
|
|
|
|
*
|
|
|
|
* @param object $template
|
|
|
|
*/
|
|
|
|
public static function ignore($template)
|
|
|
|
{
|
|
|
|
// calculate Uid if not already done
|
|
|
|
if ($template->source->uid == '') {
|
|
|
|
$template->source->filepath;
|
|
|
|
}
|
|
|
|
self::$ignore_uid[$template->source->uid] = true;
|
|
|
|
}
|
|
|
|
|
2011-09-16 14:19:56 +00:00
|
|
|
/**
|
|
|
|
* Start logging of compile time
|
|
|
|
*
|
|
|
|
* @param object $template
|
|
|
|
*/
|
2013-07-15 18:18:28 +00:00
|
|
|
public static function start_compile($template)
|
2011-09-16 14:19:56 +00:00
|
|
|
{
|
2013-08-24 18:46:31 +00:00
|
|
|
static $_is_stringy = array('string' => true, 'eval' => true);
|
|
|
|
if (!empty($template->compiler->trace_uid)) {
|
|
|
|
$key = $template->compiler->trace_uid;
|
|
|
|
if (!isset(self::$template_data[$key])) {
|
|
|
|
if (isset($_is_stringy[$template->source->type])) {
|
|
|
|
self::$template_data[$key]['name'] = '\'' . substr($template->source->name, 0, 25) . '...\'';
|
|
|
|
} else {
|
|
|
|
self::$template_data[$key]['name'] = $template->source->filepath;
|
|
|
|
}
|
|
|
|
self::$template_data[$key]['compile_time'] = 0;
|
|
|
|
self::$template_data[$key]['render_time'] = 0;
|
|
|
|
self::$template_data[$key]['cache_time'] = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (isset(self::$ignore_uid[$template->source->uid])) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$key = self::get_key($template);
|
|
|
|
}
|
2011-09-16 14:19:56 +00:00
|
|
|
self::$template_data[$key]['start_time'] = microtime(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* End logging of compile time
|
|
|
|
*
|
|
|
|
* @param object $template
|
|
|
|
*/
|
2013-07-15 18:18:28 +00:00
|
|
|
public static function end_compile($template)
|
2011-09-16 14:19:56 +00:00
|
|
|
{
|
2013-08-24 18:46:31 +00:00
|
|
|
if (!empty($template->compiler->trace_uid)) {
|
|
|
|
$key = $template->compiler->trace_uid;
|
|
|
|
} else {
|
|
|
|
if (isset(self::$ignore_uid[$template->source->uid])) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$key = self::get_key($template);
|
|
|
|
}
|
2011-09-16 14:19:56 +00:00
|
|
|
self::$template_data[$key]['compile_time'] += microtime(true) - self::$template_data[$key]['start_time'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start logging of render time
|
|
|
|
*
|
|
|
|
* @param object $template
|
|
|
|
*/
|
2013-07-15 18:18:28 +00:00
|
|
|
public static function start_render($template)
|
2011-09-16 14:19:56 +00:00
|
|
|
{
|
|
|
|
$key = self::get_key($template);
|
|
|
|
self::$template_data[$key]['start_time'] = microtime(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* End logging of compile time
|
|
|
|
*
|
|
|
|
* @param object $template
|
|
|
|
*/
|
2013-07-15 18:18:28 +00:00
|
|
|
public static function end_render($template)
|
2011-09-16 14:19:56 +00:00
|
|
|
{
|
|
|
|
$key = self::get_key($template);
|
|
|
|
self::$template_data[$key]['render_time'] += microtime(true) - self::$template_data[$key]['start_time'];
|
|
|
|
}
|
2009-11-11 22:09:06 +00:00
|
|
|
|
2011-09-16 14:19:56 +00:00
|
|
|
/**
|
|
|
|
* Start logging of cache time
|
|
|
|
*
|
|
|
|
* @param object $template cached template
|
|
|
|
*/
|
2013-07-15 18:18:28 +00:00
|
|
|
public static function start_cache($template)
|
2011-09-16 14:19:56 +00:00
|
|
|
{
|
|
|
|
$key = self::get_key($template);
|
|
|
|
self::$template_data[$key]['start_time'] = microtime(true);
|
|
|
|
}
|
2009-11-11 22:09:06 +00:00
|
|
|
|
2011-09-16 14:19:56 +00:00
|
|
|
/**
|
|
|
|
* End logging of cache time
|
|
|
|
*
|
|
|
|
* @param object $template cached template
|
|
|
|
*/
|
2013-07-15 18:18:28 +00:00
|
|
|
public static function end_cache($template)
|
2011-09-16 14:19:56 +00:00
|
|
|
{
|
|
|
|
$key = self::get_key($template);
|
|
|
|
self::$template_data[$key]['cache_time'] += microtime(true) - self::$template_data[$key]['start_time'];
|
|
|
|
}
|
2009-11-11 22:09:06 +00:00
|
|
|
|
2014-11-03 22:27:32 +01:00
|
|
|
/**
|
|
|
|
* Start logging of cache time
|
|
|
|
*
|
|
|
|
* @param object $template cached template
|
|
|
|
*/
|
|
|
|
public static function start_template($template)
|
|
|
|
{
|
|
|
|
$key = self::get_key($template);
|
|
|
|
self::$template_data[$key]['start_template_time'] = microtime(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* End logging of cache time
|
|
|
|
*
|
|
|
|
* @param object $template cached template
|
|
|
|
*/
|
|
|
|
public static function end_template($template)
|
|
|
|
{
|
|
|
|
$key = self::get_key($template);
|
|
|
|
self::$template_data[$key]['total_time'] += microtime(true) - self::$template_data[$key]['start_template_time'];
|
|
|
|
self::$template_data[$key]['properties'] = $template->properties;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register template object
|
|
|
|
*
|
|
|
|
* @param object $template cached template
|
|
|
|
*/
|
|
|
|
public static function register_template($template)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register data object
|
|
|
|
*
|
|
|
|
* @param object $data data object
|
|
|
|
*/
|
|
|
|
public static function register_data($data)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-09-16 14:19:56 +00:00
|
|
|
/**
|
|
|
|
* Opens a window for the Smarty Debugging Consol and display the data
|
|
|
|
*
|
|
|
|
* @param Smarty_Internal_Template|Smarty $obj object to debug
|
|
|
|
*/
|
2014-11-03 22:27:32 +01:00
|
|
|
public static function display_debug($obj, $full = false)
|
2011-09-16 14:19:56 +00:00
|
|
|
{
|
|
|
|
// prepare information of assigned variables
|
|
|
|
$ptr = self::get_debug_vars($obj);
|
|
|
|
if ($obj instanceof Smarty) {
|
|
|
|
$smarty = clone $obj;
|
|
|
|
} else {
|
|
|
|
$smarty = clone $obj->smarty;
|
|
|
|
}
|
|
|
|
$_assigned_vars = $ptr->tpl_vars;
|
|
|
|
ksort($_assigned_vars);
|
|
|
|
$_config_vars = $ptr->config_vars;
|
|
|
|
ksort($_config_vars);
|
|
|
|
$smarty->registered_filters = array();
|
|
|
|
$smarty->autoload_filters = array();
|
|
|
|
$smarty->default_modifiers = array();
|
|
|
|
$smarty->force_compile = false;
|
|
|
|
$smarty->left_delimiter = '{';
|
|
|
|
$smarty->right_delimiter = '}';
|
|
|
|
$smarty->debugging = false;
|
2013-07-29 13:58:08 +00:00
|
|
|
$smarty->debugging_ctrl = 'NONE';
|
2011-09-16 14:19:56 +00:00
|
|
|
$smarty->force_compile = false;
|
|
|
|
$_template = new Smarty_Internal_Template($smarty->debug_tpl, $smarty);
|
|
|
|
$_template->caching = false;
|
|
|
|
$_template->disableSecurity();
|
|
|
|
$_template->cache_id = null;
|
|
|
|
$_template->compile_id = null;
|
|
|
|
if ($obj instanceof Smarty_Internal_Template) {
|
|
|
|
$_template->assign('template_name', $obj->source->type . ':' . $obj->source->name);
|
|
|
|
}
|
2014-11-03 22:27:32 +01:00
|
|
|
if ($obj instanceof Smarty || $full) {
|
2011-09-16 14:19:56 +00:00
|
|
|
$_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);
|
2014-11-04 18:59:57 +01:00
|
|
|
$_template->assign('display_mode', $smarty->debugging == 2 || !$full);
|
2011-09-16 14:19:56 +00:00
|
|
|
echo $_template->fetch();
|
2014-11-03 22:27:32 +01:00
|
|
|
if ($full) {
|
|
|
|
self::$ignore_uid = array();
|
|
|
|
self::$template_data = array();
|
|
|
|
}
|
2011-09-16 14:19:56 +00:00
|
|
|
}
|
2009-11-11 22:09:06 +00:00
|
|
|
|
2011-09-16 14:19:56 +00:00
|
|
|
/**
|
|
|
|
* Recursively gets variables from all template/data scopes
|
|
|
|
*
|
2013-07-14 22:15:45 +00:00
|
|
|
* @param Smarty_Internal_Template|Smarty_Data $obj object to debug
|
2014-06-06 02:40:04 +00:00
|
|
|
*
|
2011-09-16 14:19:56 +00:00
|
|
|
* @return StdClass
|
|
|
|
*/
|
2013-07-15 18:18:28 +00:00
|
|
|
public static function get_debug_vars($obj)
|
2011-09-16 14:19:56 +00:00
|
|
|
{
|
2014-11-03 22:27:32 +01:00
|
|
|
$config_vars = array();
|
|
|
|
foreach ($obj->config_vars as $key => $var) {
|
|
|
|
$config_vars[$key]['value'] = $var;
|
|
|
|
if ($obj instanceof Smarty_Internal_Template) {
|
|
|
|
$config_vars[$key]['scope'] = $obj->source->type . ':' . $obj->source->name;
|
|
|
|
} elseif ($obj instanceof Smarty_Data) {
|
|
|
|
$tpl_vars[$key]['scope'] = $obj->dataObjectName;
|
|
|
|
} else {
|
|
|
|
$config_vars[$key]['scope'] = 'Smarty object';
|
|
|
|
}
|
|
|
|
}
|
2011-09-16 14:19:56 +00:00
|
|
|
$tpl_vars = array();
|
|
|
|
foreach ($obj->tpl_vars as $key => $var) {
|
2014-11-03 22:27:32 +01:00
|
|
|
foreach ($var as $varkey => $varvalue) {
|
|
|
|
if ($varkey == 'value') {
|
|
|
|
$tpl_vars[$key][$varkey] = $varvalue;
|
|
|
|
} else if ($varkey == 'nocache') {
|
|
|
|
if ($varvalue == true) {
|
|
|
|
$tpl_vars[$key][$varkey] = $varvalue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($varkey != 'scope' || $varvalue !== 0)
|
|
|
|
$tpl_vars[$key]['attributes'][$varkey] = $varvalue;
|
|
|
|
}
|
|
|
|
}
|
2011-09-16 14:19:56 +00:00
|
|
|
if ($obj instanceof Smarty_Internal_Template) {
|
2014-11-03 22:27:32 +01:00
|
|
|
$tpl_vars[$key]['scope'] = $obj->source->type . ':' . $obj->source->name;
|
2011-09-16 14:19:56 +00:00
|
|
|
} elseif ($obj instanceof Smarty_Data) {
|
2014-11-03 22:27:32 +01:00
|
|
|
$tpl_vars[$key]['scope'] = $obj->dataObjectName;
|
2011-09-16 14:19:56 +00:00
|
|
|
} else {
|
2014-11-03 22:27:32 +01:00
|
|
|
$tpl_vars[$key]['scope'] = 'Smarty object';
|
2011-09-16 14:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
2009-11-11 22:09:06 +00:00
|
|
|
|
2011-09-16 14:19:56 +00:00
|
|
|
if (isset($obj->parent)) {
|
|
|
|
$parent = self::get_debug_vars($obj->parent);
|
2014-11-03 22:27:32 +01:00
|
|
|
foreach($parent->tpl_vars as $name => $pvar){
|
|
|
|
if (isset($tpl_vars[$name]) && $tpl_vars[$name]['value'] === $pvar['value']) {
|
|
|
|
$tpl_vars[$name]['scope'] = $pvar['scope'];
|
|
|
|
}
|
|
|
|
}
|
2011-09-16 14:19:56 +00:00
|
|
|
$tpl_vars = array_merge($parent->tpl_vars, $tpl_vars);
|
2014-11-03 22:27:32 +01:00
|
|
|
|
|
|
|
foreach($parent->config_vars as $name => $pvar){
|
|
|
|
if (isset($config_vars[$name]) && $config_vars[$name]['value'] === $pvar['value']) {
|
|
|
|
$config_vars[$name]['scope'] = $pvar['scope'];
|
|
|
|
}
|
|
|
|
}
|
2011-09-16 14:19:56 +00:00
|
|
|
$config_vars = array_merge($parent->config_vars, $config_vars);
|
|
|
|
} else {
|
2014-11-03 22:27:32 +01:00
|
|
|
foreach (Smarty::$global_tpl_vars as $key => $var) {
|
|
|
|
if (!array_key_exists($key, $tpl_vars)) {
|
|
|
|
foreach ($var as $varkey => $varvalue) {
|
|
|
|
if ($varkey == 'value') {
|
|
|
|
$tpl_vars[$key][$varkey] = $varvalue;
|
|
|
|
} else {
|
|
|
|
if ($varkey == 'nocache') {
|
|
|
|
if ($varvalue == true) {
|
|
|
|
$tpl_vars[$key][$varkey] = $varvalue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($varkey != 'scope' || $varvalue !== 0) {
|
|
|
|
$tpl_vars[$key]['attributes'][$varkey] = $varvalue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$tpl_vars[$key]['scope'] = 'Global';
|
2011-09-16 14:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-14 22:15:45 +00:00
|
|
|
|
2014-06-06 02:40:04 +00:00
|
|
|
return (object) array('tpl_vars' => $tpl_vars, 'config_vars' => $config_vars);
|
2011-09-16 14:19:56 +00:00
|
|
|
}
|
2009-11-11 22:09:06 +00:00
|
|
|
|
2011-09-16 14:19:56 +00:00
|
|
|
/**
|
|
|
|
* Return key into $template_data for template
|
|
|
|
*
|
2013-07-14 22:15:45 +00:00
|
|
|
* @param object $template template object
|
2014-06-06 02:40:04 +00:00
|
|
|
*
|
2013-07-14 22:15:45 +00:00
|
|
|
* @return string key into $template_data
|
2011-09-16 14:19:56 +00:00
|
|
|
*/
|
|
|
|
private static function get_key($template)
|
|
|
|
{
|
2011-10-01 18:10:48 +00:00
|
|
|
static $_is_stringy = array('string' => true, 'eval' => true);
|
2011-09-16 14:19:56 +00:00
|
|
|
// calculate Uid if not already done
|
|
|
|
if ($template->source->uid == '') {
|
|
|
|
$template->source->filepath;
|
|
|
|
}
|
|
|
|
$key = $template->source->uid;
|
|
|
|
if (isset(self::$template_data[$key])) {
|
|
|
|
return $key;
|
|
|
|
} else {
|
2011-10-01 18:10:48 +00:00
|
|
|
if (isset($_is_stringy[$template->source->type])) {
|
2013-08-24 18:46:31 +00:00
|
|
|
self::$template_data[$key]['name'] = '\'' . substr($template->source->name, 0, 25) . '...\'';
|
2011-09-16 14:19:56 +00:00
|
|
|
} else {
|
|
|
|
self::$template_data[$key]['name'] = $template->source->filepath;
|
|
|
|
}
|
|
|
|
self::$template_data[$key]['compile_time'] = 0;
|
|
|
|
self::$template_data[$key]['render_time'] = 0;
|
|
|
|
self::$template_data[$key]['cache_time'] = 0;
|
2014-11-03 22:27:32 +01:00
|
|
|
self::$template_data[$key]['total_time'] = 0;
|
2013-07-14 22:15:45 +00:00
|
|
|
|
2011-09-16 14:19:56 +00:00
|
|
|
return $key;
|
|
|
|
}
|
|
|
|
}
|
2014-12-30 17:17:15 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* handle 'URL' debugging mode
|
|
|
|
*
|
|
|
|
* @param Smarty_Internal_Template $_template
|
|
|
|
*/
|
|
|
|
public static function debugUrl(Smarty_Internal_Template $_template) {
|
|
|
|
if (isset($_SERVER['QUERY_STRING'])) {
|
|
|
|
$_query_string = $_SERVER['QUERY_STRING'];
|
|
|
|
} else {
|
|
|
|
$_query_string = '';
|
|
|
|
}
|
|
|
|
if (false !== strpos($_query_string, $_template->smarty->smarty_debug_id)) {
|
|
|
|
if (false !== strpos($_query_string, $_template->smarty->smarty_debug_id . '=on')) {
|
|
|
|
// enable debugging for this browser session
|
|
|
|
setcookie('SMARTY_DEBUG', true);
|
|
|
|
$_template->smarty->debugging = true;
|
|
|
|
} elseif (false !== strpos($_query_string, $_template->smarty->smarty_debug_id . '=off')) {
|
|
|
|
// disable debugging for this browser session
|
|
|
|
setcookie('SMARTY_DEBUG', false);
|
|
|
|
$_template->smarty->debugging = false;
|
|
|
|
} else {
|
|
|
|
// enable debugging for this page
|
|
|
|
$_template->smarty->debugging = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (isset($_COOKIE['SMARTY_DEBUG'])) {
|
|
|
|
$_template->smarty->debugging = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-12-01 21:19:20 +00:00
|
|
|
}
|