]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Blocklist/Contact.php
parameters now are having a default value and are optional
[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\L10n;
7 use Friendica\Core\Renderer;
8 use Friendica\Database\DBA;
9 use Friendica\Module\BaseAdminModule;
10 use Friendica\Model;
11
12 class Contact extends BaseAdminModule
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(L10n::t('The contact has been blocked from the node'));
29                         } else {
30                                 notice(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(L10n::tt('%s contact unblocked', '%s contacts unblocked', count($contacts)));
39                 }
40
41                 self::getApp()->internalRedirect('admin/blocklist/contact');
42         }
43
44         public static function content(array $parameters = [])
45         {
46                 parent::content($parameters);
47
48                 $a = self::getApp();
49
50                 $condition = ['uid' => 0, 'blocked' => true];
51
52                 $total = DBA::count('contact', $condition);
53
54                 $pager = new Pager($a->query_string, 30);
55
56                 $contacts = Model\Contact::selectToArray([], $condition, ['limit' => [$pager->getStart(), $pager->getItemsPerPage()]]);
57
58                 $t = Renderer::getMarkupTemplate('admin/blocklist/contact.tpl');
59                 $o = Renderer::replaceMacros($t, [
60                         // strings //
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.'),
70
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')],
74
75                         '$form_security_token' => parent::getFormSecurityToken('admin_contactblock'),
76
77                         // values //
78                         '$baseurl'    => $a->getBaseURL(true),
79
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')],
85                 ]);
86                 return $o;
87         }
88 }