5df6cefd87ff74f98b24a600c467dc1c07985f5c
[friendica.git/.git] / src / Module / Admin / Features.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2024, 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\Content\Feature;
25 use Friendica\Core\Renderer;
26 use Friendica\DI;
27 use Friendica\Module\BaseAdmin;
28
29 class Features extends BaseAdmin
30 {
31         protected function post(array $request = [])
32         {
33                 self::checkAdminAccess();
34
35                 self::checkFormSecurityTokenRedirectOnError('/admin/features', 'admin_manage_features');
36
37                 foreach (Feature::get(false) as $fdata) {
38                         foreach (array_slice($fdata, 1) as $f) {
39                                 $feature = $f[0];
40                                 $feature_state = 'feature_' . $feature;
41                                 $featurelock = 'featurelock_' . $feature;
42
43                                 DI::config()->set('feature', $feature, !empty($_POST[$feature_state]));
44
45                                 if (!empty($_POST[$featurelock])) {
46                                         DI::config()->set('feature_lock', $feature, true);
47                                 } else {
48                                         DI::config()->delete('feature_lock', $feature);
49                                 }
50                         }
51                 }
52
53                 DI::baseUrl()->redirect('admin/features');
54         }
55
56         protected function content(array $request = []): string
57         {
58                 parent::content();
59
60                 $features = [];
61
62                 foreach (Feature::get(false) as $fname => $fdata) {
63                         $features[$fname] = [];
64                         $features[$fname][0] = $fdata[0];
65                         foreach (array_slice($fdata, 1) as $f) {
66                                 $set = DI::config()->get('feature', $f[0], $f[3]);
67                                 $feature = [['feature_' . $f[0], $f[1], $set, $f[2]]];
68                                 if (empty($f[5])) {
69                                         $feature[] = ['featurelock_' . $f[0], DI::l10n()->t('Lock feature %s', $f[1]), $f[4], ''];
70                                 }
71                                 $features[$fname][1][] = $feature;
72                         }
73                 }
74
75                 $tpl = Renderer::getMarkupTemplate('admin/features.tpl');
76                 $o = Renderer::replaceMacros($tpl, [
77                         '$form_security_token' => self::getFormSecurityToken("admin_manage_features"),
78                         '$title'               => DI::l10n()->t('Manage Additional Features'),
79                         '$features'            => $features,
80                         '$submit'              => DI::l10n()->t('Save Settings'),
81                 ]);
82
83                 return $o;
84         }
85 }