Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.8KB

  1. <?php
  2. namespace Friendica\Core\Console;
  3. use Friendica\Core\Protocol;
  4. use Friendica\Database\DBM;
  5. use Friendica\Network\Probe;
  6. require_once 'include/text.php';
  7. /**
  8. * @brief tool to silence accounts on the global community page
  9. *
  10. * With this tool, you can silence an account on the global community page.
  11. * Postings from silenced accounts will not be displayed on the community
  12. * page. This silencing does only affect the display on the community page,
  13. * accounts following the silenced accounts will still get their postings.
  14. *
  15. * License: AGPLv3 or later, same as Friendica
  16. *
  17. * @author Tobias Diekershoff
  18. * @author Hypolite Petovan <mrpetovan@gmail.com>
  19. */
  20. class GlobalCommunitySilence extends \Asika\SimpleConsole\Console
  21. {
  22. protected $helpOptions = ['h', 'help', '?'];
  23. protected function getHelp()
  24. {
  25. $help = <<<HELP
  26. console globalcommunitysilence - Silence remote profile from global community page
  27. Usage
  28. bin/console globalcommunitysilence <profile_url> [-h|--help|-?] [-v]
  29. Description
  30. With this tool, you can silence an account on the global community page.
  31. Postings from silenced accounts will not be displayed on the community page.
  32. This silencing does only affect the display on the community page, accounts
  33. following the silenced accounts will still get their postings.
  34. Options
  35. -h|--help|-? Show help information
  36. -v Show more debug information.
  37. HELP;
  38. return $help;
  39. }
  40. protected function doExecute()
  41. {
  42. $a = get_app();
  43. if ($this->getOption('v')) {
  44. $this->out('Class: ' . __CLASS__);
  45. $this->out('Arguments: ' . var_export($this->args, true));
  46. $this->out('Options: ' . var_export($this->options, true));
  47. }
  48. if (count($this->args) == 0) {
  49. $this->out($this->getHelp());
  50. return 0;
  51. }
  52. if (count($this->args) > 1) {
  53. throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
  54. }
  55. if ($a->mode == \Friendica\App::MODE_INSTALL) {
  56. throw new \RuntimeException('Database isn\'t ready or populated yet');
  57. }
  58. /**
  59. * 1. make nurl from last parameter
  60. * 2. check DB (contact) if there is a contact with uid=0 and that nurl, get the ID
  61. * 3. set the flag hidden=1 for the contact entry with the found ID
  62. * */
  63. $net = Probe::uri($this->getArgument(0));
  64. if (in_array($net['network'], [Protocol::PHANTOM, Protocol::MAIL])) {
  65. throw new \RuntimeException('This account seems not to exist.');
  66. }
  67. $nurl = normalise_link($net['url']);
  68. $contact = \dba::selectFirst("contact", ["id"], ["nurl" => $nurl, "uid" => 0]);
  69. if (DBM::is_result($contact)) {
  70. \dba::update("contact", ["hidden" => true], ["id" => $contact["id"]]);
  71. $this->out('NOTICE: The account should be silenced from the global community page');
  72. } else {
  73. throw new \RuntimeException('NOTICE: Could not find any entry for this URL (' . $nurl . ')');
  74. }
  75. return 0;
  76. }
  77. }