+/**
+ * @brief Process data send by the contact block admin page
+ *
+ * @param App $a
+ */
+function admin_page_contactblock_post(App $a)
+{
+ $contact_url = x($_POST, 'contact_url') ? $_POST['contact_url'] : '';
+ $contacts = x($_POST, 'contacts') ? $_POST['contacts'] : [];
+
+ check_form_security_token_redirectOnErr('/admin/contactblock', 'admin_contactblock');
+
+ if (x($_POST, 'page_contactblock_block')) {
+ $contact_id = Contact::getIdForURL($contact_url, 0);
+ if ($contact_id) {
+ Contact::block($contact_id);
+ notice(t('The contact has been blocked from the node'));
+ } else {
+ notice(t('Could not find any contact entry for this URL (%s)', $contact_url));
+ }
+ }
+ if (x($_POST, 'page_contactblock_unblock')) {
+ foreach ($contacts as $uid) {
+ Contact::unblock($uid);
+ }
+ notice(tt("%s contact unblocked", "%s contacts unblocked", count($contacts)));
+ }
+ goaway('admin/contactblock');
+ return; // NOTREACHED
+}
+
+/**
+ * @brief Admin panel for server-wide contact block
+ *
+ * @param App $a
+ * @return string
+ */
+function admin_page_contactblock(App $a)
+{
+ $condition = ['uid' => 0, 'blocked' => true];
+
+ $total = dba::count('contact', $condition);
+
+ $a->set_pager_total($total);
+ $a->set_pager_itemspage(30);
+
+ $statement = dba::select('contact', [], $condition, ['limit' => [$a->pager['start'], $a->pager['itemspage']]]);
+
+ $contacts = dba::inArray($statement);
+
+ $t = get_markup_template('admin/contactblock.tpl');
+ $o = replace_macros($t, array(
+ // strings //
+ '$title' => t('Administration'),
+ '$page' => t('Remote Contact Blocklist'),
+ '$description' => t('This page allows you to prevent any message from a remote contact to reach your node.'),
+ '$submit' => t('Block Remote Contact'),
+ '$select_all' => t('select all'),
+ '$select_none' => t('select none'),
+ '$block' => t('Block'),
+ '$unblock' => t('Unblock'),
+ '$no_data' => t('No remote contact is blocked from this node.'),
+
+ '$h_contacts' => t('Blocked Remote Contacts'),
+ '$h_newblock' => t('Block New Remote Contact'),
+ '$th_contacts' => [t('Photo'), t('Name'), t('Address'), t('Profile URL')],
+
+ '$form_security_token' => get_form_security_token("admin_contactblock"),
+
+ // values //
+ '$baseurl' => System::baseUrl(true),
+
+ '$contacts' => $contacts,
+ '$total_contacts' => tt('%s total blocked contact', '%s total blocked contacts', $total),
+ '$paginate' => paginate($a),
+ '$contacturl' => ['contact_url', t("Profile URL"), '', t("URL of the remote contact to block.")],
+ ));
+ return $o;
+}
+