]> git.mxchange.org Git - friendica.git/blobdiff - src/App.php
Move DB_UPDATE_VERSION from boot.php to config/dbstructure.php
[friendica.git] / src / App.php
index 98685802b525873fa846fc8f064266cc7f2e04d9..6ec61db724c4b136b1f85ed109f1f4884d17af5b 100644 (file)
@@ -50,19 +50,14 @@ class App
        public $argv;
        public $argc;
        public $module;
-       public $hooks = [];
        public $timezone;
        public $interactive = true;
-       public $addons;
-       public $addons_admin = [];
-       public $apps = [];
        public $identities;
        public $is_mobile = false;
        public $is_tablet = false;
        public $performance = [];
        public $callstack = [];
        public $theme_info = [];
-       public $nav_sel;
        public $category;
        // Allow themes to control internal parameters
        // by changing App values in theme.php
@@ -362,7 +357,7 @@ class App
                Core\Config::load();
 
                if ($this->getMode()->has(App\Mode::DBAVAILABLE)) {
-                       Core\Addon::loadHooks();
+                       Core\Hook::loadHooks();
 
                        $this->loadAddonConfig();
                }
@@ -371,19 +366,6 @@ class App
 
                Core\L10n::init();
 
-               $this->page = [
-                       'aside' => '',
-                       'bottom' => '',
-                       'content' => '',
-                       'footer' => '',
-                       'htmlhead' => '',
-                       'nav' => '',
-                       'page_title' => '',
-                       'right_aside' => '',
-                       'template' => '',
-                       'title' => ''
-               ];
-
                $this->process_id = Core\System::processID('log');
        }
 
@@ -591,7 +573,11 @@ class App
 
                $stamp1 = microtime(true);
 
-               DBA::connect($db_host, $db_user, $db_pass, $db_data, $charset);
+               if (DBA::connect($db_host, $db_user, $db_pass, $db_data, $charset)) {
+                       // Loads DB_UPDATE_VERSION constant
+                       Database\DBStructure::definition();
+               }
+
                unset($db_host, $db_user, $db_pass, $db_data, $charset);
 
                $this->saveTimestamp($stamp1, 'network');
@@ -1732,50 +1718,51 @@ class App
                        Core\Addon::check();
                }
 
-               Content\Nav::setSelected('nothing');
-
-               //Don't populate apps_menu if apps are private
-               $privateapps = Core\Config::get('config', 'private_addons');
-               if ((local_user()) || (! $privateapps === "1")) {
-                       $arr = ['app_menu' => $this->apps];
-
-                       Core\Addon::callHooks('app_menu', $arr);
-
-                       $this->apps = $arr['app_menu'];
-               }
+               $this->page = [
+                       'aside' => '',
+                       'bottom' => '',
+                       'content' => '',
+                       'footer' => '',
+                       'htmlhead' => '',
+                       'nav' => '',
+                       'page_title' => '',
+                       'right_aside' => '',
+                       'template' => '',
+                       'title' => ''
+               ];
 
                if (strlen($this->module)) {
                        // Compatibility with the Android Diaspora client
                        if ($this->module == 'stream') {
-                               goaway('network?f=&order=post');
+                               $this->internalRedirect('network?f=&order=post');
                        }
 
                        if ($this->module == 'conversations') {
-                               goaway('message');
+                               $this->internalRedirect('message');
                        }
 
                        if ($this->module == 'commented') {
-                               goaway('network?f=&order=comment');
+                               $this->internalRedirect('network?f=&order=comment');
                        }
 
                        if ($this->module == 'liked') {
-                               goaway('network?f=&order=comment');
+                               $this->internalRedirect('network?f=&order=comment');
                        }
 
                        if ($this->module == 'activity') {
-                               goaway('network/?f=&conv=1');
+                               $this->internalRedirect('network/?f=&conv=1');
                        }
 
                        if (($this->module == 'status_messages') && ($this->cmd == 'status_messages/new')) {
-                               goaway('bookmarklet');
+                               $this->internalRedirect('bookmarklet');
                        }
 
                        if (($this->module == 'user') && ($this->cmd == 'user/edit')) {
-                               goaway('settings');
+                               $this->internalRedirect('settings');
                        }
 
                        if (($this->module == 'tag_followings') && ($this->cmd == 'tag_followings/manage')) {
-                               goaway('search');
+                               $this->internalRedirect('search');
                        }
 
                        // Compatibility with the Firefox App
@@ -1830,7 +1817,7 @@ class App
 
                                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($this->getBaseURL() . $_SERVER['REQUEST_URI']);
+                                       $this->internalRedirect($_SERVER['REQUEST_URI']);
                                }
 
                                logger('index.php: page not found: ' . $_SERVER['REQUEST_URI'] . ' ADDRESS: ' . $_SERVER['REMOTE_ADDR'] . ' QUERY: ' . $_SERVER['QUERY_STRING'], LOGGER_DEBUG);
@@ -1849,7 +1836,6 @@ class App
                        require_once $theme_info_file;
                }
 
-
                // initialise content region
                if ($this->getMode()->isNormal()) {
                        Core\Addon::callHooks('page_content_top', $this->page['content']);
@@ -1926,7 +1912,8 @@ class App
 
                // Add the navigation (menu) template
                if ($this->module != 'install' && $this->module != 'maintenance') {
-                       Content\Nav::build($this);
+                       $this->page['htmlhead'] .= replace_macros(get_markup_template('nav_head.tpl'), []);
+                       $this->page['nav']       = Content\Nav::build($this);
                }
 
                // Build the page - now that we have all the components
@@ -2001,20 +1988,21 @@ class App
        }
 
        /**
-        * Redirects to another URL and exits this process.
+        * Redirects to another module relative to the current Friendica base.
+        * If you want to redirect to a external URL, use System::externalRedirectTo()
         *
         * @param string $toUrl The destination URL (Default is empty, which is the default page of the Friendica node)
         * @param bool $ssl if true, base URL will try to get called with https:// (works just for relative paths)
+        *
+        * @throws InternalServerErrorException In Case the given URL is not relative to the Friendica node
         */
-       public function redirect($toUrl = '', $ssl = false)
+       public function internalRedirect($toUrl = '', $ssl = false)
        {
-               if (strstr(normalise_link($toUrl), 'http://')) {
-                       $redirectTo = $toUrl;
-               } else {
-                       $redirectTo = self::getApp()->getBaseURL($ssl) . '/' . ltrim($toUrl, '/');
+               if (filter_var($toUrl, FILTER_VALIDATE_URL)) {
+                       throw new InternalServerErrorException('URL is not a relative path, please use System::externalRedirectTo');
                }
 
-               header("Location: $redirectTo");
-               exit();
+               $redirectTo = $this->getBaseURL($ssl) . '/' . ltrim($toUrl, '/');
+               System::externalRedirect($redirectTo);
        }
 }