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/personalgroupnav.php';
35 //require_once INSTALLDIR.'/lib/feedlist.php';
36 require_once INSTALLDIR.'/lib/attachmentlist.php';
39 * Show notice attachments
43 * @author Evan Prodromou <evan@controlyourself.ca>
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45 * @link http://laconi.ca/
48 class AttachmentsAction extends Action
51 * Notice object to show
57 * Profile of the notice object
63 * Avatar of the profile of the notice object
69 * Is this action read-only?
71 * @return boolean true
74 function isReadOnly($args)
80 * Last-modified date for page
82 * When was the content of this page last modified? Based on notice,
85 * @return int last-modified date as unix timestamp
88 function lastModified()
90 return max(strtotime($this->notice->created),
91 strtotime($this->profile->modified),
92 ($this->avatar) ? strtotime($this->avatar->modified) : 0);
96 * An entity tag for this page
98 * Shows the ETag for the page, based on the notice ID and timestamps
99 * for the notice, profile, and avatar. It's weak, since we change
100 * the date text "one hour ago", etc.
102 * @return string etag
107 $avtime = ($this->avatar) ?
108 strtotime($this->avatar->modified) : 0;
110 return 'W/"' . implode(':', array($this->arg('action'),
113 strtotime($this->notice->created),
114 strtotime($this->profile->modified),
121 * @return string title of the page
126 return sprintf(_('%1$s\'s status on %2$s'),
127 $this->profile->nickname,
128 common_exact_date($this->notice->created));
133 * Load attributes based on database arguments
135 * Loads all the DB stuff
137 * @param array $args $_REQUEST array
139 * @return success flag
142 function prepare($args)
144 parent::prepare($args);
146 $id = $this->arg('notice');
148 $this->notice = Notice::staticGet($id);
150 if (!$this->notice) {
151 $this->clientError(_('No such notice.'), 404);
157 // STOP if there are no attachments
158 // maybe even redirect if there's a single one
160 $this->clientError(_('No such attachment.'), 404);
168 $this->profile = $this->notice->getProfile();
170 if (!$this->profile) {
171 $this->serverError(_('Notice has no profile'), 500);
175 $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
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 == 0) {
196 if (!empty($this->notice->url)) {
197 common_redirect($this->notice->url, 301);
198 } else if (!empty($this->notice->uri) && preg_match('/^https?:/', $this->notice->uri)) {
199 common_redirect($this->notice->uri, 301);
202 $f2p = new File_to_post;
203 $f2p->post_id = $this->notice->id;
205 $file->joinAdd($f2p);
207 $file->selectAdd('file.id as id');
208 $count = $file->find(true);
211 common_redirect(common_local_url('attachment', array('attachment' => $file->id)), 301);
219 * Don't show local navigation
224 function showLocalNavBlock()
229 * Fill the content area of the page
231 * Shows a single notice list item.
236 function showContent()
238 $al = new AttachmentList($this->notice, $this);
243 * Don't show page notice
248 function showPageNoticeBlock()
258 function showAside() {
262 * Extra <head> content
264 * We show the microid(s) for the author, if any.
271 $user = User::staticGet($this->profile->id);
277 if ($user->emailmicroid && $user->email && $this->notice->uri) {
278 $id = new Microid('mailto:'. $user->email,
280 $this->element('meta', array('name' => 'microid',
281 'content' => $id->toString()));
284 if ($user->jabbermicroid && $user->jabber && $this->notice->uri) {
285 $id = new Microid('xmpp:', $user->jabber,
287 $this->element('meta', array('name' => 'microid',
288 'content' => $id->toString()));