diff --git a/NEW_FEATURES.txt b/NEW_FEATURES.txt index ce09a56f..b2c18c99 100644 --- a/NEW_FEATURES.txt +++ b/NEW_FEATURES.txt @@ -64,11 +64,23 @@ Smarty 3.1.22 Compiled Templates ================== - Smarty does now automatically detect a change of the $merge_compiled_includes and $escape_html - property and create different compiled templates files depending on the setting. + Smarty does now automatically detects a change of the $merge_compiled_includes and $escape_html + property and creates different compiled templates files depending on the setting. Same applies to config files and the $config_overwrite, $config_booleanize and $config_read_hidden properties. + Debugging + ========= + The layout of the debug window has been changed for better readability + + New class constants + Smarty::DEBUG_OFF + Smarty::DEBUG_ON + Smarty::DEBUG_INDIVIDUAL + have been introduced for setting the $debugging property. + Smarty::DEBUG_INDIVIDUAL will create for each display() and fetch() call an individual gebug window. + + . \ No newline at end of file diff --git a/change_log.txt b/change_log.txt index 0e56d0ab..6ffee78e 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@  ===== 3.1.22-dev ===== (xx.xx.2015) + 07.05.2015 + - improvement of the debugging console. Read NEW_FEATURES.txt + 06.05.2015 - bugfix in 3.1.22-dev cache resource must not be loaded for subtemplates - bugfix/improvement in 3.1.22-dev cache locking did not work as expected diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 6a807eb0..98e99abc 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.22-dev/28'; + const SMARTY_VERSION = '3.1.22-dev/29'; /** * define variable scopes @@ -137,6 +137,13 @@ class Smarty extends Smarty_Internal_TemplateBase const COMPILECHECK_OFF = 0; const COMPILECHECK_ON = 1; const COMPILECHECK_CACHEMISS = 2; + + /** + * define debug modes + */ + const DEBUG_OFF = 0; + const DEBUG_ON = 1; + const DEBUG_INDIVIDUAL = 2; /** * modes for handling of "" tags in templates. */ diff --git a/libs/debug.tpl b/libs/debug.tpl index c414496a..464727b6 100644 --- a/libs/debug.tpl +++ b/libs/debug.tpl @@ -153,8 +153,8 @@ {/capture} diff --git a/libs/sysplugins/smarty_internal_debug.php b/libs/sysplugins/smarty_internal_debug.php index 3241e6c5..f12647ac 100644 --- a/libs/sysplugins/smarty_internal_debug.php +++ b/libs/sysplugins/smarty_internal_debug.php @@ -1,7 +1,7 @@ source->uid == '') { - $template->source->filepath; + if (isset($mode)) { + self::$index ++; + self::$offset ++; + self::$template_data[self::$index] = null; } - self::$ignore_uid[$template->source->uid] = true; + $key = self::get_key($template); + self::$template_data[self::$index][$key]['start_template_time'] = microtime(true); + } + + /** + * End logging of cache time + * + * @param \Smarty_Internal_Template $template cached template + */ + public static function end_template(Smarty_Internal_Template $template) + { + $key = self::get_key($template); + self::$template_data[self::$index][$key]['total_time'] += microtime(true) - self::$template_data[self::$index][$key]['start_template_time']; + self::$template_data[self::$index][$key]['properties'] = $template->properties; } /** * Start logging of compile time * - * @param object $template + * @param \Smarty_Internal_Template $template */ - public static function start_compile($template) + public static function start_compile(Smarty_Internal_Template $template) { 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(self::$template_data[self::$index][$key])) { if (isset($_is_stringy[$template->source->type])) { - self::$template_data[$key]['name'] = '\'' . substr($template->source->name, 0, 25) . '...\''; + self::$template_data[self::$index][$key]['name'] = '\'' . substr($template->source->name, 0, 25) . '...\''; } else { - self::$template_data[$key]['name'] = $template->source->filepath; + self::$template_data[self::$index][$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; + self::$template_data[self::$index][$key]['compile_time'] = 0; + self::$template_data[self::$index][$key]['render_time'] = 0; + self::$template_data[self::$index][$key]['cache_time'] = 0; } } else { if (isset(self::$ignore_uid[$template->source->uid])) { @@ -70,15 +99,15 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data } $key = self::get_key($template); } - self::$template_data[$key]['start_time'] = microtime(true); + self::$template_data[self::$index][$key]['start_time'] = microtime(true); } /** * End logging of compile time * - * @param object $template + * @param \Smarty_Internal_Template $template */ - public static function end_compile($template) + public static function end_compile(Smarty_Internal_Template $template) { if (!empty($template->compiler->trace_uid)) { $key = $template->compiler->trace_uid; @@ -89,102 +118,84 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data $key = self::get_key($template); } - self::$template_data[$key]['compile_time'] += microtime(true) - self::$template_data[$key]['start_time']; + self::$template_data[self::$index][$key]['compile_time'] += microtime(true) - self::$template_data[self::$index][$key]['start_time']; } /** * Start logging of render time * - * @param object $template + * @param \Smarty_Internal_Template $template */ - public static function start_render($template) + public static function start_render(Smarty_Internal_Template $template) { $key = self::get_key($template); - self::$template_data[$key]['start_time'] = microtime(true); + self::$template_data[self::$index][$key]['start_time'] = microtime(true); } /** * End logging of compile time * - * @param object $template + * @param \Smarty_Internal_Template $template */ - public static function end_render($template) + public static function end_render(Smarty_Internal_Template $template) { $key = self::get_key($template); - self::$template_data[$key]['render_time'] += microtime(true) - self::$template_data[$key]['start_time']; + self::$template_data[self::$index][$key]['render_time'] += microtime(true) - self::$template_data[self::$index][$key]['start_time']; } /** * Start logging of cache time * - * @param object $template cached template + * @param \Smarty_Internal_Template $template cached template */ - public static function start_cache($template) + public static function start_cache(Smarty_Internal_Template $template) { $key = self::get_key($template); - self::$template_data[$key]['start_time'] = microtime(true); + self::$template_data[self::$index][$key]['start_time'] = microtime(true); } /** * End logging of cache time * - * @param object $template cached template + * @param o\Smarty_Internal_Template $template cached template */ - public static function end_cache($template) + public static function end_cache(Smarty_Internal_Template $template) { $key = self::get_key($template); - self::$template_data[$key]['cache_time'] += microtime(true) - self::$template_data[$key]['start_time']; - } - - /** - * 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; - + self::$template_data[self::$index][$key]['cache_time'] += microtime(true) - self::$template_data[self::$index][$key]['start_time']; } /** * Register template object * - * @param object $template cached template + * @param \Smarty_Internal_Template $template cached template */ - public static function register_template($template) + public static function register_template(Smarty_Internal_Template $template) { } /** * Register data object * - * @param object $data data object + * @param \Smarty_Data $data data object */ - public static function register_data($data) + public static function register_data(Smarty_Data $data) { } /** - * Opens a window for the Smarty Debugging Consol and display the data + * Opens a window for the Smarty Debugging Console and display the data * * @param Smarty_Internal_Template|Smarty $obj object to debug + * @param bool $full */ public static function display_debug($obj, $full = false) { + if (!$full) { + self::$offset ++; + $savedIndex = self::$index; + self::$index = 9999; + } // prepare information of assigned variables $ptr = self::get_debug_vars($obj); if ($obj instanceof Smarty) { @@ -192,6 +203,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data } else { $smarty = clone $obj->smarty; } + $debugging = $smarty->debugging; $_assigned_vars = $ptr->tpl_vars; ksort($_assigned_vars); $_config_vars = $ptr->config_vars; @@ -207,25 +219,28 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data $smarty->force_compile = false; $_template = new Smarty_Internal_Template($smarty->debug_tpl, $smarty); $_template->caching = false; - $_template->disableSecurity(); + $_template->smarty->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); } if ($obj instanceof Smarty || $full) { - $_template->assign('template_data', self::$template_data); + $_template->assign('template_data', self::$template_data[self::$index]); } 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); - $_template->assign('display_mode', $smarty->debugging == 2 || !$full); + $_template->assign('display_mode', $debugging == 2 || !$full); + $_template->assign('offset', self::$offset * 50); echo $_template->fetch(); - if ($full) { - self::$ignore_uid = array(); - self::$template_data = array(); + if (isset($full)) { + self::$index --; + } + if (!$full) { + self::$index = $savedIndex; } } @@ -254,13 +269,16 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data 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; + if ($varkey == 'nocache') { + if ($varvalue == true) { + $tpl_vars[$key][$varkey] = $varvalue; + } + } else { + if ($varkey != 'scope' || $varvalue !== 0) { + $tpl_vars[$key]['attributes'][$varkey] = $varvalue; + } + } } } if ($obj instanceof Smarty_Internal_Template) { @@ -274,14 +292,14 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data if (isset($obj->parent)) { $parent = self::get_debug_vars($obj->parent); - foreach($parent->tpl_vars as $name => $pvar){ + foreach ($parent->tpl_vars as $name => $pvar) { if (isset($tpl_vars[$name]) && $tpl_vars[$name]['value'] === $pvar['value']) { $tpl_vars[$name]['scope'] = $pvar['scope']; } } $tpl_vars = array_merge($parent->tpl_vars, $tpl_vars); - foreach($parent->config_vars as $name => $pvar){ + foreach ($parent->config_vars as $name => $pvar) { if (isset($config_vars[$name]) && $config_vars[$name]['value'] === $pvar['value']) { $config_vars[$name]['scope'] = $pvar['scope']; } @@ -316,11 +334,11 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data /** * Return key into $template_data for template * - * @param object $template template object + * @param \Smarty_Internal_Template $template template object * * @return string key into $template_data */ - private static function get_key($template) + private static function get_key(Smarty_Internal_Template $template) { static $_is_stringy = array('string' => true, 'eval' => true); // calculate Uid if not already done @@ -328,29 +346,44 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data $template->source->filepath; } $key = $template->source->uid; - if (isset(self::$template_data[$key])) { + if (isset(self::$template_data[self::$index][$key])) { return $key; } else { if (isset($_is_stringy[$template->source->type])) { - self::$template_data[$key]['name'] = '\'' . substr($template->source->name, 0, 25) . '...\''; + self::$template_data[self::$index][$key]['name'] = '\'' . substr($template->source->name, 0, 25) . '...\''; } else { - self::$template_data[$key]['name'] = $template->source->filepath; + self::$template_data[self::$index][$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; - self::$template_data[$key]['total_time'] = 0; + self::$template_data[self::$index][$key]['compile_time'] = 0; + self::$template_data[self::$index][$key]['render_time'] = 0; + self::$template_data[self::$index][$key]['cache_time'] = 0; + self::$template_data[self::$index][$key]['total_time'] = 0; return $key; } } + /** + * Ignore template + * + * @param \Smarty_Internal_Template $template + */ + public static function ignore(Smarty_Internal_Template $template) + { + // calculate Uid if not already done + if ($template->source->uid == '') { + $template->source->filepath; + } + self::$ignore_uid[$template->source->uid] = true; + } + /** * handle 'URL' debugging mode * * @param Smarty_Internal_Template $_template */ - public static function debugUrl(Smarty_Internal_Template $_template) { + public static function debugUrl(Smarty_Internal_Template $_template) + { if (isset($_SERVER['QUERY_STRING'])) { $_query_string = $_SERVER['QUERY_STRING']; } else { diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index 55b3214f..f2f42372 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -139,7 +139,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase */ public function fetch() { - return $this->render(true, false); + return $this->render(true, false, false); } /** @@ -155,17 +155,17 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase * * @param bool $merge_tpl_vars if true parent template variables merged in to local scope * @param bool $no_output_filter if true do not run output filter - * @param bool $display true: display, false: fetch + * @param bool $display true: display, false: fetch null: subtemplate * * @throws Exception * @throws SmartyException * @return string rendered template output */ - public function render($merge_tpl_vars = false, $no_output_filter = true, $display = false) + public function render($merge_tpl_vars = false, $no_output_filter = true, $display = null) { $parentIsTpl = $this->parent instanceof Smarty_Internal_Template; if ($this->smarty->debugging) { - Smarty_Internal_Debug::start_template($this); + Smarty_Internal_Debug::start_template($this, $display); } $save_tpl_vars = null; $save_config_vars = null; @@ -306,7 +306,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase echo $content; } if ($this->smarty->debugging) { - Smarty_Internal_Debug::end_template($this); + Smarty_Internal_Debug::end_template($this, $display); } // debug output if ($this->smarty->debugging) { @@ -325,7 +325,12 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase $this->config_vars = $save_config_vars; } if ($this->smarty->debugging) { - Smarty_Internal_Debug::end_template($this); + Smarty_Internal_Debug::end_template($this, $display); + } + if ($this->smarty->debugging == 2 and $display === false) { + if ($this->smarty->debugging) { + Smarty_Internal_Debug::display_debug($this, true); + } } if ($parentIsTpl) { $this->parent->properties['tpl_function'] = array_merge($this->parent->properties['tpl_function'], $this->properties['tpl_function']);