*/
namespace Friendica;
+use Detection\MobileDetect;
+use Exception;
use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Core\PConfig;
use Friendica\Core\System;
-use Friendica\Database\DBM;
-use dba;
-
-use Detection\MobileDetect;
-
-use Exception;
+use Friendica\Database\DBA;
require_once 'boot.php';
require_once 'include/dba.php';
* @brief App constructor.
*
* @param string $basepath Path to the app base folder
+ *
+ * @throws Exception if the Basepath is not usable
*/
public function __construct($basepath)
{
$this->basepath = rtrim($basepath, DIRECTORY_SEPARATOR);
- // The order of the following calls is important to ensure proper initialization
- $this->loadConfigFiles();
-
- $this->loadDatabase();
-
- $this->determineMode();
-
- $this->determineUrlPath();
-
- Config::load();
-
- if ($this->mode & self::MODE_DBAVAILABLE) {
- Core\Addon::loadHooks();
-
- $this->loadAddonConfig();
- }
-
- $this->loadDefaultTimezone();
-
$this->performance['start'] = microtime(true);
$this->performance['database'] = 0;
$this->performance['database_write'] = 0;
$this->callstack['rendering'] = [];
$this->callstack['parser'] = [];
- $this->page = [
- 'aside' => '',
- 'bottom' => '',
- 'content' => '',
- 'end' => '',
- 'footer' => '',
- 'htmlhead' => '',
- 'nav' => '',
- 'page_title' => '',
- 'right_aside' => '',
- 'template' => '',
- 'title' => ''
- ];
-
- $this->process_id = System::processID('log');
+ $this->reload();
set_time_limit(0);
$this->register_template_engine('Friendica\Render\FriendicaSmartyEngine');
}
+ /**
+ * Reloads the whole app instance
+ */
+ public function reload()
+ {
+ // The order of the following calls is important to ensure proper initialization
+ $this->loadConfigFiles();
+
+ $this->loadDatabase();
+
+ $this->determineMode();
+
+ $this->determineUrlPath();
+
+ Config::load();
+
+ if ($this->mode & self::MODE_DBAVAILABLE) {
+ Core\Addon::loadHooks();
+
+ $this->loadAddonConfig();
+ }
+
+ $this->loadDefaultTimezone();
+
+ $this->page = [
+ 'aside' => '',
+ 'bottom' => '',
+ 'content' => '',
+ 'end' => '',
+ 'footer' => '',
+ 'htmlhead' => '',
+ 'nav' => '',
+ 'page_title' => '',
+ 'right_aside' => '',
+ 'template' => '',
+ 'title' => ''
+ ];
+
+ $this->process_id = System::processID('log');
+ }
+
/**
* Load the configuration files
*
*/
private function loadConfigFiles()
{
- $this->loadConfigFile($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'defaults.ini.php');
+ $this->loadConfigFile($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.ini.php');
+ $this->loadConfigFile($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'settings.ini.php');
// Legacy .htconfig.php support
if (file_exists($this->basepath . DIRECTORY_SEPARATOR . '.htpreconfig.php')) {
$a = $this;
include $this->basepath . DIRECTORY_SEPARATOR . '.htconfig.php';
+
+ $this->setConfigValue('database', 'hostname', $db_host);
+ $this->setConfigValue('database', 'username', $db_user);
+ $this->setConfigValue('database', 'password', $db_pass);
+ $this->setConfigValue('database', 'database', $db_data);
+ if (isset($a->config['system']['db_charset'])) {
+ $this->setConfigValue('database', 'charset', $a->config['system']['db_charset']);
+ }
+
unset($db_host, $db_user, $db_pass, $db_data);
if (isset($default_timezone)) {
$this->setConfigValue('system', 'pidfile', $pidfile);
unset($pidfile);
}
+
+ if (isset($lang)) {
+ $this->setConfigValue('system', 'language', $lang);
+ unset($lang);
+ }
}
if (file_exists($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php')) {
$this->mode |= App::MODE_LOCALCONFIGPRESENT;
- if (!\dba::connected()) {
+ if (!DBA::connected()) {
return;
}
$this->mode |= App::MODE_DBAVAILABLE;
- if (\dba::fetch_first("SHOW TABLES LIKE 'config'") === false) {
+ if (DBA::fetchFirst("SHOW TABLES LIKE 'config'") === false) {
return;
}
public function loadDatabase()
{
- if (\dba::connected()) {
+ if (DBA::connected()) {
return;
}
}
$db_pass = (string) getenv('MYSQL_PASSWORD');
$db_data = getenv('MYSQL_DATABASE');
- } elseif (file_exists($this->basepath . DIRECTORY_SEPARATOR . '.htconfig.php')) {
- $a = new \stdClass();
- include $this->basepath . DIRECTORY_SEPARATOR . '.htconfig.php';
- $charset = isset($a->config["system"]["db_charset"]) ? $a->config["system"]["db_charset"] : $charset;
-
- unset($a);
}
$stamp1 = microtime(true);
- \dba::connect($db_host, $db_user, $db_pass, $db_data, $charset);
+ DBA::connect($db_host, $db_user, $db_pass, $db_data, $charset);
unset($db_host, $db_user, $db_pass, $db_data, $charset);
- $this->save_timestamp($stamp1, "network");
+ $this->save_timestamp($stamp1, 'network');
}
/**
}
}
- $processlist = DBM::processlist();
+ $processlist = DBA::processlist();
if ($processlist['list'] != '') {
logger('Processcheck: Processes: ' . $processlist['amount'] . ' - Processlist: ' . $processlist['list'], LOGGER_DEBUG);
return false;
}
- public function proc_run($args)
+ /**
+ * Executes a child process with 'proc_open'
+ *
+ * @param string $command The command to execute
+ * @param array $args Arguments to pass to the command ( [ 'key' => value, 'key2' => value2, ... ]
+ */
+ public function proc_run($command, $args)
{
if (!function_exists('proc_open')) {
return;
}
- array_unshift($args, $this->getConfigValue('config', 'php_path', 'php'));
+ $cmdline = $this->getConfigValue('config', 'php_path', 'php') . ' ' . escapeshellarg($command);
- for ($x = 0; $x < count($args); $x ++) {
- $args[$x] = escapeshellarg($args[$x]);
- }
+ foreach ($args as $key => $value) {
+ if (!is_null($value) && is_bool($value) && !$value) {
+ continue;
+ }
- $cmdline = implode(' ', $args);
+ $cmdline .= ' --' . $key;
+ if (!is_null($value) && !is_bool($value)) {
+ $cmdline .= ' ' . $value;
+ }
+ }
if ($this->min_memory_reached()) {
return;
// Only arrays are serialized in database, so we have to unserialize sparingly
$value = is_string($v) && preg_match("|^a:[0-9]+:{.*}$|s", $v) ? unserialize($v) : $v;
- if (!isset($this->config[$uid])) {
+ if (!isset($this->config[$uid]) || !is_array($this->config[$uid])) {
$this->config[$uid] = [];
}
- if (!isset($this->config[$uid][$cat])) {
+ if (!isset($this->config[$uid][$cat]) || !is_array($this->config[$uid][$cat])) {
$this->config[$uid][$cat] = [];
}
if ($this->profile_uid && ($this->profile_uid != local_user())) {
// Allow folks to override user themes and always use their own on their own site.
// This works only if the user is on the same server
- $user = dba::selectFirst('user', ['theme'], ['uid' => $this->profile_uid]);
- if (DBM::is_result($user) && !PConfig::get(local_user(), 'system', 'always_my_theme')) {
+ $user = DBA::selectFirst('user', ['theme'], ['uid' => $this->profile_uid]);
+ if (DBA::isResult($user) && !PConfig::get(local_user(), 'system', 'always_my_theme')) {
$page_theme = $user['theme'];
}
}
- if (!empty($_SESSION)) {
- $user_theme = defaults($_SESSION, 'theme', $system_theme);
- } else {
- $user_theme = $system_theme;
- }
+ $user_theme = Core\Session::get('theme', $system_theme);
// Specific mobile theme override
- if (($this->is_mobile || $this->is_tablet) && defaults($_SESSION, 'show-mobile', true)) {
+ if (($this->is_mobile || $this->is_tablet) && Core\Session::get('show-mobile', true)) {
$system_mobile_theme = Config::get('system', 'mobile-theme');
- $user_mobile_theme = defaults($_SESSION, 'mobile-theme', $system_mobile_theme);
+ $user_mobile_theme = Core\Session::get('mobile-theme', $system_mobile_theme);
// --- means same mobile theme as desktop
if (!empty($user_mobile_theme) && $user_mobile_theme !== '---') {