]> git.mxchange.org Git - friendica.git/blobdiff - src/App.php
Little fixes (#5414)
[friendica.git] / src / App.php
index be4c7785ee200a555c9d4c5caddbdbeb8e3fb191..e1843e5737dc99f318bf3f590d8e658a13c9c917 100644 (file)
@@ -154,25 +154,6 @@ class App
 
                $this->basepath = rtrim($basepath, DIRECTORY_SEPARATOR);
 
-               // The order of the following calls is important to ensure proper initialization
-               $this->loadConfigFiles();
-
-               $this->loadDatabase();
-
-               $this->determineMode();
-
-               $this->determineUrlPath();
-
-               Config::load();
-
-               if ($this->mode & self::MODE_DBAVAILABLE) {
-                       Core\Addon::loadHooks();
-
-                       $this->loadAddonConfig();
-               }
-
-               $this->loadDefaultTimezone();
-
                $this->performance['start'] = microtime(true);
                $this->performance['database'] = 0;
                $this->performance['database_write'] = 0;
@@ -194,6 +175,25 @@ class App
                $this->callstack['rendering'] = [];
                $this->callstack['parser'] = [];
 
+               // The order of the following calls is important to ensure proper initialization
+               $this->loadConfigFiles();
+
+               $this->loadDatabase();
+
+               $this->determineMode();
+
+               $this->determineUrlPath();
+
+               Config::load();
+
+               if ($this->mode & self::MODE_DBAVAILABLE) {
+                       Core\Addon::loadHooks();
+
+                       $this->loadAddonConfig();
+               }
+
+               $this->loadDefaultTimezone();
+
                $this->page = [
                        'aside' => '',
                        'bottom' => '',
@@ -323,7 +323,8 @@ class App
         */
        private function loadConfigFiles()
        {
-               $this->loadConfigFile($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'defaults.ini.php');
+               $this->loadConfigFile($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.ini.php');
+               $this->loadConfigFile($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'settings.ini.php');
 
                // Legacy .htconfig.php support
                if (file_exists($this->basepath . DIRECTORY_SEPARATOR . '.htpreconfig.php')) {
@@ -336,6 +337,15 @@ class App
                        $a = $this;
 
                        include $this->basepath . DIRECTORY_SEPARATOR . '.htconfig.php';
+
+                       $this->setConfigValue('database', 'hostname', $db_host);
+                       $this->setConfigValue('database', 'username', $db_user);
+                       $this->setConfigValue('database', 'password', $db_pass);
+                       $this->setConfigValue('database', 'database', $db_data);
+                       if (isset($a->config['system']['db_charset'])) {
+                               $this->setConfigValue('database', 'charset', $a->config['system']['db_charset']);
+                       }
+
                        unset($db_host, $db_user, $db_pass, $db_data);
 
                        if (isset($default_timezone)) {
@@ -347,6 +357,11 @@ class App
                                $this->setConfigValue('system', 'pidfile', $pidfile);
                                unset($pidfile);
                        }
+
+                       if (isset($lang)) {
+                               $this->setConfigValue('system', 'language', $lang);
+                               unset($lang);
+                       }
                }
 
                if (file_exists($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php')) {
@@ -385,8 +400,8 @@ class App
                        throw new Exception('Error parsing config file ' . $filepath);
                }
 
-               foreach($config as $category => $values) {
-                       foreach($values as $key => $value) {
+               foreach ($config as $category => $values) {
+                       foreach ($values as $key => $value) {
                                $this->setConfigValue($category, $key, $value);
                        }
                }
@@ -403,9 +418,9 @@ class App
                // Loads addons default config
                Core\Addon::callHooks('load_config');
 
-               // Load the local config file again in case there are overwritten addon config
-               if (file_exists($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php')) {
-                       $this->loadConfigFile($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php');
+               // Load the local addon config file to overwritten default addon config values
+               if (file_exists($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'addon.ini.php')) {
+                       $this->loadConfigFile($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'addon.ini.php');
                }
        }
 
@@ -442,8 +457,14 @@ class App
                 *
                 * To get /path/to/friendica we perform dirname() for as many levels as there are slashes in the QUERY_STRING
                 */
-               if (!empty($_SERVER['SCRIPT_URL']) && !empty($_SERVER['QUERY_STRING'])) {
-                       $path = trim(dirname($_SERVER['SCRIPT_URL'], substr_count(trim($_SERVER['QUERY_STRING'], '/'), '/') + 1), '/');
+               if (!empty($_SERVER['SCRIPT_URL'])) {
+                       // Module
+                       if (!empty($_SERVER['QUERY_STRING'])) {
+                               $path = trim(dirname($_SERVER['SCRIPT_URL'], substr_count(trim($_SERVER['QUERY_STRING'], '/'), '/') + 1), '/');
+                       } else {
+                               // Root page
+                               $path = trim($_SERVER['SCRIPT_URL'], '/');
+                       }
 
                        if ($path && $path != $this->urlpath) {
                                $this->urlpath = $path;
@@ -505,7 +526,7 @@ class App
                // Use environment variables for mysql if they are set beforehand
                if (!empty(getenv('MYSQL_HOST'))
                        && (!empty(getenv('MYSQL_USERNAME')) || !empty(getenv('MYSQL_USER')))
-                       && !getenv('MYSQL_PASSWORD') === false
+                       && getenv('MYSQL_PASSWORD') !== false
                        && !empty(getenv('MYSQL_DATABASE')))
                {
                        $db_host = getenv('MYSQL_HOST');
@@ -519,12 +540,6 @@ class App
                        }
                        $db_pass = (string) getenv('MYSQL_PASSWORD');
                        $db_data = getenv('MYSQL_DATABASE');
-               } elseif (file_exists($this->basepath . DIRECTORY_SEPARATOR . '.htconfig.php')) {
-                       $a = new \stdClass();
-                       include $this->basepath . DIRECTORY_SEPARATOR . '.htconfig.php';
-                       $charset = isset($a->config["system"]["db_charset"]) ? $a->config["system"]["db_charset"] : $charset;
-
-                       unset($a);
                }
 
                $stamp1 = microtime(true);
@@ -532,7 +547,7 @@ class App
                \dba::connect($db_host, $db_user, $db_pass, $db_data, $charset);
                unset($db_host, $db_user, $db_pass, $db_data, $charset);
 
-               $this->save_timestamp($stamp1, "network");
+               $this->save_timestamp($stamp1, 'network');
        }
 
        /**