3 * StatusNet, the distributed open-source microblogging tool
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Evan Prodromou <evan@status.net>
25 * @copyright 2008-2011 StatusNet, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('GNUSOCIAL')) {
34 require_once INSTALLDIR.'/lib/noticelist.php';
37 * Show a single notice
41 * @author Evan Prodromou <evan@status.net>
42 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43 * @link http://status.net/
45 class ShownoticeAction extends ManagedAction
47 protected $redirectAfterLogin = true;
50 * Notice object to show
52 public $notice = null;
55 * Profile of the notice object
57 public $profile = null;
60 * Avatar of the profile of the notice object
62 public $avatar = null;
65 * Load attributes based on database arguments
67 * Loads all the DB stuff
69 * @param array $args $_REQUEST array
71 * @return success flag
73 protected function prepare(array $args=[])
75 parent::prepare($args);
76 if ($this->boolean('ajax')) {
77 GNUsocial::setApi(true);
80 $this->notice = $this->getNotice();
81 $this->target = $this->notice;
83 if (!$this->notice->inScope($this->scoped)) {
84 // TRANS: Client exception thrown when trying a view a notice the user has no access to.
85 throw new ClientException(_('Access restricted.'), 403);
88 $this->profile = $this->notice->getProfile();
90 if (!$this->profile instanceof Profile) {
91 // TRANS: Server error displayed trying to show a notice without a connected profile.
92 $this->serverError(_('Notice has no profile.'), 500);
96 $this->user = $this->profile->getUser();
97 } catch (NoSuchUserException $e) {
98 // FIXME: deprecate $this->user stuff in extended classes
103 $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
104 } catch (Exception $e) {
105 $this->avatar = null;
112 * Fetch the notice to show. This may be overridden by child classes to
113 * customize what we fetch without duplicating all of the prepare() method.
117 protected function getNotice()
119 $id = $this->arg('notice');
123 $notice = Notice::getByID($id);
126 } catch (NoResultException $e) {
129 Event::handle('IsNoticeDeleted', [$id, &$deleted]);
130 if ($deleted === true) {
131 // TRANS: Client error displayed trying to show a deleted notice.
132 throw new ClientException(_('Notice deleted.'), 410);
135 // TRANS: Client error displayed trying to show a non-existing notice.
136 throw new ClientException(_('No such notice.'), 404);
140 * Is this action read-only?
142 * @return boolean true
144 public function isReadOnly($args)
150 * Last-modified date for page
152 * When was the content of this page last modified? Based on notice,
155 * @return int last-modified date as unix timestamp
157 public function lastModified()
159 return max(strtotime($this->notice->modified),
160 strtotime($this->profile->modified),
161 ($this->avatar) ? strtotime($this->avatar->modified) : 0);
165 * An entity tag for this page
167 * Shows the ETag for the page, based on the notice ID and timestamps
168 * for the notice, profile, and avatar. It's weak, since we change
169 * the date text "one hour ago", etc.
171 * @return string etag
173 public function etag()
175 $avtime = ($this->avatar) ?
176 strtotime($this->avatar->modified) : 0;
178 return 'W/"' . implode(':', [$this->arg('action'),
179 common_user_cache_hash(),
182 strtotime($this->notice->created),
183 strtotime($this->profile->modified),
190 * @return string title of the page
192 public function title()
194 return $this->notice->getTitle();
198 * Fill the content area of the page
200 * Shows a single notice list item.
204 public function showContent()
206 $this->elementStart('ol', ['class' => 'notices xoxo']);
207 $nli = new NoticeListItem($this->notice, $this);
209 $this->elementEnd('ol');
213 * Don't show page notice
217 public function showPageNoticeBlock()
221 public function getFeeds()
225 common_local_url('ApiStatusesShow',
226 ['id' => $this->target->getID(),
227 'format' => 'json']),
228 // TRANS: Title for link to single notice representation.
229 // TRANS: %s is a user nickname.
230 sprintf(_('Single notice (JSON)'))
233 common_local_url('ApiStatusesShow',
234 ['id' => $this->target->getID(),
235 'format' => 'atom']),
236 // TRANS: Title for link to notice feed.
237 // TRANS: %s is a user nickname.
238 sprintf(_('Single notice (Atom)'))
244 * Extra <head> content
246 * Facebook OpenGraph metadata.
250 public function extraHead()
252 // Extras to aid in sharing notices to Facebook
253 $avatarUrl = $this->profile->avatarUrl(AVATAR_PROFILE_SIZE);
254 $this->element('meta', ['property' => 'og:image',
255 'content' => $avatarUrl]);
256 $this->element('meta', ['property' => 'og:description',
257 'content' => $this->notice->content]);