3 namespace Friendica\Core\Console;
5 use Friendica\Core\Protocol;
6 use Friendica\Database\DBA;
7 use Friendica\Network\Probe;
8 use Friendica\Util\Strings;
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 <tobias.diekershoff@gmx.net>
22 * @author Hypolite Petovan <hypolite@mrpetovan.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 if ($a->getMode()->isInstall()) {
68 throw new RuntimeException('Database isn\'t ready or populated yet');
72 * 1. make nurl from last parameter
73 * 2. check DB (contact) if there is a contact with uid=0 and that nurl, get the ID
74 * 3. set the flag hidden=1 for the contact entry with the found ID
76 $net = Probe::uri($this->getArgument(0));
77 if (in_array($net['network'], [Protocol::PHANTOM, Protocol::MAIL])) {
78 throw new RuntimeException('This account seems not to exist.');
81 $nurl = Strings::normaliseLink($net['url']);
82 $contact = DBA::selectFirst("contact", ["id"], ["nurl" => $nurl, "uid" => 0]);
83 if (DBA::isResult($contact)) {
84 DBA::update("contact", ["hidden" => true], ["id" => $contact["id"]]);
85 $this->out('NOTICE: The account should be silenced from the global community page');
87 throw new RuntimeException('NOTICE: Could not find any entry for this URL (' . $nurl . ')');