3 namespace Friendica\Core\Console;
5 use Friendica\Core\Protocol;
6 use Friendica\Database\DBM;
7 use Friendica\Network\Probe;
9 require_once 'include/text.php';
12 * @brief tool to silence accounts on the global community page
14 * With this tool, you can silence an account on the global community page.
15 * Postings from silenced accounts will not be displayed on the community
16 * page. This silencing does only affect the display on the community page,
17 * accounts following the silenced accounts will still get their postings.
19 * License: AGPLv3 or later, same as Friendica
21 * @author Tobias Diekershoff
22 * @author Hypolite Petovan <mrpetovan@gmail.com>
24 class GlobalCommunitySilence extends \Asika\SimpleConsole\Console
26 protected $helpOptions = ['h', 'help', '?'];
28 protected function getHelp()
31 console globalcommunitysilence - Silence remote profile from global community page
33 bin/console globalcommunitysilence <profile_url> [-h|--help|-?] [-v]
36 With this tool, you can silence an account on the global community page.
37 Postings from silenced accounts will not be displayed on the community page.
38 This silencing does only affect the display on the community page, accounts
39 following the silenced accounts will still get their postings.
42 -h|--help|-? Show help information
43 -v Show more debug information.
48 protected function doExecute()
52 if ($this->getOption('v')) {
53 $this->out('Class: ' . __CLASS__);
54 $this->out('Arguments: ' . var_export($this->args, true));
55 $this->out('Options: ' . var_export($this->options, true));
58 if (count($this->args) == 0) {
59 $this->out($this->getHelp());
63 if (count($this->args) > 1) {
64 throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
67 require_once '.htconfig.php';
68 $result = \dba::connect($db_host, $db_user, $db_pass, $db_data);
69 unset($db_host, $db_user, $db_pass, $db_data);
72 throw new \RuntimeException('Unable to connect to database');
76 * 1. make nurl from last parameter
77 * 2. check DB (contact) if there is a contact with uid=0 and that nurl, get the ID
78 * 3. set the flag hidden=1 for the contact entry with the found ID
80 $net = Probe::uri($this->getArgument(0));
81 if (in_array($net['network'], [Protocol::PHANTOM, Protocol::MAIL])) {
82 throw new \RuntimeException('This account seems not to exist.');
85 $nurl = normalise_link($net['url']);
86 $contact = \dba::selectFirst("contact", ["id"], ["nurl" => $nurl, "uid" => 0]);
87 if (DBM::is_result($contact)) {
88 \dba::update("contact", ["hidden" => true], ["id" => $contact["id"]]);
89 $this->out('NOTICE: The account should be silenced from the global community page');
91 throw new \RuntimeException('NOTICE: Could not find any entry for this URL (' . $nurl . ')');