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 | switch ($page['sub_section']) |
---|
9 | { |
---|
10 | /* list */ |
---|
11 | case 'list': |
---|
12 | { |
---|
13 | // security |
---|
14 | if (is_a_guest()) access_denied(); |
---|
15 | |
---|
16 | $template->set_filename('index', dirname(__FILE__) . '/../template/list.tpl'); |
---|
17 | |
---|
18 | // actions |
---|
19 | if ( isset($_GET['action']) and filter_var($_GET['col_id'], FILTER_VALIDATE_INT) !== false ) |
---|
20 | { |
---|
21 | switch ($_GET['action']) |
---|
22 | { |
---|
23 | // new |
---|
24 | case 'new': |
---|
25 | { |
---|
26 | new UserCollection('new', array(), empty($_GET['name']) ? 'temp' : $_GET['name'], 1); |
---|
27 | redirect(USER_COLLEC_PUBLIC); |
---|
28 | break; |
---|
29 | } |
---|
30 | |
---|
31 | // clear |
---|
32 | case 'clear': |
---|
33 | { |
---|
34 | $query = ' |
---|
35 | DELETE ci |
---|
36 | FROM '.COLLECTION_IMAGES_TABLE.' AS ci |
---|
37 | INNER JOIN '.COLLECTIONS_TABLE.' AS c |
---|
38 | ON ci.col_id = c.id |
---|
39 | WHERE |
---|
40 | c.user_id = '.$user['id'].' |
---|
41 | AND c.id = '.$_GET['col_id'].' |
---|
42 | ;'; |
---|
43 | pwg_query($query); |
---|
44 | |
---|
45 | if (!empty($_SERVER['HTTP_REFERER'])) |
---|
46 | { |
---|
47 | redirect($_SERVER['HTTP_REFERER']); |
---|
48 | } |
---|
49 | break; |
---|
50 | } |
---|
51 | |
---|
52 | // delete |
---|
53 | case 'delete': |
---|
54 | { |
---|
55 | $query = ' |
---|
56 | DELETE ci, c |
---|
57 | FROM '.COLLECTION_IMAGES_TABLE.' AS ci |
---|
58 | RIGHT JOIN '.COLLECTIONS_TABLE.' AS c |
---|
59 | ON ci.col_id = c.id |
---|
60 | WHERE |
---|
61 | c.user_id = '.$user['id'].' |
---|
62 | AND c.id = '.$_GET['col_id'].' |
---|
63 | ;'; |
---|
64 | pwg_query($query); |
---|
65 | |
---|
66 | redirect(USER_COLLEC_PUBLIC); |
---|
67 | break; |
---|
68 | } |
---|
69 | |
---|
70 | // save |
---|
71 | case 'save': |
---|
72 | { |
---|
73 | if (empty($_GET['name'])) |
---|
74 | { |
---|
75 | array_push($page['errors'], l10n('Please give a name')); |
---|
76 | } |
---|
77 | else |
---|
78 | { |
---|
79 | $query = ' |
---|
80 | UPDATE '.COLLECTIONS_TABLE.' |
---|
81 | SET |
---|
82 | name = "'.pwg_db_real_escape_string($_GET['name']).'", |
---|
83 | active = 0 |
---|
84 | WHERE |
---|
85 | user_id = '.$user['id'].' |
---|
86 | AND id = '.$_GET['col_id'].' |
---|
87 | ;'; |
---|
88 | pwg_query($query); |
---|
89 | |
---|
90 | redirect(USER_COLLEC_PUBLIC); |
---|
91 | } |
---|
92 | break; |
---|
93 | } |
---|
94 | |
---|
95 | // set active |
---|
96 | case 'set_active': |
---|
97 | { |
---|
98 | $query = ' |
---|
99 | UPDATE '.COLLECTIONS_TABLE.' |
---|
100 | SET active = 0 |
---|
101 | WHERE user_id = '.$user['id'].' |
---|
102 | ;'; |
---|
103 | pwg_query($query); |
---|
104 | |
---|
105 | $query = ' |
---|
106 | UPDATE '.COLLECTIONS_TABLE.' |
---|
107 | SET active = 1 |
---|
108 | WHERE |
---|
109 | user_id = '.$user['id'].' |
---|
110 | AND id = '.$_GET['col_id'].' |
---|
111 | ;'; |
---|
112 | pwg_query($query); |
---|
113 | |
---|
114 | redirect(USER_COLLEC_PUBLIC); |
---|
115 | break; |
---|
116 | } |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | // get collections |
---|
122 | $query = ' |
---|
123 | SELECT * |
---|
124 | FROM '.COLLECTIONS_TABLE.' |
---|
125 | WHERE user_id = '.$user['id'].' |
---|
126 | ORDER BY date_creation DESC |
---|
127 | '; |
---|
128 | $collections = hash_from_query($query, 'id'); |
---|
129 | |
---|
130 | foreach ($collections as $col) |
---|
131 | { |
---|
132 | $col['date_creation'] = format_date($col['date_creation'], true); |
---|
133 | $col['U_EDIT'] = USER_COLLEC_PUBLIC.'edit/'.$col['id']; |
---|
134 | $col['U_ACTIVE'] = USER_COLLEC_PUBLIC.'&action=set_active&col_id='.$col['id']; |
---|
135 | $col['U_DELETE'] = USER_COLLEC_PUBLIC.'&action=delete&col_id='.$col['id']; |
---|
136 | |
---|
137 | if (isset($pwg_loaded_plugins['BatchDownloader'])) |
---|
138 | { |
---|
139 | $col['U_DOWNLOAD'] = USER_COLLEC_PUBLIC.'view/'.$col['public_id'].'&action=advdown_set'; |
---|
140 | } |
---|
141 | |
---|
142 | // temporary collections are above save collections |
---|
143 | if ($col['name'] == 'temp') |
---|
144 | { |
---|
145 | $col['name'] = 'temp #'.$col['id']; |
---|
146 | $col['U_SAVE'] = USER_COLLEC_PUBLIC.'&action=save&col_id='.$col['id']; |
---|
147 | $template->append('temp_col', $col); |
---|
148 | } |
---|
149 | else |
---|
150 | { |
---|
151 | $template->append('collections', $col); |
---|
152 | } |
---|
153 | } |
---|
154 | |
---|
155 | $template->assign('U_CREATE', USER_COLLEC_PUBLIC.'&action=new&col_id=0'); |
---|
156 | break; |
---|
157 | } |
---|
158 | |
---|
159 | /* edit */ |
---|
160 | case 'edit': |
---|
161 | { |
---|
162 | // security |
---|
163 | if (empty($page['col_id'])) |
---|
164 | { |
---|
165 | $_SESSION['page_errors'][] = l10n('Invalid collection'); |
---|
166 | redirect(USER_COLLEC_PUBLIC); |
---|
167 | } |
---|
168 | |
---|
169 | $template->set_filename('index', dirname(__FILE__).'/../template/edit.tpl'); |
---|
170 | |
---|
171 | $self_url = USER_COLLEC_PUBLIC . 'edit/'.$page['col_id']; |
---|
172 | $template->assign(array( |
---|
173 | 'USER_COLLEC_PATH' => USER_COLLEC_PATH, |
---|
174 | 'F_ACTION' => $self_url, |
---|
175 | 'collection_toggle_url' => $self_url, |
---|
176 | 'U_LIST' => USER_COLLEC_PUBLIC, |
---|
177 | 'COL_ID' => $page['col_id'], |
---|
178 | )); |
---|
179 | |
---|
180 | try { |
---|
181 | $UserCollection = new UserCollection($page['col_id']); |
---|
182 | |
---|
183 | // security |
---|
184 | if ( !is_admin() and $UserCollection->getParam('user_id') != $user['id'] ) |
---|
185 | { |
---|
186 | access_denied(); |
---|
187 | } |
---|
188 | |
---|
189 | // save properties |
---|
190 | if (isset($_POST['save_col'])) |
---|
191 | { |
---|
192 | $UserCollection->updateParam('name', $_POST['name']); |
---|
193 | $UserCollection->updateParam('public', $_POST['public']); |
---|
194 | } |
---|
195 | |
---|
196 | // remove an element |
---|
197 | if ( isset($_GET['collection_toggle']) and preg_match('#^[0-9]+$#', $_GET['collection_toggle']) ) |
---|
198 | { |
---|
199 | $UserCollection->removeImages(array($_GET['collection_toggle'])); |
---|
200 | } |
---|
201 | |
---|
202 | // special template |
---|
203 | add_event_handler('loc_end_index_thumbnails', 'user_collections_thumbnails_in_collection', EVENT_HANDLER_PRIORITY_NEUTRAL+10, 2); // +10 to overload GThumb+ |
---|
204 | $template->set_prefilter('index_thumbnails', 'user_collections_thumbnails_list_prefilter'); |
---|
205 | |
---|
206 | // collection content |
---|
207 | $template->assign('collection', $UserCollection->getCollectionInfo()); |
---|
208 | $page['items'] = $UserCollection->getImages(); |
---|
209 | |
---|
210 | // navigation bar |
---|
211 | $page['start'] = isset($_GET['start']) ? $_GET['start'] : 0; |
---|
212 | if (count($page['items']) > $page['nb_image_page']) |
---|
213 | { |
---|
214 | $page['navigation_bar'] = create_navigation_bar( |
---|
215 | $self_url, |
---|
216 | count($page['items']), |
---|
217 | $page['start'], |
---|
218 | $page['nb_image_page'], |
---|
219 | false |
---|
220 | ); |
---|
221 | $template->assign('navbar', $page['navigation_bar']); |
---|
222 | } |
---|
223 | |
---|
224 | // display |
---|
225 | include(PHPWG_ROOT_PATH . 'include/category_default.inc.php'); |
---|
226 | |
---|
227 | $template->concat('TITLE', $conf['level_separator'].$UserCollection->getParam('name')); |
---|
228 | } |
---|
229 | catch (Exception $e) |
---|
230 | { |
---|
231 | array_push($page['errors'], $e->getMessage()); |
---|
232 | } |
---|
233 | |
---|
234 | break; |
---|
235 | } |
---|
236 | |
---|
237 | /* view */ |
---|
238 | case 'view': |
---|
239 | { |
---|
240 | // security |
---|
241 | if ( empty($page['col_id']) or strlen($page['col_id']) != 10 or strpos($page['col_id'], 'uc') === false ) |
---|
242 | { |
---|
243 | $_SESSION['page_errors'][] = l10n('Invalid collection'); |
---|
244 | redirect('index.php'); |
---|
245 | } |
---|
246 | |
---|
247 | $template->set_filename('index', dirname(__FILE__).'/../template/view.tpl'); |
---|
248 | |
---|
249 | $self_url = USER_COLLEC_PUBLIC . 'view/'.$page['col_id']; |
---|
250 | |
---|
251 | try { |
---|
252 | $UserCollection = new UserCollection($page['col_id']); |
---|
253 | |
---|
254 | // backlink for owner |
---|
255 | if ($UserCollection->getParam('user_id') == $user['id']) |
---|
256 | { |
---|
257 | $template->assign('U_LIST', USER_COLLEC_PUBLIC); |
---|
258 | } |
---|
259 | |
---|
260 | // special template |
---|
261 | add_event_handler('loc_end_index_thumbnails', 'user_collections_thumbnails_in_collection', EVENT_HANDLER_PRIORITY_NEUTRAL+10, 2); // +10 to overload GThumb+ |
---|
262 | |
---|
263 | // collection content |
---|
264 | $template->assign('collection', $UserCollection->getCollectionInfo()); |
---|
265 | $page['items'] = $UserCollection->getImages(); |
---|
266 | |
---|
267 | // navigation bar |
---|
268 | $page['start'] = isset($_GET['start']) ? $_GET['start'] : 0; |
---|
269 | if (count($page['items']) > $page['nb_image_page']) |
---|
270 | { |
---|
271 | $page['navigation_bar'] = create_navigation_bar( |
---|
272 | $self_url, |
---|
273 | count($page['items']), |
---|
274 | $page['start'], |
---|
275 | $page['nb_image_page'], |
---|
276 | false |
---|
277 | ); |
---|
278 | $template->assign('navbar', $page['navigation_bar']); |
---|
279 | } |
---|
280 | |
---|
281 | // display |
---|
282 | include(PHPWG_ROOT_PATH . 'include/category_default.inc.php'); |
---|
283 | |
---|
284 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
285 | $template->concat('TITLE', |
---|
286 | $conf['level_separator'].$UserCollection->getParam('name'). |
---|
287 | ' ('.sprintf(l10n('by %s'), get_username($UserCollection->getParam('user_id'))).')' |
---|
288 | ); |
---|
289 | } |
---|
290 | catch (Exception $e) |
---|
291 | { |
---|
292 | access_denied(); |
---|
293 | } |
---|
294 | |
---|
295 | break; |
---|
296 | } |
---|
297 | } |
---|
298 | |
---|
299 | $template->assign('USER_COLLEC_PATH', USER_COLLEC_PATH); |
---|
300 | |
---|
301 | |
---|
302 | function user_collections_thumbnails_in_collection($tpl_thumbnails_var, $pictures) |
---|
303 | { |
---|
304 | global $template, $page; |
---|
305 | |
---|
306 | $template->set_filename('index_thumbnails', dirname(__FILE__).'/../template/thumbnails.tpl'); |
---|
307 | |
---|
308 | foreach ($tpl_thumbnails_var as &$thumbnail) |
---|
309 | { |
---|
310 | $src_image = new SrcImage($thumbnail); |
---|
311 | |
---|
312 | $thumbnail['FILE_SRC'] = DerivativeImage::url(IMG_LARGE, $src_image); |
---|
313 | $thumbnail['URL'] = duplicate_picture_url( |
---|
314 | array( |
---|
315 | 'image_id' => $thumbnail['id'], |
---|
316 | 'image_file' => $thumbnail['file'], |
---|
317 | 'section' => 'none', |
---|
318 | ), |
---|
319 | array('start') |
---|
320 | ); |
---|
321 | } |
---|
322 | |
---|
323 | return $tpl_thumbnails_var; |
---|
324 | } |
---|
325 | |
---|
326 | ?> |
---|