Normalize use of form security tokens in Admin modules
[friendica.git/.git] / src / Module / Admin / Tos.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
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\Core\Renderer;
25 use Friendica\DI;
26 use Friendica\Module\BaseAdmin;
27
28 class Tos extends BaseAdmin
29 {
30         public static function post(array $parameters = [])
31         {
32                 parent::post($parameters);
33
34                 if (empty($_POST['page_tos'])) {
35                         return;
36                 }
37
38                 self::checkFormSecurityTokenRedirectOnError('/admin/tos', 'admin_tos');
39
40                 $displaytos = !empty($_POST['displaytos']);
41                 $displayprivstatement = !empty($_POST['displayprivstatement']);
42                 $tostext = (!empty($_POST['tostext']) ? strip_tags(trim($_POST['tostext'])) : '');
43
44                 DI::config()->set('system', 'tosdisplay', $displaytos);
45                 DI::config()->set('system', 'tosprivstatement', $displayprivstatement);
46                 DI::config()->set('system', 'tostext', $tostext);
47
48                 info(DI::l10n()->t('The Terms of Service settings have been updated.'));
49
50                 DI::baseUrl()->redirect('admin/tos');
51         }
52
53         public static function content(array $parameters = [])
54         {
55                 parent::content($parameters);
56
57                 $tos = new \Friendica\Module\Tos();
58                 $t = Renderer::getMarkupTemplate('admin/tos.tpl');
59                 return Renderer::replaceMacros($t, [
60                         '$title' => DI::l10n()->t('Administration'),
61                         '$page' => DI::l10n()->t('Terms of Service'),
62                         '$displaytos' => ['displaytos', DI::l10n()->t('Display Terms of Service'), DI::config()->get('system', 'tosdisplay'), DI::l10n()->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.')],
63                         '$displayprivstatement' => ['displayprivstatement', DI::l10n()->t('Display Privacy Statement'), DI::config()->get('system', 'tosprivstatement'), DI::l10n()->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')],
64                         '$preview' => DI::l10n()->t('Privacy Statement Preview'),
65                         '$privtext' => $tos->privacy_complete,
66                         '$tostext' => ['tostext', DI::l10n()->t('The Terms of Service'), DI::config()->get('system', 'tostext'), DI::l10n()->t('Enter the Terms of Service for your node here. You can use BBCode. Headers of sections should be [h2] and below.')],
67                         '$form_security_token' => self::getFormSecurityToken('admin_tos'),
68                         '$submit' => DI::l10n()->t('Save Settings'),
69                 ]);
70         }
71 }