mirror of
https://github.com/friendica/friendica
synced 2024-12-23 04:00:15 +00:00
Add user settings page to manage remote server settings
This commit is contained in:
parent
4c6334ea13
commit
a670d478f8
4 changed files with 173 additions and 0 deletions
|
@ -151,6 +151,13 @@ class BaseSettings extends BaseModule
|
||||||
'accesskey' => 'b',
|
'accesskey' => 'b',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$tabs[] = [
|
||||||
|
'label' => $this->t('Remote servers'),
|
||||||
|
'url' => 'settings/server',
|
||||||
|
'selected' => static::class == Settings\Server\Index::class ? 'active' : '',
|
||||||
|
'accesskey' => 's',
|
||||||
|
];
|
||||||
|
|
||||||
$tabs[] = [
|
$tabs[] = [
|
||||||
'label' => $this->t('Export personal data'),
|
'label' => $this->t('Export personal data'),
|
||||||
'url' => 'settings/userexport',
|
'url' => 'settings/userexport',
|
||||||
|
|
126
src/Module/Settings/Server/Index.php
Normal file
126
src/Module/Settings/Server/Index.php
Normal file
|
@ -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),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -640,6 +640,7 @@ return [
|
||||||
|
|
||||||
'/settings' => [
|
'/settings' => [
|
||||||
'/server' => [
|
'/server' => [
|
||||||
|
'[/]' => [Module\Settings\Server\Index::class, [R::GET, R::POST]],
|
||||||
'/{gsid:\d+}/{action}' => [Module\Settings\Server\Action::class, [ R::POST]],
|
'/{gsid:\d+}/{action}' => [Module\Settings\Server\Action::class, [ R::POST]],
|
||||||
],
|
],
|
||||||
'[/]' => [Module\Settings\Account::class, [R::GET, R::POST]],
|
'[/]' => [Module\Settings\Account::class, [R::GET, R::POST]],
|
||||||
|
|
39
view/templates/settings/server/index.tpl
Normal file
39
view/templates/settings/server/index.tpl
Normal file
|
@ -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>
|
Loading…
Reference in a new issue