123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class ApiStatusesDestroyAction extends ApiAuthAction
- {
- var $status = null;
-
- function prepare($args)
- {
- parent::prepare($args);
- $this->user = $this->auth_user;
- $this->notice_id = (int)$this->trimmed('id');
- if (empty($notice_id)) {
- $this->notice_id = (int)$this->arg('id');
- }
- $this->notice = Notice::getKV((int)$this->notice_id);
- return true;
- }
-
- function handle($args)
- {
- parent::handle($args);
- if (!in_array($this->format, array('xml', 'json'))) {
- $this->clientError(
-
- _('API method not found.'),
- 404
- );
- return;
- }
- if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) {
- $this->clientError(
-
-
- _('This method requires a POST or DELETE.'),
- 400,
- $this->format
- );
- return;
- }
- if (empty($this->notice)) {
- $this->clientError(
-
- _('No status found with that ID.'),
- 404, $this->format
- );
- return;
- }
- if ($this->user->id == $this->notice->profile_id) {
- if (Event::handle('StartDeleteOwnNotice', array($this->user, $this->notice))) {
- $this->notice->delete();
- Event::handle('EndDeleteOwnNotice', array($this->user, $this->notice));
- }
- $this->showNotice();
- } else {
- $this->clientError(
-
- _('You may not delete another user\'s status.'),
- 403,
- $this->format
- );
- }
- }
-
- 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);
- }
- }
- }
- }
|