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-2009 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('STATUSNET') && !defined('LACONICA')) {
34 require_once INSTALLDIR.'/lib/personalgroupnav.php';
35 require_once INSTALLDIR.'/lib/noticelist.php';
36 require_once INSTALLDIR.'/lib/feedlist.php';
39 * Show a single notice
43 * @author Evan Prodromou <evan@status.net>
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45 * @link http://status.net/
48 class ShownoticeAction extends OwnerDesignAction
51 * Notice object to show
57 * Profile of the notice object
63 * Avatar of the profile of the notice object
69 * Load attributes based on database arguments
71 * Loads all the DB stuff
73 * @param array $args $_REQUEST array
75 * @return success flag
78 function prepare($args)
80 parent::prepare($args);
81 if ($this->boolean('ajax')) {
82 StatusNet::setApi(true);
85 $id = $this->arg('notice');
87 $this->notice = Notice::staticGet($id);
89 if (empty($this->notice)) {
90 // Did we used to have it, and it got deleted?
91 $deleted = Deleted_notice::staticGet($id);
92 if (!empty($deleted)) {
93 $this->clientError(_('Notice deleted.'), 410);
95 $this->clientError(_('No such notice.'), 404);
100 $this->profile = $this->notice->getProfile();
102 if (empty($this->profile)) {
103 $this->serverError(_('Notice has no profile.'), 500);
107 $this->user = User::staticGet('id', $this->profile->id);
109 $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
115 * Is this action read-only?
117 * @return boolean true
120 function isReadOnly($args)
126 * Last-modified date for page
128 * When was the content of this page last modified? Based on notice,
131 * @return int last-modified date as unix timestamp
134 function lastModified()
136 return max(strtotime($this->notice->modified),
137 strtotime($this->profile->modified),
138 ($this->avatar) ? strtotime($this->avatar->modified) : 0);
142 * An entity tag for this page
144 * Shows the ETag for the page, based on the notice ID and timestamps
145 * for the notice, profile, and avatar. It's weak, since we change
146 * the date text "one hour ago", etc.
148 * @return string etag
153 $avtime = ($this->avatar) ?
154 strtotime($this->avatar->modified) : 0;
156 return 'W/"' . implode(':', array($this->arg('action'),
157 common_user_cache_hash(),
160 strtotime($this->notice->created),
161 strtotime($this->profile->modified),
168 * @return string title of the page
173 $base = $this->profile->getFancyName();
175 return sprintf(_('%1$s\'s status on %2$s'),
177 common_exact_date($this->notice->created));
183 * Only handles get, so just show the page.
185 * @param array $args $_REQUEST data (unused)
190 function handle($args)
192 parent::handle($args);
194 if ($this->boolean('ajax')) {
197 if ($this->notice->is_local == Notice::REMOTE_OMB) {
198 if (!empty($this->notice->url)) {
199 $target = $this->notice->url;
200 } else if (!empty($this->notice->uri) && preg_match('/^https?:/', $this->notice->uri)) {
201 // Old OMB posts saved the remote URL only into the URI field.
202 $target = $this->notice->uri;
207 if ($target && $target != $this->selfUrl()) {
208 common_redirect($target, 301);
217 * Don't show local navigation
222 function showLocalNavBlock()
227 * Fill the content area of the page
229 * Shows a single notice list item.
234 function showContent()
236 $this->elementStart('ol', array('class' => 'notices xoxo'));
237 $nli = new SingleNoticeItem($this->notice, $this);
239 $this->elementEnd('ol');
244 header('Content-Type: text/xml;charset=utf-8');
245 $this->xw->startDocument('1.0', 'UTF-8');
246 $this->elementStart('html');
247 $this->elementStart('head');
248 $this->element('title', null, _('Notice'));
249 $this->elementEnd('head');
250 $this->elementStart('body');
251 $nli = new NoticeListItem($this->notice, $this);
253 $this->elementEnd('body');
254 $this->elementEnd('html');
258 * Don't show page notice
263 function showPageNoticeBlock()
273 function showAside() {
277 * Extra <head> content
279 * We show the microid(s) for the author, if any.
286 $user = User::staticGet($this->profile->id);
292 if ($user->emailmicroid && $user->email && $this->notice->uri) {
293 $id = new Microid('mailto:'. $user->email,
295 $this->element('meta', array('name' => 'microid',
296 'content' => $id->toString()));
299 $this->element('link',array('rel'=>'alternate',
300 'type'=>'application/json+oembed',
301 'href'=>common_local_url(
304 array('format'=>'json','url'=>$this->notice->uri)),
305 'title'=>'oEmbed'),null);
306 $this->element('link',array('rel'=>'alternate',
307 'type'=>'text/xml+oembed',
308 'href'=>common_local_url(
311 array('format'=>'xml','url'=>$this->notice->uri)),
312 'title'=>'oEmbed'),null);
314 // Extras to aid in sharing notices to Facebook
315 $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
316 $avatarUrl = ($avatar) ?
317 $avatar->displayUrl() :
318 Avatar::defaultImage(AVATAR_PROFILE_SIZE);
319 $this->element('meta', array('property' => 'og:image',
320 'content' => $avatarUrl));
321 $this->element('meta', array('property' => 'og:description',
322 'content' => $this->notice->content));
326 class SingleNoticeItem extends DoFollowListItem
329 * recipe function for displaying a single notice.
331 * We overload to show attachments.
339 if (Event::handle('StartShowNoticeItem', array($this))) {
341 $this->showNoticeAttachments();
342 $this->showNoticeInfo();
343 $this->showNoticeOptions();
344 Event::handle('EndShowNoticeItem', array($this));
351 * For our zoomed-in special case we'll use a fuller list
352 * for the attachment info.
354 function showNoticeAttachments() {
355 $al = new AttachmentList($this->notice, $this->out);
360 * show the avatar of the notice's author
362 * We use the larger size for single notice page.
367 function showAvatar()
369 $avatar_size = AVATAR_PROFILE_SIZE;
371 $avatar = $this->profile->getAvatar($avatar_size);
373 $this->out->element('img', array('src' => ($avatar) ?
374 $avatar->displayUrl() :
375 Avatar::defaultImage($avatar_size),
376 'class' => 'avatar photo',
377 'width' => $avatar_size,
378 'height' => $avatar_size,
380 ($this->profile->fullname) ?
381 $this->profile->fullname :
382 $this->profile->nickname));