Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there)
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.

GlobalCommunitySilence.php 2.8KB

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