-/**
- * 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'];
-}
-
-if (isset($homebase)) {
- $a->page['content'] .= '<script>var homebase="' . $homebase . '" ; </script>';
-}
-
-/*
- * now that we've been through the module content, see if the page reported
- * a permission problem and if so, a 403 response would seem to be in order.
- */
-if (stristr(implode("", $_SESSION['sysmsg']), L10n::t('Permission denied'))) {
- header($_SERVER["SERVER_PROTOCOL"] . ' 403 ' . L10n::t('Permission denied.'));
-}
-
-/*
- * Report anything which needs to be communicated in the notification area (before the main body)
- */
-Addon::callHooks('page_end', $a->page['content']);
-
-/*
- * Add the navigation (menu) template
- */
-if ($a->module != 'install' && $a->module != 'maintenance') {
- Nav::build($a);
-}
-
-/*
- * Add a "toggle mobile" link if we're using a mobile device
- */
-if ($a->is_mobile || $a->is_tablet) {
- if (isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) {
- $link = 'toggle_mobile?address=' . curPageURL();
- } else {
- $link = 'toggle_mobile?off=1&address=' . curPageURL();
- }
- $a->page['footer'] = replace_macros(
- get_markup_template("toggle_mobile_footer.tpl"),
- [
- '$toggle_link' => $link,
- '$toggle_text' => L10n::t('toggle mobile')]
- );
-}
-
-/**
- * Build the page - now that we have all the components
- */
-
-if (!$a->theme['stylesheet']) {
- $stylesheet = $a->getCurrentThemeStylesheetPath();
-} else {
- $stylesheet = $a->theme['stylesheet'];
-}
-
-$a->page['htmlhead'] = str_replace('{{$stylesheet}}', $stylesheet, $a->page['htmlhead']);
-//$a->page['htmlhead'] = replace_macros($a->page['htmlhead'], array('$stylesheet' => $stylesheet));
-
-if (isset($_GET["mode"]) && (($_GET["mode"] == "raw") || ($_GET["mode"] == "minimal"))) {
- $doc = new DOMDocument();
-
- $target = new DOMDocument();
- $target->loadXML("<root></root>");
-
- $content = mb_convert_encoding($a->page["content"], 'HTML-ENTITIES', "UTF-8");
-
- /// @TODO one day, kill those error-surpressing @ stuff, or PHP should ban it
- @$doc->loadHTML($content);
-
- $xpath = new DOMXPath($doc);
-
- $list = $xpath->query("//*[contains(@id,'tread-wrapper-')]"); /* */
-
- foreach ($list as $item) {
- $item = $target->importNode($item, true);
-
- // And then append it to the target
- $target->documentElement->appendChild($item);
- }
-}
-
-if (isset($_GET["mode"]) && ($_GET["mode"] == "raw")) {
- header("Content-type: text/html; charset=utf-8");
-
- echo substr($target->saveHTML(), 6, -8);
-
- killme();
-}
-
-$page = $a->page;
-$profile = $a->profile;
-
-header("X-Friendica-Version: " . FRIENDICA_VERSION);
-header("Content-type: text/html; charset=utf-8");
-
-if (Config::get('system', 'hsts') && (Config::get('system', 'ssl_policy') == SSL_POLICY_FULL)) {
- header("Strict-Transport-Security: max-age=31536000");
-}
-
-// Some security stuff
-header('X-Content-Type-Options: nosniff');
-header('X-XSS-Protection: 1; mode=block');
-header('X-Permitted-Cross-Domain-Policies: none');
-header('X-Frame-Options: sameorigin');
-
-// Things like embedded OSM maps don't work, when this is enabled
-// header("Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; connect-src 'self'; style-src 'self' 'unsafe-inline'; font-src 'self'; img-src 'self' https: data:; media-src 'self' https:; child-src 'self' https:; object-src 'none'");
-
-/*
- * We use $_GET["mode"] for special page templates. So we will check if we have
- * to load another page template than the default one.
- * The page templates are located in /view/php/ or in the theme directory.
- */
-if (isset($_GET["mode"])) {
- $template = Theme::getPathForFile($_GET["mode"] . '.php');
-}
-
-// If there is no page template use the default page template
-if (empty($template)) {
- $template = Theme::getPathForFile("default.php");
-}
-
-/// @TODO Looks unsafe (remote-inclusion), is maybe not but Theme::getPathForFile() uses file_exists() but does not escape anything
-require_once $template;