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\Content\Pager;
26 use Friendica\Core\L10n;
27 use Friendica\Core\Renderer;
28 use Friendica\Core\Session\Capability\IHandleUserSessions;
29 use Friendica\Module\BaseSettings;
30 use Friendica\Module\Response;
31 use Friendica\Navigation\SystemMessages;
32 use Friendica\Network\HTTPException\NotFoundException;
33 use Friendica\User\Settings\Entity\UserGServer;
34 use Friendica\User\Settings\Repository;
35 use Friendica\Util\Profiler;
36 use Psr\Log\LoggerInterface;
38 class Index extends BaseSettings
40 /** @var Repository\UserGServer */
42 /** @var SystemMessages */
43 private $systemMessages;
45 public function __construct(SystemMessages $systemMessages, Repository\UserGServer $repository, IHandleUserSessions $session, App\Page $page, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
47 parent::__construct($session, $page, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
49 $this->repository = $repository;
50 $this->systemMessages = $systemMessages;
53 protected function post(array $request = [])
55 self::checkFormSecurityTokenRedirectOnError($this->args->getQueryString(), 'settings-server');
57 foreach ($request['delete'] ?? [] as $gsid => $delete) {
59 unset($request['ignored'][$gsid]);
62 $userGServer = $this->repository->selectOneByUserAndServer($this->session->getLocalUserId(), $gsid, false);
63 $this->repository->delete($userGServer);
64 } catch (NotFoundException $e) {
70 foreach ($request['ignored'] ?? [] as $gsid => $ignored) {
71 $userGServer = $this->repository->getOneByUserAndServer($this->session->getLocalUserId(), $gsid, false);
72 if ($userGServer->ignored != $ignored) {
73 $userGServer->toggleIgnored();
74 $this->repository->save($userGServer);
78 $this->systemMessages->addInfo($this->t('Settings saved'));
80 $this->baseUrl->redirect($this->args->getQueryString());
83 protected function content(array $request = []): string
87 $pager = new Pager($this->l10n, $this->args->getQueryString(), 30);
89 $total = $this->repository->countByUser($this->session->getLocalUserId());
91 $servers = $this->repository->selectByUserWithPagination($this->session->getLocalUserId(), $pager);
93 $ignoredCheckboxes = array_map(function (UserGServer $server) {
94 return ['ignored[' . $server->gsid . ']', '', $server->ignored];
95 }, $servers->getArrayCopy());
97 $deleteCheckboxes = array_map(function (UserGServer $server) {
98 return ['delete[' . $server->gsid . ']'];
99 }, $servers->getArrayCopy());
101 $tpl = Renderer::getMarkupTemplate('settings/server/index.tpl');
102 return Renderer::replaceMacros($tpl, [
104 'title' => $this->t('Remote server settings'),
105 'desc' => $this->t('Here you can find all the remote servers you have taken individual moderation actions against. For a list of servers your node has blocked, please check out the <a href="friendica">Information</a> page.'),
106 'siteName' => $this->t('Server Name'),
107 'ignored' => $this->t('Ignored'),
108 'ignored_title' => $this->t("You won't see any content from this server including reshares in your Network page, the community pages and individual conversations."),
109 'delete' => $this->t('Delete'),
110 'delete_title' => $this->t('Delete all your settings for the remote server'),
111 'submit' => $this->t('Save changes'),
116 '$servers' => $servers,
118 '$form_security_token' => self::getFormSecurityToken('settings-server'),
120 '$ignoredCheckboxes' => $ignoredCheckboxes,
121 '$deleteCheckboxes' => $deleteCheckboxes,
123 '$paginate' => $pager->renderFull($total),