Example #1
0
function ob_sessrewrite($buffer)
{
    global $scripturl, $modSettings, $context, $user_info, $txt, $time_start, $db_count;
    /*
     * tidy support as a debugging option to generate prettified output 
     * and only do it for the admin when 'tidyup' is set in the request string (tidy can be slow) 
     * pretty HTML output might help with debugging templates
     */
    if (isset($_REQUEST['tidyup']) && !isset($_REQUEST['xml']) && class_exists('Tidy') && $user_info['is_admin']) {
        $tidy = new Tidy();
        $tidy_config = array('indent' => true, 'output-html' => true, 'wrap' => 0, 'merge-divs' => false, 'merge-spans' => false);
        $tidy->parseString($buffer, $tidy_config, 'utf8');
        $buffer = $tidy;
    }
    // If $scripturl is set to nothing, or the SID is not defined (SSI?) just quit.
    if ($scripturl == '' || !defined('SID')) {
        return $buffer;
    }
    // rewrite urls with PHPSESSID, but only if the session isn't cookied and NOT for spiders
    if (empty($_COOKIE) && SID != '' && empty($context['browser']['possibly_robot'])) {
        $buffer = preg_replace('/"' . preg_quote($scripturl, '/') . '(?!\\?' . preg_quote(SID, '/') . ')\\??/', '"' . $scripturl . '?' . SID . '&', $buffer);
    } elseif (isset($_GET['debug'])) {
        $buffer = preg_replace('/(?<!<link rel="canonical" href=)"' . preg_quote($scripturl, '/') . '\\??/', '"' . $scripturl . '?debug;', $buffer);
    }
    $now = microtime();
    $context['load_time'] = round(array_sum(explode(' ', $now)) - array_sum(explode(' ', $time_start)), 3);
    $context['load_queries'] = $db_count;
    $context['template_benchmark_time'] = round(array_sum(explode(' ', $now)) - array_sum(explode(' ', $context['template_benchmark'])), 3);
    if (!empty($modSettings['simplesef_enable'])) {
        $buffer = isset($context['sef_full_rewrite']) ? SimpleSEF::ob_simplesef($buffer) : SimpleSEF::ob_simplesef_light($buffer);
        //$buffer .= SimpleSEF::$debug_info;
    }
    $_t = EoS_Smarty::isActive() ? 's template-smarty), ' : 's template), ';
    $buffer = str_replace('@%%__loadtime__%%@', $user_info['is_admin'] ? $context['load_time'] . 's CPU (' . $context['template_benchmark_time'] . $_t . $context['load_queries'] . ' ' . $txt['queries'] . SimpleSEF::getPerfData() : '', $buffer);
    if (isset($_REQUEST['xml'])) {
        $buffer = ltrim($buffer);
    }
    return $buffer;
}