closechannel.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Action to close a channel
  18. *
  19. * @category Realtime
  20. * @package GNUsocial
  21. * @author Evan Prodromou <evan@status.net>
  22. * @copyright 2011-2019 Free Software Foundation, Inc http://www.fsf.org
  23. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  24. */
  25. defined('GNUSOCIAL') || die();
  26. /**
  27. * Action to close a channel
  28. *
  29. * @category Realtime
  30. * @package GNUsocial
  31. * @author Evan Prodromou <evan@status.net>
  32. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  33. */
  34. class ClosechannelAction extends Action
  35. {
  36. protected $channelKey = null;
  37. protected $channel = null;
  38. /**
  39. * For initializing members of the class.
  40. *
  41. * @param array $args misc. arguments
  42. *
  43. * @return boolean true
  44. * @throws ClientException
  45. */
  46. public function prepare(array $args = [])
  47. {
  48. parent::prepare($args);
  49. if (!$this->isPost()) {
  50. // TRANS: Client exception. Do not translate POST.
  51. throw new ClientException(_m('You have to POST it.'));
  52. }
  53. $this->channelKey = $this->trimmed('channelkey');
  54. if (empty($this->channelKey)) {
  55. // TRANS: Client exception thrown when the channel key argument is missing.
  56. throw new ClientException(_m('No channel key argument.'));
  57. }
  58. $this->channel = Realtime_channel::getKV('channel_key', $this->channelKey);
  59. if (empty($this->channel)) {
  60. // TRANS: Client exception thrown when referring to a non-existing channel.
  61. throw new ClientException(_m('No such channel.'));
  62. }
  63. return true;
  64. }
  65. /**
  66. * Handler method
  67. *
  68. * @return void
  69. */
  70. public function handle(): void
  71. {
  72. $this->channel->decrement();
  73. http_response_code(204);
  74. return;
  75. }
  76. /**
  77. * Return true if read only.
  78. *
  79. * MAY override
  80. *
  81. * @param array $args other arguments
  82. *
  83. * @return bool is read only action?
  84. */
  85. public function isReadOnly($args): bool
  86. {
  87. return false;
  88. }
  89. }