3 namespace Friendica\Module\Admin\Blocklist;
5 use Friendica\Content\Pager;
6 use Friendica\Core\Renderer;
7 use Friendica\Database\DBA;
9 use Friendica\Module\BaseAdmin;
12 class Contact extends BaseAdmin
14 public static function post(array $parameters = [])
16 parent::post($parameters);
18 $contact_url = $_POST['contact_url'] ?? '';
19 $block_reason = $_POST['contact_block_reason'] ?? '';
20 $contacts = $_POST['contacts'] ?? [];
22 parent::checkFormSecurityTokenRedirectOnError('/admin/blocklist/contact', 'admin_contactblock');
24 if (!empty($_POST['page_contactblock_block'])) {
25 $contact_id = Model\Contact::getIdForURL($contact_url);
27 Model\Contact::block($contact_id, $block_reason);
28 notice(DI::l10n()->t('The contact has been blocked from the node'));
30 notice(DI::l10n()->t('Could not find any contact entry for this URL (%s)', $contact_url));
34 if (!empty($_POST['page_contactblock_unblock'])) {
35 foreach ($contacts as $uid) {
36 Model\Contact::unblock($uid);
38 notice(DI::l10n()->tt('%s contact unblocked', '%s contacts unblocked', count($contacts)));
41 DI::baseUrl()->redirect('admin/blocklist/contact');
44 public static function content(array $parameters = [])
46 parent::content($parameters);
48 $condition = ['uid' => 0, 'blocked' => true];
50 $total = DBA::count('contact', $condition);
52 $pager = new Pager(DI::args()->getQueryString(), 30);
54 $contacts = Model\Contact::selectToArray([], $condition, ['limit' => [$pager->getStart(), $pager->getItemsPerPage()]]);
56 $t = Renderer::getMarkupTemplate('admin/blocklist/contact.tpl');
57 $o = Renderer::replaceMacros($t, [
59 '$title' => DI::l10n()->t('Administration'),
60 '$page' => DI::l10n()->t('Remote Contact Blocklist'),
61 '$description' => DI::l10n()->t('This page allows you to prevent any message from a remote contact to reach your node.'),
62 '$submit' => DI::l10n()->t('Block Remote Contact'),
63 '$select_all' => DI::l10n()->t('select all'),
64 '$select_none' => DI::l10n()->t('select none'),
65 '$block' => DI::l10n()->t('Block'),
66 '$unblock' => DI::l10n()->t('Unblock'),
67 '$no_data' => DI::l10n()->t('No remote contact is blocked from this node.'),
69 '$h_contacts' => DI::l10n()->t('Blocked Remote Contacts'),
70 '$h_newblock' => DI::l10n()->t('Block New Remote Contact'),
71 '$th_contacts' => [DI::l10n()->t('Photo'), DI::l10n()->t('Name'), DI::l10n()->t('Reason')],
73 '$form_security_token' => parent::getFormSecurityToken('admin_contactblock'),
76 '$baseurl' => DI::baseUrl()->get(true),
78 '$contacts' => $contacts,
79 '$total_contacts' => DI::l10n()->tt('%s total blocked contact', '%s total blocked contacts', $total),
80 '$paginate' => $pager->renderFull($total),
81 '$contacturl' => ['contact_url', DI::l10n()->t('Profile URL'), '', DI::l10n()->t('URL of the remote contact to block.')],
82 '$contact_block_reason' => ['contact_block_reason', DI::l10n()->t('Block Reason')],