123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- if (!defined('GNUSOCIAL')) { exit(1); }
- class ApiStatusesDestroyAction extends ApiAuthAction
- {
- protected function prepare(array $args=array())
- {
- parent::prepare($args);
- if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) {
-
-
- throw new ClientException(_('This method requires a POST or DELETE.'));
- }
-
- if (!in_array($this->format, array('xml', 'json'))) {
-
- throw new ClientException(_('API method not found.'), 404);
- }
- try {
- $this->notice = Notice::getByID($this->trimmed('id'));
- } catch (NoResultException $e) {
-
- throw new ClientException(_('No status found with that ID.'), 404);
- }
- return true;
- }
- protected function handle()
- {
- parent::handle();
- if (!$this->scoped->sameAs($this->notice->getProfile()) && !$this->scoped->hasRight(Right::DELETEOTHERSNOTICE)) {
-
- throw new AuthorizationException(_('You may not delete another user\'s status.'));
- }
- if (Event::handle('StartDeleteOwnNotice', array($this->scoped->getUser(), $this->notice))) {
- $this->notice->deleteAs($this->scoped);
- Event::handle('EndDeleteOwnNotice', array($this->scoped->getUser(), $this->notice));
- }
- $this->showNotice();
- }
-
- function showNotice()
- {
- if (!empty($this->notice)) {
- if ($this->format == 'xml') {
- $this->showSingleXmlStatus($this->notice);
- } elseif ($this->format == 'json') {
- $this->show_single_json_status($this->notice);
- }
- }
- }
- }
|