Exemplo n.º 1
0
function db_debug_junk()
{
    global $context, $scripturl, $boarddir, $modSettings, $boarddir;
    global $db_cache, $db_count, $db_show_debug, $cache_count, $cache_hits, $txt;
    // Add to Settings.php if you want to show the debugging information.
    if (!isset($db_show_debug) || $db_show_debug !== true || isset($_GET['action']) && $_GET['action'] == 'viewquery' || WIRELESS) {
        return;
    }
    if (empty($_SESSION['view_queries'])) {
        $_SESSION['view_queries'] = 0;
    }
    if (empty($context['debug']['language_files'])) {
        $context['debug']['language_files'] = array();
    }
    if (empty($context['debug']['sheets'])) {
        $context['debug']['sheets'] = array();
    }
    $files = get_included_files();
    $total_size = 0;
    for ($i = 0, $n = count($files); $i < $n; $i++) {
        if (file_exists($files[$i])) {
            $total_size += filesize($files[$i]);
        }
        $files[$i] = strtr($files[$i], array($boarddir => '.'));
    }
    $warnings = 0;
    if (!empty($db_cache)) {
        foreach ($db_cache as $q => $qq) {
            if (!empty($qq['w'])) {
                $warnings += count($qq['w']);
            }
        }
        $_SESSION['debug'] =& $db_cache;
    }
    // Gotta have valid HTML ;).
    $temp = ob_get_contents();
    if (function_exists('ob_clean')) {
        ob_clean();
    } else {
        ob_end_clean();
        ob_start('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;
    if (!empty($modSettings['cache_enable']) && !empty($cache_hits)) {
        $entries = array();
        $total_t = 0;
        $total_s = 0;
        foreach ($cache_hits as $cache_hit) {
            $entries[] = $cache_hit['d'] . ' ' . $cache_hit['k'] . ': ' . sprintf($txt['debug_cache_seconds_bytes'], comma_format($cache_hit['t'], 5), $cache_hit['s']);
            $total_t += $cache_hit['t'];
            $total_s += $cache_hit['s'];
        }
        echo '
	', $txt['debug_cache_hits'], $cache_count, ': ', sprintf($txt['debug_cache_seconds_bytes_total'], comma_format($total_t, 5), comma_format($total_s)), ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_cache_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_cache_info" style="display: none;"><em>', implode('</em>, <em>', $entries), '</em></span>)<br />';
    }
    echo '
	<a href="', $scripturl, '?action=viewquery" target="_blank" class="new_win">', $warnings == 0 ? sprintf($txt['debug_queries_used'], (int) $db_count) : sprintf($txt['debug_queries_used_and_warnings'], (int) $db_count, $warnings), '</a><br />
	<br />';
    if ($_SESSION['view_queries'] == 1 && !empty($db_cache)) {
        foreach ($db_cache as $q => $qq) {
            $is_select = substr(trim($qq['q']), 0, 6) == 'SELECT' || preg_match('~^INSERT(?: IGNORE)? INTO \\w+(?:\\s+\\([^)]+\\))?\\s+SELECT .+$~s', trim($qq['q'])) != 0;
            // Temporary tables created in earlier queries are not explainable.
            if ($is_select) {
                foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp) {
                    if (strpos(trim($qq['q']), $tmp) !== false) {
                        $is_select = false;
                        break;
                    }
                }
            } elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($qq['q'])) != 0) {
                $is_select = true;
            }
            // Make the filenames look a bit better.
            if (isset($qq['f'])) {
                $qq['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $qq['f']);
            }
            echo '
	<strong>', $is_select ? '<a href="' . $scripturl . '?action=viewquery;qq=' . ($q + 1) . '#qq' . $q . '" target="_blank" class="new_win" style="text-decoration: none;">' : '', nl2br(str_replace("\t", '&nbsp;&nbsp;&nbsp;', htmlspecialchars(ltrim($qq['q'], "\n\r")))) . ($is_select ? '</a></strong>' : '</strong>') . '<br />
	&nbsp;&nbsp;&nbsp;';
            if (!empty($qq['f']) && !empty($qq['l'])) {
                echo sprintf($txt['debug_query_in_line'], $qq['f'], $qq['l']);
            }
            if (isset($qq['s'], $qq['t']) && isset($txt['debug_query_which_took_at'])) {
                echo sprintf($txt['debug_query_which_took_at'], round($qq['t'], 8), round($qq['s'], 8)) . '<br />';
            } elseif (isset($qq['t'])) {
                echo sprintf($txt['debug_query_which_took'], round($qq['t'], 8)) . '<br />';
            }
            echo '
	<br />';
        }
    }
    echo '
	<a href="' . $scripturl . '?action=viewquery;sa=hide">', $txt['debug_' . (empty($_SESSION['view_queries']) ? 'show' : 'hide') . '_queries'], '</a>
</div></body></html>';
}