]> git.mxchange.org Git - friendica.git/blob - src/Module/BaseSettings.php
Changes:
[friendica.git] / src / Module / BaseSettings.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;
23
24 use Friendica\App;
25 use Friendica\BaseModule;
26 use Friendica\Content\Feature;
27 use Friendica\Content\Nav;
28 use Friendica\Core\L10n;
29 use Friendica\Core\Renderer;
30 use Friendica\Core\Session\Capability\IHandleUserSessions;
31 use Friendica\Network\HTTPException\ForbiddenException;
32 use Friendica\Util\Profiler;
33 use Psr\Log\LoggerInterface;
34
35 class BaseSettings extends BaseModule
36 {
37         /** @var App\Page */
38         protected $page;
39         /** @var IHandleUserSessions */
40         protected $session;
41
42         public function __construct(IHandleUserSessions $session, App\Page $page, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
43         {
44                 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
45
46                 $this->page    = $page;
47                 $this->session = $session;
48
49                 if ($this->session->getSubManagedUserId()) {
50                         throw new ForbiddenException($this->t('Permission denied.'));
51                 }
52         }
53
54         protected function content(array $request = []): string
55         {
56                 Nav::setSelected('settings');
57
58                 if (!$this->session->getLocalUserId()) {
59                         $this->session->set('return_path', $this->args->getCommand());
60                         $this->baseUrl->redirect('login');
61                 }
62
63                 $this->createAside();
64
65                 return '';
66         }
67
68         public function createAside()
69         {
70                 $tpl = Renderer::getMarkupTemplate('settings/head.tpl');
71                 $this->page['htmlhead'] .= Renderer::replaceMacros($tpl, [
72                         '$ispublic' => $this->t('everybody')
73                 ]);
74
75                 $tabs = [];
76
77                 $tabs[] = [
78                         'label'     => $this->t('Account'),
79                         'url'       => 'settings',
80                         'selected'  => static::class == Settings\Account::class ? 'active' : '',
81                         'accesskey' => 'o',
82                 ];
83
84                 $tabs[] = [
85                         'label'     => $this->t('Two-factor authentication'),
86                         'url'       => 'settings/2fa',
87                         'selected'  => in_array(static::class, [
88                                 Settings\TwoFactor\AppSpecific::class,
89                                 Settings\TwoFactor\Index::class,
90                                 Settings\TwoFactor\Recovery::class,
91                                 Settings\TwoFactor\Trusted::class,
92                                 Settings\TwoFactor\Verify::class
93                         ]) ? 'active' : '',
94                         'accesskey' => '2',
95                 ];
96
97                 $tabs[] = [
98                         'label'     => $this->t('Profile'),
99                         'url'       => 'settings/profile',
100                         'selected'  => in_array(static::class, [
101                                 Settings\Profile\Index::class,
102                                 Settings\Profile\Photo\Crop::class,
103                                 Settings\Profile\Photo\Index::class,
104                         ]) ? 'active' : '',
105                         'accesskey' => 'p',
106                 ];
107
108                 if (Feature::get()) {
109                         $tabs[] = [
110                                 'label'     => $this->t('Additional features'),
111                                 'url'       => 'settings/features',
112                                 'selected'  => static::class == Settings\Features::class ? 'active' : '',
113                                 'accesskey' => 't',
114                         ];
115                 }
116
117                 $tabs[] = [
118                         'label'     => $this->t('Display'),
119                         'url'       => 'settings/display',
120                         'selected'  => static::class == Settings\Display::class ? 'active' : '',
121                         'accesskey' => 'i',
122                 ];
123
124                 $tabs[] = [
125                         'label'     => $this->t('Channels'),
126                         'url'       => 'settings/channels',
127                         'selected'  => static::class == Settings\Channels::class ? 'active' : '',
128                         'accesskey' => '',
129                 ];
130
131                 $tabs[] = [
132                         'label'     => $this->t('Social Networks'),
133                         'url'       => 'settings/connectors',
134                         'selected'  => static::class == Settings\Connectors::class ? 'active' : '',
135                         'accesskey' => 'w',
136                 ];
137
138                 $tabs[] = [
139                         'label'     => $this->t('Addons'),
140                         'url'       => 'settings/addons',
141                         'selected'  => static::class == Settings\Addons::class ? 'active' : '',
142                         'accesskey' => 'l',
143                 ];
144
145                 $tabs[] = [
146                         'label'     => $this->t('Manage Accounts'),
147                         'url'       => 'settings/delegation',
148                         'selected'  => static::class == Settings\Delegation::class ? 'active' : '',
149                         'accesskey' => 'd',
150                 ];
151
152                 $tabs[] = [
153                         'label'     => $this->t('Connected apps'),
154                         'url'       => 'settings/oauth',
155                         'selected'  => static::class == Settings\OAuth::class ? 'active' : '',
156                         'accesskey' => 'b',
157                 ];
158
159                 $tabs[] = [
160                         'label'     => $this->t('Remote servers'),
161                         'url'       => 'settings/server',
162                         'selected'  => static::class == Settings\Server\Index::class ? 'active' : '',
163                         'accesskey' => 's',
164                 ];
165
166                 $tabs[] = [
167                         'label'     => $this->t('Export personal data'),
168                         'url'       => 'settings/userexport',
169                         'selected'  => static::class == Settings\UserExport::class ? 'active' : '',
170                         'accesskey' => 'e',
171                 ];
172
173                 $tabs[] = [
174                         'label'     => $this->t('Remove account'),
175                         'url'       => 'settings/removeme',
176                         'selected'  => static::class === Settings\RemoveMe::class ? 'active' : '',
177                         'accesskey' => 'r',
178                 ];
179
180                 $tabtpl              = Renderer::getMarkupTemplate('generic_links_widget.tpl');
181                 $this->page['aside'] = Renderer::replaceMacros($tabtpl, [
182                         '$title' => $this->t('Settings'),
183                         '$class' => 'settings-widget',
184                         '$items' => $tabs,
185                 ]);
186         }
187 }