]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Admin/Site.php
Merge remote-tracking branch 'upstream/develop' into item-notification
[friendica.git] / src / Module / Admin / Site.php
index 37507ca9964f6171814a9bbecbe9fce4a53cfd14..3302e0dc16c821dd76ed857dbc41e799412346aa 100644 (file)
@@ -6,28 +6,30 @@ use Friendica\App;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\Renderer;
+use Friendica\Core\Search;
 use Friendica\Core\StorageManager;
 use Friendica\Core\Theme;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
+use Friendica\DI;
 use Friendica\Module\BaseAdminModule;
 use Friendica\Module\Register;
 use Friendica\Protocol\PortableContact;
 use Friendica\Util\BasePath;
-use Friendica\Util\BaseURL;
 use Friendica\Util\Strings;
+use Friendica\Worker\Delivery;
 
 require_once __DIR__ . '/../../../boot.php';
 
 class Site extends BaseAdminModule
 {
-       public static function post()
+       public static function post(array $parameters = [])
        {
-               parent::post();
+               parent::post($parameters);
 
                self::checkFormSecurityTokenRedirectOnError('/admin/site', 'admin_site');
 
-               $a = self::getApp();
+               $a = DI::app();
 
                if (!empty($_POST['republish_directory'])) {
                        Worker::add(PRIORITY_LOW, 'Directory');
@@ -47,7 +49,7 @@ class Site extends BaseAdminModule
                        $parsed = @parse_url($new_url);
                        if (!is_array($parsed) || empty($parsed['host']) || empty($parsed['scheme'])) {
                                notice(L10n::t("Can not parse base url. Must have at least <scheme>://<domain>"));
-                               $a->internalRedirect('admin/site');
+                               DI::baseUrl()->redirect('admin/site');
                        }
 
                        /* steps:
@@ -55,7 +57,7 @@ class Site extends BaseAdminModule
                         * send relocate for every local user
                         * */
 
-                       $old_url = $a->getBaseURL(true);
+                       $old_url = DI::baseUrl()->get(true);
 
                        // Generate host names for relocation the addresses in the format user@address.tld
                        $new_host = str_replace("http://", "@", Strings::normaliseLink($new_url));
@@ -76,7 +78,7 @@ class Site extends BaseAdminModule
                                $r = DBA::e(sprintf("UPDATE %s SET %s;", $table_name, $upds));
                                if (!DBA::isResult($r)) {
                                        notice("Failed updating '$table_name': " . DBA::errorMessage());
-                                       $a->internalRedirect('admin/site');
+                                       DI::baseUrl()->redirect('admin/site');
                                }
                        }
 
@@ -94,17 +96,17 @@ class Site extends BaseAdminModule
 
                        // update config
                        Config::set('system', 'url', $new_url);
-                       $a->setBaseURL($new_url);
+                       DI::baseUrl()->saveByURL($new_url);
 
                        // send relocate
                        $usersStmt = DBA::select('user', ['uid'], ['account_removed' => false, 'account_expired' => false]);
                        while ($user = DBA::fetch($usersStmt)) {
-                               Worker::add(PRIORITY_HIGH, 'Notifier', 'relocate', $user['uid']);
+                               Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::RELOCATION, $user['uid']);
                        }
 
                        info("Relocation started. Could take a while to complete.");
 
-                       $a->internalRedirect('admin/site');
+                       DI::baseUrl()->redirect('admin/site');
                }
                // end relocate
 
@@ -165,7 +167,6 @@ class Site extends BaseAdminModule
                $nodeinfo               = !empty($_POST['nodeinfo']);
                $dfrn_only              = !empty($_POST['dfrn_only']);
                $ostatus_disabled       = !empty($_POST['ostatus_disabled']);
-               $ostatus_full_threads   = !empty($_POST['ostatus_full_threads']);
                $diaspora_enabled       = !empty($_POST['diaspora_enabled']);
                $ssl_policy             = (!empty($_POST['ssl_policy'])             ? intval($_POST['ssl_policy'])                    : 0);
                $force_ssl              = !empty($_POST['force_ssl']);
@@ -201,7 +202,7 @@ class Site extends BaseAdminModule
                /**
                 * @var $storagebackend \Friendica\Model\Storage\IStorage
                 */
-               $storagebackend    = Strings::escapeTags(trim(defaults($_POST, 'storagebackend', '')));
+               $storagebackend    = Strings::escapeTags(trim($_POST['storagebackend'] ?? ''));
 
                // save storage backend form
                if (!is_null($storagebackend) && $storagebackend != "") {
@@ -217,7 +218,7 @@ class Site extends BaseAdminModule
                                                        $value = !empty($_POST[$fieldname]);
                                                        break;
                                                default:
-                                                       $value = defaults($_POST, $fieldname, '');
+                                                       $value = $_POST[$fieldname] ?? '';
                                        }
                                        $storage_opts_data[$name] = $value;
                                }
@@ -229,7 +230,7 @@ class Site extends BaseAdminModule
                                        foreach ($storage_form_errors as $name => $err) {
                                                notice('Storage backend, ' . $storage_opts[$name][1] . ': ' . $err);
                                        }
-                                       $a->internalRedirect('admin/site' . $active_panel);
+                                       DI::baseUrl()->redirect('admin/site' . $active_panel);
                                }
                        } else {
                                info(L10n::t('Invalid storage backend setting value.'));
@@ -242,11 +243,11 @@ class Site extends BaseAdminModule
                        Worker::add(PRIORITY_LOW, 'Directory');
                }
 
-               if ($a->getURLPath() != "") {
+               if (DI::baseUrl()->getUrlPath() != "") {
                        $diaspora_enabled = false;
                }
                if ($ssl_policy != intval(Config::get('system', 'ssl_policy'))) {
-                       if ($ssl_policy == BaseURL::SSL_POLICY_FULL) {
+                       if ($ssl_policy == App\BaseURL::SSL_POLICY_FULL) {
                                DBA::e("UPDATE `contact` SET
                                `url`     = REPLACE(`url`    , 'http:' , 'https:'),
                                `photo`   = REPLACE(`photo`  , 'http:' , 'https:'),
@@ -264,7 +265,7 @@ class Site extends BaseAdminModule
                                `thumb`   = REPLACE(`thumb`  , 'http:' , 'https:')
                                WHERE 1 "
                                );
-                       } elseif ($ssl_policy == BaseURL::SSL_POLICY_SELFSIGN) {
+                       } elseif ($ssl_policy == App\BaseURL::SSL_POLICY_SELFSIGN) {
                                DBA::e("UPDATE `contact` SET
                                `url`     = REPLACE(`url`    , 'https:' , 'http:'),
                                `photo`   = REPLACE(`photo`  , 'https:' , 'http:'),
@@ -360,7 +361,6 @@ class Site extends BaseAdminModule
                Config::set('system', 'curl_timeout'           , $timeout);
                Config::set('system', 'dfrn_only'              , $dfrn_only);
                Config::set('system', 'ostatus_disabled'       , $ostatus_disabled);
-               Config::set('system', 'ostatus_full_threads'   , $ostatus_full_threads);
                Config::set('system', 'diaspora_enabled'       , $diaspora_enabled);
 
                Config::set('config', 'private_addons'         , $private_addons);
@@ -411,14 +411,12 @@ class Site extends BaseAdminModule
 
                info(L10n::t('Site settings updated.') . EOL);
 
-               $a->internalRedirect('admin/site' . $active_panel);
+               DI::baseUrl()->redirect('admin/site' . $active_panel);
        }
 
-       public static function content()
+       public static function content(array $parameters = [])
        {
-               parent::content();
-
-               $a = self::getApp();
+               parent::content($parameters);
 
                /* Installed langs */
                $lang_choices = L10n::getAvailableLanguages();
@@ -483,6 +481,7 @@ class Site extends BaseAdminModule
                ];
 
                /* get user names to make the install a personal install of X */
+               // @TODO Move to Model\User::getNames()
                $user_names = [];
                $user_names['---'] = L10n::t('Multi user instance');
 
@@ -512,9 +511,9 @@ class Site extends BaseAdminModule
                ];
 
                $ssl_choices = [
-                       BaseURL::SSL_POLICY_NONE => L10n::t('No SSL policy, links will track page SSL state'),
-                       BaseURL::SSL_POLICY_FULL => L10n::t('Force all links to use SSL'),
-                       BaseURL::SSL_POLICY_SELFSIGN => L10n::t('Self-signed certificate, use SSL for local links only (discouraged)')
+                       App\BaseURL::SSL_POLICY_NONE => L10n::t('No SSL policy, links will track page SSL state'),
+                       App\BaseURL::SSL_POLICY_FULL => L10n::t('Force all links to use SSL'),
+                       App\BaseURL::SSL_POLICY_SELFSIGN => L10n::t('Self-signed certificate, use SSL for local links only (discouraged)')
                ];
 
                $check_git_version_choices = [
@@ -523,7 +522,7 @@ class Site extends BaseAdminModule
                        'develop' => L10n::t('check the development version')
                ];
 
-               $diaspora_able = ($a->getURLPath() == '');
+               $diaspora_able = (DI::baseUrl()->getUrlPath() == '');
 
                $optimize_max_tablesize = Config::get('system', 'optimize_max_tablesize', -1);
 
@@ -578,7 +577,7 @@ class Site extends BaseAdminModule
                        '$relay_title'       => L10n::t('Message Relay'),
                        '$relocate'          => L10n::t('Relocate Instance'),
                        '$relocate_warning'  => L10n::t('Warning! Advanced function. Could make this server unreachable.'),
-                       '$baseurl'           => $a->getBaseURL(true),
+                       '$baseurl'           => DI::baseUrl()->get(true),
 
                        // name, label, value, help string, extra data...
                        '$sitename'         => ['sitename', L10n::t('Site name'), Config::get('config', 'sitename'), ''],
@@ -586,7 +585,7 @@ class Site extends BaseAdminModule
                        '$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.')],
-                       '$additional_info'  => ['additional_info', L10n::t('Additional Info'), $additional_info, L10n::t('For public servers: you can add additional information here that will be listed at %s/servers.', get_server())],
+                       '$additional_info'  => ['additional_info', L10n::t('Additional Info'), $additional_info, L10n::t('For public servers: you can add additional information here that will be listed at %s/servers.', Search::getGlobalDirectory())],
                        '$language'         => ['language', L10n::t('System language'), Config::get('system', 'language'), '', $lang_choices],
                        '$theme'            => ['theme', L10n::t('System theme'), Config::get('system', 'theme'), L10n::t('Default system theme - may be over-ridden by user profiles - <a href="/admin/themes" id="cnftheme">Change default theme settings</a>'), $theme_choices],
                        '$theme_mobile'     => ['theme_mobile', L10n::t('Mobile system theme'), Config::get('system', 'mobile-theme', '---'), L10n::t('Theme for mobile devices'), $theme_choices_mobile],
@@ -625,7 +624,6 @@ class Site extends BaseAdminModule
                        '$community_page_style'   => ['community_page_style', L10n::t('Community pages for visitors'), Config::get('system', 'community_page_style'), L10n::t('Which community pages should be available for visitors. Local users always see both pages.'), $community_page_style_choices],
                        '$max_author_posts_community_page' => ['max_author_posts_community_page', L10n::t('Posts per user on community page'), Config::get('system', 'max_author_posts_community_page'), L10n::t('The maximum number of posts per user on the community page. (Not valid for "Global Community")')],
                        '$ostatus_disabled'       => ['ostatus_disabled', L10n::t('Disable OStatus support'), Config::get('system', 'ostatus_disabled'), L10n::t('Disable built-in OStatus (StatusNet, GNU Social etc.) compatibility. All communications in OStatus are public, so privacy warnings will be occasionally displayed.')],
-                       '$ostatus_full_threads'   => ['ostatus_full_threads', L10n::t('Only import OStatus/ActivityPub threads from our contacts'), Config::get('system', 'ostatus_full_threads'), L10n::t('Normally we import every content from our OStatus and ActivityPub contacts. With this option we only store threads that are started by a contact that is known on our system.')],
                        '$ostatus_not_able'       => L10n::t('OStatus support can only be enabled if threading is enabled.'),
                        '$diaspora_able'          => $diaspora_able,
                        '$diaspora_not_able'      => L10n::t('Diaspora support can\'t be enabled because Friendica was installed into a sub directory.'),
@@ -662,14 +660,14 @@ class Site extends BaseAdminModule
                        '$proxy_disabled'         => ['proxy_disabled', L10n::t('Disable picture proxy'), Config::get('system', 'proxy_disabled'), L10n::t('The picture proxy increases performance and privacy. It shouldn\'t be used on systems with very low bandwidth.')],
                        '$only_tag_search'        => ['only_tag_search', L10n::t('Only search in tags'), Config::get('system', 'only_tag_search'), L10n::t('On large systems the text search can slow down the system extremely.')],
 
-                       '$relocate_url'           => ['relocate_url', L10n::t('New base url'), $a->getBaseURL(), L10n::t('Change base url for this server. Sends relocate message to all Friendica and Diaspora* contacts of all users.')],
+                       '$relocate_url'           => ['relocate_url', L10n::t('New base url'), DI::baseUrl()->get(), L10n::t('Change base url for this server. Sends relocate message to all Friendica and Diaspora* contacts of all users.')],
 
                        '$rino'                   => ['rino', L10n::t('RINO Encryption'), intval(Config::get('system', 'rino_encrypt')), L10n::t('Encryption layer between nodes.'), [0 => L10n::t('Disabled'), 1 => L10n::t('Enabled')]],
 
                        '$worker_queues'          => ['worker_queues', L10n::t('Maximum number of parallel workers'), Config::get('system', 'worker_queues'), L10n::t('On shared hosters set this to %d. On larger systems, values of %d are great. Default value is %d.', 5, 20, 10)],
                        '$worker_dont_fork'       => ['worker_dont_fork', L10n::t('Don\'t use "proc_open" with the worker'), Config::get('system', 'worker_dont_fork'), L10n::t('Enable this if your system doesn\'t allow the use of "proc_open". This can happen on shared hosters. If this is enabled you should increase the frequency of worker calls in your crontab.')],
                        '$worker_fastlane'        => ['worker_fastlane', L10n::t('Enable fastlane'), Config::get('system', 'worker_fastlane'), L10n::t('When enabed, the fastlane mechanism starts an additional worker if processes with higher priority are blocked by processes of lower priority.')],
-                       '$worker_frontend'        => ['worker_frontend', L10n::t('Enable frontend worker'), Config::get('system', 'frontend_worker'), L10n::t('When enabled the Worker process is triggered when backend access is performed (e.g. messages being delivered). On smaller sites you might want to call %s/worker on a regular basis via an external cron job. You should only enable this option if you cannot utilize cron/scheduled jobs on your server.', $a->getBaseURL())],
+                       '$worker_frontend'        => ['worker_frontend', L10n::t('Enable frontend worker'), Config::get('system', 'frontend_worker'), L10n::t('When enabled the Worker process is triggered when backend access is performed (e.g. messages being delivered). On smaller sites you might want to call %s/worker on a regular basis via an external cron job. You should only enable this option if you cannot utilize cron/scheduled jobs on your server.', DI::baseUrl()->get())],
 
                        '$relay_subscribe'        => ['relay_subscribe', L10n::t('Subscribe to relay'), Config::get('system', 'relay_subscribe'), L10n::t('Enables the receiving of public posts from the relay. They will be included in the search, subscribed tags and on the global community page.')],
                        '$relay_server'           => ['relay_server', L10n::t('Relay server'), Config::get('system', 'relay_server', 'https://relay.diasp.org'), L10n::t('Address of the relay server where public posts should be send to. For example https://relay.diasp.org')],