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);
82 $id = $this->arg('notice');
84 $this->notice = Notice::staticGet($id);
86 if (empty($this->notice)) {
87 // Did we used to have it, and it got deleted?
88 $deleted = Deleted_notice::staticGet($id);
89 if (!empty($deleted)) {
90 $this->clientError(_('Notice deleted.'), 410);
92 $this->clientError(_('No such notice.'), 404);
97 $this->profile = $this->notice->getProfile();
99 if (empty($this->profile)) {
100 $this->serverError(_('Notice has no profile.'), 500);
104 $this->user = User::staticGet('id', $this->profile->id);
106 $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
112 * Is this action read-only?
114 * @return boolean true
117 function isReadOnly($args)
123 * Last-modified date for page
125 * When was the content of this page last modified? Based on notice,
128 * @return int last-modified date as unix timestamp
131 function lastModified()
133 return max(strtotime($this->notice->modified),
134 strtotime($this->profile->modified),
135 ($this->avatar) ? strtotime($this->avatar->modified) : 0);
139 * An entity tag for this page
141 * Shows the ETag for the page, based on the notice ID and timestamps
142 * for the notice, profile, and avatar. It's weak, since we change
143 * the date text "one hour ago", etc.
145 * @return string etag
150 $avtime = ($this->avatar) ?
151 strtotime($this->avatar->modified) : 0;
153 return 'W/"' . implode(':', array($this->arg('action'),
154 common_user_cache_hash(),
157 strtotime($this->notice->created),
158 strtotime($this->profile->modified),
165 * @return string title of the page
170 if (!empty($this->profile->fullname)) {
171 $base = $this->profile->fullname . ' (' . $this->profile->nickname . ')';
173 $base = $this->profile->nickname;
176 return sprintf(_('%1$s\'s status on %2$s'),
178 common_exact_date($this->notice->created));
184 * Only handles get, so just show the page.
186 * @param array $args $_REQUEST data (unused)
191 function handle($args)
193 parent::handle($args);
195 if ($this->notice->is_local == Notice::REMOTE_OMB) {
196 if (!empty($this->notice->url)) {
197 $target = $this->notice->url;
198 } else if (!empty($this->notice->uri) && preg_match('/^https?:/', $this->notice->uri)) {
199 // Old OMB posts saved the remote URL only into the URI field.
200 $target = $this->notice->uri;
205 if ($target && $target != $this->selfUrl()) {
206 common_redirect($target, 301);
214 * Don't show local navigation
219 function showLocalNavBlock()
224 * Fill the content area of the page
226 * Shows a single notice list item.
231 function showContent()
233 $this->elementStart('ol', array('class' => 'notices xoxo'));
234 $nli = new SingleNoticeItem($this->notice, $this);
236 $this->elementEnd('ol');
240 * Don't show page notice
245 function showPageNoticeBlock()
255 function showAside() {
259 * Extra <head> content
261 * We show the microid(s) for the author, if any.
268 $user = User::staticGet($this->profile->id);
274 if ($user->emailmicroid && $user->email && $this->notice->uri) {
275 $id = new Microid('mailto:'. $user->email,
277 $this->element('meta', array('name' => 'microid',
278 'content' => $id->toString()));
281 $this->element('link',array('rel'=>'alternate',
282 'type'=>'application/json+oembed',
283 'href'=>common_local_url(
286 array('format'=>'json','url'=>$this->notice->uri)),
287 'title'=>'oEmbed'),null);
288 $this->element('link',array('rel'=>'alternate',
289 'type'=>'text/xml+oembed',
290 'href'=>common_local_url(
293 array('format'=>'xml','url'=>$this->notice->uri)),
294 'title'=>'oEmbed'),null);
296 // Extras to aid in sharing notices to Facebook
297 $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
298 $avatarUrl = ($avatar) ?
299 $avatar->displayUrl() :
300 Avatar::defaultImage(AVATAR_PROFILE_SIZE);
301 $this->element('meta', array('property' => 'og:image',
302 'content' => $avatarUrl));
303 $this->element('meta', array('property' => 'og:description',
304 'content' => $this->notice->content));
308 class SingleNoticeItem extends DoFollowListItem
311 * recipe function for displaying a single notice.
313 * We overload to show attachments.
321 if (Event::handle('StartShowNoticeItem', array($this))) {
323 $this->showNoticeAttachments();
324 $this->showNoticeInfo();
325 $this->showNoticeOptions();
326 Event::handle('EndShowNoticeItem', array($this));
332 function showNoticeAttachments() {
333 $al = new AttachmentList($this->notice, $this->out);