3 namespace Friendica\Module\Admin\Blocklist;
5 use Friendica\Content\Pager;
6 use Friendica\Core\L10n;
7 use Friendica\Core\Renderer;
8 use Friendica\Database\DBA;
9 use Friendica\Module\BaseAdminModule;
12 class Contact extends BaseAdminModule
14 public static function post()
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(L10n::t('The contact has been blocked from the node'));
30 notice(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(L10n::tt('%s contact unblocked', '%s contacts unblocked', count($contacts)));
41 self::getApp()->internalRedirect('admin/blocklist/contact');
44 public static function content()
50 $condition = ['uid' => 0, 'blocked' => true];
52 $total = DBA::count('contact', $condition);
54 $pager = new Pager($a->query_string, 30);
56 $contacts = Model\Contact::selectToArray([], $condition, ['limit' => [$pager->getStart(), $pager->getItemsPerPage()]]);
58 $t = Renderer::getMarkupTemplate('admin/blocklist/contact.tpl');
59 $o = Renderer::replaceMacros($t, [
61 '$title' => L10n::t('Administration'),
62 '$page' => L10n::t('Remote Contact Blocklist'),
63 '$description' => L10n::t('This page allows you to prevent any message from a remote contact to reach your node.'),
64 '$submit' => L10n::t('Block Remote Contact'),
65 '$select_all' => L10n::t('select all'),
66 '$select_none' => L10n::t('select none'),
67 '$block' => L10n::t('Block'),
68 '$unblock' => L10n::t('Unblock'),
69 '$no_data' => L10n::t('No remote contact is blocked from this node.'),
71 '$h_contacts' => L10n::t('Blocked Remote Contacts'),
72 '$h_newblock' => L10n::t('Block New Remote Contact'),
73 '$th_contacts' => [L10n::t('Photo'), L10n::t('Name'), L10n::t('Reason')],
75 '$form_security_token' => parent::getFormSecurityToken('admin_contactblock'),
78 '$baseurl' => $a->getBaseURL(true),
80 '$contacts' => $contacts,
81 '$total_contacts' => L10n::tt('%s total blocked contact', '%s total blocked contacts', $total),
82 '$paginate' => $pager->renderFull($total),
83 '$contacturl' => ['contact_url', L10n::t('Profile URL'), '', L10n::t('URL of the remote contact to block.')],
84 '$contact_block_reason' => ['contact_block_reason', L10n::t('Block Reason')],