- if ((x($_SERVER, 'QUERY_STRING')) && ($_SERVER['QUERY_STRING'] === 'q=internal_error.html') && isset($dreamhost_error_hack)) {
- logger('index.php: dreamhost_error_hack invoked. Original URI =' . $_SERVER['REQUEST_URI']);
- goaway(System::baseUrl() . $_SERVER['REQUEST_URI']);
- }
-
- logger('index.php: page not found: ' . $_SERVER['REQUEST_URI'] . ' ADDRESS: ' . $_SERVER['REMOTE_ADDR'] . ' QUERY: ' . $_SERVER['QUERY_STRING'], LOGGER_DEBUG);
- header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . L10n::t('Not Found'));
- $tpl = get_markup_template("404.tpl");
- $a->page['content'] = replace_macros(
- $tpl,
- [
- '$message' => L10n::t('Page not found.')]
- );
- }
-}
-
-/**
- * Load current theme info
- */
-$theme_info_file = 'view/theme/' . $a->getCurrentTheme() . '/theme.php';
-if (file_exists($theme_info_file)) {
- require_once $theme_info_file;
-}
-
-
-/* initialise content region */
-
-if (! x($a->page, 'content')) {
- $a->page['content'] = '';
-}
-
-if ($a->mode == App::MODE_NORMAL) {
- Addon::callHooks('page_content_top', $a->page['content']);
-}
-
-/**
- * Call module functions
- */
-
-if ($a->module_loaded) {
- $a->page['page_title'] = $a->module;
- $placeholder = '';
-
- Addon::callHooks($a->module . '_mod_init', $placeholder);
-
- if ($a->module_class) {
- call_user_func([$a->module_class, 'init']);
- } else if (function_exists($a->module . '_init')) {
- $func = $a->module . '_init';
- $func($a);
- }
-
- // "rawContent" is especially meant for technical endpoints.
- // This endpoint doesn't need any theme initialization or other comparable stuff.
- if (!$a->error && $a->module_class) {
- call_user_func([$a->module_class, 'rawContent']);
- }
-
- if (function_exists(str_replace('-', '_', $a->getCurrentTheme()) . '_init')) {
- $func = str_replace('-', '_', $a->getCurrentTheme()) . '_init';
- $func($a);
- }
-
- if (! $a->error && $_SERVER['REQUEST_METHOD'] === 'POST') {
- Addon::callHooks($a->module . '_mod_post', $_POST);
- if ($a->module_class) {
- call_user_func([$a->module_class, 'post']);
- } else if (function_exists($a->module . '_post')) {
- $func = $a->module . '_post';
- $func($a);
- }
- }
-
- if (! $a->error) {
- Addon::callHooks($a->module . '_mod_afterpost', $placeholder);
- if ($a->module_class) {
- call_user_func([$a->module_class, 'afterpost']);
- } else if (function_exists($a->module . '_afterpost')) {
- $func = $a->module . '_afterpost';
- $func($a);
- }
- }
-
- if (! $a->error) {
- $arr = ['content' => $a->page['content']];
- Addon::callHooks($a->module . '_mod_content', $arr);
- $a->page['content'] = $arr['content'];
- if ($a->module_class) {
- $arr = ['content' => call_user_func([$a->module_class, 'content'])];
- } else if (function_exists($a->module . '_content')) {
- $func = $a->module . '_content';
- $arr = ['content' => $func($a)];
- }
- Addon::callHooks($a->module . '_mod_aftercontent', $arr);
- $a->page['content'] .= $arr['content'];
- }
-
- if (function_exists(str_replace('-', '_', $a->getCurrentTheme()) . '_content_loaded')) {
- $func = str_replace('-', '_', $a->getCurrentTheme()) . '_content_loaded';
- $func($a);
- }
-}
-
-/*
- * Create the page head after setting the language
- * and getting any auth credentials.
- *
- * Moved init_pagehead() and init_page_end() to after
- * all the module functions have executed so that all
- * theme choices made by the modules can take effect.
- */
-
-$a->init_pagehead();
-
-/*
- * Build the page ending -- this is stuff that goes right before
- * the closing </body> tag
- */
-$a->init_page_end();
-
-// If you're just visiting, let javascript take you home
-if (x($_SESSION, 'visitor_home')) {
- $homebase = $_SESSION['visitor_home'];
-} elseif (local_user()) {
- $homebase = 'profile/' . $a->user['nickname'];