]> git.mxchange.org Git - friendica.git/blob - util/global_community_block.php
some minor stuff
[friendica.git] / util / global_community_block.php
1 #!/usr/bin/env php
2 <?php
3
4 /**
5  * @brief tool to block an account from the node
6  *
7  * With this tool, you can block an account in such a way, that no postings
8  * or comments this account writes are accepted to the node.
9  *
10  * Usage: pass the URL of the to be blocked account as only parameter
11  *        at the command line when running this tool. E.g.
12  *
13  *        $> util/global_community_block.php http://example.com/profile/bob
14  *
15  *        will block bob@example.com.
16  *
17  * Author: Tobias Diekershoff
18  *
19  * License: AGPLv3 or later, same as Friendica
20  **/
21
22 if ($argc != 2 || $argv[1] == "-h" || $argv[1] == "--help" || $argv[1] == "-?") {
23         echo "Usage: ".$argv[0]." [-h|profile_url]\r\n";
24         echo "    -h, -?, --help ... show this help\r\n";
25         echo "    profile_url ...... The URL of the profile you want to silence\r\n";
26         echo "\r\n";
27         echo "Example: block bob@example.com\r\n";
28         echo "$> ".$argv[0]." https://example.com/profiles/bob\r\n";
29         echo "\r\n";
30         exit(0);
31 }
32
33 use Friendica\Database\DBM;
34 use Friendica\Network\Probe;
35
36 require_once('boot.php');
37 require_once('include/dba.php');
38 require_once('include/text.php');
39 $a = get_app();
40 require_once('.htconfig.php');
41
42 dba::connect($db_host, $db_user, $db_pass, $db_data);
43 unset($db_host, $db_user, $db_pass, $db_data);
44
45 /**
46  * 1. make nurl from last parameter
47  * 2. check DB (contact) if there is a contact with uid=0 and that nurl, get the ID
48  * 3. set the flag hidden=1 for the contact entry with the found ID
49  **/
50 $net = Probe::uri($argv[1]);
51 if (in_array($net['network'], array(NETWORK_PHANTOM, NETWORK_MAIL))) {
52         echo "This account seems not to exist.";
53         echo "\r\n";
54         exit(1);
55 }
56 $nurl = normalise_link($net['url']);
57 $r = dba::select("contact", array("id"), array("nurl" => $nurl, "uid" => 0), array("limit" => 1));
58 if (DBM::is_result($r)) {
59         dba::update("contact", array("blocked" => true), array("id" => $r["id"]));
60         echo "NOTICE: The account should be blocked from the node now\r\n";
61 } else {
62         echo "NOTICE: Could not find any entry for this URL (".$nurl.")\r\n";
63 }
64
65 ?>