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();
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(_('Access restricted.'), 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');
118 $notice = Notice::getByID($id);
121 } catch (NoResultException $e) {
124 Event::handle('IsNoticeDeleted', array($id, &$deleted));
125 if ($deleted === true) {
126 // TRANS: Client error displayed trying to show a deleted notice.
127 throw new ClientException(_('Notice deleted.'), 410);
130 // TRANS: Client error displayed trying to show a non-existing notice.
131 throw new ClientException(_('No such notice.'), 404);
135 * Is this action read-only?
137 * @return boolean true
139 function isReadOnly($args)
145 * Last-modified date for page
147 * When was the content of this page last modified? Based on notice,
150 * @return int last-modified date as unix timestamp
152 function lastModified()
154 return max(strtotime($this->notice->modified),
155 strtotime($this->profile->modified),
156 ($this->avatar) ? strtotime($this->avatar->modified) : 0);
160 * An entity tag for this page
162 * Shows the ETag for the page, based on the notice ID and timestamps
163 * for the notice, profile, and avatar. It's weak, since we change
164 * the date text "one hour ago", etc.
166 * @return string etag
170 $avtime = ($this->avatar) ?
171 strtotime($this->avatar->modified) : 0;
173 return 'W/"' . implode(':', array($this->arg('action'),
174 common_user_cache_hash(),
177 strtotime($this->notice->created),
178 strtotime($this->profile->modified),
185 * @return string title of the page
189 return $this->notice->getTitle();
193 * Fill the content area of the page
195 * Shows a single notice list item.
199 function showContent()
201 $this->elementStart('ol', array('class' => 'notices xoxo'));
202 $nli = new NoticeListItem($this->notice, $this);
204 $this->elementEnd('ol');
208 * Don't show page notice
212 function showPageNoticeBlock()
221 function showAside() {
225 * Extra <head> content
227 * Facebook OpenGraph metadata.
233 // Extras to aid in sharing notices to Facebook
234 $avatarUrl = $this->profile->avatarUrl(AVATAR_PROFILE_SIZE);
235 $this->element('meta', array('property' => 'og:image',
236 'content' => $avatarUrl));
237 $this->element('meta', array('property' => 'og:description',
238 'content' => $this->notice->content));