906e03629a553efaf1e5d2b3064971941fb1d3a3
[friendica.git/.git] / src / Module / Settings / 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\Settings;
23
24 use Friendica\App;
25 use Friendica\Content\Feature;
26 use Friendica\Core\L10n;
27 use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
28 use Friendica\Core\Renderer;
29 use Friendica\Core\Session\Capability\IHandleUserSessions;
30 use Friendica\Module\BaseSettings;
31 use Friendica\Module\Response;
32 use Friendica\Util\Profiler;
33 use Psr\Log\LoggerInterface;
34
35 class Features extends BaseSettings
36 {
37         /** @var IManagePersonalConfigValues */
38         private $pConfig;
39
40         public function __construct(IManagePersonalConfigValues $pConfig, IHandleUserSessions $session, App\Page $page, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
41         {
42                 parent::__construct($session, $page, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
43
44                 $this->pConfig = $pConfig;
45         }
46
47         protected function post(array $request = [])
48         {
49                 BaseSettings::checkFormSecurityTokenRedirectOnError('/settings/features', 'settings_features');
50                 foreach ($request as $k => $v) {
51                         if (strpos($k, 'feature_') === 0) {
52                                 $this->pConfig->set($this->session->getLocalUserId(), 'feature', substr($k, 8), ((intval($v)) ? 1 : 0));
53                         }
54                 }
55         }
56
57         protected function content(array $request = []): string
58         {
59                 parent::content($request);
60
61                 $arr      = [];
62                 $features = Feature::get();
63                 foreach ($features as $name => $feature) {
64                         $arr[$name]    = [];
65                         $arr[$name][0] = $feature[0];
66                         foreach (array_slice($feature, 1) as $f) {
67                                 $arr[$name][1][] = ['feature_' . $f[0], $f[1], Feature::isEnabled($this->session->getLocalUserId(), $f[0]), $f[2]];
68                         }
69                 }
70
71                 $tpl = Renderer::getMarkupTemplate('settings/features.tpl');
72                 return Renderer::replaceMacros($tpl, [
73                         '$form_security_token' => BaseSettings::getFormSecurityToken('settings_features'),
74                         '$title'               => $this->t('Additional Features'),
75                         '$features'            => $arr,
76                         '$submit'              => $this->t('Save Settings'),
77                 ]);
78         }
79 }