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