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')) { exit(1); }
32 require_once INSTALLDIR.'/lib/noticelist.php';
35 * Show a single notice
39 * @author Evan Prodromou <evan@status.net>
40 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
41 * @link http://status.net/
43 class ShownoticeAction extends ManagedAction
46 * Notice object to show
51 * Profile of the notice object
56 * Avatar of the profile of the notice object
61 * Load attributes based on database arguments
63 * Loads all the DB stuff
65 * @param array $args $_REQUEST array
67 * @return success flag
69 protected function prepare(array $args=array())
71 parent::prepare($args);
72 if ($this->boolean('ajax')) {
73 GNUsocial::setApi(true);
76 $this->notice = $this->getNotice();
77 $this->target = $this->notice;
79 if (!$this->notice->inScope($this->scoped)) {
80 // TRANS: Client exception thrown when trying a view a notice the user has no access to.
81 throw new ClientException(_('Access restricted.'), 403);
84 $this->profile = $this->notice->getProfile();
86 if (!$this->profile instanceof Profile) {
87 // TRANS: Server error displayed trying to show a notice without a connected profile.
88 $this->serverError(_('Notice has no profile.'), 500);
92 $this->user = $this->profile->getUser();
93 } catch (NoSuchUserException $e) {
94 // FIXME: deprecate $this->user stuff in extended classes
99 $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
100 } catch (Exception $e) {
101 $this->avatar = null;
108 * Fetch the notice to show. This may be overridden by child classes to
109 * customize what we fetch without duplicating all of the prepare() method.
113 protected function getNotice()
115 $id = $this->arg('notice');
119 $notice = Notice::getByID($id);
122 } catch (NoResultException $e) {
125 Event::handle('IsNoticeDeleted', array($id, &$deleted));
126 if ($deleted === true) {
127 // TRANS: Client error displayed trying to show a deleted notice.
128 throw new ClientException(_('Notice deleted.'), 410);
131 // TRANS: Client error displayed trying to show a non-existing notice.
132 throw new ClientException(_('No such notice.'), 404);
136 * Is this action read-only?
138 * @return boolean true
140 function isReadOnly($args)
146 * Last-modified date for page
148 * When was the content of this page last modified? Based on notice,
151 * @return int last-modified date as unix timestamp
153 function lastModified()
155 return max(strtotime($this->notice->modified),
156 strtotime($this->profile->modified),
157 ($this->avatar) ? strtotime($this->avatar->modified) : 0);
161 * An entity tag for this page
163 * Shows the ETag for the page, based on the notice ID and timestamps
164 * for the notice, profile, and avatar. It's weak, since we change
165 * the date text "one hour ago", etc.
167 * @return string etag
171 $avtime = ($this->avatar) ?
172 strtotime($this->avatar->modified) : 0;
174 return 'W/"' . implode(':', array($this->arg('action'),
175 common_user_cache_hash(),
178 strtotime($this->notice->created),
179 strtotime($this->profile->modified),
186 * @return string title of the page
190 return $this->notice->getTitle();
194 * Fill the content area of the page
196 * Shows a single notice list item.
200 function showContent()
202 $this->elementStart('ol', array('class' => 'notices xoxo'));
203 $nli = new NoticeListItem($this->notice, $this);
205 $this->elementEnd('ol');
209 * Don't show page notice
213 function showPageNoticeBlock()
219 return array(new Feed(Feed::JSON,
220 common_local_url('ApiStatusesShow',
222 'id' => $this->target->getID(),
223 'format' => 'json')),
224 // TRANS: Title for link to single notice representation.
225 // TRANS: %s is a user nickname.
226 sprintf(_('Single notice (JSON)'))),
228 common_local_url('ApiStatusesShow',
230 'id' => $this->target->getID(),
231 'format' => 'atom')),
232 // TRANS: Title for link to notice feed.
233 // TRANS: %s is a user nickname.
234 sprintf(_('Single notice (Atom)'))));
238 * Extra <head> content
240 * Facebook OpenGraph metadata.
246 // Extras to aid in sharing notices to Facebook
247 $avatarUrl = $this->profile->avatarUrl(AVATAR_PROFILE_SIZE);
248 $this->element('meta', array('property' => 'og:image',
249 'content' => $avatarUrl));
250 $this->element('meta', array('property' => 'og:description',
251 'content' => $this->notice->content));