]> git.mxchange.org Git - friendica.git/blobdiff - util/global_community_block.php
regen credits
[friendica.git] / util / global_community_block.php
index cb6789e45c455779a1f0b442ad0b92147d468010..02f0c53ec0426ee6a9c21372e86ab235f1dcea1e 100755 (executable)
@@ -1,6 +1,5 @@
 #!/usr/bin/env php
 <?php
-
 /**
  * @brief tool to block an account from the node
  *
  * Author: Tobias Diekershoff
  *
  * License: AGPLv3 or later, same as Friendica
- **/
-
+ */
 if ($argc != 2 || $argv[1] == "-h" || $argv[1] == "--help" || $argv[1] == "-?") {
-       echo "Usage: ".$argv[0]." [-h|profile_url]\r\n";
+       echo "Usage: " . $argv[0] . " [-h|profile_url]\r\n";
        echo "    -h, -?, --help ... show this help\r\n";
        echo "    profile_url ...... The URL of the profile you want to silence\r\n";
        echo "\r\n";
        echo "Example: block bob@example.com\r\n";
-       echo "$> ".$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\Core\L10n;
+use Friendica\Model\Contact;
 
 require_once 'boot.php';
 require_once 'include/dba.php';
 require_once 'include/text.php';
+
 $a = get_app();
-require_once '.htconfig.php';
+BaseObject::setApp($a);
 
+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]);
+if (!$contact_id) {
+       echo L10n::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 L10n::t('The contact has been blocked from the node');
+echo "\r\n";
+exit(0);