1 | <?php |
---|
2 | defined('USER_COLLEC_PATH') or die('Hacking attempt!'); |
---|
3 | |
---|
4 | # this file is called on basket public page # |
---|
5 | |
---|
6 | global $page, $template, $conf, $user, $tokens, $pwg_loaded_plugins; |
---|
7 | |
---|
8 | $template->assign(array( |
---|
9 | 'USER_COLLEC_PATH' => USER_COLLEC_PATH, |
---|
10 | 'USER_COLLEC_ABS_PATH' => realpath(USER_COLLEC_PATH).'/', |
---|
11 | )); |
---|
12 | |
---|
13 | switch ($page['sub_section']) |
---|
14 | { |
---|
15 | /* list */ |
---|
16 | case 'list': |
---|
17 | { |
---|
18 | // security |
---|
19 | if (is_a_guest()) access_denied(); |
---|
20 | |
---|
21 | $template->set_filename('index', dirname(__FILE__) . '/../template/list.tpl'); |
---|
22 | |
---|
23 | // actions |
---|
24 | if ( isset($_GET['action']) and preg_match('#^([0-9]+)$#', $_GET['col_id']) ) |
---|
25 | { |
---|
26 | switch ($_GET['action']) |
---|
27 | { |
---|
28 | // new |
---|
29 | case 'new': |
---|
30 | { |
---|
31 | $UserCollection = new UserCollection('new', array(), empty($_GET['name']) ? 'temp' : $_GET['name'], 1); |
---|
32 | |
---|
33 | if (isset($_GET['redirect'])) |
---|
34 | { |
---|
35 | $redirect = USER_COLLEC_PUBLIC.'edit/'.$UserCollection->getParam('id'); |
---|
36 | } |
---|
37 | else |
---|
38 | { |
---|
39 | $redirect = USER_COLLEC_PUBLIC; |
---|
40 | } |
---|
41 | redirect($redirect); |
---|
42 | break; |
---|
43 | } |
---|
44 | |
---|
45 | // delete |
---|
46 | case 'delete': |
---|
47 | { |
---|
48 | $query = ' |
---|
49 | DELETE ci, c |
---|
50 | FROM '.COLLECTION_IMAGES_TABLE.' AS ci |
---|
51 | RIGHT JOIN '.COLLECTIONS_TABLE.' AS c |
---|
52 | ON ci.col_id = c.id |
---|
53 | WHERE |
---|
54 | c.user_id = '.$user['id'].' |
---|
55 | AND c.id = '.$_GET['col_id'].' |
---|
56 | ;'; |
---|
57 | pwg_query($query); |
---|
58 | |
---|
59 | redirect(USER_COLLEC_PUBLIC); |
---|
60 | break; |
---|
61 | } |
---|
62 | |
---|
63 | // save |
---|
64 | case 'save': |
---|
65 | { |
---|
66 | if (empty($_GET['name'])) |
---|
67 | { |
---|
68 | array_push($page['errors'], l10n('Please give a name')); |
---|
69 | } |
---|
70 | else |
---|
71 | { |
---|
72 | $query = ' |
---|
73 | UPDATE '.COLLECTIONS_TABLE.' |
---|
74 | SET |
---|
75 | name = "'.pwg_db_real_escape_string($_GET['name']).'", |
---|
76 | active = 0 |
---|
77 | WHERE |
---|
78 | user_id = '.$user['id'].' |
---|
79 | AND id = '.$_GET['col_id'].' |
---|
80 | ;'; |
---|
81 | pwg_query($query); |
---|
82 | |
---|
83 | redirect(USER_COLLEC_PUBLIC); |
---|
84 | } |
---|
85 | break; |
---|
86 | } |
---|
87 | |
---|
88 | // set active |
---|
89 | case 'set_active': |
---|
90 | { |
---|
91 | $query = ' |
---|
92 | UPDATE '.COLLECTIONS_TABLE.' |
---|
93 | SET active = 0 |
---|
94 | WHERE user_id = '.$user['id'].' |
---|
95 | ;'; |
---|
96 | pwg_query($query); |
---|
97 | |
---|
98 | $query = ' |
---|
99 | UPDATE '.COLLECTIONS_TABLE.' |
---|
100 | SET active = 1 |
---|
101 | WHERE |
---|
102 | user_id = '.$user['id'].' |
---|
103 | AND id = '.$_GET['col_id'].' |
---|
104 | ;'; |
---|
105 | pwg_query($query); |
---|
106 | |
---|
107 | redirect(USER_COLLEC_PUBLIC); |
---|
108 | break; |
---|
109 | } |
---|
110 | } |
---|
111 | } |
---|
112 | |
---|
113 | |
---|
114 | // get collections |
---|
115 | $query = ' |
---|
116 | SELECT * |
---|
117 | FROM '.COLLECTIONS_TABLE.' |
---|
118 | WHERE user_id = '.$user['id'].' |
---|
119 | ORDER BY date_creation DESC |
---|
120 | '; |
---|
121 | $collections = hash_from_query($query, 'id'); |
---|
122 | |
---|
123 | foreach ($collections as $col) |
---|
124 | { |
---|
125 | $col['date_creation'] = format_date($col['date_creation'], true); |
---|
126 | $col['U_EDIT'] = USER_COLLEC_PUBLIC.'edit/'.$col['id']; |
---|
127 | $col['U_ACTIVE'] = add_url_params(USER_COLLEC_PUBLIC, array('action'=>'set_active','col_id'=>$col['id'])); |
---|
128 | $col['U_DELETE'] = add_url_params(USER_COLLEC_PUBLIC, array('action'=>'delete','col_id'=>$col['id'])); |
---|
129 | |
---|
130 | if (isset($pwg_loaded_plugins['BatchDownloader'])) |
---|
131 | { |
---|
132 | $col['U_DOWNLOAD'] = add_url_params(USER_COLLEC_PUBLIC.'view/'.$col['public_id'], array('action'=>'advdown_set')); |
---|
133 | } |
---|
134 | |
---|
135 | // temporary collections are above save collections |
---|
136 | if ($col['name'] == 'temp') |
---|
137 | { |
---|
138 | $col['name'] = 'temp #'.$col['id']; |
---|
139 | $col['U_SAVE'] = add_url_params(USER_COLLEC_PUBLIC, array('action'=>'save','col_id'=>$col['id'])); |
---|
140 | $template->append('temp_col', $col); |
---|
141 | } |
---|
142 | else |
---|
143 | { |
---|
144 | $template->append('collections', $col); |
---|
145 | } |
---|
146 | } |
---|
147 | |
---|
148 | $template->assign('U_CREATE', add_url_params(USER_COLLEC_PUBLIC, array('action'=>'new','col_id'=>'0'))); |
---|
149 | break; |
---|
150 | } |
---|
151 | |
---|
152 | /* edit */ |
---|
153 | case 'edit': |
---|
154 | { |
---|
155 | // security |
---|
156 | if (empty($page['col_id'])) |
---|
157 | { |
---|
158 | $_SESSION['page_errors'][] = l10n('Invalid collection'); |
---|
159 | redirect(USER_COLLEC_PUBLIC); |
---|
160 | } |
---|
161 | |
---|
162 | $template->set_filename('index', dirname(__FILE__).'/../template/edit.tpl'); |
---|
163 | |
---|
164 | $self_url = USER_COLLEC_PUBLIC . 'edit/'.$page['col_id']; |
---|
165 | |
---|
166 | $template->assign(array( |
---|
167 | 'user_collections' => $conf['user_collections'], |
---|
168 | 'F_ACTION' => $self_url, |
---|
169 | 'collection_toggle_url' => $self_url, |
---|
170 | 'U_LIST' => USER_COLLEC_PUBLIC, |
---|
171 | 'AJAX_COL_ID' => $page['col_id'], |
---|
172 | 'UC_IN_EDIT' => true, |
---|
173 | )); |
---|
174 | |
---|
175 | try { |
---|
176 | $UserCollection = new UserCollection($page['col_id']); |
---|
177 | |
---|
178 | // security |
---|
179 | if ( !is_admin() and $UserCollection->getParam('user_id') != $user['id'] ) |
---|
180 | { |
---|
181 | access_denied(); |
---|
182 | } |
---|
183 | |
---|
184 | // save properties |
---|
185 | if (isset($_POST['save_col'])) |
---|
186 | { |
---|
187 | if (empty($_POST['name'])) |
---|
188 | { |
---|
189 | array_push($page['errors'], l10n('Please give a name')); |
---|
190 | } |
---|
191 | else |
---|
192 | { |
---|
193 | $UserCollection->updateParam('name', stripslashes($_POST['name'])); |
---|
194 | } |
---|
195 | if (!$conf['user_collections']['allow_public']) |
---|
196 | { |
---|
197 | $_POST['public'] = '0'; |
---|
198 | } |
---|
199 | $UserCollection->updateParam('public', $_POST['public']); |
---|
200 | } |
---|
201 | |
---|
202 | // send mail |
---|
203 | if ( $conf['user_collections']['allow_public'] and $conf['user_collections']['allow_mails'] ) |
---|
204 | { |
---|
205 | $contact = array( |
---|
206 | 'sender_name' => $user['username'], |
---|
207 | 'sender_email' => $user['email'], |
---|
208 | 'recipient_name' => null, |
---|
209 | 'recipient_email' => null, |
---|
210 | 'nb_images' => 4, |
---|
211 | 'message' => null, |
---|
212 | ); |
---|
213 | |
---|
214 | if ( isset($_POST['send_mail']) and (bool)$UserCollection->getParam('public') ) |
---|
215 | { |
---|
216 | $contact = array( |
---|
217 | 'sender_email' => trim($_POST['sender_email']), |
---|
218 | 'sender_name' => trim($_POST['sender_name']), |
---|
219 | 'recipient_email' => trim($_POST['recipient_email']), |
---|
220 | 'recipient_name' => trim($_POST['recipient_name']), |
---|
221 | 'nb_images' => $_POST['nb_images'], |
---|
222 | 'message' => $_POST['message'], |
---|
223 | ); |
---|
224 | |
---|
225 | $errors = $UserCollection->sendEmail($contact, @$_POST['key']); |
---|
226 | if (count($errors)) |
---|
227 | { |
---|
228 | $template->assign('uc_mail_errors', $errors); |
---|
229 | } |
---|
230 | else |
---|
231 | { |
---|
232 | array_push($page['infos'], l10n('E-mail sent successfully')); |
---|
233 | } |
---|
234 | } |
---|
235 | |
---|
236 | $contact['KEY'] = get_ephemeral_key(3); |
---|
237 | $template->assign('contact', $contact); |
---|
238 | } |
---|
239 | |
---|
240 | // clear |
---|
241 | if ( isset($_GET['action']) and $_GET['action'] == 'clear' ) |
---|
242 | { |
---|
243 | $UserCollection->clearImages(); |
---|
244 | } |
---|
245 | |
---|
246 | // remove an element |
---|
247 | if ( isset($_GET['collection_toggle']) and preg_match('#^[0-9]+$#', $_GET['collection_toggle']) ) |
---|
248 | { |
---|
249 | $UserCollection->removeImages(array($_GET['collection_toggle'])); |
---|
250 | unset($_GET['collection_toggle']); |
---|
251 | } |
---|
252 | |
---|
253 | // add remove item links |
---|
254 | $template->set_prefilter('index_thumbnails', 'user_collections_thumbnails_list_prefilter'); |
---|
255 | |
---|
256 | // thumbnails |
---|
257 | include(USER_COLLEC_PATH . '/include/display_thumbnails.inc.php'); |
---|
258 | |
---|
259 | |
---|
260 | // collection properties |
---|
261 | $col = $UserCollection->getCollectionInfo(); |
---|
262 | $col['DATE_CREATION'] = format_date($col['DATE_CREATION'], true); |
---|
263 | $template->assign('collection', $col); |
---|
264 | |
---|
265 | // toolbar buttons |
---|
266 | if (!empty($page['items'])) |
---|
267 | { |
---|
268 | $template->assign('U_CLEAR', |
---|
269 | add_url_params($self_url, array('action'=>'clear') ) |
---|
270 | ); |
---|
271 | } |
---|
272 | $template->assign('U_DELETE', |
---|
273 | add_url_params(USER_COLLEC_PUBLIC, array('action'=>'delete','col_id'=>$page['col_id'])) |
---|
274 | ); |
---|
275 | if ($conf['user_collections']['allow_public'] and $conf['user_collections']['allow_mails']) |
---|
276 | { |
---|
277 | $template->assign('U_MAIL', true); |
---|
278 | } |
---|
279 | |
---|
280 | |
---|
281 | $template->concat('TITLE', |
---|
282 | $conf['level_separator'].$UserCollection->getParam('name') |
---|
283 | ); |
---|
284 | } |
---|
285 | catch (Exception $e) |
---|
286 | { |
---|
287 | array_push($page['errors'], $e->getMessage()); |
---|
288 | } |
---|
289 | |
---|
290 | break; |
---|
291 | } |
---|
292 | |
---|
293 | /* view */ |
---|
294 | case 'view': |
---|
295 | { |
---|
296 | // security |
---|
297 | if ( empty($page['col_id']) or strlen($page['col_id']) != 10 or strpos($page['col_id'], 'uc') === false or !$conf['user_collections']['allow_public'] ) |
---|
298 | { |
---|
299 | $_SESSION['page_errors'][] = l10n('Invalid collection'); |
---|
300 | redirect('index.php'); |
---|
301 | } |
---|
302 | |
---|
303 | $template->set_filename('index', dirname(__FILE__).'/../template/view.tpl'); |
---|
304 | |
---|
305 | $self_url = USER_COLLEC_PUBLIC . 'view/'.$page['col_id']; |
---|
306 | |
---|
307 | try { |
---|
308 | $UserCollection = new UserCollection($page['col_id']); |
---|
309 | $page['col_id'] = $UserCollection->getParam('id'); |
---|
310 | |
---|
311 | // thumbnails |
---|
312 | include(USER_COLLEC_PATH . '/include/display_thumbnails.inc.php'); |
---|
313 | |
---|
314 | // add username in title |
---|
315 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
316 | $template->concat('TITLE', |
---|
317 | $conf['level_separator'].$UserCollection->getParam('name'). |
---|
318 | ' ('.sprintf(l10n('by %s'), get_username($UserCollection->getParam('user_id'))).')' |
---|
319 | ); |
---|
320 | } |
---|
321 | catch (Exception $e) |
---|
322 | { |
---|
323 | access_denied(); |
---|
324 | } |
---|
325 | |
---|
326 | break; |
---|
327 | } |
---|
328 | } |
---|
329 | |
---|
330 | |
---|
331 | function user_collections_thumbnails_in_collection($tpl_thumbnails_var, $pictures) |
---|
332 | { |
---|
333 | global $template, $page; |
---|
334 | |
---|
335 | $url = USER_COLLEC_PUBLIC . 'edit/'.$page['col_id']; |
---|
336 | |
---|
337 | foreach ($tpl_thumbnails_var as &$thumbnail) |
---|
338 | { |
---|
339 | $src_image = new SrcImage($thumbnail); |
---|
340 | |
---|
341 | $thumbnail['FILE_SRC'] = DerivativeImage::url(IMG_LARGE, $src_image); |
---|
342 | $thumbnail['URL'] = duplicate_picture_url( |
---|
343 | array( |
---|
344 | 'image_id' => $thumbnail['id'], |
---|
345 | 'image_file' => $thumbnail['file'], |
---|
346 | 'section' => 'none', |
---|
347 | ), |
---|
348 | array('start') |
---|
349 | ); |
---|
350 | |
---|
351 | $thumbnail['COLLECTION_SELECTED'] = true; |
---|
352 | $thumbnail['COLLECTION_TOGGLE_URL'] = add_url_params($url, array('collection_toggle'=>$thumbnail['id'])); |
---|
353 | } |
---|
354 | |
---|
355 | $template->set_prefilter('index_thumbnails', 'user_collections_add_colorbox'); |
---|
356 | |
---|
357 | return $tpl_thumbnails_var; |
---|
358 | } |
---|
359 | |
---|
360 | function user_collections_add_colorbox($content) |
---|
361 | { |
---|
362 | // add datas |
---|
363 | $search = '<a href="{$thumbnail.URL}"'; |
---|
364 | $replace = $search.' class="preview-box" data-src="{$thumbnail.FILE_SRC}" data-id="{$thumbnail.id}"'; |
---|
365 | |
---|
366 | // colorbox script |
---|
367 | $content.= file_get_contents(USER_COLLEC_PATH.'template/thumbnails_colorbox.tpl'); |
---|
368 | |
---|
369 | return str_replace($search, $replace, $content); |
---|
370 | } |
---|
371 | |
---|
372 | ?> |
---|