]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Admin/Logs/Settings.php
Some removed escapeTags calls
[friendica.git] / src / Module / Admin / Logs / Settings.php
index b9a5e3832d87b3d3dd6027a0c9cb1442a1eb723d..b0fcaebc33117d00e07a34870cd7681e6dff4233 100644 (file)
@@ -1,47 +1,64 @@
 <?php
+/**
+ * @copyright Copyright (C) 2010-2021, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
 
 namespace Friendica\Module\Admin\Logs;
 
-use Friendica\Core\Config;
-use Friendica\Core\L10n;
 use Friendica\Core\Renderer;
-use Friendica\Module\BaseAdminModule;
+use Friendica\DI;
+use Friendica\Module\BaseAdmin;
 use Friendica\Util\Strings;
 use Psr\Log\LogLevel;
 
-class Settings extends BaseAdminModule
+class Settings extends BaseAdmin
 {
-       public static function post()
+       public static function post(array $parameters = [])
        {
-               parent::post();
+               self::checkAdminAccess();
 
-               if (!empty($_POST['page_logs'])) {
-                       parent::checkFormSecurityTokenRedirectOnError('/admin/logs', 'admin_logs');
+               if (empty($_POST['page_logs'])) {
+                       return;
+               }
 
-                       $logfile   = (!empty($_POST['logfile']) ? Strings::escapeTags(trim($_POST['logfile'])) : '');
-                       $debugging = !empty($_POST['debugging']);
-                       $loglevel  = defaults($_POST, 'loglevel', LogLevel::ERROR);
+               self::checkFormSecurityTokenRedirectOnError('/admin/logs', 'admin_logs');
 
-                       if (is_file($logfile) &&
-                       !is_writeable($logfile)) {
-                               notice(L10n::t('The logfile \'%s\' is not writable. No logging possible', $logfile));
-                               return;
-                       }
+               $logfile   = (!empty($_POST['logfile']) ? trim($_POST['logfile']) : '');
+               $debugging = !empty($_POST['debugging']);
+               $loglevel  = ($_POST['loglevel'] ?? '') ?: LogLevel::ERROR;
 
-                       Config::set('system', 'logfile', $logfile);
-                       Config::set('system', 'debugging', $debugging);
-                       Config::set('system', 'loglevel', $loglevel);
+               if (is_file($logfile) &&
+               !is_writeable($logfile)) {
+                       notice(DI::l10n()->t('The logfile \'%s\' is not writable. No logging possible', $logfile));
+                       return;
                }
 
-               info(L10n::t("Log settings updated."));
-               self::getApp()->internalRedirect('admin/logs');
+               DI::config()->set('system', 'logfile', $logfile);
+               DI::config()->set('system', 'debugging', $debugging);
+               DI::config()->set('system', 'loglevel', $loglevel);
+
+               DI::baseUrl()->redirect('admin/logs');
        }
 
-       public static function content()
+       public static function content(array $parameters = [])
        {
-               parent::content();
-
-               $a = self::getApp();
+               parent::content($parameters);
 
                $log_choices = [
                        LogLevel::ERROR   => 'Error',
@@ -52,27 +69,27 @@ class Settings extends BaseAdminModule
                ];
 
                if (ini_get('log_errors')) {
-                       $phplogenabled = L10n::t('PHP log currently enabled.');
+                       $phplogenabled = DI::l10n()->t('PHP log currently enabled.');
                } else {
-                       $phplogenabled = L10n::t('PHP log currently disabled.');
+                       $phplogenabled = DI::l10n()->t('PHP log currently disabled.');
                }
 
                $t = Renderer::getMarkupTemplate('admin/logs/settings.tpl');
 
                return Renderer::replaceMacros($t, [
-                       '$title' => L10n::t('Administration'),
-                       '$page' => L10n::t('Logs'),
-                       '$submit' => L10n::t('Save Settings'),
-                       '$clear' => L10n::t('Clear'),
-                       '$baseurl' => $a->getBaseURL(true),
-                       '$logname' => Config::get('system', 'logfile'),
+                       '$title' => DI::l10n()->t('Administration'),
+                       '$page' => DI::l10n()->t('Logs'),
+                       '$submit' => DI::l10n()->t('Save Settings'),
+                       '$clear' => DI::l10n()->t('Clear'),
+                       '$baseurl' => DI::baseUrl()->get(true),
+                       '$logname' => DI::config()->get('system', 'logfile'),
                        // see /help/smarty3-templates#1_1 on any Friendica node
-                       '$debugging' => ['debugging', L10n::t("Enable Debugging"), Config::get('system', 'debugging'), ""],
-                       '$logfile' => ['logfile', L10n::t("Log file"), Config::get('system', 'logfile'), L10n::t("Must be writable by web server. Relative to your Friendica top-level directory.")],
-                       '$loglevel' => ['loglevel', L10n::t("Log level"), Config::get('system', 'loglevel'), "", $log_choices],
-                       '$form_security_token' => parent::getFormSecurityToken("admin_logs"),
-                       '$phpheader' => L10n::t("PHP logging"),
-                       '$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."),
+                       '$debugging' => ['debugging', DI::l10n()->t("Enable Debugging"), DI::config()->get('system', 'debugging'), ""],
+                       '$logfile' => ['logfile', DI::l10n()->t("Log file"), DI::config()->get('system', 'logfile'), DI::l10n()->t("Must be writable by web server. Relative to your Friendica top-level directory.")],
+                       '$loglevel' => ['loglevel', DI::l10n()->t("Log level"), DI::config()->get('system', 'loglevel'), "", $log_choices],
+                       '$form_security_token' => self::getFormSecurityToken("admin_logs"),
+                       '$phpheader' => DI::l10n()->t("PHP logging"),
+                       '$phphint' => DI::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,
                ]);