- * Modules which emit other serialisations besides HTML (XML,JSON, etc.) should do
- * so within the module init and/or post functions and then invoke killme() to terminate
- * further processing.
- */
-if (strlen($a->module)) {
-
- /**
- * We will always have a module name.
- * First see if we have an addon which is masquerading as a module.
- */
-
- // Compatibility with the Android Diaspora client
- if ($a->module == 'stream') {
- goaway('network?f=&order=post');
- }
-
- if ($a->module == 'conversations') {
- goaway('message');
- }
-
- if ($a->module == 'commented') {
- goaway('network?f=&order=comment');
- }
-
- if ($a->module == 'liked') {
- goaway('network?f=&order=comment');
- }
-
- if ($a->module == 'activity') {
- goaway('network/?f=&conv=1');
- }
-
- if (($a->module == 'status_messages') && ($a->cmd == 'status_messages/new')) {
- goaway('bookmarklet');
- }
-
- if (($a->module == 'user') && ($a->cmd == 'user/edit')) {
- goaway('settings');
- }
-
- if (($a->module == 'tag_followings') && ($a->cmd == 'tag_followings/manage')) {
- goaway('search');
- }
-
- // Compatibility with the Firefox App
- if (($a->module == "users") && ($a->cmd == "users/sign_in")) {
- $a->module = "login";
- }
-
- $privateapps = Config::get('config', 'private_addons');
-
- if (is_array($a->addons) && in_array($a->module, $a->addons) && file_exists("addon/{$a->module}/{$a->module}.php")) {
- //Check if module is an app and if public access to apps is allowed or not
- if ((!local_user()) && Addon::isApp($a->module) && $privateapps === "1") {
- info(L10n::t("You must be logged in to use addons. "));
- } else {
- include_once "addon/{$a->module}/{$a->module}.php";
- if (function_exists($a->module . '_module')) {
- $a->module_loaded = true;
- }
- }
- }
-
- // Controller class routing
- if (! $a->module_loaded && class_exists('Friendica\\Module\\' . ucfirst($a->module))) {
- $a->module_class = 'Friendica\\Module\\' . ucfirst($a->module);
- $a->module_loaded = true;
- }
-
- /**
- * If not, next look for a 'standard' program module in the 'mod' directory
- */
-
- if (! $a->module_loaded && file_exists("mod/{$a->module}.php")) {
- include_once "mod/{$a->module}.php";
- $a->module_loaded = true;
- }
-
- /**
- * The URL provided does not resolve to a valid module.
- *
- * On Dreamhost sites, quite often things go wrong for no apparent reason and they send us to '/internal_error.html'.
- * We don't like doing this, but as it occasionally accounts for 10-20% or more of all site traffic -
- * we are going to trap this and redirect back to the requested page. As long as you don't have a critical error on your page
- * this will often succeed and eventually do the right thing.
- *
- * Otherwise we are going to emit a 404 not found.
- */
-
- if (! $a->module_loaded) {
- // Stupid browser tried to pre-fetch our Javascript img template. Don't log the event or return anything - just quietly exit.
- if (!empty($_SERVER['QUERY_STRING']) && preg_match('/{[0-9]}/', $_SERVER['QUERY_STRING']) !== 0) {
- killme();
- }
-
- if (!empty($_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 ($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.