3 * Laconica, the distributed open-source microblogging tool
5 * Show notice attachments
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@controlyourself.ca>
25 * @copyright 2008-2009 Control Yourself, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://laconi.ca/
30 if (!defined('LACONICA')) {
34 require_once INSTALLDIR.'/lib/attachmentlist.php';
37 * Show notice attachments
41 * @author Evan Prodromou <evan@controlyourself.ca>
42 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43 * @link http://laconi.ca/
46 class AttachmentsAction extends Action
49 * Notice object to show
55 * Profile of the notice object
61 * Avatar of the profile of the notice object
67 * Is this action read-only?
69 * @return boolean true
72 function isReadOnly($args)
78 * Last-modified date for page
80 * When was the content of this page last modified? Based on notice,
83 * @return int last-modified date as unix timestamp
86 function lastModified()
88 return max(strtotime($this->notice->created),
89 strtotime($this->profile->modified),
90 ($this->avatar) ? strtotime($this->avatar->modified) : 0);
94 * An entity tag for this page
96 * Shows the ETag for the page, based on the notice ID and timestamps
97 * for the notice, profile, and avatar. It's weak, since we change
98 * the date text "one hour ago", etc.
100 * @return string etag
105 $avtime = ($this->avatar) ?
106 strtotime($this->avatar->modified) : 0;
108 return 'W/"' . implode(':', array($this->arg('action'),
111 strtotime($this->notice->created),
112 strtotime($this->profile->modified),
119 * @return string title of the page
124 return sprintf(_('%1$s\'s status on %2$s'),
125 $this->profile->nickname,
126 common_exact_date($this->notice->created));
131 * Load attributes based on database arguments
133 * Loads all the DB stuff
135 * @param array $args $_REQUEST array
137 * @return success flag
140 function prepare($args)
142 parent::prepare($args);
144 $id = $this->arg('notice');
146 $this->notice = Notice::staticGet($id);
148 if (!$this->notice) {
149 $this->clientError(_('No such notice.'), 404);
155 // STOP if there are no attachments
156 // maybe even redirect if there's a single one
158 $this->clientError(_('No such attachment.'), 404);
166 $this->profile = $this->notice->getProfile();
168 if (!$this->profile) {
169 $this->serverError(_('Notice has no profile'), 500);
173 $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
182 * Only handles get, so just show the page.
184 * @param array $args $_REQUEST data (unused)
189 function handle($args)
191 parent::handle($args);
193 if ($this->notice->is_local == 0) {
194 if (!empty($this->notice->url)) {
195 common_redirect($this->notice->url, 301);
196 } else if (!empty($this->notice->uri) && preg_match('/^https?:/', $this->notice->uri)) {
197 common_redirect($this->notice->uri, 301);
200 $f2p = new File_to_post;
201 $f2p->post_id = $this->notice->id;
203 $file->joinAdd($f2p);
205 $file->selectAdd('file.id as id');
206 $count = $file->find(true);
209 common_redirect(common_local_url('attachment', array('attachment' => $file->id)), 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 $al = new AttachmentList($this->notice, $this);
241 * Don't show page notice
246 function showPageNoticeBlock()
256 function showAside() {
260 * Extra <head> content
262 * We show the microid(s) for the author, if any.
269 $user = User::staticGet($this->profile->id);
275 if ($user->emailmicroid && $user->email && $this->notice->uri) {
276 $id = new Microid('mailto:'. $user->email,
278 $this->element('meta', array('name' => 'microid',
279 'content' => $id->toString()));
282 if ($user->jabbermicroid && $user->jabber && $this->notice->uri) {
283 $id = new Microid('xmpp:', $user->jabber,
285 $this->element('meta', array('name' => 'microid',
286 'content' => $id->toString()));