]> git.mxchange.org Git - friendica.git/commitdiff
Add user settings page to manage remote server settings
authorHypolite Petovan <hypolite@mrpetovan.com>
Sun, 16 Jul 2023 21:26:31 +0000 (17:26 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sun, 20 Aug 2023 18:27:09 +0000 (14:27 -0400)
src/Module/BaseSettings.php
src/Module/Settings/Server/Index.php [new file with mode: 0644]
static/routes.config.php
view/templates/settings/server/index.tpl [new file with mode: 0644]

index a1e88e9a104a3b0a12630d4e97ebd1c160f383f0..4b26a0f262d85f764b091147918b23c52657298d 100644 (file)
@@ -151,6 +151,13 @@ class BaseSettings extends BaseModule
                        'accesskey' => 'b',
                ];
 
+               $tabs[] = [
+                       'label'     => $this->t('Remote servers'),
+                       'url'       => 'settings/server',
+                       'selected'  => static::class == Settings\Server\Index::class ? 'active' : '',
+                       'accesskey' => 's',
+               ];
+
                $tabs[] = [
                        'label'     => $this->t('Export personal data'),
                        'url'       => 'settings/userexport',
diff --git a/src/Module/Settings/Server/Index.php b/src/Module/Settings/Server/Index.php
new file mode 100644 (file)
index 0000000..f59e23a
--- /dev/null
@@ -0,0 +1,126 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2023, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Module\Settings\Server;
+
+use Friendica\App;
+use Friendica\Content\Pager;
+use Friendica\Core\L10n;
+use Friendica\Core\Renderer;
+use Friendica\Core\Session\Capability\IHandleUserSessions;
+use Friendica\Module\BaseSettings;
+use Friendica\Module\Response;
+use Friendica\Navigation\SystemMessages;
+use Friendica\Network\HTTPException\NotFoundException;
+use Friendica\User\Settings\Entity\UserGServer;
+use Friendica\User\Settings\Repository;
+use Friendica\Util\Profiler;
+use Psr\Log\LoggerInterface;
+
+class Index extends BaseSettings
+{
+       /** @var Repository\UserGServer */
+       private $repository;
+       /** @var SystemMessages */
+       private $systemMessages;
+
+       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 = [])
+       {
+               parent::__construct($session, $page, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
+
+               $this->repository     = $repository;
+               $this->systemMessages = $systemMessages;
+       }
+
+       protected function post(array $request = [])
+       {
+               self::checkFormSecurityTokenRedirectOnError($this->args->getQueryString(), 'settings-server');
+
+               foreach ($request['delete'] ?? [] as $gsid => $delete) {
+                       if ($delete) {
+                               unset($request['ignored'][$gsid]);
+
+                               try {
+                                       $userGServer = $this->repository->selectOneByUserAndServer($this->session->getLocalUserId(), $gsid, false);
+                                       $this->repository->delete($userGServer);
+                               } catch (NotFoundException $e) {
+                                       // Nothing to delete
+                               }
+                       }
+               }
+
+               foreach ($request['ignored'] ?? [] as $gsid => $ignored) {
+                       $userGServer = $this->repository->getOneByUserAndServer($this->session->getLocalUserId(), $gsid, false);
+                       if ($userGServer->ignored != $ignored) {
+                               $userGServer->toggleIgnored();
+                               $this->repository->save($userGServer);
+                       }
+               }
+
+               $this->systemMessages->addInfo($this->t('Settings saved'));
+
+               $this->baseUrl->redirect($this->args->getQueryString());
+       }
+
+       protected function content(array $request = []): string
+       {
+               parent::content();
+
+               $pager = new Pager($this->l10n, $this->args->getQueryString(), 30);
+
+               $total = $this->repository->countByUser($this->session->getLocalUserId());
+
+               $servers = $this->repository->selectByUserWithPagination($this->session->getLocalUserId(), $pager);
+
+               $ignoredCheckboxes = array_map(function (UserGServer $server) {
+                       return ['ignored[' . $server->gsid . ']', '', $server->ignored];
+               }, $servers->getArrayCopy());
+
+               $deleteCheckboxes = array_map(function (UserGServer $server) {
+                       return ['delete[' . $server->gsid . ']'];
+               }, $servers->getArrayCopy());
+
+               $tpl = Renderer::getMarkupTemplate('settings/server/index.tpl');
+               return Renderer::replaceMacros($tpl, [
+                       '$l10n' => [
+                               'title'         => $this->t('Remote server settings'),
+                               '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.'),
+                               'siteName'      => $this->t('Server Name'),
+                               'ignored'       => $this->t('Ignored'),
+                               '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."),
+                               'delete'        => $this->t('Delete'),
+                               'delete_title'  => $this->t('Delete all your settings for the remote server'),
+                               'submit'        => $this->t('Save changes'),
+                       ],
+
+                       '$count' => $total,
+
+                       '$servers' => $servers,
+
+                       '$form_security_token' => self::getFormSecurityToken('settings-server'),
+
+                       '$ignoredCheckboxes' => $ignoredCheckboxes,
+                       '$deleteCheckboxes'  => $deleteCheckboxes,
+
+                       '$paginate' => $pager->renderFull($total),
+               ]);
+       }
+}
index edfd69ea20e9388c1f58e82f62c9846c08a89a14..f16a1936272a2639b2c1f853d6ad4eae75487f0d 100644 (file)
@@ -640,6 +640,7 @@ return [
 
        '/settings' => [
                '/server' => [
+                       '[/]'                  => [Module\Settings\Server\Index::class,  [R::GET, R::POST]],
                        '/{gsid:\d+}/{action}' => [Module\Settings\Server\Action::class, [        R::POST]],
                ],
                '[/]'         => [Module\Settings\Account::class,               [R::GET, R::POST]],
diff --git a/view/templates/settings/server/index.tpl b/view/templates/settings/server/index.tpl
new file mode 100644 (file)
index 0000000..112af6d
--- /dev/null
@@ -0,0 +1,39 @@
+<div id="settings-server" class="generic-page-wrapper">
+       <h1>{{$l10n.title}} ({{$count}})</h1>
+
+       <p>{{$l10n.desc nofilter}}</p>
+
+       {{$paginate nofilter}}
+
+       <form action="" method="POST">
+               <input type="hidden" name="form_security_token" value="{{$form_security_token}}">
+
+               <p><button type="submit" class="btn btn-primary">{{$l10n.submit}}</button></p>
+
+               <table class="table table-striped table-condensed table-bordered">
+                       <tr>
+                               <th>{{$l10n.siteName}}</th>
+                               <th><span title="{{$l10n.ignored_title}}">{{$l10n.ignored}} <i class="fa fa-question-circle"></i></span></th>
+                               <th><span title="{{$l10n.delete_title}}"><i class="fa fa-trash"  aria-hidden="true" title="{{$l10n.delete}}"></i> <span class="sr-only">{{$l10n.delete}}</span> <i class="fa fa-question-circle"></i></span></th>
+                       </tr>
+
+{{foreach $servers as $index => $server}}
+                       <tr>
+                               <td>
+                                       <a href="{{$server->gserver->url}}">{{($server->gserver->siteName) ? $server->gserver->siteName : $server->gserver->url}} <i class="fa fa-external-link"></i></a>
+                               </td>
+                               <td>
+                       {{include file="field_checkbox.tpl" field=$ignoredCheckboxes[$index]}}
+                               </td>
+                               <td>
+                       {{include file="field_checkbox.tpl" field=$deleteCheckboxes[$index]}}
+                               </td>
+                       </tr>
+{{/foreach}}
+
+               </table>
+               <p><button type="submit" class="btn btn-primary">{{$l10n.submit}}</button></p>
+       </form>
+
+    {{$paginate nofilter}}
+</div>