123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- <?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 = Notice::getKV('id', $this->notice_id);
- if (!$this->notice instanceof Notice) {
- $deleted = Deleted_notice::getKV('id', $this->notice_id);
- if ($deleted instanceof Deleted_notice) {
-
- $this->clientError(_('Notice deleted.'), 410);
- }
-
- $this->clientError(_('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()
- {
- if (!empty($this->notice)) {
- 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));
- }
- } else {
-
-
- $deleted = Deleted_notice::getKV($this->notice_id);
- if (!empty($deleted)) {
- $this->clientError(
-
- _('Status deleted.'),
- 410,
- $this->format
- );
- } else {
- $this->clientError(
-
- _('No status with that ID found.'),
- 404,
- $this->format
- );
- }
- }
- }
-
- function isReadOnly($args)
- {
- return ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'HEAD');
- }
-
- function lastModified()
- {
- if (!empty($this->notice)) {
- return strtotime($this->notice->created);
- }
- return null;
- }
-
- function etag()
- {
- if (!empty($this->notice)) {
- return '"' . implode(
- ':',
- array($this->arg('action'),
- common_user_cache_hash($this->auth_user),
- common_language(),
- $this->notice->id,
- strtotime($this->notice->created))
- )
- . '"';
- }
- return null;
- }
- 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->delete();
- 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");
- }
- }
|