]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Blocklist/Contact.php
Remove deprecated App::getBaseURL() - process methods to DI::baseUrl()->get()
[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\DI;
10 use Friendica\Module\BaseAdminModule;
11 use Friendica\Model;
12
13 class Contact extends BaseAdminModule
14 {
15         public static function post(array $parameters = [])
16         {
17                 parent::post($parameters);
18
19                 $contact_url  = $_POST['contact_url'] ?? '';
20                 $block_reason = $_POST['contact_block_reason'] ?? '';
21                 $contacts     = $_POST['contacts'] ?? [];
22
23                 parent::checkFormSecurityTokenRedirectOnError('/admin/blocklist/contact', 'admin_contactblock');
24
25                 if (!empty($_POST['page_contactblock_block'])) {
26                         $contact_id = Model\Contact::getIdForURL($contact_url);
27                         if ($contact_id) {
28                                 Model\Contact::block($contact_id, $block_reason);
29                                 notice(L10n::t('The contact has been blocked from the node'));
30                         } else {
31                                 notice(L10n::t('Could not find any contact entry for this URL (%s)', $contact_url));
32                         }
33                 }
34
35                 if (!empty($_POST['page_contactblock_unblock'])) {
36                         foreach ($contacts as $uid) {
37                                 Model\Contact::unblock($uid);
38                         }
39                         notice(L10n::tt('%s contact unblocked', '%s contacts unblocked', count($contacts)));
40                 }
41
42                 DI::baseUrl()->redirect('admin/blocklist/contact');
43         }
44
45         public static function content(array $parameters = [])
46         {
47                 parent::content($parameters);
48
49                 $a = DI::app();
50
51                 $condition = ['uid' => 0, 'blocked' => true];
52
53                 $total = DBA::count('contact', $condition);
54
55                 $pager = new Pager($a->query_string, 30);
56
57                 $contacts = Model\Contact::selectToArray([], $condition, ['limit' => [$pager->getStart(), $pager->getItemsPerPage()]]);
58
59                 $t = Renderer::getMarkupTemplate('admin/blocklist/contact.tpl');
60                 $o = Renderer::replaceMacros($t, [
61                         // strings //
62                         '$title'       => L10n::t('Administration'),
63                         '$page'        => L10n::t('Remote Contact Blocklist'),
64                         '$description' => L10n::t('This page allows you to prevent any message from a remote contact to reach your node.'),
65                         '$submit'      => L10n::t('Block Remote Contact'),
66                         '$select_all'  => L10n::t('select all'),
67                         '$select_none' => L10n::t('select none'),
68                         '$block'       => L10n::t('Block'),
69                         '$unblock'     => L10n::t('Unblock'),
70                         '$no_data'     => L10n::t('No remote contact is blocked from this node.'),
71
72                         '$h_contacts'  => L10n::t('Blocked Remote Contacts'),
73                         '$h_newblock'  => L10n::t('Block New Remote Contact'),
74                         '$th_contacts' => [L10n::t('Photo'), L10n::t('Name'), L10n::t('Reason')],
75
76                         '$form_security_token' => parent::getFormSecurityToken('admin_contactblock'),
77
78                         // values //
79                         '$baseurl'    => DI::baseUrl()->get(true),
80
81                         '$contacts'   => $contacts,
82                         '$total_contacts' => L10n::tt('%s total blocked contact', '%s total blocked contacts', $total),
83                         '$paginate'   => $pager->renderFull($total),
84                         '$contacturl' => ['contact_url', L10n::t('Profile URL'), '', L10n::t('URL of the remote contact to block.')],
85                         '$contact_block_reason' => ['contact_block_reason', L10n::t('Block Reason')],
86                 ]);
87                 return $o;
88         }
89 }