]> git.mxchange.org Git - friendica.git/blob - src/Module/Settings/Server/Action.php
Merge pull request #13724 from Raroun/Fix-for-Issue-#13637---Photo-caption-prevents...
[friendica.git] / src / Module / Settings / Server / Action.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\Settings\Server;
23
24 use Friendica\App;
25 use Friendica\Core\L10n;
26 use Friendica\Core\Renderer;
27 use Friendica\Core\Session\Capability\IHandleUserSessions;
28 use Friendica\Core\System;
29 use Friendica\Federation\Repository\GServer;
30 use Friendica\Module\Response;
31 use Friendica\Network\HTTPException\BadRequestException;
32 use Friendica\User\Settings\Repository\UserGServer;
33 use Friendica\Util\Profiler;
34 use Psr\Log\LoggerInterface;
35
36 class Action extends \Friendica\BaseModule
37 {
38         /** @var IHandleUserSessions */
39         private $session;
40         /** @var UserGServer */
41         private $repository;
42         /** @var GServer */
43         private $gserverRepo;
44
45         public function __construct(GServer $gserverRepo, UserGServer $repository, IHandleUserSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
46         {
47                 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
48
49                 $this->session     = $session;
50                 $this->repository  = $repository;
51                 $this->gserverRepo = $gserverRepo;
52         }
53
54         public function content(array $request = []): string
55         {
56                 $GServer = $this->gserverRepo->selectOneById($this->parameters['gsid']);
57
58                 switch ($this->parameters['action']) {
59                         case 'ignore':
60                                 $action = $this->t('Do you want to ignore this server?');
61                                 $desc   = $this->t("You won't see any content from this server including reshares in your Network page, the community pages and individual conversations.");
62                                 break;
63                         case 'unignore':
64                                 $action = $this->t('Do you want to unignore this server?');
65                                 $desc   = '';
66                                 break;
67                         default:
68                                 throw new BadRequestException('Unknown user server action ' . $this->parameters['action']);
69                 }
70
71                 $tpl = Renderer::getMarkupTemplate('settings/server/action.tpl');
72                 return Renderer::replaceMacros($tpl, [
73                         '$l10n' => [
74                                 'title'    => $this->t('Remote server settings'),
75                                 'action'   => $action,
76                                 'siteName' => $this->t('Server Name'),
77                                 'siteUrl'  => $this->t('Server URL'),
78                                 'desc'     => $desc,
79                                 'submit'   => $this->t('Submit'),
80                         ],
81
82                         '$action' => $this->args->getQueryString(),
83
84                         '$GServer' => $GServer,
85
86                         '$form_security_token' => self::getFormSecurityToken('settings-server'),
87                 ]);
88         }
89
90         public function post(array $request = [])
91         {
92                 if (!empty($request['redirect_url'])) {
93                         self::checkFormSecurityTokenRedirectOnError($this->args->getQueryString(), 'settings-server');
94                 }
95
96                 $userGServer = $this->repository->getOneByUserAndServer($this->session->getLocalUserId(), $this->parameters['gsid']);
97
98                 switch ($this->parameters['action']) {
99                         case 'ignore':
100                                 $userGServer->ignore();
101                                 break;
102                         case 'unignore':
103                                 $userGServer->unignore();
104                                 break;
105                         default:
106                                 throw new BadRequestException('Unknown user server action ' . $this->parameters['action']);
107                 }
108
109                 $this->repository->save($userGServer);
110
111                 if (!empty($request['redirect_url'])) {
112                         $this->baseUrl->redirect($request['redirect_url']);
113                 }
114
115                 System::exit();
116         }
117 }