]> git.mxchange.org Git - friendica.git/blobdiff - src/App.php
Another renamed function
[friendica.git] / src / App.php
index 3f67dbada9ba1edaf73315cab8045e8cbb283ebb..7622a1a0ce3aacb5e2795fbdd6b9c1e7b572e78e 100644 (file)
@@ -99,6 +99,15 @@ class App
        public $stylesheets = [];
        public $footerScripts = [];
 
+       /**
+        * Register a stylesheet file path to be included in the <head> tag of every page.
+        * Inclusion is done in App->initHead().
+        * The path can be absolute or relative to the Friendica installation base folder.
+        *
+        * @see App->initHead()
+        *
+        * @param string $path
+        */
        public function registerStylesheet($path)
        {
                $url = str_replace($this->get_basepath() . DIRECTORY_SEPARATOR, '', $path);
@@ -106,6 +115,15 @@ class App
                $this->stylesheets[] = trim($url, '/');
        }
 
+       /**
+        * Register a javascript file path to be included in the <footer> tag of every page.
+        * Inclusion is done in App->initFooter().
+        * The path can be absolute or relative to the Friendica installation base folder.
+        *
+        * @see App->initFooter()
+        *
+        * @param string $path
+        */
        public function registerFooterScript($path)
        {
                $url = str_replace($this->get_basepath() . DIRECTORY_SEPARATOR, '', $path);
@@ -388,13 +406,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:
         *
@@ -407,9 +425,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);
@@ -425,7 +444,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);
+                               }
                        }
                }
        }
@@ -443,7 +466,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);
                }
        }
 
@@ -749,6 +772,16 @@ class App
                $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
        }
 
+       /**
+        * Initializes App->page['htmlhead'].
+        *
+        * Includes:
+        * - Page title
+        * - Favicons
+        * - Registered stylesheets (through App->registerStylesheet())
+        * - Infinite scroll data
+        * - head.tpl template
+        */
        public function initHead()
        {
                $interval = ((local_user()) ? PConfig::get(local_user(), 'system', 'update_interval') : 40000);
@@ -814,13 +847,22 @@ class App
                ]) . $this->page['htmlhead'];
        }
 
+       /**
+        * Initializes App->page['footer'].
+        *
+        * Includes:
+        * - Javascript homebase
+        * - Mobile toggle link
+        * - Registered footer scripts (through App->registerFooterScript())
+        * - footer.tpl template
+        */
        public function initFooter()
        {
                // If you're just visiting, let javascript take you home
                if (!empty($_SESSION['visitor_home'])) {
                        $homebase = $_SESSION['visitor_home'];
                } elseif (local_user()) {
-                       $homebase = 'profile/' . $a->user['nickname'];
+                       $homebase = 'profile/' . $this->user['nickname'];
                }
 
                if (isset($homebase)) {
@@ -1112,7 +1154,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);
                }
@@ -1278,6 +1324,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
         *