1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
5 | // | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | branch : BSF (Best So Far) |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2006-01-27 02:11:43 +0100 (ven, 27 jan 2006) $ |
---|
10 | // | last modifier : $Author: rvelices $ |
---|
11 | // | revision : $Revision: 1014 $ |
---|
12 | // +-----------------------------------------------------------------------+ |
---|
13 | // | This program is free software; you can redistribute it and/or modify | |
---|
14 | // | it under the terms of the GNU General Public License as published by | |
---|
15 | // | the Free Software Foundation | |
---|
16 | // | | |
---|
17 | // | This program is distributed in the hope that it will be useful, but | |
---|
18 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
19 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
20 | // | General Public License for more details. | |
---|
21 | // | | |
---|
22 | // | You should have received a copy of the GNU General Public License | |
---|
23 | // | along with this program; if not, write to the Free Software | |
---|
24 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
25 | // | USA. | |
---|
26 | // +-----------------------------------------------------------------------+ |
---|
27 | |
---|
28 | /** |
---|
29 | * This included page checks section related parameter and provides |
---|
30 | * following informations: |
---|
31 | * |
---|
32 | * - $page['title'] |
---|
33 | * |
---|
34 | * - $page['items']: ordered list of items to display |
---|
35 | * |
---|
36 | * - $page['cat_nb_images']: number of items in the section (should be equal |
---|
37 | * to count($page['items'])) |
---|
38 | * |
---|
39 | * - $page['thumbnails_include']: include page managing thumbnails to |
---|
40 | * display |
---|
41 | */ |
---|
42 | |
---|
43 | // "index.php?/category/12-foo/start-24&action=fill_caddie" must return : |
---|
44 | // |
---|
45 | // array( |
---|
46 | // 'section' => 'categories', |
---|
47 | // 'category' => 12, |
---|
48 | // 'start' => 24 |
---|
49 | // 'action' => 'fill_caddie' |
---|
50 | // ); |
---|
51 | |
---|
52 | $page['section'] = 'categories'; |
---|
53 | |
---|
54 | foreach (array_keys($_GET) as $keynum => $key) |
---|
55 | { |
---|
56 | if (0 == $keynum) |
---|
57 | { |
---|
58 | // deleting first "/" if displayed |
---|
59 | $tokens = explode( |
---|
60 | '/', |
---|
61 | preg_replace('#^/#', '', $key) |
---|
62 | ); |
---|
63 | |
---|
64 | // $tokens = array( |
---|
65 | // 0 => category, |
---|
66 | // 1 => 12-foo, |
---|
67 | // 2 => start-24 |
---|
68 | // ); |
---|
69 | |
---|
70 | $next_token = 0; |
---|
71 | |
---|
72 | if (basename($_SERVER['PHP_SELF']) == 'picture.php') |
---|
73 | { |
---|
74 | // the first token must be the numeric identifier of the picture |
---|
75 | preg_match('/(\d+)/', $tokens[$next_token], $matches); |
---|
76 | if (!isset($matches[1])) |
---|
77 | { |
---|
78 | die('Fatal: picture identifier is missing'); |
---|
79 | } |
---|
80 | $page['image_id'] = $matches[1]; |
---|
81 | |
---|
82 | $next_token++; |
---|
83 | } |
---|
84 | |
---|
85 | if (0 === strpos($tokens[$next_token], 'cat')) |
---|
86 | { |
---|
87 | $page['section'] = 'categories'; |
---|
88 | $next_token++; |
---|
89 | |
---|
90 | if (isset($tokens[$next_token]) |
---|
91 | and preg_match('/(\d+)/', $tokens[$next_token], $matches)) |
---|
92 | { |
---|
93 | $page['category'] = $matches[1]; |
---|
94 | $next_token++; |
---|
95 | } |
---|
96 | } |
---|
97 | else if (0 === strpos($tokens[$next_token], 'tag')) |
---|
98 | { |
---|
99 | $page['section'] = 'tags'; |
---|
100 | $page['tags'] = array(); |
---|
101 | |
---|
102 | $next_token++; |
---|
103 | |
---|
104 | for ($i = $next_token; ; $i++) |
---|
105 | { |
---|
106 | if (!isset($tokens[$i])) |
---|
107 | { |
---|
108 | break; |
---|
109 | } |
---|
110 | |
---|
111 | preg_match('/^(\d+)/', $tokens[$i], $matches); |
---|
112 | if (!isset($matches[1])) |
---|
113 | { |
---|
114 | if (0 == count($page['tags'])) |
---|
115 | { |
---|
116 | die('Fatal: at least one tag required'); |
---|
117 | } |
---|
118 | else |
---|
119 | { |
---|
120 | break; |
---|
121 | } |
---|
122 | } |
---|
123 | array_push($page['tags'], $matches[1]); |
---|
124 | } |
---|
125 | |
---|
126 | $next_token = $i; |
---|
127 | } |
---|
128 | else if (0 === strpos($tokens[$next_token], 'fav')) |
---|
129 | { |
---|
130 | $page['section'] = 'favorites'; |
---|
131 | $next_token++; |
---|
132 | } |
---|
133 | else if ('most_visited' == $tokens[$next_token]) |
---|
134 | { |
---|
135 | $page['section'] = 'most_visited'; |
---|
136 | $next_token++; |
---|
137 | } |
---|
138 | else if ('best_rated' == $tokens[$next_token]) |
---|
139 | { |
---|
140 | $page['section'] = 'best_rated'; |
---|
141 | $next_token++; |
---|
142 | } |
---|
143 | else if ('recent_pics' == $tokens[$next_token]) |
---|
144 | { |
---|
145 | $page['section'] = 'recent_pics'; |
---|
146 | $next_token++; |
---|
147 | } |
---|
148 | else if ('recent_cats' == $tokens[$next_token]) |
---|
149 | { |
---|
150 | $page['section'] = 'recent_cats'; |
---|
151 | $next_token++; |
---|
152 | } |
---|
153 | else if ('search' == $tokens[$next_token]) |
---|
154 | { |
---|
155 | $page['section'] = 'search'; |
---|
156 | $next_token++; |
---|
157 | |
---|
158 | preg_match('/(\d+)/', $tokens[$next_token], $matches); |
---|
159 | if (!isset($matches[1])) |
---|
160 | { |
---|
161 | die('Fatal: search identifier is missing'); |
---|
162 | } |
---|
163 | $page['search'] = $matches[1]; |
---|
164 | $next_token++; |
---|
165 | } |
---|
166 | else if ('list' == $tokens[$next_token]) |
---|
167 | { |
---|
168 | $page['section'] = 'list'; |
---|
169 | $next_token++; |
---|
170 | |
---|
171 | $page['list'] = array(); |
---|
172 | if (!preg_match('/^\d+(,\d+)*$/', $tokens[$next_token])) |
---|
173 | { |
---|
174 | die('wrong format on list GET parameter'); |
---|
175 | } |
---|
176 | foreach (explode(',', $tokens[$next_token]) as $image_id) |
---|
177 | { |
---|
178 | array_push($page['list'], $image_id); |
---|
179 | } |
---|
180 | $next_token++; |
---|
181 | } |
---|
182 | else |
---|
183 | { |
---|
184 | $page['section'] = 'categories'; |
---|
185 | $next_token++; |
---|
186 | } |
---|
187 | |
---|
188 | for ($i = $next_token; ; $i++) |
---|
189 | { |
---|
190 | if (!isset($tokens[$i])) |
---|
191 | { |
---|
192 | break; |
---|
193 | } |
---|
194 | |
---|
195 | if (preg_match('/^start-(\d+)/', $tokens[$i], $matches)) |
---|
196 | { |
---|
197 | $page['start'] = $matches[1]; |
---|
198 | } |
---|
199 | |
---|
200 | if (preg_match('/^calendar-(.+)$/', $tokens[$i], $matches)) |
---|
201 | { |
---|
202 | // TODO: decide with rvelices how we name calendar/chronology is the |
---|
203 | // URL |
---|
204 | $_GET['calendar'] = $matches[1]; |
---|
205 | } |
---|
206 | } |
---|
207 | } |
---|
208 | } |
---|
209 | |
---|
210 | // $page['nb_image_page'] is the number of picture to display on this page |
---|
211 | // By default, it is the same as the $user['nb_image_page'] |
---|
212 | $page['nb_image_page'] = $user['nb_image_page']; |
---|
213 | |
---|
214 | if (isset($_COOKIE['pwg_image_order']) |
---|
215 | and is_numeric($_COOKIE['pwg_image_order']) |
---|
216 | and $_COOKIE['pwg_image_order'] > 0) |
---|
217 | { |
---|
218 | $orders = get_category_preferred_image_orders(); |
---|
219 | |
---|
220 | $conf['order_by'] = str_replace( |
---|
221 | 'ORDER BY ', |
---|
222 | 'ORDER BY '.$orders[ $_COOKIE['pwg_image_order'] ][1].',', |
---|
223 | $conf['order_by'] |
---|
224 | ); |
---|
225 | $page['super_order_by'] = true; |
---|
226 | } |
---|
227 | |
---|
228 | // +-----------------------------------------------------------------------+ |
---|
229 | // | category | |
---|
230 | // +-----------------------------------------------------------------------+ |
---|
231 | if ('categories' == $page['section']) |
---|
232 | { |
---|
233 | if (isset($page['category'])) |
---|
234 | { |
---|
235 | $result = get_cat_info($page['category']); |
---|
236 | |
---|
237 | $page = array_merge( |
---|
238 | $page, |
---|
239 | array( |
---|
240 | 'comment' => $result['comment'], |
---|
241 | 'cat_dir' => $result['dir'], |
---|
242 | 'cat_name' => $result['name'], |
---|
243 | 'cat_nb_images' => $result['nb_images'], |
---|
244 | 'cat_site_id' => $result['site_id'], |
---|
245 | 'cat_uploadable' => $result['uploadable'], |
---|
246 | 'cat_commentable' => $result['commentable'], |
---|
247 | 'cat_id_uppercat' => $result['id_uppercat'], |
---|
248 | 'uppercats' => $result['uppercats'], |
---|
249 | |
---|
250 | 'title' => get_cat_display_name($result['name'], '', false), |
---|
251 | ) |
---|
252 | ); |
---|
253 | |
---|
254 | if (!isset($_GET['calendar'])) |
---|
255 | { |
---|
256 | $query = ' |
---|
257 | SELECT image_id |
---|
258 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
259 | INNER JOIN '.IMAGES_TABLE.' ON id = image_id |
---|
260 | WHERE category_id = '.$page['category'].' |
---|
261 | '.$conf['order_by'].' |
---|
262 | ;'; |
---|
263 | $page['items'] = array_from_query($query, 'image_id'); |
---|
264 | |
---|
265 | $page['thumbnails_include'] = |
---|
266 | $result['nb_images'] > 0 |
---|
267 | ? 'include/category_default.inc.php' |
---|
268 | : 'include/category_subcats.inc.php'; |
---|
269 | } //otherwise the calendar will requery all subitems |
---|
270 | } |
---|
271 | else |
---|
272 | { |
---|
273 | $page['title'] = $lang['no_category']; |
---|
274 | $page['thumbnails_include'] = 'include/category_subcats.inc.php'; |
---|
275 | } |
---|
276 | } |
---|
277 | // special sections |
---|
278 | else |
---|
279 | { |
---|
280 | if (!empty($user['forbidden_categories'])) |
---|
281 | { |
---|
282 | $forbidden = |
---|
283 | ' category_id NOT IN ('.$user['forbidden_categories'].')'; |
---|
284 | } |
---|
285 | else |
---|
286 | { |
---|
287 | $forbidden = ' 1 = 1'; |
---|
288 | } |
---|
289 | // +-----------------------------------------------------------------------+ |
---|
290 | // | search section | |
---|
291 | // +-----------------------------------------------------------------------+ |
---|
292 | if ($page['section'] == 'search') |
---|
293 | { |
---|
294 | $query = ' |
---|
295 | SELECT DISTINCT(id) |
---|
296 | FROM '.IMAGES_TABLE.' |
---|
297 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id |
---|
298 | WHERE '.get_sql_search_clause($_GET['search']).' |
---|
299 | AND '.$forbidden.' |
---|
300 | '.$conf['order_by'].' |
---|
301 | ;'; |
---|
302 | |
---|
303 | $page = array_merge( |
---|
304 | $page, |
---|
305 | array( |
---|
306 | 'title' => $lang['search_result'], |
---|
307 | 'items' => array_from_query($query, 'id'), |
---|
308 | 'thumbnails_include' => 'include/category_default.inc.php', |
---|
309 | ) |
---|
310 | ); |
---|
311 | } |
---|
312 | // +-----------------------------------------------------------------------+ |
---|
313 | // | favorite section | |
---|
314 | // +-----------------------------------------------------------------------+ |
---|
315 | else if ($page['section'] == 'favorites') |
---|
316 | { |
---|
317 | check_user_favorites(); |
---|
318 | |
---|
319 | $query = ' |
---|
320 | SELECT image_id |
---|
321 | FROM '.FAVORITES_TABLE.' |
---|
322 | INNER JOIN '.IMAGES_TABLE.' ON image_id = id |
---|
323 | WHERE user_id = '.$user['id'].' |
---|
324 | '.$conf['order_by'].' |
---|
325 | ;'; |
---|
326 | |
---|
327 | $page = array_merge( |
---|
328 | $page, |
---|
329 | array( |
---|
330 | 'title' => $lang['favorites'], |
---|
331 | 'items' => array_from_query($query, 'image_id'), |
---|
332 | 'thumbnails_include' => 'include/category_default.inc.php', |
---|
333 | ) |
---|
334 | ); |
---|
335 | } |
---|
336 | // +-----------------------------------------------------------------------+ |
---|
337 | // | recent pictures section | |
---|
338 | // +-----------------------------------------------------------------------+ |
---|
339 | else if ($page['section'] == 'recent_pics') |
---|
340 | { |
---|
341 | $query = ' |
---|
342 | SELECT DISTINCT(id) |
---|
343 | FROM '.IMAGES_TABLE.' |
---|
344 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id |
---|
345 | WHERE date_available > \''. |
---|
346 | date('Y-m-d', time() - 60*60*24*$user['recent_period']).'\' |
---|
347 | AND '.$forbidden.' |
---|
348 | '.$conf['order_by'].' |
---|
349 | ;'; |
---|
350 | |
---|
351 | $page = array_merge( |
---|
352 | $page, |
---|
353 | array( |
---|
354 | 'title' => $lang['recent_pics_cat'], |
---|
355 | 'items' => array_from_query($query, 'id'), |
---|
356 | 'thumbnails_include' => 'include/category_default.inc.php', |
---|
357 | ) |
---|
358 | ); |
---|
359 | } |
---|
360 | // +-----------------------------------------------------------------------+ |
---|
361 | // | recently updated categories section | |
---|
362 | // +-----------------------------------------------------------------------+ |
---|
363 | else if ($page['section'] == 'recent_cats') |
---|
364 | { |
---|
365 | $page = array_merge( |
---|
366 | $page, |
---|
367 | array( |
---|
368 | 'title' => $lang['recent_cats_cat'], |
---|
369 | 'cat_nb_images' => 0, |
---|
370 | 'thumbnails_include' => 'include/category_recent_cats.inc.php', |
---|
371 | ) |
---|
372 | ); |
---|
373 | } |
---|
374 | // +-----------------------------------------------------------------------+ |
---|
375 | // | most visited section | |
---|
376 | // +-----------------------------------------------------------------------+ |
---|
377 | else if ($page['section'] == 'most_visited') |
---|
378 | { |
---|
379 | $page['super_order_by'] = true; |
---|
380 | $conf['order_by'] = ' ORDER BY hit DESC, file ASC'; |
---|
381 | $query = ' |
---|
382 | SELECT DISTINCT(id) |
---|
383 | FROM '.IMAGES_TABLE.' |
---|
384 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id |
---|
385 | WHERE hit > 0 |
---|
386 | AND '.$forbidden.' |
---|
387 | '.$conf['order_by'].' |
---|
388 | LIMIT 0, '.$conf['top_number'].' |
---|
389 | ;'; |
---|
390 | |
---|
391 | $page = array_merge( |
---|
392 | $page, |
---|
393 | array( |
---|
394 | 'title' => $conf['top_number'].' '.$lang['most_visited_cat'], |
---|
395 | 'items' => array_from_query($query, 'id'), |
---|
396 | 'thumbnails_include' => 'include/category_default.inc.php', |
---|
397 | ) |
---|
398 | ); |
---|
399 | } |
---|
400 | // +-----------------------------------------------------------------------+ |
---|
401 | // | best rated section | |
---|
402 | // +-----------------------------------------------------------------------+ |
---|
403 | else if ($page['section'] == 'best_rated') |
---|
404 | { |
---|
405 | $page['super_order_by'] = true; |
---|
406 | $conf['order_by'] = ' ORDER BY average_rate DESC, id ASC'; |
---|
407 | |
---|
408 | $query =' |
---|
409 | SELECT DISTINCT(id) |
---|
410 | FROM '.IMAGES_TABLE.' |
---|
411 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id |
---|
412 | WHERE average_rate IS NOT NULL |
---|
413 | AND '.$forbidden.' |
---|
414 | '.$conf['order_by'].' |
---|
415 | LIMIT 0, '.$conf['top_number'].' |
---|
416 | ;'; |
---|
417 | $page = array_merge( |
---|
418 | $page, |
---|
419 | array( |
---|
420 | 'title' => $conf['top_number'].' '.$lang['best_rated_cat'], |
---|
421 | 'items' => array_from_query($query, 'id'), |
---|
422 | 'thumbnails_include' => 'include/category_default.inc.php', |
---|
423 | ) |
---|
424 | ); |
---|
425 | } |
---|
426 | // +-----------------------------------------------------------------------+ |
---|
427 | // | list section | |
---|
428 | // +-----------------------------------------------------------------------+ |
---|
429 | else if ($page['section'] == 'list') |
---|
430 | { |
---|
431 | $query =' |
---|
432 | SELECT DISTINCT(id) |
---|
433 | FROM '.IMAGES_TABLE.' |
---|
434 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id |
---|
435 | WHERE image_id IN ('.implode(',', $page['list']).') |
---|
436 | AND '.$forbidden.' |
---|
437 | '.$conf['order_by'].' |
---|
438 | ;'; |
---|
439 | |
---|
440 | $page = array_merge( |
---|
441 | $page, |
---|
442 | array( |
---|
443 | 'title' => $lang['random_cat'], |
---|
444 | 'items' => array_from_query($query, 'id'), |
---|
445 | 'thumbnails_include' => 'include/category_default.inc.php', |
---|
446 | ) |
---|
447 | ); |
---|
448 | } |
---|
449 | |
---|
450 | if (!isset($page['cat_nb_images'])) |
---|
451 | { |
---|
452 | $page['cat_nb_images'] = count($page['items']); |
---|
453 | } |
---|
454 | } |
---|
455 | |
---|
456 | // +-----------------------------------------------------------------------+ |
---|
457 | // | chronology | |
---|
458 | // +-----------------------------------------------------------------------+ |
---|
459 | |
---|
460 | if (isset($_GET['calendar'])) |
---|
461 | { |
---|
462 | include_once( PHPWG_ROOT_PATH.'include/functions_calendar.inc.php' ); |
---|
463 | initialize_calendar(); |
---|
464 | } |
---|
465 | |
---|
466 | // echo '<pre>'; print_r($page); echo '</pre>'; |
---|
467 | |
---|
468 | |
---|
469 | ?> |
---|