]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/attachments.php
Merge branch '0.8.x' into stats
[quix0rs-gnu-social.git] / actions / attachments.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 AttachmentsAction extends Action
49 {
50     /**
51      * Notice object to show
52      */
53
54     var $notice = 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      * Is this action read-only?
70      *
71      * @return boolean true
72      */
73
74     function isReadOnly($args)
75     {
76         return true;
77     }
78
79     /**
80      * Last-modified date for page
81      *
82      * When was the content of this page last modified? Based on notice,
83      * profile, avatar.
84      *
85      * @return int last-modified date as unix timestamp
86      */
87
88     function lastModified()
89     {
90         return max(strtotime($this->notice->created),
91                    strtotime($this->profile->modified),
92                    ($this->avatar) ? strtotime($this->avatar->modified) : 0);
93     }
94
95     /**
96      * An entity tag for this page
97      *
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.
101      *
102      * @return string etag
103      */
104
105     function etag()
106     {
107         $avtime = ($this->avatar) ?
108           strtotime($this->avatar->modified) : 0;
109
110         return 'W/"' . implode(':', array($this->arg('action'),
111                                           common_language(),
112                                           $this->notice->id,
113                                           strtotime($this->notice->created),
114                                           strtotime($this->profile->modified),
115                                           $avtime)) . '"';
116     }
117
118     /**
119      * Title of the page
120      *
121      * @return string title of the page
122      */
123
124     function title()
125     {
126         return sprintf(_('%1$s\'s status on %2$s'),
127                        $this->profile->nickname,
128                        common_exact_date($this->notice->created));
129     }
130
131
132     /**
133      * Load attributes based on database arguments
134      *
135      * Loads all the DB stuff
136      *
137      * @param array $args $_REQUEST array
138      *
139      * @return success flag
140      */
141
142     function prepare($args)
143     {
144         parent::prepare($args);
145
146         $id = $this->arg('notice');
147
148         $this->notice = Notice::staticGet($id);
149
150         if (!$this->notice) {
151             $this->clientError(_('No such notice.'), 404);
152             return false;
153         }
154
155
156 /*
157 // STOP if there are no attachments
158 // maybe even redirect if there's a single one
159 // RYM FIXME TODO
160             $this->clientError(_('No such attachment.'), 404);
161             return false;
162
163 */
164
165
166
167
168         $this->profile = $this->notice->getProfile();
169
170         if (!$this->profile) {
171             $this->serverError(_('Notice has no profile'), 500);
172             return false;
173         }
174
175         $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
176         return true;
177     }
178
179
180
181     /**
182      * Handle input
183      *
184      * Only handles get, so just show the page.
185      *
186      * @param array $args $_REQUEST data (unused)
187      *
188      * @return void
189      */
190
191     function handle($args)
192     {
193         parent::handle($args);
194
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);
200             }
201         } else {
202             $f2p = new File_to_post;
203             $f2p->post_id = $this->notice->id;
204             $file = new File;
205             $file->joinAdd($f2p);
206             $file->selectAdd();
207             $file->selectAdd('file.id as id');
208             $count = $file->find(true);
209             if (!$count) return;
210             if (1 === $count) {
211                 common_redirect(common_local_url('attachment', array('attachment' => $file->id)), 301);
212             } else {
213                 $this->showPage();
214             }
215         }
216     }
217
218     /**
219      * Don't show local navigation
220      *
221      * @return void
222      */
223
224     function showLocalNavBlock()
225     {
226     }
227
228     /**
229      * Fill the content area of the page
230      *
231      * Shows a single notice list item.
232      *
233      * @return void
234      */
235
236     function showContent()
237     {
238         $al = new AttachmentList($this->notice, $this);
239         $cnt = $al->show();
240     }
241
242     /**
243      * Don't show page notice
244      *
245      * @return void
246      */
247
248     function showPageNoticeBlock()
249     {
250     }
251
252     /**
253      * Don't show aside
254      *
255      * @return void
256      */
257
258     function showAside() {
259     }
260
261     /**
262      * Extra <head> content
263      *
264      * We show the microid(s) for the author, if any.
265      *
266      * @return void
267      */
268
269     function extraHead()
270     {
271         $user = User::staticGet($this->profile->id);
272
273         if (!$user) {
274             return;
275         }
276
277         if ($user->emailmicroid && $user->email && $this->notice->uri) {
278             $id = new Microid('mailto:'. $user->email,
279                               $this->notice->uri);
280             $this->element('meta', array('name' => 'microid',
281                                          'content' => $id->toString()));
282         }
283
284         if ($user->jabbermicroid && $user->jabber && $this->notice->uri) {
285             $id = new Microid('xmpp:', $user->jabber,
286                               $this->notice->uri);
287             $this->element('meta', array('name' => 'microid',
288                                          'content' => $id->toString()));
289         }
290     }
291 }
292