From 7d8c45dde8a221c653745b4139bea1ac92f0fe60 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 24 Jun 2018 11:15:26 -0400 Subject: [PATCH 01/81] Remove dependency to App in dba::connect - Remove timing (can be done centrally) - Add charset parameter to dba::connect and dba::reconnect --- include/dba.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/include/dba.php b/include/dba.php index b95589970e..8214501e9b 100644 --- a/include/dba.php +++ b/include/dba.php @@ -29,21 +29,20 @@ class dba { private static $db_user = ''; private static $db_pass = ''; private static $db_name = ''; + private static $db_charset = ''; - public static function connect($serveraddr, $user, $pass, $db) { + public static function connect($serveraddr, $user, $pass, $db, $charset = null) + { if (!is_null(self::$db) && self::connected()) { return true; } - $a = get_app(); - - $stamp1 = microtime(true); - // We are storing these values for being able to perform a reconnect self::$db_serveraddr = $serveraddr; self::$db_user = $user; self::$db_pass = $pass; self::$db_name = $db; + self::$db_charset = $charset; $serveraddr = trim($serveraddr); @@ -58,6 +57,7 @@ class dba { $user = trim($user); $pass = trim($pass); $db = trim($db); + $charset = trim($charset); if (!(strlen($server) && strlen($user))) { return false; @@ -71,9 +71,10 @@ class dba { $connect .= ";port=".$port; } - if (isset($a->config["system"]["db_charset"])) { - $connect .= ";charset=".$a->config["system"]["db_charset"]; + if ($charset) { + $connect .= ";charset=".$charset; } + try { self::$db = @new PDO($connect, $user, $pass); self::$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); @@ -88,8 +89,8 @@ class dba { if (!mysqli_connect_errno()) { self::$connected = true; - if (isset($a->config["system"]["db_charset"])) { - self::$db->set_charset($a->config["system"]["db_charset"]); + if ($charset) { + self::$db->set_charset($charset); } } } @@ -99,7 +100,6 @@ class dba { self::$driver = null; self::$db = null; } - $a->save_timestamp($stamp1, "network"); return self::$connected; } @@ -130,7 +130,7 @@ class dba { public static function reconnect() { self::disconnect(); - $ret = self::connect(self::$db_serveraddr, self::$db_user, self::$db_pass, self::$db_name); + $ret = self::connect(self::$db_serveraddr, self::$db_user, self::$db_pass, self::$db_name, self::$db_charset); return $ret; } @@ -1377,7 +1377,7 @@ class dba { $is_alpha = true; } } - + if ($is_int && $is_alpha) { foreach ($value as &$ref) { if (is_int($ref)) { From 7c17d2026fe74ac379f619d1901cff1768b8b109 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 24 Jun 2018 14:02:57 -0400 Subject: [PATCH 02/81] Add config/local.ini.php to gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index de0fbc3d76..b75c19af19 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,9 @@ addon *~ robots.txt +#ignore local config +/config/local.ini.php + #ignore documentation, it should be newly built doc/html From 2503660f97c3f9588f1965c23b98d0c78109ee0b Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 24 Jun 2018 20:26:00 -0400 Subject: [PATCH 03/81] Add new INI config files - Add new local.ini.tpl template - Change all references from .htconfig.php to config/local.ini.php --- INSTALL.txt | 30 +- boot.php | 13 +- config/defaults.ini.php | 444 +++++++++++++++++++++++++++ config/local-sample.ini.php | 41 +++ index.php | 2 +- mod/admin.php | 2 +- mod/install.php | 2 +- src/Core/Config/JITConfigAdapter.php | 2 +- src/Core/Install.php | 20 +- view/templates/local.ini.tpl | 65 ++++ 10 files changed, 585 insertions(+), 36 deletions(-) create mode 100644 config/defaults.ini.php create mode 100644 config/local-sample.ini.php create mode 100644 view/templates/local.ini.tpl diff --git a/INSTALL.txt b/INSTALL.txt index 4345fcab1b..c6a994da63 100644 --- a/INSTALL.txt +++ b/INSTALL.txt @@ -106,8 +106,8 @@ password, database name). - Please check the additional notes if running on MySQ 5.7.17 or newer 4. If you know in advance that it will be impossible for the web server to -write or create files in your web directory, create an empty file called -.htconfig.php and make it writable by the web server. +write or create files in the /config/ subfolder, create an empty file called +local.ini.php and make it writable by the web server. 5. Visit your website with a web browser and follow the instructions. Please note any error messages and correct these before continuing. @@ -121,9 +121,9 @@ so in the host name setting for the database. 6. *If* the automated installation fails for any reason, check the following: - - ".htconfig.php" exists - If not, edit htconfig.php and change system settings. Rename -to .htconfig.php + - "config/local.ini.php" exists + If not, edit local-sample.ini.php and change system settings. Rename +to local.ini.php - Database is populated. If not, import the contents of "database.sql" with phpmyadmin or mysql command line @@ -132,7 +132,7 @@ or mysql command line Registration errors should all be recoverable automatically. If you get any *critical* failure at this point, it generally indicates the database was not installed correctly. You might wish to move/rename -.htconfig.php to another name and empty (called 'dropping') the database +local.ini.php to another name and empty (called 'dropping') the database tables, so that you can start fresh. **************************************************************************** @@ -177,7 +177,7 @@ Bad things will happen. Let there be a hardware failure, a corrupted database or whatever you can think of. So once the installation of your Friendica node is done, you should make yoursef a backup plan. -The most important file is the `.htconfig.php` file in the base directory. +The most important file is the `config/local.ini.php` file in the base directory. As it stores all your data, you should also have a recent dump of your Friendica database at hand, should you have to recover your node. @@ -274,21 +274,21 @@ Windows). ##################################################################### -- If you are unable to write the file .htconfig.php during installation +- If you are unable to write the file config/local.ini.php during installation due to permissions issues: ##################################################################### create an empty file with that name and give it world-write permission. For Linux: -% touch .htconfig.php -% chmod 777 .htconfig.php +% touch config/local.ini.php +% chmod 777 config/local.ini.php Retry the installation. As soon as the database has been created, ******* this is important ********* -% chmod 755 .htconfig.php +% chmod 755 config/local.ini.php ##################################################################### - Some configurations with "suhosin" security are configured without @@ -327,11 +327,11 @@ After a while I noticed, that bin/worker.php calls further php script via proc_open. These scripts themselves also use proc_open and fail, because they are NOT called with -d suhosin.executor.func.blacklist=none. -So the simple solution is to put the correct parameters into .htconfig.php: - // Location of PHP command line processor - $a->config['php_path'] = '/usr/bin/php -d suhosin.executor.func.blacklist=none --d suhosin.executor.eval.blacklist=none'; +So the simple solution is to put the correct parameters into config/local.ini.php: +[config] +; Location of PHP command line processor +php_path = "/usr/bin/php -d suhosin.executor.func.blacklist=none -d suhosin.executor.eval.blacklist=none" This is obvious as soon as you notice that the friendica-cron uses proc_open to execute php-scripts that also use proc_open, but it took me quite some time to diff --git a/boot.php b/boot.php index ae33f7c414..bececa9470 100644 --- a/boot.php +++ b/boot.php @@ -64,15 +64,13 @@ define('EOL', "
\r\n"); * @brief Image storage quality. * * Lower numbers save space at cost of image detail. - * For ease of upgrade, please do not change here. Change jpeg quality with - * $a->config['system']['jpeg_quality'] = n; - * in .htconfig.php, where n is netween 1 and 100, and with very poor results - * below about 50 + * For ease of upgrade, please do not change here. Set [system] jpegquality = n in config/local.ini.php, + * where n is between 1 and 100, and with very poor results below about 50 */ define('JPEG_QUALITY', 100); /** - * $a->config['system']['png_quality'] from 0 (uncompressed) to 9 + * [system] png_quality = n where is between 0 (uncompressed) to 9 */ define('PNG_QUALITY', 8); @@ -83,9 +81,10 @@ define('PNG_QUALITY', 8); * this length (on the longest side, the other side will be scaled appropriately). * Modify this value using * - * $a->config['system']['max_image_length'] = n; + * [system] + * max_image_length = n; * - * in .htconfig.php + * in config/local.ini.php * * If you don't want to set a maximum length, set to -1. The default value is * defined by 'MAX_IMAGE_LENGTH' below. diff --git a/config/defaults.ini.php b/config/defaults.ini.php new file mode 100644 index 0000000000..ffc3c495de --- /dev/null +++ b/config/defaults.ini.php @@ -0,0 +1,444 @@ +mode == App::MODE_INSTALL) { } /** - * Load configs from db. Overwrite configs from .htconfig.php + * Load configs from db. Overwrite configs from config/local.ini.php */ Config::load(); diff --git a/mod/admin.php b/mod/admin.php index 54b7e6504e..b308a2049b 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -2378,7 +2378,7 @@ function admin_page_logs(App $a) '$loglevel' => ['loglevel', L10n::t("Log level"), Config::get('system', 'loglevel'), "", $log_choices], '$form_security_token' => get_form_security_token("admin_logs"), '$phpheader' => L10n::t("PHP logging"), - '$phphint' => L10n::t("To enable logging of PHP errors and warnings you can add the following to the .htconfig.php file of your installation. The filename set in the 'error_log' line is relative to the friendica top-level directory and must be writeable by the web server. The option '1' for 'log_errors' and 'display_errors' is to enable these options, set to '0' to disable them."), + '$phphint' => L10n::t("To temporarily enable logging of PHP errors and warnings you can prepend the following to the index.php file of your installation. The filename set in the 'error_log' line is relative to the friendica top-level directory and must be writeable by the web server. The option '1' for 'log_errors' and 'display_errors' is to enable these options, set to '0' to disable them."), '$phplogcode' => "error_reporting(E_ERROR | E_WARNING | E_PARSE);\nini_set('error_log','php.out');\nini_set('log_errors','1');\nini_set('display_errors', '1');", '$phplogenabled' => $phplogenabled, ]); diff --git a/mod/install.php b/mod/install.php index 4596f9a251..79a5c40a3f 100644 --- a/mod/install.php +++ b/mod/install.php @@ -245,7 +245,7 @@ function install_content(App $a) { function manual_config(App $a) { $data = htmlentities($a->data['txt'],ENT_COMPAT, 'UTF-8'); - $o = L10n::t('The database configuration file ".htconfig.php" could not be written. Please use the enclosed text to create a configuration file in your web server root.'); + $o = L10n::t('The database configuration file "config/local.ini.php" could not be written. Please use the enclosed text to create a configuration file in your web server root.'); $o .= ""; return $o; } diff --git a/src/Core/Config/JITConfigAdapter.php b/src/Core/Config/JITConfigAdapter.php index 0e7731690b..0596974aaa 100644 --- a/src/Core/Config/JITConfigAdapter.php +++ b/src/Core/Config/JITConfigAdapter.php @@ -66,7 +66,7 @@ class JITConfigAdapter extends BaseObject implements IConfigAdapter $this->in_db[$cat][$k] = true; return $value; } elseif (isset($a->config[$cat][$k])) { - // Assign the value (mostly) from the .htconfig.php to the cache + // Assign the value (mostly) from config/local.ini.php file to the cache $this->cache[$cat][$k] = $a->config[$cat][$k]; $this->in_db[$cat][$k] = false; diff --git a/src/Core/Install.php b/src/Core/Install.php index 65ef1db241..663195e104 100644 --- a/src/Core/Install.php +++ b/src/Core/Install.php @@ -66,7 +66,7 @@ class Install extends BaseObject /** * Executes the installation of Friendica in the given environment. - * - Creates `.htconfig.php` + * - Creates `config/local.ini.php` * - Installs Database Structure * * @param string $urlpath Path based on the URL of Friendica (e.g. '/friendica') @@ -82,7 +82,7 @@ class Install extends BaseObject */ public static function install($urlpath, $dbhost, $dbuser, $dbpass, $dbdata, $phpath, $timezone, $language, $adminmail, $rino = 1) { - $tpl = get_markup_template('htconfig.tpl'); + $tpl = get_markup_template('local.ini.tpl'); $txt = replace_macros($tpl,[ '$dbhost' => $dbhost, '$dbuser' => $dbuser, @@ -96,7 +96,7 @@ class Install extends BaseObject '$rino' => $rino ]); - $result = file_put_contents('.htconfig.php', $txt); + $result = file_put_contents('config/local.ini.php', $txt); if (! $result) { self::getApp()->data['txt'] = $txt; } @@ -303,9 +303,9 @@ class Install extends BaseObject } /** - * ".htconfig.php" - Check + * "config/local.ini.php" - Check * - * Checks if it's possible to create the ".htconfig.php" + * Checks if it's possible to create the "config/local.ini.php" * * @param array $checks The list of all checks (by-ref parameter!) */ @@ -313,17 +313,17 @@ class Install extends BaseObject { $status = true; $help = ""; - if ((file_exists('.htconfig.php') && !is_writable('.htconfig.php')) || - (!file_exists('.htconfig.php') && !is_writable('.'))) { + if ((file_exists('config/local.ini.php') && !is_writable('config/local.ini.php')) || + (!file_exists('config/local.ini.php') && !is_writable('.'))) { $status = false; - $help = L10n::t('The web installer needs to be able to create a file called ".htconfig.php" in the top folder of your web server and it is unable to do so.') . EOL; + $help = L10n::t('The web installer needs to be able to create a file called "local.ini.php" in the "config" folder of your web server and it is unable to do so.') . EOL; $help .= L10n::t('This is most often a permission setting, as the web server may not be able to write files in your folder - even if you can.') . EOL; - $help .= L10n::t('At the end of this procedure, we will give you a text to save in a file named .htconfig.php in your Friendica top folder.') . EOL; + $help .= L10n::t('At the end of this procedure, we will give you a text to save in a file named local.ini.php in your Friendica "config" folder.') . EOL; $help .= L10n::t('You can alternatively skip this procedure and perform a manual installation. Please see the file "INSTALL.txt" for instructions.') . EOL; } - self::addCheck($checks, L10n::t('.htconfig.php is writable'), $status, false, $help); + self::addCheck($checks, L10n::t('config/local.ini.php is writable'), $status, false, $help); } diff --git a/view/templates/local.ini.tpl b/view/templates/local.ini.tpl new file mode 100644 index 0000000000..1b91fec88f --- /dev/null +++ b/view/templates/local.ini.tpl @@ -0,0 +1,65 @@ + Date: Mon, 25 Jun 2018 20:38:41 -0400 Subject: [PATCH 04/81] Centralize startup steps in Friendica\App - Add loadDatabase startup step - Add loadConfigFiles startup step - Remove startup() in boot.php - Replace App::checkMaintenanceMode() with App::determineMode() --- index.php | 2 - src/App.php | 245 +++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 184 insertions(+), 63 deletions(-) diff --git a/index.php b/index.php index a5120187b1..d4e263bcc0 100644 --- a/index.php +++ b/index.php @@ -76,8 +76,6 @@ if (!$a->mode == App::MODE_INSTALL) { Session::init(); Addon::loadHooks(); Addon::callHooks('init_1'); - - $a->checkMaintenanceMode(); } $lang = L10n::getBrowserLanguage(); diff --git a/src/App.php b/src/App.php index 059efc17cc..ac86b2f6c7 100644 --- a/src/App.php +++ b/src/App.php @@ -4,7 +4,6 @@ */ namespace Friendica; -use Friendica\Core\Cache; use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\PConfig; @@ -17,6 +16,7 @@ use Detection\MobileDetect; use Exception; require_once 'boot.php'; +require_once 'include/dba.php'; require_once 'include/text.php'; /** @@ -40,9 +40,10 @@ class App public $module_loaded = false; public $module_class = null; - public $query_string; - public $config; - public $page; + public $query_string = ''; + public $config = []; + public $page = []; + public $pager = []; public $page_offset; public $profile; public $profile_uid; @@ -54,16 +55,15 @@ class App public $content; public $data = []; public $error = false; - public $cmd; + public $cmd = ''; public $argv; public $argc; public $module; public $mode = App::MODE_NORMAL; - public $pager; public $strings; public $basepath; - public $path; - public $hooks; + public $urlpath; + public $hooks = []; public $timezone; public $interactive = true; public $addons; @@ -127,7 +127,6 @@ class App private $curl_code; private $curl_content_type; private $curl_headers; - private static $a; /** * @brief App constructor. @@ -136,21 +135,21 @@ class App */ public function __construct($basepath) { - global $default_timezone; - if (!static::directory_usable($basepath, false)) { throw new Exception('Basepath ' . $basepath . ' isn\'t usable.'); } $this->basepath = rtrim($basepath, DIRECTORY_SEPARATOR); - if (file_exists($this->basepath . DIRECTORY_SEPARATOR . '.htpreconfig.php')) { - include $this->basepath . DIRECTORY_SEPARATOR . '.htpreconfig.php'; - } + $this->determineUrlPath(); - $this->timezone = ((x($default_timezone)) ? $default_timezone : 'UTC'); + $this->loadConfigFiles(); - date_default_timezone_set($this->timezone); + $this->loadDatabase(); + + $this->determineMode(); + + $this->loadDefaultTimezone(); $this->performance['start'] = microtime(true); $this->performance['database'] = 0; @@ -173,8 +172,6 @@ class App $this->callstack['rendering'] = []; $this->callstack['parser'] = []; - $this->config = []; - $this->page = [ 'aside' => '', 'bottom' => '', @@ -189,10 +186,6 @@ class App 'title' => '' ]; - $this->pager = []; - - $this->query_string = ''; - $this->process_id = System::processID('log'); set_time_limit(0); @@ -218,16 +211,6 @@ class App if (x($_SERVER, 'SERVER_PORT') && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) { $this->hostname .= ':' . $_SERVER['SERVER_PORT']; } - /* - * Figure out if we are running at the top of a domain - * or in a sub-directory and adjust accordingly - */ - - /// @TODO This kind of escaping breaks syntax-highlightning on CoolEdit (Midnight Commander) - $path = trim(dirname($_SERVER['SCRIPT_NAME']), '/\\'); - if (isset($path) && strlen($path) && ($path != $this->path)) { - $this->path = $path; - } } set_include_path( @@ -238,19 +221,16 @@ class App if ((x($_SERVER, 'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'], 0, 9) === 'pagename=') { $this->query_string = substr($_SERVER['QUERY_STRING'], 9); - - // removing trailing / - maybe a nginx problem - $this->query_string = ltrim($this->query_string, '/'); } elseif ((x($_SERVER, 'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'], 0, 2) === 'q=') { $this->query_string = substr($_SERVER['QUERY_STRING'], 2); - - // removing trailing / - maybe a nginx problem - $this->query_string = ltrim($this->query_string, '/'); } - if (x($_GET, 'pagename')) { + // removing trailing / - maybe a nginx problem + $this->query_string = ltrim($this->query_string, '/'); + + if (!empty($_GET['pagename'])) { $this->cmd = trim($_GET['pagename'], '/\\'); - } elseif (x($_GET, 'q')) { + } elseif (!empty($_GET['q'])) { $this->cmd = trim($_GET['q'], '/\\'); } @@ -311,16 +291,174 @@ class App // Register template engines $this->register_template_engine('Friendica\Render\FriendicaSmartyEngine'); + } - /** - * Load the configuration file which contains our DB credentials. - * Ignore errors. If the file doesn't exist or is empty, we are running in - * installation mode. * + private function loadConfigFiles() + { + $this->loadConfigFile($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'defaults.ini.php'); + + // Legacy .htconfig.php support + if (file_exists($this->basepath . DIRECTORY_SEPARATOR . '.htpreconfig.php')) { + $a = $this; + include $this->basepath . DIRECTORY_SEPARATOR . '.htpreconfig.php'; + } + + // Legacy .htconfig.php support + if (file_exists($this->basepath . DIRECTORY_SEPARATOR . '.htconfig.php')) { + $a = $this; + + include $this->basepath . DIRECTORY_SEPARATOR . '.htconfig.php'; + unset($db_host, $db_user, $db_pass, $db_data); + + if (isset($default_timezone)) { + $this->setConfigValue('system', 'default_timezone', $default_timezone); + unset($default_timezone); + } + + if (isset($pidfile)) { + $this->setConfigValue('system', 'pidfile', $pidfile); + unset($pidfile); + } + } + + if (file_exists($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php')) { + $this->loadConfigFile($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php'); + } + } + + public function loadConfigFile($filepath) + { + if (!file_exists($filepath)) { + throw new Exception('Error parsing non-existent config file ' . $filepath); + } + + $contents = include($filepath); + + $config = parse_ini_string($contents, true, INI_SCANNER_TYPED); + + if ($config === false) { + throw new Exception('Error parsing config file ' . $filepath); + } + + foreach($config as $category => $values) { + foreach($values as $key => $value) { + $this->setConfigValue($category, $key, $value); + } + } + } + + private function loadAddonConfig() + { + // Loads addons default config + Core\Addon::callHooks('load_config'); + + // Load the local config file again in case there are overwritten addon config + if (file_exists($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php')) { + $this->loadConfigFile($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php'); + } + } + + private function loadDefaultTimezone() + { + if ($this->getConfigValue('system', 'default_timezone')) { + $this->timezone = $this->getConfigValue('system', 'default_timezone'); + } else { + global $default_timezone; + $this->timezone = !empty($default_timezone) ? $default_timezone : 'UTC'; + } + + if ($this->timezone) { + date_default_timezone_set($this->timezone); + } + } + + /** + * Figure out if we are running at the top of a domain + * or in a sub-directory and adjust accordingly + */ + private function determineUrlPath() + { + $this->urlpath = $this->getConfigValue('system', 'urlpath'); + + /* SCRIPT_URL gives /path/to/friendica/module/parameter + * QUERY_STRING gives pagename=module/parameter + * + * To get /path/to/friendica we perform dirname() for as many levels as there are slashes in the QUERY_STRING */ - $this->mode = ((file_exists('.htconfig.php') && filesize('.htconfig.php')) ? App::MODE_NORMAL : App::MODE_INSTALL); + if (!empty($_SERVER['SCRIPT_URL']) && !empty($_SERVER['QUERY_STRING'])) { + $path = trim(dirname($_SERVER['SCRIPT_URL'], substr_count(trim($_SERVER['QUERY_STRING'], '/'), '/') + 1), '/'); + if ($path && $path != $this->urlpath) { + $this->urlpath = $path; + } + } + } - self::$a = $this; + private function determineMode() + { + $this->mode = App::MODE_INSTALL; + + // Missing DB connection + if (!\dba::connected()) { + return; + } + + // Working DB connection, missing tables + if (\dba::fetch_first("SHOW TABLES LIKE 'config'") === false) { + return; + } + + // Maintenance mode check + if (Config::get('system', 'maintenance')) { + $this->mode = App::MODE_MAINTENANCE; + } else { + $this->mode = App::MODE_NORMAL; + } + } + + public function loadDatabase() + { + if (\dba::connected()) { + return; + } + + $db_host = $this->getConfigValue('database', 'hostname'); + $db_user = $this->getConfigValue('database', 'username'); + $db_pass = $this->getConfigValue('database', 'password'); + $db_data = $this->getConfigValue('database', 'database'); + $charset = $this->getConfigValue('database', 'charset'); + + // Use environment variables for mysql if they are set beforehand + if (!empty(getenv('MYSQL_HOST')) + && !empty(getenv('MYSQL_PORT')) + && (!empty(getenv('MYSQL_USERNAME')) || !empty(getenv('MYSQL_USER'))) + && !empty(getenv('MYSQL_PASSWORD')) + && !empty(getenv('MYSQL_DATABASE'))) + { + $db_host = getenv('MYSQL_HOST') . ':' . getenv('MYSQL_PORT'); + + if (!empty(getenv('MYSQL_USERNAME'))) { + $db_user = getenv('MYSQL_USERNAME'); + } elseif (!empty(getenv('MYSQL_USER'))) { + $db_user = getenv('MYSQL_USER'); + } + + $db_pass = 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); + unset($db_host, $db_user, $db_pass, $db_data, $charset); + + $this->save_timestamp($stamp1, "network"); } /** @@ -1107,21 +1245,6 @@ class App return $sender_email; } - /** - * @note Checks, if the App is in the Maintenance-Mode - * - * @return boolean - */ - public function checkMaintenanceMode() - { - if (Config::get('system', 'maintenance')) { - $this->mode = App::MODE_MAINTENANCE; - return true; - } - - return false; - } - /** * Returns the current theme name. * From e952d6677bf01ab23f80c4ffbe0e4e3d0c1ef43b Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 25 Jun 2018 20:39:56 -0400 Subject: [PATCH 05/81] Rename App->path to App->urlpath --- mod/dfrn_request.php | 2 +- mod/hcard.php | 2 +- mod/profile.php | 2 +- mod/redir.php | 2 +- src/App.php | 6 +++--- src/Core/NotificationsManager.php | 2 +- src/Model/Contact.php | 2 +- src/Module/Magic.php | 2 +- util/htconfig.vagrant.php | 2 +- view/theme/frio/php/default.php | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index 6592bf901f..b7a0dd7487 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -611,7 +611,7 @@ function dfrn_request_content(App $a) } elseif (x($_GET, 'address') && ($_GET['address'] != "")) { $myaddr = $_GET['address']; } elseif (local_user()) { - if (strlen($a->path)) { + if (strlen($a->urlpath)) { $myaddr = System::baseUrl() . '/profile/' . $a->user['nickname']; } else { $myaddr = $a->user['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3); diff --git a/mod/hcard.php b/mod/hcard.php index 07c551ebdb..f2b86baf99 100644 --- a/mod/hcard.php +++ b/mod/hcard.php @@ -49,7 +49,7 @@ function hcard_init(App $a) $a->page['htmlhead'] .= '' . "\r\n" ; $a->page['htmlhead'] .= '' . "\r\n" ; - $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : '')); + $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $a->get_hostname() . (($a->urlpath) ? '/' . $a->urlpath : '')); $a->page['htmlhead'] .= '' . "\r\n"; header('Link: <' . System::baseUrl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false); diff --git a/mod/profile.php b/mod/profile.php index 60741db726..08c0dfdb86 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -79,7 +79,7 @@ function profile_init(App $a) $a->page['htmlhead'] .= '' . "\r\n"; $a->page['htmlhead'] .= '' . "\r\n"; $a->page['htmlhead'] .= '' . "\r\n"; - $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $a->get_hostname() . ($a->path ? '/' . $a->path : '')); + $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $a->get_hostname() . ($a->urlpath ? '/' . $a->urlpath : '')); $a->page['htmlhead'] .= '' . "\r\n"; header('Link: <' . System::baseUrl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false); diff --git a/mod/redir.php b/mod/redir.php index 8484b53eba..e448aa36d3 100644 --- a/mod/redir.php +++ b/mod/redir.php @@ -56,7 +56,7 @@ function redir_init(App $a) { } if (remote_user()) { - $host = substr(System::baseUrl() . ($a->path ? '/' . $a->path : ''), strpos(System::baseUrl(), '://') + 3); + $host = substr(System::baseUrl() . ($a->urlpath ? '/' . $a->urlpath : ''), strpos(System::baseUrl(), '://') + 3); $remotehost = substr($contact['addr'], strpos($contact['addr'], '@') + 1); // On a local instance we have to check if the local user has already authenticated diff --git a/src/App.php b/src/App.php index ac86b2f6c7..652b048260 100644 --- a/src/App.php +++ b/src/App.php @@ -551,7 +551,7 @@ class App $this->hostname = Config::get('config', 'hostname'); } - return $scheme . '://' . $this->hostname . ((isset($this->path) && strlen($this->path)) ? '/' . $this->path : '' ); + return $scheme . '://' . $this->hostname . (!empty($this->urlpath) ? '/' . $this->urlpath : '' ); } /** @@ -579,7 +579,7 @@ class App $hostname .= ':' . $parsed['port']; } if (x($parsed, 'path')) { - $this->path = trim($parsed['path'], '\\/'); + $this->urlpath = trim($parsed['path'], '\\/'); } if (file_exists($this->basepath . DIRECTORY_SEPARATOR . '.htpreconfig.php')) { @@ -607,7 +607,7 @@ class App public function get_path() { - return $this->path; + return $this->urlpath; } public function set_pager_total($n) diff --git a/src/Core/NotificationsManager.php b/src/Core/NotificationsManager.php index 507d4db131..fa8476b906 100644 --- a/src/Core/NotificationsManager.php +++ b/src/Core/NotificationsManager.php @@ -613,7 +613,7 @@ class NotificationsManager extends BaseObject // We have to distinguish between these two because they use different data. // Contact suggestions if ($it['fid']) { - $return_addr = bin2hex(self::getApp()->user['nickname'] . '@' . self::getApp()->get_hostname() . ((self::getApp()->path) ? '/' . self::getApp()->path : '')); + $return_addr = bin2hex(self::getApp()->user['nickname'] . '@' . self::getApp()->get_hostname() . ((self::getApp()->urlpath) ? '/' . self::getApp()->urlpath : '')); $intro = [ 'label' => 'friend_suggestion', diff --git a/src/Model/Contact.php b/src/Model/Contact.php index dcd6c37db5..093ee0d91e 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -1316,7 +1316,7 @@ class Contact extends BaseObject if (($ret['network'] === NETWORK_DFRN) && !DBM::is_result($r)) { if ($interactive) { - if (strlen($a->path)) { + if (strlen($a->urlpath)) { $myaddr = bin2hex(System::baseUrl() . '/profile/' . $a->user['nickname']); } else { $myaddr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname()); diff --git a/src/Module/Magic.php b/src/Module/Magic.php index 0b6874069a..d55e8f93bc 100644 --- a/src/Module/Magic.php +++ b/src/Module/Magic.php @@ -80,7 +80,7 @@ class Magic extends BaseModule '', $headers, $user['prvkey'], - 'acct:' . $user['nickname'] . '@' . $a->get_hostname() . ($a->path ? '/' . $a->path : ''), + 'acct:' . $user['nickname'] . '@' . $a->get_hostname() . ($a->urlpath ? '/' . $a->urlpath : ''), false, true, 'sha512' diff --git a/util/htconfig.vagrant.php b/util/htconfig.vagrant.php index 623b587ef0..f75e208ee5 100644 --- a/util/htconfig.vagrant.php +++ b/util/htconfig.vagrant.php @@ -13,7 +13,7 @@ $db_data = 'friendica'; // For instance if your URL is 'http://example.com/directory/subdirectory', // set path to 'directory/subdirectory'. -$a->path = ''; +$a->urlpath = ''; // Choose a legal default timezone. If you are unsure, use "America/Los_Angeles". // It can be changed later and only applies to timestamps for anonymous viewers. diff --git a/view/theme/frio/php/default.php b/view/theme/frio/php/default.php index 99baa8efc8..28f44504b6 100644 --- a/view/theme/frio/php/default.php +++ b/view/theme/frio/php/default.php @@ -26,7 +26,7 @@ if (!isset($minimal)) { path ? "/" . $a->path . "/" : "/"; + $basepath = $a->urlpath ? "/" . $a->urlpath . "/" : "/"; $frio = "view/theme/frio"; // Because we use minimal for modals the header and the included js stuff should be only loaded From decfc553f752fc6c00ad2a965f53ac01833557ad Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 25 Jun 2018 20:44:35 -0400 Subject: [PATCH 06/81] Set BaseObject::setApp in App --- bin/auth_ejabberd.php | 4 +--- bin/daemon.php | 2 -- bin/worker.php | 1 - boot.php | 9 +-------- index.php | 2 -- src/App.php | 2 ++ src/BaseObject.php | 8 +++----- 7 files changed, 7 insertions(+), 21 deletions(-) diff --git a/bin/auth_ejabberd.php b/bin/auth_ejabberd.php index 06d8488df8..10b9d874f1 100755 --- a/bin/auth_ejabberd.php +++ b/bin/auth_ejabberd.php @@ -33,7 +33,6 @@ */ use Friendica\App; -use Friendica\BaseObject; use Friendica\Core\Config; use Friendica\Util\ExAuth; @@ -55,7 +54,6 @@ require_once "boot.php"; require_once "include/dba.php"; $a = new App(dirname(__DIR__)); -BaseObject::setApp($a); @include ".htconfig.php"; dba::connect($db_host, $db_user, $db_pass, $db_data); @@ -63,4 +61,4 @@ unset($db_host, $db_user, $db_pass, $db_data); $oAuth = new ExAuth(); -$oAuth->readStdin(); +$oAuth->readStdin(); \ No newline at end of file diff --git a/bin/daemon.php b/bin/daemon.php index 1abb701462..acb4a2c682 100755 --- a/bin/daemon.php +++ b/bin/daemon.php @@ -8,7 +8,6 @@ */ use Friendica\App; -use Friendica\BaseObject; use Friendica\Core\Config; use Friendica\Core\Worker; @@ -28,7 +27,6 @@ require_once "boot.php"; require_once "include/dba.php"; $a = new App(dirname(__DIR__)); -BaseObject::setApp($a); require_once ".htconfig.php"; dba::connect($db_host, $db_user, $db_pass, $db_data); diff --git a/bin/worker.php b/bin/worker.php index 44980961cf..77c85b1d58 100755 --- a/bin/worker.php +++ b/bin/worker.php @@ -27,7 +27,6 @@ require_once "boot.php"; require_once "include/dba.php"; $a = new App(dirname(__DIR__)); -BaseObject::setApp($a); require_once ".htconfig.php"; dba::connect($db_host, $db_user, $db_pass, $db_data); diff --git a/boot.php b/boot.php index bececa9470..728f36b16e 100644 --- a/boot.php +++ b/boot.php @@ -508,14 +508,7 @@ if (!defined('CURLE_OPERATION_TIMEDOUT')) { */ function get_app() { - global $a; - - if (empty($a)) { - $a = new App(dirname(__DIR__)); - BaseObject::setApp($a); - } - - return $a; + return BaseObject::getApp(); } /** diff --git a/index.php b/index.php index d4e263bcc0..d83e202d2a 100644 --- a/index.php +++ b/index.php @@ -9,7 +9,6 @@ */ use Friendica\App; -use Friendica\BaseObject; use Friendica\Content\Nav; use Friendica\Core\Addon; use Friendica\Core\Config; @@ -25,7 +24,6 @@ use Friendica\Module\Login; require_once 'boot.php'; $a = new App(__DIR__); -BaseObject::setApp($a); // We assume that the index.php is called by a frontend process // The value is set to "true" by default in boot.php diff --git a/src/App.php b/src/App.php index 652b048260..17cfd3eefc 100644 --- a/src/App.php +++ b/src/App.php @@ -139,6 +139,8 @@ class App throw new Exception('Basepath ' . $basepath . ' isn\'t usable.'); } + BaseObject::setApp($this); + $this->basepath = rtrim($basepath, DIRECTORY_SEPARATOR); $this->determineUrlPath(); diff --git a/src/BaseObject.php b/src/BaseObject.php index 5adfe096d7..6b64daccf0 100644 --- a/src/BaseObject.php +++ b/src/BaseObject.php @@ -24,12 +24,10 @@ class BaseObject */ public static function getApp() { - if (self::$app) { - return self::$app; + if (empty(self::$app)) { + self::$app = new App(dirname(__DIR__)); } - self::$app = get_app(); - return self::$app; } @@ -40,7 +38,7 @@ class BaseObject * * @return void */ - public static function setApp($app) + public static function setApp(App $app) { self::$app = $app; } From 3985a4bc43cb923ed0348a0881d5aa11a13d70ef Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 25 Jun 2018 20:56:07 -0400 Subject: [PATCH 07/81] Remove extraneous dba::connect calls --- bin/auth_ejabberd.php | 5 ----- bin/daemon.php | 9 ++++----- bin/worker.php | 5 ----- index.php | 5 +---- src/Core/Console/ArchiveContact.php | 8 ++------ src/Core/Console/Config.php | 8 ++------ src/Core/Console/DatabaseStructure.php | 6 +----- src/Core/Console/GlobalCommunityBlock.php | 8 ++------ src/Core/Console/GlobalCommunitySilence.php | 8 ++------ src/Core/Console/Maintenance.php | 8 ++------ src/Core/Console/NewPassword.php | 8 ++------ 11 files changed, 18 insertions(+), 60 deletions(-) diff --git a/bin/auth_ejabberd.php b/bin/auth_ejabberd.php index 10b9d874f1..6c078e2249 100755 --- a/bin/auth_ejabberd.php +++ b/bin/auth_ejabberd.php @@ -33,7 +33,6 @@ */ use Friendica\App; -use Friendica\Core\Config; use Friendica\Util\ExAuth; if (sizeof($_SERVER["argv"]) == 0) { @@ -55,10 +54,6 @@ require_once "include/dba.php"; $a = new App(dirname(__DIR__)); -@include ".htconfig.php"; -dba::connect($db_host, $db_user, $db_pass, $db_data); -unset($db_host, $db_user, $db_pass, $db_data); - $oAuth = new ExAuth(); $oAuth->readStdin(); \ No newline at end of file diff --git a/bin/daemon.php b/bin/daemon.php index acb4a2c682..2450e4223e 100755 --- a/bin/daemon.php +++ b/bin/daemon.php @@ -28,8 +28,9 @@ require_once "include/dba.php"; $a = new App(dirname(__DIR__)); -require_once ".htconfig.php"; -dba::connect($db_host, $db_user, $db_pass, $db_data); +if ($a->mode === App::MODE_INSTALL) { + die("Friendica isn't properly installed yet.\n"); +} Config::load(); @@ -125,11 +126,9 @@ if (!$foreground) { file_put_contents($pidfile, $pid); // We lose the database connection upon forking - dba::connect($db_host, $db_user, $db_pass, $db_data); + $a->loadDatabase(); } -unset($db_host, $db_user, $db_pass, $db_data); - Config::set('system', 'worker_daemon_mode', true); // Just to be sure that this script really runs endlessly diff --git a/bin/worker.php b/bin/worker.php index 77c85b1d58..2abfa0ad92 100755 --- a/bin/worker.php +++ b/bin/worker.php @@ -24,14 +24,9 @@ if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) { } require_once "boot.php"; -require_once "include/dba.php"; $a = new App(dirname(__DIR__)); -require_once ".htconfig.php"; -dba::connect($db_host, $db_user, $db_pass, $db_data); -unset($db_host, $db_user, $db_pass, $db_data); - Config::load(); // Check the database structure and possibly fixes it diff --git a/index.php b/index.php index d83e202d2a..501235f497 100644 --- a/index.php +++ b/index.php @@ -41,10 +41,7 @@ if (!$a->mode == App::MODE_INSTALL) { require_once "include/dba.php"; if (!$a->mode == App::MODE_INSTALL) { - $result = dba::connect($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - - if (!$result) { + if (!dba::connected()) { System::unavailable(); } diff --git a/src/Core/Console/ArchiveContact.php b/src/Core/Console/ArchiveContact.php index 7a973f3116..63ace91c0f 100644 --- a/src/Core/Console/ArchiveContact.php +++ b/src/Core/Console/ArchiveContact.php @@ -54,12 +54,8 @@ HELP; throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); } - require_once '.htconfig.php'; - $result = \dba::connect($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - - if (!$result) { - throw new \RuntimeException('Unable to connect to database'); + if ($a->mode === App::MODE_INSTALL) { + throw new \RuntimeException('Friendica isn\'t properly installed yet.'); } $nurl = normalise_link($this->getArgument(0)); diff --git a/src/Core/Console/Config.php b/src/Core/Console/Config.php index 306e1c275e..4f7d090d5c 100644 --- a/src/Core/Console/Config.php +++ b/src/Core/Console/Config.php @@ -92,12 +92,8 @@ HELP; throw new CommandArgsException('Too many arguments'); } - require_once '.htconfig.php'; - $result = dba::connect($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - - if (!$result) { - throw new \RuntimeException('Unable to connect to database'); + if ($a->mode === \Friendica\App::MODE_INSTALL) { + $this->out('Database isn\'t ready or populated yet, showing file config only'); } if (count($this->args) == 3) { diff --git a/src/Core/Console/DatabaseStructure.php b/src/Core/Console/DatabaseStructure.php index eb4c6df998..1190484310 100644 --- a/src/Core/Console/DatabaseStructure.php +++ b/src/Core/Console/DatabaseStructure.php @@ -56,11 +56,7 @@ HELP; throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); } - require_once '.htconfig.php'; - $result = \dba::connect($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - - if (!$result) { + if (!\dba::connected()) { throw new \RuntimeException('Unable to connect to database'); } diff --git a/src/Core/Console/GlobalCommunityBlock.php b/src/Core/Console/GlobalCommunityBlock.php index 26c5d13131..5fcc6be160 100644 --- a/src/Core/Console/GlobalCommunityBlock.php +++ b/src/Core/Console/GlobalCommunityBlock.php @@ -56,12 +56,8 @@ HELP; throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); } - require_once '.htconfig.php'; - $result = \dba::connect($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - - if (!$result) { - throw new \RuntimeException('Unable to connect to database'); + if ($a->mode == \Friendica\App::MODE_INSTALL) { + throw new \RuntimeException('Database isn\'t ready or populated yet'); } $contact_id = Contact::getIdForURL($this->getArgument(0)); diff --git a/src/Core/Console/GlobalCommunitySilence.php b/src/Core/Console/GlobalCommunitySilence.php index 72d5a4f881..a70888e454 100644 --- a/src/Core/Console/GlobalCommunitySilence.php +++ b/src/Core/Console/GlobalCommunitySilence.php @@ -64,12 +64,8 @@ HELP; throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); } - require_once '.htconfig.php'; - $result = \dba::connect($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - - if (!$result) { - throw new \RuntimeException('Unable to connect to database'); + if ($a->mode == \Friendica\App::MODE_INSTALL) { + throw new \RuntimeException('Database isn\'t ready or populated yet'); } /** diff --git a/src/Core/Console/Maintenance.php b/src/Core/Console/Maintenance.php index 6638e4bfe1..68d33337ab 100644 --- a/src/Core/Console/Maintenance.php +++ b/src/Core/Console/Maintenance.php @@ -64,12 +64,8 @@ HELP; throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); } - require_once '.htconfig.php'; - $result = \dba::connect($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - - if (!$result) { - throw new \RuntimeException('Unable to connect to database'); + if ($a->mode == \Friendica\App::MODE_INSTALL) { + throw new \RuntimeException('Database isn\'t ready or populated yet'); } Core\Config::load(); diff --git a/src/Core/Console/NewPassword.php b/src/Core/Console/NewPassword.php index f5698ba716..e5f9349190 100644 --- a/src/Core/Console/NewPassword.php +++ b/src/Core/Console/NewPassword.php @@ -58,12 +58,8 @@ HELP; throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); } - require_once '.htconfig.php'; - $result = \dba::connect($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - - if (!$result) { - throw new \RuntimeException('Unable to connect to database'); + if ($a->mode == \Friendica\App::MODE_INSTALL) { + throw new \RuntimeException('Database isn\'t ready or populated yet'); } $nick = $this->getArgument(0); From 46b34574d97734127f32c3010d48cca59d755dd8 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 25 Jun 2018 20:56:35 -0400 Subject: [PATCH 08/81] Update support for daemon pidfile config --- bin/daemon.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bin/daemon.php b/bin/daemon.php index 2450e4223e..2813100267 100755 --- a/bin/daemon.php +++ b/bin/daemon.php @@ -34,11 +34,14 @@ if ($a->mode === App::MODE_INSTALL) { Config::load(); -if (!isset($pidfile)) { - die('Please specify a pid file in the variable $pidfile in the .htconfig.php. For example:'."\n". - '$pidfile = "/path/to/daemon.pid";'."\n"); +if (empty(Config::get('system', 'pidfile'))) { + die('Please set system.pidfile in config/local.ini.php. For example:'."\n". + '[system]'."\n". + 'pidfile = /path/to/daemon.pid'."\n"); } +$pidfile = Config::get('system', 'pidfile'); + if (in_array("start", $_SERVER["argv"])) { $mode = "start"; } From fd7179ee6cbc154af0db9d41114bc671deeba08c Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 25 Jun 2018 20:57:57 -0400 Subject: [PATCH 09/81] Prevent infinite loops with Config when App is in install mode --- bin/auth_ejabberd.php | 7 ++++--- src/Core/Config.php | 25 +++++++++++++++++++++++++ src/Core/PConfig.php | 28 ++++++++++++++++++++++++++-- 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/bin/auth_ejabberd.php b/bin/auth_ejabberd.php index 6c078e2249..7ad28c96f5 100755 --- a/bin/auth_ejabberd.php +++ b/bin/auth_ejabberd.php @@ -54,6 +54,7 @@ require_once "include/dba.php"; $a = new App(dirname(__DIR__)); -$oAuth = new ExAuth(); - -$oAuth->readStdin(); \ No newline at end of file +if ($a->mode === App::MODE_NORMAL) { + $oAuth = new ExAuth(); + $oAuth->readStdin(); +} \ No newline at end of file diff --git a/src/Core/Config.php b/src/Core/Config.php index 3c1d3245fd..b327eb133f 100644 --- a/src/Core/Config.php +++ b/src/Core/Config.php @@ -29,6 +29,11 @@ class Config extends BaseObject public static function init() { + // Database isn't ready or populated yet + if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) { + return; + } + if (self::getApp()->getConfigValue('system', 'config_adapter') == 'preload') { self::$adapter = new Config\PreloadConfigAdapter(); } else { @@ -48,6 +53,11 @@ class Config extends BaseObject */ public static function load($family = "config") { + // Database isn't ready or populated yet + if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) { + return; + } + if (empty(self::$adapter)) { self::init(); } @@ -76,6 +86,11 @@ class Config extends BaseObject */ public static function get($family, $key, $default_value = null, $refresh = false) { + // Database isn't ready or populated yet, fallback to file config + if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) { + return self::getApp()->getConfigValue($family, $key, $default_value); + } + if (empty(self::$adapter)) { self::init(); } @@ -99,6 +114,11 @@ class Config extends BaseObject */ public static function set($family, $key, $value) { + // Database isn't ready or populated yet + if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) { + return false; + } + if (empty(self::$adapter)) { self::init(); } @@ -119,6 +139,11 @@ class Config extends BaseObject */ public static function delete($family, $key) { + // Database isn't ready or populated yet + if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) { + return false; + } + if (empty(self::$adapter)) { self::init(); } diff --git a/src/Core/PConfig.php b/src/Core/PConfig.php index 274122deda..3b01bceeaf 100644 --- a/src/Core/PConfig.php +++ b/src/Core/PConfig.php @@ -9,7 +9,6 @@ namespace Friendica\Core; use Friendica\BaseObject; -use Friendica\Core\Config; require_once 'include/dba.php'; @@ -29,7 +28,12 @@ class PConfig extends BaseObject public static function init($uid) { - if (Config::get('system', 'config_adapter') == 'preload') { + // Database isn't ready or populated yet + if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) { + return; + } + + if (self::getApp()->getConfigValue('system', 'config_adapter') == 'preload') { self::$adapter = new Config\PreloadPConfigAdapter($uid); } else { self::$adapter = new Config\JITPConfigAdapter($uid); @@ -49,6 +53,11 @@ class PConfig extends BaseObject */ public static function load($uid, $family) { + // Database isn't ready or populated yet + if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) { + return; + } + if (empty(self::$adapter)) { self::init($uid); } @@ -73,6 +82,11 @@ class PConfig extends BaseObject */ public static function get($uid, $family, $key, $default_value = null, $refresh = false) { + // Database isn't ready or populated yet + if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) { + return; + } + if (empty(self::$adapter)) { self::init($uid); } @@ -97,6 +111,11 @@ class PConfig extends BaseObject */ public static function set($uid, $family, $key, $value) { + // Database isn't ready or populated yet + if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) { + return false; + } + if (empty(self::$adapter)) { self::init($uid); } @@ -118,6 +137,11 @@ class PConfig extends BaseObject */ public static function delete($uid, $family, $key) { + // Database isn't ready or populated yet + if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) { + return false; + } + if (empty(self::$adapter)) { self::init($uid); } From f0ce897647a5ca8fb2ec498579bc080f07488f2d Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 25 Jun 2018 20:58:33 -0400 Subject: [PATCH 10/81] Remove stray include of .htconfig.php in index.php --- index.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/index.php b/index.php index 501235f497..16597fa62e 100644 --- a/index.php +++ b/index.php @@ -29,11 +29,6 @@ $a = new App(__DIR__); // The value is set to "true" by default in boot.php $a->backend = false; -// Only load config if found, don't suppress errors -if (!$a->mode == App::MODE_INSTALL) { - include ".htconfig.php"; -} - /** * Try to open the database; */ From e7c3d453c2695dab046767d78fcf29570aa77aff Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 25 Jun 2018 20:59:02 -0400 Subject: [PATCH 11/81] Update config console command --- src/Core/Console/Config.php | 43 ++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/src/Core/Console/Config.php b/src/Core/Console/Config.php index 4f7d090d5c..a6083ddb9f 100644 --- a/src/Core/Console/Config.php +++ b/src/Core/Console/Config.php @@ -67,7 +67,7 @@ Description Sets the value of the provided key in the category Notes: - Setting config entries which are manually set in .htconfig.php may result in + Setting config entries which are manually set in config/local.ini.php may result in conflict between database settings and the manual startup settings. Options @@ -97,23 +97,26 @@ HELP; } if (count($this->args) == 3) { - Core\Config::set($this->getArgument(0), $this->getArgument(1), $this->getArgument(2)); - $this->out("config[{$this->getArgument(0)}][{$this->getArgument(1)}] = " . Core\Config::get($this->getArgument(0), - $this->getArgument(1))); + $result = Core\Config::set($this->getArgument(0), $this->getArgument(1), $this->getArgument(2)); + if ($result) { + $this->out("{$this->getArgument(0)}.{$this->getArgument(1)} = " . + Core\Config::get($this->getArgument(0), $this->getArgument(1))); + } else { + $this->out("Unable to set {$this->getArgument(0)}.{$this->getArgument(1)}"); + } } if (count($this->args) == 2) { - $this->out("config[{$this->getArgument(0)}][{$this->getArgument(1)}] = " . Core\Config::get($this->getArgument(0), - $this->getArgument(1))); + $this->out("{$this->getArgument(0)}.{$this->getArgument(1)} = " . + Core\Config::get($this->getArgument(0), $this->getArgument(1))); } if (count($this->args) == 1) { Core\Config::load($this->getArgument(0)); - $a = get_app(); if (!is_null($a->config[$this->getArgument(0)])) { foreach ($a->config[$this->getArgument(0)] as $k => $x) { - $this->out("config[{$this->getArgument(0)}][{$k}] = " . $x); + $this->out("{$this->getArgument(0)}.{$k} = " . $x); } } else { $this->out('Config section ' . $this->getArgument(0) . ' returned nothing'); @@ -121,13 +124,29 @@ HELP; } if (count($this->args) == 0) { - $configs = dba::select('config'); - foreach ($configs as $config) { - $this->out("config[{$config['cat']}][{$config['k']}] = " . $config['v']); + Core\Config::load(); + + if (Core\Config::get('system', 'config_adapter') != 'preload' && $a->mode !== \Friendica\App::MODE_INSTALL) { + $this->out('Warning: The JIT (Just In Time) Config adapter doesn\'t support loading the entire configuration, showing file config only'); + } + + foreach ($a->config as $cat => $section) { + if (is_array($section)) { + foreach ($section as $key => $value) { + if (is_array($value)) { + foreach ($value as $k => $v) { + $this->out("{$cat}.{$key}[{$k}] = " . $v); + } + } else { + $this->out("{$cat}.{$key} = " . $value); + } + } + } else { + $this->out("config.{$cat} = " . $section); + } } } return 0; } - } From 0448ca38973fed14840d33079989fd71af93708b Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 25 Jun 2018 21:00:58 -0400 Subject: [PATCH 12/81] Update install procedure - Fix Notice messages in Core\Install and Database\DBStructure - Move local config file template from htconfig.tpl to local.ini.tpl - Remove htconfig.php --- htconfig.php | 114 --------------------------------- mod/install.php | 7 +-- src/Core/Install.php | 7 +-- view/templates/htconfig.tpl | 118 ----------------------------------- view/templates/local.ini.tpl | 12 ---- 5 files changed, 5 insertions(+), 253 deletions(-) delete mode 100644 htconfig.php delete mode 100644 view/templates/htconfig.tpl diff --git a/htconfig.php b/htconfig.php deleted file mode 100644 index 87c1301abd..0000000000 --- a/htconfig.php +++ /dev/null @@ -1,114 +0,0 @@ -config['system']['db_charset'] = "utf8mb4"; - -// Choose a legal default timezone. If you are unsure, use "America/Los_Angeles". -// It can be changed later and only applies to timestamps for anonymous viewers. - -$default_timezone = 'America/Los_Angeles'; - -// Default system language - -$a->config['system']['language'] = 'en'; - -// What is your site name? - -$a->config['sitename'] = "Friendica Social Network"; - -// Your choices are REGISTER_OPEN, REGISTER_APPROVE, or REGISTER_CLOSED. -// Be certain to create your own personal account before setting -// REGISTER_CLOSED. 'register_text' (if set) will be displayed prominently on -// the registration page. REGISTER_APPROVE requires you set 'admin_email' -// to the email address of an already registered person who can authorise -// and/or approve/deny the request. - -// In order to perform system administration via the admin panel, admin_email -// must precisely match the email address of the person logged in. - -$a->config['register_policy'] = REGISTER_OPEN; -$a->config['register_text'] = ''; -$a->config['admin_email'] = ''; - -// Maximum size of an imported message, 0 is unlimited - -$a->config['max_import_size'] = 200000; - -// maximum size of uploaded photos - -$a->config['system']['maximagesize'] = 800000; - -// Location of PHP command line processor - -$a->config['php_path'] = 'php'; - -// Server-to-server private message encryption (RINO) is allowed by default. -// set to 0 to disable, 1 to enable - -$a->config['system']['rino_encrypt'] = 1; - -// allowed themes (change this from admin panel after installation) - -$a->config['system']['allowed_themes'] = 'quattro,vier,duepuntozero,smoothly'; - -// default system theme - -$a->config['system']['theme'] = 'vier'; - - -// By default allow pseudonyms - -$a->config['system']['no_regfullname'] = true; - -//Deny public access to the local directory -//$a->config['system']['block_local_dir'] = false; - -// Location of the global directory -$a->config['system']['directory'] = 'https://dir.friendica.social'; - -// Allowed protocols in link URLs; HTTP protocols always are accepted -$a->config['system']['allowed_link_protocols'] = ['ftp', 'ftps', 'mailto', 'cid', 'gopher']; - -// Authentication cookie lifetime, in days -$a->config['system']['auth_cookie_lifetime'] = 7; diff --git a/mod/install.php b/mod/install.php index 79a5c40a3f..6962ff2dda 100644 --- a/mod/install.php +++ b/mod/install.php @@ -67,12 +67,11 @@ function install_post(App $a) { $timezone = notags(trim($_POST['timezone'])); $language = notags(trim($_POST['language'])); $adminmail = notags(trim($_POST['adminmail'])); - $rino = 1; // connect to db dba::connect($dbhost, $dbuser, $dbpass, $dbdata); - Install::install($urlpath, $dbhost, $dbuser, $dbpass, $dbdata, $phpath, $timezone, $language, $adminmail, $rino); + Install::install($urlpath, $dbhost, $dbuser, $dbpass, $dbdata, $phpath, $timezone, $language, $adminmail); return; break; @@ -140,9 +139,7 @@ function install_content(App $a) { switch ($install_wizard_pass) { case 1: { // System check - if (x($_POST, 'phpath')) { - $phpath = notags(trim($_POST['phpath'])); - } + $phpath = defaults($_POST, 'phpath', 'php'); list($checks, $checkspassed) = Install::check($phpath); diff --git a/src/Core/Install.php b/src/Core/Install.php index 663195e104..d6ef52df93 100644 --- a/src/Core/Install.php +++ b/src/Core/Install.php @@ -54,7 +54,7 @@ class Install extends BaseObject $checkspassed = array_reduce($checks, function ($v, $c) { - if ($c['require']) { + if (!empty($c['require'])) { $v = $v && $c['status']; } return $v; @@ -80,7 +80,7 @@ class Install extends BaseObject * @param string $adminmail Mail-Adress of the administrator * @param int $rino Rino-enabled (1 = true, 0 = false) */ - public static function install($urlpath, $dbhost, $dbuser, $dbpass, $dbdata, $phpath, $timezone, $language, $adminmail, $rino = 1) + public static function install($urlpath, $dbhost, $dbuser, $dbpass, $dbdata, $phpath, $timezone, $language, $adminmail) { $tpl = get_markup_template('local.ini.tpl'); $txt = replace_macros($tpl,[ @@ -93,7 +93,6 @@ class Install extends BaseObject '$urlpath' => $urlpath, '$phpath' => $phpath, '$adminmail' => $adminmail, - '$rino' => $rino ]); $result = file_put_contents('config/local.ini.php', $txt); @@ -376,7 +375,7 @@ class Install extends BaseObject $error_msg = []; $error_msg['head'] = L10n::t('Error message from Curl when fetching'); $error_msg['url'] = $test['redirect_url']; - $error_msg['msg'] = $test['error']; + $error_msg['msg'] = defaults($test, 'error', ''); } self::addCheck($checks, L10n::t('Url rewrite is working'), $status, true, $help, $error_msg); } else { diff --git a/view/templates/htconfig.tpl b/view/templates/htconfig.tpl deleted file mode 100644 index dc2d4bcdab..0000000000 --- a/view/templates/htconfig.tpl +++ /dev/null @@ -1,118 +0,0 @@ -config['system']['db_charset'] = "utf8mb4"; - -// email adress for the system admin - -$a->config['admin_email'] = '{{$adminmail}}'; - -// Location of PHP command line processor - -$a->config['php_path'] = '{{$phpath}}'; - -// If you are using a subdirectory of your domain you will need to put the -// relative path (from the root of your domain) here. -// For instance if your URL is 'http://example.com/directory/subdirectory', -// set path to 'directory/subdirectory'. - -$a->path = '{{$urlpath}}'; - -// Allowed protocols in link URLs; HTTP protocols always are accepted -$a->config['system']['allowed_link_protocols'] = array('ftp', 'ftps', 'mailto', 'cid', 'gopher'); - -/* ********************************************************************* - * The configuration below will be overruled by the admin panel. - * Changes made below will only have an effect if the database does - * not contain any configuration for the friendica system. - * *********************************************************************/ - -// Choose a legal default timezone. If you are unsure, use "America/Los_Angeles". -// It can be changed later and only applies to timestamps for anonymous viewers. - -$default_timezone = '{{$timezone}}'; - -// Default system language - -$a->config['system']['language'] = '{{$language}}'; - -// What is your site name? - -$a->config['sitename'] = "My Friend Network"; - -// Your choices are REGISTER_OPEN, REGISTER_APPROVE, or REGISTER_CLOSED. -// Be certain to create your own personal account before setting -// REGISTER_CLOSED. 'register_text' (if set) will be displayed prominently on -// the registration page. REGISTER_APPROVE requires you set 'admin_email' -// to the email address of an already registered person who can authorise -// and/or approve/deny the request. - -$a->config['register_policy'] = REGISTER_OPEN; -$a->config['register_text'] = ''; - -// Maximum size of an imported message, 0 is unlimited - -$a->config['max_import_size'] = 200000; - -// maximum size of uploaded photos - -$a->config['system']['maximagesize'] = 800000; - -// Server-to-server private message encryption (RINO) is allowed by default. -// set to 0 to disable, 1 to enable - -$a->config['system']['rino_encrypt'] = {{$rino}}; - -// default system theme - -$a->config['system']['theme'] = 'vier'; -$a->config['system']['allowed_themes'] = 'vier,quattro,duepuntozero,smoothly,frio'; - -// By default allow pseudonyms - -$a->config['system']['no_regfullname'] = true; - -//Deny public access to the local directory -//$a->config['system']['block_local_dir'] = false; - -// Location of the global directory -$a->config['system']['directory'] = 'https://dir.friendica.social'; - -// Authentication cookie lifetime, in days -$a->config['system']['auth_cookie_lifetime'] = 7; diff --git a/view/templates/local.ini.tpl b/view/templates/local.ini.tpl index 1b91fec88f..632b34e5a7 100644 --- a/view/templates/local.ini.tpl +++ b/view/templates/local.ini.tpl @@ -1,15 +1,5 @@ Date: Wed, 27 Jun 2018 23:05:01 -0400 Subject: [PATCH 13/81] Updated configuration files - Added system.account_abandon_days and system.addon to defaults.ini.php - Fixed database section key names in local-sample.ini.php --- config/defaults.ini.php | 15 ++++++++++++++- config/local-sample.ini.php | 8 ++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/config/defaults.ini.php b/config/defaults.ini.php index ffc3c495de..fac979c005 100644 --- a/config/defaults.ini.php +++ b/config/defaults.ini.php @@ -4,6 +4,7 @@ ; Please don't edit this file as its content may change in the upcoming versions. [jabber] + ; debug (Boolean) ; Enable debug level for the jabber account synchronisation. debug = false @@ -13,6 +14,7 @@ debug = false lockpath = [database] + ; host (String) ; Hostname or IP address of the database server. ; Can contain the port number with the syntax "hostname:port". @@ -64,6 +66,16 @@ register_text = '' sitename = "Friendica Social Network" [system] + +; account_abandon_days (Integer) +; Will not waste system resources polling external sites for abandonded accounts. +; Enter 0 for no time limit. +account_abandon_days = 0 + +; addon (Comma-separated list) +; Manual list of addons which are enabled on this system. +addon = + ; allowed_link_protocols (Array) ; Allowed protocols in links URLs, add at your own risk. http is always allowed. allowed_link_protocols[] = ftp @@ -189,7 +201,8 @@ invitation_only = false jpeg_quality = 100 ; language (String) -; Default system language. Two-letters ISO 639-1 code. +; Admin-created user default language. +; Two-letters ISO 639-1 code. language = en ; like_no_comment (Boolean) diff --git a/config/local-sample.ini.php b/config/local-sample.ini.php index 6afbf121ea..0e46f22f91 100644 --- a/config/local-sample.ini.php +++ b/config/local-sample.ini.php @@ -11,10 +11,10 @@ ; Then set the following for your MySQL installation [database] -host = localhost -user = mysqlusername -pass = mysqlpassword -data = mysqldatabasename +hostname = localhost +username = mysqlusername +password = mysqlpassword +database = mysqldatabasename charset = utf8mb4 From 2e2930d770e9de39e14c8172fc8875041bcc00fd Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 27 Jun 2018 23:05:38 -0400 Subject: [PATCH 14/81] Add addon config hook --- index.php | 4 ---- mod/admin.php | 6 +++++ src/App.php | 66 +++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 67 insertions(+), 9 deletions(-) diff --git a/index.php b/index.php index 16597fa62e..3a2067471e 100644 --- a/index.php +++ b/index.php @@ -36,10 +36,6 @@ $a->backend = false; require_once "include/dba.php"; if (!$a->mode == App::MODE_INSTALL) { - if (!dba::connected()) { - System::unavailable(); - } - /** * Load configs from db. Overwrite configs from config/local.ini.php */ diff --git a/mod/admin.php b/mod/admin.php index b308a2049b..d431fac2a2 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -845,6 +845,12 @@ function admin_page_summary(App $a) $warningtext[] = L10n::t('The last worker execution was on %s UTC. This is older than one hour. Please check your crontab settings.', $last_worker_call); } + // Legacy config file warning + if (file_exists('.htconfig.php')) { + $showwarning = true; + $warningtext[] = L10n::t('Friencia\'s configuration now is stored in config/local.ini.php, please copy config/local-sample.ini.php and move your config from .htconfig.php.'); + } + $r = q("SELECT `page-flags`, COUNT(`uid`) AS `count` FROM `user` GROUP BY `page-flags`"); $accounts = [ [L10n::t('Normal Account'), 0], diff --git a/src/App.php b/src/App.php index 17cfd3eefc..d35b497c2a 100644 --- a/src/App.php +++ b/src/App.php @@ -151,6 +151,12 @@ class App $this->determineMode(); + if ($this->mode === self::MODE_NORMAL) { + Core\Addon::loadHooks(); + + $this->loadAddonConfig(); + } + $this->loadDefaultTimezone(); $this->performance['start'] = microtime(true); @@ -295,6 +301,12 @@ class App $this->register_template_engine('Friendica\Render\FriendicaSmartyEngine'); } + /** + * Load the configuration files + * + * First loads the default value for all the configuration keys, then the legacy configuration files, then the + * expected local.ini.php + */ private function loadConfigFiles() { $this->loadConfigFile($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'defaults.ini.php'); @@ -328,6 +340,23 @@ class App } } + /** + * Tries to load the specified configuration file into the App->config array. + * Overwrites previously set values. + * + * The config format is INI and the template for configuration files is the following: + * + * getConfigValue('system', 'default_timezone')) { @@ -375,8 +417,7 @@ class App } /** - * Figure out if we are running at the top of a domain - * or in a sub-directory and adjust accordingly + * Figure out if we are running at the top of a domain or in a sub-directory and adjust accordingly */ private function determineUrlPath() { @@ -396,16 +437,31 @@ class App } } + /** + * Sets the App mode + * + * - App::MODE_INSTALL : Either the database connection can't be established or the config table doesn't exist + * - App::MODE_MAINTENANCE: The maintenance mode has been set + * - App::MODE_NORMAL : Normal run with all features enabled + * + * @return type + */ private function determineMode() { $this->mode = App::MODE_INSTALL; - // Missing DB connection - if (!\dba::connected()) { + // Missing local config files: MODE_INSTALL + if (!file_exists($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php') + && !file_exists($this->basepath . DIRECTORY_SEPARATOR . '.htconfig.php')) { return; } - // Working DB connection, missing tables + // Missing DB connection: ERROR + if (!\dba::connected()) { + System::unavailable(); + } + + // Working DB connection, missing tables: MODE_INSTALL if (\dba::fetch_first("SHOW TABLES LIKE 'config'") === false) { return; } From 3fc21f0d64b229043e6d76750083a82d22237f23 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 27 Jun 2018 23:06:23 -0400 Subject: [PATCH 15/81] Fix config mentions (no doc) --- bin/dev/friendica-to-smarty-tpl.py | 6 +++--- src/Core/Console/AutomaticInstallation.php | 2 +- src/Core/Install.php | 4 ++-- util/Doxyfile | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bin/dev/friendica-to-smarty-tpl.py b/bin/dev/friendica-to-smarty-tpl.py index 8149051cae..017b8b77ae 100755 --- a/bin/dev/friendica-to-smarty-tpl.py +++ b/bin/dev/friendica-to-smarty-tpl.py @@ -83,7 +83,7 @@ def fix_element(element): element += ldelim + parts[first+1].rstrip('}') + rdelim else: # This takes care of elements where the filename is a path, e.g. {{ inc file.tpl }} - element += parts[first+1].rstrip('}') + element += parts[first+1].rstrip('}') element += '"' @@ -205,7 +205,7 @@ try: except getopt.GetoptError: help(sys.argv[0]) sys.exit(2) - + if path == '': path = raw_input('Path to template folder to convert: ') @@ -220,7 +220,7 @@ if not os.path.exists(outpath): files = os.listdir(path) for a_file in files: - if a_file == 'htconfig.tpl': + if a_file == 'local.ini.tpl': php_tpl = True else: php_tpl = False diff --git a/src/Core/Console/AutomaticInstallation.php b/src/Core/Console/AutomaticInstallation.php index e0eea1f507..dbc36190ef 100644 --- a/src/Core/Console/AutomaticInstallation.php +++ b/src/Core/Console/AutomaticInstallation.php @@ -121,7 +121,7 @@ HELP; Install::checkFunctions($checks); Install::checkImagick($checks); - Install::checkHtConfig($checks); + Install::checkLocalIni($checks); Install::checkSmarty3($checks); Install::checkKeys($checks); diff --git a/src/Core/Install.php b/src/Core/Install.php index d6ef52df93..ec33ef9634 100644 --- a/src/Core/Install.php +++ b/src/Core/Install.php @@ -42,7 +42,7 @@ class Install extends BaseObject self::checkImagick($checks); - self::checkHtConfig($checks); + self::checkLocalIni($checks); self::checkSmarty3($checks); @@ -308,7 +308,7 @@ class Install extends BaseObject * * @param array $checks The list of all checks (by-ref parameter!) */ - public static function checkHtConfig(&$checks) + public static function checkLocalIni(&$checks) { $status = true; $help = ""; diff --git a/util/Doxyfile b/util/Doxyfile index 373d172558..aef2307927 100644 --- a/util/Doxyfile +++ b/util/Doxyfile @@ -2,8 +2,8 @@ INPUT = README.md index.php boot.php testargs.php update.php mod/ object/ includ RECURSIVE = YES PROJECT_NAME = "Friendica" PROJECT_LOGO = images/friendica-64.jpg -EXCLUDE = .htconfig.php library/ doc/ .git/ log/ util/zotsh/easywebdav/ addon/ report/ privacy_image_cache/ photo/ proxy/ local/ -EXCLUDE_PATTERNS = *smarty3* *strings.php*.log *.out *test* +EXCLUDE = .htconfig.php config/ library/ doc/ .git/ log/ util/zotsh/easywebdav/ addon/ report/ privacy_image_cache/ photo/ proxy/ local/ +EXCLUDE_PATTERNS = *smarty3* *strings.php*.log *.out *test* OUTPUT_DIRECTORY = doc GENERATE_HTML = YES HTML_OUTPUT = html/ From 02cabef99d9fabcfbc7e6cd7653503d381b6f259 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 27 Jun 2018 23:07:38 -0400 Subject: [PATCH 16/81] Move doc/htconfig.md to doc/Config.md - Updated all .htconfig.php references in other documentation pages - Added migration part --- doc/{htconfig.md => Config.md} | 227 ++++++++++++++++++++++++++++---- doc/FAQ.md | 4 +- doc/Home.md | 2 +- doc/Install.md | 10 +- doc/Installing-Connectors.md | 17 +-- doc/Settings.md | 17 ++- doc/Update.md | 2 +- doc/Vagrant.md | 4 +- doc/de/FAQ.md | 14 +- doc/de/Home.md | 2 +- doc/de/Install.md | 16 +-- doc/de/Installing-Connectors.md | 33 ++--- doc/de/Settings.md | 95 ++++++------- 13 files changed, 315 insertions(+), 128 deletions(-) rename doc/{htconfig.md => Config.md} (72%) diff --git a/doc/htconfig.md b/doc/Config.md similarity index 72% rename from doc/htconfig.md rename to doc/Config.md index a2ce91d4dc..2ffc0bf7e6 100644 --- a/doc/htconfig.md +++ b/doc/Config.md @@ -1,8 +1,198 @@ -Config values that can only be set in .htconfig.php -=================================================== +Friendica Configuration +======================= * [Home](help) +Friendica's configuration is done in two places: in INI configuration files and in the `config` database table. +Database config values overwrite the same file config values. + +# File configuration + +The configuration format for file configuration is an INI string returned from a PHP file. +This prevents your webserver from displaying your private configuration it interprets the configuration files and displays nothing. + +A typical configuration file looks like this: + +```php + +table.config { + margin: 1em 0; + background-color: #f9f9f9; + border: 1px solid #aaa; + border-collapse: collapse; + color: #000; + width: 100%; +} + +table.config > tr > th, +table.config > tr > td, +table.config > * > tr > th, +table.config > * > tr > td { + border: 1px solid #aaa; + padding: 0.2em 0.4em +} + +table.config > tr > th, +table.config > * > tr > th { + background-color: #f2f2f2; + text-align: center; + width: 50% +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
.htconfig.phpconfig/local.ini.php
+$db_host = 'localhost';
+$db_user = 'mysqlusername';
+$db_pass = 'mysqlpassword';
+$db_data = 'mysqldatabasename';
+$a->config["system"]["db_charset"] = 'utf8mb4';
+
+[database]
+hostname = localhost
+username = mysqlusername
+password = mysqlpassword
+database = mysqldatabasename
+charset = utf8mb4
+
+$a->config["section"]["key"] = "value";
+
+[section]
+key = value
+
+$a->config["section"]["key"] = array(
+	"value1",
+	"value2",
+	"value3"
+);
+
+[section]
+key[] = value1
+key[] = value2
+key[] = value3
+
+$a->config["key"] = "value";
+
+[config]
+key = value
+
+$a->path = "value";
+
+[system]
+urlpath = value
+
+$default_timezone = "value";
+
+[system]
+default_timezone = value
+
+$pidfile = "value";
+
+[system]
+pidfile = value
+
+$lang = "value";
+
+No equivalent (yet)
+
+ + +## Database Settings + +The configuration variables database.hostname, database.username, database.password, database.database and database.charset are holding your credentials for the database connection. +If you need to specify a port to access the database, you can do so by appending ":portnumber" to the database.hostname variable. + + [database] + hostname = your.mysqlhost.com:123456 + +If all of the following environment variables are set, Friendica will use them instead of the previously configured variables for the db: + + MYSQL_HOST + MYSQL_PORT + MYSQL_USERNAME + MYSQL_PASSWORD + MYSQL_DATABASE + + + +# Config values that can only be set in config/local.ini.php + There are some config values that haven't found their way into the administration page. This has several reasons. Maybe they are part of a current development that isn't considered stable and will be added later in the administration page when it is considered safe. @@ -13,9 +203,10 @@ Or it is for testing purposes only. Especially don't do that with undocumented values. The header of the section describes the category, the value is the parameter. -Example: To set the automatic database cleanup process add this line to your .htconfig.php: +Example: To set the automatic database cleanup process add this line to your config/local.ini.php: - $a->config['system']['always_show_preview'] = true; + [system] + always_show_preview = true ## jabber ## * **debug** (Boolean) - Enable debug level for the jabber account synchronisation. @@ -111,28 +302,16 @@ Example: To set the automatic database cleanup process add this line to your .ht Enabling the admin panel for an account, and thus making the account holder admin of the node, is done by setting the variable - $a->config['admin_email'] = "someone@example.com"; + [config] + admin_email = someone@example.com -Where you have to match the email address used for the account with the one you enter to the .htconfig file. -If more then one account should be able to access the admin panel, seperate the email addresses with a comma. +Where you have to match the email address used for the account with the one you enter to the config/local.ini.php file. +If more then one account should be able to access the admin panel, separate the email addresses with a comma. - $a->config['admin_email'] = "someone@example.com,someonelese@example.com"; + [config] + admin_email = someone@example.com,someoneelse@example.com If you want to have a more personalized closing line for the notification emails you can set a variable for the admin_name. - $a->config['admin_name'] = "Marvin"; - -## Database Settings - -The configuration variables db_host, db_user, db_pass and db_data are holding your credentials for the database connection. -If you need to specify a port to access the database, you can do so by appending ":portnumber" to the db_host variable. - - $db_host = 'your.mysqlhost.com:123456'; - -If all of the following environment variables are set, Friendica will use them instead of the previously configured variables for the db: - - MYSQL_HOST - MYSQL_PORT - MYSQL_USERNAME - MYSQL_PASSWORD - MYSQL_DATABASE + [config] + admin_name = Marvin diff --git a/doc/FAQ.md b/doc/FAQ.md index 31d980a9a1..1b84b5cd80 100644 --- a/doc/FAQ.md +++ b/doc/FAQ.md @@ -197,14 +197,14 @@ If you are searching for new themes, you can find them at [Friendica-Themes.com] ### I've changed my email address now the admin panel is gone? -Have a look into your .htconfig.php and fix your email address there. +Have a look into your config/local.ini.php and fix your email address there. ### Can there be more then one admin for a node? Yes. You just have to list more then one email address in the -.htconfig.php file. +config/local.ini.php file. The listed emails need to be separated by a comma. diff --git a/doc/Home.md b/doc/Home.md index 0a41a46146..a353bab0d3 100644 --- a/doc/Home.md +++ b/doc/Home.md @@ -32,7 +32,7 @@ Friendica Documentation and Resources * [Installing Connectors (Twitter/GNU Social)](help/Installing-Connectors) * [Install an ejabberd server (XMPP chat) with synchronized credentials](help/install-ejabberd) * [Using SSL with Friendica](help/SSL) -* [Config values that can only be set in .htconfig.php](help/htconfig) +* [Config values that can only be set in config/local.ini.php](help/Config) * [Improve Performance](help/Improve-Performance) * [Administration Tools](help/tools) diff --git a/doc/Install.md b/doc/Install.md index 3574780961..154a321174 100644 --- a/doc/Install.md +++ b/doc/Install.md @@ -100,19 +100,19 @@ If you need to specify a port for the connection to the database, you can do so *If* the manual installation fails for any reason, check the following: -* Does ".htconfig.php" exist? If not, edit htconfig.php and change the system settings. Rename to .htconfig.php +* Does "config/local.ini.php" exist? If not, edit config/local-sample.ini.php and change the system settings. Rename to config/local.ini.php * Is the database is populated? If not, import the contents of "database.sql" with phpmyadmin or the mysql command line. At this point visit your website again, and register your personal account. Registration errors should all be recoverable automatically. If you get any *critical* failure at this point, it generally indicates the database was not installed correctly. -You might wish to move/rename .htconfig.php to another name and empty (called 'dropping') the database tables, so that you can start fresh. +You might wish to move/rename config/local.ini.php to another name and empty (called 'dropping') the database tables, so that you can start fresh. ### Option B: Run the automatic install script Open the file htconfig.php in the main Friendica directory with a text editor. Remove the `die('...');` line and edit the lines to suit your installation (MySQL, language, theme etc.). -Then save the file (do not rename it). +Then save the file (do not rename it). Navigate to the main Friendica directory and execute the following command: @@ -126,7 +126,7 @@ At this point visit your website again, and register your personal account. *If* the automatic installation fails for any reason, check the following: -* Does ".htconfig.php" already exist? If yes, the automatic installation won't start +* Does "config/local.ini.php" already exist? If yes, the automatic installation won't start * Are the settings inside "htconfig.php" correct? If not, edit the file again. * Is the empty MySQL-database created? If not, create it. @@ -162,5 +162,5 @@ Bad things will happen. Let there be a hardware failure, a corrupted database or whatever you can think of. So once the installation of your Friendica node is done, you should make yourself a backup plan. -The most important file is the `.htconfig.php` file in the base directory. +The most important file is the `config/local.ini.php` file in the base directory. As it stores all your data, you should also have a recent dump of your Friendica database at hand, should you have to recover your node. diff --git a/doc/Installing-Connectors.md b/doc/Installing-Connectors.md index 5ea34d4733..6ad140fa90 100644 --- a/doc/Installing-Connectors.md +++ b/doc/Installing-Connectors.md @@ -4,7 +4,7 @@ Installing Connectors (Twitter/GNU Social) * [Home](help) -Friendica uses addons to provide connectivity to some networks, such as Twitter or App.net. +Friendica uses addons to provide connectivity to some networks, such as Twitter or App.net. There is also a addon to post through to an existing account on a GNU Social service. You only need this to post to an already existing GNU Social account, but not to communicate with GNU Social members in general. @@ -19,7 +19,7 @@ Addons must be installed by the site administrator before they can be used. This is accomplished through the site administration panel. Each of the connectors also requires an "API key" from the service you wish to connect with. -Some addons allow you to enter this information in the site administration pages, while others may require you to edit your configuration file (.htconfig.php). +Some addons allow you to enter this information in the site administration pages, while others may require you to edit your configuration file (config/local.ini.php). The ways to obtain these keys vary between the services, but they all require an existing account on the target service. Once installed, these API keys can usually be shared by all site members. @@ -39,10 +39,11 @@ You can get it from [Twitter](https://twitter.com/apps). Register your Friendica site as "Client" application with "Read & Write" access. We do not need "Twitter as login". When you've registered the app you get a key pair with an OAuth Consumer key and a secret key for your application/site. -Add this key pair to your global .htconfig.php: +Add this key pair to your config/local.ini.php: - $a->config['twitter']['consumerkey'] = 'your consumer_key here'; - $a->config['twitter']['consumersecret'] = 'your consumer_secret here'; + [twitter] + consumerkey = your consumer_key here + consumersecret = your consumer_secret here After this, your users can configure their Twitter account settings from "Settings -> Connector Settings". @@ -67,8 +68,8 @@ When the addon is activated the user has to acquire the following in order to co To get the OAuth Consumer key pair the user has to -1 ask her Friendica admin if a pair already exists or -2 has to register the Friendica server as a client application on the GNU Social server. +1 ask her Friendica admin if a pair already exists or +2 has to register the Friendica server as a client application on the GNU Social server. This can be done from the account settings under "Settings -> Connections -> Register an OAuth client application -> Register a new application" on the GNU Social server. @@ -83,6 +84,6 @@ During the registration of the OAuth client remember the following: After the required credentials for the application are stored in the configuration you have to actually connect your Friendica account with GNU Social. This is done from the Settings -> Connector Settings page. Follow the Sign in with GNU Social button, allow access and then copy the security code into the box provided. -Friendica will then try to acquire the final OAuth credentials from the API. +Friendica will then try to acquire the final OAuth credentials from the API. If successful, the addon settings will allow you to select to post your public messages to your GNU Social account (have a look behind the little lock symbol beneath the status "editor" on your Home or Network pages). diff --git a/doc/Settings.md b/doc/Settings.md index 04a9b9699a..dda2a9a587 100644 --- a/doc/Settings.md +++ b/doc/Settings.md @@ -69,7 +69,7 @@ You can chose between the following modes: ##### Invitation based registry Additionally to the setting in the admin panel, you can devide if registrations are only possible using an invitation code or not. -To enable invitation based registration, you have to set the `invitation_only` setting in the [.htconfig.php](/help/htconfig) file. +To enable invitation based registration, you have to set the `invitation_only` setting in the [config/local.ini.php](/help/Config) file. If you want to use this method, the registration policy has to be set to either *open* or *requires approval*. #### Check Full Names @@ -325,7 +325,7 @@ You should set up some kind of [log rotation](https://en.wikipedia.org/wiki/Log_ **Known Issues**: The filename ``friendica.log`` can cause problems depending on your server configuration (see [issue 2209](https://github.com/friendica/friendica/issues/2209)). By default PHP warnings and error messages are supressed. -If you want to enable those, you have to activate them in the ``.htconfig.php`` file. +If you want to enable those, you have to activate them in the ``config/local.ini.php`` file. Use the following settings to redirect PHP errors to a file. Config: @@ -373,24 +373,27 @@ By default this will be the one account you create during the installation proce But you can expand the list of email addresses by any used email address you want. Registration of new accounts with a listed email address is not possible. - $a->config['admin_email'] = 'you@example.com, buddy@example.com'; + [config] + admin_email = you@example.com, buddy@example.com ## PHP Path Some of Friendicas processes are running in the background. For this you need to specify the path to the PHP binary to be used. - $a->config['php_path'] = '{{$phpath}}'; + [config] + php_path = {{$phpath}} ## Subdirectory configuration It is possible to install Friendica into a subdirectory of your webserver. -We strongly discurage you from doing so, as this will break federation to other networks (e.g. Diaspora, GNU Socia, Hubzilla) +We strongly discourage you from doing so, as this will break federation to other networks (e.g. Diaspora, GNU Socia, Hubzilla) Say you have a subdirectory for tests and put Friendica into a further subdirectory, the config would be: - $a->path = 'tests/friendica'; + [system] + urlpath = tests/friendica ## Other exceptions -Furthermore there are some experimental settings, you can read-up in the [Config values that can only be set in .htconfig.php](help/htconfig) section of the documentation. +Furthermore there are some experimental settings, you can read-up in the [Config values that can only be set in config/local.ini.php](help/Config) section of the documentation. diff --git a/doc/Update.md b/doc/Update.md index 9e9324da94..835dd3375d 100644 --- a/doc/Update.md +++ b/doc/Update.md @@ -7,7 +7,7 @@ Updating Friendica If you installed Friendica in the ``path/to/friendica`` folder: 1. Unpack the new Friendica archive in ``path/to/friendica_new``. -2. Copy ``.htconfig.php``, ``photo/`` and ``proxy/`` from ``path/to/friendica`` to ``path/to/friendica_new``. +2. Copy ``config/local.ini.php``, ``photo/`` and ``proxy/`` from ``path/to/friendica`` to ``path/to/friendica_new``. 3. Rename the ``path/to/friendica`` folder to ``path/to/friendica_old``. 4. Rename the ``path/to/friendica_new`` folder to ``path/to/friendica``. 5. Check your site. Note: it may go into maintenance mode to update the database schema. diff --git a/doc/Vagrant.md b/doc/Vagrant.md index a224ebafc2..6fd74240d9 100644 --- a/doc/Vagrant.md +++ b/doc/Vagrant.md @@ -42,7 +42,7 @@ This will not delete the virtual machine. 9. To ultimately delete the virtual machine run $> vagrant destroy - $> rm /vagrant/.htconfig.php + $> rm /vagrant/config/local.ini.php to make sure that you can start from scratch with another "vagrant up". @@ -53,6 +53,6 @@ You will then have the following accounts to login: * friendica1, password friendica1 * friendica2, password friendica2 and so on until friendica5 * friendica1 is connected to all others. friendica1 has two groups: group1 with friendica2 and friendica4, group2 with friendica3 and friendica5. - * friendica2 and friendica3 are conntected. friendica4 and friendica5 are connected. + * friendica2 and friendica3 are conntected. friendica4 and friendica5 are connected. For further documentation of vagrant, please see [the vagrant*docs*](https://docs.vagrantup.com/v2/). diff --git a/doc/de/FAQ.md b/doc/de/FAQ.md index b52aa3d396..6baa5c5f5e 100644 --- a/doc/de/FAQ.md +++ b/doc/de/FAQ.md @@ -85,9 +85,9 @@ Zum Konvertieren von Videos in das lizenfreie Videoformat WebM gibt es unter Win ### Ist es möglich, bei mehreren Profilen verschiedene Avatare (Nutzerbilder) zu haben? Ja. -Auf Deiner ["Profile verwalten/editieren"-Seite](../profiles) wählst Du zunächst das gewünschte Profil aus. -Anschließend siehst Du eine Seite mit allen Infos zu diesem Profil. -Klicke nun oben auf den Link "Profilbild ändern" und lade im nächsten Fenster ein Bild von Deinem PC hoch. +Auf Deiner ["Profile verwalten/editieren"-Seite](../profiles) wählst Du zunächst das gewünschte Profil aus. +Anschließend siehst Du eine Seite mit allen Infos zu diesem Profil. +Klicke nun oben auf den Link "Profilbild ändern" und lade im nächsten Fenster ein Bild von Deinem PC hoch. Um Deine privaten Daten zu schützen, wird in Beiträgen nur das Bild aus Deinem öffentlichen Profil angezeigt. @@ -180,7 +180,7 @@ Hier ist eine Liste von Clients bei denen dies möglich ist, bzw. die speziell f ### Wo finde ich Hilfe? -Wenn Du Probleme mit Deiner Friendica-Seite hast, dann kannst Du die Community in der [Friendica-Support-Gruppe](https://forum.friendi.ca/profile/helpers) oder im [deutschen Friendica-Support-Forum](http://toktan.org/profile/wiki) fragen oder Dir das [deutsche Wiki](http://wiki.toktan.org/doku.php) anschauen. +Wenn Du Probleme mit Deiner Friendica-Seite hast, dann kannst Du die Community in der [Friendica-Support-Gruppe](https://forum.friendi.ca/profile/helpers) oder im [deutschen Friendica-Support-Forum](http://toktan.org/profile/wiki) fragen oder Dir das [deutsche Wiki](http://wiki.toktan.org/doku.php) anschauen. Wenn Du Deinen Account nicht nutzen kannst, kannst Du entweder einen [Testaccount](https://tryfriendica.de) bzw. einen Account auf einer öffentlichen Seite ([Liste](https://dir.friendica.social/servers)) nutzen. Wenn du dir keinen weiteren Friendica Account einrichten willst, kannst du auch gerne über einen der folgenden alternativen Kanäle Hilfe suchen: @@ -199,7 +199,7 @@ Admin Ja, das ist möglich. Es ist allerdings nicht möglich, eine Datenbank durch zwei Domains zu nutzen. -Solange Du Deine .htconfig.php allerdings so einrichtest, dass das System nicht versucht, eine Installation durchzuführen, kannst Du die richtige Config-Datei in include/$hostname/.htconfig.php hinterlegen. +Solange Du Deine config/local.ini.php allerdings so einrichtest, dass das System nicht versucht, eine Installation durchzuführen, kannst Du die richtige Config-Datei in include/$hostname/config/local.ini.php hinterlegen. Alle Cache-Aspekte und der Zugriffsschutz können pro Instanz konfiguriert werden. @@ -216,13 +216,13 @@ Wenn Du neue Themen suchst, findest Du sie auf [Friendica-Themes.com](http://fri ### Ich habe meine E-Mail Adresse geändern und jetzt ist das Admin Panel verschwunden? -Bitte aktualisiere deine E-Mail Adresse in der .htconfig.php Datei. +Bitte aktualisiere deine E-Mail Adresse in der config/local.ini.php Datei. ### Kann es mehr als einen Admin auf einer Friendica Instanz geben? Ja. -Du kannst in der .htconfig.php Datei mehrere E-Mail Adressen auflisten. +Du kannst in der config/local.ini.php Datei mehrere E-Mail Adressen auflisten. Die aufgelisteten Adressen werden mit Kommata von einander getrennt. diff --git a/doc/de/Home.md b/doc/de/Home.md index 31cce7aea4..b6a07cc09a 100644 --- a/doc/de/Home.md +++ b/doc/de/Home.md @@ -34,7 +34,7 @@ Friendica - Dokumentation und Ressourcen * [Konnektoren (Connectors) installieren (Twitter/GNU Social)](help/Installing-Connectors) * [Installation eines ejabberd Servers (XMPP-Chat) mit synchronisierten Anmeldedaten](help/install-ejabberd) (EN) * [Betreibe deine Seite mit einem SSL-Zertifikat](help/SSL) -* [Konfigurationswerte, die nur in der .htconfig.php gesetzt werden können](help/htconfig) (EN) +* [Konfigurationswerte, die nur in der config/local.ini.php gesetzt werden können](help/Config) (EN) * [Performance verbessern](help/Improve-Performance) * [Administration Werkzeuge](help/tools) (EN) diff --git a/doc/de/Install.md b/doc/de/Install.md index f324da68e0..ef4ef8aadc 100644 --- a/doc/de/Install.md +++ b/doc/de/Install.md @@ -56,7 +56,7 @@ Stelle sicher, dass der Ordner *view/smarty3* existiert and von dem Webserver-Be mkdir view/smarty3 chmod 775 view/smarty3 -Falls Addons installiert werden sollen: Gehe in den Friendica-Ordner +Falls Addons installiert werden sollen: Gehe in den Friendica-Ordner cd mywebsite @@ -98,19 +98,19 @@ Starte MySQL dann neu und es sollte klappen. ### Option A: Der manuelle Installer -Besuche deine Webseite mit deinem Browser und befolge die Anleitung. +Besuche deine Webseite mit deinem Browser und befolge die Anleitung. Bitte beachte jeden Fehler und korrigiere diese, bevor du fortfährst. Falls du einen Port für die Datenbankverbindung angeben musst, kannst du diesen in der Host-Eingabe Zeile angeben. *Wenn* die manuelle Installation aus irgendeinem Grund fehlschlägt, dann prüfe das Folgende: -* ".htconfig.php" existiert ... wenn nicht, bearbeite die „htconfig.php“ und ändere die Systemeinstellungen. Benenne sie um in „.htconfig.php". +* "config/local.ini.php" existiert ... wenn nicht, bearbeite die „config/local-sample.ini.php“ und ändere die Systemeinstellungen. Benenne sie um in „config/local.ini.php". * die Datenbank beinhaltet Daten. ... wenn nicht, importiere den Inhalt der Datei "database.sql" mit phpmyadmin oder per mysql-Kommandozeile. Besuche deine Seite an diesem Punkt wieder und registriere deinen persönlichen Account. Alle Registrierungsprobleme sollten automatisch behebbar sein. Wenn du irgendwelche **kritischen** Fehler zu diesen Zeitpunkt erhalten solltest, deutet das darauf hin, dass die Datenbank nicht korrekt installiert wurde. -Du kannst bei Bedarf die Datei .htconfig.php verschieben/umbenennen und die Datenbank leeren (als „Dropping“ bezeichnet), so dass du mit einem sauberen System neu starten kannst. +Du kannst bei Bedarf die Datei config/local.ini.php verschieben/umbenennen und die Datenbank leeren (als „Dropping“ bezeichnet), so dass du mit einem sauberen System neu starten kannst. ### Option B: Starte das manuelle Installationsscript @@ -127,8 +127,8 @@ Oder falls du alle optionalen Checks ausfürehn lassen möchtest, benutze diese bin/console autoinstall -a *Wenn* die automatisierte Installation aus irgendeinem Grund fehlschlägt, dann prüfe das Folgende: -* Existiert die `.htconfig.php`? Falls ja, wird die automatisierte Installation nicht gestartet. -* Sind Einstellungen in der `.htconfig.php` korrekt? Falls nicht, bitte bearbeite diese Datei erneut. +* Existiert die `config/local.ini.php`? Falls ja, wird die automatisierte Installation nicht gestartet. +* Sind Einstellungen in der `config/local.ini.php` korrekt? Falls nicht, bitte bearbeite diese Datei erneut. * Ist die leere MySQL-Datenbank erstellt? Falls nicht, erstelle diese. Für mehr Informationen kannst du diese Option verwenden: @@ -137,7 +137,7 @@ Für mehr Informationen kannst du diese Option verwenden: ### Einen Worker einrichten -Erstelle einen Cron job oder einen regelmäßigen Task, um den Poller alle 5-10 Minuten im Hintergrund ablaufen zu lassen. +Erstelle einen Cron job oder einen regelmäßigen Task, um den Poller alle 5-10 Minuten im Hintergrund ablaufen zu lassen. Beispiel: cd /base/directory; /path/to/php bin/worker.php @@ -160,5 +160,5 @@ Es werden schlimme Dinge geschehen. Sei es nun ein Hardwareversagen oder eine kaputte Datenbank. Deshalb solltest du dir, nachdem die Installation deines Friendica Knotens abgeschlossen ist, einen Backup Plan erstellen. -Die wichtigste Datei ist die `.htconfig.php` im Stammverzeichnis deiner Friendica Installation. +Die wichtigste Datei ist die `config/local.ini.php` im Stammverzeichnis deiner Friendica Installation. Und da alle Daten in der Datenbank gespeichert werden, solltest du einen nicht all zu alten Dump der Friendica Datenbank zur Hand haben, solltest du deinen Knoten wieder herstellen müssen. diff --git a/doc/de/Installing-Connectors.md b/doc/de/Installing-Connectors.md index f9fe5b0f72..3fa46ab5a4 100644 --- a/doc/de/Installing-Connectors.md +++ b/doc/de/Installing-Connectors.md @@ -1,25 +1,25 @@ -Konnektoren installieren (Twitter/GNU Social) +Konnektoren installieren (Twitter/GNU Social) ================================================== * [Zur Startseite der Hilfe](help) Friendica nutzt Erweiterung, um die Verbindung zu anderen Netzwerken wie Twitter oder App.net zu gewährleisten. -Es gibt außerdem ein Erweiterung, um über einen bestehenden GNU Social-Account diesen Service zu nutzen. -Du brauchst dieses Erweiterung aber nicht, um mit GNU Social-Mitgliedern von Friendica aus zu kommunizieren - es sei denn, du wünschst es, über einen existierenden Account einen Beitrag zu schreiben. +Es gibt außerdem ein Erweiterung, um über einen bestehenden GNU Social-Account diesen Service zu nutzen. +Du brauchst dieses Erweiterung aber nicht, um mit GNU Social-Mitgliedern von Friendica aus zu kommunizieren - es sei denn, du wünschst es, über einen existierenden Account einen Beitrag zu schreiben. -Alle drei Erweiterung benötigen einen Account im gewünschten Netzwerk. +Alle drei Erweiterung benötigen einen Account im gewünschten Netzwerk. Zusätzlich musst du (bzw. der Administrator der Seite) einen API-Schlüssel holen, um einen authentifizierten Zugriff zu deinem Friendica-Server herstellen zu lassen. **Seitenkonfiguration** -Erweiterung müssen vom Administrator installiert werden, bevor sie genutzt werden können. +Erweiterung müssen vom Administrator installiert werden, bevor sie genutzt werden können. Dieses kann über das Administrationsmenü erstellt werden. -Jeder der Konnektoren benötigt zudem einen API-Schlüssel vom Service, der verbunden werden soll. -Einige Erweiterung erlaube es, diese Informationen auf den Administrationsseiten einzustellen, wohingegen andere eine direkte Bearbeitung der Konfigurationsdatei ".htconfig.php" erfordern. -Der Weg, um diese Schlüssel zu erhalten, variiert stark, jedoch brauchen fast alle einen bestehenden Account im gewünschten Service. +Jeder der Konnektoren benötigt zudem einen API-Schlüssel vom Service, der verbunden werden soll. +Einige Erweiterung erlaube es, diese Informationen auf den Administrationsseiten einzustellen, wohingegen andere eine direkte Bearbeitung der Konfigurationsdatei "config/local.ini.php" erfordern. +Der Weg, um diese Schlüssel zu erhalten, variiert stark, jedoch brauchen fast alle einen bestehenden Account im gewünschten Service. Einmal installiert, können diese Schlüssel von allen Seitennutzern genutzt werden. Im Folgenden findest du die Einstellungen für die verschiedenen Services (viele dieser Informationen kommen direkt aus den Quelldateien der Erweiterung): @@ -37,11 +37,12 @@ Um dieses Erweiterung zu nutzen, benötigst du einen OAuth Consumer-Schlüsselpa Registriere deine Friendica-Seite als "Client"-Anwendung mit "Read&Write"-Zugriff. Wir benötigen "Twitter als Login" nicht. Sobald du deine Anwendung installiert hast, erhältst du das Schlüsselpaar für deine Seite. -Trage dieses Schlüsselpaar in deine globale ".htconfig.php"-Datei ein. +Trage dieses Schlüsselpaar in deine globale "config/local.ini.php"-Datei ein. ``` -$a->config['twitter']['consumerkey'] = 'your consumer_key here'; -$a->config['twitter']['consumersecret'] = 'your consumer_secret here'; +[twitter] +consumerkey = your consumer_key here +consumersecret = your consumer_secret here ``` Anschließend kann der Nutzer deiner Seite die Twitter-Einstellungen selbst eintragen: "Einstellungen -> Connector Einstellungen". @@ -63,10 +64,10 @@ Wenn das Addon aktiv ist, muss der Nutzer die folgenden Einstellungen vornehmen, Um das OAuth-Schlüsselpaar zu erhalten, muss der Nutzer -(a) seinen Friendica-Admin fragen, ob bereits ein Schlüsselpaar existiert oder +(a) seinen Friendica-Admin fragen, ob bereits ein Schlüsselpaar existiert oder (b) einen Friendica-Server als Anwendung auf dem GNU Social-Server anmelden. -Dies kann über Einstellungen --> Connections --> "Register an OAuth client application" -> "Register a new application" auf dem GNU Social-Server durchgeführt werden. +Dies kann über Einstellungen --> Connections --> "Register an OAuth client application" -> "Register a new application" auf dem GNU Social-Server durchgeführt werden. Während der Registrierung des OAuth-Clients ist Folgendes zu beachten: @@ -76,9 +77,9 @@ Während der Registrierung des OAuth-Clients ist Folgendes zu beachten: * stelle Lese- und Schreibrechte ein * die Quell-URL sollte die URL deines Friendica-Servers sein -Sobald die benötigten Daten gespeichert sind, musst du deinen Friendica-Account mit GNU Social verbinden. -Das kannst du über Einstellungen --> Connector-Einstellungen durchführen. -Folge dem "Einloggen mit GNU Social"-Button, erlaube den Zugriff und kopiere den Sicherheitscode in die entsprechende Box. +Sobald die benötigten Daten gespeichert sind, musst du deinen Friendica-Account mit GNU Social verbinden. +Das kannst du über Einstellungen --> Connector-Einstellungen durchführen. +Folge dem "Einloggen mit GNU Social"-Button, erlaube den Zugriff und kopiere den Sicherheitscode in die entsprechende Box. Friendica wird dann versuchen, die abschließende OAuth-Einstellungen über die API zu beziehen. Wenn es geklappt hat, kannst du in den Einstellungen festlegen, ob deine öffentlichen Nachrichten automatisch in deinem GNU Social-Account erscheinen soll (achte hierbei auf das kleine Schloss-Symbol im Status-Editor) diff --git a/doc/de/Settings.md b/doc/de/Settings.md index 6365668729..4d84f873ff 100644 --- a/doc/de/Settings.md +++ b/doc/de/Settings.md @@ -8,8 +8,8 @@ Auf der Startseite des Admin Panels werden die Informationen zu der Instanz zusa Die erste Zahl gibt die Anzahl von Nachrichten an, die nicht zugestellt werden konnten. Die Zustellung wird zu einem späteren Zeitpunkt noch einmal versucht. Unter dem Punkt "Warteschlange Inspizieren" kannst du einen schnellen Blick auf die zweite Warteschlange werfen. -Die zweite Zahl steht für die Anzahl der Aufgaben, die die Worker noch vor sich haben. -Die Worker arbeiten Hintergrundprozesse ab. +Die zweite Zahl steht für die Anzahl der Aufgaben, die die Worker noch vor sich haben. +Die Worker arbeiten Hintergrundprozesse ab. Die Aufgaben der Worker sind priorisiert und werden anhand dieser Prioritäten abgearbeitet. Desweiteren findest du eine Übersicht über die Accounts auf dem Friendica Knoten, die unter dem Punkt "Nutzer" moderiert werden können. @@ -31,7 +31,7 @@ Da die meisten Konfigurationsoptionen einen Hilfstext im Admin Panel haben, kann #### Banner/Logo -Hiermit legst du das Banner der Seite fest. Standardmäßig ist das Friendica-Logo und der Name festgelegt. +Hiermit legst du das Banner der Seite fest. Standardmäßig ist das Friendica-Logo und der Name festgelegt. Du kannst hierfür HTML/CSS nutzen, um den Inhalt zu gestalten und/oder die Position zu ändern, wenn es nicht bereits voreingestellt ist. #### Systensprache @@ -63,33 +63,33 @@ Dabei kannst du zwischen den folgenden Optionen wählen: * **Bedarf der Zustimmung**: Jeder kann ein Nutzerkonto anlegen. Dieses muss allerdings durch den Admin freigeschaltet werden, bevor es verwendet werden kann. * **Geschlossen**: Es können keine weiteren Nutzerkonten angelegt werden. -##### Einladungen +##### Einladungen Zusätzlich zu den oben genannten Möglichkeiten, kann die Registrierung eines neuen Nutzerkontos an eine Einladung durch einen bestehenden Nutzer gekoppelt werden. -Hierzu muss in der [.htconfig.php](/help/htconfig) Datei die Option `invitation_only` aktiviert und als Registrierungsmethode entweder *Offen* oder *Bedarf der Zustimmung* gewählt werden. +Hierzu muss in der [config/local.ini.php](/help/Config) Datei die Option `invitation_only` aktiviert und als Registrierungsmethode entweder *Offen* oder *Bedarf der Zustimmung* gewählt werden. #### Namen auf Vollständigkeit überprüfen -Es kann vorkommen, dass viele Spammer versuchen, sich auf deiner Seite zu registrieren. -In Testphasen haben wir festgestellt, dass diese automatischen Registrierungen das Feld "Vollständiger Name" oft nur mit Namen ausfüllen, die kein Leerzeichen beinhalten. -Wenn du Leuten erlauben willst, sich nur mit einem Namen anzumelden, dann setze die Einstellung auf "true". +Es kann vorkommen, dass viele Spammer versuchen, sich auf deiner Seite zu registrieren. +In Testphasen haben wir festgestellt, dass diese automatischen Registrierungen das Feld "Vollständiger Name" oft nur mit Namen ausfüllen, die kein Leerzeichen beinhalten. +Wenn du Leuten erlauben willst, sich nur mit einem Namen anzumelden, dann setze die Einstellung auf "true". Die Standardeinstellung ist auf "false" gesetzt. - + #### OpenID Unterstützung -Standardmäßig wird OpenID für die Registrierung und für Logins genutzt. +Standardmäßig wird OpenID für die Registrierung und für Logins genutzt. Wenn du nicht willst, dass OpenID-Strukturen für dein System übernommen werden, dann setze "no_openid" auf "true". Standardmäßig ist hier "false" gesetzt. #### Unterbinde Mehrfachregistrierung -Um mehrfache Seiten zu erstellen, muss sich eine Person mehrfach registrieren können. -Deine Seiteneinstellung kann Registrierungen komplett blockieren oder an Bedingungen knüpfen. -Standardmäßig können eingeloggte Nutzer weitere Accounts für die Seitenerstellung registrieren. -Hier ist weiterhin eine Bestätigung notwendig, wenn "REGISTER_APPROVE" ausgewählt ist. -Wenn du die Erstellung weiterer Accounts blockieren willst, dann setze die Einstellung "block_extended_register" auf "true". +Um mehrfache Seiten zu erstellen, muss sich eine Person mehrfach registrieren können. +Deine Seiteneinstellung kann Registrierungen komplett blockieren oder an Bedingungen knüpfen. +Standardmäßig können eingeloggte Nutzer weitere Accounts für die Seitenerstellung registrieren. +Hier ist weiterhin eine Bestätigung notwendig, wenn "REGISTER_APPROVE" ausgewählt ist. +Wenn du die Erstellung weiterer Accounts blockieren willst, dann setze die Einstellung "block_extended_register" auf "true". Standardmäßig ist hier "false" gesetzt. - + ### Datei hochladen #### Maximale Bildgröße @@ -100,26 +100,26 @@ Maximale Bild-Dateigröße in Byte. Standardmäßig ist 0 gesetzt, was bedeutet, #### URL des weltweiten Verzeichnisses -Mit diesem Befehl wird die URL eingestellt, die zum Update des globalen Verzeichnisses genutzt wird. -Dieser Befehl ist in der Standardkonfiguration enthalten. -Der nicht dokumentierte Teil dieser Einstellung ist, dass das globale Verzeichnis gar nicht verfügbar ist, wenn diese Einstellung nicht gesetzt wird. +Mit diesem Befehl wird die URL eingestellt, die zum Update des globalen Verzeichnisses genutzt wird. +Dieser Befehl ist in der Standardkonfiguration enthalten. +Der nicht dokumentierte Teil dieser Einstellung ist, dass das globale Verzeichnis gar nicht verfügbar ist, wenn diese Einstellung nicht gesetzt wird. Dies erlaubt eine private Kommunikation, die komplett vom globalen Verzeichnis isoliert ist. #### Erzwinge Veröffentlichung -Standardmäßig können Nutzer selbst auswählen, ob ihr Profil im Seitenverzeichnis erscheint. -Diese Einstellung zwingt alle Nutzer dazu, im Verzeichnis zu erscheinen. +Standardmäßig können Nutzer selbst auswählen, ob ihr Profil im Seitenverzeichnis erscheint. +Diese Einstellung zwingt alle Nutzer dazu, im Verzeichnis zu erscheinen. Diese Einstellung kann vom Nutzer nicht deaktiviert werden. Die Standardeinstellung steht auf "false". #### Öffentlichen Zugriff blockieren -Aktiviere diese Einstellung um den öffentlichen Zugriff auf alle Seiten zu sperren, solange man nicht eingeloggt ist. -Das blockiert die Ansicht von Profilen, Freunden, Fotos, vom Verzeichnis und den Suchseiten. -Ein Nebeneffekt ist, dass Einträge dieser Seite nicht im globalen Verzeichnis erscheinen. -Wir empfehlen, speziell diese Einstellung auszuschalten (die Einstellung ist an anderer Stelle auf dieser Seite erklärt). -Beachte: das ist speziell für Seiten, die beabsichtigen, von anderen Friendica-Netzwerken abgeschottet zu sein. -Unautorisierte Personen haben ebenfalls nicht die Möglichkeit, Freundschaftsanfragen von Seitennutzern zu beantworten. -Die Standardeinstellung ist deaktiviert. +Aktiviere diese Einstellung um den öffentlichen Zugriff auf alle Seiten zu sperren, solange man nicht eingeloggt ist. +Das blockiert die Ansicht von Profilen, Freunden, Fotos, vom Verzeichnis und den Suchseiten. +Ein Nebeneffekt ist, dass Einträge dieser Seite nicht im globalen Verzeichnis erscheinen. +Wir empfehlen, speziell diese Einstellung auszuschalten (die Einstellung ist an anderer Stelle auf dieser Seite erklärt). +Beachte: das ist speziell für Seiten, die beabsichtigen, von anderen Friendica-Netzwerken abgeschottet zu sein. +Unautorisierte Personen haben ebenfalls nicht die Möglichkeit, Freundschaftsanfragen von Seitennutzern zu beantworten. +Die Standardeinstellung ist deaktiviert. Verfügbar in Version 2.2 und höher. #### Für Besucher verfügbare Gemeinschaftsseiten @@ -133,15 +133,15 @@ Angemeldete Nutzer des Knotens können grundsätzlich beide Seiten verwenden. #### Erlaubte Domains für Kontakte -Kommagetrennte Liste von Domains, welche eine Freundschaft mit dieser Seite eingehen dürfen. +Kommagetrennte Liste von Domains, welche eine Freundschaft mit dieser Seite eingehen dürfen. Wildcards werden akzeptiert (Wildcard-Unterstützung unter Windows benötigt PHP5.3) Standardmäßig sind alle gültigen Domains erlaubt. Mit dieser Option kann man einfach geschlossene Netzwerke, z.B. im schulischen Bereich aufbauen, aus denen nicht mit dem Rest des Netzwerks kommuniziert werden soll. #### Erlaubte Domains für E-Mails -Kommagetrennte Liste von Domains, welche bei der Registrierung als Part der Email-Adresse erlaubt sind. -Das grenzt Leute aus, die nicht Teil der Gruppe oder Organisation sind. +Kommagetrennte Liste von Domains, welche bei der Registrierung als Part der Email-Adresse erlaubt sind. +Das grenzt Leute aus, die nicht Teil der Gruppe oder Organisation sind. Wildcards werden akzeptiert (Wildcard-Unterstützung unter Windows benötigt PHP5.3) Standardmäßig sind alle gültigen Email-Adressen erlaubt. #### Nutzern erlauben das remote_self Flag zu setzen @@ -172,23 +172,23 @@ Wenn deine Seite eine Proxy-Einstellung nutzt, musst du diese Einstellungen vorn #### Netzwerk Wartezeit -Legt fest, wie lange das Netzwerk warten soll, bevor ein Timeout eintritt. +Legt fest, wie lange das Netzwerk warten soll, bevor ein Timeout eintritt. Der Wert wird in Sekunden angegeben. Standardmäßig ist 60 eingestellt; 0 steht für "unbegrenzt" (nicht empfohlen). #### UTF-8 Reguläre Ausdrücke -Während der Registrierung werden die Namen daraufhin geprüft, ob sie reguläre UTF-8-Ausdrücke nutzen. -Hierfür wird PHP benötigt, um mit einer speziellen Einstellung kompiliert zu werden, die UTF-8-Ausdrücke benutzt. +Während der Registrierung werden die Namen daraufhin geprüft, ob sie reguläre UTF-8-Ausdrücke nutzen. +Hierfür wird PHP benötigt, um mit einer speziellen Einstellung kompiliert zu werden, die UTF-8-Ausdrücke benutzt. Wenn du absolut keine Möglichkeit hast, Accounts zu registrieren, setze diesen Wert auf ja. #### SSL Überprüfen -Standardmäßig erlaubt Friendica SSL-Kommunikation von Seiten, die "selbst unterzeichnete" SSL-Zertifikate nutzen. -Um eine weitreichende Kompatibilität mit anderen Netzwerken und Browsern zu gewährleisten, empfehlen wir, selbst unterzeichnete Zertifikate **nicht** zu nutzen. -Aber wir halten dich nicht davon ab, solche zu nutzen. SSL verschlüsselt alle Daten zwischen den Webseiten (und für deinen Browser), was dir eine komplett verschlüsselte Kommunikation erlaubt. -Auch schützt es deine Login-Daten vor Datendiebstahl. Selbst unterzeichnete Zertifikate können kostenlos erstellt werden. -Diese Zertifikate können allerdings Opfer eines sogenannten ["man-in-the-middle"-Angriffs](http://de.wikipedia.org/wiki/Man-in-the-middle-Angriff) werden, und sind daher weniger bevorzugt. -Wenn du es wünscht, kannst du eine strikte Zertifikatabfrage einstellen. +Standardmäßig erlaubt Friendica SSL-Kommunikation von Seiten, die "selbst unterzeichnete" SSL-Zertifikate nutzen. +Um eine weitreichende Kompatibilität mit anderen Netzwerken und Browsern zu gewährleisten, empfehlen wir, selbst unterzeichnete Zertifikate **nicht** zu nutzen. +Aber wir halten dich nicht davon ab, solche zu nutzen. SSL verschlüsselt alle Daten zwischen den Webseiten (und für deinen Browser), was dir eine komplett verschlüsselte Kommunikation erlaubt. +Auch schützt es deine Login-Daten vor Datendiebstahl. Selbst unterzeichnete Zertifikate können kostenlos erstellt werden. +Diese Zertifikate können allerdings Opfer eines sogenannten ["man-in-the-middle"-Angriffs](http://de.wikipedia.org/wiki/Man-in-the-middle-Angriff) werden, und sind daher weniger bevorzugt. +Wenn du es wünscht, kannst du eine strikte Zertifikatabfrage einstellen. Das führt dazu, dass du keinerlei Verbindung zu einer selbst unterzeichneten SSL-Seite erstellen kannst ### Automatisch ein Kontaktverzeichnis erstellen @@ -313,7 +313,7 @@ Du solltest deshalb einen Dienst zur [log rotation](https://en.wikipedia.org/wik **Bekannte Probleme**: Der Dateiname `friendica.log` kann bei speziellen Server Konfigurationen zu Problemen führen (siehe [issue 2209](https://github.com/friendica/friendica/issues/2209)). Normalerweise werden Fehler- und Warnmeldungen von PHP unterdrückt. -Wenn du sie aktivieren willst, musst du folgendes in der `.htconfig.php` Datei eintragen um die Meldungen in die Datei `php.out` zu speichern +Wenn du sie aktivieren willst, musst du folgendes in der `config/local.ini.php` Datei eintragen um die Meldungen in die Datei `php.out` zu speichern error_reporting(E_ERROR | E_WARNING | E_PARSE ); ini_set('error_log','php.out'); @@ -367,14 +367,16 @@ Normalerweise trifft dies auf den ersten Account zu, der nach der Installation a Die Liste der E-Mail Adressen kann aber einfach erweitert werden. Mit keiner der angegebenen E-Mail Adressen können weitere Accounts registriert werden. - $a->config['admin_email'] = 'you@example.com, buddy@example.com'; + [config] + admin_email = you@example.com, buddy@example.com ## PHP Pfad Einige Prozesse von Friendica laufen im Hintergrund. Für diese Prozesse muss der Pfad zu der PHP Version gesetzt sein, die verwendet werden soll. - $a->config['php_path'] = '/pfad/zur/php-version'; + [config] + php_path = {{$phpath}} ## Unterverzeichnis Konfiguration @@ -382,9 +384,10 @@ Man kann Friendica in ein Unterverzeichnis des Webservers installieren. Wir raten allerdings dringen davon ab, da es die Interoperabilität mit anderen Netzwerken (z.B. Diaspora, GNU Social, Hubzilla) verhindert. Mal angenommen, du hast ein Unterverzeichnis tests und willst Friendica in ein weiteres Unterverzeichnis installieren, dann lautet die Konfiguration hierfür: - $a->path = 'tests/friendica'; + [system] + urlpath = tests/friendica ## Weitere Ausnahmen -Es gibt noch einige experimentelle Einstellungen, die nur in der ``.htconfig.php`` Datei konfiguriert werden können. -Im [Konfigurationswerte, die nur in der .htconfig.php gesetzt werden können (EN)](help/htconfig) Artikel kannst du mehr darüber erfahren. +Es gibt noch einige experimentelle Einstellungen, die nur in der ``config/local.ini.php`` Datei konfiguriert werden können. +Im [Konfigurationswerte, die nur in der config/local.ini.php gesetzt werden können (EN)](help/Config) Artikel kannst du mehr darüber erfahren. From cce1a96bee91edad24faeead472ac8681e2ad50c Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 29 Jun 2018 00:25:43 -0400 Subject: [PATCH 17/81] Reorganize .gitignore - Delete duplicates - Add leading slash to /doc/html - Typo --- .gitignore | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index b75c19af19..c1eb430b4b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,13 +2,11 @@ favicon.* .htconfig.php .htpreconfig.php \#* -include/jquery-1.4.2.min.js *.log *.out *.version* -favicon.* home.html -addon + *~ robots.txt @@ -16,9 +14,9 @@ robots.txt /config/local.ini.php #ignore documentation, it should be newly built -doc/html +/doc/html -#ignore reports, should be generted with every build +#ignore reports, should be generated with every build report/ #ignore config files from eclipse, we don't want IDE files in our repository @@ -64,5 +62,6 @@ venv/ #ignore config files from JetBrains /.idea -#ignore addons/ directory -addons/ +#ignore addons directory +/addons +/addon \ No newline at end of file From 5a93c3abfa1ca61f392fb073da1927845a2fed1d Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 29 Jun 2018 00:26:00 -0400 Subject: [PATCH 18/81] Revert doc/Config title --- doc/Config.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/Config.md b/doc/Config.md index 2ffc0bf7e6..7ac3f7a02e 100644 --- a/doc/Config.md +++ b/doc/Config.md @@ -1,5 +1,5 @@ -Friendica Configuration -======================= +Config values that can only be set in config/local.ini.php +========================================================== * [Home](help) From 54a465c577bb3cdceeeaa49a67e2c889da35cdf0 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 29 Jun 2018 00:26:53 -0400 Subject: [PATCH 19/81] Update documentation - Add line breaks on periods - Remove obsolete text --- doc/Install.md | 9 +++++---- doc/Installing-Connectors.md | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/doc/Install.md b/doc/Install.md index 154a321174..ea0bff26c3 100644 --- a/doc/Install.md +++ b/doc/Install.md @@ -100,13 +100,14 @@ If you need to specify a port for the connection to the database, you can do so *If* the manual installation fails for any reason, check the following: -* Does "config/local.ini.php" exist? If not, edit config/local-sample.ini.php and change the system settings. Rename to config/local.ini.php -* Is the database is populated? If not, import the contents of "database.sql" with phpmyadmin or the mysql command line. +* Does "config/local.ini.php" exist? If not, edit config/local-sample.ini.php and change the system settings. +* Rename to `config/local.ini.php`. +* Is the database is populated? If not, import the contents of `database.sql` with phpmyadmin or the mysql command line. At this point visit your website again, and register your personal account. Registration errors should all be recoverable automatically. If you get any *critical* failure at this point, it generally indicates the database was not installed correctly. -You might wish to move/rename config/local.ini.php to another name and empty (called 'dropping') the database tables, so that you can start fresh. +You might wish to move/rename `config/local.ini.php` to another name and empty (called 'dropping') the database tables, so that you can start fresh. ### Option B: Run the automatic install script @@ -162,5 +163,5 @@ Bad things will happen. Let there be a hardware failure, a corrupted database or whatever you can think of. So once the installation of your Friendica node is done, you should make yourself a backup plan. -The most important file is the `config/local.ini.php` file in the base directory. +The most important file is the `config/local.ini.php` file. As it stores all your data, you should also have a recent dump of your Friendica database at hand, should you have to recover your node. diff --git a/doc/Installing-Connectors.md b/doc/Installing-Connectors.md index 6ad140fa90..f1eba5a6a0 100644 --- a/doc/Installing-Connectors.md +++ b/doc/Installing-Connectors.md @@ -4,7 +4,7 @@ Installing Connectors (Twitter/GNU Social) * [Home](help) -Friendica uses addons to provide connectivity to some networks, such as Twitter or App.net. +Friendica uses addons to provide connectivity to some networks, such as Twitter. There is also a addon to post through to an existing account on a GNU Social service. You only need this to post to an already existing GNU Social account, but not to communicate with GNU Social members in general. From 5e8185f7b4a345c31b7143742c1695051bdabc41 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 29 Jun 2018 00:27:21 -0400 Subject: [PATCH 20/81] Fix INSTALL - Change config file permissions - Remove leading slash of config/ --- INSTALL.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/INSTALL.txt b/INSTALL.txt index c6a994da63..a849f493a7 100644 --- a/INSTALL.txt +++ b/INSTALL.txt @@ -85,7 +85,7 @@ Clone the addon repository (separately): git clone https://github.com/friendica/friendica-addons.git -b master addon -If you copy the directory tree to your webserver, make sure that you also +If you copy the directory tree to your webserver, make sure that you also copy .htaccess - as "dot" files are often hidden and aren't normally copied. If you want to use the development version of Friendica you can switch to @@ -106,7 +106,7 @@ password, database name). - Please check the additional notes if running on MySQ 5.7.17 or newer 4. If you know in advance that it will be impossible for the web server to -write or create files in the /config/ subfolder, create an empty file called +write or create files in the config/ subfolder, create an empty file called local.ini.php and make it writable by the web server. 5. Visit your website with a web browser and follow the instructions. Please @@ -282,13 +282,13 @@ due to permissions issues: For Linux: % touch config/local.ini.php -% chmod 777 config/local.ini.php +% chmod 664 config/local.ini.php Retry the installation. As soon as the database has been created, ******* this is important ********* -% chmod 755 config/local.ini.php +% chmod 644 config/local.ini.php ##################################################################### - Some configurations with "suhosin" security are configured without From 6d4615fabd1a504e8962891dc702d6b4b5b5962a Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 29 Jun 2018 00:31:22 -0400 Subject: [PATCH 21/81] Update config/defaults.ini.php - Move sections around - Update config.admin_email value type --- config/defaults.ini.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/config/defaults.ini.php b/config/defaults.ini.php index fac979c005..d1d7903157 100644 --- a/config/defaults.ini.php +++ b/config/defaults.ini.php @@ -3,16 +3,6 @@ ; This file declares the default values for all the config values of Friendica. ; Please don't edit this file as its content may change in the upcoming versions. -[jabber] - -; debug (Boolean) -; Enable debug level for the jabber account synchronisation. -debug = false - -; lockpath (Path) -; Must be writable by the ejabberd process. if set then it will prevent the running of multiple processes. -lockpath = - [database] ; host (String) @@ -38,7 +28,7 @@ charset = utf8mb4 [config] -; admin_email (String) +; admin_email (Comma-separated list) ; In order to perform system administration via the admin panel, this must precisely match the email address of the person logged in. admin_email = @@ -444,14 +434,26 @@ directory = https://dir.friendi.social xrd_timeout = 20 [experimental] + ; exp_themes (Boolean) ; Show experimental themes in user settings. exp_themes = false [theme] + ; hide_eventlist (Boolean) ; Don't show the birthdays and events on the profile and network page hide_eventlist = false +[jabber] + +; debug (Boolean) +; Enable debug level for the jabber account synchronisation. +debug = false + +; lockpath (Path) +; Must be writable by the ejabberd process. if set then it will prevent the running of multiple processes. +lockpath = + INI; // Keep this line \ No newline at end of file From 73b4e0552d11fdc53c0154ee6d2ebe18020bb95e Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 30 Jun 2018 11:11:22 -0400 Subject: [PATCH 22/81] Fix wrong urlpath determination --- src/App.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/App.php b/src/App.php index d35b497c2a..1eca4329f5 100644 --- a/src/App.php +++ b/src/App.php @@ -143,14 +143,15 @@ class App $this->basepath = rtrim($basepath, DIRECTORY_SEPARATOR); - $this->determineUrlPath(); - + // The order of the following calls is important to ensure proper initialization $this->loadConfigFiles(); $this->loadDatabase(); $this->determineMode(); + $this->determineUrlPath(); + if ($this->mode === self::MODE_NORMAL) { Core\Addon::loadHooks(); From d487c399dd05e65b4b0990eb7c3ee86b4cc78e22 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 30 Jun 2018 14:07:01 -0400 Subject: [PATCH 23/81] Standards: Rename App methods - Rename App->max_processes_reached to App->isMaxProcessesReached - Rename App->maxload_reached to App->isMaxLoadReached --- index.php | 2 +- src/App.php | 4 ++-- src/Core/Worker.php | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/index.php b/index.php index 3a2067471e..5da31f100e 100644 --- a/index.php +++ b/index.php @@ -42,7 +42,7 @@ if (!$a->mode == App::MODE_INSTALL) { Config::load(); - if ($a->max_processes_reached() || $a->maxload_reached()) { +if ($a->isMaxProcessesReached() || $a->isMaxLoadReached()) { header($_SERVER["SERVER_PROTOCOL"] . ' 503 Service Temporarily Unavailable'); header('Retry-After: 120'); header('Refresh: 120; url=' . System::baseUrl() . "/" . $a->query_string); diff --git a/src/App.php b/src/App.php index 1eca4329f5..eca5c4b7db 100644 --- a/src/App.php +++ b/src/App.php @@ -972,7 +972,7 @@ class App * * @return bool Is the limit reached? */ - public function max_processes_reached() + public function isMaxProcessesReached() { // Deactivated, needs more investigating if this check really makes sense return false; @@ -1052,7 +1052,7 @@ class App * * @return bool Is the load reached? */ - public function maxload_reached() + public function isMaxLoadReached() { if ($this->is_backend()) { $process = 'backend'; diff --git a/src/Core/Worker.php b/src/Core/Worker.php index 0d51bb725d..897a80111d 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -41,7 +41,7 @@ class Worker self::$up_start = microtime(true); // At first check the maximum load. We shouldn't continue with a high load - if ($a->maxload_reached()) { + if ($a->isMaxLoadReached()) { logger('Pre check: maximum load reached, quitting.', LOGGER_DEBUG); return; } @@ -75,7 +75,7 @@ class Worker } // Possibly there are too much database processes that block the system - if ($a->max_processes_reached()) { + if ($a->isMaxProcessesReached()) { logger('Pre check: maximum processes reached, quitting.', LOGGER_DEBUG); return; } @@ -203,7 +203,7 @@ class Worker } // Constantly check the number of parallel database processes - if ($a->max_processes_reached()) { + if ($a->isMaxProcessesReached()) { logger("Max processes reached for process ".$mypid, LOGGER_DEBUG); return false; } From cd9b864045588308e18e16f7a1c1029fd380d8fd Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 30 Jun 2018 14:40:09 -0400 Subject: [PATCH 24/81] Rework App modes - Replace App mode constants with capability-based flags - Add App->isInstallMode() - Add file config fallback in (P)Config abstraction - Removed logger disabling code --- bin/daemon.php | 2 +- include/text.php | 24 ++------- index.php | 26 +++++----- src/App.php | 55 +++++++++++++++------ src/Core/Config.php | 10 ++-- src/Core/Console/Config.php | 4 +- src/Core/Console/GlobalCommunityBlock.php | 2 +- src/Core/Console/GlobalCommunitySilence.php | 2 +- src/Core/Console/Maintenance.php | 2 +- src/Core/Console/NewPassword.php | 2 +- src/Core/PConfig.php | 10 ++-- src/Core/System.php | 14 ------ 12 files changed, 74 insertions(+), 79 deletions(-) diff --git a/bin/daemon.php b/bin/daemon.php index 2813100267..65ae2a53b6 100755 --- a/bin/daemon.php +++ b/bin/daemon.php @@ -28,7 +28,7 @@ require_once "include/dba.php"; $a = new App(dirname(__DIR__)); -if ($a->mode === App::MODE_INSTALL) { +if ($a->isInstallMode()) { die("Friendica isn't properly installed yet.\n"); } diff --git a/include/text.php b/include/text.php index 3ee23ff164..d48986161d 100644 --- a/include/text.php +++ b/include/text.php @@ -608,17 +608,9 @@ function logger($msg, $level = 0) { $a = get_app(); global $LOGGER_LEVELS; - // turn off logger in install mode - if ( - $a->mode == App::MODE_INSTALL - || !dba::$connected - ) { - return; - } - - $debugging = Config::get('system','debugging'); - $logfile = Config::get('system','logfile'); - $loglevel = intval(Config::get('system','loglevel')); + $debugging = Config::get('system', 'debugging'); + $logfile = Config::get('system', 'logfile'); + $loglevel = intval(Config::get('system', 'loglevel')); if ( !$debugging @@ -687,14 +679,6 @@ function logger($msg, $level = 0) { function dlogger($msg, $level = 0) { $a = get_app(); - // turn off logger in install mode - if ( - $a->mode == App::MODE_INSTALL - || !dba::$connected - ) { - return; - } - $logfile = Config::get('system', 'dlogfile'); if (!$logfile) { return; @@ -716,7 +700,7 @@ function dlogger($msg, $level = 0) { $process_id = session_id(); if ($process_id == '') { - $process_id = get_app()->process_id; + $process_id = $a->process_id; } $callers = debug_backtrace(); diff --git a/index.php b/index.php index 5da31f100e..a8098942c2 100644 --- a/index.php +++ b/index.php @@ -35,20 +35,20 @@ $a->backend = false; require_once "include/dba.php"; -if (!$a->mode == App::MODE_INSTALL) { - /** - * Load configs from db. Overwrite configs from config/local.ini.php - */ - - Config::load(); +// Missing DB connection: ERROR +if ($a->mode & App::MODE_LOCALCONFIGPRESENT && !($a->mode & App::MODE_DBAVAILABLE)) { + System::httpExit(500, ['title' => 'Error 500 - Internal Server Error', 'description' => 'Apologies but the website is unavailable at the moment.']); +} +// Max Load Average reached: ERROR if ($a->isMaxProcessesReached() || $a->isMaxLoadReached()) { - header($_SERVER["SERVER_PROTOCOL"] . ' 503 Service Temporarily Unavailable'); - header('Retry-After: 120'); - header('Refresh: 120; url=' . System::baseUrl() . "/" . $a->query_string); - die("System is currently unavailable. Please try again later"); - } + header('Retry-After: 120'); + header('Refresh: 120; url=' . System::baseUrl() . "/" . $a->query_string); + System::httpExit(503, ['title' => 'Error 503 - Service Temporarily Unavailable', 'description' => 'System is currently overloaded. Please try again later.']); +} + +if ($a->isInstallMode()) { if (Config::get('system', 'force_ssl') && ($a->get_scheme() == "http") && (intval(Config::get('system', 'ssl_policy')) == SSL_POLICY_FULL) && (substr(System::baseUrl(), 0, 8) == "https://") @@ -167,9 +167,9 @@ $_SESSION['last_updated'] = defaults($_SESSION, 'last_updated', []); // in install mode, any url loads install module // but we need "view" module for stylesheet -if ($a->mode == App::MODE_INSTALL && $a->module!="view") { +if ($a->isInstallMode() && $a->module!="view") { $a->module = 'install'; -} elseif ($a->mode == App::MODE_MAINTENANCE && $a->module!="view") { +} elseif (!($a->mode & App::MODE_MAINTENANCEDISABLED) && $a->module != "view") { $a->module = 'maintenance'; } else { check_url($a); diff --git a/src/App.php b/src/App.php index eca5c4b7db..6773140f26 100644 --- a/src/App.php +++ b/src/App.php @@ -34,9 +34,20 @@ require_once 'include/text.php'; */ class App { - const MODE_NORMAL = 0; - const MODE_INSTALL = 1; - const MODE_MAINTENANCE = 2; + const MODE_LOCALCONFIGPRESENT = 1; + const MODE_DBAVAILABLE = 2; + const MODE_DBCONFIGAVAILABLE = 4; + const MODE_MAINTENANCEDISABLED = 8; + + /** + * @deprecated since version 2008.08 Use App->isInstallMode() instead to check for install mode. + */ + const MODE_INSTALL = 0; + + /** + * @deprecated since version 2008.08 Use the precise mode constant to check for a specific capability instead. + */ + const MODE_NORMAL = App::MODE_LOCALCONFIGPRESENT | App::MODE_DBAVAILABLE | App::MODE_DBCONFIGAVAILABLE | App::MODE_MAINTENANCEDISABLED; public $module_loaded = false; public $module_class = null; @@ -59,7 +70,7 @@ class App public $argv; public $argc; public $module; - public $mode = App::MODE_NORMAL; + public $mode = App::MODE_INSTALL; public $strings; public $basepath; public $urlpath; @@ -152,7 +163,9 @@ class App $this->determineUrlPath(); - if ($this->mode === self::MODE_NORMAL) { + Config::load(); + + if ($this->mode & self::MODE_DBAVAILABLE) { Core\Addon::loadHooks(); $this->loadAddonConfig(); @@ -449,30 +462,32 @@ class App */ private function determineMode() { - $this->mode = App::MODE_INSTALL; + $this->mode = 0; - // Missing local config files: MODE_INSTALL if (!file_exists($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php') && !file_exists($this->basepath . DIRECTORY_SEPARATOR . '.htconfig.php')) { return; } - // Missing DB connection: ERROR + $this->mode |= App::MODE_LOCALCONFIGPRESENT; + if (!\dba::connected()) { - System::unavailable(); + return; } - // Working DB connection, missing tables: MODE_INSTALL + $this->mode |= App::MODE_DBAVAILABLE; + if (\dba::fetch_first("SHOW TABLES LIKE 'config'") === false) { return; } - // Maintenance mode check + $this->mode |= App::MODE_DBCONFIGAVAILABLE; + if (Config::get('system', 'maintenance')) { - $this->mode = App::MODE_MAINTENANCE; - } else { - $this->mode = App::MODE_NORMAL; + return; } + + $this->mode |= App::MODE_MAINTENANCEDISABLED; } public function loadDatabase() @@ -520,6 +535,16 @@ class App $this->save_timestamp($stamp1, "network"); } + /** + * Install mode is when the local config file is missing or the DB schema hasn't been installed yet. + * + * @return bool + */ + public function isInstallMode() + { + return !($this->mode & App::MODE_LOCALCONFIGPRESENT) || !($this->mode & App::MODE_DBCONFIGAVAILABLE); + } + /** * @brief Returns the base filesystem path of the App * @@ -1311,7 +1336,7 @@ class App */ public function getCurrentTheme() { - if ($this->mode == App::MODE_INSTALL) { + if ($this->isInstallMode()) { return ''; } diff --git a/src/Core/Config.php b/src/Core/Config.php index b327eb133f..93cb266577 100644 --- a/src/Core/Config.php +++ b/src/Core/Config.php @@ -30,7 +30,7 @@ class Config extends BaseObject public static function init() { // Database isn't ready or populated yet - if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) { + if (!(self::getApp()->mode & \Friendica\App::MODE_DBCONFIGAVAILABLE)) { return; } @@ -54,7 +54,7 @@ class Config extends BaseObject public static function load($family = "config") { // Database isn't ready or populated yet - if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) { + if (!(self::getApp()->mode & \Friendica\App::MODE_DBCONFIGAVAILABLE)) { return; } @@ -87,7 +87,7 @@ class Config extends BaseObject public static function get($family, $key, $default_value = null, $refresh = false) { // Database isn't ready or populated yet, fallback to file config - if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) { + if (!(self::getApp()->mode & \Friendica\App::MODE_DBCONFIGAVAILABLE)) { return self::getApp()->getConfigValue($family, $key, $default_value); } @@ -115,7 +115,7 @@ class Config extends BaseObject public static function set($family, $key, $value) { // Database isn't ready or populated yet - if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) { + if (!(self::getApp()->mode & \Friendica\App::MODE_DBCONFIGAVAILABLE)) { return false; } @@ -140,7 +140,7 @@ class Config extends BaseObject public static function delete($family, $key) { // Database isn't ready or populated yet - if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) { + if (!(self::getApp()->mode & \Friendica\App::MODE_DBCONFIGAVAILABLE)) { return false; } diff --git a/src/Core/Console/Config.php b/src/Core/Console/Config.php index a6083ddb9f..f619afade0 100644 --- a/src/Core/Console/Config.php +++ b/src/Core/Console/Config.php @@ -92,7 +92,7 @@ HELP; throw new CommandArgsException('Too many arguments'); } - if ($a->mode === \Friendica\App::MODE_INSTALL) { + if (!($a->mode & \Friendica\App::MODE_DBCONFIGAVAILABLE)) { $this->out('Database isn\'t ready or populated yet, showing file config only'); } @@ -126,7 +126,7 @@ HELP; if (count($this->args) == 0) { Core\Config::load(); - if (Core\Config::get('system', 'config_adapter') != 'preload' && $a->mode !== \Friendica\App::MODE_INSTALL) { + if (Core\Config::get('system', 'config_adapter') != 'preload' && $a->mode & \Friendica\App::MODE_DBCONFIGAVAILABLE) { $this->out('Warning: The JIT (Just In Time) Config adapter doesn\'t support loading the entire configuration, showing file config only'); } diff --git a/src/Core/Console/GlobalCommunityBlock.php b/src/Core/Console/GlobalCommunityBlock.php index 5fcc6be160..59a5d9cfdc 100644 --- a/src/Core/Console/GlobalCommunityBlock.php +++ b/src/Core/Console/GlobalCommunityBlock.php @@ -56,7 +56,7 @@ HELP; throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); } - if ($a->mode == \Friendica\App::MODE_INSTALL) { + if ($a->isInstallMode()) { throw new \RuntimeException('Database isn\'t ready or populated yet'); } diff --git a/src/Core/Console/GlobalCommunitySilence.php b/src/Core/Console/GlobalCommunitySilence.php index a70888e454..ccd6014e9c 100644 --- a/src/Core/Console/GlobalCommunitySilence.php +++ b/src/Core/Console/GlobalCommunitySilence.php @@ -64,7 +64,7 @@ HELP; throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); } - if ($a->mode == \Friendica\App::MODE_INSTALL) { + if ($a->isInstallMode()) { throw new \RuntimeException('Database isn\'t ready or populated yet'); } diff --git a/src/Core/Console/Maintenance.php b/src/Core/Console/Maintenance.php index 68d33337ab..90449c4787 100644 --- a/src/Core/Console/Maintenance.php +++ b/src/Core/Console/Maintenance.php @@ -64,7 +64,7 @@ HELP; throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); } - if ($a->mode == \Friendica\App::MODE_INSTALL) { + if ($a->isInstallMode()) { throw new \RuntimeException('Database isn\'t ready or populated yet'); } diff --git a/src/Core/Console/NewPassword.php b/src/Core/Console/NewPassword.php index e5f9349190..0035974727 100644 --- a/src/Core/Console/NewPassword.php +++ b/src/Core/Console/NewPassword.php @@ -58,7 +58,7 @@ HELP; throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); } - if ($a->mode == \Friendica\App::MODE_INSTALL) { + if ($a->isInstallMode()) { throw new \RuntimeException('Database isn\'t ready or populated yet'); } diff --git a/src/Core/PConfig.php b/src/Core/PConfig.php index 3b01bceeaf..aa5f75abe7 100644 --- a/src/Core/PConfig.php +++ b/src/Core/PConfig.php @@ -29,7 +29,7 @@ class PConfig extends BaseObject public static function init($uid) { // Database isn't ready or populated yet - if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) { + if (!(self::getApp()->mode & \Friendica\App::MODE_DBCONFIGAVAILABLE)) { return; } @@ -54,7 +54,7 @@ class PConfig extends BaseObject public static function load($uid, $family) { // Database isn't ready or populated yet - if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) { + if (!(self::getApp()->mode & \Friendica\App::MODE_DBCONFIGAVAILABLE)) { return; } @@ -83,7 +83,7 @@ class PConfig extends BaseObject public static function get($uid, $family, $key, $default_value = null, $refresh = false) { // Database isn't ready or populated yet - if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) { + if (!(self::getApp()->mode & \Friendica\App::MODE_DBCONFIGAVAILABLE)) { return; } @@ -112,7 +112,7 @@ class PConfig extends BaseObject public static function set($uid, $family, $key, $value) { // Database isn't ready or populated yet - if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) { + if (!(self::getApp()->mode & \Friendica\App::MODE_DBCONFIGAVAILABLE)) { return false; } @@ -138,7 +138,7 @@ class PConfig extends BaseObject public static function delete($uid, $family, $key) { // Database isn't ready or populated yet - if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) { + if (!(self::getApp()->mode & \Friendica\App::MODE_DBCONFIGAVAILABLE)) { return false; } diff --git a/src/Core/System.php b/src/Core/System.php index e3dc4e5870..4e2b63f044 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -85,20 +85,6 @@ class System extends BaseObject return implode(', ', $callstack2); } - /** - * @brief Called from db initialisation when db is dead. - */ - static public function unavailable() { -echo <<< EOT - - System Unavailable - Apologies but this site is unavailable at the moment. Please try again later. - -EOT; - - killme(); - } - /** * Generic XML return * Outputs a basic dfrn XML status structure to STDOUT, with a variable From 2e40c39fa424d6cc14a44bb3bd2fc9ec11906fdb Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 1 Jul 2018 00:12:57 -0400 Subject: [PATCH 25/81] Add system.groupedit_image_limit config key to defaults.ini.php --- config/defaults.ini.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/config/defaults.ini.php b/config/defaults.ini.php index d1d7903157..27108530c6 100644 --- a/config/defaults.ini.php +++ b/config/defaults.ini.php @@ -165,6 +165,11 @@ dlogip = ; Value in minutes after we think that a frontend task was killed by the webserver. frontend_worker_timeout = 10 +; groupedit_image_limit (Integer) +; Number of contacts at which the group editor should switch from display the profile pictures of the contacts to only display the names. +; This can alternatively be set on a per account basis in the pconfig table. +groupedit_image_limit = 400 + ; hsts (Boolean) ; Enables the sending of HTTP Strict Transport Security headers hsts = false From 7f04a2ab8b38cd7208dc4e9d507aef54cb400f24 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 1 Jul 2018 04:04:42 -0400 Subject: [PATCH 26/81] Replace system.proc_windows config by PHP_OS test --- config/defaults.ini.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/config/defaults.ini.php b/config/defaults.ini.php index 27108530c6..f5974b9258 100644 --- a/config/defaults.ini.php +++ b/config/defaults.ini.php @@ -359,10 +359,6 @@ profiler = false ; Sets the ImageMagick compression level for PNG images. Values ranges from 0 (uncompressed) to 9 (most compressed). png_quality = 8 -; proc_windows (Boolean) -; Should be enabled if Friendica is running under Windows. -proc_windows = false - ; proxy_cache_time (Integer) ; Period in seconds after which the cache is cleared. proxy_cache_time = 86400 From 5196ea22ffc2a39c0f3f9b41a6aa5945b63d04b2 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 1 Jul 2018 04:05:20 -0400 Subject: [PATCH 27/81] Fix Database connexion in tests --- tests/DatabaseTest.php | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/tests/DatabaseTest.php b/tests/DatabaseTest.php index e79e9237be..1a1b53b120 100644 --- a/tests/DatabaseTest.php +++ b/tests/DatabaseTest.php @@ -81,21 +81,8 @@ abstract class DatabaseTest extends TestCase */ protected function getConnection() { - if (!dba::$connected) { - dba::connect(getenv('MYSQL_HOST') . ':' . getenv('MYSQL_PORT'), getenv('MYSQL_USERNAME'), getenv('MYSQL_PASSWORD'), getenv('MYSQL_DATABASE')); - - if (dba::$connected) { - $app = get_app(); - // We need to do this in order to disable logging - $app->mode = \Friendica\App::MODE_INSTALL; - - // Create database structure - DBStructure::update(false, true, true); - - $app->mode = \Friendica\App::MODE_NORMAL; - } else { - $this->markTestSkipped('Could not connect to the database. Please check the MYSQL_* environment variables.'); - } + if (!dba::connected()) { + $this->markTestSkipped('Could not connect to the database.'); } return $this->createDefaultDBConnection(dba::get_db(), getenv('MYSQL_DATABASE')); From 4e7471232ef0ba3152fc919583bff2f92fe933ad Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 1 Jul 2018 15:15:17 -0400 Subject: [PATCH 28/81] Bump minimum PHP version to 5.6.1 --- .travis.yml | 2 +- INSTALL.txt | 2 +- composer.json | 2 +- composer.lock | 4 ++-- doc/Install.md | 2 +- doc/de/Install.md | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6e7ac1c2e0..7419ecbfbe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ --- language: php -## Friendica supports PHP version >= 5.6 +## Friendica supports PHP version >= 5.6.1 php: - 5.6 - 7.0 diff --git a/INSTALL.txt b/INSTALL.txt index a849f493a7..705eb8fed2 100644 --- a/INSTALL.txt +++ b/INSTALL.txt @@ -32,7 +32,7 @@ link if your cert is self-signed). - Apache with mod-rewrite enabled and "Options All" so you can use a local .htaccess file - - PHP 5.6+ (PHP 7 recommended for performance). + - PHP 5.6.1+ (PHP 7 recommended for performance). - PHP *command line* access with register_argc_argv set to true in the php.ini file [or see 'poormancron' in section 8] diff --git a/composer.json b/composer.json index 941464e70c..9ef0dcd101 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "issues": "https://github.com/friendica/friendica/issues" }, "require": { - "php": ">5.6", + "php": ">=5.6.1", "ext-xml": "*", "asika/simple-console": "^1.0", "divineomega/password_exposed": "^2.4", diff --git a/composer.lock b/composer.lock index 7ba8fc1cfd..5ba2709835 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "4fcae78061a3eb72f91e4fa81e53af56", + "content-hash": "9e24971ae9340c5d9d4d4ca477d4ec29", "packages": [ { "name": "asika/simple-console", @@ -3582,7 +3582,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">5.6", + "php": ">=5.6.1", "ext-xml": "*" }, "platform-dev": [] diff --git a/doc/Install.md b/doc/Install.md index ea0bff26c3..6eb249a812 100644 --- a/doc/Install.md +++ b/doc/Install.md @@ -27,7 +27,7 @@ Requirements --- * Apache with mod-rewrite enabled and "Options All" so you can use a local .htaccess file -* PHP 5.6+ (PHP 7 is recommended for performance) +* PHP 5.6.1+ (PHP 7 is recommended for performance) * PHP *command line* access with register_argc_argv set to true in the php.ini file * Curl, GD, PDO, MySQLi, hash, xml, zip and OpenSSL extensions * The POSIX module of PHP needs to be activated (e.g. [RHEL, CentOS](http://www.bigsoft.co.uk/blog/index.php/2014/12/08/posix-php-commands-not-working-under-centos-7) have disabled it) diff --git a/doc/de/Install.md b/doc/de/Install.md index ef4ef8aadc..84941d9282 100644 --- a/doc/de/Install.md +++ b/doc/de/Install.md @@ -28,7 +28,7 @@ Requirements --- * Apache mit einer aktiverten mod-rewrite-Funktion und dem Eintrag "Options All", so dass du die lokale .htaccess-Datei nutzen kannst -* PHP 5.6+ (PHP 7 ist aufgrund der Performance empfohlen) +* PHP 5.6.1+ (PHP 7 ist aufgrund der Performance empfohlen) * PHP *Kommandozeilen*-Zugang mit register_argc_argv auf "true" gesetzt in der php.ini-Datei * Curl, GD, PDO, MySQLi, xml, zip und OpenSSL-Erweiterung * Das POSIX Modul muss aktiviert sein ([CentOS, RHEL](http://www.bigsoft.co.uk/blog/index.php/2014/12/08/posix-php-commands-not-working-under-centos-7http://www.bigsoft.co.uk/blog/index.php/2014/12/08/posix-php-commands-not-working-under-centos-7) haben dies z.B. deaktiviert) From de7277ac69849ea93d5c15c4b7d8aeb10156f313 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 1 Jul 2018 15:27:05 -0400 Subject: [PATCH 29/81] Add load_config hook doc --- doc/Addons.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/Addons.md b/doc/Addons.md index 375f5eafdd..2465db7307 100644 --- a/doc/Addons.md +++ b/doc/Addons.md @@ -323,6 +323,9 @@ Called before calling PHP's `mail()`. - **body** - **headers** +### load_config +Called during `App` initialization to allow addons to load their own configuration file(s) with `App::loadConfigFile()`. + ### nav_info Called after the navigational menu is build in `include/nav.php`. `$b` is an array containing `$nav` from `include/nav.php`. @@ -565,6 +568,10 @@ Here is a complete list of all hook callbacks with file locations (as of 01-Apr- Addon::callHooks("template_vars", $arr); +### src/App.php + + Addon::callHooks('load_config'); + ### src/Model/Item.php Addon::callHooks('post_local', $item); From d8096a402c9262b938e64d1c75b3cd5c3d3fb3a6 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 6 Jul 2018 21:08:48 -0400 Subject: [PATCH 30/81] Update use of environment variables in loadDatabase --- src/App.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/App.php b/src/App.php index 6773140f26..be4c7785ee 100644 --- a/src/App.php +++ b/src/App.php @@ -504,22 +504,22 @@ class App // Use environment variables for mysql if they are set beforehand if (!empty(getenv('MYSQL_HOST')) - && !empty(getenv('MYSQL_PORT')) && (!empty(getenv('MYSQL_USERNAME')) || !empty(getenv('MYSQL_USER'))) - && !empty(getenv('MYSQL_PASSWORD')) + && !getenv('MYSQL_PASSWORD') === false && !empty(getenv('MYSQL_DATABASE'))) { - $db_host = getenv('MYSQL_HOST') . ':' . getenv('MYSQL_PORT'); - + $db_host = getenv('MYSQL_HOST'); + if (!empty(getenv('MYSQL_PORT'))) { + $db_host .= ':' . getenv('MYSQL_PORT'); + } if (!empty(getenv('MYSQL_USERNAME'))) { $db_user = getenv('MYSQL_USERNAME'); - } elseif (!empty(getenv('MYSQL_USER'))) { + } else { $db_user = getenv('MYSQL_USER'); } - - $db_pass = getenv('MYSQL_PASSWORD'); + $db_pass = (string) getenv('MYSQL_PASSWORD'); $db_data = getenv('MYSQL_DATABASE'); - }elseif (file_exists($this->basepath . DIRECTORY_SEPARATOR . '.htconfig.php')) { + } 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; From 3433c22116bb2e32dc3ce0072cd5bc8b04a92302 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 6 Jul 2018 21:17:04 -0400 Subject: [PATCH 31/81] Remove .htconfig.php reference from DatabaseTest --- tests/DatabaseTest.php | 48 ------------------------------------------ 1 file changed, 48 deletions(-) diff --git a/tests/DatabaseTest.php b/tests/DatabaseTest.php index 1a1b53b120..579e45084d 100644 --- a/tests/DatabaseTest.php +++ b/tests/DatabaseTest.php @@ -20,54 +20,6 @@ abstract class DatabaseTest extends TestCase use TestCaseTrait; - /** - * Renames an eventually existing .htconfig.php to .htconfig.php.tmp - * Creates a new .htconfig.php for bin/worker.php execution - */ - public static function setUpBeforeClass() - { - parent::setUpBeforeClass(); - - $base_config_file_name = 'htconfig.php'; - $config_file_name = '.htconfig.php'; - - $base_config_file_path = stream_resolve_include_path($base_config_file_name); - $config_file_path = dirname($base_config_file_path) . DIRECTORY_SEPARATOR . $config_file_name; - $config_file_path_tmp = $config_file_path . '.tmp'; - - if (file_exists($config_file_path)) { - rename($config_file_path, $config_file_path_tmp); - } - - $config_string = file_get_contents($base_config_file_path); - - $config_string = str_replace('die(', '// die(', $config_string); - - file_put_contents($config_file_path, $config_string); - } - - /** - * Delete the created .htconfig.php - * Renames an eventually existing .htconfig.php.tmp to .htconfig.php - */ - public static function tearDownAfterClass() - { - $base_config_file_name = 'htconfig.php'; - $config_file_name = '.htconfig.php'; - - $base_config_file_path = stream_resolve_include_path($base_config_file_name); - $config_file_path = dirname($base_config_file_path) . DIRECTORY_SEPARATOR . $config_file_name; - $config_file_path_tmp = $config_file_path . '.tmp'; - - if (file_exists($config_file_path)) { - unlink($config_file_path); - } - - if (file_exists($config_file_path_tmp)) { - rename($config_file_path_tmp, $config_file_path); - } - } - /** * Get database connection. * From 1f1a3930b238b5773ca23f0e3dfb6702b0928549 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 6 Jul 2018 21:20:29 -0400 Subject: [PATCH 32/81] Instantiate the App in test bootstrap - Remove wrong App instantiation in Lock test --- tests/bootstrap.php | 2 ++ tests/src/Core/Lock/LockTest.php | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 4474e4ee8e..4b03aa246b 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -10,6 +10,8 @@ use PHPUnit\Framework\TestCase; require_once __DIR__.'/../boot.php'; require_once __DIR__.'/../include/api.php'; +new App(dirname(__DIR__)); + // Backward compatibility if (!class_exists(TestCase::class)) { class_alias(PHPUnit_Framework_TestCase::class, TestCase::class); diff --git a/tests/src/Core/Lock/LockTest.php b/tests/src/Core/Lock/LockTest.php index dafbd74a6f..5e4bebd45c 100644 --- a/tests/src/Core/Lock/LockTest.php +++ b/tests/src/Core/Lock/LockTest.php @@ -23,7 +23,7 @@ abstract class LockTest extends DatabaseTest $this->instance = $this->getInstance(); // Reusable App object - $this->app = new App(__DIR__.'/../'); + $this->app = \Friendica\BaseObject::getApp(); $a = $this->app; // Default config From 32418e8660af66fde215e576cef0e660a232ea92 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 6 Jul 2018 21:24:17 -0400 Subject: [PATCH 33/81] Fix test bootstrap namespace issue --- tests/bootstrap.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 4b03aa246b..875ec8ab7d 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -3,6 +3,7 @@ * This file is loaded by PHPUnit before any test. */ +use Friendica\App; use PHPUnit\DbUnit\DataSet\YamlDataSet; use PHPUnit\DbUnit\TestCaseTrait; use PHPUnit\Framework\TestCase; From e98216b5bbfef23424cb422c29de1cbbe1901457 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 6 Jul 2018 21:24:40 -0400 Subject: [PATCH 34/81] Improve comparison in App->loadDatabase() --- src/App.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/App.php b/src/App.php index be4c7785ee..3ce5bf576c 100644 --- a/src/App.php +++ b/src/App.php @@ -505,7 +505,7 @@ class App // Use environment variables for mysql if they are set beforehand if (!empty(getenv('MYSQL_HOST')) && (!empty(getenv('MYSQL_USERNAME')) || !empty(getenv('MYSQL_USER'))) - && !getenv('MYSQL_PASSWORD') === false + && getenv('MYSQL_PASSWORD') !== false && !empty(getenv('MYSQL_DATABASE'))) { $db_host = getenv('MYSQL_HOST'); From 66ac16e101f18057a099e2f746661cfa45392a24 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 6 Jul 2018 21:39:24 -0400 Subject: [PATCH 35/81] Fix set_baseurl() notice messages in worker during tests --- config/defaults.ini.php | 5 +++++ tests/bootstrap.php | 2 ++ 2 files changed, 7 insertions(+) diff --git a/config/defaults.ini.php b/config/defaults.ini.php index f5974b9258..36c06da4cd 100644 --- a/config/defaults.ini.php +++ b/config/defaults.ini.php @@ -416,6 +416,11 @@ throttle_limit_week = 0 ; Maximum number of posts that a user can send per month with the API. 0 to disable monthly throttling. throttle_limit_month = 0 +; url (String) +; The fully-qualified URL of this Friendica node. +; Used by the worker in a non-HTTP execution environment. +url = + ; worker_cooldown (Integer) ; Cooldown period in seconds after each worker function call. worker_cooldown = 0 diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 875ec8ab7d..e566b58042 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -13,6 +13,8 @@ require_once __DIR__.'/../include/api.php'; new App(dirname(__DIR__)); +\Friendica\Core\Config::set('system', 'url', 'http://localhost/'); + // Backward compatibility if (!class_exists(TestCase::class)) { class_alias(PHPUnit_Framework_TestCase::class, TestCase::class); From 4d5b79a9d46ad07716febaac02e59dafe3baad90 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 6 Jul 2018 21:46:35 -0400 Subject: [PATCH 36/81] Move forbidden_nicknames default to config file --- config/defaults.ini.php | 5 +++++ mod/admin.php | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/config/defaults.ini.php b/config/defaults.ini.php index 36c06da4cd..0c4492ea96 100644 --- a/config/defaults.ini.php +++ b/config/defaults.ini.php @@ -161,6 +161,11 @@ dlogfile = ; restricts develop log writes to requests originating from this IP address dlogip = +; forbidden_nicknames (Comma-separated list) +; Prevents users from registering the specified nicknames on this node +; Default value comprises classic role names from RFC 2142 +forbidden_nicknames = info, marketing, sales, support, abuse, noc, security, postmaster, hostmaster, usenet, news, webmaster, www, uucp, ftp, root, sysop + ; frontend_worker_timeout (Integer) ; Value in minutes after we think that a frontend task was killed by the webserver. frontend_worker_timeout = 10 diff --git a/mod/admin.php b/mod/admin.php index d431fac2a2..1209ad92bc 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -1394,8 +1394,6 @@ function admin_page_site(App $a) if ($optimize_max_tablesize <= 0) { $optimize_max_tablesize = -1; } - // Default list of forbidden names, classic role names from RFC 2142 - $default_forbidden_nicknames = 'info, marketing, sales, support, abuse, noc, security, postmaster, hostmaster, usenet, news, webmaster, www, uucp, ftp, root, sysop'; $t = get_markup_template('admin/site.tpl'); return replace_macros($t, [ @@ -1435,7 +1433,7 @@ function admin_page_site(App $a) '$register_policy' => ['register_policy', L10n::t("Register policy"), $a->config['register_policy'], "", $register_choices], '$daily_registrations' => ['max_daily_registrations', L10n::t("Maximum Daily Registrations"), Config::get('system', 'max_daily_registrations'), L10n::t("If registration is permitted above, this sets the maximum number of new user registrations to accept per day. If register is set to closed, this setting has no effect.")], '$register_text' => ['register_text', L10n::t("Register text"), $a->config['register_text'], L10n::t("Will be displayed prominently on the registration page. You can use BBCode here.")], - '$forbidden_nicknames' => ['forbidden_nicknames', L10n::t('Forbidden Nicknames'), Config::get('system', 'forbidden_nicknames', $default_forbidden_nicknames), L10n::t('Comma separated list of nicknames that are forbidden from registration. Preset is a list of role names according RFC 2142.')], + '$forbidden_nicknames' => ['forbidden_nicknames', L10n::t('Forbidden Nicknames'), Config::get('system', 'forbidden_nicknames'), L10n::t('Comma separated list of nicknames that are forbidden from registration. Preset is a list of role names according RFC 2142.')], '$abandon_days' => ['abandon_days', L10n::t('Accounts abandoned after x days'), Config::get('system','account_abandon_days'), L10n::t('Will not waste system resources polling external sites for abandonded accounts. Enter 0 for no time limit.')], '$allowed_sites' => ['allowed_sites', L10n::t("Allowed friend domains"), Config::get('system','allowed_sites'), L10n::t("Comma separated list of domains which are allowed to establish friendships with this site. Wildcards are accepted. Empty to allow any domains")], '$allowed_email' => ['allowed_email', L10n::t("Allowed email domains"), Config::get('system','allowed_email'), L10n::t("Comma separated list of domains which are allowed in email addresses for registrations to this site. Wildcards are accepted. Empty to allow any domains")], From e627054f687e027e5de5418882ccf5d1fb75fda9 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 6 Jul 2018 21:46:51 -0400 Subject: [PATCH 37/81] Add optimize_max_tablesize to default config file --- config/defaults.ini.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/config/defaults.ini.php b/config/defaults.ini.php index 0c4492ea96..5139102779 100644 --- a/config/defaults.ini.php +++ b/config/defaults.ini.php @@ -265,6 +265,12 @@ min_poll_interval = 1 ; Allow pseudonyms (true) or enforce a space between firstname and lastname in Full name, as an antispam measure (false). no_regfullname = true +; optimize_max_tablesize (Integer) +; Maximum table size (in MB) for the automatic optimization. +; -1 to disable automatic optimization. +; 0 to use internal default (100MB) +optimize_max_tablesize = -1 + ; session_handler (database|cache|native) ; Whether to use Cache to store session data or to use PHP native session storage. session_handler = database From 3255b2364b3727618ec28855948c9b7f2992fa06 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 7 Jul 2018 16:31:03 -0400 Subject: [PATCH 38/81] Fix dbesc as a constant notice message --- src/Database/DBStructure.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Database/DBStructure.php b/src/Database/DBStructure.php index 5c03c1afd6..00ab09ccf2 100644 --- a/src/Database/DBStructure.php +++ b/src/Database/DBStructure.php @@ -53,7 +53,7 @@ class DBStructure $a = get_app(); //send the administrators an e-mail - $admin_mail_list = "'".implode("','", array_map(dbesc, explode(",", str_replace(" ", "", $a->config['admin_email']))))."'"; + $admin_mail_list = "'".implode("','", array_map('dbesc', explode(",", str_replace(" ", "", $a->config['admin_email']))))."'"; $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)", $admin_mail_list ); From d1f2d04803b799092e16a260824a548c574cfaca Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 7 Jul 2018 17:46:20 -0400 Subject: [PATCH 39/81] Add missing default config keys - Add config.admin_nickname - Add config.info - Add featurelock section --- config/defaults.ini.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/config/defaults.ini.php b/config/defaults.ini.php index 5139102779..cd17347410 100644 --- a/config/defaults.ini.php +++ b/config/defaults.ini.php @@ -32,6 +32,14 @@ charset = utf8mb4 ; In order to perform system administration via the admin panel, this must precisely match the email address of the person logged in. admin_email = +; admin_nickname (String) +; Nickname of the main admin user, used if there are more than one admin user defined in config.admin_email +admin_nickname = + +; info (String) +; Plaintext description of this node, used in the /friendica module +info = + ; max_import_size (Integer) ; Maximum body size of DFRN and Mail messages in characters. 0 is unlimited. max_import_size = 200000 @@ -450,6 +458,9 @@ directory = https://dir.friendi.social ; Timeout in seconds for fetching the XRD links. xrd_timeout = 20 +; Used in the admin settings to lock certain features +[featurelock] + [experimental] ; exp_themes (Boolean) From 762a78661109d28dbc29a15b379b342938b35f40 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 7 Jul 2018 17:46:30 -0400 Subject: [PATCH 40/81] Replace direct accesses to App->config by Config::get/set calls --- boot.php | 24 +--- include/dba.php | 23 ++- include/enotify.php | 8 +- mod/admin.php | 23 ++- mod/bookmarklet.php | 3 +- mod/friendica.php | 17 +-- mod/home.php | 6 +- mod/install.php | 3 +- mod/invite.php | 4 +- mod/lostpass.php | 4 +- mod/nodeinfo.php | 4 +- mod/openid.php | 2 +- mod/ping.php | 2 +- mod/profile_photo.php | 155 +++++++++++---------- mod/register.php | 22 +-- mod/regmod.php | 5 +- mod/removeme.php | 6 +- mod/settings.php | 5 +- mod/statistics_json.php | 4 +- mod/uimport.php | 4 +- src/Content/Nav.php | 2 +- src/Content/Text/BBCode.php | 4 +- src/Core/Console/AutomaticInstallation.php | 24 ++-- src/Database/DBStructure.php | 2 +- src/Model/Profile.php | 2 +- src/Model/User.php | 4 +- src/Module/Login.php | 4 +- src/Protocol/OStatus.php | 2 +- view/theme/frio/theme.php | 2 +- 29 files changed, 180 insertions(+), 190 deletions(-) diff --git a/boot.php b/boot.php index 728f36b16e..8f25c2b931 100644 --- a/boot.php +++ b/boot.php @@ -774,7 +774,7 @@ function run_update_function($x) /** * @brief Synchronise addons: * - * $a->config['system']['addon'] contains a comma-separated list of names + * system.addon contains a comma-separated list of names * of addons which are used on this system. * Go through the database list of already installed addons, and if we have * an entry, but it isn't in the config list, call the uninstall procedure @@ -957,17 +957,6 @@ function info($s) } } -/** - * @brief Wrapper around config to limit the text length of an incoming message - * - * @return int - */ -function get_max_import_size() -{ - $a = get_app(); - return (x($a->config, 'max_import_size') ? $a->config['max_import_size'] : 0); -} - function feed_birthday($uid, $tz) { /** @@ -1023,14 +1012,11 @@ function is_site_admin() { $a = get_app(); - $adminlist = explode(",", str_replace(" ", "", $a->config['admin_email'])); + $admin_email = Config::get('config', 'admin_email'); - //if(local_user() && x($a->user,'email') && x($a->config,'admin_email') && ($a->user['email'] === $a->config['admin_email'])) - /// @TODO This if() + 2 returns can be shrinked into one return - if (local_user() && x($a->user, 'email') && x($a->config, 'admin_email') && in_array($a->user['email'], $adminlist)) { - return true; - } - return false; + $adminlist = explode(',', str_replace(' ', '', $admin_email)); + + return local_user() && $admin_email && in_array(defaults($a->user, 'email', ''), $adminlist); } /** diff --git a/include/dba.php b/include/dba.php index 8214501e9b..0d8eeef3d5 100644 --- a/include/dba.php +++ b/include/dba.php @@ -184,7 +184,7 @@ class dba { private static function logIndex($query) { $a = get_app(); - if (empty($a->config["system"]["db_log_index"])) { + if (empty(Config::get('system', 'db_log_index'))) { return; } @@ -203,18 +203,18 @@ class dba { return; } - $watchlist = explode(',', $a->config["system"]["db_log_index_watch"]); - $blacklist = explode(',', $a->config["system"]["db_log_index_blacklist"]); + $watchlist = explode(',', Config::get('system', 'db_log_index_watch')); + $blacklist = explode(',', Config::get('system', 'db_log_index_blacklist')); while ($row = dba::fetch($r)) { - if ((intval($a->config["system"]["db_loglimit_index"]) > 0)) { + if ((intval(Config::get('system', 'db_loglimit_index')) > 0)) { $log = (in_array($row['key'], $watchlist) && - ($row['rows'] >= intval($a->config["system"]["db_loglimit_index"]))); + ($row['rows'] >= intval(Config::get('system', 'db_loglimit_index')))); } else { $log = false; } - if ((intval($a->config["system"]["db_loglimit_index_high"]) > 0) && ($row['rows'] >= intval($a->config["system"]["db_loglimit_index_high"]))) { + if ((intval(Config::get('system', 'db_loglimit_index_high')) > 0) && ($row['rows'] >= intval(Config::get('system', 'db_loglimit_index_high')))) { $log = true; } @@ -224,7 +224,7 @@ class dba { if ($log) { $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); - @file_put_contents($a->config["system"]["db_log_index"], DateTimeFormat::utcNow()."\t". + @file_put_contents(Config::get('system', 'db_log_index'), DateTimeFormat::utcNow()."\t". $row['key']."\t".$row['rows']."\t".$row['Extra']."\t". basename($backtrace[1]["file"])."\t". $backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t". @@ -384,7 +384,7 @@ class dba { $orig_sql = $sql; - if (x($a->config,'system') && x($a->config['system'], 'db_callstack')) { + if (Config::get('system', 'db_callstack')) { $sql = "/*".System::callstack()." */ ".$sql; } @@ -545,16 +545,15 @@ class dba { $a->save_timestamp($stamp1, 'database'); - if (x($a->config,'system') && x($a->config['system'], 'db_log')) { - + if (Config::get('system', 'db_log')) { $stamp2 = microtime(true); $duration = (float)($stamp2 - $stamp1); - if (($duration > $a->config["system"]["db_loglimit"])) { + if (($duration > Config::get('system', 'db_loglimit'))) { $duration = round($duration, 3); $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); - @file_put_contents($a->config["system"]["db_log"], DateTimeFormat::utcNow()."\t".$duration."\t". + @file_put_contents(Config::get('system', 'db_log'), DateTimeFormat::utcNow()."\t".$duration."\t". basename($backtrace[1]["file"])."\t". $backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t". substr(self::replaceParameters($sql, $args), 0, 2000)."\n", FILE_APPEND); diff --git a/include/enotify.php b/include/enotify.php index a19693816f..2d4cbdadb5 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -33,11 +33,11 @@ function notification($params) $product = FRIENDICA_PLATFORM; $siteurl = System::baseUrl(true); $thanks = L10n::t('Thank You,'); - $sitename = $a->config['sitename']; - if (empty($a->config['admin_name'])) { - $site_admin = L10n::t('%s Administrator', $sitename); + $sitename = Config::get('config', 'sitename'); + if (Config::get('config', 'admin_name')) { + $site_admin = L10n::t('%1$s, %2$s Administrator', Config::get('config', 'admin_name'), $sitename); } else { - $site_admin = L10n::t('%1$s, %2$s Administrator', $a->config['admin_name'], $sitename); + $site_admin = L10n::t('%s Administrator', $sitename); } $sender_name = $sitename; diff --git a/mod/admin.php b/mod/admin.php index 1209ad92bc..c90eb3c5eb 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -1384,8 +1384,8 @@ function admin_page_site(App $a) "develop" => L10n::t("check the development version") ]; - if ($a->config['hostname'] == "") { - $a->config['hostname'] = $a->get_hostname(); + if (empty(Config::get('config', 'hostname'))) { + Config::set('config', 'hostname', $a->get_hostname()); } $diaspora_able = ($a->get_path() == ""); @@ -1412,9 +1412,9 @@ function admin_page_site(App $a) '$relocate' => L10n::t('Relocate - WARNING: advanced function. Could make this server unreachable.'), '$baseurl' => System::baseUrl(true), // name, label, value, help string, extra data... - '$sitename' => ['sitename', L10n::t("Site name"), $a->config['sitename'],''], - '$hostname' => ['hostname', L10n::t("Host name"), $a->config['hostname'], ""], - '$sender_email' => ['sender_email', L10n::t("Sender Email"), $a->config['sender_email'], L10n::t("The email address your server shall use to send notification emails from."), "", "", "email"], + '$sitename' => ['sitename', L10n::t("Site name"), Config::get('config', 'sitename'),''], + '$hostname' => ['hostname', L10n::t("Host name"), Config::get('config', 'hostname'), ""], + '$sender_email' => ['sender_email', L10n::t("Sender Email"), Config::get('config', 'sender_email'), L10n::t("The email address your server shall use to send notification emails from."), "", "", "email"], '$banner' => ['banner', L10n::t("Banner/Logo"), $banner, ""], '$shortcut_icon' => ['shortcut_icon', L10n::t("Shortcut icon"), Config::get('system','shortcut_icon'), L10n::t("Link to an icon that will be used for browsers.")], '$touch_icon' => ['touch_icon', L10n::t("Touch icon"), Config::get('system','touch_icon'), L10n::t("Link to an icon that will be used for tablets and mobiles.")], @@ -1430,9 +1430,9 @@ function admin_page_site(App $a) '$maximagelength' => ['maximagelength', L10n::t("Maximum image length"), Config::get('system','max_image_length'), L10n::t("Maximum length in pixels of the longest side of uploaded images. Default is -1, which means no limits.")], '$jpegimagequality' => ['jpegimagequality', L10n::t("JPEG image quality"), Config::get('system','jpeg_quality'), L10n::t("Uploaded JPEGS will be saved at this quality setting [0-100]. Default is 100, which is full quality.")], - '$register_policy' => ['register_policy', L10n::t("Register policy"), $a->config['register_policy'], "", $register_choices], + '$register_policy' => ['register_policy', L10n::t("Register policy"), Config::get('config', 'register_policy'), "", $register_choices], '$daily_registrations' => ['max_daily_registrations', L10n::t("Maximum Daily Registrations"), Config::get('system', 'max_daily_registrations'), L10n::t("If registration is permitted above, this sets the maximum number of new user registrations to accept per day. If register is set to closed, this setting has no effect.")], - '$register_text' => ['register_text', L10n::t("Register text"), $a->config['register_text'], L10n::t("Will be displayed prominently on the registration page. You can use BBCode here.")], + '$register_text' => ['register_text', L10n::t("Register text"), Config::get('config', 'register_text'), L10n::t("Will be displayed prominently on the registration page. You can use BBCode here.")], '$forbidden_nicknames' => ['forbidden_nicknames', L10n::t('Forbidden Nicknames'), Config::get('system', 'forbidden_nicknames'), L10n::t('Comma separated list of nicknames that are forbidden from registration. Preset is a list of role names according RFC 2142.')], '$abandon_days' => ['abandon_days', L10n::t('Accounts abandoned after x days'), Config::get('system','account_abandon_days'), L10n::t('Will not waste system resources polling external sites for abandonded accounts. Enter 0 for no time limit.')], '$allowed_sites' => ['allowed_sites', L10n::t("Allowed friend domains"), Config::get('system','allowed_sites'), L10n::t("Comma separated list of domains which are allowed to establish friendships with this site. Wildcards are accepted. Empty to allow any domains")], @@ -1670,13 +1670,13 @@ function admin_page_users_post(App $a) Thank you and welcome to %4$s.')); - $preamble = sprintf($preamble, $user['username'], $a->config['sitename']); - $body = sprintf($body, System::baseUrl(), $user['email'], $result['password'], $a->config['sitename']); + $preamble = sprintf($preamble, $user['username'], Config::get('config', 'sitename')); + $body = sprintf($body, System::baseUrl(), $user['email'], $result['password'], Config::get('config', 'sitename')); notification([ 'type' => SYSTEM_EMAIL, 'to_email' => $user['email'], - 'subject' => L10n::t('Registration details for %s', $a->config['sitename']), + 'subject' => L10n::t('Registration details for %s', Config::get('config', 'sitename')), 'preamble' => $preamble, 'body' => $body]); } @@ -1801,7 +1801,7 @@ function admin_page_users(App $a) ORDER BY $sql_order $sql_order_direction LIMIT %d, %d", intval($a->pager['start']), intval($a->pager['itemspage']) ); - $adminlist = explode(",", str_replace(" ", "", $a->config['admin_email'])); + $adminlist = explode(",", str_replace(" ", "", Config::get('config', 'admin_email'))); $_setup_users = function ($e) use ($adminlist) { $page_types = [ PAGE_NORMAL => L10n::t('Normal Account Page'), @@ -1828,7 +1828,6 @@ function admin_page_users(App $a) $e['register_date'] = Temporal::getRelativeDate($e['register_date']); $e['login_date'] = Temporal::getRelativeDate($e['login_date']); $e['lastitem_date'] = Temporal::getRelativeDate($e['lastitem_date']); - //$e['is_admin'] = ($e['email'] === $a->config['admin_email']); $e['is_admin'] = in_array($e['email'], $adminlist); $e['is_deletable'] = (intval($e['uid']) != local_user()); $e['deleted'] = ($e['account_removed'] ? Temporal::getRelativeDate($e['account_expires_on']) : False); diff --git a/mod/bookmarklet.php b/mod/bookmarklet.php index 9ae3e28f08..88097eb910 100644 --- a/mod/bookmarklet.php +++ b/mod/bookmarklet.php @@ -5,6 +5,7 @@ use Friendica\App; use Friendica\Core\ACL; +use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\System; use Friendica\Module\Login; @@ -21,7 +22,7 @@ function bookmarklet_content(App $a) { if (!local_user()) { $o = '

' . L10n::t('Login') . '

'; - $o .= Login::form($a->query_string, $a->config['register_policy'] == REGISTER_CLOSED ? false : true); + $o .= Login::form($a->query_string, Config::get('config', 'register_policy') === REGISTER_CLOSED ? false : true); return $o; } diff --git a/mod/friendica.php b/mod/friendica.php index 9d4bdd801c..b3cea56dc6 100644 --- a/mod/friendica.php +++ b/mod/friendica.php @@ -2,11 +2,12 @@ /** * @file mod/friendica.php */ + use Friendica\App; use Friendica\Core\Addon; -use Friendica\Core\System; use Friendica\Core\Config; use Friendica\Core\L10n; +use Friendica\Core\System; use Friendica\Database\DBM; function friendica_init(App $a) @@ -16,10 +17,10 @@ function friendica_init(App $a) $sql_extra = ''; if (x($a->config, 'admin_nickname')) { - $sql_extra = sprintf(" AND `nickname` = '%s' ", dbesc($a->config['admin_nickname'])); + $sql_extra = sprintf(" AND `nickname` = '%s' ", dbesc(Config::get('config', 'admin_nickname'))); } - if (isset($a->config['admin_email']) && $a->config['admin_email']!='') { - $adminlist = explode(",", str_replace(" ", "", $a->config['admin_email'])); + if (!empty(Config::get('config', 'admin_email'))) { + $adminlist = explode(",", str_replace(" ", "", Config::get('config', 'admin_email'))); $r = q("SELECT `username`, `nickname` FROM `user` WHERE `email` = '%s' $sql_extra", dbesc($adminlist[0])); $admin = [ @@ -55,13 +56,13 @@ function friendica_init(App $a) $data = [ 'version' => FRIENDICA_VERSION, 'url' => System::baseUrl(), - 'addons' => $visible_addons, + 'addons' => $visible_addons, 'locked_features' => $locked_features, - 'register_policy' => $register_policy[$a->config['register_policy']], + 'register_policy' => $register_policy[Config::get('config', 'register_policy')], 'admin' => $admin, - 'site_name' => $a->config['sitename'], + 'site_name' => Config::get('config', 'sitename'), 'platform' => FRIENDICA_PLATFORM, - 'info' => ((x($a->config, 'info')) ? $a->config['info'] : ''), + 'info' => Config::get('config', 'info'), 'no_scrape_url' => System::baseUrl().'/noscrape' ]; diff --git a/mod/home.php b/mod/home.php index 206a1827ea..c386763ca3 100644 --- a/mod/home.php +++ b/mod/home.php @@ -36,7 +36,7 @@ function home_content(App $a) { } $customhome = false; - $defaultheader = '

'.((x($a->config,'sitename')) ? L10n::t("Welcome to %s", $a->config['sitename']) : "").'

'; + $defaultheader = '

' . (Config::get('config', 'sitename') ? L10n::t('Welcome to %s', Config::get('config', 'sitename')) : '') . '

'; $homefilepath = $a->basepath . "/home.html"; $cssfilepath = $a->basepath . "/home.css"; @@ -45,9 +45,9 @@ function home_content(App $a) { if (file_exists($cssfilepath)) { $a->page['htmlhead'] .= ''; } - } + } - $login = Login::form($a->query_string, $a->config['register_policy'] == REGISTER_CLOSED ? 0 : 1); + $login = Login::form($a->query_string, Config::get('config', 'register_policy') === REGISTER_CLOSED ? 0 : 1); $content = ''; Addon::callHooks("home_content",$content); diff --git a/mod/install.php b/mod/install.php index 6962ff2dda..0f08b0fd8b 100644 --- a/mod/install.php +++ b/mod/install.php @@ -22,7 +22,8 @@ function install_init(App $a) { // We overwrite current theme css, because during install we could not have a working mod_rewrite // so we could not have a css at all. Here we set a static css file for the install procedure pages - $a->config['system']['theme'] = "../install"; + + $a->setConfigValue('system', 'value', '../install'); $a->theme['stylesheet'] = System::baseUrl()."/view/install/style.css"; Install::setInstallMode(); diff --git a/mod/invite.php b/mod/invite.php index 813dbf7044..bea479a8f7 100644 --- a/mod/invite.php +++ b/mod/invite.php @@ -126,14 +126,14 @@ function invite_content(App $a) { $dirloc = Config::get('system', 'directory'); if (strlen($dirloc)) { - if ($a->config['register_policy'] == REGISTER_CLOSED) { + if (Config::get('config', 'register_policy') === REGISTER_CLOSED) { $linktxt = L10n::t('Visit %s for a list of public sites that you can join. Friendica members on other sites can all connect with each other, as well as with members of many other social networks.', $dirloc . '/servers'); } else { $linktxt = L10n::t('To accept this invitation, please visit and register at %s or any other public Friendica website.', System::baseUrl()) . "\r\n" . "\r\n" . L10n::t('Friendica sites all inter-connect to create a huge privacy-enhanced social web that is owned and controlled by its members. They can also connect with many traditional social networks. See %s for a list of alternate Friendica sites you can join.', $dirloc . '/servers'); } } else { // there is no global directory URL defined - if ($a->config['register_policy'] == REGISTER_CLOSED) { + if (Config::get('config', 'register_policy') === REGISTER_CLOSED) { $o = L10n::t('Our apologies. This system is not currently configured to connect with other public sites or invite members.'); return $o; } else { diff --git a/mod/lostpass.php b/mod/lostpass.php index af4518ca16..0d22252bdc 100644 --- a/mod/lostpass.php +++ b/mod/lostpass.php @@ -39,7 +39,7 @@ function lostpass_post(App $a) info(L10n::t('Password reset request issued. Check your email.') . EOL); } - $sitename = $a->config['sitename']; + $sitename = Config::get('config', 'sitename'); $resetlink = System::baseUrl() . '/lostpass/' . $pwdreset_token; $preamble = deindent(L10n::t(' @@ -145,7 +145,7 @@ function lostpass_generate_password($user) info("Your password has been reset." . EOL); - $sitename = $a->config['sitename']; + $sitename = Config::get('config', 'sitename'); $preamble = deindent(L10n::t(' Dear %1$s, Your password has been changed as requested. Please retain this diff --git a/mod/nodeinfo.php b/mod/nodeinfo.php index 1b9dce5f55..74645bc66d 100644 --- a/mod/nodeinfo.php +++ b/mod/nodeinfo.php @@ -61,9 +61,9 @@ function nodeinfo_init(App $a) { $nodeinfo['usage'] = []; - $nodeinfo['openRegistrations'] = ($a->config['register_policy'] != 0); + $nodeinfo['openRegistrations'] = Config::get('config', 'register_policy') !== REGISTER_CLOSED; - $nodeinfo['metadata'] = ['nodeName' => $a->config['sitename']]; + $nodeinfo['metadata'] = ['nodeName' => Config::get('config', 'sitename')]; if (Config::get('system', 'nodeinfo')) { diff --git a/mod/openid.php b/mod/openid.php index 2c284f76d8..7be8544cd9 100644 --- a/mod/openid.php +++ b/mod/openid.php @@ -62,7 +62,7 @@ function openid_content(App $a) { // Successful OpenID login - but we can't match it to an existing account. // New registration? - if ($a->config['register_policy'] == REGISTER_CLOSED) { + if (Config::get('config', 'register_policy') === REGISTER_CLOSED) { notice(L10n::t('Account not found and OpenID registration is not permitted on this site.') . EOL); goaway(System::baseUrl()); } diff --git a/mod/ping.php b/mod/ping.php index 196758b0df..7153752b05 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -200,7 +200,7 @@ function ping_init(App $a) ); $mail_count = count($mails); - if ($a->config['register_policy'] == REGISTER_APPROVE && is_site_admin()) { + if (Config::get('config', 'register_policy') === REGISTER_APPROVE && is_site_admin()) { $regs = q( "SELECT `contact`.`name`, `contact`.`url`, `contact`.`micro`, `register`.`created` FROM `contact` RIGHT JOIN `register` ON `register`.`uid` = `contact`.`uid` diff --git a/mod/profile_photo.php b/mod/profile_photo.php index 1a80b539db..a1428adc87 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -13,54 +13,52 @@ use Friendica\Model\Contact; use Friendica\Model\Photo; use Friendica\Model\Profile; use Friendica\Object\Image; -use Friendica\Util\DateTimeFormat; function profile_photo_init(App $a) { - if (! local_user()) { + if (!local_user()) { return; } Profile::load($a, $a->user['nickname']); } -function profile_photo_post(App $a) { +function profile_photo_post(App $a) +{ - if (! local_user()) { - notice(L10n::t('Permission denied.') . EOL ); + if (!local_user()) { + notice(L10n::t('Permission denied.') . EOL); return; } check_form_security_token_redirectOnErr('/profile_photo', 'profile_photo'); - if((x($_POST,'cropfinal')) && ($_POST['cropfinal'] == 1)) { + if ((x($_POST, 'cropfinal')) && ($_POST['cropfinal'] == 1)) { // unless proven otherwise $is_default_profile = 1; - if($_REQUEST['profile']) { - $r = q("select id, `is-default` from profile where id = %d and uid = %d limit 1", - intval($_REQUEST['profile']), + if ($_REQUEST['profile']) { + $r = q("select id, `is-default` from profile where id = %d and uid = %d limit 1", intval($_REQUEST['profile']), intval(local_user()) ); - if (DBM::is_result($r) && (! intval($r[0]['is-default']))) - $is_default_profile = 0; + if (DBM::is_result($r) && (!intval($r[0]['is-default']))) $is_default_profile = 0; } // phase 2 - we have finished cropping - if($a->argc != 2) { - notice(L10n::t('Image uploaded but image cropping failed.') . EOL ); + if ($a->argc != 2) { + notice(L10n::t('Image uploaded but image cropping failed.') . EOL); return; } $image_id = $a->argv[1]; - if(substr($image_id,-2,1) == '-') { - $scale = substr($image_id,-1,1); - $image_id = substr($image_id,0,-2); + if (substr($image_id, -2, 1) == '-') { + $scale = substr($image_id, -1, 1); + $image_id = substr($image_id, 0, -2); } @@ -69,10 +67,8 @@ function profile_photo_post(App $a) { $srcW = $_POST['xfinal'] - $srcX; $srcH = $_POST['yfinal'] - $srcY; - $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = %d LIMIT 1", - dbesc($image_id), - dbesc(local_user()), - intval($scale)); + $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = %d LIMIT 1", dbesc($image_id), + dbesc(local_user()), intval($scale)); if (DBM::is_result($r)) { @@ -80,9 +76,10 @@ function profile_photo_post(App $a) { $Image = new Image($base_image['data'], $base_image['type']); if ($Image->isValid()) { - $Image->crop(175,$srcX,$srcY,$srcW,$srcH); + $Image->crop(175, $srcX, $srcY, $srcW, $srcH); - $r = Photo::store($Image, local_user(), 0, $base_image['resource-id'],$base_image['filename'], L10n::t('Profile Photos'), 4, $is_default_profile); + $r = Photo::store($Image, local_user(), 0, $base_image['resource-id'], $base_image['filename'], + L10n::t('Profile Photos'), 4, $is_default_profile); if ($r === false) { notice(L10n::t('Image size reduction [%s] failed.', "175") . EOL); @@ -90,7 +87,8 @@ function profile_photo_post(App $a) { $Image->scaleDown(80); - $r = Photo::store($Image, local_user(), 0, $base_image['resource-id'],$base_image['filename'], L10n::t('Profile Photos'), 5, $is_default_profile); + $r = Photo::store($Image, local_user(), 0, $base_image['resource-id'], $base_image['filename'], + L10n::t('Profile Photos'), 5, $is_default_profile); if ($r === false) { notice(L10n::t('Image size reduction [%s] failed.', "80") . EOL); @@ -98,7 +96,8 @@ function profile_photo_post(App $a) { $Image->scaleDown(48); - $r = Photo::store($Image, local_user(), 0, $base_image['resource-id'],$base_image['filename'], L10n::t('Profile Photos'), 6, $is_default_profile); + $r = Photo::store($Image, local_user(), 0, $base_image['resource-id'], $base_image['filename'], + L10n::t('Profile Photos'), 6, $is_default_profile); if ($r === false) { notice(L10n::t('Image size reduction [%s] failed.', "48") . EOL); @@ -108,15 +107,13 @@ function profile_photo_post(App $a) { if ($is_default_profile) { $r = q("UPDATE `photo` SET `profile` = 0 WHERE `profile` = 1 AND `resource-id` != '%s' AND `uid` = %d", - dbesc($base_image['resource-id']), - intval(local_user()) + dbesc($base_image['resource-id']), intval(local_user()) ); } else { $r = q("update profile set photo = '%s', thumb = '%s' where id = %d and uid = %d", dbesc(System::baseUrl() . '/photo/' . $base_image['resource-id'] . '-4.' . $Image->getExt()), dbesc(System::baseUrl() . '/photo/' . $base_image['resource-id'] . '-5.' . $Image->getExt()), - intval($_REQUEST['profile']), - intval(local_user()) + intval($_REQUEST['profile']), intval(local_user()) ); } @@ -125,7 +122,7 @@ function profile_photo_post(App $a) { info(L10n::t('Shift-reload the page or clear browser cache if the new photo does not display immediately.') . EOL); // Update global directory in background $url = System::baseUrl() . '/profile/' . $a->user['nickname']; - if ($url && strlen(Config::get('system','directory'))) { + if ($url && strlen(Config::get('system', 'directory'))) { Worker::add(PRIORITY_LOW, "Directory", $url); } @@ -139,7 +136,7 @@ function profile_photo_post(App $a) { return; // NOTREACHED } - $src = $_FILES['userfile']['tmp_name']; + $src = $_FILES['userfile']['tmp_name']; $filename = basename($_FILES['userfile']['name']); $filesize = intval($_FILES['userfile']['size']); $filetype = $_FILES['userfile']['type']; @@ -158,7 +155,7 @@ function profile_photo_post(App $a) { $imagedata = @file_get_contents($src); $ph = new Image($imagedata, $filetype); - if (! $ph->isValid()) { + if (!$ph->isValid()) { notice(L10n::t('Unable to process image.') . EOL); @unlink($src); return; @@ -166,25 +163,28 @@ function profile_photo_post(App $a) { $ph->orient($src); @unlink($src); - return profile_photo_crop_ui_head($a, $ph); + profile_photo_crop_ui_head($a, $ph); } +function profile_photo_content(App $a) +{ -function profile_photo_content(App $a) { - - if (! local_user()) { - notice(L10n::t('Permission denied.') . EOL ); + if (!local_user()) { + notice(L10n::t('Permission denied.') . EOL); return; } $newuser = false; - if($a->argc == 2 && $a->argv[1] === 'new') + if ($a->argc == 2 && $a->argv[1] === 'new') { $newuser = true; + } - if( $a->argv[1]=='use'){ - if ($a->argc<3){ - notice(L10n::t('Permission denied.') . EOL ); + $imagecrop = []; + + if ($a->argv[1] == 'use') { + if ($a->argc < 3) { + notice(L10n::t('Permission denied.') . EOL); return; }; @@ -192,36 +192,32 @@ function profile_photo_content(App $a) { $resource_id = $a->argv[2]; //die(":".local_user()); - $r=q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' ORDER BY `scale` ASC", - intval(local_user()), + $r = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' ORDER BY `scale` ASC", intval(local_user()), dbesc($resource_id) - ); - if (!DBM::is_result($r)){ - notice(L10n::t('Permission denied.') . EOL ); + ); + if (!DBM::is_result($r)) { + notice(L10n::t('Permission denied.') . EOL); return; } $havescale = false; foreach ($r as $rr) { - if($rr['scale'] == 5) - $havescale = true; + if ($rr['scale'] == 5) $havescale = true; } // set an already uloaded photo as profile photo // if photo is in 'Profile Photos', change it in db - if (($r[0]['album']== L10n::t('Profile Photos')) && ($havescale)){ - $r=q("UPDATE `photo` SET `profile`=0 WHERE `profile`=1 AND `uid`=%d", - intval(local_user())); + if (($r[0]['album'] == L10n::t('Profile Photos')) && ($havescale)) { + $r = q("UPDATE `photo` SET `profile`=0 WHERE `profile`=1 AND `uid`=%d", intval(local_user())); - $r=q("UPDATE `photo` SET `profile`=1 WHERE `uid` = %d AND `resource-id` = '%s'", - intval(local_user()), + $r = q("UPDATE `photo` SET `profile`=1 WHERE `uid` = %d AND `resource-id` = '%s'", intval(local_user()), dbesc($resource_id) - ); + ); Contact::updateSelfFromUserID(local_user(), true); // Update global directory in background $url = $_SESSION['my_url']; - if ($url && strlen(Config::get('system','directory'))) { + if ($url && strlen(Config::get('system', 'directory'))) { Worker::add(PRIORITY_LOW, "Directory", $url); } @@ -229,7 +225,7 @@ function profile_photo_content(App $a) { return; // NOTREACHED } $ph = new Image($r[0]['data'], $r[0]['type']); - profile_photo_crop_ui_head($a, $ph); + $imagecrop = profile_photo_crop_ui_head($a, $ph); // go ahead as we have jus uploaded a new photo to crop } @@ -238,11 +234,11 @@ function profile_photo_content(App $a) { ); - if(! x($a->config,'imagecrop')) { - + if (!empty($imagecrop)) { $tpl = get_markup_template('profile_photo.tpl'); - $o = replace_macros($tpl,[ + $o = replace_macros($tpl, + [ '$user' => $a->user['nickname'], '$lbl_upfile' => L10n::t('Upload File:'), '$lbl_profiles' => L10n::t('Select a profile:'), @@ -250,23 +246,24 @@ function profile_photo_content(App $a) { '$submit' => L10n::t('Upload'), '$profiles' => $profiles, '$form_security_token' => get_form_security_token("profile_photo"), - '$select' => sprintf('%s %s', L10n::t('or'), ($newuser) ? '
' . L10n::t('skip this step') . '' : '' . L10n::t('select a photo from your photo albums') . '') + '$select' => sprintf('%s %s', L10n::t('or'), + ($newuser) ? '' . L10n::t('skip this step') . '' : '' . L10n::t('select a photo from your photo albums') . '') ]); return $o; - } - else { - $filename = $a->config['imagecrop'] . '-' . $a->config['imagecrop_resolution'] . '.'.$a->config['imagecrop_ext']; + } else { + $filename = $imagecrop['hash'] . '-' . $imagecrop['resolution'] . '.' . $imagecrop['ext']; $tpl = get_markup_template("cropbody.tpl"); - $o = replace_macros($tpl,[ - '$filename' => $filename, - '$profile' => intval($_REQUEST['profile']), - '$resource' => $a->config['imagecrop'] . '-' . $a->config['imagecrop_resolution'], + $o = replace_macros($tpl, + [ + '$filename' => $filename, + '$profile' => intval($_REQUEST['profile']), + '$resource' => $imagecrop['hash'] . '-' . $imagecrop['resolution'], '$image_url' => System::baseUrl() . '/photo/' . $filename, - '$title' => L10n::t('Crop Image'), - '$desc' => L10n::t('Please adjust the image cropping for optimum viewing.'), + '$title' => L10n::t('Crop Image'), + '$desc' => L10n::t('Please adjust the image cropping for optimum viewing.'), '$form_security_token' => get_form_security_token("profile_photo"), - '$done' => L10n::t('Done Editing') + '$done' => L10n::t('Done Editing') ]); return $o; } @@ -274,10 +271,10 @@ function profile_photo_content(App $a) { return; // NOTREACHED } - -function profile_photo_crop_ui_head(App $a, Image $Image) { - $max_length = Config::get('system','max_image_length'); - if (! $max_length) { +function profile_photo_crop_ui_head(App $a, Image $Image) +{ + $max_length = Config::get('system', 'max_image_length'); + if (!$max_length) { $max_length = MAX_IMAGE_LENGTH; } if ($max_length > 0) { @@ -318,10 +315,14 @@ function profile_photo_crop_ui_head(App $a, Image $Image) { } } - $a->config['imagecrop'] = $hash; - $a->config['imagecrop_resolution'] = $smallest; - $a->config['imagecrop_ext'] = $Image->getExt(); $a->page['htmlhead'] .= replace_macros(get_markup_template("crophead.tpl"), []); $a->page['end'] .= replace_macros(get_markup_template("cropend.tpl"), []); - return; + + $imagecrop = [ + 'hash' => $hash, + 'resolution' => $smallest, + 'ext' => $Image->getExt(), + ]; + + return $imagecrop; } diff --git a/mod/register.php b/mod/register.php index 6b4f2b1f5c..75f2ec8532 100644 --- a/mod/register.php +++ b/mod/register.php @@ -37,7 +37,7 @@ function register_post(App $a) } } - switch ($a->config['register_policy']) { + switch (Config::get('config', 'register_policy')) { case REGISTER_OPEN: $blocked = 0; $verified = 1; @@ -50,7 +50,7 @@ function register_post(App $a) default: case REGISTER_CLOSED: - if ((!x($_SESSION, 'authenticated') && (!x($_SESSION, 'administrator')))) { + if (empty($_SESSION['authenticated']) && empty($_SESSION['administrator'])) { notice(L10n::t('Permission denied.') . EOL); return; } @@ -76,7 +76,7 @@ function register_post(App $a) $user = $result['user']; - if ($netpublish && $a->config['register_policy'] != REGISTER_APPROVE) { + if ($netpublish && Config::get('config', 'register_policy') !== REGISTER_APPROVE) { $url = System::baseUrl() . '/profile/' . $user['nickname']; Worker::add(PRIORITY_LOW, "Directory", $url); } @@ -85,7 +85,7 @@ function register_post(App $a) $num_invites = Config::get('system', 'number_invites'); $invite_id = ((x($_POST, 'invite_id')) ? notags(trim($_POST['invite_id'])) : ''); - if ($a->config['register_policy'] == REGISTER_OPEN) { + if (Config::get('config', 'register_policy') === REGISTER_OPEN) { if ($using_invites && $invite_id) { q("delete * from register where hash = '%s' limit 1", dbesc($invite_id)); PConfig::set($user['uid'], 'system', 'invites_remaining', $num_invites); @@ -94,7 +94,7 @@ function register_post(App $a) // Only send a password mail when the password wasn't manually provided if (!x($_POST, 'password1') || !x($_POST, 'confirm')) { $res = User::sendRegisterOpenEmail( - $user['email'], $a->config['sitename'], System::baseUrl(), $user['username'], $result['password']); + $user['email'], Config::get('config', 'sitename'), System::baseUrl(), $user['username'], $result['password']); if ($res) { info(L10n::t('Registration successful. Please check your email for further instructions.') . EOL); @@ -111,8 +111,8 @@ function register_post(App $a) info(L10n::t('Registration successful.') . EOL); goaway(System::baseUrl()); } - } elseif ($a->config['register_policy'] == REGISTER_APPROVE) { - if (!strlen($a->config['admin_email'])) { + } elseif (Config::get('config', 'register_policy') === REGISTER_APPROVE) { + if (!strlen(Config::get('config', 'admin_email'))) { notice(L10n::t('Your registration can not be processed.') . EOL); goaway(System::baseUrl()); } @@ -134,7 +134,7 @@ function register_post(App $a) } // send email to admins - $admin_mail_list = "'" . implode("','", array_map("dbesc", explode(",", str_replace(" ", "", $a->config['admin_email'])))) . "'"; + $admin_mail_list = "'" . implode("','", array_map("dbesc", explode(",", str_replace(" ", "", Config::get('config', 'admin_email'))))) . "'"; $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)", $admin_mail_list ); @@ -158,7 +158,7 @@ function register_post(App $a) } // send notification to the user, that the registration is pending User::sendRegisterPendingEmail( - $user['email'], $a->config['sitename'], $user['username']); + $user['email'], Config::get('config', 'sitename'), $user['username']); info(L10n::t('Your registration is pending approval by the site owner.') . EOL); goaway(System::baseUrl()); @@ -179,7 +179,7 @@ function register_content(App $a) return; } - if ((!local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) { + if ((!local_user()) && (Config::get('config', 'register_policy') === REGISTER_CLOSED)) { notice("Permission denied." . EOL); return; } @@ -258,7 +258,7 @@ function register_content(App $a) $o = replace_macros($tpl, [ '$oidhtml' => $oidhtml, '$invitations' => Config::get('system', 'invitation_only'), - '$permonly' => $a->config['register_policy'] == REGISTER_APPROVE, + '$permonly' => Config::get('config', 'register_policy') === REGISTER_APPROVE, '$permonlybox' => ['permonlybox', L10n::t('Note for the admin'), '', L10n::t('Leave a message for the admin, why you want to join this node')], '$invite_desc' => L10n::t('Membership on this site is by invitation only.'), '$invite_label' => L10n::t('Your invitation code: '), diff --git a/mod/regmod.php b/mod/regmod.php index aa64986d06..083465984f 100644 --- a/mod/regmod.php +++ b/mod/regmod.php @@ -2,6 +2,7 @@ /** * @file mod/regmod.php */ + use Friendica\App; use Friendica\Core\Config; use Friendica\Core\L10n; @@ -57,7 +58,7 @@ function user_allow($hash) $res = User::sendRegisterOpenEmail( $user[0]['email'], - $a->config['sitename'], + Config::get('config', 'sitename'), System::baseUrl(), $user[0]['username'], $register[0]['password']); @@ -100,7 +101,7 @@ function regmod_content(App $a) if (!local_user()) { info(L10n::t('Please login.') . EOL); - $o = '

' . Login::form($a->query_string, $a->config['register_policy'] == REGISTER_CLOSED ? 0 : 1); + $o = '

' . Login::form($a->query_string, Config::get('config', 'register_policy') === REGISTER_CLOSED ? 0 : 1); return $o; } diff --git a/mod/removeme.php b/mod/removeme.php index 2db63d8d8e..dd0ca0f81f 100644 --- a/mod/removeme.php +++ b/mod/removeme.php @@ -2,11 +2,13 @@ /** * @file mod/removeme.php */ + use Friendica\App; +use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\System; -use Friendica\Model\User; use Friendica\Database\DBM; +use Friendica\Model\User; require_once 'include/enotify.php'; @@ -34,7 +36,7 @@ function removeme_post(App $a) // send notification to admins so that they can clean um the backups // send email to admins - $admin_mails = explode(",", str_replace(" ", "", $a->config['admin_email'])); + $admin_mails = explode(",", str_replace(" ", "", Config::get('config', 'admin_email'))); foreach ($admin_mails as $mail) { $admin = dba::selectFirst('user', ['uid', 'language', 'email'], ['email' => $mail]); if (!DBM::is_result($admin)) { diff --git a/mod/settings.php b/mod/settings.php index d7e8b7b459..34e9ce41ec 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -511,9 +511,8 @@ function settings_post(App $a) $err .= L10n::t('Invalid email.'); } // ensure new email is not the admin mail - //if ((x($a->config, 'admin_email')) && (strcasecmp($email, $a->config['admin_email']) == 0)) { - if (x($a->config, 'admin_email')) { - $adminlist = explode(",", str_replace(" ", "", strtolower($a->config['admin_email']))); + if (Config::get('config', 'admin_email')) { + $adminlist = explode(",", str_replace(" ", "", strtolower(Config::get('config', 'admin_email')))); if (in_array(strtolower($email), $adminlist)) { $err .= L10n::t('Cannot change to that email.'); $email = $a->user['email']; diff --git a/mod/statistics_json.php b/mod/statistics_json.php index c035c1c05a..0dbe0ea492 100644 --- a/mod/statistics_json.php +++ b/mod/statistics_json.php @@ -17,10 +17,10 @@ function statistics_json_init(App $a) { } $statistics = [ - "name" => $a->config["sitename"], + "name" => Config::get('config', 'sitename'), "network" => FRIENDICA_PLATFORM, "version" => FRIENDICA_VERSION . "-" . DB_UPDATE_VERSION, - "registrations_open" => ($a->config['register_policy'] != 0), + "registrations_open" => Config::get('config', 'register_policy') !== REGISTER_CLOSED, "total_users" => Config::get('nodeinfo', 'total_users'), "active_users_halfyear" => Config::get('nodeinfo', 'active_users_halfyear'), "active_users_monthly" => Config::get('nodeinfo', 'active_users_monthly'), diff --git a/mod/uimport.php b/mod/uimport.php index 7d6805e7c7..660544b471 100644 --- a/mod/uimport.php +++ b/mod/uimport.php @@ -11,7 +11,7 @@ use Friendica\Core\UserImport; function uimport_post(App $a) { - switch ($a->config['register_policy']) { + switch (Config::get('config', 'register_policy')) { case REGISTER_OPEN: $blocked = 0; $verified = 1; @@ -42,7 +42,7 @@ function uimport_post(App $a) function uimport_content(App $a) { - if ((!local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) { + if ((!local_user()) && (Config::get('config', 'register_policy') === REGISTER_CLOSED)) { notice("Permission denied." . EOL); return; } diff --git a/src/Content/Nav.php b/src/Content/Nav.php index b0fe8a14e6..93090c06ec 100644 --- a/src/Content/Nav.php +++ b/src/Content/Nav.php @@ -124,7 +124,7 @@ class Nav $nav['home'] = [$homelink, L10n::t('Home'), '', L10n::t('Home Page')]; } - if (($a->config['register_policy'] == REGISTER_OPEN) && (! local_user()) && (! remote_user())) { + if ((Config::get('config', 'register_policy') === REGISTER_OPEN) && (! local_user()) && (! remote_user())) { $nav['register'] = ['register', L10n::t('Register'), '', L10n::t('Create an account')]; } diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index de3877d3f1..8237714ab6 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1,5 +1,4 @@ extractErrors($checkResults['basic']); if ($errorMessage !== '') { - throw new \RuntimeException($errorMessage); + throw new RuntimeException($errorMessage); } $this->out(" Complete!\n\n"); @@ -75,7 +77,7 @@ HELP; $errorMessage = $this->extractErrors($checkResults['db']); if ($errorMessage !== '') { - throw new \RuntimeException($errorMessage); + throw new RuntimeException($errorMessage); } $this->out(" Complete!\n\n"); @@ -86,15 +88,15 @@ HELP; $checkResults['data'] = Install::installDatabaseStructure(); if ($checkResults['data'] !== '') { - throw new \RuntimeException("ERROR: DB Database creation error. Is the DB empty?\n"); + throw new RuntimeException("ERROR: DB Database creation error. Is the DB empty?\n"); } $this->out(" Complete!\n\n"); // Install theme $this->out("Installing theme\n"); - if (!empty($a->config['system']['theme'])) { - Theme::install($a->config['system']['theme']); + if (!empty(Config::get('system', 'theme'))) { + Theme::install(Config::get('system', 'theme')); $this->out(" Complete\n\n"); } else { $this->out(" Theme setting is empty. Please check the file htconfig.php\n\n"); @@ -103,7 +105,7 @@ HELP; // Copy config file $this->out("Saving config file...\n"); if ($config_file != '.htconfig.php' && !copy($config_file, '.htconfig.php')) { - throw new \RuntimeException("ERROR: Saving config file failed. Please copy '$config_file' to '.htconfig.php' manually.\n"); + throw new RuntimeException("ERROR: Saving config file failed. Please copy '$config_file' to '.htconfig.php' manually.\n"); } $this->out(" Complete!\n\n"); $this->out("\nInstallation is finished\n"); @@ -125,10 +127,10 @@ HELP; Install::checkSmarty3($checks); Install::checkKeys($checks); - if (!empty($app->config['php_path'])) { - Install::checkPHP($app->config['php_path'], $checks); + if (!empty(Config::get('config', 'php_path'))) { + Install::checkPHP(Config::get('config', 'php_path'), $checks); } else { - throw new \RuntimeException(" ERROR: The php_path is not set in the config. Please check the file .htconfig.php.\n"); + throw new RuntimeException(" ERROR: The php_path is not set in the config.\n"); } $this->out(" NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.\n"); diff --git a/src/Database/DBStructure.php b/src/Database/DBStructure.php index 00ab09ccf2..ee46c2b4cb 100644 --- a/src/Database/DBStructure.php +++ b/src/Database/DBStructure.php @@ -53,7 +53,7 @@ class DBStructure $a = get_app(); //send the administrators an e-mail - $admin_mail_list = "'".implode("','", array_map('dbesc', explode(",", str_replace(" ", "", $a->config['admin_email']))))."'"; + $admin_mail_list = "'".implode("','", array_map('dbesc', explode(",", str_replace(" ", "", Config::get('config', 'admin_email')))))."'"; $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)", $admin_mail_list ); diff --git a/src/Model/Profile.php b/src/Model/Profile.php index c16fb745a7..92355b216e 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -138,7 +138,7 @@ class Profile $a->profile['mobile-theme'] = PConfig::get($a->profile['profile_uid'], 'system', 'mobile_theme'); $a->profile['network'] = NETWORK_DFRN; - $a->page['title'] = $a->profile['name'] . ' @ ' . $a->config['sitename']; + $a->page['title'] = $a->profile['name'] . ' @ ' . Config::get('config', 'sitename'); if (!$profiledata && !PConfig::get(local_user(), 'system', 'always_my_theme')) { $_SESSION['theme'] = $a->profile['theme']; diff --git a/src/Model/User.php b/src/Model/User.php index dc5702b605..57a3ecb50d 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -454,8 +454,8 @@ class User // Disallow somebody creating an account using openid that uses the admin email address, // since openid bypasses email verification. We'll allow it if there is not yet an admin account. - if (x($a->config, 'admin_email') && strlen($openid_url)) { - $adminlist = explode(',', str_replace(' ', '', strtolower($a->config['admin_email']))); + if (Config::get('config', 'admin_email') && strlen($openid_url)) { + $adminlist = explode(',', str_replace(' ', '', strtolower(Config::get('config', 'admin_email')))); if (in_array(strtolower($email), $adminlist)) { throw new Exception(L10n::t('Cannot use that email.')); } diff --git a/src/Module/Login.php b/src/Module/Login.php index 4df03f26dc..46cb3a85d2 100644 --- a/src/Module/Login.php +++ b/src/Module/Login.php @@ -43,7 +43,7 @@ class Login extends BaseModule goaway(self::getApp()->get_baseurl()); } - return self::form(self::getApp()->get_baseurl(), $a->config['register_policy'] != REGISTER_CLOSED); + return self::form(self::getApp()->get_baseurl(), Config::get('config', 'register_policy') !== REGISTER_CLOSED); } public static function post() @@ -266,7 +266,7 @@ class Login extends BaseModule * @param string $return_url The url relative to the base the user should be sent * back to after login completes * @param bool $register If $register == true provide a registration link. - * This will most always depend on the value of $a->config['register_policy']. + * This will most always depend on the value of config.register_policy. * @param array $hiddens optional * * @return string Returns the complete html for inserting into the page diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index 36f3faf2de..f4b299761d 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -1269,7 +1269,7 @@ class OStatus XML::addElement($doc, $root, "generator", FRIENDICA_PLATFORM, $attributes); XML::addElement($doc, $root, "id", System::baseUrl() . "/profile/" . $owner["nick"]); XML::addElement($doc, $root, "title", $title); - XML::addElement($doc, $root, "subtitle", sprintf("Updates from %s on %s", $owner["name"], $a->config["sitename"])); + XML::addElement($doc, $root, "subtitle", sprintf("Updates from %s on %s", $owner["name"], Config::get('config', 'sitename'))); XML::addElement($doc, $root, "logo", $owner["photo"]); XML::addElement($doc, $root, "updated", DateTimeFormat::utcNow(DateTimeFormat::ATOM)); diff --git a/view/theme/frio/theme.php b/view/theme/frio/theme.php index 9d2b77d1f1..f2cbb7e6ac 100644 --- a/view/theme/frio/theme.php +++ b/view/theme/frio/theme.php @@ -268,7 +268,7 @@ function frio_remote_nav($a, &$nav) $nav['messages'] = [$server_url . '/message', L10n::t('Messages'), '', L10n::t('Private mail')]; $nav['settings'] = [$server_url . '/settings', L10n::t('Settings'), '', L10n::t('Account settings')]; $nav['contacts'] = [$server_url . '/contacts', L10n::t('Contacts'), '', L10n::t('Manage/edit friends and contacts')]; - $nav['sitename'] = $a->config['sitename']; + $nav['sitename'] = Config::get('config', 'sitename'); } } From fc5d8e41a4a154a6ff13e8b118d03d7d01246df1 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 7 Jul 2018 17:46:51 -0400 Subject: [PATCH 41/81] [tests] Prevent bin/worker.php from being called during tests --- tests/bootstrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index e566b58042..6a4f778024 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -13,7 +13,7 @@ require_once __DIR__.'/../include/api.php'; new App(dirname(__DIR__)); -\Friendica\Core\Config::set('system', 'url', 'http://localhost/'); +\Friendica\Core\Config::set('system', 'worker_dont_fork', true); // Backward compatibility if (!class_exists(TestCase::class)) { From 9be9741562a37dd83f67a6cd760f2be3fb292cd4 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 7 Jul 2018 17:55:06 -0400 Subject: [PATCH 42/81] Fix uses in include/dba --- include/dba.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/dba.php b/include/dba.php index 0d8eeef3d5..3850cb097c 100644 --- a/include/dba.php +++ b/include/dba.php @@ -1,7 +1,6 @@ Date: Sat, 7 Jul 2018 18:03:45 -0400 Subject: [PATCH 43/81] Remove direct App instantiation from tests --- tests/src/Core/Cache/CacheTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/Core/Cache/CacheTest.php b/tests/src/Core/Cache/CacheTest.php index 5be0e4b893..a2724c12b0 100644 --- a/tests/src/Core/Cache/CacheTest.php +++ b/tests/src/Core/Cache/CacheTest.php @@ -23,7 +23,7 @@ abstract class CacheTest extends DatabaseTest $this->instance = $this->getInstance(); // Reusable App object - $this->app = new App(__DIR__.'/../'); + $this->app = \Friendica\BaseObject::getApp(); $a = $this->app; // Default config From 47992d06cee2542b2c7cf00ad775bb91cb78b6cb Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 7 Jul 2018 18:03:59 -0400 Subject: [PATCH 44/81] Restore system.url declaration in tests --- tests/bootstrap.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 6a4f778024..6c04450b6a 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -13,6 +13,7 @@ require_once __DIR__.'/../include/api.php'; new App(dirname(__DIR__)); +\Friendica\Core\Config::set('system', 'url', 'http://localhost'); \Friendica\Core\Config::set('system', 'worker_dont_fork', true); // Backward compatibility From 9396b056594c6a3233ccace070c73e0acae859e6 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 8 Jul 2018 01:45:22 -0400 Subject: [PATCH 45/81] Revert using Config class in dba --- include/dba.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/include/dba.php b/include/dba.php index 3850cb097c..f6120f673f 100644 --- a/include/dba.php +++ b/include/dba.php @@ -1,6 +1,9 @@ getConfigVariable() instead. +//use Friendica\Core\Config; + use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Database\DBStructure; @@ -383,7 +386,7 @@ class dba { $orig_sql = $sql; - if (Config::get('system', 'db_callstack')) { + if ($a->getConfigValue('system', 'db_callstack')) { $sql = "/*".System::callstack()." */ ".$sql; } @@ -544,15 +547,15 @@ class dba { $a->save_timestamp($stamp1, 'database'); - if (Config::get('system', 'db_log')) { + if ($a->getConfigValue('system', 'db_log')) { $stamp2 = microtime(true); $duration = (float)($stamp2 - $stamp1); - if (($duration > Config::get('system', 'db_loglimit'))) { + if (($duration > $a->getConfigValue('system', 'db_loglimit'))) { $duration = round($duration, 3); $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); - @file_put_contents(Config::get('system', 'db_log'), DateTimeFormat::utcNow()."\t".$duration."\t". + @file_put_contents($a->getConfigValue('system', 'db_log'), DateTimeFormat::utcNow()."\t".$duration."\t". basename($backtrace[1]["file"])."\t". $backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t". substr(self::replaceParameters($sql, $args), 0, 2000)."\n", FILE_APPEND); From 59c38d1b731fec295a08d88be3535496f6219724 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 8 Jul 2018 01:46:06 -0400 Subject: [PATCH 46/81] Move meaningful message inside Exception thrown in Cache tests --- tests/src/Core/Cache/MemcacheCacheDriverTest.php | 3 +-- tests/src/Core/Cache/MemcachedCacheDriverTest.php | 3 +-- tests/src/Core/Cache/RedisCacheDriverTest.php | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/src/Core/Cache/MemcacheCacheDriverTest.php b/tests/src/Core/Cache/MemcacheCacheDriverTest.php index d2078236e2..5ed0a3a2e5 100644 --- a/tests/src/Core/Cache/MemcacheCacheDriverTest.php +++ b/tests/src/Core/Cache/MemcacheCacheDriverTest.php @@ -19,8 +19,7 @@ class MemcacheCacheDriverTest extends MemoryCacheTest try { $this->cache = CacheDriverFactory::create('memcache'); } catch (\Exception $exception) { - print "Memcache - TestCase failed: " . $exception->getMessage(); - throw new \Exception(); + throw new \Exception("Memcache - TestCase failed: " . $exception->getMessage(), $exception->getCode(), $exception); } return $this->cache; } else { diff --git a/tests/src/Core/Cache/MemcachedCacheDriverTest.php b/tests/src/Core/Cache/MemcachedCacheDriverTest.php index 2484517424..4872546b54 100644 --- a/tests/src/Core/Cache/MemcachedCacheDriverTest.php +++ b/tests/src/Core/Cache/MemcachedCacheDriverTest.php @@ -19,8 +19,7 @@ class MemcachedCacheDriverTest extends MemoryCacheTest try { $this->cache = CacheDriverFactory::create('memcached'); } catch (\Exception $exception) { - print "Memcached - TestCase failed: " . $exception->getMessage(); - throw new \Exception(); + throw new \Exception("Memcached - TestCase failed: " . $exception->getMessage(), $exception->getCode(), $exception); } return $this->cache; } else { diff --git a/tests/src/Core/Cache/RedisCacheDriverTest.php b/tests/src/Core/Cache/RedisCacheDriverTest.php index e13d95df4d..158534602a 100644 --- a/tests/src/Core/Cache/RedisCacheDriverTest.php +++ b/tests/src/Core/Cache/RedisCacheDriverTest.php @@ -19,8 +19,7 @@ class RedisCacheDriverTest extends MemoryCacheTest try { $this->cache = CacheDriverFactory::create('redis'); } catch (\Exception $exception) { - print "Redis - TestCase failed: " . $exception->getMessage(); - throw new \Exception(); + throw new \Exception("Redis - TestCase failed: " . $exception->getMessage(), $exception->getCode(), $exception); } return $this->cache; } else { From 8fe9a46ccf4e7a4fdc1210c09041e447b3cb67c3 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 8 Jul 2018 01:46:22 -0400 Subject: [PATCH 47/81] Set system.hostname in test bootstrap --- tests/bootstrap.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 6c04450b6a..4bc3e932f0 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -14,6 +14,7 @@ require_once __DIR__.'/../include/api.php'; new App(dirname(__DIR__)); \Friendica\Core\Config::set('system', 'url', 'http://localhost'); +\Friendica\Core\Config::set('system', 'hostname', 'localhost'); \Friendica\Core\Config::set('system', 'worker_dont_fork', true); // Backward compatibility From 6b03ae92b811b89cfba137d20f08a320ea83370e Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 8 Jul 2018 01:46:46 -0400 Subject: [PATCH 48/81] Fix Memached config value format usage --- src/Core/Cache/MemcachedCacheDriver.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Core/Cache/MemcachedCacheDriver.php b/src/Core/Cache/MemcachedCacheDriver.php index 870219854a..8b752fb3a8 100644 --- a/src/Core/Cache/MemcachedCacheDriver.php +++ b/src/Core/Cache/MemcachedCacheDriver.php @@ -22,6 +22,16 @@ class MemcachedCacheDriver extends AbstractCacheDriver implements IMemoryCacheDr */ private $memcached; + /** + * Due to limitations of the INI format, the expected configuration for Memcached servers is the following: + * array { + * 0 => "hostname, port(, weight)", + * 1 => ... + * } + * + * @param array $memcached_hosts + * @throws \Exception + */ public function __construct(array $memcached_hosts) { if (!class_exists('Memcached', false)) { @@ -30,6 +40,10 @@ class MemcachedCacheDriver extends AbstractCacheDriver implements IMemoryCacheDr $this->memcached = new Memcached(); + array_walk($memcached_hosts, function (&$value) { + $value = array_map('trim', explode(',', $value)); + }); + $this->memcached->addServers($memcached_hosts); if (count($this->memcached->getServerList()) == 0) { From 4efcd4780796685bb263ad3630ef44aba3b0fc61 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 8 Jul 2018 01:59:52 -0400 Subject: [PATCH 49/81] Put base test config in Yaml dataset --- tests/datasets/api.yml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/datasets/api.yml b/tests/datasets/api.yml index 25c9dade60..124c6b0d54 100644 --- a/tests/datasets/api.yml +++ b/tests/datasets/api.yml @@ -1,13 +1,27 @@ --- # Empty these tables cache: -config: conversation: pconfig: photo: workerqueue: mail: +# Base test config to avoid notice messages +config: + - + cat: system + k: url + v: http://localhost + - + cat: system + k: hostname + v: localhost + - + cat: system + k: worker_dont_fork + v: 1 + # Populate tables with test data user: - From de0afd3b3280c560f72928d9ead008a5910a9798 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 8 Jul 2018 02:32:51 -0400 Subject: [PATCH 50/81] Add api test debug --- include/api.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/api.php b/include/api.php index 4e8e9c2323..f5b887b8ce 100644 --- a/include/api.php +++ b/include/api.php @@ -772,6 +772,9 @@ function api_get_user(App $a, $contact_id = null) $theme_info = dba::selectFirst('user', ['theme'], ['uid' => $ret['uid']]); if ($theme_info['theme'] === 'frio') { $schema = PConfig::get($ret['uid'], 'frio', 'schema'); + + var_dump($ret['uid'], $schema, $a->config); + if ($schema && ($schema != '---')) { if (file_exists('view/theme/frio/schema/'.$schema.'.php')) { $schemefile = 'view/theme/frio/schema/'.$schema.'.php'; From f8a90f3425b80b75156eb7762d654a2d8c659f18 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 8 Jul 2018 02:49:12 -0400 Subject: [PATCH 51/81] Add more api test debug --- include/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/api.php b/include/api.php index f5b887b8ce..9dfc7c2652 100644 --- a/include/api.php +++ b/include/api.php @@ -773,7 +773,7 @@ function api_get_user(App $a, $contact_id = null) if ($theme_info['theme'] === 'frio') { $schema = PConfig::get($ret['uid'], 'frio', 'schema'); - var_dump($ret['uid'], $schema, $a->config); + var_dump($ret['uid'], $schema, $a->config, dba::inArray(dba::select('config', []))); if ($schema && ($schema != '---')) { if (file_exists('view/theme/frio/schema/'.$schema.'.php')) { From 224765cdf5cd0ea757b8a998e8425e7ff8a25f90 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 8 Jul 2018 02:57:00 -0400 Subject: [PATCH 52/81] Wrong table name --- include/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/api.php b/include/api.php index 9dfc7c2652..9867899834 100644 --- a/include/api.php +++ b/include/api.php @@ -773,7 +773,7 @@ function api_get_user(App $a, $contact_id = null) if ($theme_info['theme'] === 'frio') { $schema = PConfig::get($ret['uid'], 'frio', 'schema'); - var_dump($ret['uid'], $schema, $a->config, dba::inArray(dba::select('config', []))); + var_dump($ret['uid'], $schema, $a->config, dba::inArray(dba::select('pconfig', []))); if ($schema && ($schema != '---')) { if (file_exists('view/theme/frio/schema/'.$schema.'.php')) { From 6987129a0072a1c83b262784a4f9eccdafa42888 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 8 Jul 2018 03:07:38 -0400 Subject: [PATCH 53/81] Add yet more pconfig debug to testApiGetUserWithCustomFrioSchema --- tests/ApiTest.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/ApiTest.php b/tests/ApiTest.php index c8443512c8..7e7aeea654 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -719,10 +719,15 @@ class ApiTest extends DatabaseTest */ public function testApiGetUserWithCustomFrioSchema() { - PConfig::set($this->selfUser['id'], 'frio', 'schema', '---'); - PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456'); - PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456'); - PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456'); + var_dump($this->app->mode, \Friendica\App::MODE_DBCONFIGAVAILABLE, $this->app->mode & \Friendica\App::MODE_DBCONFIGAVAILABLE); + + $ret1 = PConfig::set($this->selfUser['id'], 'frio', 'schema', '---'); + $ret2 = PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456'); + $ret3 = PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456'); + $ret4 = PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456'); + + var_dump($ret1, $ret2, $ret3, $ret4, dba::inArray(dba::select('pconfig', []))); + $user = api_get_user($this->app); $this->assertSelfUser($user); $this->assertEquals('123456', $user['profile_sidebar_fill_color']); From 478b42e88f25ee499090ded1c368f00b7e3210c7 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 8 Jul 2018 03:16:20 -0400 Subject: [PATCH 54/81] Fix debug --- tests/ApiTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ApiTest.php b/tests/ApiTest.php index 7e7aeea654..e94ab05ed4 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -726,7 +726,7 @@ class ApiTest extends DatabaseTest $ret3 = PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456'); $ret4 = PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456'); - var_dump($ret1, $ret2, $ret3, $ret4, dba::inArray(dba::select('pconfig', []))); + var_dump($ret1, $ret2, $ret3, $ret4, \dba::inArray(\dba::select('pconfig', []))); $user = api_get_user($this->app); $this->assertSelfUser($user); From 7b8410f5efe604963ef825b8af0b41ec1fe6f92c Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 8 Jul 2018 03:16:38 -0400 Subject: [PATCH 55/81] Fix wrong mode for App since local conf file wasn't present --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 7419ecbfbe..6d133a0b4a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,9 @@ env: install: - composer install before_script: + - cp config/local-sample.ini.php config/local.ini.php - mysql -e 'CREATE DATABASE IF NOT EXISTS test;' - mysql -utravis test < database.sql - echo "extension=redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - echo "extension=memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini + From 5906c7e013ccdc369b56427f9f7f92662fe6b2cd Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 8 Jul 2018 03:28:29 -0400 Subject: [PATCH 56/81] Remove api test pconfig debug --- include/api.php | 2 -- tests/ApiTest.php | 5 ----- 2 files changed, 7 deletions(-) diff --git a/include/api.php b/include/api.php index 9867899834..d307afa953 100644 --- a/include/api.php +++ b/include/api.php @@ -773,8 +773,6 @@ function api_get_user(App $a, $contact_id = null) if ($theme_info['theme'] === 'frio') { $schema = PConfig::get($ret['uid'], 'frio', 'schema'); - var_dump($ret['uid'], $schema, $a->config, dba::inArray(dba::select('pconfig', []))); - if ($schema && ($schema != '---')) { if (file_exists('view/theme/frio/schema/'.$schema.'.php')) { $schemefile = 'view/theme/frio/schema/'.$schema.'.php'; diff --git a/tests/ApiTest.php b/tests/ApiTest.php index e94ab05ed4..c33ee6bfaf 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -719,15 +719,10 @@ class ApiTest extends DatabaseTest */ public function testApiGetUserWithCustomFrioSchema() { - var_dump($this->app->mode, \Friendica\App::MODE_DBCONFIGAVAILABLE, $this->app->mode & \Friendica\App::MODE_DBCONFIGAVAILABLE); - $ret1 = PConfig::set($this->selfUser['id'], 'frio', 'schema', '---'); $ret2 = PConfig::set($this->selfUser['id'], 'frio', 'nav_bg', '#123456'); $ret3 = PConfig::set($this->selfUser['id'], 'frio', 'link_color', '#123456'); $ret4 = PConfig::set($this->selfUser['id'], 'frio', 'background_color', '#123456'); - - var_dump($ret1, $ret2, $ret3, $ret4, \dba::inArray(\dba::select('pconfig', []))); - $user = api_get_user($this->app); $this->assertSelfUser($user); $this->assertEquals('123456', $user['profile_sidebar_fill_color']); From 627fa08a1ba95f06b9d50a223f87440bfb5ba938 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 9 Jul 2018 09:22:01 -0400 Subject: [PATCH 57/81] Chasing a segfault in PHP 5.6 tests --- config/defaults.ini.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/config/defaults.ini.php b/config/defaults.ini.php index cd17347410..84c039c2a0 100644 --- a/config/defaults.ini.php +++ b/config/defaults.ini.php @@ -76,11 +76,11 @@ addon = ; allowed_link_protocols (Array) ; Allowed protocols in links URLs, add at your own risk. http is always allowed. -allowed_link_protocols[] = ftp -allowed_link_protocols[] = ftps -allowed_link_protocols[] = mailto -allowed_link_protocols[] = cid -allowed_link_protocols[] = gopher +allowed_link_protocols[0] = ftp +allowed_link_protocols[1] = ftps +allowed_link_protocols[2] = mailto +allowed_link_protocols[3] = cid +allowed_link_protocols[4] = gopher ; always_show_preview (Boolean) ; Only show small preview picures. @@ -297,7 +297,7 @@ memcache_port = 11211 ; memcached_hosts (Array) ; Array of Memcached servers info "host, port(, weight)". -memcached_hosts[] = 127.0.0.1, 11211 +memcached_hosts[0] = 127.0.0.1,11211 ; redis_host (String) ; Host name of the redis daemon. From 4161908f43a6861884ee23a17257da843aa8b22f Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 9 Jul 2018 21:53:19 -0400 Subject: [PATCH 58/81] Fix formatting in mod/help --- mod/help.php | 92 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 54 insertions(+), 38 deletions(-) diff --git a/mod/help.php b/mod/help.php index 981fe97f70..ef640737aa 100644 --- a/mod/help.php +++ b/mod/help.php @@ -2,31 +2,32 @@ /** * @file mod/help.php */ + use Friendica\App; use Friendica\Content\Nav; use Friendica\Content\Text\Markdown; use Friendica\Core\L10n; use Friendica\Core\System; -if (!function_exists('load_doc_file')) { - - function load_doc_file($s) { - global $lang; - if (!isset($lang)) - $lang = 'en'; - $b = basename($s); - $d = dirname($s); - if (file_exists("$d/$lang/$b")) - return file_get_contents("$d/$lang/$b"); - if (file_exists($s)) - return file_get_contents($s); - return ''; +function load_doc_file($s) +{ + global $lang; + if (!isset($lang)) $lang = 'en'; + $b = basename($s); + $d = dirname($s); + if (file_exists("$d/$lang/$b")) { + return file_get_contents("$d/$lang/$b"); } + if (file_exists($s)) { + return file_get_contents($s); + } + + return ''; } -function help_content(App $a) { - +function help_content(App $a) +{ Nav::setSelected('help'); global $lang; @@ -37,9 +38,11 @@ function help_content(App $a) { $path = ''; // looping through the argv keys bigger than 0 to build // a path relative to /help - for($x = 1; $x < argc(); $x ++) { - if(strlen($path)) + for ($x = 1; $x < argc(); $x ++) { + if (strlen($path)) { $path .= '/'; + } + $path .= argv($x); } $title = basename($path); @@ -47,6 +50,7 @@ function help_content(App $a) { $text = load_doc_file('doc/' . $path . '.md'); $a->page['title'] = L10n::t('Help:') . ' ' . str_replace('-', ' ', notags($title)); } + $home = load_doc_file('doc/Home.md'); if (!$text) { $text = $home; @@ -60,8 +64,8 @@ function help_content(App $a) { header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . L10n::t('Not Found')); $tpl = get_markup_template("404.tpl"); return replace_macros($tpl, [ - '$message' => L10n::t('Page not found.') - ]); + '$message' => L10n::t('Page not found.') + ]); } $html = Markdown::convert($text, false); @@ -69,34 +73,46 @@ function help_content(App $a) { if ($filename !== "Home") { // create TOC but not for home $lines = explode("\n", $html); - $toc="

TOC

    "; - $lastlevel=1; - $idnum = [0,0,0,0,0,0,0]; - foreach($lines as &$line){ - if (substr($line,0,2)=="$lastlevel) $toc.="
      "; - $idnum[$level]++; - $id = implode("_", array_slice($idnum,1,$level)); - $href = System::baseUrl()."/help/{$filename}#{$id}"; - $toc .= "
    • ".strip_tags($line)."
    • "; - $line = "".$line; + + if ($level > $lastlevel) { + $toc .= "
        "; + } + + $idnum[$level] ++; + $id = implode("_", array_slice($idnum, 1, $level)); + $href = System::baseUrl() . "/help/{$filename}#{$id}"; + $toc .= "
      • " . strip_tags($line) . "
      • "; + $line = "" . $line; $lastlevel = $level; } } } - for($k=0;$k<$lastlevel; $k++) $toc.="
      "; - $html = implode("\n",$lines); + + for ($k = 0; $k < $lastlevel; $k++) { + $toc .= "
    "; + } + + $html = implode("\n", $lines); $a->page['aside'] = '
    ' . $toc . '
    ' . $a->page['aside'] . '
    '; } return $html; - } From adacf421a66228948f8805d2310efdf01b5ceb93 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 9 Jul 2018 22:11:39 -0400 Subject: [PATCH 59/81] Remove deprecated functions in include/text --- include/text.php | 80 ------------------------------------------------ 1 file changed, 80 deletions(-) diff --git a/include/text.php b/include/text.php index d48986161d..679873b532 100644 --- a/include/text.php +++ b/include/text.php @@ -462,86 +462,6 @@ function perms2str($p) { return $ret; } -/** - * @deprecated - * wrapper to load a view template, checking for alternate - * languages before falling back to the default - * - * @global string $lang - * @global App $a - * @param string $s view name - * @return string - */ -function load_view_file($s) { - global $lang, $a; - if (!isset($lang)) { - $lang = 'en'; - } - $b = basename($s); - $d = dirname($s); - if (file_exists("$d/$lang/$b")) { - $stamp1 = microtime(true); - $content = file_get_contents("$d/$lang/$b"); - $a->save_timestamp($stamp1, "file"); - return $content; - } - - $theme = $a->getCurrentTheme(); - - if (file_exists("$d/theme/$theme/$b")) { - $stamp1 = microtime(true); - $content = file_get_contents("$d/theme/$theme/$b"); - $a->save_timestamp($stamp1, "file"); - return $content; - } - - $stamp1 = microtime(true); - $content = file_get_contents($s); - $a->save_timestamp($stamp1, "file"); - return $content; -} - - -/** - * load a view template, checking for alternate - * languages before falling back to the default - * - * @global string $lang - * @param string $s view path - * @return string - */ -function get_intltext_template($s) { - global $lang; - - $a = get_app(); - $engine = ''; - if ($a->theme['template_engine'] === 'smarty3') { - $engine = "/smarty3"; - } - - if (!isset($lang)) { - $lang = 'en'; - } - - if (file_exists("view/lang/$lang$engine/$s")) { - $stamp1 = microtime(true); - $content = file_get_contents("view/lang/$lang$engine/$s"); - $a->save_timestamp($stamp1, "file"); - return $content; - } elseif (file_exists("view/lang/en$engine/$s")) { - $stamp1 = microtime(true); - $content = file_get_contents("view/lang/en$engine/$s"); - $a->save_timestamp($stamp1, "file"); - return $content; - } else { - $stamp1 = microtime(true); - $content = file_get_contents("view$engine/$s"); - $a->save_timestamp($stamp1, "file"); - return $content; - } -} - - /** * load template $s * From d0780ccf7dd3efb5337912dcf293617bea495d2a Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 9 Jul 2018 22:37:51 -0400 Subject: [PATCH 60/81] Replace global $lang with system.language --- config/defaults.ini.php | 2 +- mod/help.php | 6 ++---- mod/register.php | 4 +--- mod/regmod.php | 2 -- src/Content/Text/HTML.php | 2 -- src/Core/L10n.php | 26 ++++++++++++-------------- 6 files changed, 16 insertions(+), 26 deletions(-) diff --git a/config/defaults.ini.php b/config/defaults.ini.php index 84c039c2a0..2f1357e3aa 100644 --- a/config/defaults.ini.php +++ b/config/defaults.ini.php @@ -209,7 +209,7 @@ invitation_only = false jpeg_quality = 100 ; language (String) -; Admin-created user default language. +; System default languague, inluding admin-created user default language. ; Two-letters ISO 639-1 code. language = en diff --git a/mod/help.php b/mod/help.php index ef640737aa..5db74c15e8 100644 --- a/mod/help.php +++ b/mod/help.php @@ -6,13 +6,13 @@ use Friendica\App; use Friendica\Content\Nav; use Friendica\Content\Text\Markdown; +use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\System; function load_doc_file($s) { - global $lang; - if (!isset($lang)) $lang = 'en'; + $lang = Config::get('system', 'language'); $b = basename($s); $d = dirname($s); if (file_exists("$d/$lang/$b")) { @@ -30,8 +30,6 @@ function help_content(App $a) { Nav::setSelected('help'); - global $lang; - $text = ''; if ($a->argc > 1) { diff --git a/mod/register.php b/mod/register.php index 75f2ec8532..53bca68405 100644 --- a/mod/register.php +++ b/mod/register.php @@ -21,8 +21,6 @@ function register_post(App $a) { check_form_security_token_redirectOnErr('/register', 'register'); - global $lang; - $verified = 0; $blocked = 1; @@ -123,7 +121,7 @@ function register_post(App $a) dbesc(DateTimeFormat::utcNow()), intval($user['uid']), dbesc($result['password']), - dbesc($lang), + dbesc(Config::get('system', 'language')), dbesc($_POST['permonlybox']) ); diff --git a/mod/regmod.php b/mod/regmod.php index 083465984f..2a418fcda0 100644 --- a/mod/regmod.php +++ b/mod/regmod.php @@ -97,8 +97,6 @@ function user_deny($hash) function regmod_content(App $a) { - global $lang; - if (!local_user()) { info(L10n::t('Please login.') . EOL); $o = '

    ' . Login::form($a->query_string, Config::get('config', 'register_policy') === REGISTER_CLOSED ? 0 : 1); diff --git a/src/Content/Text/HTML.php b/src/Content/Text/HTML.php index 896db876f5..d6e699ed7b 100644 --- a/src/Content/Text/HTML.php +++ b/src/Content/Text/HTML.php @@ -549,8 +549,6 @@ class HTML public static function toPlaintext($html, $wraplength = 75, $compact = false) { - global $lang; - $message = str_replace("\r", "", $html); $doc = new DOMDocument(); diff --git a/src/Core/L10n.php b/src/Core/L10n.php index 24be010955..2389817021 100644 --- a/src/Core/L10n.php +++ b/src/Core/L10n.php @@ -14,7 +14,7 @@ require_once 'include/dba.php'; * Provide Languange, Translation, and Localisation functions to the application * Localisation can be referred to by the numeronym L10N (as in: "L", followed by ten more letters, and then "N"). */ -class L10n +class L10n extends \Friendica\BaseObject { /** * @brief get the prefered language from the HTTP_ACCEPT_LANGUAGE header @@ -62,11 +62,11 @@ class L10n */ public static function pushLang($language) { - global $lang, $a; + $a = self::getApp(); - $a->langsave = $lang; + $a->langsave = Config::get('system', 'language'); - if ($language === $lang) { + if ($language === $a->langsave) { return; } @@ -75,7 +75,7 @@ class L10n } $a->strings = []; self::loadTranslationTable($language); - $lang = $language; + Config::set('system', 'language', $language); } /** @@ -83,9 +83,9 @@ class L10n */ public static function popLang() { - global $lang, $a; + $a = self::getApp(); - if ($lang === $a->langsave) { + if (Config::get('system', 'language') === $a->langsave) { return; } @@ -95,7 +95,7 @@ class L10n $a->strings = []; } - $lang = $a->langsave; + Config::set('system', 'language', $a->langsave); } /** @@ -107,7 +107,7 @@ class L10n */ public static function loadTranslationTable($lang) { - $a = get_app(); + $a = self::getApp(); $a->strings = []; // load enabled addons strings @@ -142,7 +142,7 @@ class L10n */ public static function t($s, ...$vars) { - $a = get_app(); + $a = self::getApp(); if (empty($s)) { return ''; @@ -173,7 +173,6 @@ class L10n * - L10n::tt('Like', 'Likes', $count) * - L10n::tt("%s user deleted", "%s users deleted", count($users)) * - * @global type $lang * @param string $singular * @param string $plural * @param int $count @@ -181,10 +180,9 @@ class L10n */ public static function tt($singular, $plural, $count) { - global $lang; - $a = get_app(); + $lang = Config::get('system', 'language'); - if (x($a->strings, $singular)) { + if (!empty($a->strings[$singular])) { $t = $a->strings[$singular]; if (is_array($t)) { $plural_function = 'string_plural_select_' . str_replace('-', '_', $lang); From 820afa2284eb603c286921a302d5b827a1b47b9e Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 9 Jul 2018 22:39:59 -0400 Subject: [PATCH 61/81] Replace global $a with BaseObject::getApp() --- include/text.php | 3 --- mod/admin.php | 2 -- src/Worker/CheckVersion.php | 8 ++++---- src/Worker/Cron.php | 8 +++++--- src/Worker/CronJobs.php | 2 +- src/Worker/DBUpdate.php | 8 +++++--- src/Worker/DiscoverPoCo.php | 5 ++--- src/Worker/Expire.php | 8 +++++--- src/Worker/ForkHook.php | 8 +++++--- src/Worker/Notifier.php | 8 +++++--- src/Worker/OnePoll.php | 11 +++++++---- src/Worker/PubSubPublish.php | 8 +++++--- src/Worker/Queue.php | 2 -- src/Worker/UpdateGContact.php | 2 -- tests/ApiTest.php | 17 +++++++---------- tests/src/Core/Cache/CacheTest.php | 3 --- tests/src/Core/Lock/LockTest.php | 4 ---- 17 files changed, 51 insertions(+), 56 deletions(-) diff --git a/include/text.php b/include/text.php index 679873b532..6aa0c9d2dd 100644 --- a/include/text.php +++ b/include/text.php @@ -519,7 +519,6 @@ $LOGGER_LEVELS = []; * LOGGER_DATA * LOGGER_ALL * - * @global App $a * @global array $LOGGER_LEVELS * @param string $msg * @param int $level @@ -590,12 +589,10 @@ function logger($msg, $level = 0) { * LOGGER_DATA * LOGGER_ALL * - * @global App $a * @global array $LOGGER_LEVELS * @param string $msg * @param int $level */ - function dlogger($msg, $level = 0) { $a = get_app(); diff --git a/mod/admin.php b/mod/admin.php index c90eb3c5eb..da50007131 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -944,8 +944,6 @@ function admin_page_site_post(App $a) function update_table($table_name, $fields, $old_url, $new_url) { - global $a; - $dbold = dbesc($old_url); $dbnew = dbesc($new_url); diff --git a/src/Worker/CheckVersion.php b/src/Worker/CheckVersion.php index a6056ccbc4..e37e37a060 100644 --- a/src/Worker/CheckVersion.php +++ b/src/Worker/CheckVersion.php @@ -16,10 +16,10 @@ use Friendica\Util\Network; * Checking the upstream version is optional (opt-in) and can be done to either * the master or the develop branch in the repository. */ -class CheckVersion { - public static function execute() { - global $a; - +class CheckVersion +{ + public static function execute() + { logger('checkversion: start'); $checkurl = Config::get('system', 'check_new_version_url', 'none'); diff --git a/src/Worker/Cron.php b/src/Worker/Cron.php index e425c03508..a0dfda3309 100644 --- a/src/Worker/Cron.php +++ b/src/Worker/Cron.php @@ -13,9 +13,11 @@ use dba; require_once 'include/dba.php'; -Class Cron { - public static function execute($parameter = '', $generation = 0) { - global $a; +class Cron +{ + public static function execute($parameter = '', $generation = 0) + { + $a = \Friendica\BaseObject::getApp(); // Poll contacts with specific parameters if (!empty($parameter)) { diff --git a/src/Worker/CronJobs.php b/src/Worker/CronJobs.php index 80839874da..8b9d3b9bcf 100644 --- a/src/Worker/CronJobs.php +++ b/src/Worker/CronJobs.php @@ -24,7 +24,7 @@ class CronJobs { public static function execute($command = '') { - global $a; + $a = \Friendica\BaseObject::getApp(); // No parameter set? So return if ($command == '') { diff --git a/src/Worker/DBUpdate.php b/src/Worker/DBUpdate.php index 5f85c8ebef..ed8e409e98 100644 --- a/src/Worker/DBUpdate.php +++ b/src/Worker/DBUpdate.php @@ -7,9 +7,11 @@ namespace Friendica\Worker; use Friendica\Core\Config; -class DBUpdate { - public static function execute() { - $a = get_app(); +class DBUpdate +{ + public static function execute() + { + $a = \Friendica\BaseObject::getApp(); // We are deleting the latest dbupdate entry. // This is done to avoid endless loops because the update was interupted. diff --git a/src/Worker/DiscoverPoCo.php b/src/Worker/DiscoverPoCo.php index f0335bc8e4..c77830d60a 100644 --- a/src/Worker/DiscoverPoCo.php +++ b/src/Worker/DiscoverPoCo.php @@ -15,7 +15,8 @@ use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; use dba; -class DiscoverPoCo { +class DiscoverPoCo +{ /// @todo Clean up this mess of a parameter hell and split it in several classes public static function execute($command = '', $param1 = '', $param2 = '', $param3 = '', $param4 = '') { @@ -276,8 +277,6 @@ class DiscoverPoCo { // It is not removed since I hope that there will be a successor. return false; - $a = get_app(); - $url = "http://gstools.org/api/users_search/".urlencode($search); $result = Network::curl($url); diff --git a/src/Worker/Expire.php b/src/Worker/Expire.php index 6cc333dd05..685fad49e8 100644 --- a/src/Worker/Expire.php +++ b/src/Worker/Expire.php @@ -15,9 +15,11 @@ use dba; require_once 'include/dba.php'; -class Expire { - public static function execute($param = '', $hook_name = '') { - global $a; +class Expire +{ + public static function execute($param = '', $hook_name = '') + { + $a = \Friendica\BaseObject::getApp(); require_once 'include/items.php'; diff --git a/src/Worker/ForkHook.php b/src/Worker/ForkHook.php index 6c138bace4..3654bdd3ca 100644 --- a/src/Worker/ForkHook.php +++ b/src/Worker/ForkHook.php @@ -7,9 +7,11 @@ namespace Friendica\Worker; use Friendica\Core\Addon; -Class ForkHook { - public static function execute($name, $hook, $data) { - global $a; +Class ForkHook +{ + public static function execute($name, $hook, $data) + { + $a = \Friendica\BaseObject::getApp(); Addon::callSingleHook($a, $name, $hook, $data); } diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 6c3717200b..385892f991 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -48,9 +48,11 @@ require_once 'include/items.php'; * and ITEM_ID is the id of the item in the database that needs to be sent to others. */ -class Notifier { - public static function execute($cmd, $item_id) { - global $a; +class Notifier +{ + public static function execute($cmd, $item_id) + { + $a = \Friendica\BaseObject::getApp(); logger('notifier: invoked: '.$cmd.': '.$item_id, LOGGER_DEBUG); diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php index eaef5f252d..951a20b012 100644 --- a/src/Worker/OnePoll.php +++ b/src/Worker/OnePoll.php @@ -21,8 +21,9 @@ require_once 'include/dba.php'; class OnePoll { - public static function execute($contact_id = 0, $command = '') { - global $a; + public static function execute($contact_id = 0, $command = '') + { + $a = \Friendica\BaseObject::getApp(); require_once 'include/items.php'; @@ -634,7 +635,8 @@ class OnePoll return; } - private static function RemoveReply($subject) { + private static function RemoveReply($subject) + { while (in_array(strtolower(substr($subject, 0, 3)), ["re:", "aw:"])) { $subject = trim(substr($subject, 4)); } @@ -648,7 +650,8 @@ class OnePoll * @param array $contact The personal contact entry * @param array $fields The fields that are updated */ - private static function updateContact($contact, $fields) { + private static function updateContact($contact, $fields) + { dba::update('contact', $fields, ['id' => $contact['id']]); dba::update('contact', $fields, ['uid' => 0, 'nurl' => $contact['nurl']]); } diff --git a/src/Worker/PubSubPublish.php b/src/Worker/PubSubPublish.php index 0a60e5a599..b90fc11a49 100644 --- a/src/Worker/PubSubPublish.php +++ b/src/Worker/PubSubPublish.php @@ -15,7 +15,8 @@ use dba; require_once 'include/items.php'; -class PubSubPublish { +class PubSubPublish +{ public static function execute($pubsubpublish_id = 0) { if ($pubsubpublish_id == 0) { @@ -25,8 +26,9 @@ class PubSubPublish { self::publish($pubsubpublish_id); } - private static function publish($id) { - global $a; + private static function publish($id) + { + $a = \Friendica\BaseObject::getApp(); $subscriber = dba::selectFirst('push_subscriber', [], ['id' => $id]); if (!DBM::is_result($subscriber)) { diff --git a/src/Worker/Queue.php b/src/Worker/Queue.php index c8ba5795a6..1ec4090565 100644 --- a/src/Worker/Queue.php +++ b/src/Worker/Queue.php @@ -25,8 +25,6 @@ class Queue { public static function execute($queue_id = 0) { - global $a; - $cachekey_deadguy = 'queue_run:deadguy:'; $cachekey_server = 'queue_run:server:'; diff --git a/src/Worker/UpdateGContact.php b/src/Worker/UpdateGContact.php index 98a62818e9..b943d966be 100644 --- a/src/Worker/UpdateGContact.php +++ b/src/Worker/UpdateGContact.php @@ -15,8 +15,6 @@ class UpdateGContact { public static function execute($contact_id) { - global $a; - logger('update_gcontact: start'); if (empty($contact_id)) { diff --git a/tests/ApiTest.php b/tests/ApiTest.php index c33ee6bfaf..1854c996b0 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -5,12 +5,11 @@ namespace Friendica\Test; -use Friendica\App; use Friendica\Core\Config; use Friendica\Core\PConfig; -use Friendica\Network\BadRequestException; +use Friendica\Core\Protocol; +use Friendica\Core\System; use Friendica\Network\HTTPException; -use Friendica\Render\FriendicaSmarty; /** * Tests for the API functions. @@ -26,12 +25,10 @@ class ApiTest extends DatabaseTest */ protected function setUp() { - global $a; parent::setUp(); // Reusable App object - $this->app = new App(__DIR__.'/../'); - $a = $this->app; + $this->app = \Friendica\BaseObject::getApp(); // User data that the test database is populated with $this->selfUser = [ @@ -2164,7 +2161,7 @@ class ApiTest extends DatabaseTest public function testApiFormatItemsEmbededImages() { $this->assertEquals( - 'text ' . \Friendica\Core\System::baseUrl() . '/display/item_guid', + 'text ' . System::baseUrl() . '/display/item_guid', api_format_items_embeded_images(['guid' => 'item_guid'], 'text data:image/foo') ); } @@ -2338,7 +2335,7 @@ class ApiTest extends DatabaseTest 'body' => '', 'verb' => '', 'author-id' => 43, - 'author-network' => \Friendica\Core\Protocol::DFRN, + 'author-network' => Protocol::DFRN, 'author-link' => 'http://localhost/profile/othercontact', 'plink' => '', ] @@ -2361,7 +2358,7 @@ class ApiTest extends DatabaseTest 'body' => '', 'verb' => '', 'author-id' => 43, - 'author-network' => \Friendica\Core\Protocol::DFRN, + 'author-network' => Protocol::DFRN, 'author-link' => 'http://localhost/profile/othercontact', 'plink' => '', ] @@ -2635,7 +2632,7 @@ class ApiTest extends DatabaseTest $result = api_statusnet_config('json'); $this->assertEquals('localhost', $result['config']['site']['server']); $this->assertEquals('default', $result['config']['site']['theme']); - $this->assertEquals(\Friendica\Core\System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']); + $this->assertEquals(System::baseUrl() . '/images/friendica-64.png', $result['config']['site']['logo']); $this->assertTrue($result['config']['site']['fancy']); $this->assertEquals('en', $result['config']['site']['language']); $this->assertEquals('UTC', $result['config']['site']['timezone']); diff --git a/tests/src/Core/Cache/CacheTest.php b/tests/src/Core/Cache/CacheTest.php index a2724c12b0..39dc56f301 100644 --- a/tests/src/Core/Cache/CacheTest.php +++ b/tests/src/Core/Cache/CacheTest.php @@ -2,7 +2,6 @@ namespace Friendica\Test\src\Core\Cache; -use Friendica\App; use Friendica\Core\Config; use Friendica\Test\DatabaseTest; use Friendica\Util\DateTimeFormat; @@ -18,13 +17,11 @@ abstract class CacheTest extends DatabaseTest protected function setUp() { - global $a; parent::setUp(); $this->instance = $this->getInstance(); // Reusable App object $this->app = \Friendica\BaseObject::getApp(); - $a = $this->app; // Default config Config::set('config', 'hostname', 'localhost'); diff --git a/tests/src/Core/Lock/LockTest.php b/tests/src/Core/Lock/LockTest.php index 5e4bebd45c..79ee023bd8 100644 --- a/tests/src/Core/Lock/LockTest.php +++ b/tests/src/Core/Lock/LockTest.php @@ -2,10 +2,8 @@ namespace Friendica\Test\src\Core\Lock; -use Friendica\App; use Friendica\Core\Config; use Friendica\Test\DatabaseTest; -use PHPUnit\Framework\TestCase; abstract class LockTest extends DatabaseTest { @@ -18,13 +16,11 @@ abstract class LockTest extends DatabaseTest protected function setUp() { - global $a; parent::setUp(); $this->instance = $this->getInstance(); // Reusable App object $this->app = \Friendica\BaseObject::getApp(); - $a = $this->app; // Default config Config::set('config', 'hostname', 'localhost'); From 0cbe3aa8e60c8b66a1140d3f6a3e9453341e4d1e Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 9 Jul 2018 22:40:10 -0400 Subject: [PATCH 62/81] Remove global $db variable --- src/Worker/DBClean.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Worker/DBClean.php b/src/Worker/DBClean.php index deb23e8dd8..7a0b1f8473 100644 --- a/src/Worker/DBClean.php +++ b/src/Worker/DBClean.php @@ -60,8 +60,6 @@ class DBClean { * 10: Old conversations. */ private static function removeOrphans($stage) { - global $db; - $count = 0; // We split the deletion in many small tasks From 39767fb366a7b4d8bdf79028009790040f80f3a0 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 11 Jul 2018 22:23:35 -0400 Subject: [PATCH 63/81] Fix undefined index notice messages in mod/install --- mod/install.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/mod/install.php b/mod/install.php index 0f08b0fd8b..55a7cdd7fd 100644 --- a/mod/install.php +++ b/mod/install.php @@ -161,13 +161,12 @@ function install_content(App $a) { case 2: { // Database config - $dbhost = ((x($_POST, 'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost'); - $dbuser = notags(trim($_POST['dbuser'])); - $dbpass = notags(trim($_POST['dbpass'])); - $dbdata = notags(trim($_POST['dbdata'])); - $phpath = notags(trim($_POST['phpath'])); - - $adminmail = notags(trim($_POST['adminmail'])); + $dbhost = notags(trim(defaults($_POST, 'dbhost' , 'localhost'))); + $dbuser = notags(trim(defaults($_POST, 'dbuser' , '' ))); + $dbpass = notags(trim(defaults($_POST, 'dbpass' , '' ))); + $dbdata = notags(trim(defaults($_POST, 'dbdata' , '' ))); + $phpath = notags(trim(defaults($_POST, 'phpath' , '' ))); + $adminmail = notags(trim(defaults($_POST, 'adminmail', '' ))); $tpl = get_markup_template('install_db.tpl'); $o .= replace_macros($tpl, [ @@ -185,8 +184,6 @@ function install_content(App $a) { '$dbdata' => ['dbdata', L10n::t('Database Name'), $dbdata, '', 'required'], '$adminmail' => ['adminmail', L10n::t('Site administrator email address'), $adminmail, L10n::t('Your account email address must match this in order to use the web admin panel.'), 'required', 'autofocus', 'email'], - - '$lbl_10' => L10n::t('Please select a default timezone for your website'), '$baseurl' => System::baseUrl(), @@ -194,7 +191,6 @@ function install_content(App $a) { '$phpath' => $phpath, '$submit' => L10n::t('Submit'), - ]); return $o; }; break; From bd04c03c9f5fe0d1ff458fe117aba9b8fd18ed95 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 11 Jul 2018 22:23:57 -0400 Subject: [PATCH 64/81] Fix urlpath determination on the root page --- src/App.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/App.php b/src/App.php index 3ce5bf576c..8bde1afc43 100644 --- a/src/App.php +++ b/src/App.php @@ -442,8 +442,14 @@ class App * * To get /path/to/friendica we perform dirname() for as many levels as there are slashes in the QUERY_STRING */ - if (!empty($_SERVER['SCRIPT_URL']) && !empty($_SERVER['QUERY_STRING'])) { - $path = trim(dirname($_SERVER['SCRIPT_URL'], substr_count(trim($_SERVER['QUERY_STRING'], '/'), '/') + 1), '/'); + if (!empty($_SERVER['SCRIPT_URL'])) { + // Module + if (!empty($_SERVER['QUERY_STRING'])) { + $path = trim(dirname($_SERVER['SCRIPT_URL'], substr_count(trim($_SERVER['QUERY_STRING'], '/'), '/') + 1), '/'); + } else { + // Root page + $path = trim($_SERVER['SCRIPT_URL'], '/'); + } if ($path && $path != $this->urlpath) { $this->urlpath = $path; From c8d3067d0a284c1e0b3ac40629f28ae95a63e7f5 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 11 Jul 2018 22:24:20 -0400 Subject: [PATCH 65/81] Fix JITConfigAdapter to retrieve non-db config.* values --- src/Core/Config/JITConfigAdapter.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Core/Config/JITConfigAdapter.php b/src/Core/Config/JITConfigAdapter.php index 0596974aaa..c03a010cd4 100644 --- a/src/Core/Config/JITConfigAdapter.php +++ b/src/Core/Config/JITConfigAdapter.php @@ -71,6 +71,12 @@ class JITConfigAdapter extends BaseObject implements IConfigAdapter $this->in_db[$cat][$k] = false; return $a->config[$cat][$k]; + } elseif (isset($a->config[$k])) { + // Assign the value (mostly) from config/local.ini.php file to the cache + $this->cache[$k] = $a->config[$k]; + $this->in_db[$k] = false; + + return $a->config[$k]; } $this->cache[$cat][$k] = '!!'; From b3439871201ab5c8a8f14333ab1d334a68c299e6 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 11 Jul 2018 22:24:52 -0400 Subject: [PATCH 66/81] Fix segfault in PHP 5.6 parsing INI strings - add documentation to generated local.ini.php file --- view/templates/local.ini.tpl | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/view/templates/local.ini.tpl b/view/templates/local.ini.tpl index 632b34e5a7..109a732301 100644 --- a/view/templates/local.ini.tpl +++ b/view/templates/local.ini.tpl @@ -1,5 +1,8 @@ Date: Wed, 11 Jul 2018 22:41:52 -0400 Subject: [PATCH 67/81] Fix missing use in mod/ping --- mod/ping.php | 1 + 1 file changed, 1 insertion(+) diff --git a/mod/ping.php b/mod/ping.php index 7153752b05..47c8cb40d7 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -9,6 +9,7 @@ use Friendica\Content\ForumManager; use Friendica\Content\Text\BBCode; use Friendica\Core\Addon; use Friendica\Core\Cache; +use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\PConfig; use Friendica\Core\System; From 30019510759c06c5b1884ce4aa353ac50f26a180 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 11 Jul 2018 22:58:37 -0400 Subject: [PATCH 68/81] Move the addon-specific config in config/addon.ini.php - Add sample addon.ini.php file - Add config/addon.ini.php file to git ignore --- .gitignore | 1 + config/addon-sample.ini.php | 10 ++++++++++ src/App.php | 6 +++--- 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 config/addon-sample.ini.php diff --git a/.gitignore b/.gitignore index c1eb430b4b..114bb5dbb9 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ robots.txt #ignore local config /config/local.ini.php +/config/addon.ini.php #ignore documentation, it should be newly built /doc/html diff --git a/config/addon-sample.ini.php b/config/addon-sample.ini.php new file mode 100644 index 0000000000..7d8054cd2a --- /dev/null +++ b/config/addon-sample.ini.php @@ -0,0 +1,10 @@ +basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php')) { - $this->loadConfigFile($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php'); + // Load the local addon config file to overwritten default addon config values + if (file_exists($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'addon.ini.php')) { + $this->loadConfigFile($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'addon.ini.php'); } } From 796eb1c8748a92171798bbeeaa8b5c310a3c1c1f Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 11 Jul 2018 22:58:52 -0400 Subject: [PATCH 69/81] Fix undefined index in mod/settings --- mod/settings.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mod/settings.php b/mod/settings.php index 34e9ce41ec..ff969d65eb 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -26,14 +26,12 @@ use Friendica\Util\Temporal; function get_theme_config_file($theme) { $a = get_app(); - if (!empty($a->theme_info['extends'])) { - $base_theme = $a->theme_info['extends']; - } + $base_theme = defaults($a->theme_info, 'extends'); if (file_exists("view/theme/$theme/config.php")) { return "view/theme/$theme/config.php"; } - if (!empty($base_theme) && file_exists("view/theme/$base_theme/config.php")) { + if ($base_theme && file_exists("view/theme/$base_theme/config.php")) { return "view/theme/$base_theme/config.php"; } return null; From 763c66dd499bd16f0ae62012d98b2e5bd79665e5 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 11 Jul 2018 23:00:44 -0400 Subject: [PATCH 70/81] Improve console/config display - Add visual distinction between get/set value --- src/Core/Console/Config.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Core/Console/Config.php b/src/Core/Console/Config.php index f619afade0..860c9e891d 100644 --- a/src/Core/Console/Config.php +++ b/src/Core/Console/Config.php @@ -99,7 +99,7 @@ HELP; if (count($this->args) == 3) { $result = Core\Config::set($this->getArgument(0), $this->getArgument(1), $this->getArgument(2)); if ($result) { - $this->out("{$this->getArgument(0)}.{$this->getArgument(1)} = " . + $this->out("{$this->getArgument(0)}.{$this->getArgument(1)} <= " . Core\Config::get($this->getArgument(0), $this->getArgument(1))); } else { $this->out("Unable to set {$this->getArgument(0)}.{$this->getArgument(1)}"); @@ -107,7 +107,7 @@ HELP; } if (count($this->args) == 2) { - $this->out("{$this->getArgument(0)}.{$this->getArgument(1)} = " . + $this->out("{$this->getArgument(0)}.{$this->getArgument(1)} => " . Core\Config::get($this->getArgument(0), $this->getArgument(1))); } @@ -116,7 +116,7 @@ HELP; if (!is_null($a->config[$this->getArgument(0)])) { foreach ($a->config[$this->getArgument(0)] as $k => $x) { - $this->out("{$this->getArgument(0)}.{$k} = " . $x); + $this->out("{$this->getArgument(0)}.{$k} => " . $x); } } else { $this->out('Config section ' . $this->getArgument(0) . ' returned nothing'); @@ -135,14 +135,14 @@ HELP; foreach ($section as $key => $value) { if (is_array($value)) { foreach ($value as $k => $v) { - $this->out("{$cat}.{$key}[{$k}] = " . $v); + $this->out("{$cat}.{$key}[{$k}] => " . $v); } } else { - $this->out("{$cat}.{$key} = " . $value); + $this->out("{$cat}.{$key} => " . $value); } } } else { - $this->out("config.{$cat} = " . $section); + $this->out("config.{$cat} => " . $section); } } } From c207f6d59732e690b9e7ff68c5e6eeb0c6488a79 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 15 Jul 2018 12:44:10 -0400 Subject: [PATCH 71/81] Remove remaining references to Config::get in include/dba --- include/dba.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/include/dba.php b/include/dba.php index f6120f673f..0b5c822531 100644 --- a/include/dba.php +++ b/include/dba.php @@ -186,7 +186,7 @@ class dba { private static function logIndex($query) { $a = get_app(); - if (empty(Config::get('system', 'db_log_index'))) { + if (!$a->getConfigVariable('system', 'db_log_index')) { return; } @@ -205,18 +205,18 @@ class dba { return; } - $watchlist = explode(',', Config::get('system', 'db_log_index_watch')); - $blacklist = explode(',', Config::get('system', 'db_log_index_blacklist')); + $watchlist = explode(',', $a->getConfigVariable('system', 'db_log_index_watch')); + $blacklist = explode(',', $a->getConfigVariable('system', 'db_log_index_blacklist')); while ($row = dba::fetch($r)) { - if ((intval(Config::get('system', 'db_loglimit_index')) > 0)) { + if ((intval($a->getConfigVariable('system', 'db_loglimit_index')) > 0)) { $log = (in_array($row['key'], $watchlist) && - ($row['rows'] >= intval(Config::get('system', 'db_loglimit_index')))); + ($row['rows'] >= intval($a->getConfigVariable('system', 'db_loglimit_index')))); } else { $log = false; } - if ((intval(Config::get('system', 'db_loglimit_index_high')) > 0) && ($row['rows'] >= intval(Config::get('system', 'db_loglimit_index_high')))) { + if ((intval($a->getConfigVariable('system', 'db_loglimit_index_high')) > 0) && ($row['rows'] >= intval($a->getConfigVariable('system', 'db_loglimit_index_high')))) { $log = true; } @@ -226,7 +226,7 @@ class dba { if ($log) { $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); - @file_put_contents(Config::get('system', 'db_log_index'), DateTimeFormat::utcNow()."\t". + @file_put_contents($a->getConfigVariable('system', 'db_log_index'), DateTimeFormat::utcNow()."\t". $row['key']."\t".$row['rows']."\t".$row['Extra']."\t". basename($backtrace[1]["file"])."\t". $backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t". From b260ca4d1eb3807ea2bbe9f07ceaa979da400245 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 15 Jul 2018 12:44:19 -0400 Subject: [PATCH 72/81] Fix typo in mod/admin --- mod/admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/admin.php b/mod/admin.php index da50007131..77a5aada7f 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -848,7 +848,7 @@ function admin_page_summary(App $a) // Legacy config file warning if (file_exists('.htconfig.php')) { $showwarning = true; - $warningtext[] = L10n::t('Friencia\'s configuration now is stored in config/local.ini.php, please copy config/local-sample.ini.php and move your config from .htconfig.php.'); + $warningtext[] = L10n::t('Friendica\'s configuration now is stored in config/local.ini.php, please copy config/local-sample.ini.php and move your config from .htconfig.php.'); } $r = q("SELECT `page-flags`, COUNT(`uid`) AS `count` FROM `user` GROUP BY `page-flags`"); From 9b01a23c9b3bd8a4a75d990a058f8a0c1648ca31 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 15 Jul 2018 12:44:32 -0400 Subject: [PATCH 73/81] Code standards in App --- src/App.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/App.php b/src/App.php index e495f48dd4..2429fde407 100644 --- a/src/App.php +++ b/src/App.php @@ -385,8 +385,8 @@ class App throw new Exception('Error parsing config file ' . $filepath); } - foreach($config as $category => $values) { - foreach($values as $key => $value) { + foreach ($config as $category => $values) { + foreach ($values as $key => $value) { $this->setConfigValue($category, $key, $value); } } From 67dc08d120828fe277584ba4127340eeb447f8d4 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 15 Jul 2018 15:04:48 -0400 Subject: [PATCH 74/81] Enforce systen.register_policy value type --- include/api.php | 2 +- mod/bookmarklet.php | 2 +- mod/friendica.php | 2 +- mod/home.php | 2 +- mod/invite.php | 4 ++-- mod/nodeinfo.php | 2 +- mod/openid.php | 2 +- mod/ping.php | 2 +- mod/register.php | 10 +++++----- mod/regmod.php | 2 +- mod/statistics_json.php | 2 +- mod/uimport.php | 2 +- src/Content/Nav.php | 2 +- src/Module/Login.php | 2 +- 14 files changed, 19 insertions(+), 19 deletions(-) diff --git a/include/api.php b/include/api.php index d307afa953..58f086c012 100644 --- a/include/api.php +++ b/include/api.php @@ -3345,7 +3345,7 @@ function api_statusnet_config($type) $server = $a->get_hostname(); $logo = System::baseUrl() . '/images/friendica-64.png'; $email = Config::get('config', 'admin_email'); - $closed = Config::get('config', 'register_policy') == REGISTER_CLOSED ? 'true' : 'false'; + $closed = intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED ? 'true' : 'false'; $private = Config::get('system', 'block_public') ? 'true' : 'false'; $textlimit = (string) Config::get('config', 'api_import_size', Config::get('config', 'max_import_size', 200000)); $ssl = Config::get('system', 'have_ssl') ? 'true' : 'false'; diff --git a/mod/bookmarklet.php b/mod/bookmarklet.php index 88097eb910..a26757740a 100644 --- a/mod/bookmarklet.php +++ b/mod/bookmarklet.php @@ -22,7 +22,7 @@ function bookmarklet_content(App $a) { if (!local_user()) { $o = '

    ' . L10n::t('Login') . '

    '; - $o .= Login::form($a->query_string, Config::get('config', 'register_policy') === REGISTER_CLOSED ? false : true); + $o .= Login::form($a->query_string, intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED ? false : true); return $o; } diff --git a/mod/friendica.php b/mod/friendica.php index b3cea56dc6..f1b0fb4761 100644 --- a/mod/friendica.php +++ b/mod/friendica.php @@ -58,7 +58,7 @@ function friendica_init(App $a) 'url' => System::baseUrl(), 'addons' => $visible_addons, 'locked_features' => $locked_features, - 'register_policy' => $register_policy[Config::get('config', 'register_policy')], + 'register_policy' => $register_policy[intval(Config::get('config', 'register_policy'))], 'admin' => $admin, 'site_name' => Config::get('config', 'sitename'), 'platform' => FRIENDICA_PLATFORM, diff --git a/mod/home.php b/mod/home.php index c386763ca3..d28bf3cb43 100644 --- a/mod/home.php +++ b/mod/home.php @@ -47,7 +47,7 @@ function home_content(App $a) { } } - $login = Login::form($a->query_string, Config::get('config', 'register_policy') === REGISTER_CLOSED ? 0 : 1); + $login = Login::form($a->query_string, intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED ? 0 : 1); $content = ''; Addon::callHooks("home_content",$content); diff --git a/mod/invite.php b/mod/invite.php index bea479a8f7..d8d98bec28 100644 --- a/mod/invite.php +++ b/mod/invite.php @@ -126,14 +126,14 @@ function invite_content(App $a) { $dirloc = Config::get('system', 'directory'); if (strlen($dirloc)) { - if (Config::get('config', 'register_policy') === REGISTER_CLOSED) { + if (intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED) { $linktxt = L10n::t('Visit %s for a list of public sites that you can join. Friendica members on other sites can all connect with each other, as well as with members of many other social networks.', $dirloc . '/servers'); } else { $linktxt = L10n::t('To accept this invitation, please visit and register at %s or any other public Friendica website.', System::baseUrl()) . "\r\n" . "\r\n" . L10n::t('Friendica sites all inter-connect to create a huge privacy-enhanced social web that is owned and controlled by its members. They can also connect with many traditional social networks. See %s for a list of alternate Friendica sites you can join.', $dirloc . '/servers'); } } else { // there is no global directory URL defined - if (Config::get('config', 'register_policy') === REGISTER_CLOSED) { + if (intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED) { $o = L10n::t('Our apologies. This system is not currently configured to connect with other public sites or invite members.'); return $o; } else { diff --git a/mod/nodeinfo.php b/mod/nodeinfo.php index 74645bc66d..fad7246075 100644 --- a/mod/nodeinfo.php +++ b/mod/nodeinfo.php @@ -61,7 +61,7 @@ function nodeinfo_init(App $a) { $nodeinfo['usage'] = []; - $nodeinfo['openRegistrations'] = Config::get('config', 'register_policy') !== REGISTER_CLOSED; + $nodeinfo['openRegistrations'] = intval(Config::get('config', 'register_policy')) !== REGISTER_CLOSED; $nodeinfo['metadata'] = ['nodeName' => Config::get('config', 'sitename')]; diff --git a/mod/openid.php b/mod/openid.php index 7be8544cd9..3baeec28d0 100644 --- a/mod/openid.php +++ b/mod/openid.php @@ -62,7 +62,7 @@ function openid_content(App $a) { // Successful OpenID login - but we can't match it to an existing account. // New registration? - if (Config::get('config', 'register_policy') === REGISTER_CLOSED) { + if (intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED) { notice(L10n::t('Account not found and OpenID registration is not permitted on this site.') . EOL); goaway(System::baseUrl()); } diff --git a/mod/ping.php b/mod/ping.php index 47c8cb40d7..f68040a2cb 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -201,7 +201,7 @@ function ping_init(App $a) ); $mail_count = count($mails); - if (Config::get('config', 'register_policy') === REGISTER_APPROVE && is_site_admin()) { + if (intval(Config::get('config', 'register_policy')) === REGISTER_APPROVE && is_site_admin()) { $regs = q( "SELECT `contact`.`name`, `contact`.`url`, `contact`.`micro`, `register`.`created` FROM `contact` RIGHT JOIN `register` ON `register`.`uid` = `contact`.`uid` diff --git a/mod/register.php b/mod/register.php index 53bca68405..aa0f2f59bc 100644 --- a/mod/register.php +++ b/mod/register.php @@ -74,7 +74,7 @@ function register_post(App $a) $user = $result['user']; - if ($netpublish && Config::get('config', 'register_policy') !== REGISTER_APPROVE) { + if ($netpublish && intval(Config::get('config', 'register_policy')) !== REGISTER_APPROVE) { $url = System::baseUrl() . '/profile/' . $user['nickname']; Worker::add(PRIORITY_LOW, "Directory", $url); } @@ -83,7 +83,7 @@ function register_post(App $a) $num_invites = Config::get('system', 'number_invites'); $invite_id = ((x($_POST, 'invite_id')) ? notags(trim($_POST['invite_id'])) : ''); - if (Config::get('config', 'register_policy') === REGISTER_OPEN) { + if (intval(Config::get('config', 'register_policy')) === REGISTER_OPEN) { if ($using_invites && $invite_id) { q("delete * from register where hash = '%s' limit 1", dbesc($invite_id)); PConfig::set($user['uid'], 'system', 'invites_remaining', $num_invites); @@ -109,7 +109,7 @@ function register_post(App $a) info(L10n::t('Registration successful.') . EOL); goaway(System::baseUrl()); } - } elseif (Config::get('config', 'register_policy') === REGISTER_APPROVE) { + } elseif (intval(Config::get('config', 'register_policy')) === REGISTER_APPROVE) { if (!strlen(Config::get('config', 'admin_email'))) { notice(L10n::t('Your registration can not be processed.') . EOL); goaway(System::baseUrl()); @@ -177,7 +177,7 @@ function register_content(App $a) return; } - if ((!local_user()) && (Config::get('config', 'register_policy') === REGISTER_CLOSED)) { + if ((!local_user()) && (intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED)) { notice("Permission denied." . EOL); return; } @@ -256,7 +256,7 @@ function register_content(App $a) $o = replace_macros($tpl, [ '$oidhtml' => $oidhtml, '$invitations' => Config::get('system', 'invitation_only'), - '$permonly' => Config::get('config', 'register_policy') === REGISTER_APPROVE, + '$permonly' => intval(Config::get('config', 'register_policy')) === REGISTER_APPROVE, '$permonlybox' => ['permonlybox', L10n::t('Note for the admin'), '', L10n::t('Leave a message for the admin, why you want to join this node')], '$invite_desc' => L10n::t('Membership on this site is by invitation only.'), '$invite_label' => L10n::t('Your invitation code: '), diff --git a/mod/regmod.php b/mod/regmod.php index 2a418fcda0..2b7df0bd13 100644 --- a/mod/regmod.php +++ b/mod/regmod.php @@ -99,7 +99,7 @@ function regmod_content(App $a) { if (!local_user()) { info(L10n::t('Please login.') . EOL); - $o = '

    ' . Login::form($a->query_string, Config::get('config', 'register_policy') === REGISTER_CLOSED ? 0 : 1); + $o = '

    ' . Login::form($a->query_string, intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED ? 0 : 1); return $o; } diff --git a/mod/statistics_json.php b/mod/statistics_json.php index 0dbe0ea492..c197060ff5 100644 --- a/mod/statistics_json.php +++ b/mod/statistics_json.php @@ -20,7 +20,7 @@ function statistics_json_init(App $a) { "name" => Config::get('config', 'sitename'), "network" => FRIENDICA_PLATFORM, "version" => FRIENDICA_VERSION . "-" . DB_UPDATE_VERSION, - "registrations_open" => Config::get('config', 'register_policy') !== REGISTER_CLOSED, + "registrations_open" => intval(Config::get('config', 'register_policy')) !== REGISTER_CLOSED, "total_users" => Config::get('nodeinfo', 'total_users'), "active_users_halfyear" => Config::get('nodeinfo', 'active_users_halfyear'), "active_users_monthly" => Config::get('nodeinfo', 'active_users_monthly'), diff --git a/mod/uimport.php b/mod/uimport.php index 660544b471..1dbc571e2f 100644 --- a/mod/uimport.php +++ b/mod/uimport.php @@ -42,7 +42,7 @@ function uimport_post(App $a) function uimport_content(App $a) { - if ((!local_user()) && (Config::get('config', 'register_policy') === REGISTER_CLOSED)) { + if ((!local_user()) && (intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED)) { notice("Permission denied." . EOL); return; } diff --git a/src/Content/Nav.php b/src/Content/Nav.php index 93090c06ec..92ca714df8 100644 --- a/src/Content/Nav.php +++ b/src/Content/Nav.php @@ -124,7 +124,7 @@ class Nav $nav['home'] = [$homelink, L10n::t('Home'), '', L10n::t('Home Page')]; } - if ((Config::get('config', 'register_policy') === REGISTER_OPEN) && (! local_user()) && (! remote_user())) { + if (intval(Config::get('config', 'register_policy')) === REGISTER_OPEN && !local_user() && !remote_user()) { $nav['register'] = ['register', L10n::t('Register'), '', L10n::t('Create an account')]; } diff --git a/src/Module/Login.php b/src/Module/Login.php index 46cb3a85d2..06d724bb2a 100644 --- a/src/Module/Login.php +++ b/src/Module/Login.php @@ -43,7 +43,7 @@ class Login extends BaseModule goaway(self::getApp()->get_baseurl()); } - return self::form(self::getApp()->get_baseurl(), Config::get('config', 'register_policy') !== REGISTER_CLOSED); + return self::form(self::getApp()->get_baseurl(), intval(Config::get('config', 'register_policy')) !== REGISTER_CLOSED); } public static function post() From bad2774817be42c5589ebd91fb1802fdc75385f8 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 16 Jul 2018 19:07:46 -0400 Subject: [PATCH 75/81] Separate default config values between file-only and admin settings --- config/{defaults.ini.php => config.ini.php} | 245 +++++++------------- config/settings.ini.php | 108 +++++++++ src/App.php | 3 +- 3 files changed, 193 insertions(+), 163 deletions(-) rename config/{defaults.ini.php => config.ini.php} (77%) create mode 100644 config/settings.ini.php diff --git a/config/defaults.ini.php b/config/config.ini.php similarity index 77% rename from config/defaults.ini.php rename to config/config.ini.php index 2f1357e3aa..9808c970d2 100644 --- a/config/defaults.ini.php +++ b/config/config.ini.php @@ -1,7 +1,11 @@ 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')) { From dfa461b3bc99b03f807d8a326c3a978c5e459d3c Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 17 Jul 2018 02:03:39 -0400 Subject: [PATCH 76/81] Improve help/Config page - Remove obsolete file-only config list - Fix heading level - Add transition instruction for $lang - Add reference to config.ini.php, settings.ini.php and addon.ini.php - Add link to help page in admin warning about legacy config file --- doc/Config.md | 127 ++++++++------------------------------------------ mod/admin.php | 2 +- 2 files changed, 21 insertions(+), 108 deletions(-) diff --git a/doc/Config.md b/doc/Config.md index 7ac3f7a02e..ba6e674fc6 100644 --- a/doc/Config.md +++ b/doc/Config.md @@ -6,7 +6,7 @@ Config values that can only be set in config/local.ini.php Friendica's configuration is done in two places: in INI configuration files and in the `config` database table. Database config values overwrite the same file config values. -# File configuration +## File configuration The configuration format for file configuration is an INI string returned from a PHP file. This prevents your webserver from displaying your private configuration it interprets the configuration files and displays nothing. @@ -31,16 +31,24 @@ INI; // Keep this line ``` -## Configuration location +### Configuration location -All the configuration keys Friendica uses are listed with their default value if any in `config/defaults.ini.php`. -Addons can define their own default configuration values in `addon/[addon]/config/[addon].ini.php` which are loaded when the addon is activated. +The `config` directory holds key configuration files: -### Migrating from .htconfig.php to config/local.ini.php +- `config.ini.php` holds the default values for all the configuration keys that can only be set in `local.ini.php`. +- `settings.ini.php` holds the default values for some configuration keys that are set through the admin settings page. +- `local.ini.php` holds the current node custom configuration. +- `addon.ini.php` is optional and holds the custom configuration for specific addons. + +Addons can define their own default configuration values in `addon/[addon]/config/[addon].ini.php` which is loaded when the addon is activated. + +#### Migrating from .htconfig.php to config/local.ini.php The legacy `.htconfig.php` configuration file is still supported, but is deprecated and will be removed in a subsequent Friendica release. -The migration is pretty straightforward, just copy `config/local-sample.ini.php` to `config/local.ini.php`, add your configuration values to it according to the following conversion chart, then rename your `.htconfig.php` to check your node is working as expected before deleting it. +The migration is pretty straightforward: +If you had any addon-specific configuration in your `.htconfig.php`, just copy `config/addon-sample.ini.php` to `config/addon.ini.php` and move your configuration values. +Afterwards, copy `config/local-sample.ini.php` to `config/local.ini.php`, move the remaining configuration values to it according to the following conversion chart, then rename your `.htconfig.php` to check your node is working as expected before deleting it.