apiqvittersilencecreate.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3. · ·
  4. · Silence a user ·
  5. · ·
  6. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7. · ·
  8. · ·
  9. · Q V I T T E R ·
  10. · ·
  11. · https://git.gnu.io/h2p/Qvitter ·
  12. · ·
  13. · ·
  14. · <o) ·
  15. · /_//// ·
  16. · (____/ ·
  17. · (o< ·
  18. · o> \\\\_\ ·
  19. · \\) \____) ·
  20. · ·
  21. · ·
  22. · ·
  23. · Qvitter is free software: you can redistribute it and / or modify it ·
  24. · under the terms of the GNU Affero General Public License as published by ·
  25. · the Free Software Foundation, either version three of the License or (at ·
  26. · your option) any later version. ·
  27. · ·
  28. · Qvitter is distributed in hope that it will be useful but WITHOUT ANY ·
  29. · WARRANTY; without even the implied warranty of MERCHANTABILTY or FITNESS ·
  30. · FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for ·
  31. · more details. ·
  32. · ·
  33. · You should have received a copy of the GNU Affero General Public License ·
  34. · along with Qvitter. If not, see <http://www.gnu.org/licenses/>. ·
  35. · ·
  36. · Contact h@nnesmannerhe.im if you have any questions. ·
  37. · ·
  38. · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */
  39. if (!defined('GNUSOCIAL')) { exit(1); }
  40. class ApiQvitterSilenceCreateAction extends ApiAuthAction
  41. {
  42. protected $needPost = true;
  43. /**
  44. * Take arguments for running
  45. *
  46. * @param array $args $_REQUEST args
  47. *
  48. * @return boolean success flag
  49. */
  50. protected function prepare(array $args=array())
  51. {
  52. parent::prepare($args);
  53. $this->format = 'json';
  54. $this->other = $this->getTargetProfile($this->arg('id'));
  55. return true;
  56. }
  57. /**
  58. * Handle the request
  59. *
  60. * @param array $args $_REQUEST data (unused)
  61. *
  62. * @return void
  63. */
  64. protected function handle()
  65. {
  66. parent::handle();
  67. if (!$this->other instanceof Profile) {
  68. $this->clientError(_('No such user.'), 404);
  69. }
  70. if ($this->scoped->id == $this->other->id) {
  71. $this->clientError(_("You cannot silence yourself!"), 403);
  72. }
  73. try {
  74. $this->other->silenceAs($this->scoped);
  75. } catch (AlreadyFulfilledException $e) {
  76. // don't throw client error here, just return the user array like
  77. // if we successfully silenced the user. the client is only interested
  78. // in making sure the user is silenced.
  79. } catch (Exception $e) {
  80. $this->clientError($e->getMessage(), $e->getCode());
  81. }
  82. $this->initDocument('json');
  83. $this->showJsonObjects($this->twitterUserArray($this->other));
  84. $this->endDocument('json');
  85. }
  86. }