3 * @copyright Copyright (C) 2010-2022, 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\Admin\Blocklist;
24 use Friendica\Content\Pager;
25 use Friendica\Core\Renderer;
26 use Friendica\Core\Worker;
27 use Friendica\Database\DBA;
30 use Friendica\Module\BaseAdmin;
31 use Friendica\Util\Network;
33 class Contact extends BaseAdmin
35 protected function post(array $request = [])
37 self::checkAdminAccess();
39 self::checkFormSecurityTokenRedirectOnError('/admin/blocklist/contact', 'admin_contactblock');
41 $contact_url = $_POST['contact_url'] ?? '';
42 $block_reason = $_POST['contact_block_reason'] ?? '';
43 $block_purge = $_POST['contact_block_purge'] ?? false;
44 $contacts = $_POST['contacts'] ?? [];
46 if (!empty($_POST['page_contactblock_block'])) {
47 $contact = Model\Contact::getByURL($contact_url, null, ['id', 'nurl']);
48 if (empty($contact)) {
49 notice(DI::l10n()->t('Could not find any contact entry for this URL (%s)', $contact_url));
50 DI::baseUrl()->redirect('admin/blocklist/contact');
53 if (Network::isLocalLink($contact['nurl'])) {
54 notice(DI::l10n()->t('You can\'t block a local contact, please block the user instead'));
55 DI::baseUrl()->redirect('admin/blocklist/contact');
58 Model\Contact::block($contact['id'], $block_reason);
61 foreach (Model\Contact::selectToArray(['id'], ['nurl' => $contact['nurl']]) as $contact) {
62 Worker::add(PRIORITY_LOW, 'Contact\RemoveContent', $contact['id']);
66 info(DI::l10n()->t('The contact has been blocked from the node'));
69 if (!empty($_POST['page_contactblock_unblock'])) {
70 foreach ($contacts as $uid) {
71 Model\Contact::unblock($uid);
73 info(DI::l10n()->tt('%s contact unblocked', '%s contacts unblocked', count($contacts)));
76 DI::baseUrl()->redirect('admin/blocklist/contact');
79 protected function content(array $request = []): string
83 $condition = ['uid' => 0, 'blocked' => true];
85 $total = DBA::count('contact', $condition);
87 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 30);
89 $contacts = Model\Contact::selectToArray([], $condition, ['limit' => [$pager->getStart(), $pager->getItemsPerPage()]]);
91 $t = Renderer::getMarkupTemplate('admin/blocklist/contact.tpl');
92 $o = Renderer::replaceMacros($t, [
94 '$title' => DI::l10n()->t('Administration'),
95 '$page' => DI::l10n()->t('Remote Contact Blocklist'),
96 '$description' => DI::l10n()->t('This page allows you to prevent any message from a remote contact to reach your node.'),
97 '$submit' => DI::l10n()->t('Block Remote Contact'),
98 '$select_all' => DI::l10n()->t('select all'),
99 '$select_none' => DI::l10n()->t('select none'),
100 '$block' => DI::l10n()->t('Block'),
101 '$unblock' => DI::l10n()->t('Unblock'),
102 '$no_data' => DI::l10n()->t('No remote contact is blocked from this node.'),
104 '$h_contacts' => DI::l10n()->t('Blocked Remote Contacts'),
105 '$h_newblock' => DI::l10n()->t('Block New Remote Contact'),
106 '$th_contacts' => [DI::l10n()->t('Photo'), DI::l10n()->t('Name'), DI::l10n()->t('Reason')],
108 '$form_security_token' => self::getFormSecurityToken('admin_contactblock'),
111 '$baseurl' => DI::baseUrl()->get(true),
113 '$contacts' => $contacts,
114 '$total_contacts' => DI::l10n()->tt('%s total blocked contact', '%s total blocked contacts', $total),
115 '$paginate' => $pager->renderFull($total),
116 '$contacturl' => ['contact_url', DI::l10n()->t('Profile URL'), '', DI::l10n()->t('URL of the remote contact to block.')],
117 '$contact_block_purge' => ['contact_block_purge', DI::l10n()->t('Also purge contact'), false, DI::l10n()->t('Removes all content related to this contact from the node. Keeps the contact record. This action cannot be undone.')],
118 '$contact_block_reason' => ['contact_block_reason', DI::l10n()->t('Block Reason')],