-<?php\r
-\r
-namespace Friendica\Module\Admin\Blocklist;\r
-\r
-use Friendica\Content\Pager;\r
-use Friendica\Core\L10n;\r
-use Friendica\Core\Renderer;\r
-use Friendica\Database\DBA;\r
-use Friendica\Module\BaseAdminModule;\r
-use Friendica\Model;\r
-\r
-class Contact extends BaseAdminModule\r
-{\r
- public static function post()\r
- {\r
- parent::post();\r
-\r
- $contact_url = defaults($_POST, 'contact_url', '');\r
- $contacts = defaults($_POST, 'contacts', []);\r
-\r
- parent::checkFormSecurityTokenRedirectOnError('/admin/blocklist/contact', 'admin_contactblock');\r
-\r
- if (!empty($_POST['page_contactblock_block'])) {\r
- $contact_id = Model\Contact::getIdForURL($contact_url);\r
- if ($contact_id) {\r
- Model\Contact::block($contact_id);\r
- notice(L10n::t('The contact has been blocked from the node'));\r
- } else {\r
- notice(L10n::t("Could not find any contact entry for this URL \x28%s\x29", $contact_url));\r
- }\r
- }\r
-\r
- if (!empty($_POST['page_contactblock_unblock'])) {\r
- foreach ($contacts as $uid) {\r
- Model\Contact::unblock($uid);\r
- }\r
- notice(L10n::tt("%s contact unblocked", "%s contacts unblocked", count($contacts)));\r
- }\r
-\r
- self::getApp()->internalRedirect('admin/blocklist/contact');\r
- }\r
-\r
- public static function content()\r
- {\r
- parent::content();\r
-\r
- $a = self::getApp();\r
-\r
- $condition = ['uid' => 0, 'blocked' => true];\r
-\r
- $total = DBA::count('contact', $condition);\r
-\r
- $pager = new Pager($a->query_string, 30);\r
-\r
- $contacts = Model\Contact::select([], $condition, ['limit' => [$pager->getStart(), $pager->getItemsPerPage()]]);\r
-\r
- $t = Renderer::getMarkupTemplate('admin/blocklist/contact.tpl');\r
- $o = Renderer::replaceMacros($t, [\r
- // strings //\r
- '$title' => L10n::t('Administration'),\r
- '$page' => L10n::t('Remote Contact Blocklist'),\r
- '$description' => L10n::t('This page allows you to prevent any message from a remote contact to reach your node.'),\r
- '$submit' => L10n::t('Block Remote Contact'),\r
- '$select_all' => L10n::t('select all'),\r
- '$select_none' => L10n::t('select none'),\r
- '$block' => L10n::t('Block'),\r
- '$unblock' => L10n::t('Unblock'),\r
- '$no_data' => L10n::t('No remote contact is blocked from this node.'),\r
-\r
- '$h_contacts' => L10n::t('Blocked Remote Contacts'),\r
- '$h_newblock' => L10n::t('Block New Remote Contact'),\r
- '$th_contacts' => [L10n::t('Photo'), L10n::t('Name'), L10n::t('Address'), L10n::t('Profile URL')],\r
-\r
- '$form_security_token' => parent::getFormSecurityToken("admin_contactblock"),\r
-\r
- // values //\r
- '$baseurl' => $a->getBaseURL(true),\r
-\r
- '$contacts' => $contacts,\r
- '$total_contacts' => L10n::tt('%s total blocked contact', '%s total blocked contacts', $total),\r
- '$paginate' => $pager->renderFull($total),\r
- '$contacturl' => ['contact_url', L10n::t("Profile URL"), '', L10n::t("URL of the remote contact to block.")],\r
- ]);\r
- return $o;\r
- }\r
-}\r
+<?php
+/**
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Module\Admin\Blocklist;
+
+use Friendica\Content\Pager;
+use Friendica\Core\Renderer;
+use Friendica\Database\DBA;
+use Friendica\DI;
+use Friendica\Module\BaseAdmin;
+use Friendica\Model;
+
+class Contact extends BaseAdmin
+{
+ public static function post(array $parameters = [])
+ {
+ self::checkAdminAccess();
+
+ self::checkFormSecurityTokenRedirectOnError('/admin/blocklist/contact', 'admin_contactblock');
+
+ $contact_url = $_POST['contact_url'] ?? '';
+ $block_reason = $_POST['contact_block_reason'] ?? '';
+ $contacts = $_POST['contacts'] ?? [];
+
+ if (!empty($_POST['page_contactblock_block'])) {
+ $contact_id = Model\Contact::getIdForURL($contact_url);
+ if ($contact_id) {
+ Model\Contact::block($contact_id, $block_reason);
+ info(DI::l10n()->t('The contact has been blocked from the node'));
+ } else {
+ notice(DI::l10n()->t('Could not find any contact entry for this URL (%s)', $contact_url));
+ }
+ }
+
+ if (!empty($_POST['page_contactblock_unblock'])) {
+ foreach ($contacts as $uid) {
+ Model\Contact::unblock($uid);
+ }
+ info(DI::l10n()->tt('%s contact unblocked', '%s contacts unblocked', count($contacts)));
+ }
+
+ DI::baseUrl()->redirect('admin/blocklist/contact');
+ }
+
+ public static function content(array $parameters = [])
+ {
+ parent::content($parameters);
+
+ $condition = ['uid' => 0, 'blocked' => true];
+
+ $total = DBA::count('contact', $condition);
+
+ $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 30);
+
+ $contacts = Model\Contact::selectToArray([], $condition, ['limit' => [$pager->getStart(), $pager->getItemsPerPage()]]);
+
+ $t = Renderer::getMarkupTemplate('admin/blocklist/contact.tpl');
+ $o = Renderer::replaceMacros($t, [
+ // strings //
+ '$title' => DI::l10n()->t('Administration'),
+ '$page' => DI::l10n()->t('Remote Contact Blocklist'),
+ '$description' => DI::l10n()->t('This page allows you to prevent any message from a remote contact to reach your node.'),
+ '$submit' => DI::l10n()->t('Block Remote Contact'),
+ '$select_all' => DI::l10n()->t('select all'),
+ '$select_none' => DI::l10n()->t('select none'),
+ '$block' => DI::l10n()->t('Block'),
+ '$unblock' => DI::l10n()->t('Unblock'),
+ '$no_data' => DI::l10n()->t('No remote contact is blocked from this node.'),
+
+ '$h_contacts' => DI::l10n()->t('Blocked Remote Contacts'),
+ '$h_newblock' => DI::l10n()->t('Block New Remote Contact'),
+ '$th_contacts' => [DI::l10n()->t('Photo'), DI::l10n()->t('Name'), DI::l10n()->t('Reason')],
+
+ '$form_security_token' => self::getFormSecurityToken('admin_contactblock'),
+
+ // values //
+ '$baseurl' => DI::baseUrl()->get(true),
+
+ '$contacts' => $contacts,
+ '$total_contacts' => DI::l10n()->tt('%s total blocked contact', '%s total blocked contacts', $total),
+ '$paginate' => $pager->renderFull($total),
+ '$contacturl' => ['contact_url', DI::l10n()->t('Profile URL'), '', DI::l10n()->t('URL of the remote contact to block.')],
+ '$contact_block_reason' => ['contact_block_reason', DI::l10n()->t('Block Reason')],
+ ]);
+ return $o;
+ }
+}