apistatusesdestroy.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Destroy a notice through the API
  6. *
  7. * PHP version 5
  8. *
  9. * LICENCE: This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @category API
  23. * @package StatusNet
  24. * @author Craig Andrews <candrews@integralblue.com>
  25. * @author Evan Prodromou <evan@status.net>
  26. * @author Jeffery To <jeffery.to@gmail.com>
  27. * @author Tom Blankenship <mac65@mac65.com>
  28. * @author Mike Cochrane <mikec@mikenz.geek.nz>
  29. * @author Robin Millette <robin@millette.info>
  30. * @author Zach Copley <zach@status.net>
  31. * @copyright 2009 StatusNet, Inc.
  32. * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
  33. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  34. * @link http://status.net/
  35. */
  36. if (!defined('GNUSOCIAL')) { exit(1); }
  37. /**
  38. * Deletes one of the authenticating user's statuses (notices).
  39. *
  40. * @category API
  41. * @package StatusNet
  42. * @author Craig Andrews <candrews@integralblue.com>
  43. * @author Evan Prodromou <evan@status.net>
  44. * @author Jeffery To <jeffery.to@gmail.com>
  45. * @author Tom Blankenship <mac65@mac65.com>
  46. * @author Mike Cochrane <mikec@mikenz.geek.nz>
  47. * @author Robin Millette <robin@millette.info>
  48. * @author Zach Copley <zach@status.net>
  49. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  50. * @link http://status.net/
  51. */
  52. class ApiStatusesDestroyAction extends ApiAuthAction
  53. {
  54. protected function prepare(array $args=array())
  55. {
  56. parent::prepare($args);
  57. if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) {
  58. // TRANS: Client error displayed trying to delete a status not using POST or DELETE.
  59. // TRANS: POST and DELETE should not be translated.
  60. throw new ClientException(_('This method requires a POST or DELETE.'));
  61. }
  62. // FIXME: Return with a Not Acceptable status code?
  63. if (!in_array($this->format, array('xml', 'json'))) {
  64. // TRANS: Client error displayed when coming across a non-supported API method.
  65. throw new ClientException(_('API method not found.'), 404);
  66. }
  67. try {
  68. $this->notice = Notice::getByID($this->trimmed('id'));
  69. } catch (NoResultException $e) {
  70. // TRANS: Client error displayed trying to delete a status with an invalid ID.
  71. throw new ClientException(_('No status found with that ID.'), 404);
  72. }
  73. return true;
  74. }
  75. protected function handle()
  76. {
  77. parent::handle();
  78. if (!$this->scoped->sameAs($this->notice->getProfile()) && !$this->scoped->hasRight(Right::DELETEOTHERSNOTICE)) {
  79. // TRANS: Client error displayed trying to delete a status of another user.
  80. throw new AuthorizationException(_('You may not delete another user\'s status.'));
  81. }
  82. if (Event::handle('StartDeleteOwnNotice', array($this->scoped->getUser(), $this->notice))) {
  83. $this->notice->deleteAs($this->scoped);
  84. Event::handle('EndDeleteOwnNotice', array($this->scoped->getUser(), $this->notice));
  85. }
  86. $this->showNotice();
  87. }
  88. /**
  89. * Show the deleted notice
  90. *
  91. * @return void
  92. */
  93. function showNotice()
  94. {
  95. if (!empty($this->notice)) {
  96. if ($this->format == 'xml') {
  97. $this->showSingleXmlStatus($this->notice);
  98. } elseif ($this->format == 'json') {
  99. $this->show_single_json_status($this->notice);
  100. }
  101. }
  102. }
  103. }