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 Action
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 StatusNet::setApi(true);
76 $this->notice = $this->getNotice();
78 if (!$this->notice->inScope($this->scoped)) {
79 // TRANS: Client exception thrown when trying a view a notice the user has no access to.
80 throw new ClientException(_('Not available.'), 403);
83 $this->profile = $this->notice->getProfile();
85 if (!$this->profile instanceof Profile) {
86 // TRANS: Server error displayed trying to show a notice without a connected profile.
87 $this->serverError(_('Notice has no profile.'), 500);
91 $this->user = $this->profile->getUser();
92 } catch (NoSuchUserException $e) {
93 // FIXME: deprecate $this->user stuff in extended classes
98 $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
99 } catch (Exception $e) {
100 $this->avatar = null;
107 * Fetch the notice to show. This may be overridden by child classes to
108 * customize what we fetch without duplicating all of the prepare() method.
112 protected function getNotice()
114 $id = $this->arg('notice');
116 $notice = Notice::getKV('id', $id);
118 if (!$notice instanceof Notice) {
119 // Did we used to have it, and it got deleted?
120 $deleted = Deleted_notice::getKV($id);
121 if ($deleted instanceof Deleted_notice) {
122 // TRANS: Client error displayed trying to show a deleted notice.
123 $this->clientError(_('Notice deleted.'), 410);
125 // TRANS: Client error displayed trying to show a non-existing notice.
126 $this->clientError(_('No such notice.'), 404);
134 * Is this action read-only?
136 * @return boolean true
138 function isReadOnly($args)
144 * Last-modified date for page
146 * When was the content of this page last modified? Based on notice,
149 * @return int last-modified date as unix timestamp
151 function lastModified()
153 return max(strtotime($this->notice->modified),
154 strtotime($this->profile->modified),
155 ($this->avatar) ? strtotime($this->avatar->modified) : 0);
159 * An entity tag for this page
161 * Shows the ETag for the page, based on the notice ID and timestamps
162 * for the notice, profile, and avatar. It's weak, since we change
163 * the date text "one hour ago", etc.
165 * @return string etag
169 $avtime = ($this->avatar) ?
170 strtotime($this->avatar->modified) : 0;
172 return 'W/"' . implode(':', array($this->arg('action'),
173 common_user_cache_hash(),
176 strtotime($this->notice->created),
177 strtotime($this->profile->modified),
184 * @return string title of the page
188 $base = $this->profile->getFancyName();
190 // TRANS: Title of the page that shows a notice.
191 // TRANS: %1$s is a user name, %2$s is the notice creation date/time.
192 return sprintf(_('%1$s\'s status on %2$s'),
194 common_exact_date($this->notice->created));
200 * Only handles get, so just show the page.
202 * @param array $args $_REQUEST data (unused)
206 protected function handle()
210 if (StatusNet::isAjax()) {
218 * Fill the content area of the page
220 * Shows a single notice list item.
224 function showContent()
226 $this->elementStart('ol', array('class' => 'notices xoxo'));
227 $nli = new SingleNoticeItem($this->notice, $this);
229 $this->elementEnd('ol');
234 $this->startHTML('text/xml;charset=utf-8');
235 $this->elementStart('head');
236 // TRANS: Title for page that shows a notice.
237 $this->element('title', null, _m('TITLE','Notice'));
238 $this->elementEnd('head');
239 $this->elementStart('body');
240 $nli = new NoticeListItem($this->notice, $this);
242 $this->elementEnd('body');
247 * Don't show page notice
251 function showPageNoticeBlock()
260 function showAside() {
264 * Extra <head> content
266 * We show the microid(s) for the author, if any.
272 $user = User::getKV($this->profile->id);
278 if ($user->emailmicroid && $user->email && $this->notice->uri) {
279 $id = new Microid('mailto:'. $user->email,
281 $this->element('meta', array('name' => 'microid',
282 'content' => $id->toString()));
285 $this->element('link',array('rel'=>'alternate',
286 'type'=>'application/json+oembed',
287 'href'=>common_local_url(
290 array('format'=>'json','url'=>$this->notice->getUrl())),
291 'title'=>'oEmbed'),null);
292 $this->element('link',array('rel'=>'alternate',
293 'type'=>'text/xml+oembed',
294 'href'=>common_local_url(
297 array('format'=>'xml','url'=>$this->notice->getUrl())),
298 'title'=>'oEmbed'),null);
300 // Extras to aid in sharing notices to Facebook
301 $avatarUrl = $this->profile->avatarUrl(AVATAR_PROFILE_SIZE);
302 $this->element('meta', array('property' => 'og:image',
303 'content' => $avatarUrl));
304 $this->element('meta', array('property' => 'og:description',
305 'content' => $this->notice->content));
309 // @todo FIXME: Class documentation missing.
310 class SingleNoticeItem extends DoFollowListItem
312 function avatarSize()
314 return AVATAR_STREAM_SIZE;