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;
10 use Friendica\Module\BaseAdminModule;
13 class Contact extends BaseAdminModule
15 public static function post(array $parameters = [])
17 parent::post($parameters);
19 $contact_url = $_POST['contact_url'] ?? '';
20 $block_reason = $_POST['contact_block_reason'] ?? '';
21 $contacts = $_POST['contacts'] ?? [];
23 parent::checkFormSecurityTokenRedirectOnError('/admin/blocklist/contact', 'admin_contactblock');
25 if (!empty($_POST['page_contactblock_block'])) {
26 $contact_id = Model\Contact::getIdForURL($contact_url);
28 Model\Contact::block($contact_id, $block_reason);
29 notice(DI::l10n()->t('The contact has been blocked from the node'));
31 notice(DI::l10n()->t('Could not find any contact entry for this URL (%s)', $contact_url));
35 if (!empty($_POST['page_contactblock_unblock'])) {
36 foreach ($contacts as $uid) {
37 Model\Contact::unblock($uid);
39 notice(L10n::tt('%s contact unblocked', '%s contacts unblocked', count($contacts)));
42 DI::baseUrl()->redirect('admin/blocklist/contact');
45 public static function content(array $parameters = [])
47 parent::content($parameters);
49 $condition = ['uid' => 0, 'blocked' => true];
51 $total = DBA::count('contact', $condition);
53 $pager = new Pager(DI::args()->getQueryString(), 30);
55 $contacts = Model\Contact::selectToArray([], $condition, ['limit' => [$pager->getStart(), $pager->getItemsPerPage()]]);
57 $t = Renderer::getMarkupTemplate('admin/blocklist/contact.tpl');
58 $o = Renderer::replaceMacros($t, [
60 '$title' => DI::l10n()->t('Administration'),
61 '$page' => DI::l10n()->t('Remote Contact Blocklist'),
62 '$description' => DI::l10n()->t('This page allows you to prevent any message from a remote contact to reach your node.'),
63 '$submit' => DI::l10n()->t('Block Remote Contact'),
64 '$select_all' => DI::l10n()->t('select all'),
65 '$select_none' => DI::l10n()->t('select none'),
66 '$block' => DI::l10n()->t('Block'),
67 '$unblock' => DI::l10n()->t('Unblock'),
68 '$no_data' => DI::l10n()->t('No remote contact is blocked from this node.'),
70 '$h_contacts' => DI::l10n()->t('Blocked Remote Contacts'),
71 '$h_newblock' => DI::l10n()->t('Block New Remote Contact'),
72 '$th_contacts' => [DI::l10n()->t('Photo'), DI::l10n()->t('Name'), DI::l10n()->t('Reason')],
74 '$form_security_token' => parent::getFormSecurityToken('admin_contactblock'),
77 '$baseurl' => DI::baseUrl()->get(true),
79 '$contacts' => $contacts,
80 '$total_contacts' => L10n::tt('%s total blocked contact', '%s total blocked contacts', $total),
81 '$paginate' => $pager->renderFull($total),
82 '$contacturl' => ['contact_url', DI::l10n()->t('Profile URL'), '', DI::l10n()->t('URL of the remote contact to block.')],
83 '$contact_block_reason' => ['contact_block_reason', DI::l10n()->t('Block Reason')],