]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Blocklist/Contact.php
post/thread views are renamed, search bugs fixed
[friendica.git] / src / Module / Admin / Blocklist / Contact.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Module\Admin\Blocklist;
23
24 use Friendica\Content\Pager;
25 use Friendica\Core\Renderer;
26 use Friendica\Database\DBA;
27 use Friendica\DI;
28 use Friendica\Module\BaseAdmin;
29 use Friendica\Model;
30
31 class Contact extends BaseAdmin
32 {
33         public static function post(array $parameters = [])
34         {
35                 self::checkAdminAccess();
36
37                 self::checkFormSecurityTokenRedirectOnError('/admin/blocklist/contact', 'admin_contactblock');
38
39                 $contact_url  = $_POST['contact_url'] ?? '';
40                 $block_reason = $_POST['contact_block_reason'] ?? '';
41                 $contacts     = $_POST['contacts'] ?? [];
42
43                 if (!empty($_POST['page_contactblock_block'])) {
44                         $contact_id = Model\Contact::getIdForURL($contact_url);
45                         if ($contact_id) {
46                                 Model\Contact::block($contact_id, $block_reason);
47                                 info(DI::l10n()->t('The contact has been blocked from the node'));
48                         } else {
49                                 notice(DI::l10n()->t('Could not find any contact entry for this URL (%s)', $contact_url));
50                         }
51                 }
52
53                 if (!empty($_POST['page_contactblock_unblock'])) {
54                         foreach ($contacts as $uid) {
55                                 Model\Contact::unblock($uid);
56                         }
57                         info(DI::l10n()->tt('%s contact unblocked', '%s contacts unblocked', count($contacts)));
58                 }
59
60                 DI::baseUrl()->redirect('admin/blocklist/contact');
61         }
62
63         public static function content(array $parameters = [])
64         {
65                 parent::content($parameters);
66
67                 $condition = ['uid' => 0, 'blocked' => true];
68
69                 $total = DBA::count('contact', $condition);
70
71                 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 30);
72
73                 $contacts = Model\Contact::selectToArray([], $condition, ['limit' => [$pager->getStart(), $pager->getItemsPerPage()]]);
74
75                 $t = Renderer::getMarkupTemplate('admin/blocklist/contact.tpl');
76                 $o = Renderer::replaceMacros($t, [
77                         // strings //
78                         '$title'       => DI::l10n()->t('Administration'),
79                         '$page'        => DI::l10n()->t('Remote Contact Blocklist'),
80                         '$description' => DI::l10n()->t('This page allows you to prevent any message from a remote contact to reach your node.'),
81                         '$submit'      => DI::l10n()->t('Block Remote Contact'),
82                         '$select_all'  => DI::l10n()->t('select all'),
83                         '$select_none' => DI::l10n()->t('select none'),
84                         '$block'       => DI::l10n()->t('Block'),
85                         '$unblock'     => DI::l10n()->t('Unblock'),
86                         '$no_data'     => DI::l10n()->t('No remote contact is blocked from this node.'),
87
88                         '$h_contacts'  => DI::l10n()->t('Blocked Remote Contacts'),
89                         '$h_newblock'  => DI::l10n()->t('Block New Remote Contact'),
90                         '$th_contacts' => [DI::l10n()->t('Photo'), DI::l10n()->t('Name'), DI::l10n()->t('Reason')],
91
92                         '$form_security_token' => self::getFormSecurityToken('admin_contactblock'),
93
94                         // values //
95                         '$baseurl'    => DI::baseUrl()->get(true),
96
97                         '$contacts'   => $contacts,
98                         '$total_contacts' => DI::l10n()->tt('%s total blocked contact', '%s total blocked contacts', $total),
99                         '$paginate'   => $pager->renderFull($total),
100                         '$contacturl' => ['contact_url', DI::l10n()->t('Profile URL'), '', DI::l10n()->t('URL of the remote contact to block.')],
101                         '$contact_block_reason' => ['contact_block_reason', DI::l10n()->t('Block Reason')],
102                 ]);
103                 return $o;
104         }
105 }