]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Tos.php
Introduce `Response` for Modules to create a testable way for module responses
[friendica.git] / src / Module / Admin / Tos.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Module\Admin;
23
24 use Friendica\App;
25 use Friendica\Core\Config\Capability\IManageConfigValues;
26 use Friendica\Core\L10n;
27 use Friendica\Core\Renderer;
28 use Friendica\Module\BaseAdmin;
29 use Friendica\Module\Response;
30 use Friendica\Util\Profiler;
31 use Psr\Log\LoggerInterface;
32
33 class Tos extends BaseAdmin
34 {
35         /** @var \Friendica\Module\Tos */
36         protected $tos;
37         /** @var IManageConfigValues */
38         protected $config;
39
40         public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, \Friendica\Module\Tos $tos, IManageConfigValues $config, array $server, array $parameters = [])
41         {
42                 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
43
44                 $this->tos     = $tos;
45                 $this->config  = $config;
46         }
47
48         protected function post(array $request = [], array $post = [])
49         {
50                 self::checkAdminAccess();
51
52                 if (empty($_POST['page_tos'])) {
53                         return;
54                 }
55
56                 self::checkFormSecurityTokenRedirectOnError('/admin/tos', 'admin_tos');
57
58                 $displaytos = !empty($_POST['displaytos']);
59                 $displayprivstatement = !empty($_POST['displayprivstatement']);
60                 $tostext = (!empty($_POST['tostext']) ? strip_tags(trim($_POST['tostext'])) : '');
61
62                 $this->config->set('system', 'tosdisplay', $displaytos);
63                 $this->config->set('system', 'tosprivstatement', $displayprivstatement);
64                 $this->config->set('system', 'tostext', $tostext);
65
66                 $this->baseUrl->redirect('admin/tos');
67         }
68
69         protected function content(array $request = []): string
70         {
71                 parent::content();
72
73                 $t = Renderer::getMarkupTemplate('admin/tos.tpl');
74                 return Renderer::replaceMacros($t, [
75                         '$title' => $this->t('Administration'),
76                         '$page' => $this->t('Terms of Service'),
77                         '$displaytos' => ['displaytos', $this->t('Display Terms of Service'), $this->config->get('system', 'tosdisplay'), $this->t('Enable the Terms of Service page. If this is enabled a link to the terms will be added to the registration form and the general information page.')],
78                         '$displayprivstatement' => ['displayprivstatement', $this->t('Display Privacy Statement'), $this->config->get('system', 'tosprivstatement'), $this->t('Show some informations regarding the needed information to operate the node according e.g. to <a href="%s" target="_blank" rel="noopener noreferrer">EU-GDPR</a>.', 'https://en.wikipedia.org/wiki/General_Data_Protection_Regulation')],
79                         '$preview' => $this->t('Privacy Statement Preview'),
80                         '$privtext' => $this->tos->privacy_complete,
81                         '$tostext' => ['tostext', $this->t('The Terms of Service'), $this->config->get('system', 'tostext'), $this->t('Enter the Terms of Service for your node here. You can use BBCode. Headers of sections should be [h2] and below.')],
82                         '$form_security_token' => self::getFormSecurityToken('admin_tos'),
83                         '$submit' => $this->t('Save Settings'),
84                 ]);
85         }
86 }