Permalink
Browse files

separate theme debugging from database debugging

new setting for Settings.php: $theme_show_debug (admin only)
implement theme debugging context in EoS_Smarty.php and output via template hook in footer.tpl
  • Loading branch information...
1 parent f980d6a commit 1bdaad5abb65f5761ef933db663e414c392472da @silvercircle committed Mar 21, 2015
View
@@ -51,6 +51,7 @@
$ssi_db_user = '';
$db_character_set = 'utf8';
$db_show_debug = false;
+$theme_show_debug = false;
$g_disable_all_hooks = false;
$db_cache_api = 'file';
$db_cache_memcached = 'localhost:11211';
View
@@ -32,16 +32,17 @@ class EoS_Smarty {
private static $_is_Debug = false;
/**
- * @param bool $debug - true enables the debug mode
+ * @param bool $debug - true enables template debug mode
*
* this initializes the smarty template system. Should be called early in index.php,
- * but after all settings have been loaded.
+ * but after all settings have been loaded, especially AFTER loadTheme()
*/
public static function init($debug = false)
{
- global $sourcedir, $settings, $boarddir, $context;
+ global $sourcedir, $settings, $boarddir, $context, $user_info;
- self::$_is_Debug = $debug;
+ // set debug context from Settings.php, but only for admins
+ self::$_is_Debug = $user_info['is_admin'] ? $debug : false;
// todo: Installer must check template cache directory for write access!
$compiledir = rtrim($boarddir, '/') . '/template_cache/themeid_' . $settings['theme_id']; // TODO: make this customizable
@@ -190,10 +191,35 @@ public static function Display()
$context['template_benchmark'] = microtime();
self::$_configInstance->setupContext();
- foreach(self::$_template_names as $the_template)
+
+ // if we are in template debugging mode, register the output template and
+ // set up the debugging context.
+ if(self::$_is_Debug) {
+ self::$_configInstance->registerHookTemplate('theme_debug_output', 'admin/theme_debug');
+ self::prepareDebugContext();
+ }
+
+ foreach(self::$_template_names as $the_template)
self::$_smartyInstance->display($the_template);
}
+ /**
+ * @static
+ * prepares the template debug output with information from the template engine
+ * The special template admin/theme_debug.tpl will output it and is called via
+ * a template hook (theme_debug_output), by default in the footer template fragment.
+ */
+ public static function prepareDebugContext()
+ {
+ global $context, $settings;
+
+ loadLanguage('ThemeDebug');
+ $context['theme_debug'] = array(
+ 'template_hooks' => self::$_configInstance->getHookDebugInfo(),
+ 'template_dirs' => implode('<br>', self::$_smartyInstance->getTemplateDir(null)),
+ );
+ }
+
// Ends execution. Takes care of template loading and remembering the previous URL.
public static function obExit($header = null, $do_footer = null, $from_index = false, $from_fatal_error = false)
{
View
@@ -3349,25 +3349,13 @@ function db_debug_junk()
ob_end_clean();
ob_start('EoS_QueryString::ob_sessrewrite');
}
- if(EoS_Smarty::isActive()) {
- $_t = EoS_Smarty::getSmartyInstance()->getTemplateDir();
- $smarty_template_dirs = is_array($_t) ? implode(', ', $_t) : $_t;
- $_t = EoS_Smarty::getTemplates();
- $smarty_templates = is_array($_t) ? implode(', ', $_t) : $_t;
-
- $smarty_debug_info = '<h1 class="bigheader secondary borderless">Smarty debug info</h1><span style="font-size:1.1em;color:red;"><strong>Template directories:</strong></span> ' . $smarty_template_dirs . '</br><span style="font-size:1.1em;color:red;"><strong>Templates:</strong></span> ' . $smarty_templates . '<br>' . EoS_Smarty::getConfigInstance()->getHookDebugInfo() . '<br>';
- }
- else
- $smarty_debug_info = '';
-
echo preg_replace('~</body>\s*</html>~', '', $temp), '
<div class="smalltext" style="text-align: left; margin: 1ex;">
', (isset($context['debug']['templates']) ? ($txt['debug_templates'] . count($context['debug']['templates']) . ': <em>' . implode('</em>, <em>', $context['debug']['templates']) . '</em>.<br />') : ''),'
', (isset($context['debug']['sub_templates']) ? ($txt['debug_subtemplates'] . count($context['debug']['sub_templates']) . ': <em>' . implode('</em>, <em>', $context['debug']['sub_templates']) . '</em>.<br />') : ''),'
', $txt['debug_language_files'], count($context['debug']['language_files']), ': <em>', implode('</em>, <em>', $context['debug']['language_files']), '</em>.<br />
', $txt['debug_stylesheets'], count($context['debug']['sheets']), ': <em>', implode('</em>, <em>', $context['debug']['sheets']), '</em>.<br />
- ', $txt['debug_files_included'], count($files), ' - ', round($total_size / 1024), $txt['debug_kb'], ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_include_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_include_info" style="display: none;"><em>', implode('</em>, <em>', $files), '</em></span>)<br />',
- $smarty_debug_info;
+ ', $txt['debug_files_included'], count($files), ' - ', round($total_size / 1024), $txt['debug_kb'], ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_include_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_include_info" style="display: none;"><em>', implode('</em>, <em>', $files), '</em></span>)<br />';
if (!empty($modSettings['cache_enable']) && !empty($cache_hits))
{
@@ -0,0 +1,5 @@
+<?php
+
+$txt['theme_debug_title'] = 'Theme debug output (click to view details)';
+$txt['theme_debug_hooks'] = 'Hook summary:';
+$txt['theme_debug_template_dirs'] = 'Template directories:';
@@ -0,0 +1,8 @@
+<div>
+ <strong><a href="#" onClick="$('#theme_debug_content').show(); return false;">{$T.theme_debug_title}</a></strong>
+ <div id="theme_debug_content" style="display:none; margin:10px;">
+ {$C.theme_debug.template_hooks}<br>
+ <strong><span class="alert">{$T.theme_debug_template_dirs}</span></strong><br>
+ {$C.theme_debug.template_dirs}
+ </div>
+</div>
@@ -1,4 +1,5 @@
<div class="clear" id="footer_section">
+ {$SUPPORT->displayHook('theme_debug_output')}
<div>
{*customization space in the footer*}
{$SUPPORT->displayHook('footer_area')}
View
@@ -122,7 +122,7 @@
// The main controlling function.
function smf_main()
{
- global $context, $modSettings, $settings, $user_info, $board, $topic, $board_info, $maintenance, $sourcedir, $backend_subdir, $db_show_debug;
+ global $context, $modSettings, $settings, $user_info, $board, $topic, $board_info, $maintenance, $sourcedir, $backend_subdir, $theme_show_debug;
// Special case: session keep-alive, output a transparent pixel.
if (isset($_GET['action']) && $_GET['action'] == 'keepalive')
@@ -149,7 +149,7 @@ function smf_main()
// Load the current theme. (note that ?theme=1 will also work, may be used for guest theming.)
else {
loadTheme();
- EoS_Smarty::init($db_show_debug);
+ EoS_Smarty::init($theme_show_debug);
}
$user_info['notify_count'] += (!empty($context['open_mod_reports']) ? 1 : 0);
URL::setSID();

0 comments on commit 1bdaad5

Please sign in to comment.