diff --git a/mod/admin.php b/mod/admin.php index 83ef15f4a..1bcbb45e7 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -381,17 +381,12 @@ function admin_page_contactblock_post(App $a) check_form_security_token_redirectOnErr('/admin/contactblock', 'admin_contactblock'); if (x($_POST, 'page_contactblock_block')) { - $net = Probe::uri($contact_url); - if (in_array($net['network'], array(NETWORK_PHANTOM, NETWORK_MAIL))) { - notice(t('This contact doesn\'t seem to exist.')); - } - $nurl = normalise_link($net['url']); - $r = dba::select('contact', ['id'], ['nurl' => $nurl, 'uid' => 0], ['limit' => 1]); - if (DBM::is_result($r)) { - Contact::block($r['id']); + $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)', $nurl)); + notice(t('Could not find any contact entry for this URL (%s)', $contact_url)); } } if (x($_POST, 'page_contactblock_unblock')) { @@ -428,7 +423,7 @@ function admin_page_contactblock(App $a) // 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. However, your node must have knowledge of the contact before you can block it.'), + '$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'), diff --git a/util/global_community_block.php b/util/global_community_block.php index cb6789e45..db68fdb4b 100755 --- a/util/global_community_block.php +++ b/util/global_community_block.php @@ -1,6 +1,5 @@ #!/usr/bin/env php ".$argv[0]." https://example.com/profiles/bob\r\n"; + echo "$> " . $argv[0] . " https://example.com/profiles/bob\r\n"; echo "\r\n"; exit(0); } -use Friendica\Database\DBM; -use Friendica\Network\Probe; +use Friendica\BaseObject; +use Friendica\Object\Contact; require_once 'boot.php'; + +$a = get_app();; +BaseObject::setApp($a); + +require_once '.htconfig.php'; require_once 'include/dba.php'; require_once 'include/text.php'; -$a = get_app(); -require_once '.htconfig.php'; dba::connect($db_host, $db_user, $db_pass, $db_data); unset($db_host, $db_user, $db_pass, $db_data); -/** - * 1. make nurl from last parameter - * 2. check DB (contact) if there is a contact with uid=0 and that nurl, get the ID - * 3. set the flag hidden=1 for the contact entry with the found ID - **/ -$net = Probe::uri($argv[1]); -if (in_array($net['network'], array(NETWORK_PHANTOM, NETWORK_MAIL))) { - echo 'This account seems not to exist.'; +$contact_id = Contact::getIdForURL($argv[1], 0); +if (!$contact_id) { + echo t('Could not find any contact entry for this URL (%s)', $nurl); echo "\r\n"; exit(1); } -$nurl = normalise_link($net['url']); -$r = dba::select('contact', array('id'), array('nurl' => $nurl, 'uid' => 0), array('limit' => 1)); -if (DBM::is_result($r)) { - dba::update('contact', array('blocked' => true), array('id' => $r['id'])); - echo "NOTICE: The account should be blocked from the node now\r\n"; -} else { - echo "NOTICE: Could not find any entry for this URL (".$nurl.")\r\n"; -} - -?> +Contact::block($contact_id); +echo t('The contact has been blocked from the node'); +echo "\r\n"; +exit(0);