]> git.mxchange.org Git - friendica.git/blobdiff - src/App.php
Yet more global classes to escape
[friendica.git] / src / App.php
index 45a9db435cc497d854f79b186769c1eced7a1d9b..efb60c0386bd4502a07d07cc29db552310486216 100644 (file)
@@ -40,6 +40,7 @@ class App {
        public $module;\r
        public $pager;\r
        public $strings;\r
+       public $basepath;\r
        public $path;\r
        public $hooks;\r
        public $timezone;\r
@@ -112,8 +113,10 @@ class App {
 \r
        /**\r
         * @brief App constructor.\r
+        *\r
+        * @param string $basepath Path to the app base folder\r
         */\r
-       function __construct() {\r
+       function __construct($basepath) {\r
 \r
                global $default_timezone;\r
 \r
@@ -154,13 +157,6 @@ class App {
 \r
                startup();\r
 \r
-               set_include_path(\r
-                       get_include_path() . PATH_SEPARATOR\r
-                       . 'include' . PATH_SEPARATOR\r
-                       . 'library' . PATH_SEPARATOR\r
-                       . 'library/langdet' . PATH_SEPARATOR\r
-                       . '.');\r
-\r
                $this->scheme = 'http';\r
 \r
                if ((x($_SERVER, 'HTTPS') && $_SERVER['HTTPS']) ||\r
@@ -195,6 +191,20 @@ class App {
                        $this->hostname = $hostname;\r
                }\r
 \r
+               if (! static::directory_usable($basepath)) {\r
+                       throw new Exception('Basepath ' . $basepath . ' isn\'t usable.');\r
+               }\r
+\r
+               $this->basepath = rtrim($basepath, DIRECTORY_SEPARATOR);\r
+\r
+               set_include_path(\r
+                       get_include_path() . PATH_SEPARATOR\r
+                       . $this->basepath . DIRECTORY_SEPARATOR . 'include' . PATH_SEPARATOR\r
+                       . $this->basepath . DIRECTORY_SEPARATOR . 'library' . PATH_SEPARATOR\r
+                       . $this->basepath . DIRECTORY_SEPARATOR . 'library/langdet' . PATH_SEPARATOR\r
+                       . $this->basepath);\r
+\r
+\r
                if (is_array($_SERVER['argv']) && $_SERVER['argc'] > 1 && substr(end($_SERVER['argv']), 0, 4) == 'http') {\r
                        $this->set_baseurl(array_pop($_SERVER['argv']));\r
                        $_SERVER['argc'] --;\r
@@ -284,18 +294,28 @@ class App {
                self::$a = $this;\r
        }\r
 \r
+       /**\r
+        * @brief Returns the base filesystem path of the App\r
+        *\r
+        * It first checks for the internal variable, then for DOCUMENT_ROOT and\r
+        * finally for PWD\r
+        *\r
+        * @return string\r
+        */\r
        public static function get_basepath() {\r
-               $basepath = get_config('system', 'basepath');\r
+               if (isset($this)) {\r
+                       $basepath = $this->basepath;\r
+               }\r
 \r
-               if ($basepath == '') {\r
-                       $basepath = dirname(__FILE__);\r
+               if (! $basepath) {\r
+                       $basepath = Config::get('system', 'basepath');\r
                }\r
 \r
-               if ($basepath == '') {\r
+               if (! $basepath && x($_SERVER, 'DOCUMENT_ROOT')) {\r
                        $basepath = $_SERVER['DOCUMENT_ROOT'];\r
                }\r
 \r
-               if ($basepath == '') {\r
+               if (! $basepath && x($_SERVER, 'PWD')) {\r
                        $basepath = $_SERVER['PWD'];\r
                }\r
 \r
@@ -375,8 +395,8 @@ class App {
                                include '.htpreconfig.php';\r
                        }\r
 \r
-                       if (get_config('config', 'hostname') != '') {\r
-                               $this->hostname = get_config('config', 'hostname');\r
+                       if (Config::get('config', 'hostname') != '') {\r
+                               $this->hostname = Config::get('config', 'hostname');\r
                        }\r
 \r
                        if (!isset($this->hostname) OR ( $this->hostname == '')) {\r
@@ -386,8 +406,8 @@ class App {
        }\r
 \r
        function get_hostname() {\r
-               if (get_config('config', 'hostname') != '') {\r
-                       $this->hostname = get_config('config', 'hostname');\r
+               if (Config::get('config', 'hostname') != '') {\r
+                       $this->hostname = Config::get('config', 'hostname');\r
                }\r
 \r
                return $this->hostname;\r
@@ -420,7 +440,7 @@ class App {
        }\r
 \r
        function init_pagehead() {\r
-               $interval = ((local_user()) ? get_pconfig(local_user(), 'system', 'update_interval') : 40000);\r
+               $interval = ((local_user()) ? PConfig::get(local_user(), 'system', 'update_interval') : 40000);\r
 \r
                // If the update is 'deactivated' set it to the highest integer number (~24 days)\r
                if ($interval < 0) {\r
@@ -457,12 +477,12 @@ class App {
                        $stylesheet = '$stylesheet';\r
                }\r
 \r
-               $shortcut_icon = get_config('system', 'shortcut_icon');\r
+               $shortcut_icon = Config::get('system', 'shortcut_icon');\r
                if ($shortcut_icon == '') {\r
                        $shortcut_icon = 'images/friendica-32.png';\r
                }\r
 \r
-               $touch_icon = get_config('system', 'touch_icon');\r
+               $touch_icon = Config::get('system', 'touch_icon');\r
                if ($touch_icon == '') {\r
                        $touch_icon = 'images/friendica-128.png';\r
                }\r
@@ -773,13 +793,13 @@ class App {
 \r
                if ($this->is_backend()) {\r
                        $process = 'backend';\r
-                       $max_processes = get_config('system', 'max_processes_backend');\r
+                       $max_processes = Config::get('system', 'max_processes_backend');\r
                        if (intval($max_processes) == 0) {\r
                                $max_processes = 5;\r
                        }\r
                } else {\r
                        $process = 'frontend';\r
-                       $max_processes = get_config('system', 'max_processes_frontend');\r
+                       $max_processes = Config::get('system', 'max_processes_frontend');\r
                        if (intval($max_processes) == 0) {\r
                                $max_processes = 20;\r
                        }\r
@@ -845,13 +865,13 @@ class App {
 \r
                if ($this->is_backend()) {\r
                        $process = 'backend';\r
-                       $maxsysload = intval(get_config('system', 'maxloadavg'));\r
+                       $maxsysload = intval(Config::get('system', 'maxloadavg'));\r
                        if ($maxsysload < 1) {\r
                                $maxsysload = 50;\r
                        }\r
                } else {\r
                        $process = 'frontend';\r
-                       $maxsysload = intval(get_config('system', 'maxloadavg_frontend'));\r
+                       $maxsysload = intval(Config::get('system', 'maxloadavg_frontend'));\r
                        if ($maxsysload < 1) {\r
                                $maxsysload = 50;\r
                        }\r
@@ -900,10 +920,10 @@ class App {
                        return;\r
                }\r
 \r
-               if (get_config('system', 'proc_windows')) {\r
-                       $resource = proc_open('cmd /c start /b ' . $cmdline, array(), $foo, dirname(__FILE__));\r
+               if (Config::get('system', 'proc_windows')) {\r
+                       $resource = proc_open('cmd /c start /b ' . $cmdline, array(), $foo, $this->get_basepath());\r
                } else {\r
-                       $resource = proc_open($cmdline . ' &', array(), $foo, dirname(__FILE__));\r
+                       $resource = proc_open($cmdline . ' &', array(), $foo, $this->get_basepath());\r
                }\r
                if (!is_resource($resource)) {\r
                        logger('We got no resource for command ' . $cmdline, LOGGER_DEBUG);\r
@@ -957,5 +977,4 @@ class App {
                }\r
                return true;\r
        }\r
-\r
 }\r