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-2007 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | branch : BSF (Best So Far) |
---|
8 | // | file : $Id: section_init.inc.php 1722 2007-01-15 00:09:14Z rub $ |
---|
9 | // | last update : $Date: 2007-01-15 00:09:14 +0000 (Mon, 15 Jan 2007) $ |
---|
10 | // | last modifier : $Author: rub $ |
---|
11 | // | revision : $Revision: 1722 $ |
---|
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" or |
---|
44 | // "index.php/category/12-foo/start-24&action=fill_caddie" |
---|
45 | // must return : |
---|
46 | // |
---|
47 | // array( |
---|
48 | // 'section' => 'categories', |
---|
49 | // 'category' => 12, |
---|
50 | // 'start' => 24 |
---|
51 | // 'action' => 'fill_caddie' |
---|
52 | // ); |
---|
53 | |
---|
54 | $page['section'] = 'categories'; |
---|
55 | |
---|
56 | // some ISPs set PATH_INFO to empty string or to SCRIPT_FILENAME while in the |
---|
57 | // default apache implementation it is not set |
---|
58 | if ( $conf['question_mark_in_urls']==false and |
---|
59 | isset($_SERVER["PATH_INFO"]) and !empty($_SERVER["PATH_INFO"]) ) |
---|
60 | { |
---|
61 | $rewritten = $_SERVER["PATH_INFO"]; |
---|
62 | $rewritten = str_replace('//', '/', $rewritten); |
---|
63 | $path_count = count( explode('/', $rewritten) ); |
---|
64 | $page['root_path'] = PHPWG_ROOT_PATH.str_repeat('../', $path_count-1); |
---|
65 | } |
---|
66 | else |
---|
67 | { |
---|
68 | $rewritten = ''; |
---|
69 | foreach (array_keys($_GET) as $keynum => $key) |
---|
70 | { |
---|
71 | $rewritten = $key; |
---|
72 | break; |
---|
73 | } |
---|
74 | $page['root_path'] = PHPWG_ROOT_PATH; |
---|
75 | } |
---|
76 | |
---|
77 | // deleting first "/" if displayed |
---|
78 | $tokens = explode( |
---|
79 | '/', |
---|
80 | preg_replace('#^/#', '', $rewritten) |
---|
81 | ); |
---|
82 | // $tokens = array( |
---|
83 | // 0 => category, |
---|
84 | // 1 => 12-foo, |
---|
85 | // 2 => start-24 |
---|
86 | // ); |
---|
87 | |
---|
88 | $next_token = 0; |
---|
89 | if (script_basename() == 'picture') // basename without file extention |
---|
90 | { // the first token must be the identifier for the picture |
---|
91 | if ( isset($_GET['image_id']) |
---|
92 | and isset($_GET['cat']) and is_numeric($_GET['cat']) ) |
---|
93 | {// url compatibility with versions below 1.6 |
---|
94 | $url = make_picture_url( array( |
---|
95 | 'section' => 'categories', |
---|
96 | 'category' => $_GET['cat'], |
---|
97 | 'image_id' => $_GET['image_id'] |
---|
98 | ) ); |
---|
99 | redirect($url); |
---|
100 | } |
---|
101 | $token = $tokens[$next_token]; |
---|
102 | $next_token++; |
---|
103 | if ( is_numeric($token) ) |
---|
104 | { |
---|
105 | $page['image_id'] = $token; |
---|
106 | } |
---|
107 | else |
---|
108 | { |
---|
109 | preg_match('/^(\d+-)?(.*)?$/', $token, $matches); |
---|
110 | if (isset($matches[1]) and is_numeric($matches[1]=rtrim($matches[1],'-')) ) |
---|
111 | { |
---|
112 | $page['image_id'] = $matches[1]; |
---|
113 | if ( !empty($matches[2]) ) |
---|
114 | { |
---|
115 | $page['image_file'] = $matches[2]; |
---|
116 | } |
---|
117 | |
---|
118 | } |
---|
119 | else |
---|
120 | { |
---|
121 | if ( !empty($matches[2]) ) |
---|
122 | { |
---|
123 | $page['image_file'] = $matches[2]; |
---|
124 | } |
---|
125 | else |
---|
126 | { |
---|
127 | die('Fatal: picture identifier is missing'); |
---|
128 | } |
---|
129 | } |
---|
130 | } |
---|
131 | } |
---|
132 | |
---|
133 | if (0 === strpos($tokens[$next_token], 'categor')) |
---|
134 | { |
---|
135 | $page['section'] = 'categories'; |
---|
136 | $next_token++; |
---|
137 | |
---|
138 | if (isset($tokens[$next_token]) |
---|
139 | and preg_match('/^(\d+)/', $tokens[$next_token], $matches)) |
---|
140 | { |
---|
141 | $page['category'] = $matches[1]; |
---|
142 | $next_token++; |
---|
143 | } |
---|
144 | } |
---|
145 | else if (0 === strpos($tokens[$next_token], 'tag')) |
---|
146 | { |
---|
147 | $page['section'] = 'tags'; |
---|
148 | $page['tags'] = array(); |
---|
149 | |
---|
150 | $next_token++; |
---|
151 | $i = $next_token; |
---|
152 | |
---|
153 | $requested_tag_ids = array(); |
---|
154 | $requested_tag_url_names = array(); |
---|
155 | |
---|
156 | while (isset($tokens[$i])) |
---|
157 | { |
---|
158 | if ( preg_match('/^(created-|posted-|start-(\d)+)/', $tokens[$i]) ) |
---|
159 | break; |
---|
160 | |
---|
161 | if ( preg_match('/^(\d+)(?:-(.*))?/', $tokens[$i], $matches) ) |
---|
162 | { |
---|
163 | array_push($requested_tag_ids, $matches[1]); |
---|
164 | } |
---|
165 | else |
---|
166 | { |
---|
167 | array_push($requested_tag_url_names, "'".$tokens[$i]."'"); |
---|
168 | } |
---|
169 | $i++; |
---|
170 | } |
---|
171 | $next_token = $i; |
---|
172 | |
---|
173 | if ( empty($requested_tag_ids) && empty($requested_tag_url_names) ) |
---|
174 | { |
---|
175 | die('Fatal: at least one tag required'); |
---|
176 | } |
---|
177 | // tag infos |
---|
178 | $query = ' |
---|
179 | SELECT name, url_name, id |
---|
180 | FROM '.TAGS_TABLE.' |
---|
181 | WHERE '; |
---|
182 | if ( !empty($requested_tag_ids) ) |
---|
183 | { |
---|
184 | $query.= 'id IN ('.implode(',', $requested_tag_ids ).')'; |
---|
185 | } |
---|
186 | if ( !empty($requested_tag_url_names) ) |
---|
187 | { |
---|
188 | if ( !empty($requested_tag_ids) ) |
---|
189 | { |
---|
190 | $query.= ' OR '; |
---|
191 | } |
---|
192 | $query.= 'url_name IN ('.implode(',', $requested_tag_url_names ).')'; |
---|
193 | } |
---|
194 | $result = pwg_query($query); |
---|
195 | $tag_infos = array(); |
---|
196 | while ($row = mysql_fetch_assoc($result)) |
---|
197 | { |
---|
198 | $tag_infos[ $row['id'] ] = $row; |
---|
199 | array_push($page['tags'], $row );//we loose given tag order; is it important? |
---|
200 | } |
---|
201 | if ( empty($page['tags']) ) |
---|
202 | { |
---|
203 | page_not_found('Requested tag does not exist', get_root_url().'tags.php' ); |
---|
204 | } |
---|
205 | } |
---|
206 | else if (0 === strpos($tokens[$next_token], 'fav')) |
---|
207 | { |
---|
208 | $page['section'] = 'favorites'; |
---|
209 | $next_token++; |
---|
210 | } |
---|
211 | else if ('most_visited' == $tokens[$next_token]) |
---|
212 | { |
---|
213 | $page['section'] = 'most_visited'; |
---|
214 | $next_token++; |
---|
215 | } |
---|
216 | else if ('best_rated' == $tokens[$next_token]) |
---|
217 | { |
---|
218 | $page['section'] = 'best_rated'; |
---|
219 | $next_token++; |
---|
220 | } |
---|
221 | else if ('recent_pics' == $tokens[$next_token]) |
---|
222 | { |
---|
223 | $page['section'] = 'recent_pics'; |
---|
224 | $next_token++; |
---|
225 | } |
---|
226 | else if ('recent_cats' == $tokens[$next_token]) |
---|
227 | { |
---|
228 | $page['section'] = 'recent_cats'; |
---|
229 | $next_token++; |
---|
230 | } |
---|
231 | else if ('search' == $tokens[$next_token]) |
---|
232 | { |
---|
233 | $page['section'] = 'search'; |
---|
234 | $next_token++; |
---|
235 | |
---|
236 | preg_match('/(\d+)/', $tokens[$next_token], $matches); |
---|
237 | if (!isset($matches[1])) |
---|
238 | { |
---|
239 | die('Fatal: search identifier is missing'); |
---|
240 | } |
---|
241 | $page['search'] = $matches[1]; |
---|
242 | $next_token++; |
---|
243 | } |
---|
244 | else if ('list' == $tokens[$next_token]) |
---|
245 | { |
---|
246 | $page['section'] = 'list'; |
---|
247 | $next_token++; |
---|
248 | |
---|
249 | $page['list'] = array(); |
---|
250 | |
---|
251 | // No pictures |
---|
252 | if (empty($tokens[$next_token])) |
---|
253 | { |
---|
254 | // Add dummy element list |
---|
255 | array_push($page['list'], -1); |
---|
256 | } |
---|
257 | // With pictures list |
---|
258 | else |
---|
259 | { |
---|
260 | if (!preg_match('/^\d+(,\d+)*$/', $tokens[$next_token])) |
---|
261 | { |
---|
262 | die('wrong format on list GET parameter'); |
---|
263 | } |
---|
264 | foreach (explode(',', $tokens[$next_token]) as $image_id) |
---|
265 | { |
---|
266 | array_push($page['list'], $image_id); |
---|
267 | } |
---|
268 | } |
---|
269 | $next_token++; |
---|
270 | } |
---|
271 | |
---|
272 | $i = $next_token; |
---|
273 | |
---|
274 | while (isset($tokens[$i])) |
---|
275 | { |
---|
276 | if (preg_match('/^start-(\d+)/', $tokens[$i], $matches)) |
---|
277 | { |
---|
278 | $page['start'] = $matches[1]; |
---|
279 | } |
---|
280 | |
---|
281 | if ('categories' == $page['section'] and |
---|
282 | 'flat_cat' == $tokens[$i]) |
---|
283 | { |
---|
284 | // indicate a special list of images |
---|
285 | $page['flat_cat'] = true; |
---|
286 | } |
---|
287 | |
---|
288 | if (preg_match('/^(posted|created)/', $tokens[$i] )) |
---|
289 | { |
---|
290 | $chronology_tokens = explode('-', $tokens[$i] ); |
---|
291 | |
---|
292 | $page['chronology_field'] = $chronology_tokens[0]; |
---|
293 | |
---|
294 | array_shift($chronology_tokens); |
---|
295 | $page['chronology_style'] = $chronology_tokens[0]; |
---|
296 | |
---|
297 | array_shift($chronology_tokens); |
---|
298 | if ( count($chronology_tokens)>0 ) |
---|
299 | { |
---|
300 | if ('list'==$chronology_tokens[0] or |
---|
301 | 'calendar'==$chronology_tokens[0]) |
---|
302 | { |
---|
303 | $page['chronology_view'] = $chronology_tokens[0]; |
---|
304 | array_shift($chronology_tokens); |
---|
305 | } |
---|
306 | $page['chronology_date'] = $chronology_tokens; |
---|
307 | } |
---|
308 | } |
---|
309 | |
---|
310 | $i++; |
---|
311 | } |
---|
312 | |
---|
313 | |
---|
314 | // $page['nb_image_page'] is the number of picture to display on this page |
---|
315 | // By default, it is the same as the $user['nb_image_page'] |
---|
316 | $page['nb_image_page'] = $user['nb_image_page']; |
---|
317 | |
---|
318 | if (pwg_get_session_var('image_order',0) > 0) |
---|
319 | { |
---|
320 | $orders = get_category_preferred_image_orders(); |
---|
321 | |
---|
322 | $conf['order_by'] = str_replace( |
---|
323 | 'ORDER BY ', |
---|
324 | 'ORDER BY '.$orders[ pwg_get_session_var('image_order',0) ][1].',', |
---|
325 | $conf['order_by'] |
---|
326 | ); |
---|
327 | $page['super_order_by'] = true; |
---|
328 | } |
---|
329 | |
---|
330 | $forbidden = get_sql_condition_FandF( |
---|
331 | array |
---|
332 | ( |
---|
333 | 'forbidden_categories' => 'category_id', |
---|
334 | 'visible_categories' => 'category_id', |
---|
335 | 'visible_images' => 'image_id' |
---|
336 | ), |
---|
337 | 'AND' |
---|
338 | ); |
---|
339 | |
---|
340 | // +-----------------------------------------------------------------------+ |
---|
341 | // | category | |
---|
342 | // +-----------------------------------------------------------------------+ |
---|
343 | if ('categories' == $page['section']) |
---|
344 | { |
---|
345 | if (isset($page['category'])) |
---|
346 | { |
---|
347 | $result = get_cat_info($page['category']); |
---|
348 | if (empty($result)) |
---|
349 | { |
---|
350 | page_not_found('Requested category does not exist' ); |
---|
351 | } |
---|
352 | |
---|
353 | $page = array_merge( |
---|
354 | $page, |
---|
355 | array( |
---|
356 | 'comment' => $result['comment'], |
---|
357 | 'cat_dir' => $result['dir'], |
---|
358 | 'cat_name' => $result['name'], |
---|
359 | 'cat_site_id' => $result['site_id'], |
---|
360 | 'cat_uploadable' => $result['uploadable'], |
---|
361 | 'cat_commentable' => $result['commentable'], |
---|
362 | 'cat_id_uppercat' => $result['id_uppercat'], |
---|
363 | 'uppercats' => $result['uppercats'], |
---|
364 | 'title' => |
---|
365 | get_cat_display_name($result['name'], '', false), |
---|
366 | 'thumbnails_include' => |
---|
367 | (($result['nb_images'] > 0) or (isset($page['flat_cat']))) |
---|
368 | ? 'include/category_default.inc.php' |
---|
369 | : 'include/category_cats.inc.php' |
---|
370 | ) |
---|
371 | ); |
---|
372 | } |
---|
373 | else |
---|
374 | { |
---|
375 | $page['title'] = $lang['no_category']; |
---|
376 | $page['thumbnails_include'] = |
---|
377 | (isset($page['flat_cat'])) |
---|
378 | ? 'include/category_default.inc.php' |
---|
379 | : 'include/category_cats.inc.php'; |
---|
380 | } |
---|
381 | |
---|
382 | if (isset($page['flat_cat'])) |
---|
383 | { |
---|
384 | $page['title'] = $lang['recent_pics_cat'].' : '.$page['title'] ; |
---|
385 | } |
---|
386 | |
---|
387 | if |
---|
388 | ( |
---|
389 | (!isset($page['chronology_field'])) and |
---|
390 | ( |
---|
391 | (isset($page['category'])) or |
---|
392 | (isset($page['flat_cat'])) |
---|
393 | ) |
---|
394 | ) |
---|
395 | { |
---|
396 | if ( !empty($result['image_order']) and !isset($page['super_order_by']) ) |
---|
397 | { |
---|
398 | $conf[ 'order_by' ] = ' ORDER BY '.$result['image_order']; |
---|
399 | } |
---|
400 | |
---|
401 | if (isset($page['flat_cat'])) |
---|
402 | { |
---|
403 | // flat recent categories mode |
---|
404 | $query = ' |
---|
405 | SELECT |
---|
406 | DISTINCT(ic.image_id) |
---|
407 | FROM '.IMAGES_TABLE.' AS i |
---|
408 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON i.id = ic.image_id |
---|
409 | INNER JOIN '.CATEGORIES_TABLE.' AS c ON ic.category_id = c.id |
---|
410 | WHERE |
---|
411 | '.(isset($page['category']) ? ' |
---|
412 | uppercats REGEXP \'(^|,)'.$page['category'].'(,|$)\'' : '1=1' ).' |
---|
413 | '.$forbidden.' |
---|
414 | ;'; |
---|
415 | |
---|
416 | $where_sql = array_from_query($query, 'image_id'); |
---|
417 | if (!empty($where_sql)) |
---|
418 | { |
---|
419 | $where_sql = 'image_id in ('.implode(',', $where_sql).')'; |
---|
420 | } |
---|
421 | } |
---|
422 | else |
---|
423 | { |
---|
424 | // Normal mode |
---|
425 | $where_sql = 'category_id = '.$page['category']; |
---|
426 | } |
---|
427 | |
---|
428 | if (!empty($where_sql)) |
---|
429 | { |
---|
430 | // Main query |
---|
431 | $query = ' |
---|
432 | SELECT DISTINCT(image_id) |
---|
433 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
434 | INNER JOIN '.IMAGES_TABLE.' ON id = image_id |
---|
435 | WHERE |
---|
436 | '.$where_sql.' |
---|
437 | '.$forbidden.' |
---|
438 | '.$conf['order_by'].' |
---|
439 | ;'; |
---|
440 | |
---|
441 | $page['items'] = array_from_query($query, 'image_id'); |
---|
442 | } |
---|
443 | else |
---|
444 | { |
---|
445 | $page['items'] = array(); |
---|
446 | } |
---|
447 | } //otherwise the calendar will requery all subitems |
---|
448 | } |
---|
449 | // special sections |
---|
450 | else |
---|
451 | { |
---|
452 | // +-----------------------------------------------------------------------+ |
---|
453 | // | tags section | |
---|
454 | // +-----------------------------------------------------------------------+ |
---|
455 | if ($page['section'] == 'tags') |
---|
456 | { |
---|
457 | $page['tag_ids'] = array(); |
---|
458 | foreach ($page['tags'] as $tag) |
---|
459 | { |
---|
460 | array_push($page['tag_ids'], $tag['id']); |
---|
461 | } |
---|
462 | |
---|
463 | $items = get_image_ids_for_tags($page['tag_ids']); |
---|
464 | |
---|
465 | // permissions depends on category, so to only keep images that are |
---|
466 | // reachable to the connected user, we need to check category |
---|
467 | // associations |
---|
468 | if (!empty($items) ) |
---|
469 | { |
---|
470 | $query = ' |
---|
471 | SELECT image_id |
---|
472 | FROM '.IMAGE_CATEGORY_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON image_id=id |
---|
473 | WHERE image_id IN ('.implode(',', $items).') |
---|
474 | '.$forbidden. |
---|
475 | $conf['order_by'].' |
---|
476 | ;'; |
---|
477 | $items = array_unique( |
---|
478 | array_from_query($query, 'image_id') |
---|
479 | ); |
---|
480 | } |
---|
481 | |
---|
482 | $title = get_tags_content_title(); |
---|
483 | |
---|
484 | $page = array_merge( |
---|
485 | $page, |
---|
486 | array( |
---|
487 | 'title' => $title, |
---|
488 | 'items' => array_values($items), |
---|
489 | 'thumbnails_include' => 'include/category_default.inc.php', |
---|
490 | ) |
---|
491 | ); |
---|
492 | } |
---|
493 | // +-----------------------------------------------------------------------+ |
---|
494 | // | search section | |
---|
495 | // +-----------------------------------------------------------------------+ |
---|
496 | if ($page['section'] == 'search') |
---|
497 | { |
---|
498 | include_once( PHPWG_ROOT_PATH .'include/functions_search.inc.php' ); |
---|
499 | |
---|
500 | $search_result = get_search_results($page['search']); |
---|
501 | if ( !empty($search_result['items']) and !isset($search_result['as_is']) ) |
---|
502 | { |
---|
503 | $query = ' |
---|
504 | SELECT DISTINCT(id) |
---|
505 | FROM '.IMAGES_TABLE.' |
---|
506 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id |
---|
507 | WHERE id IN ('.implode(',', $search_result['items']).') |
---|
508 | '.$forbidden.' |
---|
509 | '.$conf['order_by'].' |
---|
510 | ;'; |
---|
511 | $page['items'] = array_from_query($query, 'id'); |
---|
512 | } |
---|
513 | else |
---|
514 | { |
---|
515 | $page['items'] = $search_result['items']; |
---|
516 | } |
---|
517 | |
---|
518 | $page = array_merge( |
---|
519 | $page, |
---|
520 | array( |
---|
521 | 'title' => $lang['search_result'], |
---|
522 | 'thumbnails_include' => 'include/category_default.inc.php', |
---|
523 | ) |
---|
524 | ); |
---|
525 | } |
---|
526 | // +-----------------------------------------------------------------------+ |
---|
527 | // | favorite section | |
---|
528 | // +-----------------------------------------------------------------------+ |
---|
529 | else if ($page['section'] == 'favorites') |
---|
530 | { |
---|
531 | check_user_favorites(); |
---|
532 | |
---|
533 | $query = ' |
---|
534 | SELECT image_id |
---|
535 | FROM '.FAVORITES_TABLE.' |
---|
536 | INNER JOIN '.IMAGES_TABLE.' ON image_id = id |
---|
537 | WHERE user_id = '.$user['id'].' |
---|
538 | '.get_sql_condition_FandF |
---|
539 | ( |
---|
540 | array |
---|
541 | ( |
---|
542 | 'visible_images' => 'image_id' |
---|
543 | ), |
---|
544 | 'AND' |
---|
545 | ).' |
---|
546 | '.$conf['order_by'].' |
---|
547 | ;'; |
---|
548 | |
---|
549 | $page = array_merge( |
---|
550 | $page, |
---|
551 | array( |
---|
552 | 'title' => $lang['favorites'], |
---|
553 | 'items' => array_from_query($query, 'image_id'), |
---|
554 | 'thumbnails_include' => 'include/category_default.inc.php', |
---|
555 | ) |
---|
556 | ); |
---|
557 | } |
---|
558 | // +-----------------------------------------------------------------------+ |
---|
559 | // | recent pictures section | |
---|
560 | // +-----------------------------------------------------------------------+ |
---|
561 | else if ($page['section'] == 'recent_pics') |
---|
562 | { |
---|
563 | $query = ' |
---|
564 | SELECT DISTINCT(id) |
---|
565 | FROM '.IMAGES_TABLE.' |
---|
566 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id |
---|
567 | WHERE date_available > \''. |
---|
568 | date('Y-m-d', time() - 60*60*24*$user['recent_period']).'\' |
---|
569 | '.$forbidden.' |
---|
570 | '.$conf['order_by'].' |
---|
571 | ;'; |
---|
572 | |
---|
573 | $page = array_merge( |
---|
574 | $page, |
---|
575 | array( |
---|
576 | 'title' => '<a href="'.duplicate_index_url().'">' |
---|
577 | .$lang['recent_pics_cat'].'</a>', |
---|
578 | 'items' => array_from_query($query, 'id'), |
---|
579 | 'thumbnails_include' => 'include/category_default.inc.php', |
---|
580 | ) |
---|
581 | ); |
---|
582 | } |
---|
583 | // +-----------------------------------------------------------------------+ |
---|
584 | // | recently updated categories section | |
---|
585 | // +-----------------------------------------------------------------------+ |
---|
586 | else if ($page['section'] == 'recent_cats') |
---|
587 | { |
---|
588 | $page = array_merge( |
---|
589 | $page, |
---|
590 | array( |
---|
591 | 'title' => $lang['recent_cats_cat'], |
---|
592 | 'thumbnails_include' => 'include/category_cats.inc.php', |
---|
593 | ) |
---|
594 | ); |
---|
595 | } |
---|
596 | // +-----------------------------------------------------------------------+ |
---|
597 | // | most visited section | |
---|
598 | // +-----------------------------------------------------------------------+ |
---|
599 | else if ($page['section'] == 'most_visited') |
---|
600 | { |
---|
601 | $page['super_order_by'] = true; |
---|
602 | $conf['order_by'] = ' ORDER BY hit DESC, file ASC'; |
---|
603 | $query = ' |
---|
604 | SELECT DISTINCT(id) |
---|
605 | FROM '.IMAGES_TABLE.' |
---|
606 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id |
---|
607 | WHERE hit > 0 |
---|
608 | '.$forbidden.' |
---|
609 | '.$conf['order_by'].' |
---|
610 | LIMIT 0, '.$conf['top_number'].' |
---|
611 | ;'; |
---|
612 | |
---|
613 | $page = array_merge( |
---|
614 | $page, |
---|
615 | array( |
---|
616 | 'title' => '<a href="'.duplicate_index_url().'">' |
---|
617 | .$conf['top_number'].' '.$lang['most_visited_cat'].'</a>', |
---|
618 | 'items' => array_from_query($query, 'id'), |
---|
619 | 'thumbnails_include' => 'include/category_default.inc.php', |
---|
620 | ) |
---|
621 | ); |
---|
622 | } |
---|
623 | // +-----------------------------------------------------------------------+ |
---|
624 | // | best rated section | |
---|
625 | // +-----------------------------------------------------------------------+ |
---|
626 | else if ($page['section'] == 'best_rated') |
---|
627 | { |
---|
628 | $page['super_order_by'] = true; |
---|
629 | $conf['order_by'] = ' ORDER BY average_rate DESC, id ASC'; |
---|
630 | |
---|
631 | $query =' |
---|
632 | SELECT DISTINCT(id) |
---|
633 | FROM '.IMAGES_TABLE.' |
---|
634 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id |
---|
635 | WHERE average_rate IS NOT NULL |
---|
636 | '.$forbidden.' |
---|
637 | '.$conf['order_by'].' |
---|
638 | LIMIT 0, '.$conf['top_number'].' |
---|
639 | ;'; |
---|
640 | $page = array_merge( |
---|
641 | $page, |
---|
642 | array( |
---|
643 | 'title' => '<a href="'.duplicate_index_url().'">' |
---|
644 | .$conf['top_number'].' '.$lang['best_rated_cat'].'</a>', |
---|
645 | 'items' => array_from_query($query, 'id'), |
---|
646 | 'thumbnails_include' => 'include/category_default.inc.php', |
---|
647 | ) |
---|
648 | ); |
---|
649 | } |
---|
650 | // +-----------------------------------------------------------------------+ |
---|
651 | // | list section | |
---|
652 | // +-----------------------------------------------------------------------+ |
---|
653 | else if ($page['section'] == 'list') |
---|
654 | { |
---|
655 | $query =' |
---|
656 | SELECT DISTINCT(id) |
---|
657 | FROM '.IMAGES_TABLE.' |
---|
658 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id |
---|
659 | WHERE image_id IN ('.implode(',', $page['list']).') |
---|
660 | '.$forbidden.' |
---|
661 | '.$conf['order_by'].' |
---|
662 | ;'; |
---|
663 | |
---|
664 | $page = array_merge( |
---|
665 | $page, |
---|
666 | array( |
---|
667 | 'title' => '<a href="'.duplicate_index_url().'">' |
---|
668 | .$lang['random_cat'].'</a>', |
---|
669 | 'items' => array_from_query($query, 'id'), |
---|
670 | 'thumbnails_include' => 'include/category_default.inc.php', |
---|
671 | ) |
---|
672 | ); |
---|
673 | } |
---|
674 | } |
---|
675 | |
---|
676 | // +-----------------------------------------------------------------------+ |
---|
677 | // | chronology | |
---|
678 | // +-----------------------------------------------------------------------+ |
---|
679 | |
---|
680 | if (isset($page['chronology_field'])) |
---|
681 | { |
---|
682 | include_once( PHPWG_ROOT_PATH.'include/functions_calendar.inc.php' ); |
---|
683 | initialize_calendar(); |
---|
684 | } |
---|
685 | |
---|
686 | $page['cat_nb_images'] = isset($page['items']) ? count($page['items']) : 0; |
---|
687 | |
---|
688 | if (script_basename() == 'picture' |
---|
689 | and !isset($page['image_id']) ) |
---|
690 | { |
---|
691 | if ( !empty($page['items']) ) |
---|
692 | { |
---|
693 | $query = ' |
---|
694 | SELECT id,file |
---|
695 | FROM '.IMAGES_TABLE .' |
---|
696 | WHERE id IN ('.implode(',',$page['items']).') |
---|
697 | AND file LIKE "' . $page['image_file'] . '.%" ESCAPE "|"' |
---|
698 | ; |
---|
699 | $result = pwg_query($query); |
---|
700 | if (mysql_num_rows($result)>0) |
---|
701 | { |
---|
702 | list($page['image_id'], $page['image_file']) = mysql_fetch_row($result); |
---|
703 | } |
---|
704 | } |
---|
705 | if ( !isset($page['image_id']) ) |
---|
706 | { |
---|
707 | $page['image_id'] = -1; // will fail in picture.php |
---|
708 | } |
---|
709 | } |
---|
710 | |
---|
711 | // add meta robots noindex, nofollow to avoid unnecesary robot crawls |
---|
712 | $page['meta_robots']=array(); |
---|
713 | if ( isset($page['chronology_field']) or isset($page['flat_cat']) |
---|
714 | or 'list'==$page['section'] or 'recent_pics'==$page['section'] ) |
---|
715 | { |
---|
716 | $page['meta_robots']=array('noindex'=>1, 'nofollow'=>1); |
---|
717 | } |
---|
718 | elseif ('tags' == $page['section']) |
---|
719 | { |
---|
720 | if ( count($page['tag_ids'])>1 ) |
---|
721 | { |
---|
722 | $page['meta_robots']=array('noindex'=>1, 'nofollow'=>1); |
---|
723 | } |
---|
724 | } |
---|
725 | elseif ('recent_cats'==$page['section']) |
---|
726 | { |
---|
727 | $page['meta_robots']['nofollow']=1; |
---|
728 | } |
---|
729 | if ( $filter['enabled'] ) |
---|
730 | { |
---|
731 | $page['meta_robots']['noindex']=1; |
---|
732 | } |
---|
733 | |
---|
734 | trigger_action('loc_end_section_init'); |
---|
735 | ?> |
---|