]> git.mxchange.org Git - friendica.git/blobdiff - index.php
Merge pull request #4269 from MrPetovan/task/4265-move-base64-to-composer
[friendica.git] / index.php
index 5e8860afd32dc7438f5767eb2b5ea6370df9757d..dcb25cc3a37d513998914d1aab4c887b0cc8d22f 100644 (file)
--- a/index.php
+++ b/index.php
@@ -9,11 +9,14 @@
  */
 
 use Friendica\App;
-use Friendica\Core\BaseObject;
+use Friendica\BaseObject;
+use Friendica\Content\Nav;
 use Friendica\Core\System;
 use Friendica\Core\Config;
 use Friendica\Core\Worker;
 use Friendica\Database\DBM;
+use Friendica\Model\Profile;
+use Friendica\Module\Login;
 
 require_once 'boot.php';
 
@@ -97,6 +100,7 @@ if (!$a->is_backend()) {
        session_start();
        $a->save_timestamp($stamp1, "parser");
 } else {
+       $_SESSION = [];
        Worker::executeIfIdle();
 }
 
@@ -105,11 +109,11 @@ if (!$a->is_backend()) {
  * We have to do it here because the session was just now opened.
  */
 if (x($_SESSION, 'authenticated') && !x($_SESSION, 'language')) {
-       // we didn't loaded user data yet, but we need user language
-       $r = dba::select('user', array('language'), array('uid' => $_SESSION['uid']), array('limit' => 1));
+       // we haven't loaded user data yet, but we need user language
+       $user = dba::selectFirst('user', ['language'], ['uid' => $_SESSION['uid']]);
        $_SESSION['language'] = $lang;
-       if (DBM::is_result($r)) {
-               $_SESSION['language'] = $r['language'];
+       if (DBM::is_result($user)) {
+               $_SESSION['language'] = $user['language'];
        }
 }
 
@@ -126,7 +130,7 @@ if ((x($_GET, 'zrl')) && (!$install && !$maintenance)) {
        ) {
                $_SESSION['my_url'] = $_GET['zrl'];
                $a->query_string = preg_replace('/[\?&]zrl=(.*?)([\?&]|$)/is', '', $a->query_string);
-               zrl_init($a);
+               Profile::zrlInit($a);
        } else {
                // Someone came with an invalid parameter, maybe as a DDoS attempt
                // We simply stop processing here
@@ -148,9 +152,7 @@ if ((x($_GET, 'zrl')) && (!$install && !$maintenance)) {
 
 // header('Link: <' . System::baseUrl() . '/amcd>; rel="acct-mgmt";');
 
-if (x($_COOKIE["Friendica"]) || (x($_SESSION, 'authenticated')) || (x($_POST, 'auth-params')) || ($a->module === 'login')) {
-       require "include/auth.php";
-}
+Login::sessionAuth();
 
 if (! x($_SESSION, 'authenticated')) {
        header('X-Account-Management-Status: none');
@@ -162,16 +164,16 @@ $a->page['end'] = '';
 
 
 if (! x($_SESSION, 'sysmsg')) {
-       $_SESSION['sysmsg'] = array();
+       $_SESSION['sysmsg'] = [];
 }
 
 if (! x($_SESSION, 'sysmsg_info')) {
-       $_SESSION['sysmsg_info'] = array();
+       $_SESSION['sysmsg_info'] = [];
 }
 
 // Array for informations about last received items
 if (! x($_SESSION, 'last_updated')) {
-       $_SESSION['last_updated'] = array();
+       $_SESSION['last_updated'] = [];
 }
 /*
  * check_config() is responsible for running update scripts. These automatically
@@ -191,12 +193,12 @@ if ($install && $a->module!="view") {
        check_plugins($a);
 }
 
-nav_set_selected('nothing');
+Nav::setSelected('nothing');
 
 //Don't populate apps_menu if apps are private
 $privateapps = Config::get('config', 'private_addons');
 if ((local_user()) || (! $privateapps === "1")) {
-       $arr = array('app_menu' => $a->apps);
+       $arr = ['app_menu' => $a->apps];
 
        call_hooks('app_menu', $arr);
 
@@ -220,7 +222,6 @@ if ((local_user()) || (! $privateapps === "1")) {
  * so within the module init and/or post functions and then invoke killme() to terminate
  * further processing.
  */
-
 if (strlen($a->module)) {
 
        /**
@@ -252,11 +253,17 @@ if (strlen($a->module)) {
                }
        }
 
+       // 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"))) {
+       if (! $a->module_loaded && file_exists("mod/{$a->module}.php")) {
                include_once "mod/{$a->module}.php";
                $a->module_loaded = true;
        }
@@ -288,8 +295,8 @@ if (strlen($a->module)) {
                $tpl = get_markup_template("404.tpl");
                $a->page['content'] = replace_macros(
                        $tpl,
-                       array(
-                       '$message' =>  t('Page not found.'))
+                       [
+                       '$message' =>  t('Page not found.')]
                );
        }
 }
@@ -321,7 +328,10 @@ if ($a->module_loaded) {
        $a->page['page_title'] = $a->module;
        $placeholder = '';
 
-       if (function_exists($a->module . '_init')) {
+       if ($a->module_class) {
+               call_hooks($a->module . '_mod_init', $placeholder);
+               call_user_func([$a->module_class, 'init']);
+       } else if (function_exists($a->module . '_init')) {
                call_hooks($a->module . '_mod_init', $placeholder);
                $func = $a->module . '_init';
                $func($a);
@@ -332,27 +342,36 @@ if ($a->module_loaded) {
                $func($a);
        }
 
-       if (($_SERVER['REQUEST_METHOD'] === 'POST') && (! $a->error)
-               && (function_exists($a->module . '_post'))
-               && (! x($_POST, 'auth-params'))
-       ) {
+       if (! $a->error && $_SERVER['REQUEST_METHOD'] === 'POST') {
                call_hooks($a->module . '_mod_post', $_POST);
-               $func = $a->module . '_post';
-               $func($a);
+               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) && (function_exists($a->module . '_afterpost'))) {
+       if (! $a->error) {
                call_hooks($a->module . '_mod_afterpost', $placeholder);
-               $func = $a->module . '_afterpost';
-               $func($a);
+               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) && (function_exists($a->module . '_content'))) {
-               $arr = array('content' => $a->page['content']);
+       if (! $a->error) {
+               $arr = ['content' => $a->page['content']];
                call_hooks($a->module . '_mod_content', $arr);
                $a->page['content'] = $arr['content'];
-               $func = $a->module . '_content';
-               $arr = array('content' => $func($a));
+               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)];
+               }
                call_hooks($a->module . '_mod_aftercontent', $arr);
                $a->page['content'] .= $arr['content'];
        }
@@ -408,7 +427,7 @@ call_hooks('page_end', $a->page['content']);
  * Add the navigation (menu) template
  */
 if ($a->module != 'install' && $a->module != 'maintenance') {
-       nav($a);
+       Nav::build($a);
 }
 
 /*
@@ -422,9 +441,9 @@ if ($a->is_mobile || $a->is_tablet) {
        }
        $a->page['footer'] = replace_macros(
                get_markup_template("toggle_mobile_footer.tpl"),
-               array(
+               [
                        '$toggle_link' => $link,
-                       '$toggle_text' => t('toggle mobile'))
+                       '$toggle_text' => t('toggle mobile')]
        );
 }