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');
116 $notice = Notice::getKV('id', $id);
117 if ($notice instanceof Notice) {
122 // Did we use to have it, and it got deleted?
123 $deleted = Deleted_notice::getKV('id', $id);
124 if ($deleted instanceof Deleted_notice) {
125 // TRANS: Client error displayed trying to show a deleted notice.
126 $this->clientError(_('Notice deleted.'), 410);
128 // TRANS: Client error displayed trying to show a non-existing notice.
129 $this->clientError(_('No such notice.'), 404);
133 * Is this action read-only?
135 * @return boolean true
137 function isReadOnly($args)
143 * Last-modified date for page
145 * When was the content of this page last modified? Based on notice,
148 * @return int last-modified date as unix timestamp
150 function lastModified()
152 return max(strtotime($this->notice->modified),
153 strtotime($this->profile->modified),
154 ($this->avatar) ? strtotime($this->avatar->modified) : 0);
158 * An entity tag for this page
160 * Shows the ETag for the page, based on the notice ID and timestamps
161 * for the notice, profile, and avatar. It's weak, since we change
162 * the date text "one hour ago", etc.
164 * @return string etag
168 $avtime = ($this->avatar) ?
169 strtotime($this->avatar->modified) : 0;
171 return 'W/"' . implode(':', array($this->arg('action'),
172 common_user_cache_hash(),
175 strtotime($this->notice->created),
176 strtotime($this->profile->modified),
183 * @return string title of the page
187 return $this->notice->getTitle();
191 * Fill the content area of the page
193 * Shows a single notice list item.
197 function showContent()
199 $this->elementStart('ol', array('class' => 'notices xoxo'));
200 $nli = new NoticeListItem($this->notice, $this);
202 $this->elementEnd('ol');
206 * Don't show page notice
210 function showPageNoticeBlock()
219 function showAside() {
223 * Extra <head> content
225 * We show the microid(s) for the author, if any.
231 $user = User::getKV($this->profile->id);
233 if (!$user instanceof User) {
237 if ($user->emailmicroid && $user->email && $this->notice->uri) {
238 $id = new Microid('mailto:'. $user->email,
240 $this->element('meta', array('name' => 'microid',
241 'content' => $id->toString()));
244 // Extras to aid in sharing notices to Facebook
245 $avatarUrl = $this->profile->avatarUrl(AVATAR_PROFILE_SIZE);
246 $this->element('meta', array('property' => 'og:image',
247 'content' => $avatarUrl));
248 $this->element('meta', array('property' => 'og:description',
249 'content' => $this->notice->content));