mirror of
https://github.com/friendica/friendica
synced 2025-04-19 13:10:10 +00:00
New area "moderation"
- Moved several admin pages to the moderation area - ACL still is checking for administrator credentials
This commit is contained in:
parent
4fb7e9b023
commit
18f54f4425
61 changed files with 1707 additions and 1417 deletions
149
src/Module/Moderation/BaseUsers.php
Normal file
149
src/Module/Moderation/BaseUsers.php
Normal file
|
@ -0,0 +1,149 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022, 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\Moderation;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Register;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\BaseModeration;
|
||||
use Friendica\Module\Response;
|
||||
use Friendica\Navigation\SystemMessages;
|
||||
use Friendica\Network\HTTPException\ServiceUnavailableException;
|
||||
use Friendica\Util\Profiler;
|
||||
use Friendica\Util\Temporal;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
abstract class BaseUsers extends BaseModeration
|
||||
{
|
||||
/** @var Database */
|
||||
protected $database;
|
||||
|
||||
public function __construct(Database $database, App\Page $page, App $app, SystemMessages $systemMessages, IHandleUserSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($page, $app, $systemMessages, $session, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->database = $database;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the users moderation tabs menu
|
||||
*
|
||||
* @param string $selectedTab
|
||||
* @return string HTML
|
||||
* @throws ServiceUnavailableException
|
||||
*/
|
||||
protected function getTabsHTML(string $selectedTab): string
|
||||
{
|
||||
$all = $this->database->count('user', ["`uid` != ?", 0]);
|
||||
$active = $this->database->count('user', ["NOT `blocked` AND `verified` AND NOT `account_removed` AND `uid` != ?", 0]);
|
||||
$pending = Register::getPendingCount();
|
||||
$blocked = $this->database->count('user', ['blocked' => true, 'verified' => true, 'account_removed' => false]);
|
||||
$deleted = $this->database->count('user', ['account_removed' => true]);
|
||||
|
||||
$tabs = [
|
||||
[
|
||||
'label' => $this->t('All') . ' (' . $all . ')',
|
||||
'url' => 'moderation/users',
|
||||
'sel' => !$selectedTab || $selectedTab == 'all' ? 'active' : '',
|
||||
'title' => $this->t('List of all users'),
|
||||
'id' => 'admin-users-all',
|
||||
'accesskey' => 'a',
|
||||
],
|
||||
[
|
||||
'label' => $this->t('Active') . ' (' . $active . ')',
|
||||
'url' => 'moderation/users/active',
|
||||
'sel' => $selectedTab == 'active' ? 'active' : '',
|
||||
'title' => $this->t('List of active accounts'),
|
||||
'id' => 'admin-users-active',
|
||||
'accesskey' => 'k',
|
||||
],
|
||||
[
|
||||
'label' => $this->t('Pending') . ($pending ? ' (' . $pending . ')' : ''),
|
||||
'url' => 'moderation/users/pending',
|
||||
'sel' => $selectedTab == 'pending' ? 'active' : '',
|
||||
'title' => $this->t('List of pending registrations'),
|
||||
'id' => 'admin-users-pending',
|
||||
'accesskey' => 'p',
|
||||
],
|
||||
[
|
||||
'label' => $this->t('Blocked') . ($blocked ? ' (' . $blocked . ')' : ''),
|
||||
'url' => 'moderation/users/blocked',
|
||||
'sel' => $selectedTab == 'blocked' ? 'active' : '',
|
||||
'title' => $this->t('List of blocked users'),
|
||||
'id' => 'admin-users-blocked',
|
||||
'accesskey' => 'b',
|
||||
],
|
||||
[
|
||||
'label' => $this->t('Deleted') . ($deleted ? ' (' . $deleted . ')' : ''),
|
||||
'url' => 'moderation/users/deleted',
|
||||
'sel' => $selectedTab == 'deleted' ? 'active' : '',
|
||||
'title' => $this->t('List of pending user deletions'),
|
||||
'id' => 'admin-users-deleted',
|
||||
'accesskey' => 'd',
|
||||
],
|
||||
];
|
||||
|
||||
$tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
|
||||
return Renderer::replaceMacros($tpl, ['$tabs' => $tabs]);
|
||||
}
|
||||
|
||||
protected function setupUserCallback(): \Closure
|
||||
{
|
||||
$adminlist = explode(',', str_replace(' ', '', DI::config()->get('config', 'admin_email')));
|
||||
return function ($user) use ($adminlist) {
|
||||
$page_types = [
|
||||
User::PAGE_FLAGS_NORMAL => $this->t('Normal Account Page'),
|
||||
User::PAGE_FLAGS_SOAPBOX => $this->t('Soapbox Page'),
|
||||
User::PAGE_FLAGS_COMMUNITY => $this->t('Public Forum'),
|
||||
User::PAGE_FLAGS_FREELOVE => $this->t('Automatic Friend Page'),
|
||||
User::PAGE_FLAGS_PRVGROUP => $this->t('Private Forum')
|
||||
];
|
||||
$account_types = [
|
||||
User::ACCOUNT_TYPE_PERSON => $this->t('Personal Page'),
|
||||
User::ACCOUNT_TYPE_ORGANISATION => $this->t('Organisation Page'),
|
||||
User::ACCOUNT_TYPE_NEWS => $this->t('News Page'),
|
||||
User::ACCOUNT_TYPE_COMMUNITY => $this->t('Community Forum'),
|
||||
User::ACCOUNT_TYPE_RELAY => $this->t('Relay'),
|
||||
];
|
||||
|
||||
$user['page_flags_raw'] = $user['page-flags'];
|
||||
$user['page_flags'] = $page_types[$user['page-flags']];
|
||||
|
||||
$user['account_type_raw'] = ($user['page_flags_raw'] == 0) ? $user['account-type'] : -1;
|
||||
$user['account_type'] = ($user['page_flags_raw'] == 0) ? $account_types[$user['account-type']] : '';
|
||||
|
||||
$user['register_date'] = Temporal::getRelativeDate($user['register_date']);
|
||||
$user['login_date'] = Temporal::getRelativeDate($user['login_date']);
|
||||
$user['lastitem_date'] = Temporal::getRelativeDate($user['last-item']);
|
||||
$user['is_admin'] = in_array($user['email'], $adminlist);
|
||||
$user['is_deletable'] = !$user['account_removed'] && intval($user['uid']) != $this->session->getLocalUserId();
|
||||
$user['deleted'] = $user['account_removed'] ? Temporal::getRelativeDate($user['account_expires_on']) : false;
|
||||
|
||||
return $user;
|
||||
};
|
||||
}
|
||||
}
|
138
src/Module/Moderation/Blocklist/Contact.php
Normal file
138
src/Module/Moderation/Blocklist/Contact.php
Normal file
|
@ -0,0 +1,138 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022, 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\Moderation\Blocklist;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\Content\Pager;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Model;
|
||||
use Friendica\Module\BaseModeration;
|
||||
use Friendica\Module\Response;
|
||||
use Friendica\Navigation\SystemMessages;
|
||||
use Friendica\Util\Network;
|
||||
use Friendica\Util\Profiler;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Contact extends BaseModeration
|
||||
{
|
||||
/** @var Database */
|
||||
private $database;
|
||||
|
||||
public function __construct(Database $database, App\Page $page, App $app, SystemMessages $systemMessages, IHandleUserSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($page, $app, $systemMessages, $session, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->database = $database;
|
||||
}
|
||||
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
$this->checkModerationAccess();
|
||||
|
||||
self::checkFormSecurityTokenRedirectOnError('/moderation/blocklist/contact', 'moderation_contactblock');
|
||||
|
||||
$contact_url = $request['contact_url'] ?? '';
|
||||
$block_reason = $request['contact_block_reason'] ?? '';
|
||||
$block_purge = $request['contact_block_purge'] ?? false;
|
||||
$contacts = $request['contacts'] ?? [];
|
||||
|
||||
if (!empty($request['page_contactblock_block'])) {
|
||||
$contact = Model\Contact::getByURL($contact_url, null, ['id', 'nurl']);
|
||||
if (empty($contact)) {
|
||||
$this->systemMessages->addNotice($this->t('Could not find any contact entry for this URL (%s)', $contact_url));
|
||||
$this->baseUrl->redirect('moderation/blocklist/contact');
|
||||
}
|
||||
|
||||
if (Network::isLocalLink($contact['nurl'])) {
|
||||
$this->systemMessages->addNotice($this->t('You can\'t block a local contact, please block the user instead'));
|
||||
$this->baseUrl->redirect('moderation/blocklist/contact');
|
||||
}
|
||||
|
||||
Model\Contact::block($contact['id'], $block_reason);
|
||||
|
||||
if ($block_purge) {
|
||||
foreach (Model\Contact::selectToArray(['id'], ['nurl' => $contact['nurl']]) as $contact) {
|
||||
Worker::add(Worker::PRIORITY_LOW, 'Contact\RemoveContent', $contact['id']);
|
||||
}
|
||||
}
|
||||
|
||||
$this->systemMessages->addInfo($this->t('The contact has been blocked from the node'));
|
||||
}
|
||||
|
||||
if (!empty($request['page_contactblock_unblock'])) {
|
||||
foreach ($contacts as $uid) {
|
||||
Model\Contact::unblock($uid);
|
||||
}
|
||||
$this->systemMessages->addInfo($this->tt('%s contact unblocked', '%s contacts unblocked', count($contacts)));
|
||||
}
|
||||
|
||||
$this->baseUrl->redirect('moderation/blocklist/contact');
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
parent::content();
|
||||
|
||||
$condition = ['uid' => 0, 'blocked' => true];
|
||||
|
||||
$total = $this->database->count('contact', $condition);
|
||||
|
||||
$pager = new Pager($this->l10n, $this->args->getQueryString(), 30);
|
||||
|
||||
$contacts = Model\Contact::selectToArray([], $condition, ['limit' => [$pager->getStart(), $pager->getItemsPerPage()]]);
|
||||
|
||||
$t = Renderer::getMarkupTemplate('moderation/blocklist/contact.tpl');
|
||||
return Renderer::replaceMacros($t, [
|
||||
// strings //
|
||||
'$title' => $this->t('Moderation'),
|
||||
'$page' => $this->t('Remote Contact Blocklist'),
|
||||
'$description' => $this->t('This page allows you to prevent any message from a remote contact to reach your node.'),
|
||||
'$submit' => $this->t('Block Remote Contact'),
|
||||
'$select_all' => $this->t('select all'),
|
||||
'$select_none' => $this->t('select none'),
|
||||
'$block' => $this->t('Block'),
|
||||
'$unblock' => $this->t('Unblock'),
|
||||
'$no_data' => $this->t('No remote contact is blocked from this node.'),
|
||||
|
||||
'$h_contacts' => $this->t('Blocked Remote Contacts'),
|
||||
'$h_newblock' => $this->t('Block New Remote Contact'),
|
||||
'$th_contacts' => [$this->t('Photo'), $this->t('Name'), $this->t('Reason')],
|
||||
|
||||
'$form_security_token' => self::getFormSecurityToken('moderation_contactblock'),
|
||||
|
||||
// values //
|
||||
'$baseurl' => $this->baseUrl->get(true),
|
||||
|
||||
'$contacts' => $contacts,
|
||||
'$total_contacts' => $this->tt('%s total blocked contact', '%s total blocked contacts', $total),
|
||||
'$paginate' => $pager->renderFull($total),
|
||||
|
||||
'$contacturl' => ['contact_url', $this->t('Profile URL'), '', $this->t('URL of the remote contact to block.')],
|
||||
'$contact_block_purge' => ['contact_block_purge', $this->t('Also purge contact'), false, $this->t('Removes all content related to this contact from the node. Keeps the contact record. This action cannot be undone.')],
|
||||
'$contact_block_reason' => ['contact_block_reason', $this->t('Block Reason')],
|
||||
]);
|
||||
}
|
||||
}
|
143
src/Module/Moderation/Blocklist/Server/Add.php
Normal file
143
src/Module/Moderation/Blocklist/Server/Add.php
Normal file
|
@ -0,0 +1,143 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022, 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\Moderation\Blocklist\Server;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\Content\ContactSelector;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\GServer;
|
||||
use Friendica\Moderation\DomainPatternBlocklist;
|
||||
use Friendica\Module\BaseModeration;
|
||||
use Friendica\Module\Response;
|
||||
use Friendica\Navigation\SystemMessages;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Util\Profiler;
|
||||
use GuzzleHttp\Psr7\Uri;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Add extends BaseModeration
|
||||
{
|
||||
/** @var DomainPatternBlocklist */
|
||||
private $blocklist;
|
||||
|
||||
public function __construct(DomainPatternBlocklist $blocklist, App\Page $page, App $app, SystemMessages $systemMessages, IHandleUserSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($page, $app, $systemMessages, $session, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->blocklist = $blocklist;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $request
|
||||
* @return void
|
||||
* @throws HTTPException\ForbiddenException
|
||||
* @throws HTTPException\FoundException
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws HTTPException\MovedPermanentlyException
|
||||
* @throws HTTPException\TemporaryRedirectException
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
$this->checkModerationAccess();
|
||||
|
||||
if (empty($request['page_blocklist_add'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
self::checkFormSecurityTokenRedirectOnError('/moderation/blocklist/server/add', 'moderation_blocklist_add');
|
||||
|
||||
$pattern = trim($request['pattern']);
|
||||
|
||||
// Add new item to blocklist
|
||||
$this->blocklist->addPattern($pattern, trim($request['reason']));
|
||||
|
||||
$this->systemMessages->addInfo($this->t('Server domain pattern added to the blocklist.'));
|
||||
|
||||
if (!empty($request['purge'])) {
|
||||
$gservers = GServer::listByDomainPattern($pattern);
|
||||
foreach (Contact::selectToArray(['id'], ['gsid' => array_column($gservers, 'id')]) as $contact) {
|
||||
Worker::add(Worker::PRIORITY_LOW, 'Contact\RemoveContent', $contact['id']);
|
||||
}
|
||||
|
||||
$this->systemMessages->addInfo($this->tt('%s server scheduled to be purged.', '%s servers scheduled to be purged.', count($gservers)));
|
||||
}
|
||||
|
||||
$this->baseUrl->redirect('moderation/blocklist/server');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $request
|
||||
* @return string
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws HTTPException\ServiceUnavailableException
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
parent::content();
|
||||
|
||||
$gservers = [];
|
||||
|
||||
if ($pattern = trim($request['pattern'] ?? '')) {
|
||||
$gservers = GServer::listByDomainPattern($pattern);
|
||||
}
|
||||
|
||||
array_walk($gservers, function (array &$gserver) {
|
||||
$gserver['domain'] = (new Uri($gserver['url']))->getHost();
|
||||
$gserver['network_icon'] = ContactSelector::networkToIcon($gserver['network']);
|
||||
$gserver['network_name'] = ContactSelector::networkToName($gserver['network']);
|
||||
});
|
||||
|
||||
$t = Renderer::getMarkupTemplate('moderation/blocklist/server/add.tpl');
|
||||
return Renderer::replaceMacros($t, [
|
||||
'$l10n' => [
|
||||
'return_list' => $this->t('← Return to the list'),
|
||||
'title' => $this->t('Moderation'),
|
||||
'page' => $this->t('Block A New Server Domain Pattern'),
|
||||
'syntax' => $this->t('<p>The server domain pattern syntax is case-insensitive shell wildcard, comprising the following special characters:</p>
|
||||
<ul>
|
||||
<li><code>*</code>: Any number of characters</li>
|
||||
<li><code>?</code>: Any single character</li>
|
||||
</ul>'),
|
||||
'submit' => $this->t('Check pattern'),
|
||||
'matching_servers' => $this->t('Matching known servers'),
|
||||
'server_name' => $this->t('Server Name'),
|
||||
'server_domain' => $this->t('Server Domain'),
|
||||
'known_contacts' => $this->t('Known Contacts'),
|
||||
'server_count' => $this->tt('%d known server', '%d known servers', count($gservers)),
|
||||
'add_pattern' => $this->t('Add pattern to the blocklist'),
|
||||
],
|
||||
'$newdomain' => ['pattern', $this->t('Server Domain Pattern'), $pattern, $this->t('The domain pattern of the new server to add to the blocklist. Do not include the protocol.'), $this->t('Required'), '', ''],
|
||||
'$newpurge' => ['purge', $this->t('Purge server'), $request['purge'] ?? false, $this->tt('Also purges all the locally stored content authored by the known contacts registered on that server. Keeps the contacts and the server records. This action cannot be undone.', 'Also purges all the locally stored content authored by the known contacts registered on these servers. Keeps the contacts and the servers records. This action cannot be undone.', count($gservers))],
|
||||
'$newreason' => ['reason', $this->t('Block reason'), $request['reason'] ?? '', $this->t('The reason why you blocked this server domain pattern. This reason will be shown publicly in the server information page.'), $this->t('Required'), '', ''],
|
||||
'$pattern' => $pattern,
|
||||
'$gservers' => $gservers,
|
||||
'$baseurl' => $this->baseUrl->get(true),
|
||||
'$form_security_token' => self::getFormSecurityToken('moderation_blocklist_add')
|
||||
]);
|
||||
}
|
||||
}
|
134
src/Module/Moderation/Blocklist/Server/Import.php
Normal file
134
src/Module/Moderation/Blocklist/Server/Import.php
Normal file
|
@ -0,0 +1,134 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022, 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\Moderation\Blocklist\Server;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||
use Friendica\Moderation\DomainPatternBlocklist;
|
||||
use Friendica\Module\Response;
|
||||
use Friendica\Navigation\SystemMessages;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Util\Profiler;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Import extends \Friendica\Module\BaseModeration
|
||||
{
|
||||
/** @var DomainPatternBlocklist */
|
||||
private $localBlocklist;
|
||||
|
||||
/** @var array of blocked server domain patterns */
|
||||
private $blocklist = [];
|
||||
|
||||
public function __construct(DomainPatternBlocklist $localBlocklist, App\Page $page, App $app, SystemMessages $systemMessages, IHandleUserSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($page, $app, $systemMessages, $session, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->localBlocklist = $localBlocklist;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $request
|
||||
* @return void
|
||||
* @throws HTTPException\ForbiddenException
|
||||
* @throws HTTPException\FoundException
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws HTTPException\MovedPermanentlyException
|
||||
* @throws HTTPException\TemporaryRedirectException
|
||||
*/
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
$this->checkModerationAccess();
|
||||
|
||||
if (!isset($request['page_blocklist_upload']) && !isset($request['page_blocklist_import'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
self::checkFormSecurityTokenRedirectOnError('/moderation/blocklist/server/import', 'moderation_blocklist_import');
|
||||
|
||||
if (isset($request['page_blocklist_upload'])) {
|
||||
try {
|
||||
$this->blocklist = $this->localBlocklist::extractFromCSVFile($_FILES['listfile']['tmp_name']);
|
||||
} catch (\Throwable $e) {
|
||||
$this->systemMessages->addNotice($this->t('Error importing pattern file'));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($request['page_blocklist_import'])) {
|
||||
$blocklist = json_decode($request['blocklist'], true);
|
||||
if ($blocklist === null) {
|
||||
$this->systemMessages->addNotice($this->t('Error importing pattern file'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (($request['mode'] ?? 'append') == 'replace') {
|
||||
$this->localBlocklist->set($blocklist);
|
||||
$this->systemMessages->addNotice($this->t('Local blocklist replaced with the provided file.'));
|
||||
} else {
|
||||
$count = $this->localBlocklist->append($blocklist);
|
||||
if ($count) {
|
||||
$this->systemMessages->addNotice($this->tt('%d pattern was added to the local blocklist.', '%d patterns were added to the local blocklist.', $count));
|
||||
} else {
|
||||
$this->systemMessages->addNotice($this->t('No pattern was added to the local blocklist.'));
|
||||
}
|
||||
}
|
||||
|
||||
$this->baseUrl->redirect('/moderation/blocklist/server');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $request
|
||||
* @return string
|
||||
* @throws HTTPException\ServiceUnavailableException
|
||||
*/
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
parent::content();
|
||||
|
||||
$t = Renderer::getMarkupTemplate('moderation/blocklist/server/import.tpl');
|
||||
return Renderer::replaceMacros($t, [
|
||||
'$l10n' => [
|
||||
'return_list' => $this->t('← Return to the list'),
|
||||
'title' => $this->t('Moderation'),
|
||||
'page' => $this->t('Import a Server Domain Pattern Blocklist'),
|
||||
'download' => $this->t('<p>This file can be downloaded from the <code>/friendica</code> path of any Friendica server.</p>'),
|
||||
'upload' => $this->t('Upload file'),
|
||||
'patterns' => $this->t('Patterns to import'),
|
||||
'domain_pattern' => $this->t('Domain Pattern'),
|
||||
'block_reason' => $this->t('Block Reason'),
|
||||
'mode' => $this->t('Import Mode'),
|
||||
'import' => $this->t('Import Patterns'),
|
||||
'pattern_count' => $this->tt('%d total pattern', '%d total patterns', count($this->blocklist)),
|
||||
],
|
||||
'$listfile' => ['listfile', $this->t('Server domain pattern blocklist CSV file'), '', '', $this->t('Required'), '', 'file'],
|
||||
'$mode_append' => ['mode', $this->t('Append'), 'append', $this->t('Imports patterns from the file that weren\'t already existing in the current blocklist.'), 'checked="checked"'],
|
||||
'$mode_replace' => ['mode', $this->t('Replace'), 'replace', $this->t('Replaces the current blocklist by the imported patterns.')],
|
||||
'$blocklist' => $this->blocklist,
|
||||
'$baseurl' => $this->baseUrl->get(true),
|
||||
'$form_security_token' => self::getFormSecurityToken('moderation_blocklist_import')
|
||||
]);
|
||||
}
|
||||
}
|
121
src/Module/Moderation/Blocklist/Server/Index.php
Normal file
121
src/Module/Moderation/Blocklist/Server/Index.php
Normal file
|
@ -0,0 +1,121 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022, 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\Moderation\Blocklist\Server;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||
use Friendica\Moderation\DomainPatternBlocklist;
|
||||
use Friendica\Module\BaseModeration;
|
||||
use Friendica\Module\Response;
|
||||
use Friendica\Navigation\SystemMessages;
|
||||
use Friendica\Util\Profiler;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Index extends BaseModeration
|
||||
{
|
||||
/** @var DomainPatternBlocklist */
|
||||
private $blocklist;
|
||||
|
||||
public function __construct(DomainPatternBlocklist $blocklist, App\Page $page, App $app, SystemMessages $systemMessages, IHandleUserSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($page, $app, $systemMessages, $session, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->blocklist = $blocklist;
|
||||
}
|
||||
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
$this->checkModerationAccess();
|
||||
|
||||
if (empty($request['page_blocklist_edit'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
self::checkFormSecurityTokenRedirectOnError('/moderation/blocklist/server', 'moderation_blocklist');
|
||||
|
||||
// Edit the entries from blocklist
|
||||
$blocklist = [];
|
||||
foreach ($request['domain'] as $id => $domain) {
|
||||
// Trimming whitespaces as well as any lingering slashes
|
||||
$domain = trim($domain);
|
||||
$reason = trim($request['reason'][$id]);
|
||||
if (empty($request['delete'][$id])) {
|
||||
$blocklist[] = [
|
||||
'domain' => $domain,
|
||||
'reason' => $reason
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$this->blocklist->set($blocklist);
|
||||
|
||||
$this->baseUrl->redirect('moderation/blocklist/server');
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
parent::content();
|
||||
|
||||
$blocklistform = [];
|
||||
foreach ($this->blocklist->get() as $id => $b) {
|
||||
$blocklistform[] = [
|
||||
'domain' => ["domain[$id]", $this->t('Blocked server domain pattern'), $b['domain'], '', $this->t('Required'), '', ''],
|
||||
'reason' => ["reason[$id]", $this->t("Reason for the block"), $b['reason'], '', $this->t('Required'), '', ''],
|
||||
'delete' => ["delete[$id]", $this->t("Delete server domain pattern") . ' (' . $b['domain'] . ')', false, $this->t("Check to delete this entry from the blocklist")]
|
||||
];
|
||||
}
|
||||
|
||||
$t = Renderer::getMarkupTemplate('moderation/blocklist/server/index.tpl');
|
||||
return Renderer::replaceMacros($t, [
|
||||
'$l10n' => [
|
||||
'title' => $this->t('Moderation'),
|
||||
'page' => $this->t('Server Domain Pattern Blocklist'),
|
||||
'intro' => $this->t('This page can be used to define a blocklist of server domain patterns from the federated network that are not allowed to interact with your node. For each domain pattern you should also provide the reason why you block it.'),
|
||||
'public' => $this->t('The list of blocked server domain patterns will be made publically available on the <a href="/friendica">/friendica</a> page so that your users and people investigating communication problems can find the reason easily.'),
|
||||
'syntax' => $this->t('<p>The server domain pattern syntax is case-insensitive shell wildcard, comprising the following special characters:</p>
|
||||
<ul>
|
||||
<li><code>*</code>: Any number of characters</li>
|
||||
<li><code>?</code>: Any single character</li>
|
||||
</ul>'),
|
||||
'importtitle' => $this->t('Import server domain pattern blocklist'),
|
||||
'addtitle' => $this->t('Add new entry to the blocklist'),
|
||||
'importsubmit' => $this->t('Upload file'),
|
||||
'addsubmit' => $this->t('Check pattern'),
|
||||
'savechanges' => $this->t('Save changes to the blocklist'),
|
||||
'currenttitle' => $this->t('Current Entries in the Blocklist'),
|
||||
'thurl' => $this->t('Blocked server domain pattern'),
|
||||
'threason' => $this->t('Reason for the block'),
|
||||
'delentry' => $this->t('Delete entry from the blocklist'),
|
||||
'confirm_delete' => $this->t('Delete entry from the blocklist?'),
|
||||
],
|
||||
'$listfile' => ['listfile', $this->t('Server domain pattern blocklist CSV file'), '', '', $this->t('Required'), '', 'file'],
|
||||
'$newdomain' => ['pattern', $this->t('Server Domain Pattern'), '', $this->t('The domain pattern of the new server to add to the blocklist. Do not include the protocol.'), $this->t('Required'), '', ''],
|
||||
'$entries' => $blocklistform,
|
||||
'$baseurl' => $this->baseUrl->get(true),
|
||||
|
||||
'$form_security_token' => self::getFormSecurityToken('moderation_blocklist'),
|
||||
'$form_security_token_import' => self::getFormSecurityToken('moderation_blocklist_import'),
|
||||
]);
|
||||
}
|
||||
}
|
71
src/Module/Moderation/Item/Delete.php
Normal file
71
src/Module/Moderation/Item/Delete.php
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022, 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\Moderation\Item;
|
||||
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Module\BaseModeration;
|
||||
|
||||
class Delete extends BaseModeration
|
||||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
$this->checkModerationAccess();
|
||||
|
||||
if (empty($request['page_deleteitem_submit'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
self::checkFormSecurityTokenRedirectOnError('/moderation/item/delete', 'moderation_deleteitem');
|
||||
|
||||
$guid = trim($request['deleteitemguid']);
|
||||
// The GUID should not include a "/", so if there is one, we got an URL
|
||||
// and the last part of it is most likely the GUID.
|
||||
if (strpos($guid, '/')) {
|
||||
$guid = substr($guid, strrpos($guid, '/') + 1);
|
||||
}
|
||||
// Now that we have the GUID, drop those items, which will also delete the
|
||||
// associated threads.
|
||||
Item::markForDeletion(['guid' => $guid]);
|
||||
|
||||
$this->systemMessages->addInfo($this->t('Item marked for deletion.'));
|
||||
$this->baseUrl->redirect('moderation/item/delete');
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
parent::content();
|
||||
|
||||
$t = Renderer::getMarkupTemplate('moderation/item/delete.tpl');
|
||||
|
||||
return Renderer::replaceMacros($t, [
|
||||
'$title' => $this->t('Moderation'),
|
||||
'$page' => $this->t('Delete Item'),
|
||||
'$submit' => $this->t('Delete this Item'),
|
||||
'$intro1' => $this->t('On this page you can delete an item from your node. If the item is a top level posting, the entire thread will be deleted.'),
|
||||
'$intro2' => $this->t('You need to know the GUID of the item. You can find it e.g. by looking at the display URL. The last part of http://example.com/display/123456 is the GUID, here 123456.'),
|
||||
|
||||
'$deleteitemguid' => ['deleteitemguid', $this->t("GUID"), '', $this->t("The GUID of the item you want to delete."), $this->t('Required'), 'autofocus'],
|
||||
'$form_security_token' => self::getFormSecurityToken("moderation_deleteitem")
|
||||
]);
|
||||
}
|
||||
}
|
68
src/Module/Moderation/Item/Source.php
Normal file
68
src/Module/Moderation/Item/Source.php
Normal file
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022, 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\Moderation\Item;
|
||||
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Model;
|
||||
use Friendica\Module\BaseModeration;
|
||||
|
||||
class Source extends BaseModeration
|
||||
{
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
parent::content();
|
||||
|
||||
$guid = basename($request['guid'] ?? $this->parameters['guid'] ?? '');
|
||||
|
||||
$item_uri = '';
|
||||
$item_id = '';
|
||||
$terms = [];
|
||||
if (!empty($guid)) {
|
||||
$item = Model\Post::selectFirst(['id', 'uri-id', 'guid', 'uri'], ['guid' => $guid]);
|
||||
|
||||
if ($item) {
|
||||
$item_id = $item['id'];
|
||||
$item_uri = $item['uri'];
|
||||
$terms = Model\Tag::getByURIId($item['uri-id'], [Model\Tag::HASHTAG, Model\Tag::MENTION, Model\Tag::IMPLICIT_MENTION]);
|
||||
}
|
||||
}
|
||||
|
||||
$tpl = Renderer::getMarkupTemplate('moderation/item/source.tpl');
|
||||
return Renderer::replaceMacros($tpl, [
|
||||
'$title' => $this->t('Item Source'),
|
||||
'$guid' => ['guid', $this->t('Item Guid'), $guid, ''],
|
||||
'$item_uri' => $item_uri,
|
||||
'$item_id' => $item_id,
|
||||
'$terms' => $terms,
|
||||
'$itemidlbl' => $this->t('Item Id'),
|
||||
'$itemurilbl' => $this->t('Item URI'),
|
||||
'$submit' => $this->t('Submit'),
|
||||
'$termslbl' => $this->t('Terms'),
|
||||
'$taglbl' => $this->t('Tag'),
|
||||
'$typelbl' => $this->t('Type'),
|
||||
'$termlbl' => $this->t('Term'),
|
||||
'$urllbl' => $this->t('URL'),
|
||||
'$mentionlbl' => $this->t('Mention'),
|
||||
'$implicitlbl' => $this->t('Implicit Mention'),
|
||||
]);
|
||||
}
|
||||
}
|
84
src/Module/Moderation/Summary.php
Normal file
84
src/Module/Moderation/Summary.php
Normal file
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022, 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\Moderation;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Model\Register;
|
||||
use Friendica\Module\BaseModeration;
|
||||
use Friendica\Module\Response;
|
||||
use Friendica\Navigation\SystemMessages;
|
||||
use Friendica\Util\Profiler;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Summary extends BaseModeration
|
||||
{
|
||||
/** @var Database */
|
||||
private $database;
|
||||
|
||||
public function __construct(Database $database, App\Page $page, App $app, SystemMessages $systemMessages, IHandleUserSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($page, $app, $systemMessages, $session, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->database = $database;
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
parent::content();
|
||||
|
||||
$accounts = [
|
||||
[$this->t('Normal Account'), 0],
|
||||
[$this->t('Automatic Follower Account'), 0],
|
||||
[$this->t('Public Forum Account'), 0],
|
||||
[$this->t('Automatic Friend Account'), 0],
|
||||
[$this->t('Blog Account'), 0],
|
||||
[$this->t('Private Forum Account'), 0]
|
||||
];
|
||||
|
||||
$users = 0;
|
||||
|
||||
$pageFlagsCountStmt = $this->database->p('SELECT `page-flags`, COUNT(`uid`) AS `count` FROM `user` WHERE `uid` != ? GROUP BY `page-flags`', 0);
|
||||
while ($pageFlagsCount = $this->database->fetch($pageFlagsCountStmt)) {
|
||||
$accounts[$pageFlagsCount['page-flags']][1] = $pageFlagsCount['count'];
|
||||
$users += $pageFlagsCount['count'];
|
||||
}
|
||||
$this->database->close($pageFlagsCountStmt);
|
||||
|
||||
$this->logger->debug('accounts', ['accounts' => $accounts]);
|
||||
|
||||
$pending = Register::getPendingCount();
|
||||
|
||||
$t = Renderer::getMarkupTemplate('moderation/summary.tpl');
|
||||
return Renderer::replaceMacros($t, [
|
||||
'$title' => $this->t('Moderation'),
|
||||
'$page' => $this->t('Summary'),
|
||||
'$users' => [$this->t('Registered users'), $users],
|
||||
'$accounts' => $accounts,
|
||||
'$pending' => [$this->t('Pending registrations'), $pending],
|
||||
'$warningtext' => [],
|
||||
]);
|
||||
}
|
||||
}
|
161
src/Module/Moderation/Users/Active.php
Normal file
161
src/Module/Moderation/Users/Active.php
Normal file
|
@ -0,0 +1,161 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022, 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\Moderation\Users;
|
||||
|
||||
use Friendica\Content\Pager;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\Moderation\BaseUsers;
|
||||
|
||||
class Active extends BaseUsers
|
||||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
$this->checkModerationAccess();
|
||||
|
||||
self::checkFormSecurityTokenRedirectOnError($this->baseUrl->get(true), 'moderation_users_active');
|
||||
|
||||
$users = $request['user'] ?? [];
|
||||
|
||||
if (!empty($request['page_users_block'])) {
|
||||
foreach ($users as $uid) {
|
||||
User::block($uid);
|
||||
}
|
||||
$this->systemMessages->addInfo($this->tt('%s user blocked', '%s users blocked', count($users)));
|
||||
}
|
||||
|
||||
if (!empty($request['page_users_delete'])) {
|
||||
foreach ($users as $uid) {
|
||||
if ($this->session->getLocalUserId() != $uid) {
|
||||
User::remove($uid);
|
||||
} else {
|
||||
$this->systemMessages->addNotice($this->t('You can\'t remove yourself'));
|
||||
}
|
||||
}
|
||||
|
||||
$this->systemMessages->addInfo($this->tt('%s user deleted', '%s users deleted', count($users)));
|
||||
}
|
||||
|
||||
$this->baseUrl->redirect($this->args->getQueryString());
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
parent::content();
|
||||
|
||||
$action = $this->parameters['action'] ?? '';
|
||||
$uid = $this->parameters['uid'] ?? 0;
|
||||
|
||||
if ($uid) {
|
||||
$user = User::getById($uid, ['username', 'blocked']);
|
||||
if (!$user) {
|
||||
$this->systemMessages->addNotice($this->t('User not found'));
|
||||
$this->baseUrl->redirect('moderation/users');
|
||||
}
|
||||
}
|
||||
|
||||
switch ($action) {
|
||||
case 'delete':
|
||||
if ($this->session->getLocalUserId() != $uid) {
|
||||
self::checkFormSecurityTokenRedirectOnError('moderation/users/active', 'moderation_users_active', 't');
|
||||
// delete user
|
||||
User::remove($uid);
|
||||
|
||||
$this->systemMessages->addNotice($this->t('User "%s" deleted', $user['username']));
|
||||
} else {
|
||||
$this->systemMessages->addNotice($this->t('You can\'t remove yourself'));
|
||||
}
|
||||
|
||||
$this->baseUrl->redirect('moderation/users/active');
|
||||
break;
|
||||
case 'block':
|
||||
self::checkFormSecurityTokenRedirectOnError('moderation/users/active', 'moderation_users_active', 't');
|
||||
User::block($uid);
|
||||
$this->systemMessages->addNotice($this->t('User "%s" blocked', $user['username']));
|
||||
$this->baseUrl->redirect('moderation/users/active');
|
||||
break;
|
||||
}
|
||||
$pager = new Pager($this->l10n, $this->args->getQueryString(), 100);
|
||||
|
||||
$valid_orders = [
|
||||
'name',
|
||||
'email',
|
||||
'register_date',
|
||||
'login_date',
|
||||
'last-item',
|
||||
'page-flags',
|
||||
];
|
||||
|
||||
$order = 'name';
|
||||
$order_direction = '+';
|
||||
if (!empty($request['o'])) {
|
||||
$new_order = $request['o'];
|
||||
if ($new_order[0] === '-') {
|
||||
$order_direction = '-';
|
||||
$new_order = substr($new_order, 1);
|
||||
}
|
||||
|
||||
if (in_array($new_order, $valid_orders)) {
|
||||
$order = $new_order;
|
||||
}
|
||||
}
|
||||
|
||||
$users = User::getList($pager->getStart(), $pager->getItemsPerPage(), 'active', $order, ($order_direction == '-'));
|
||||
|
||||
$users = array_map($this->setupUserCallback(), $users);
|
||||
|
||||
$th_users = array_map(null, [$this->t('Name'), $this->t('Email'), $this->t('Register date'), $this->t('Last login'), $this->t('Last public item'), $this->t('Type')], $valid_orders);
|
||||
|
||||
$count = $this->database->count('user', ["NOT `blocked` AND `verified` AND NOT `account_removed` AND `uid` != ?", 0]);
|
||||
|
||||
$t = Renderer::getMarkupTemplate('moderation/users/active.tpl');
|
||||
return self::getTabsHTML('active') . Renderer::replaceMacros($t, [
|
||||
// strings //
|
||||
'$title' => $this->t('Moderation'),
|
||||
'$page' => $this->t('Active Accounts'),
|
||||
'$select_all' => $this->t('select all'),
|
||||
'$delete' => $this->t('Delete'),
|
||||
'$block' => $this->t('Block'),
|
||||
'$blocked' => $this->t('User blocked'),
|
||||
'$siteadmin' => $this->t('Site admin'),
|
||||
'$accountexpired' => $this->t('Account expired'),
|
||||
'$h_newuser' => $this->t('Create a new user'),
|
||||
|
||||
'$th_users' => $th_users,
|
||||
'$order_users' => $order,
|
||||
'$order_direction_users' => $order_direction,
|
||||
|
||||
'$confirm_delete_multi' => $this->t('Selected users will be deleted!\n\nEverything these users had posted on this site will be permanently deleted!\n\nAre you sure?'),
|
||||
'$confirm_delete' => $this->t('The user {0} will be deleted!\n\nEverything this user has posted on this site will be permanently deleted!\n\nAre you sure?'),
|
||||
|
||||
'$form_security_token' => self::getFormSecurityToken('moderation_users_active'),
|
||||
|
||||
// values //
|
||||
'$baseurl' => $this->baseUrl->get(true),
|
||||
'$query_string' => $this->args->getQueryString(),
|
||||
|
||||
'$users' => $users,
|
||||
'$count' => $count,
|
||||
'$pager' => $pager->renderFull($count),
|
||||
]);
|
||||
}
|
||||
}
|
160
src/Module/Moderation/Users/Blocked.php
Normal file
160
src/Module/Moderation/Users/Blocked.php
Normal file
|
@ -0,0 +1,160 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022, 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\Moderation\Users;
|
||||
|
||||
use Friendica\Content\Pager;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\Moderation\BaseUsers;
|
||||
|
||||
class Blocked extends BaseUsers
|
||||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
$this->checkModerationAccess();
|
||||
|
||||
self::checkFormSecurityTokenRedirectOnError('/moderation/users/blocked', 'moderation_users_blocked');
|
||||
|
||||
$users = $request['user'] ?? [];
|
||||
|
||||
if (!empty($request['page_users_unblock'])) {
|
||||
foreach ($users as $uid) {
|
||||
User::block($uid, false);
|
||||
}
|
||||
$this->systemMessages->addInfo($this->tt('%s user unblocked', '%s users unblocked', count($users)));
|
||||
}
|
||||
|
||||
if (!empty($request['page_users_delete'])) {
|
||||
foreach ($users as $uid) {
|
||||
if ($this->session->getLocalUserId() != $uid) {
|
||||
User::remove($uid);
|
||||
} else {
|
||||
$this->systemMessages->addNotice($this->t('You can\'t remove yourself'));
|
||||
}
|
||||
}
|
||||
|
||||
$this->systemMessages->addInfo($this->tt('%s user deleted', '%s users deleted', count($users)));
|
||||
}
|
||||
|
||||
$this->baseUrl->redirect('moderation/users/blocked');
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
parent::content();
|
||||
|
||||
$action = $this->parameters['action'] ?? '';
|
||||
$uid = $this->parameters['uid'] ?? 0;
|
||||
|
||||
if ($uid) {
|
||||
$user = User::getById($uid, ['username', 'blocked']);
|
||||
if (!$user) {
|
||||
$this->systemMessages->addNotice($this->t('User not found'));
|
||||
$this->baseUrl->redirect('moderation/users');
|
||||
}
|
||||
}
|
||||
|
||||
switch ($action) {
|
||||
case 'delete':
|
||||
if ($this->session->getLocalUserId() != $uid) {
|
||||
self::checkFormSecurityTokenRedirectOnError('/moderation/users/blocked', 'moderation_users_blocked', 't');
|
||||
// delete user
|
||||
User::remove($uid);
|
||||
|
||||
$this->systemMessages->addNotice($this->t('User "%s" deleted', $user['username']));
|
||||
} else {
|
||||
$this->systemMessages->addNotice($this->t('You can\'t remove yourself'));
|
||||
}
|
||||
$this->baseUrl->redirect('moderation/users/blocked');
|
||||
break;
|
||||
case 'unblock':
|
||||
self::checkFormSecurityTokenRedirectOnError('/moderation/users/blocked', 'moderation_users_blocked', 't');
|
||||
User::block($uid, false);
|
||||
$this->systemMessages->addNotice($this->t('User "%s" unblocked', $user['username']));
|
||||
$this->baseUrl->redirect('moderation/users/blocked');
|
||||
break;
|
||||
}
|
||||
|
||||
$pager = new Pager($this->l10n, $this->args->getQueryString(), 100);
|
||||
|
||||
$valid_orders = [
|
||||
'name',
|
||||
'email',
|
||||
'register_date',
|
||||
'login_date',
|
||||
'last-item',
|
||||
'page-flags',
|
||||
];
|
||||
|
||||
$order = 'name';
|
||||
$order_direction = '+';
|
||||
if (!empty($request['o'])) {
|
||||
$new_order = $request['o'];
|
||||
if ($new_order[0] === '-') {
|
||||
$order_direction = '-';
|
||||
$new_order = substr($new_order, 1);
|
||||
}
|
||||
|
||||
if (in_array($new_order, $valid_orders)) {
|
||||
$order = $new_order;
|
||||
}
|
||||
}
|
||||
|
||||
$users = User::getList($pager->getStart(), $pager->getItemsPerPage(), 'blocked', $order, ($order_direction == '-'));
|
||||
|
||||
$users = array_map($this->setupUserCallback(), $users);
|
||||
|
||||
$th_users = array_map(null, [$this->t('Name'), $this->t('Email'), $this->t('Register date'), $this->t('Last login'), $this->t('Last public item'), $this->t('Type')], $valid_orders);
|
||||
|
||||
$count = $this->database->count('user', ['blocked' => true, 'verified' => true]);
|
||||
|
||||
$t = Renderer::getMarkupTemplate('moderation/users/blocked.tpl');
|
||||
return self::getTabsHTML('blocked') . Renderer::replaceMacros($t, [
|
||||
// strings //
|
||||
'$title' => $this->t('Moderation'),
|
||||
'$page' => $this->t('Blocked Users'),
|
||||
'$select_all' => $this->t('select all'),
|
||||
'$delete' => $this->t('Delete'),
|
||||
'$blocked' => $this->t('User blocked'),
|
||||
'$unblock' => $this->t('Unblock'),
|
||||
'$siteadmin' => $this->t('Site admin'),
|
||||
'$accountexpired' => $this->t('Account expired'),
|
||||
|
||||
'$th_users' => $th_users,
|
||||
'$order_users' => $order,
|
||||
'$order_direction_users' => $order_direction,
|
||||
|
||||
'$confirm_delete_multi' => $this->t('Selected users will be deleted!\n\nEverything these users had posted on this site will be permanently deleted!\n\nAre you sure?'),
|
||||
'$confirm_delete' => $this->t('The user {0} will be deleted!\n\nEverything this user has posted on this site will be permanently deleted!\n\nAre you sure?'),
|
||||
|
||||
'$form_security_token' => self::getFormSecurityToken('moderation_users_blocked'),
|
||||
|
||||
// values //
|
||||
'$baseurl' => $this->baseUrl->get(true),
|
||||
'$query_string' => $this->args->getQueryString(),
|
||||
|
||||
'$users' => $users,
|
||||
'$count' => $count,
|
||||
'$pager' => $pager->renderFull($count)
|
||||
]);
|
||||
}
|
||||
}
|
76
src/Module/Moderation/Users/Create.php
Normal file
76
src/Module/Moderation/Users/Create.php
Normal file
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022, 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\Moderation\Users;
|
||||
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\Moderation\BaseUsers;
|
||||
|
||||
class Create extends BaseUsers
|
||||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
$this->checkModerationAccess();
|
||||
|
||||
self::checkFormSecurityTokenRedirectOnError('/admin/users/create', 'admin_users_create');
|
||||
|
||||
$nu_name = $request['new_user_name'] ?? '';
|
||||
$nu_nickname = $request['new_user_nickname'] ?? '';
|
||||
$nu_email = $request['new_user_email'] ?? '';
|
||||
$nu_language = DI::config()->get('system', 'language');
|
||||
|
||||
if ($nu_name !== '' && $nu_email !== '' && $nu_nickname !== '') {
|
||||
try {
|
||||
User::createMinimal($nu_name, $nu_email, $nu_nickname, $nu_language);
|
||||
$this->baseUrl->redirect('admin/users');
|
||||
} catch (\Exception $ex) {
|
||||
$this->systemMessages->addNotice($ex->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$this->baseUrl->redirect('admin/users/create');
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
parent::content();
|
||||
|
||||
$t = Renderer::getMarkupTemplate('admin/users/create.tpl');
|
||||
return self::getTabsHTML('all') . Renderer::replaceMacros($t, [
|
||||
// strings //
|
||||
'$title' => $this->t('Administration'),
|
||||
'$page' => $this->t('New User'),
|
||||
'$submit' => $this->t('Add User'),
|
||||
|
||||
'$form_security_token' => self::getFormSecurityToken('admin_users_create'),
|
||||
|
||||
// values //
|
||||
'$baseurl' => $this->baseUrl->get(true),
|
||||
'$query_string' => $this->args->getQueryString(),
|
||||
|
||||
'$newusername' => ['new_user_name', $this->t('Name'), '', $this->t('Name of the new user.')],
|
||||
'$newusernickname' => ['new_user_nickname', $this->t('Nickname'), '', $this->t('Nickname of the new user.')],
|
||||
'$newuseremail' => ['new_user_email', $this->t('Email'), '', $this->t('Email address of the new user.'), '', '', 'email'],
|
||||
]);
|
||||
}
|
||||
}
|
96
src/Module/Moderation/Users/Deleted.php
Normal file
96
src/Module/Moderation/Users/Deleted.php
Normal file
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022, 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\Moderation\Users;
|
||||
|
||||
use Friendica\Content\Pager;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\Moderation\BaseUsers;
|
||||
|
||||
class Deleted extends BaseUsers
|
||||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
$this->checkModerationAccess();
|
||||
|
||||
self::checkFormSecurityTokenRedirectOnError('/moderation/users/deleted', 'moderation_users_deleted');
|
||||
|
||||
// @TODO: Implement user deletion cancellation
|
||||
|
||||
$this->baseUrl->redirect('moderation/users/deleted');
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
parent::content();
|
||||
|
||||
$pager = new Pager($this->l10n, $this->args->getQueryString(), 100);
|
||||
|
||||
$valid_orders = [
|
||||
'name',
|
||||
'email',
|
||||
'register_date',
|
||||
'login_date',
|
||||
'last-item',
|
||||
'page-flags',
|
||||
];
|
||||
|
||||
$order = 'name';
|
||||
$order_direction = '+';
|
||||
if (!empty($request['o'])) {
|
||||
$new_order = $request['o'];
|
||||
if ($new_order[0] === '-') {
|
||||
$order_direction = '-';
|
||||
$new_order = substr($new_order, 1);
|
||||
}
|
||||
|
||||
if (in_array($new_order, $valid_orders)) {
|
||||
$order = $new_order;
|
||||
}
|
||||
}
|
||||
|
||||
$users = User::getList($pager->getStart(), $pager->getItemsPerPage(), 'removed', $order, ($order_direction == '-'));
|
||||
|
||||
$users = array_map($this->setupUserCallback(), $users);
|
||||
|
||||
$count = $this->database->count('user', ['account_removed' => true]);
|
||||
|
||||
$t = Renderer::getMarkupTemplate('moderation/users/deleted.tpl');
|
||||
return self::getTabsHTML('deleted') . Renderer::replaceMacros($t, [
|
||||
// strings //
|
||||
'$title' => $this->t('Moderation'),
|
||||
'$page' => $this->t('Users awaiting permanent deletion'),
|
||||
|
||||
'$th_deleted' => [$this->t('Name'), $this->t('Email'), $this->t('Register date'), $this->t('Last login'), $this->t('Last public item'), $this->t('Permanent deletion')],
|
||||
|
||||
'$form_security_token' => self::getFormSecurityToken('moderation_users_deleted'),
|
||||
|
||||
// values //
|
||||
'$baseurl' => $this->baseUrl->get(true),
|
||||
'$query_string' => $this->args->getQueryString(),
|
||||
|
||||
'$users' => $users,
|
||||
'$count' => $count,
|
||||
'$pager' => $pager->renderFull($count),
|
||||
]);
|
||||
}
|
||||
}
|
179
src/Module/Moderation/Users/Index.php
Normal file
179
src/Module/Moderation/Users/Index.php
Normal file
|
@ -0,0 +1,179 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022, 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\Moderation\Users;
|
||||
|
||||
use Friendica\Content\Pager;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\Moderation\BaseUsers;
|
||||
|
||||
class Index extends BaseUsers
|
||||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
$this->checkModerationAccess();
|
||||
|
||||
self::checkFormSecurityTokenRedirectOnError('moderation/users', 'moderation_users');
|
||||
|
||||
$users = $request['user'] ?? [];
|
||||
|
||||
if (!empty($request['page_users_block'])) {
|
||||
foreach ($users as $uid) {
|
||||
User::block($uid);
|
||||
}
|
||||
$this->systemMessages->addInfo($this->tt('%s user blocked', '%s users blocked', count($users)));
|
||||
}
|
||||
|
||||
if (!empty($request['page_users_unblock'])) {
|
||||
foreach ($users as $uid) {
|
||||
User::block($uid, false);
|
||||
}
|
||||
$this->systemMessages->addInfo($this->tt('%s user unblocked', '%s users unblocked', count($users)));
|
||||
}
|
||||
|
||||
if (!empty($request['page_users_delete'])) {
|
||||
foreach ($users as $uid) {
|
||||
if ($this->session->getLocalUserId() != $uid) {
|
||||
User::remove($uid);
|
||||
} else {
|
||||
$this->systemMessages->addNotice($this->t('You can\'t remove yourself'));
|
||||
}
|
||||
}
|
||||
|
||||
$this->systemMessages->addInfo($this->tt('%s user deleted', '%s users deleted', count($users)));
|
||||
}
|
||||
|
||||
$this->baseUrl->redirect($this->args->getQueryString());
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
parent::content();
|
||||
|
||||
$action = $this->parameters['action'] ?? '';
|
||||
$uid = $this->parameters['uid'] ?? 0;
|
||||
|
||||
if ($uid) {
|
||||
$user = User::getById($uid, ['username', 'blocked']);
|
||||
if (!$user) {
|
||||
$this->systemMessages->addNotice($this->t('User not found'));
|
||||
$this->baseUrl->redirect('moderation/users');
|
||||
}
|
||||
}
|
||||
|
||||
switch ($action) {
|
||||
case 'delete':
|
||||
if ($this->session->getLocalUserId() != $uid) {
|
||||
self::checkFormSecurityTokenRedirectOnError($this->baseUrl->get(true), 'moderation_users', 't');
|
||||
// delete user
|
||||
User::remove($uid);
|
||||
|
||||
$this->systemMessages->addNotice($this->t('User "%s" deleted', $user['username']));
|
||||
} else {
|
||||
$this->systemMessages->addNotice($this->t('You can\'t remove yourself'));
|
||||
}
|
||||
|
||||
$this->baseUrl->redirect('moderation/users');
|
||||
break;
|
||||
case 'block':
|
||||
self::checkFormSecurityTokenRedirectOnError('moderation/users', 'moderation_users', 't');
|
||||
User::block($uid);
|
||||
$this->systemMessages->addNotice($this->t('User "%s" blocked', $user['username']));
|
||||
$this->baseUrl->redirect('moderation/users');
|
||||
break;
|
||||
case 'unblock':
|
||||
self::checkFormSecurityTokenRedirectOnError('moderation/users', 'moderation_users', 't');
|
||||
User::block($uid, false);
|
||||
$this->systemMessages->addNotice($this->t('User "%s" unblocked', $user['username']));
|
||||
$this->baseUrl->redirect('moderation/users');
|
||||
break;
|
||||
}
|
||||
|
||||
$pager = new Pager($this->l10n, $this->args->getQueryString(), 100);
|
||||
|
||||
$valid_orders = [
|
||||
'name',
|
||||
'email',
|
||||
'register_date',
|
||||
'login_date',
|
||||
'last-item',
|
||||
'page-flags',
|
||||
];
|
||||
|
||||
$order = 'name';
|
||||
$order_direction = '+';
|
||||
if (!empty($request['o'])) {
|
||||
$new_order = $request['o'];
|
||||
if ($new_order[0] === '-') {
|
||||
$order_direction = '-';
|
||||
$new_order = substr($new_order, 1);
|
||||
}
|
||||
|
||||
if (in_array($new_order, $valid_orders)) {
|
||||
$order = $new_order;
|
||||
}
|
||||
}
|
||||
|
||||
$users = User::getList($pager->getStart(), $pager->getItemsPerPage(), 'all', $order, ($order_direction == '-'));
|
||||
|
||||
$users = array_map($this->setupUserCallback(), $users);
|
||||
|
||||
$th_users = array_map(null, [$this->t('Name'), $this->t('Email'), $this->t('Register date'), $this->t('Last login'), $this->t('Last public item'), $this->t('Type')], $valid_orders);
|
||||
|
||||
$count = $this->database->count('user', ["`uid` != ?", 0]);
|
||||
|
||||
$t = Renderer::getMarkupTemplate('moderation/users/index.tpl');
|
||||
return self::getTabsHTML('all') . Renderer::replaceMacros($t, [
|
||||
// strings //
|
||||
'$title' => $this->t('Moderation'),
|
||||
'$page' => $this->t('Users'),
|
||||
'$select_all' => $this->t('select all'),
|
||||
'$h_deleted' => $this->t('User waiting for permanent deletion'),
|
||||
'$delete' => $this->t('Delete'),
|
||||
'$block' => $this->t('Block'),
|
||||
'$blocked' => $this->t('User blocked'),
|
||||
'$unblock' => $this->t('Unblock'),
|
||||
'$siteadmin' => $this->t('Site admin'),
|
||||
'$accountexpired' => $this->t('Account expired'),
|
||||
|
||||
'$h_users' => $this->t('Users'),
|
||||
'$h_newuser' => $this->t('Create a new user'),
|
||||
'$th_deleted' => [$this->t('Name'), $this->t('Email'), $this->t('Register date'), $this->t('Last login'), $this->t('Last public item'), $this->t('Permanent deletion')],
|
||||
'$th_users' => $th_users,
|
||||
'$order_users' => $order,
|
||||
'$order_direction_users' => $order_direction,
|
||||
|
||||
'$confirm_delete_multi' => $this->t('Selected users will be deleted!\n\nEverything these users had posted on this site will be permanently deleted!\n\nAre you sure?'),
|
||||
'$confirm_delete' => $this->t('The user {0} will be deleted!\n\nEverything this user has posted on this site will be permanently deleted!\n\nAre you sure?'),
|
||||
|
||||
'$form_security_token' => self::getFormSecurityToken('moderation_users'),
|
||||
|
||||
// values //
|
||||
'$baseurl' => $this->baseUrl->get(true),
|
||||
'$query_string' => $this->args->getQueryString(),
|
||||
|
||||
'$users' => $users,
|
||||
'$count' => $count,
|
||||
'$pager' => $pager->renderFull($count),
|
||||
]);
|
||||
}
|
||||
}
|
116
src/Module/Moderation/Users/Pending.php
Normal file
116
src/Module/Moderation/Users/Pending.php
Normal file
|
@ -0,0 +1,116 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022, 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\Moderation\Users;
|
||||
|
||||
use Friendica\Content\Pager;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Model\Register;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\Moderation\BaseUsers;
|
||||
|
||||
class Pending extends BaseUsers
|
||||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
$this->checkModerationAccess();
|
||||
|
||||
self::checkFormSecurityTokenRedirectOnError('/admin/users/pending', 'admin_users_pending');
|
||||
|
||||
$pending = $request['pending'] ?? [];
|
||||
|
||||
if (!empty($request['page_users_approve'])) {
|
||||
foreach ($pending as $hash) {
|
||||
User::allow($hash);
|
||||
}
|
||||
$this->systemMessages->addInfo($this->tt('%s user approved', '%s users approved', count($pending)));
|
||||
}
|
||||
|
||||
if (!empty($request['page_users_deny'])) {
|
||||
foreach ($pending as $hash) {
|
||||
User::deny($hash);
|
||||
}
|
||||
$this->systemMessages->addInfo($this->tt('%s registration revoked', '%s registrations revoked', count($pending)));
|
||||
}
|
||||
|
||||
$this->baseUrl->redirect('admin/users/pending');
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
parent::content();
|
||||
|
||||
$action = $this->parameters['action'] ?? '';
|
||||
$uid = $this->parameters['uid'] ?? 0;
|
||||
|
||||
if ($uid) {
|
||||
$user = User::getById($uid, ['username', 'blocked']);
|
||||
if (!$user) {
|
||||
$this->systemMessages->addNotice($this->t('User not found'));
|
||||
$this->baseUrl->redirect('admin/users');
|
||||
}
|
||||
}
|
||||
|
||||
switch ($action) {
|
||||
case 'allow':
|
||||
self::checkFormSecurityTokenRedirectOnError('/admin/users/pending', 'admin_users_pending', 't');
|
||||
User::allow(Register::getPendingForUser($uid)['hash'] ?? '');
|
||||
$this->systemMessages->addNotice($this->t('Account approved.'));
|
||||
$this->baseUrl->redirect('admin/users/pending');
|
||||
break;
|
||||
case 'deny':
|
||||
self::checkFormSecurityTokenRedirectOnError('/admin/users/pending', 'admin_users_pending', 't');
|
||||
User::deny(Register::getPendingForUser($uid)['hash'] ?? '');
|
||||
$this->systemMessages->addNotice($this->t('Registration revoked'));
|
||||
$this->baseUrl->redirect('admin/users/pending');
|
||||
break;
|
||||
}
|
||||
|
||||
$pager = new Pager($this->l10n, $this->args->getQueryString(), 100);
|
||||
|
||||
$pending = Register::getPending($pager->getStart(), $pager->getItemsPerPage());
|
||||
|
||||
$count = Register::getPendingCount();
|
||||
|
||||
$t = Renderer::getMarkupTemplate('admin/users/pending.tpl');
|
||||
return self::getTabsHTML('pending') . Renderer::replaceMacros($t, [
|
||||
// strings //
|
||||
'$title' => $this->t('Administration'),
|
||||
'$page' => $this->t('User registrations awaiting review'),
|
||||
'$select_all' => $this->t('select all'),
|
||||
'$th_pending' => [$this->t('Request date'), $this->t('Name'), $this->t('Email')],
|
||||
'$no_pending' => $this->t('No registrations.'),
|
||||
'$pendingnotetext' => $this->t('Note from the user'),
|
||||
'$approve' => $this->t('Approve'),
|
||||
'$deny' => $this->t('Deny'),
|
||||
|
||||
'$form_security_token' => self::getFormSecurityToken('admin_users_pending'),
|
||||
|
||||
// values //
|
||||
'$baseurl' => $this->baseUrl->get(true),
|
||||
'$query_string' => $this->args->getQueryString(),
|
||||
|
||||
'$pending' => $pending,
|
||||
'$count' => $count,
|
||||
'$pager' => $pager->renderFull($count),
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue