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