123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- <?php
- if (!defined('GNUSOCIAL')) { exit(1); }
- class ApiStatusesShowAction extends ApiPrivateAuthAction
- {
- var $notice_id = null;
- var $notice = null;
-
- protected function prepare(array $args=array())
- {
- parent::prepare($args);
-
-
-
- $this->notice_id = (int)$this->trimmed('id');
- $this->notice = null;
- try {
- $this->notice = Notice::getByID($this->notice_id);
- } catch (NoResultException $e) {
-
- $deleted = null;
- Event::handle('IsNoticeDeleted', array($this->notice_id, &$deleted));
- if ($deleted === true) {
-
- throw new ClientException(_('Notice deleted.'), 410);
- }
-
- throw new ClientException(_('No such notice.'), 404);
- }
- if (!$this->notice->inScope($this->scoped)) {
-
- throw new ClientException(_('Access restricted.'), 403);
- }
- return true;
- }
-
- protected function handle()
- {
- parent::handle();
- if (!in_array($this->format, array('xml', 'json', 'atom'))) {
-
- $this->clientError(_('API method not found.'), 404);
- }
- switch ($_SERVER['REQUEST_METHOD']) {
- case 'GET':
- $this->showNotice();
- break;
- case 'DELETE':
- $this->deleteNotice();
- break;
- default:
-
- $this->clientError(_('HTTP method not supported.'), 405);
- }
- }
-
- function showNotice()
- {
- switch ($this->format) {
- case 'xml':
- $this->showSingleXmlStatus($this->notice);
- break;
- case 'json':
- $this->show_single_json_status($this->notice);
- break;
- case 'atom':
- $this->showSingleAtomStatus($this->notice);
- break;
- default:
-
-
- throw new Exception(sprintf(_("Unsupported format: %s."), $this->format));
- }
- }
-
- function isReadOnly($args)
- {
- return ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'HEAD');
- }
-
- function lastModified()
- {
- return strtotime($this->notice->created);
- }
-
- function etag()
- {
- return '"' . implode(
- ':',
- array($this->arg('action'),
- common_user_cache_hash($this->auth_user),
- common_language(),
- $this->notice->id,
- strtotime($this->notice->created))
- )
- . '"';
- }
- function deleteNotice()
- {
- if ($this->format != 'atom') {
-
- $this->clientError(_('Can only delete using the Atom format.'));
- }
- if (empty($this->auth_user) ||
- ($this->notice->profile_id != $this->auth_user->id &&
- !$this->auth_user->hasRight(Right::DELETEOTHERSNOTICE))) {
-
- $this->clientError(_('Cannot delete this notice.'), 403);
- }
- if (Event::handle('StartDeleteOwnNotice', array($this->auth_user, $this->notice))) {
- $this->notice->deleteAs($this->scoped);
- Event::handle('EndDeleteOwnNotice', array($this->auth_user, $this->notice));
- }
-
- header('HTTP/1.1 200 OK');
- header('Content-Type: text/plain');
-
- print(sprintf(_('Deleted notice %d'), $this->notice->id));
- print("\n");
- }
- }
|