X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FApp.php;h=0dc4b86b95f6520f14bb966e45f552ff6e8ad511;hb=c2f6b166c7302d39e6e754119679036a4fca7473;hp=c56d9c10e4240e35d5911dfa342b534e01388127;hpb=ecea7425f8ad11ace4af39d476919e3203bff44f;p=friendica.git diff --git a/src/App.php b/src/App.php index c56d9c10e4..0dc4b86b95 100644 --- a/src/App.php +++ b/src/App.php @@ -140,6 +140,8 @@ class App * @brief App constructor. * * @param string $basepath Path to the app base folder + * + * @throws Exception if the Basepath is not usable */ public function __construct($basepath) { @@ -172,40 +174,7 @@ 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' => '', - 'content' => '', - 'end' => '', - 'footer' => '', - 'htmlhead' => '', - 'nav' => '', - 'page_title' => '', - 'right_aside' => '', - 'template' => '', - 'title' => '' - ]; - - $this->process_id = System::processID('log'); + $this->reload(); set_time_limit(0); @@ -312,6 +281,47 @@ class App $this->register_template_engine('Friendica\Render\FriendicaSmartyEngine'); } + /** + * Reloads the whole app instance + */ + public function reload() + { + // 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' => '', + 'content' => '', + 'end' => '', + 'footer' => '', + 'htmlhead' => '', + 'nav' => '', + 'page_title' => '', + 'right_aside' => '', + 'template' => '', + 'title' => '' + ]; + + $this->process_id = System::processID('log'); + } + /** * Load the configuration files * @@ -362,13 +372,13 @@ class App } 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'); + $this->loadConfigFile($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php', true); } } /** * Tries to load the specified configuration file into the App->config array. - * Overwrites previously set values. + * Doesn't overwrite previously set values by default to prevent default config files to supersede DB Config. * * The config format is INI and the template for configuration files is the following: * @@ -381,9 +391,10 @@ class App * // Keep this line * * @param type $filepath + * @param bool $overwrite Force value overwrite if the config key already exists * @throws Exception */ - public function loadConfigFile($filepath) + public function loadConfigFile($filepath, $overwrite = false) { if (!file_exists($filepath)) { throw new Exception('Error parsing non-existent config file ' . $filepath); @@ -399,7 +410,11 @@ class App foreach ($config as $category => $values) { foreach ($values as $key => $value) { - $this->setConfigValue($category, $key, $value); + if ($overwrite) { + $this->setConfigValue($category, $key, $value); + } else { + $this->setDefaultConfigValue($category, $key, $value); + } } } } @@ -417,7 +432,7 @@ class App // 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'); + $this->loadConfigFile($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'addon.ini.php', true); } } @@ -1064,7 +1079,11 @@ class App $meminfo = []; foreach ($memdata as $line) { - list($key, $val) = explode(':', $line); + $data = explode(':', $line); + if (count($data) != 2) { + continue; + } + list($key, $val) = $data; $meminfo[$key] = (int) trim(str_replace('kB', '', $val)); $meminfo[$key] = (int) ($meminfo[$key] / 1024); } @@ -1127,7 +1146,7 @@ class App return; } - $cmdline = $this->getConfigValue('config', 'php_path', 'php') . ' ' . $command; + $cmdline = $this->getConfigValue('config', 'php_path', 'php') . ' ' . escapeshellarg($command); foreach ($args as $key => $value) { if (!is_null($value) && is_bool($value) && !$value) { @@ -1140,8 +1159,6 @@ class App } } - $cmdline = escapeshellarg($cmdline); - if ($this->min_memory_reached()) { return; } @@ -1232,6 +1249,20 @@ class App return $return; } + /** + * Sets a default value in the config cache. Ignores already existing keys. + * + * @param string $cat Config category + * @param string $k Config key + * @param mixed $v Default value to set + */ + private function setDefaultConfigValue($cat, $k, $v) + { + if (!isset($this->config[$cat][$k])) { + $this->setConfigValue($cat, $k, $v); + } + } + /** * Sets a value in the config cache. Accepts raw output from the config table * @@ -1309,11 +1340,11 @@ class App // Only arrays are serialized in database, so we have to unserialize sparingly $value = is_string($v) && preg_match("|^a:[0-9]+:{.*}$|s", $v) ? unserialize($v) : $v; - if (!isset($this->config[$uid])) { + if (!isset($this->config[$uid]) || !is_array($this->config[$uid])) { $this->config[$uid] = []; } - if (!isset($this->config[$uid][$cat])) { + if (!isset($this->config[$uid][$cat]) || !is_array($this->config[$uid][$cat])) { $this->config[$uid][$cat] = []; } @@ -1401,16 +1432,12 @@ class App } } - if (!empty($_SESSION)) { - $user_theme = defaults($_SESSION, 'theme', $system_theme); - } else { - $user_theme = $system_theme; - } + $user_theme = Core\Session::get('theme', $system_theme); // Specific mobile theme override - if (($this->is_mobile || $this->is_tablet) && defaults($_SESSION, 'show-mobile', true)) { + if (($this->is_mobile || $this->is_tablet) && Core\Session::get('show-mobile', true)) { $system_mobile_theme = Config::get('system', 'mobile-theme'); - $user_mobile_theme = defaults($_SESSION, 'mobile-theme', $system_mobile_theme); + $user_mobile_theme = Core\Session::get('mobile-theme', $system_mobile_theme); // --- means same mobile theme as desktop if (!empty($user_mobile_theme) && $user_mobile_theme !== '---') {