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 AttachmentAction extends Action
51 * Attachment object to show
54 var $attachment = null;
57 * Profile of the notice object
60 // var $profile = null;
63 * Avatar of the profile of the notice object
66 // var $avatar = null;
69 * Load attributes based on database arguments
71 * Loads all the DB stuff
73 * @param array $args $_REQUEST array
75 * @return success flag
78 function prepare($args)
80 parent::prepare($args);
82 $id = $this->arg('attachment');
84 $this->attachment = File::staticGet($id);
86 if (!$this->attachment) {
87 $this->clientError(_('No such attachment.'), 404);
94 * Is this action read-only?
96 * @return boolean true
99 function isReadOnly($args)
107 * @return string title of the page
111 $a = new Attachment($this->attachment);
118 * Last-modified date for page
120 * When was the content of this page last modified? Based on notice,
123 * @return int last-modified date as unix timestamp
126 function lastModified()
128 return max(strtotime($this->notice->created),
129 strtotime($this->profile->modified),
130 ($this->avatar) ? strtotime($this->avatar->modified) : 0);
135 * An entity tag for this page
137 * Shows the ETag for the page, based on the notice ID and timestamps
138 * for the notice, profile, and avatar. It's weak, since we change
139 * the date text "one hour ago", etc.
141 * @return string etag
146 $avtime = ($this->avatar) ?
147 strtotime($this->avatar->modified) : 0;
149 return 'W/"' . implode(':', array($this->arg('action'),
152 strtotime($this->notice->created),
153 strtotime($this->profile->modified),
162 * Only handles get, so just show the page.
164 * @param array $args $_REQUEST data (unused)
169 function handle($args)
171 parent::handle($args);
176 * Don't show local navigation
181 function showLocalNavBlock()
186 * Fill the content area of the page
188 * Shows a single notice list item.
193 function showContent()
195 $this->elementStart('ul', array('class' => 'attachments'));
196 $ali = new Attachment($this->attachment, $this);
198 $this->elementEnd('ul');
202 * Don't show page notice
207 function showPageNoticeBlock()
212 * Show aside: this attachments appears in what notices
217 function showAside() {
218 $notice = new Notice;
219 $f2p = new File_to_post;
220 $f2p->file_id = $this->attachment->id;
221 $notice->joinAdd($f2p);
222 $notice->orderBy('created desc');
223 $x = $notice->find();
224 $this->elementStart('ol');
225 while($notice->fetch()) {
226 $this->elementStart('li');
227 $profile = $notice->getProfile();
228 $this->element('a', array('href' => $notice->uri), $profile->nickname . ' on ' . $notice->created);
229 $this->elementEnd('li');
231 $this->elementEnd('ol');
235 $notice_tag = new Notice_tag;
236 $attachment = new File;
238 $query = 'select tag,count(tag) as c from notice_tag join file_to_post on (notice_tag.notice_id=post_id) join notice on notice_id = notice.id where file_id=' . $notice_tag->escape($this->attachment->id) . ' group by tag order by c desc';
240 $notice_tag->query($query);
241 $this->elementStart('ol');
242 while($notice_tag->fetch()) {
243 $this->elementStart('li');
244 $href = common_local_url('tag', array('tag' => $notice_tag->tag));
245 $this->element('a', array('href' => $href), $notice_tag->tag . ' (' . $notice_tag->c . ')');
246 $this->elementEnd('li');
248 $this->elementEnd('ol');