3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Module\Settings\Server;
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;
36 class Action extends \Friendica\BaseModule
38 /** @var IHandleUserSessions */
40 /** @var UserGServer */
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 = [])
47 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
49 $this->session = $session;
50 $this->repository = $repository;
51 $this->gserverRepo = $gserverRepo;
54 public function content(array $request = []): string
56 $GServer = $this->gserverRepo->selectOneById($this->parameters['gsid']);
58 switch ($this->parameters['action']) {
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.");
64 $action = $this->t('Do you want to unignore this server?');
68 throw new BadRequestException('Unknown user server action ' . $this->parameters['action']);
71 $tpl = Renderer::getMarkupTemplate('settings/server/action.tpl');
72 return Renderer::replaceMacros($tpl, [
74 'title' => $this->t('Remote server settings'),
76 'siteName' => $this->t('Server Name'),
77 'siteUrl' => $this->t('Server URL'),
79 'submit' => $this->t('Submit'),
82 '$action' => $this->args->getQueryString(),
84 '$GServer' => $GServer,
86 '$form_security_token' => self::getFormSecurityToken('settings-server'),
90 public function post(array $request = [])
92 if (!empty($request['redirect_url'])) {
93 self::checkFormSecurityTokenRedirectOnError($this->args->getQueryString(), 'settings-server');
96 $userGServer = $this->repository->getOneByUserAndServer($this->session->getLocalUserId(), $this->parameters['gsid']);
98 switch ($this->parameters['action']) {
100 $userGServer->ignore();
103 $userGServer->unignore();
106 throw new BadRequestException('Unknown user server action ' . $this->parameters['action']);
109 $this->repository->save($userGServer);
111 if (!empty($request['redirect_url'])) {
112 $this->baseUrl->redirect($request['redirect_url']);