Browse Source

Add basepath to App

tags/3.5.2
Hypolite Petovan 2 years ago
parent
commit
569cd459ec

+ 3
- 2
include/auth_ejabberd.php View File

@@ -49,8 +49,9 @@ require_once("boot.php");
49 49
 
50 50
 global $a, $db;
51 51
 
52
-if (is_null($a))
53
-	$a = new App;
52
+if (is_null($a)) {
53
+	$a = new App(dirname(__DIR__));
54
+}
54 55
 
55 56
 if (is_null($db)) {
56 57
 	@include(".htconfig.php");

+ 1
- 1
include/cli_startup.php View File

@@ -12,7 +12,7 @@ function cli_startup() {
12 12
 	global $a, $db;
13 13
 
14 14
 	if (is_null($a)) {
15
-		$a = new App;
15
+		$a = new App(dirname(__DIR__));
16 16
 	}
17 17
 
18 18
 	if (is_null($db)) {

+ 1
- 1
include/dbstructure.php View File

@@ -1736,7 +1736,7 @@ function dbstructure_run(&$argv, &$argc) {
1736 1736
 	global $a, $db;
1737 1737
 
1738 1738
 	if (is_null($a)) {
1739
-		$a = new App;
1739
+		$a = new App(dirname(__DIR__));
1740 1740
 	}
1741 1741
 
1742 1742
 	if (is_null($db)) {

+ 2
- 2
include/poller.php View File

@@ -19,8 +19,8 @@ require_once("boot.php");
19 19
 function poller_run($argv, $argc){
20 20
 	global $a, $db;
21 21
 
22
-	if(is_null($a)) {
23
-		$a = new App;
22
+	if (is_null($a)) {
23
+		$a = new App(dirname(__DIR__));
24 24
 	}
25 25
 
26 26
 	if(is_null($db)) {

+ 1
- 1
include/shadowupdate.php View File

@@ -10,7 +10,7 @@ function shadowupdate_run(&$argv, &$argc){
10 10
 	global $a, $db;
11 11
 
12 12
 	if (is_null($a)) {
13
-		$a = new App;
13
+		$a = new App(dirname(__DIR__));
14 14
 	}
15 15
 
16 16
 	if (is_null($db)) {

+ 1
- 1
index.php View File

@@ -19,7 +19,7 @@ use Friendica\Core\Config;
19 19
 require_once 'boot.php';
20 20
 require_once 'object/BaseObject.php';
21 21
 
22
-$a = new App;
22
+$a = new App(__DIR__);
23 23
 BaseObject::set_app($a);
24 24
 
25 25
 // We assume that the index.php is called by a frontend process

+ 36
- 16
src/App.php View File

@@ -40,6 +40,7 @@ class App {
40 40
 	public $module;
41 41
 	public $pager;
42 42
 	public $strings;
43
+	public $basepath;
43 44
 	public $path;
44 45
 	public $hooks;
45 46
 	public $timezone;
@@ -112,8 +113,10 @@ class App {
112 113
 
113 114
 	/**
114 115
 	 * @brief App constructor.
116
+	 *
117
+	 * @param string $basepath Path to the app base folder
115 118
 	 */
116
-	function __construct() {
119
+	function __construct($basepath) {
117 120
 
118 121
 		global $default_timezone;
119 122
 
@@ -154,13 +157,6 @@ class App {
154 157
 
155 158
 		startup();
156 159
 
157
-		set_include_path(
158
-			get_include_path() . PATH_SEPARATOR
159
-			. 'include' . PATH_SEPARATOR
160
-			. 'library' . PATH_SEPARATOR
161
-			. 'library/langdet' . PATH_SEPARATOR
162
-			. '.');
163
-
164 160
 		$this->scheme = 'http';
165 161
 
166 162
 		if ((x($_SERVER, 'HTTPS') && $_SERVER['HTTPS']) ||
@@ -195,6 +191,20 @@ class App {
195 191
 			$this->hostname = $hostname;
196 192
 		}
197 193
 
194
+		if (! static::directory_usable($basepath)) {
195
+			throw new Exception('Basepath ' . $basepath . ' isn\'t usable.');
196
+		}
197
+
198
+		$this->basepath = rtrim($basepath, DIRECTORY_SEPARATOR);
199
+
200
+		set_include_path(
201
+			get_include_path() . PATH_SEPARATOR
202
+			. $this->basepath . DIRECTORY_SEPARATOR . 'include' . PATH_SEPARATOR
203
+			. $this->basepath . DIRECTORY_SEPARATOR . 'library' . PATH_SEPARATOR
204
+			. $this->basepath . DIRECTORY_SEPARATOR . 'library/langdet' . PATH_SEPARATOR
205
+			. $this->basepath);
206
+
207
+
198 208
 		if (is_array($_SERVER['argv']) && $_SERVER['argc'] > 1 && substr(end($_SERVER['argv']), 0, 4) == 'http') {
199 209
 			$this->set_baseurl(array_pop($_SERVER['argv']));
200 210
 			$_SERVER['argc'] --;
@@ -284,18 +294,28 @@ class App {
284 294
 		self::$a = $this;
285 295
 	}
286 296
 
297
+	/**
298
+	 * @brief Returns the base filesystem path of the App
299
+	 *
300
+	 * It first checks for the internal variable, then for DOCUMENT_ROOT and
301
+	 * finally for PWD
302
+	 *
303
+	 * @return string
304
+	 */
287 305
 	public static function get_basepath() {
288
-		$basepath = get_config('system', 'basepath');
306
+		if (isset($this)) {
307
+			$basepath = $this->basepath;
308
+		}
289 309
 
290
-		if ($basepath == '') {
291
-			$basepath = dirname(__FILE__);
310
+		if (! $basepath) {
311
+			$basepath = Config::get('system', 'basepath');
292 312
 		}
293 313
 
294
-		if ($basepath == '') {
314
+		if (! $basepath && x($_SERVER, 'DOCUMENT_ROOT')) {
295 315
 			$basepath = $_SERVER['DOCUMENT_ROOT'];
296 316
 		}
297 317
 
298
-		if ($basepath == '') {
318
+		if (! $basepath && x($_SERVER, 'PWD')) {
299 319
 			$basepath = $_SERVER['PWD'];
300 320
 		}
301 321
 
@@ -900,10 +920,10 @@ class App {
900 920
 			return;
901 921
 		}
902 922
 
903
-		if (get_config('system', 'proc_windows')) {
904
-			$resource = proc_open('cmd /c start /b ' . $cmdline, array(), $foo, dirname(__FILE__));
923
+		if (Config::get('system', 'proc_windows')) {
924
+			$resource = proc_open('cmd /c start /b ' . $cmdline, array(), $foo, $this->get_basepath());
905 925
 		} else {
906
-			$resource = proc_open($cmdline . ' &', array(), $foo, dirname(__FILE__));
926
+			$resource = proc_open($cmdline . ' &', array(), $foo, $this->get_basepath());
907 927
 		}
908 928
 		if (!is_resource($resource)) {
909 929
 			logger('We got no resource for command ' . $cmdline, LOGGER_DEBUG);

+ 1
- 1
util/db_update.php View File

@@ -11,7 +11,7 @@ use Friendica\App;
11 11
  */
12 12
 require_once("boot.php");
13 13
 
14
-$a = new App;
14
+$a = new App(dirname(__DIR__));
15 15
 @include(".htconfig.php");
16 16
 
17 17
 $lang = get_browser_language();

+ 1
- 1
util/maintenance.php View File

@@ -5,7 +5,7 @@ use Friendica\Core\Config;
5 5
 
6 6
 require_once("boot.php");
7 7
 
8
-$a = new App;
8
+$a = new App(dirname(__DIR__));
9 9
 @include(".htconfig.php");
10 10
 
11 11
 $lang = get_browser_language();

+ 1
- 1
util/typo.php View File

@@ -12,7 +12,7 @@ ini_set('log_errors', '0');
12 12
 
13 13
 include 'boot.php';
14 14
 
15
-$a = new App();
15
+$a = new App(dirname(__DIR__));
16 16
 
17 17
 if (x($a->config, 'php_path')) {
18 18
 	$phpath = $a->config['php_path'];

Loading…
Cancel
Save