123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- <?php
- if (!defined('GNUSOCIAL')) {
- exit(1);
- }
- require_once INSTALLDIR . '/lib/notices/noticelist.php';
- class ShownoticeAction extends ManagedAction
- {
- protected $redirectAfterLogin = true;
-
-
- public $notice = null;
-
- public $profile = null;
-
- public $avatar = null;
-
- protected function prepare(array $args=[])
- {
- parent::prepare($args);
- if ($this->boolean('ajax')) {
- GNUsocial::setApi(true);
- }
- $this->notice = $this->getNotice();
- $this->target = $this->notice;
- if (!$this->notice->inScope($this->scoped)) {
-
- throw new ClientException(_('Access restricted.'), 403);
- }
- $this->profile = $this->notice->getProfile();
- if (!$this->profile instanceof Profile) {
-
- $this->serverError(_('Notice has no profile.'), 500);
- }
- try {
- $this->user = $this->profile->getUser();
- } catch (NoSuchUserException $e) {
-
- $this->user = null;
- }
- try {
- $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
- } catch (Exception $e) {
- $this->avatar = null;
- }
- return true;
- }
-
- protected function getNotice()
- {
- $id = $this->arg('notice');
- $notice = null;
- try {
- $notice = Notice::getByID($id);
-
- return $notice;
- } catch (NoResultException $e) {
-
- $deleted = null;
- Event::handle('IsNoticeDeleted', [$id, &$deleted]);
- if ($deleted === true) {
-
- throw new ClientException(_('Notice deleted.'), 410);
- }
- }
-
- throw new ClientException(_('No such notice.'), 404);
- }
-
- public function isReadOnly($args)
- {
- return true;
- }
-
- public function lastModified()
- {
- return max(strtotime($this->notice->modified),
- strtotime($this->profile->modified),
- ($this->avatar) ? strtotime($this->avatar->modified) : 0);
- }
-
- public function etag()
- {
- $avtime = ($this->avatar) ?
- strtotime($this->avatar->modified) : 0;
- return 'W/"' . implode(':', [$this->arg('action'),
- common_user_cache_hash(),
- common_language(),
- $this->notice->id,
- strtotime($this->notice->created),
- strtotime($this->profile->modified),
- $avtime]) . '"';
- }
-
- public function title()
- {
- return $this->notice->getTitle();
- }
-
- public function showContent()
- {
- $this->elementStart('ol', ['class' => 'notices xoxo']);
- $nli = new NoticeListItem($this->notice, $this);
- $nli->show();
- $this->elementEnd('ol');
- }
-
- public function showPageNoticeBlock()
- {
- }
- public function getFeeds()
- {
- return [
- new Feed(Feed::JSON,
- common_local_url('ApiStatusesShow',
- ['id' => $this->target->getID(),
- 'format' => 'json']),
-
-
- sprintf(_('Single notice (JSON)'))
- ),
- new Feed(Feed::ATOM,
- common_local_url('ApiStatusesShow',
- ['id' => $this->target->getID(),
- 'format' => 'atom']),
-
-
- sprintf(_('Single notice (Atom)'))
- )
- ];
- }
-
- public function extraHead()
- {
-
- $avatarUrl = $this->profile->avatarUrl(AVATAR_PROFILE_SIZE);
- $this->element('meta', ['property' => 'og:image',
- 'content' => $avatarUrl]);
- $this->element('meta', ['property' => 'og:description',
- 'content' => $this->notice->content]);
- }
- }
|