3 * @copyright Copyright (C) 2020, Friendica
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\Database\DBA;
28 use Friendica\Module\BaseAdmin;
31 class Contact extends BaseAdmin
33 public static function post(array $parameters = [])
35 parent::post($parameters);
37 $contact_url = $_POST['contact_url'] ?? '';
38 $block_reason = $_POST['contact_block_reason'] ?? '';
39 $contacts = $_POST['contacts'] ?? [];
41 parent::checkFormSecurityTokenRedirectOnError('/admin/blocklist/contact', 'admin_contactblock');
43 if (!empty($_POST['page_contactblock_block'])) {
44 $contact_id = Model\Contact::getIdForURL($contact_url);
46 Model\Contact::block($contact_id, $block_reason);
47 notice(DI::l10n()->t('The contact has been blocked from the node'));
49 notice(DI::l10n()->t('Could not find any contact entry for this URL (%s)', $contact_url));
53 if (!empty($_POST['page_contactblock_unblock'])) {
54 foreach ($contacts as $uid) {
55 Model\Contact::unblock($uid);
57 notice(DI::l10n()->tt('%s contact unblocked', '%s contacts unblocked', count($contacts)));
60 DI::baseUrl()->redirect('admin/blocklist/contact');
63 public static function content(array $parameters = [])
65 parent::content($parameters);
67 $condition = ['uid' => 0, 'blocked' => true];
69 $total = DBA::count('contact', $condition);
71 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 30);
73 $contacts = Model\Contact::selectToArray([], $condition, ['limit' => [$pager->getStart(), $pager->getItemsPerPage()]]);
75 $t = Renderer::getMarkupTemplate('admin/blocklist/contact.tpl');
76 $o = Renderer::replaceMacros($t, [
78 '$title' => DI::l10n()->t('Administration'),
79 '$page' => DI::l10n()->t('Remote Contact Blocklist'),
80 '$description' => DI::l10n()->t('This page allows you to prevent any message from a remote contact to reach your node.'),
81 '$submit' => DI::l10n()->t('Block Remote Contact'),
82 '$select_all' => DI::l10n()->t('select all'),
83 '$select_none' => DI::l10n()->t('select none'),
84 '$block' => DI::l10n()->t('Block'),
85 '$unblock' => DI::l10n()->t('Unblock'),
86 '$no_data' => DI::l10n()->t('No remote contact is blocked from this node.'),
88 '$h_contacts' => DI::l10n()->t('Blocked Remote Contacts'),
89 '$h_newblock' => DI::l10n()->t('Block New Remote Contact'),
90 '$th_contacts' => [DI::l10n()->t('Photo'), DI::l10n()->t('Name'), DI::l10n()->t('Reason')],
92 '$form_security_token' => parent::getFormSecurityToken('admin_contactblock'),
95 '$baseurl' => DI::baseUrl()->get(true),
97 '$contacts' => $contacts,
98 '$total_contacts' => DI::l10n()->tt('%s total blocked contact', '%s total blocked contacts', $total),
99 '$paginate' => $pager->renderFull($total),
100 '$contacturl' => ['contact_url', DI::l10n()->t('Profile URL'), '', DI::l10n()->t('URL of the remote contact to block.')],
101 '$contact_block_reason' => ['contact_block_reason', DI::l10n()->t('Block Reason')],