示例#1
0
文件: Subs.php 项目: norv/EosAlpha
function obExit($header = null, $do_footer = null, $from_index = false, $from_fatal_error = false)
{
    global $context, $modSettings;
    static $header_done = false, $footer_done = false, $level = 0, $has_fatal_error = false;
    if (EoS_Smarty::isActive()) {
        return EoS_Smarty::obExit($header, $do_footer, $from_index, $from_fatal_error);
    }
    // Attempt to prevent a recursive loop.
    ++$level;
    if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
        exit;
    }
    if ($from_fatal_error) {
        $has_fatal_error = true;
    }
    // Custom templates to load, or just default?
    /*$is_admin = isset($_REQUEST['action']) && $_REQUEST['action'] === 'admin';
    	$templates = array('index');
    
    	// Load each template...
    	foreach ($templates as $template) {
    		if(!$is_admin)
    			loadTemplate($template);
    		else
    			loadAdminTemplate($template);
    	}
    	$context['template_layers'] = array('html', 'body');
    	*/
    // Clear out the stat cache.
    trackStats();
    // If we have mail to send, send it.
    if (!empty($context['flush_mail'])) {
        AddMailQueue(true);
    }
    $do_header = $header === null ? !$header_done : $header;
    if ($do_footer === null) {
        $do_footer = $do_header;
    }
    $context['template_benchmark'] = microtime();
    // Has the template/header been done yet?
    if ($do_header) {
        // Was the page title set last minute? Also update the HTML safe one.
        if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
            $context['page_title_html_safe'] = $context['forum_name_html_safe'] . ' - ' . commonAPI::htmlspecialchars(un_htmlspecialchars($context['page_title']));
        }
        // Start up the session URL fixer.
        ob_start('ob_sessrewrite');
        HookAPI::integrateOB();
        //if(!empty($modSettings['simplesef_enable']))
        //	ob_start('SimpleSEF::ob_simplesef');
        // Display the screen in the logical order.
        template_header();
        $header_done = true;
    }
    if ($do_footer) {
        if (WIRELESS && !isset($context['sub_template'])) {
            fatal_lang_error('wireless_error_notyet', false);
        }
        // Just show the footer, then.
        loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
        // Just so we don't get caught in an endless loop of errors from the footer...
        if (!$footer_done) {
            $footer_done = true;
            template_footer();
            // (since this is just debugging... it's okay that it's after </html>.)
            if (!isset($_REQUEST['xml'])) {
                db_debug_junk();
            }
        }
    }
    // Remember this URL in case someone doesn't like sending HTTP_REFERER.
    if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
        $_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
    }
    // For session check verfication.... don't switch browsers...
    $_SESSION['USER_AGENT'] = $_SERVER['HTTP_USER_AGENT'];
    // Hand off the output to the portal, etc. we're integrated with.
    HookAPI::callHook('integrate_exit', array($do_footer));
    if (!empty($modSettings['simplesef_enable'])) {
        SimpleSEF::fixXMLOutput($do_footer);
    }
    // Don't exit if we're coming from index.php; that will pass through normally.
    if (!$from_index) {
        exit;
    }
}