]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/attachment.php
Attachments and their list now provide "ajax" view. Also added a few sidebars relatin...
[quix0rs-gnu-social.git] / actions / attachment.php
1 <?php
2 /**
3  * Laconica, the distributed open-source microblogging tool
4  *
5  * Show notice attachments
6  *
7  * PHP version 5
8  *
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  Personal
23  * @package   Laconica
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/
28  */
29
30 if (!defined('LACONICA')) {
31     exit(1);
32 }
33
34 //require_once INSTALLDIR.'/lib/personalgroupnav.php';
35 //require_once INSTALLDIR.'/lib/feedlist.php';
36 require_once INSTALLDIR.'/lib/attachmentlist.php';
37
38 /**
39  * Show notice attachments
40  *
41  * @category Personal
42  * @package  Laconica
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/
46  */
47
48 class AttachmentAction extends Action
49 {
50     /**
51      * Attachment object to show
52      */
53
54     var $attachment = null;
55
56     /**
57      * Profile of the notice object
58      */
59
60 //    var $profile = null;
61
62     /**
63      * Avatar of the profile of the notice object
64      */
65
66 //    var $avatar = null;
67
68     /**
69      * Load attributes based on database arguments
70      *
71      * Loads all the DB stuff
72      *
73      * @param array $args $_REQUEST array
74      *
75      * @return success flag
76      */
77
78     function prepare($args)
79     {
80         parent::prepare($args);
81
82         $id = $this->arg('attachment');
83
84         $this->attachment = File::staticGet($id);
85
86         if (!$this->attachment) {
87             $this->clientError(_('No such attachment.'), 404);
88             return false;
89         }
90         return true;
91     }
92
93     /**
94      * Is this action read-only?
95      *
96      * @return boolean true
97      */
98
99     function isReadOnly($args)
100     {
101         return true;
102     }
103
104     /**
105      * Title of the page
106      *
107      * @return string title of the page
108      */
109     function title()
110     {
111         $a = new Attachment($this->attachment);
112         return $a->title();
113     }
114
115
116
117     /**
118      * Last-modified date for page
119      *
120      * When was the content of this page last modified? Based on notice,
121      * profile, avatar.
122      *
123      * @return int last-modified date as unix timestamp
124      */
125 /*
126     function lastModified()
127     {
128         return max(strtotime($this->notice->created),
129                    strtotime($this->profile->modified),
130                    ($this->avatar) ? strtotime($this->avatar->modified) : 0);
131     }
132 */
133
134     /**
135      * An entity tag for this page
136      *
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.
140      *
141      * @return string etag
142      */
143 /*
144     function etag()
145     {
146         $avtime = ($this->avatar) ?
147           strtotime($this->avatar->modified) : 0;
148
149         return 'W/"' . implode(':', array($this->arg('action'),
150                                           common_language(),
151                                           $this->notice->id,
152                                           strtotime($this->notice->created),
153                                           strtotime($this->profile->modified),
154                                           $avtime)) . '"';
155     }
156 */
157
158
159     /**
160      * Handle input
161      *
162      * Only handles get, so just show the page.
163      *
164      * @param array $args $_REQUEST data (unused)
165      *
166      * @return void
167      */
168
169     function handle($args)
170     {
171         parent::handle($args);
172         $this->showPage();
173     }
174
175     /**
176      * Don't show local navigation
177      *
178      * @return void
179      */
180
181     function showLocalNavBlock()
182     {
183     }
184
185     /**
186      * Fill the content area of the page
187      *
188      * Shows a single notice list item.
189      *
190      * @return void
191      */
192
193     function showContent()
194     {
195         $this->elementStart('ul', array('class' => 'attachments'));
196         $ali = new Attachment($this->attachment, $this);
197         $cnt = $ali->show();
198         $this->elementEnd('ul');
199     }
200
201     /**
202      * Don't show page notice
203      *
204      * @return void
205      */
206
207     function showPageNoticeBlock()
208     {
209     }
210
211     /**
212      * Show aside: this attachments appears in what notices
213      *
214      * @return void
215      */
216
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');
230         }
231         $this->elementEnd('ol');
232         $notice->free();
233         $f2p->free();
234
235         $notice_tag = new Notice_tag;
236         $attachment = new File;
237
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';
239
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');
247         }
248         $this->elementEnd('ol');
249     }
250 }