123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- <?php
- defined('GNUSOCIAL') || die();
- class apNoticeAction extends ManagedAction
- {
- protected $needLogin = false;
- protected $canPost = true;
-
- public $notice_id;
-
- public $notice = null;
-
- public $profile = null;
-
- public $avatar = null;
-
- protected function prepare(array $args = []): bool
- {
- parent::prepare($args);
- $this->notice_id = (int)$this->trimmed('id');
- try {
- $this->notice = $this->getNotice();
- } catch (ClientException $e) {
-
- ActivityPubReturn::answer(Activitypub_tombstone::tombstone_to_array($this->notice_id), 410);
- }
- $this->target = $this->notice;
- if (!$this->notice->inScope($this->scoped)) {
-
- throw new ClientException(_m('Access restricted.'), 403);
- }
- $this->profile = $this->notice->getProfile();
- if (!$this->profile instanceof Profile) {
-
- $this->serverError(_m('Notice has no profile.'), 500);
- }
- try {
- $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
- } catch (Exception $e) {
- $this->avatar = null;
- }
- return true;
- }
-
- public function isReadOnly($args): bool
- {
- return true;
- }
-
- public function lastModified(): int
- {
- return max(strtotime($this->notice->modified),
- strtotime($this->profile->modified),
- ($this->avatar) ? strtotime($this->avatar->modified) : 0);
- }
-
- protected function handle(): void
- {
- if (is_null($this->notice)) {
- ActivityPubReturn::error('Invalid Activity URI.', 404);
- }
- if (!$this->notice->isLocal()) {
-
- ActivityPubReturn::error("This is not a local activity.", 403);
- }
- $res = Activitypub_notice::notice_to_array($this->notice);
- ActivityPubReturn::answer($res);
- }
-
- protected function getNotice(): ?Notice
- {
- $notice = null;
- try {
- $notice = Notice::getByID($this->notice_id);
-
- return $notice;
- } catch (NoResultException $e) {
-
- $deleted = null;
- Event::handle('IsNoticeDeleted', [$this->notice_id, &$deleted]);
- if ($deleted === true) {
-
- throw new ClientException(_m('Notice deleted.'), 410);
- }
- }
-
- return null;
- }
- }
|