2018-03-24 14:39:13 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Friendica\Core\Console;
|
|
|
|
|
|
|
|
use Friendica\Core\Protocol;
|
2018-07-20 08:19:26 -04:00
|
|
|
use Friendica\Database\DBA;
|
2018-03-24 14:39:13 -04:00
|
|
|
use Friendica\Network\Probe;
|
2018-11-08 11:28:29 -05:00
|
|
|
use Friendica\Util\Strings;
|
2018-07-19 22:15:21 -04:00
|
|
|
use RuntimeException;
|
2018-03-24 14:39:13 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief tool to silence accounts on the global community page
|
|
|
|
*
|
|
|
|
* With this tool, you can silence an account on the global community page.
|
|
|
|
* Postings from silenced accounts will not be displayed on the community
|
|
|
|
* page. This silencing does only affect the display on the community page,
|
|
|
|
* accounts following the silenced accounts will still get their postings.
|
|
|
|
*
|
|
|
|
* License: AGPLv3 or later, same as Friendica
|
|
|
|
*
|
2018-09-15 19:28:38 -04:00
|
|
|
* @author Tobias Diekershoff <tobias.diekershoff@gmx.net>
|
|
|
|
* @author Hypolite Petovan <hypolite@mrpetovan.com>
|
2018-03-24 14:39:13 -04:00
|
|
|
*/
|
|
|
|
class GlobalCommunitySilence extends \Asika\SimpleConsole\Console
|
|
|
|
{
|
|
|
|
protected $helpOptions = ['h', 'help', '?'];
|
|
|
|
|
|
|
|
protected function getHelp()
|
|
|
|
{
|
|
|
|
$help = <<<HELP
|
|
|
|
console globalcommunitysilence - Silence remote profile from global community page
|
|
|
|
Usage
|
|
|
|
bin/console globalcommunitysilence <profile_url> [-h|--help|-?] [-v]
|
|
|
|
|
|
|
|
Description
|
|
|
|
With this tool, you can silence an account on the global community page.
|
|
|
|
Postings from silenced accounts will not be displayed on the community page.
|
|
|
|
This silencing does only affect the display on the community page, accounts
|
|
|
|
following the silenced accounts will still get their postings.
|
|
|
|
|
|
|
|
Options
|
|
|
|
-h|--help|-? Show help information
|
|
|
|
-v Show more debug information.
|
|
|
|
HELP;
|
|
|
|
return $help;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function doExecute()
|
|
|
|
{
|
2018-12-27 19:22:35 -05:00
|
|
|
$a = \get_app();
|
2018-03-26 16:58:34 -04:00
|
|
|
|
2018-03-24 14:39:13 -04:00
|
|
|
if ($this->getOption('v')) {
|
|
|
|
$this->out('Class: ' . __CLASS__);
|
|
|
|
$this->out('Arguments: ' . var_export($this->args, true));
|
|
|
|
$this->out('Options: ' . var_export($this->options, true));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($this->args) == 0) {
|
|
|
|
$this->out($this->getHelp());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($this->args) > 1) {
|
|
|
|
throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
|
|
|
|
}
|
|
|
|
|
2018-10-06 10:27:20 -04:00
|
|
|
if ($a->getMode()->isInstall()) {
|
2018-07-19 22:15:21 -04:00
|
|
|
throw new RuntimeException('Database isn\'t ready or populated yet');
|
2018-03-24 14:39:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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($this->getArgument(0));
|
|
|
|
if (in_array($net['network'], [Protocol::PHANTOM, Protocol::MAIL])) {
|
2018-07-19 22:15:21 -04:00
|
|
|
throw new RuntimeException('This account seems not to exist.');
|
2018-03-24 14:39:13 -04:00
|
|
|
}
|
|
|
|
|
2018-11-08 11:28:29 -05:00
|
|
|
$nurl = Strings::normaliseLink($net['url']);
|
2018-07-20 08:19:26 -04:00
|
|
|
$contact = DBA::selectFirst("contact", ["id"], ["nurl" => $nurl, "uid" => 0]);
|
2018-07-21 08:46:04 -04:00
|
|
|
if (DBA::isResult($contact)) {
|
2018-07-20 08:19:26 -04:00
|
|
|
DBA::update("contact", ["hidden" => true], ["id" => $contact["id"]]);
|
2018-03-24 14:39:13 -04:00
|
|
|
$this->out('NOTICE: The account should be silenced from the global community page');
|
|
|
|
} else {
|
2018-07-19 22:15:21 -04:00
|
|
|
throw new RuntimeException('NOTICE: Could not find any entry for this URL (' . $nurl . ')');
|
2018-03-24 14:39:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|