]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Blocklist/Contact.php
Merge pull request #7095 from annando/ap-connect
[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()
15         {
16                 parent::post();
17
18                 $contact_url = defaults($_POST, 'contact_url', '');
19                 $contacts    = defaults($_POST, 'contacts', []);
20
21                 parent::checkFormSecurityTokenRedirectOnError('/admin/blocklist/contact', 'admin_contactblock');
22
23                 if (!empty($_POST['page_contactblock_block'])) {
24                         $contact_id = Model\Contact::getIdForURL($contact_url);
25                         if ($contact_id) {
26                                 Model\Contact::block($contact_id);
27                                 notice(L10n::t('The contact has been blocked from the node'));
28                         } else {
29                                 notice(L10n::t("Could not find any contact entry for this URL \x28%s\x29", $contact_url));
30                         }
31                 }
32
33                 if (!empty($_POST['page_contactblock_unblock'])) {
34                         foreach ($contacts as $uid) {
35                                 Model\Contact::unblock($uid);
36                         }
37                         notice(L10n::tt("%s contact unblocked", "%s contacts unblocked", count($contacts)));
38                 }
39
40                 self::getApp()->internalRedirect('admin/blocklist/contact');
41         }
42
43         public static function content()
44         {
45                 parent::content();
46
47                 $a = self::getApp();
48
49                 $condition = ['uid' => 0, 'blocked' => true];
50
51                 $total = DBA::count('contact', $condition);
52
53                 $pager = new Pager($a->query_string, 30);
54
55                 $contacts = Model\Contact::select([], $condition, ['limit' => [$pager->getStart(), $pager->getItemsPerPage()]]);
56
57                 $t = Renderer::getMarkupTemplate('admin/blocklist/contact.tpl');
58                 $o = Renderer::replaceMacros($t, [
59                         // strings //
60                         '$title'       => L10n::t('Administration'),
61                         '$page'        => L10n::t('Remote Contact Blocklist'),
62                         '$description' => L10n::t('This page allows you to prevent any message from a remote contact to reach your node.'),
63                         '$submit'      => L10n::t('Block Remote Contact'),
64                         '$select_all'  => L10n::t('select all'),
65                         '$select_none' => L10n::t('select none'),
66                         '$block'       => L10n::t('Block'),
67                         '$unblock'     => L10n::t('Unblock'),
68                         '$no_data'     => L10n::t('No remote contact is blocked from this node.'),
69
70                         '$h_contacts'  => L10n::t('Blocked Remote Contacts'),
71                         '$h_newblock'  => L10n::t('Block New Remote Contact'),
72                         '$th_contacts' => [L10n::t('Photo'), L10n::t('Name'), L10n::t('Address'), L10n::t('Profile URL')],
73
74                         '$form_security_token' => parent::getFormSecurityToken("admin_contactblock"),
75
76                         // values //
77                         '$baseurl'    => $a->getBaseURL(true),
78
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', L10n::t("Profile URL"), '', L10n::t("URL of the remote contact to block.")],
83                 ]);
84                 return $o;
85         }
86 }