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