public $module;\r
public $pager;\r
public $strings;\r
+ public $basepath;\r
public $path;\r
public $hooks;\r
public $timezone;\r
\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
\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
$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
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
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
}\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
}\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
$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
q('START TRANSACTION');\r
\r
$r = q('SELECT `pid` FROM `process` WHERE `pid` = %d', intval(getmypid()));\r
- if (!dbm::is_result($r)) {\r
+ if (!\dbm::is_result($r)) {\r
q("INSERT INTO `process` (`pid`,`command`,`created`) VALUES (%d, '%s', '%s')", intval(getmypid()), dbesc($command), dbesc(datetime_convert()));\r
}\r
q('COMMIT');\r
q('START TRANSACTION');\r
\r
$r = q('SELECT `pid` FROM `process`');\r
- if (dbm::is_result($r)) {\r
+ if (\dbm::is_result($r)) {\r
foreach ($r AS $process) {\r
if (!posix_kill($process['pid'], 0)) {\r
q('DELETE FROM `process` WHERE `pid` = %d', intval($process['pid']));\r
\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
}\r
\r
- $processlist = dbm::processlist();\r
+ $processlist = \dbm::processlist();\r
if ($processlist['list'] != '') {\r
logger('Processcheck: Processes: ' . $processlist['amount'] . ' - Processlist: ' . $processlist['list'], LOGGER_DEBUG);\r
\r
\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
// If the last worker fork was less than 10 seconds before then don't fork another one.\r
// This should prevent the forking of masses of workers.\r
$cachekey = 'app:proc_run:started';\r
- $result = Cache::get($cachekey);\r
+ $result = \Cache::get($cachekey);\r
\r
if (!is_null($result) AND ( time() - $result) < 10) {\r
return;\r
}\r
\r
// Set the timestamp of the last proc_run\r
- Cache::set($cachekey, time(), CACHE_MINUTE);\r
+ \Cache::set($cachekey, time(), CACHE_MINUTE);\r
\r
array_unshift($args, ((x($this->config, 'php_path')) && (strlen($this->config['php_path'])) ? $this->config['php_path'] : 'php'));\r
\r
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
}\r
return true;\r
}\r
-\r
}\r