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('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/
47 class ShownoticeAction extends Action
50 * Notice object to show
55 * Profile of the notice object
60 * Avatar of the profile of the notice object
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=array())
75 parent::prepare($args);
76 if ($this->boolean('ajax')) {
77 StatusNet::setApi(true);
80 $this->notice = $this->getNotice();
82 $cur = common_current_user();
85 $curProfile = $cur->getProfile();
90 if (!$this->notice->inScope($curProfile)) {
91 // TRANS: Client exception thrown when trying a view a notice the user has no access to.
92 throw new ClientException(_('Not available.'), 403);
95 $this->profile = $this->notice->getProfile();
97 if (empty($this->profile)) {
98 // TRANS: Server error displayed trying to show a notice without a connected profile.
99 $this->serverError(_('Notice has no profile.'), 500);
102 $this->user = User::getKV('id', $this->profile->id);
105 $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
106 } catch (Exception $e) {
107 $this->avatar = null;
114 * Fetch the notice to show. This may be overridden by child classes to
115 * customize what we fetch without duplicating all of the prepare() method.
119 protected function getNotice()
121 $id = $this->arg('notice');
123 $notice = Notice::getKV('id', $id);
125 if (!$notice instanceof Notice) {
126 // Did we used to have it, and it got deleted?
127 $deleted = Deleted_notice::getKV($id);
128 if ($deleted instanceof Deleted_notice) {
129 // TRANS: Client error displayed trying to show a deleted notice.
130 $this->clientError(_('Notice deleted.'), 410);
132 // TRANS: Client error displayed trying to show a non-existing notice.
133 $this->clientError(_('No such notice.'), 404);
141 * Is this action read-only?
143 * @return boolean true
145 function isReadOnly($args)
151 * Last-modified date for page
153 * When was the content of this page last modified? Based on notice,
156 * @return int last-modified date as unix timestamp
158 function lastModified()
160 return max(strtotime($this->notice->modified),
161 strtotime($this->profile->modified),
162 ($this->avatar) ? strtotime($this->avatar->modified) : 0);
166 * An entity tag for this page
168 * Shows the ETag for the page, based on the notice ID and timestamps
169 * for the notice, profile, and avatar. It's weak, since we change
170 * the date text "one hour ago", etc.
172 * @return string etag
176 $avtime = ($this->avatar) ?
177 strtotime($this->avatar->modified) : 0;
179 return 'W/"' . implode(':', array($this->arg('action'),
180 common_user_cache_hash(),
183 strtotime($this->notice->created),
184 strtotime($this->profile->modified),
191 * @return string title of the page
195 $base = $this->profile->getFancyName();
197 // TRANS: Title of the page that shows a notice.
198 // TRANS: %1$s is a user name, %2$s is the notice creation date/time.
199 return sprintf(_('%1$s\'s status on %2$s'),
201 common_exact_date($this->notice->created));
207 * Only handles get, so just show the page.
209 * @param array $args $_REQUEST data (unused)
213 protected function handle()
217 if ($this->boolean('ajax')) {
220 if ($this->notice->is_local == Notice::REMOTE) {
221 if (!empty($this->notice->url)) {
222 $target = $this->notice->url;
223 } else if (!empty($this->notice->uri) && preg_match('/^https?:/', $this->notice->uri)) {
224 // Old OMB posts saved the remote URL only into the URI field.
225 $target = $this->notice->uri;
230 if ($target && $target != $this->selfUrl()) {
231 common_redirect($target, 301);
239 * Fill the content area of the page
241 * Shows a single notice list item.
245 function showContent()
247 $this->elementStart('ol', array('class' => 'notices xoxo'));
248 $nli = new SingleNoticeItem($this->notice, $this);
250 $this->elementEnd('ol');
255 $this->startHTML('text/xml;charset=utf-8');
256 $this->elementStart('head');
257 // TRANS: Title for page that shows a notice.
258 $this->element('title', null, _m('TITLE','Notice'));
259 $this->elementEnd('head');
260 $this->elementStart('body');
261 $nli = new NoticeListItem($this->notice, $this);
263 $this->elementEnd('body');
268 * Don't show page notice
272 function showPageNoticeBlock()
281 function showAside() {
285 * Extra <head> content
287 * We show the microid(s) for the author, if any.
293 $user = User::getKV($this->profile->id);
299 if ($user->emailmicroid && $user->email && $this->notice->uri) {
300 $id = new Microid('mailto:'. $user->email,
302 $this->element('meta', array('name' => 'microid',
303 'content' => $id->toString()));
306 $this->element('link',array('rel'=>'alternate',
307 'type'=>'application/json+oembed',
308 'href'=>common_local_url(
311 array('format'=>'json','url'=>$this->notice->uri)),
312 'title'=>'oEmbed'),null);
313 $this->element('link',array('rel'=>'alternate',
314 'type'=>'text/xml+oembed',
315 'href'=>common_local_url(
318 array('format'=>'xml','url'=>$this->notice->uri)),
319 'title'=>'oEmbed'),null);
321 // Extras to aid in sharing notices to Facebook
322 $avatarUrl = $this->profile->avatarUrl(AVATAR_PROFILE_SIZE);
323 $this->element('meta', array('property' => 'og:image',
324 'content' => $avatarUrl));
325 $this->element('meta', array('property' => 'og:description',
326 'content' => $this->notice->content));
330 // @todo FIXME: Class documentation missing.
331 class SingleNoticeItem extends DoFollowListItem
333 function avatarSize()
335 return AVATAR_STREAM_SIZE;