]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Blocklist/Contact.php
Remove join profile table
[friendica.git] / src / Module / Admin / Blocklist / Contact.php
1 <?php
2
3 namespace Friendica\Module\Admin\Blocklist;
4
5 use Friendica\Content\Pager;
6 use Friendica\Core\Renderer;
7 use Friendica\Database\DBA;
8 use Friendica\DI;
9 use Friendica\Module\BaseAdmin;
10 use Friendica\Model;
11
12 class Contact extends BaseAdmin
13 {
14         public static function post(array $parameters = [])
15         {
16                 parent::post($parameters);
17
18                 $contact_url  = $_POST['contact_url'] ?? '';
19                 $block_reason = $_POST['contact_block_reason'] ?? '';
20                 $contacts     = $_POST['contacts'] ?? [];
21
22                 parent::checkFormSecurityTokenRedirectOnError('/admin/blocklist/contact', 'admin_contactblock');
23
24                 if (!empty($_POST['page_contactblock_block'])) {
25                         $contact_id = Model\Contact::getIdForURL($contact_url);
26                         if ($contact_id) {
27                                 Model\Contact::block($contact_id, $block_reason);
28                                 notice(DI::l10n()->t('The contact has been blocked from the node'));
29                         } else {
30                                 notice(DI::l10n()->t('Could not find any contact entry for this URL (%s)', $contact_url));
31                         }
32                 }
33
34                 if (!empty($_POST['page_contactblock_unblock'])) {
35                         foreach ($contacts as $uid) {
36                                 Model\Contact::unblock($uid);
37                         }
38                         notice(DI::l10n()->tt('%s contact unblocked', '%s contacts unblocked', count($contacts)));
39                 }
40
41                 DI::baseUrl()->redirect('admin/blocklist/contact');
42         }
43
44         public static function content(array $parameters = [])
45         {
46                 parent::content($parameters);
47
48                 $condition = ['uid' => 0, 'blocked' => true];
49
50                 $total = DBA::count('contact', $condition);
51
52                 $pager = new Pager(DI::args()->getQueryString(), 30);
53
54                 $contacts = Model\Contact::selectToArray([], $condition, ['limit' => [$pager->getStart(), $pager->getItemsPerPage()]]);
55
56                 $t = Renderer::getMarkupTemplate('admin/blocklist/contact.tpl');
57                 $o = Renderer::replaceMacros($t, [
58                         // strings //
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.'),
68
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')],
72
73                         '$form_security_token' => parent::getFormSecurityToken('admin_contactblock'),
74
75                         // values //
76                         '$baseurl'    => DI::baseUrl()->get(true),
77
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')],
83                 ]);
84                 return $o;
85         }
86 }