1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based photo gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org | |
---|
6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // | This program is free software; you can redistribute it and/or modify | |
---|
10 | // | it under the terms of the GNU General Public License as published by | |
---|
11 | // | the Free Software Foundation | |
---|
12 | // | | |
---|
13 | // | This program is distributed in the hope that it will be useful, but | |
---|
14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
16 | // | General Public License for more details. | |
---|
17 | // | | |
---|
18 | // | You should have received a copy of the GNU General Public License | |
---|
19 | // | along with this program; if not, write to the Free Software | |
---|
20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
21 | // | USA. | |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | define('PHPWG_ROOT_PATH','./'); |
---|
25 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); |
---|
26 | include(PHPWG_ROOT_PATH.'include/section_init.inc.php'); |
---|
27 | include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); |
---|
28 | |
---|
29 | // Check Access and exit when user status is not ok |
---|
30 | check_status(ACCESS_GUEST); |
---|
31 | |
---|
32 | // access authorization check |
---|
33 | if (isset($page['category'])) |
---|
34 | { |
---|
35 | check_restrictions($page['category']['id']); |
---|
36 | } |
---|
37 | |
---|
38 | $page['rank_of'] = array_flip($page['items']); |
---|
39 | |
---|
40 | // if this image_id doesn't correspond to this category, an error message is |
---|
41 | // displayed, and execution is stopped |
---|
42 | if ( !isset($page['rank_of'][$page['image_id']]) ) |
---|
43 | { |
---|
44 | $query = ' |
---|
45 | SELECT id, file, level |
---|
46 | FROM '.IMAGES_TABLE.' |
---|
47 | WHERE '; |
---|
48 | if ($page['image_id']>0) |
---|
49 | { |
---|
50 | $query .= 'id = '.$page['image_id']; |
---|
51 | } |
---|
52 | else |
---|
53 | {// url given by file name |
---|
54 | assert( !empty($page['image_file']) ); |
---|
55 | $query .= 'file LIKE \'' . |
---|
56 | str_replace(array('_','%'), array('/_','/%'), $page['image_file'] ). |
---|
57 | '.%\' ESCAPE \'/\' LIMIT 1'; |
---|
58 | } |
---|
59 | if ( ! ( $row = pwg_db_fetch_assoc(pwg_query($query)) ) ) |
---|
60 | {// element does not exist |
---|
61 | page_not_found( 'The requested image does not exist', |
---|
62 | duplicate_index_url() |
---|
63 | ); |
---|
64 | } |
---|
65 | if ($row['level']>$user['level']) |
---|
66 | { |
---|
67 | access_denied(); |
---|
68 | } |
---|
69 | |
---|
70 | $page['image_id'] = $row['id']; |
---|
71 | $page['image_file'] = $row['file']; |
---|
72 | if ( !isset($page['rank_of'][$page['image_id']]) ) |
---|
73 | {// the image can still be non accessible (filter/cat perm) and/or not in the set |
---|
74 | global $filter; |
---|
75 | if ( !empty($filter['visible_images']) and |
---|
76 | !in_array($page['image_id'], explode(',',$filter['visible_images']) ) ) |
---|
77 | { |
---|
78 | page_not_found( 'The requested image is filtered', |
---|
79 | duplicate_index_url() |
---|
80 | ); |
---|
81 | } |
---|
82 | if ('categories'==$page['section'] and !isset($page['category']) ) |
---|
83 | {// flat view - all items |
---|
84 | access_denied(); |
---|
85 | } |
---|
86 | else |
---|
87 | {// try to see if we can access it differently |
---|
88 | $query = ' |
---|
89 | SELECT id |
---|
90 | FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id |
---|
91 | WHERE id='.$page['image_id'] |
---|
92 | . get_sql_condition_FandF( |
---|
93 | array('forbidden_categories' => 'category_id'), |
---|
94 | " AND" |
---|
95 | ).' |
---|
96 | LIMIT 1'; |
---|
97 | if ( pwg_db_num_rows( pwg_query($query) ) == 0 ) |
---|
98 | { |
---|
99 | access_denied(); |
---|
100 | } |
---|
101 | else |
---|
102 | { |
---|
103 | if ('best_rated'==$page['section']) |
---|
104 | { |
---|
105 | $page['rank_of'][$page['image_id']] = count($page['items']); |
---|
106 | array_push($page['items'], $page['image_id'] ); |
---|
107 | } |
---|
108 | else |
---|
109 | { |
---|
110 | $url = make_picture_url( |
---|
111 | array( |
---|
112 | 'image_id' => $page['image_id'], |
---|
113 | 'image_file' => $page['image_file'], |
---|
114 | 'section' => 'categories', |
---|
115 | 'flat' => true, |
---|
116 | ) |
---|
117 | ); |
---|
118 | set_status_header( 'recent_pics'==$page['section'] ? 301 : 302); |
---|
119 | redirect_http( $url ); |
---|
120 | } |
---|
121 | } |
---|
122 | } |
---|
123 | } |
---|
124 | } |
---|
125 | |
---|
126 | // There is cookie, so we must handle it at the beginning |
---|
127 | if ( isset($_GET['metadata']) ) |
---|
128 | { |
---|
129 | if ( pwg_get_session_var('show_metadata') == null ) |
---|
130 | { |
---|
131 | pwg_set_session_var('show_metadata', 1 ); |
---|
132 | } else { |
---|
133 | pwg_unset_session_var('show_metadata'); |
---|
134 | } |
---|
135 | } |
---|
136 | |
---|
137 | // add default event handler for rendering element content |
---|
138 | add_event_handler( |
---|
139 | 'render_element_content', |
---|
140 | 'default_picture_content', |
---|
141 | EVENT_HANDLER_PRIORITY_NEUTRAL, |
---|
142 | 2 |
---|
143 | ); |
---|
144 | // add default event handler for rendering element description |
---|
145 | add_event_handler('render_element_description', 'nl2br'); |
---|
146 | |
---|
147 | trigger_action('loc_begin_picture'); |
---|
148 | |
---|
149 | // this is the default handler that generates the display for the element |
---|
150 | function default_picture_content($content, $element_info) |
---|
151 | { |
---|
152 | if ( !empty($content) ) |
---|
153 | {// someone hooked us - so we skip; |
---|
154 | return $content; |
---|
155 | } |
---|
156 | |
---|
157 | if (isset($_COOKIE['picture_deriv'])) |
---|
158 | { |
---|
159 | if ( array_key_exists($_COOKIE['picture_deriv'], ImageStdParams::get_defined_type_map()) ) |
---|
160 | { |
---|
161 | pwg_set_session_var('picture_deriv', $_COOKIE['picture_deriv']); |
---|
162 | } |
---|
163 | setcookie('picture_deriv', false, 0, cookie_path() ); |
---|
164 | } |
---|
165 | $deriv_type = pwg_get_session_var('picture_deriv', IMG_LARGE); |
---|
166 | $selected_derivative = $element_info['derivatives'][$deriv_type]; |
---|
167 | |
---|
168 | $unique_derivatives = array(); |
---|
169 | $show_original = isset($element_info['element_url']); |
---|
170 | $added = array(); |
---|
171 | foreach($element_info['derivatives'] as $type => $derivative) |
---|
172 | { |
---|
173 | if ($type==IMG_SQUARE || $type==IMG_THUMB) |
---|
174 | continue; |
---|
175 | $url = $derivative->get_url(); |
---|
176 | if (isset($added[$url])) |
---|
177 | continue; |
---|
178 | $added[$url] = 1; |
---|
179 | $show_original &= !($derivative->same_as_source()); |
---|
180 | $unique_derivatives[$type]= $derivative; |
---|
181 | } |
---|
182 | |
---|
183 | global $page, $template; |
---|
184 | |
---|
185 | if ($show_original) |
---|
186 | { |
---|
187 | $template->assign( 'U_ORIGINAL', $element_info['element_url'] ); |
---|
188 | } |
---|
189 | |
---|
190 | $template->append('current', array( |
---|
191 | 'selected_derivative' => $selected_derivative, |
---|
192 | 'unique_derivatives' => $unique_derivatives, |
---|
193 | ), true); |
---|
194 | |
---|
195 | |
---|
196 | $template->set_filenames( |
---|
197 | array('default_content'=>'picture_content.tpl') |
---|
198 | ); |
---|
199 | |
---|
200 | $template->assign( array( |
---|
201 | 'ALT_IMG' => $element_info['file'], |
---|
202 | 'COOKIE_PATH' => cookie_path(), |
---|
203 | ) |
---|
204 | ); |
---|
205 | return $template->parse( 'default_content', true); |
---|
206 | } |
---|
207 | |
---|
208 | // +-----------------------------------------------------------------------+ |
---|
209 | // | initialization | |
---|
210 | // +-----------------------------------------------------------------------+ |
---|
211 | |
---|
212 | // caching first_rank, last_rank, current_rank in the displayed |
---|
213 | // section. This should also help in readability. |
---|
214 | $page['first_rank'] = 0; |
---|
215 | $page['last_rank'] = count($page['items']) - 1; |
---|
216 | $page['current_rank'] = $page['rank_of'][ $page['image_id'] ]; |
---|
217 | |
---|
218 | // caching current item : readability purpose |
---|
219 | $page['current_item'] = $page['image_id']; |
---|
220 | |
---|
221 | if ($page['current_rank'] != $page['first_rank']) |
---|
222 | { |
---|
223 | // caching first & previous item : readability purpose |
---|
224 | $page['previous_item'] = $page['items'][ $page['current_rank'] - 1 ]; |
---|
225 | $page['first_item'] = $page['items'][ $page['first_rank'] ]; |
---|
226 | } |
---|
227 | |
---|
228 | if ($page['current_rank'] != $page['last_rank']) |
---|
229 | { |
---|
230 | // caching next & last item : readability purpose |
---|
231 | $page['next_item'] = $page['items'][ $page['current_rank'] + 1 ]; |
---|
232 | $page['last_item'] = $page['items'][ $page['last_rank'] ]; |
---|
233 | } |
---|
234 | |
---|
235 | $url_up = duplicate_index_url( |
---|
236 | array( |
---|
237 | 'start' => |
---|
238 | floor($page['current_rank'] / $page['nb_image_page']) |
---|
239 | * $page['nb_image_page'] |
---|
240 | ), |
---|
241 | array( |
---|
242 | 'start', |
---|
243 | ) |
---|
244 | ); |
---|
245 | |
---|
246 | $url_self = duplicate_picture_url(); |
---|
247 | |
---|
248 | // +-----------------------------------------------------------------------+ |
---|
249 | // | actions | |
---|
250 | // +-----------------------------------------------------------------------+ |
---|
251 | |
---|
252 | /** |
---|
253 | * Actions are favorite adding, user comment deletion, setting the picture |
---|
254 | * as representative of the current category... |
---|
255 | * |
---|
256 | * Actions finish by a redirection |
---|
257 | */ |
---|
258 | |
---|
259 | if (isset($_GET['action'])) |
---|
260 | { |
---|
261 | switch ($_GET['action']) |
---|
262 | { |
---|
263 | case 'add_to_favorites' : |
---|
264 | { |
---|
265 | $query = ' |
---|
266 | INSERT INTO '.FAVORITES_TABLE.' |
---|
267 | (image_id,user_id) |
---|
268 | VALUES |
---|
269 | ('.$page['image_id'].','.$user['id'].') |
---|
270 | ;'; |
---|
271 | pwg_query($query); |
---|
272 | |
---|
273 | redirect($url_self); |
---|
274 | |
---|
275 | break; |
---|
276 | } |
---|
277 | case 'remove_from_favorites' : |
---|
278 | { |
---|
279 | $query = ' |
---|
280 | DELETE FROM '.FAVORITES_TABLE.' |
---|
281 | WHERE user_id = '.$user['id'].' |
---|
282 | AND image_id = '.$page['image_id'].' |
---|
283 | ;'; |
---|
284 | pwg_query($query); |
---|
285 | |
---|
286 | if ('favorites' == $page['section']) |
---|
287 | { |
---|
288 | redirect($url_up); |
---|
289 | } |
---|
290 | else |
---|
291 | { |
---|
292 | redirect($url_self); |
---|
293 | } |
---|
294 | |
---|
295 | break; |
---|
296 | } |
---|
297 | case 'set_as_representative' : |
---|
298 | { |
---|
299 | if (is_admin() and isset($page['category'])) |
---|
300 | { |
---|
301 | $query = ' |
---|
302 | UPDATE '.CATEGORIES_TABLE.' |
---|
303 | SET representative_picture_id = '.$page['image_id'].' |
---|
304 | WHERE id = '.$page['category']['id'].' |
---|
305 | ;'; |
---|
306 | pwg_query($query); |
---|
307 | |
---|
308 | $query = ' |
---|
309 | UPDATE '.USER_CACHE_CATEGORIES_TABLE.' |
---|
310 | SET user_representative_picture_id = NULL |
---|
311 | WHERE user_id = '.$user['id'].' |
---|
312 | AND cat_id = '.$page['category']['id'].' |
---|
313 | ;'; |
---|
314 | pwg_query($query); |
---|
315 | } |
---|
316 | |
---|
317 | redirect($url_self); |
---|
318 | |
---|
319 | break; |
---|
320 | } |
---|
321 | case 'add_to_caddie' : |
---|
322 | { |
---|
323 | fill_caddie(array($page['image_id'])); |
---|
324 | redirect($url_self); |
---|
325 | break; |
---|
326 | } |
---|
327 | case 'rate' : |
---|
328 | { |
---|
329 | include_once(PHPWG_ROOT_PATH.'include/functions_rate.inc.php'); |
---|
330 | rate_picture($page['image_id'], $_POST['rate']); |
---|
331 | redirect($url_self); |
---|
332 | } |
---|
333 | case 'edit_comment' : |
---|
334 | { |
---|
335 | check_pwg_token(); |
---|
336 | include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php'); |
---|
337 | check_input_parameter('comment_to_edit', $_GET, false, PATTERN_ID); |
---|
338 | $author_id = get_comment_author_id($_GET['comment_to_edit']); |
---|
339 | |
---|
340 | if (can_manage_comment('edit', $author_id)) |
---|
341 | { |
---|
342 | if (!empty($_POST['content'])) |
---|
343 | { |
---|
344 | $comment_action = update_user_comment( |
---|
345 | array( |
---|
346 | 'comment_id' => $_GET['comment_to_edit'], |
---|
347 | 'image_id' => $page['image_id'], |
---|
348 | 'content' => $_POST['content'] |
---|
349 | ), |
---|
350 | $_POST['key'] |
---|
351 | ); |
---|
352 | |
---|
353 | $perform_redirect = false; |
---|
354 | switch ($comment_action) |
---|
355 | { |
---|
356 | case 'moderate': |
---|
357 | $_SESSION['page_infos'][] = l10n('An administrator must authorize your comment before it is visible.'); |
---|
358 | case 'validate': |
---|
359 | $_SESSION['page_infos'][] = l10n('Your comment has been registered'); |
---|
360 | $perform_redirect = true; |
---|
361 | break; |
---|
362 | case 'reject': |
---|
363 | $_SESSION['page_errors'][] = l10n('Your comment has NOT been registered because it did not pass the validation rules'); |
---|
364 | $perform_redirect = true; |
---|
365 | break; |
---|
366 | default: |
---|
367 | trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING); |
---|
368 | } |
---|
369 | |
---|
370 | if ($perform_redirect) |
---|
371 | { |
---|
372 | redirect($url_self); |
---|
373 | } |
---|
374 | unset($_POST['content']); |
---|
375 | break; |
---|
376 | } |
---|
377 | else |
---|
378 | { |
---|
379 | $edit_comment = $_GET['comment_to_edit']; |
---|
380 | break; |
---|
381 | } |
---|
382 | } |
---|
383 | } |
---|
384 | case 'delete_comment' : |
---|
385 | { |
---|
386 | check_pwg_token(); |
---|
387 | |
---|
388 | include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php'); |
---|
389 | |
---|
390 | check_input_parameter('comment_to_delete', $_GET, false, PATTERN_ID); |
---|
391 | |
---|
392 | $author_id = get_comment_author_id($_GET['comment_to_delete']); |
---|
393 | |
---|
394 | if (can_manage_comment('delete', $author_id)) |
---|
395 | { |
---|
396 | delete_user_comment($_GET['comment_to_delete']); |
---|
397 | } |
---|
398 | |
---|
399 | redirect($url_self); |
---|
400 | } |
---|
401 | case 'validate_comment' : |
---|
402 | { |
---|
403 | check_pwg_token(); |
---|
404 | |
---|
405 | include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php'); |
---|
406 | |
---|
407 | check_input_parameter('comment_to_validate', $_GET, false, PATTERN_ID); |
---|
408 | |
---|
409 | $author_id = get_comment_author_id($_GET['comment_to_validate']); |
---|
410 | |
---|
411 | if (can_manage_comment('validate', $author_id)) |
---|
412 | { |
---|
413 | validate_user_comment($_GET['comment_to_validate']); |
---|
414 | } |
---|
415 | |
---|
416 | redirect($url_self); |
---|
417 | } |
---|
418 | |
---|
419 | } |
---|
420 | } |
---|
421 | |
---|
422 | //---------- incrementation of the number of hits, we do this only if no action |
---|
423 | if (trigger_event('allow_increment_element_hit_count', !isset($_POST['content']) ) ) |
---|
424 | { |
---|
425 | $query = ' |
---|
426 | UPDATE |
---|
427 | '.IMAGES_TABLE.' |
---|
428 | SET hit = hit+1 |
---|
429 | WHERE id = '.$page['image_id'].' |
---|
430 | ;'; |
---|
431 | pwg_query($query); |
---|
432 | } |
---|
433 | //---------------------------------------------------------- related categories |
---|
434 | $query = ' |
---|
435 | SELECT category_id,uppercats,commentable,global_rank |
---|
436 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
437 | INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id |
---|
438 | WHERE image_id = '.$page['image_id'].' |
---|
439 | '.get_sql_condition_FandF |
---|
440 | ( |
---|
441 | array |
---|
442 | ( |
---|
443 | 'forbidden_categories' => 'category_id', |
---|
444 | 'visible_categories' => 'category_id' |
---|
445 | ), |
---|
446 | 'AND' |
---|
447 | ).' |
---|
448 | ;'; |
---|
449 | $result = pwg_query($query); |
---|
450 | $related_categories = array(); |
---|
451 | while ($row = pwg_db_fetch_assoc($result)) |
---|
452 | { |
---|
453 | $row['commentable'] = get_boolean($row['commentable']); |
---|
454 | array_push($related_categories, $row); |
---|
455 | } |
---|
456 | usort($related_categories, 'global_rank_compare'); |
---|
457 | //-------------------------first, prev, current, next & last picture management |
---|
458 | $picture = array(); |
---|
459 | |
---|
460 | $ids = array($page['image_id']); |
---|
461 | if (isset($page['previous_item'])) |
---|
462 | { |
---|
463 | array_push($ids, $page['previous_item']); |
---|
464 | array_push($ids, $page['first_item']); |
---|
465 | } |
---|
466 | if (isset($page['next_item'])) |
---|
467 | { |
---|
468 | array_push($ids, $page['next_item']); |
---|
469 | array_push($ids, $page['last_item']); |
---|
470 | } |
---|
471 | |
---|
472 | $query = ' |
---|
473 | SELECT * |
---|
474 | FROM '.IMAGES_TABLE.' |
---|
475 | WHERE id IN ('.implode(',', $ids).') |
---|
476 | ;'; |
---|
477 | |
---|
478 | $result = pwg_query($query); |
---|
479 | |
---|
480 | while ($row = pwg_db_fetch_assoc($result)) |
---|
481 | { |
---|
482 | if (isset($page['previous_item']) and $row['id'] == $page['previous_item']) |
---|
483 | { |
---|
484 | $i = 'previous'; |
---|
485 | } |
---|
486 | elseif (isset($page['next_item']) and $row['id'] == $page['next_item']) |
---|
487 | { |
---|
488 | $i = 'next'; |
---|
489 | } |
---|
490 | elseif (isset($page['first_item']) and $row['id'] == $page['first_item']) |
---|
491 | { |
---|
492 | $i = 'first'; |
---|
493 | } |
---|
494 | elseif (isset($page['last_item']) and $row['id'] == $page['last_item']) |
---|
495 | { |
---|
496 | $i = 'last'; |
---|
497 | } |
---|
498 | else |
---|
499 | { |
---|
500 | $i = 'current'; |
---|
501 | } |
---|
502 | |
---|
503 | $row['src_image'] = new SrcImage($row); |
---|
504 | $row['derivatives'] = DerivativeImage::get_all($row['src_image']); |
---|
505 | |
---|
506 | if ($i=='current') |
---|
507 | { |
---|
508 | $row['element_path'] = get_element_path($row); |
---|
509 | |
---|
510 | if ( $row['src_image']->is_original() ) |
---|
511 | {// we have a photo |
---|
512 | if ( $user['enabled_high']=='true' ) |
---|
513 | { |
---|
514 | $row['element_url'] = $row['src_image']->get_url(); |
---|
515 | $row['download_url'] = get_action_url($row['id'], 'e', true); |
---|
516 | } |
---|
517 | } |
---|
518 | else |
---|
519 | { // not a pic - need download link |
---|
520 | $row['download_url'] = $row['element_url'] = get_element_url($row);; |
---|
521 | } |
---|
522 | } |
---|
523 | |
---|
524 | $row['url'] = duplicate_picture_url( |
---|
525 | array( |
---|
526 | 'image_id' => $row['id'], |
---|
527 | 'image_file' => $row['file'], |
---|
528 | ), |
---|
529 | array( |
---|
530 | 'start', |
---|
531 | ) |
---|
532 | ); |
---|
533 | |
---|
534 | $picture[$i] = $row; |
---|
535 | $picture[$i]['TITLE'] = render_element_name($row); |
---|
536 | |
---|
537 | if ('previous'==$i and $page['previous_item']==$page['first_item']) |
---|
538 | { |
---|
539 | $picture['first'] = $picture[$i]; |
---|
540 | } |
---|
541 | if ('next'==$i and $page['next_item']==$page['last_item']) |
---|
542 | { |
---|
543 | $picture['last'] = $picture[$i]; |
---|
544 | } |
---|
545 | } |
---|
546 | |
---|
547 | $slideshow_params = array(); |
---|
548 | $slideshow_url_params = array(); |
---|
549 | |
---|
550 | if (isset($_GET['slideshow'])) |
---|
551 | { |
---|
552 | $page['slideshow'] = true; |
---|
553 | $page['meta_robots'] = array('noindex'=>1, 'nofollow'=>1); |
---|
554 | |
---|
555 | $slideshow_params = decode_slideshow_params($_GET['slideshow']); |
---|
556 | $slideshow_url_params['slideshow'] = encode_slideshow_params($slideshow_params); |
---|
557 | |
---|
558 | if ($slideshow_params['play']) |
---|
559 | { |
---|
560 | $id_pict_redirect = ''; |
---|
561 | if (isset($page['next_item'])) |
---|
562 | { |
---|
563 | $id_pict_redirect = 'next'; |
---|
564 | } |
---|
565 | else |
---|
566 | { |
---|
567 | if ($slideshow_params['repeat'] and isset($page['first_item'])) |
---|
568 | { |
---|
569 | $id_pict_redirect = 'first'; |
---|
570 | } |
---|
571 | } |
---|
572 | |
---|
573 | if (!empty($id_pict_redirect)) |
---|
574 | { |
---|
575 | // $refresh, $url_link and $title are required for creating |
---|
576 | // an automated refresh page in header.tpl |
---|
577 | $refresh = $slideshow_params['period']; |
---|
578 | $url_link = add_url_params( |
---|
579 | $picture[$id_pict_redirect]['url'], |
---|
580 | $slideshow_url_params |
---|
581 | ); |
---|
582 | } |
---|
583 | } |
---|
584 | } |
---|
585 | else |
---|
586 | { |
---|
587 | $page['slideshow'] = false; |
---|
588 | } |
---|
589 | if ($page['slideshow'] and $conf['light_slideshow']) |
---|
590 | { |
---|
591 | $template->set_filenames( array('slideshow' => 'slideshow.tpl')); |
---|
592 | } |
---|
593 | else |
---|
594 | { |
---|
595 | $template->set_filenames( array('picture' => 'picture.tpl')); |
---|
596 | } |
---|
597 | |
---|
598 | $title = $picture['current']['TITLE']; |
---|
599 | $title_nb = ($page['current_rank'] + 1).'/'.count($page['items']); |
---|
600 | |
---|
601 | // metadata |
---|
602 | $url_metadata = duplicate_picture_url(); |
---|
603 | $url_metadata = add_url_params( $url_metadata, array('metadata'=>null) ); |
---|
604 | |
---|
605 | |
---|
606 | // do we have a plugin that can show metadata for something else than images? |
---|
607 | $metadata_showable = trigger_event( |
---|
608 | 'get_element_metadata_available', |
---|
609 | ( |
---|
610 | ($conf['show_exif'] or $conf['show_iptc']) |
---|
611 | and !$picture['current']['src_image']->is_mimetype() |
---|
612 | ), |
---|
613 | $picture['current'] |
---|
614 | ); |
---|
615 | |
---|
616 | if ( $metadata_showable and pwg_get_session_var('show_metadata') ) |
---|
617 | { |
---|
618 | $page['meta_robots']=array('noindex'=>1, 'nofollow'=>1); |
---|
619 | } |
---|
620 | |
---|
621 | |
---|
622 | $page['body_id'] = 'thePicturePage'; |
---|
623 | |
---|
624 | // allow plugins to change what we computed before passing data to template |
---|
625 | $picture = trigger_event('picture_pictures_data', $picture); |
---|
626 | |
---|
627 | //------------------------------------------------------- navigation management |
---|
628 | foreach (array('first','previous','next','last', 'current') as $which_image) |
---|
629 | { |
---|
630 | if (isset($picture[$which_image])) |
---|
631 | { |
---|
632 | $template->assign( |
---|
633 | $which_image, |
---|
634 | array_merge( |
---|
635 | $picture[$which_image], |
---|
636 | array( |
---|
637 | 'THUMB_SRC' => $picture[$which_image]['derivatives'][IMG_THUMB]->get_url(), |
---|
638 | // Params slideshow was transmit to navigation buttons |
---|
639 | 'U_IMG' => |
---|
640 | add_url_params( |
---|
641 | $picture[$which_image]['url'], $slideshow_url_params), |
---|
642 | ) |
---|
643 | ) |
---|
644 | ); |
---|
645 | } |
---|
646 | } |
---|
647 | if ($conf['picture_download_icon'] and !empty($picture['current']['download_url'])) |
---|
648 | { |
---|
649 | $template->append('current', array('U_DOWNLOAD' => $picture['current']['download_url']), true); |
---|
650 | } |
---|
651 | |
---|
652 | |
---|
653 | if ($page['slideshow']) |
---|
654 | { |
---|
655 | $tpl_slideshow = array(); |
---|
656 | |
---|
657 | //slideshow end |
---|
658 | $template->assign( |
---|
659 | array( |
---|
660 | 'U_SLIDESHOW_STOP' => $picture['current']['url'], |
---|
661 | ) |
---|
662 | ); |
---|
663 | |
---|
664 | foreach (array('repeat', 'play') as $p) |
---|
665 | { |
---|
666 | $var_name = |
---|
667 | 'U_' |
---|
668 | .($slideshow_params[$p] ? 'STOP_' : 'START_') |
---|
669 | .strtoupper($p); |
---|
670 | |
---|
671 | $tpl_slideshow[$var_name] = |
---|
672 | add_url_params( |
---|
673 | $picture['current']['url'], |
---|
674 | array('slideshow' => |
---|
675 | encode_slideshow_params( |
---|
676 | array_merge($slideshow_params, |
---|
677 | array($p => ! $slideshow_params[$p])) |
---|
678 | ) |
---|
679 | ) |
---|
680 | ); |
---|
681 | } |
---|
682 | |
---|
683 | foreach (array('dec', 'inc') as $op) |
---|
684 | { |
---|
685 | $new_period = $slideshow_params['period'] + ((($op == 'dec') ? -1 : 1) * $conf['slideshow_period_step']); |
---|
686 | $new_slideshow_params = |
---|
687 | correct_slideshow_params( |
---|
688 | array_merge($slideshow_params, |
---|
689 | array('period' => $new_period))); |
---|
690 | |
---|
691 | if ($new_slideshow_params['period'] === $new_period) |
---|
692 | { |
---|
693 | $var_name = 'U_'.strtoupper($op).'_PERIOD'; |
---|
694 | $tpl_slideshow[$var_name] = |
---|
695 | add_url_params( |
---|
696 | $picture['current']['url'], |
---|
697 | array('slideshow' => encode_slideshow_params($new_slideshow_params) |
---|
698 | ) |
---|
699 | ); |
---|
700 | } |
---|
701 | } |
---|
702 | $template->assign('slideshow', $tpl_slideshow ); |
---|
703 | } |
---|
704 | elseif ($conf['picture_slideshow_icon']) |
---|
705 | { |
---|
706 | $template->assign( |
---|
707 | array( |
---|
708 | 'U_SLIDESHOW_START' => |
---|
709 | add_url_params( |
---|
710 | $picture['current']['url'], |
---|
711 | array( 'slideshow'=>'')) |
---|
712 | ) |
---|
713 | ); |
---|
714 | } |
---|
715 | |
---|
716 | $template->assign( |
---|
717 | array( |
---|
718 | 'SECTION_TITLE' => $page['title'], |
---|
719 | 'PHOTO' => $title_nb, |
---|
720 | 'IS_HOME' => ('categories'==$page['section'] and !isset($page['category']) ), |
---|
721 | |
---|
722 | 'LEVEL_SEPARATOR' => $conf['level_separator'], |
---|
723 | |
---|
724 | 'U_UP' => $url_up, |
---|
725 | 'DISPLAY_NAV_BUTTONS' => $conf['picture_navigation_icons'], |
---|
726 | 'DISPLAY_NAV_THUMB' => $conf['picture_navigation_thumb'] |
---|
727 | ) |
---|
728 | ); |
---|
729 | |
---|
730 | if ($conf['picture_metadata_icon']) |
---|
731 | { |
---|
732 | $template->assign('U_METADATA', $url_metadata); |
---|
733 | } |
---|
734 | |
---|
735 | |
---|
736 | //------------------------------------------------------- upper menu management |
---|
737 | |
---|
738 | // admin links |
---|
739 | if (is_admin()) |
---|
740 | { |
---|
741 | if (isset($page['category'])) |
---|
742 | { |
---|
743 | $template->assign( |
---|
744 | array( |
---|
745 | 'U_SET_AS_REPRESENTATIVE' => add_url_params($url_self, |
---|
746 | array('action'=>'set_as_representative') |
---|
747 | ) |
---|
748 | ) |
---|
749 | ); |
---|
750 | } |
---|
751 | |
---|
752 | $url_admin = |
---|
753 | get_root_url().'admin.php?page=photo-'.$page['image_id'] |
---|
754 | .(isset($page['category']) ? '&cat_id='.$page['category']['id'] : '') |
---|
755 | ; |
---|
756 | |
---|
757 | $template->assign( |
---|
758 | array( |
---|
759 | 'U_CADDIE' => add_url_params($url_self, |
---|
760 | array('action'=>'add_to_caddie') |
---|
761 | ), |
---|
762 | 'U_ADMIN' => $url_admin, |
---|
763 | ) |
---|
764 | ); |
---|
765 | |
---|
766 | $template->assign('available_permission_levels', get_privacy_level_options()); |
---|
767 | } |
---|
768 | |
---|
769 | // favorite manipulation |
---|
770 | if (!is_a_guest() and $conf['picture_favorite_icon']) |
---|
771 | { |
---|
772 | // verify if the picture is already in the favorite of the user |
---|
773 | $query = ' |
---|
774 | SELECT COUNT(*) AS nb_fav |
---|
775 | FROM '.FAVORITES_TABLE.' |
---|
776 | WHERE image_id = '.$page['image_id'].' |
---|
777 | AND user_id = '.$user['id'].' |
---|
778 | ;'; |
---|
779 | $row = pwg_db_fetch_assoc( pwg_query($query) ); |
---|
780 | $is_favorite = $row['nb_fav'] != 0; |
---|
781 | |
---|
782 | $template->assign( |
---|
783 | 'favorite', |
---|
784 | array( |
---|
785 | 'IS_FAVORITE' => $is_favorite, |
---|
786 | 'U_FAVORITE' => add_url_params( |
---|
787 | $url_self, |
---|
788 | array('action'=> !$is_favorite ? 'add_to_favorites' : 'remove_from_favorites' ) |
---|
789 | ), |
---|
790 | ) |
---|
791 | ); |
---|
792 | } |
---|
793 | |
---|
794 | //--------------------------------------------------------- picture information |
---|
795 | // legend |
---|
796 | if (isset($picture['current']['comment']) |
---|
797 | and !empty($picture['current']['comment'])) |
---|
798 | { |
---|
799 | $template->assign( |
---|
800 | 'COMMENT_IMG', |
---|
801 | trigger_event('render_element_description', |
---|
802 | $picture['current']['comment']) |
---|
803 | ); |
---|
804 | } |
---|
805 | |
---|
806 | // author |
---|
807 | if (!empty($picture['current']['author'])) |
---|
808 | { |
---|
809 | $infos['INFO_AUTHOR'] = $picture['current']['author']; |
---|
810 | } |
---|
811 | |
---|
812 | // creation date |
---|
813 | if (!empty($picture['current']['date_creation'])) |
---|
814 | { |
---|
815 | $val = format_date($picture['current']['date_creation']); |
---|
816 | $url = make_index_url( |
---|
817 | array( |
---|
818 | 'chronology_field'=>'created', |
---|
819 | 'chronology_style'=>'monthly', |
---|
820 | 'chronology_view'=>'list', |
---|
821 | 'chronology_date' => explode('-', substr($picture['current']['date_creation'], 0, 10)) |
---|
822 | ) |
---|
823 | ); |
---|
824 | $infos['INFO_CREATION_DATE'] = |
---|
825 | '<a href="'.$url.'" rel="nofollow">'.$val.'</a>'; |
---|
826 | } |
---|
827 | |
---|
828 | // date of availability |
---|
829 | $val = format_date($picture['current']['date_available']); |
---|
830 | $url = make_index_url( |
---|
831 | array( |
---|
832 | 'chronology_field'=>'posted', |
---|
833 | 'chronology_style'=>'monthly', |
---|
834 | 'chronology_view'=>'list', |
---|
835 | 'chronology_date' => explode( |
---|
836 | '-', |
---|
837 | substr($picture['current']['date_available'], 0, 10) |
---|
838 | ) |
---|
839 | ) |
---|
840 | ); |
---|
841 | $infos['INFO_POSTED_DATE'] = '<a href="'.$url.'" rel="nofollow">'.$val.'</a>'; |
---|
842 | |
---|
843 | // size in pixels |
---|
844 | if ($picture['current']['src_image']->is_original() and isset($picture['current']['width']) ) |
---|
845 | { |
---|
846 | $infos['INFO_DIMENSIONS'] = |
---|
847 | $picture['current']['width'].'*'.$picture['current']['height']; |
---|
848 | } |
---|
849 | |
---|
850 | // filesize |
---|
851 | if (!empty($picture['current']['filesize'])) |
---|
852 | { |
---|
853 | $infos['INFO_FILESIZE'] = |
---|
854 | sprintf(l10n('%d Kb'), $picture['current']['filesize']); |
---|
855 | } |
---|
856 | |
---|
857 | // number of visits |
---|
858 | $infos['INFO_VISITS'] = $picture['current']['hit']; |
---|
859 | |
---|
860 | // file |
---|
861 | $infos['INFO_FILE'] = $picture['current']['file']; |
---|
862 | |
---|
863 | $template->assign($infos); |
---|
864 | $template->assign('display_info', unserialize($conf['picture_informations'])); |
---|
865 | |
---|
866 | // related tags |
---|
867 | $tags = get_common_tags( array($page['image_id']), -1); |
---|
868 | if ( count($tags) ) |
---|
869 | { |
---|
870 | foreach ($tags as $tag) |
---|
871 | { |
---|
872 | $template->append( |
---|
873 | 'related_tags', |
---|
874 | array_merge( $tag, |
---|
875 | array( |
---|
876 | 'URL' => make_index_url( |
---|
877 | array( |
---|
878 | 'tags' => array($tag) |
---|
879 | ) |
---|
880 | ), |
---|
881 | 'U_TAG_IMAGE' => duplicate_picture_url( |
---|
882 | array( |
---|
883 | 'section' => 'tags', |
---|
884 | 'tags' => array($tag) |
---|
885 | ) |
---|
886 | ) |
---|
887 | ) |
---|
888 | ) |
---|
889 | ); |
---|
890 | } |
---|
891 | } |
---|
892 | |
---|
893 | // related categories |
---|
894 | if ( count($related_categories)==1 and |
---|
895 | isset($page['category']) and |
---|
896 | $related_categories[0]['category_id']==$page['category']['id'] ) |
---|
897 | { // no need to go to db, we have all the info |
---|
898 | $template->append( |
---|
899 | 'related_categories', |
---|
900 | get_cat_display_name( $page['category']['upper_names'] ) |
---|
901 | ); |
---|
902 | } |
---|
903 | else |
---|
904 | { // use only 1 sql query to get names for all related categories |
---|
905 | $ids = array(); |
---|
906 | foreach ($related_categories as $category) |
---|
907 | {// add all uppercats to $ids |
---|
908 | $ids = array_merge($ids, explode(',', $category['uppercats']) ); |
---|
909 | } |
---|
910 | $ids = array_unique($ids); |
---|
911 | $query = ' |
---|
912 | SELECT id, name, permalink |
---|
913 | FROM '.CATEGORIES_TABLE.' |
---|
914 | WHERE id IN ('.implode(',',$ids).')'; |
---|
915 | $cat_map = hash_from_query($query, 'id'); |
---|
916 | foreach ($related_categories as $category) |
---|
917 | { |
---|
918 | $cats = array(); |
---|
919 | foreach ( explode(',', $category['uppercats']) as $id ) |
---|
920 | { |
---|
921 | $cats[] = $cat_map[$id]; |
---|
922 | } |
---|
923 | $template->append('related_categories', get_cat_display_name($cats) ); |
---|
924 | } |
---|
925 | } |
---|
926 | |
---|
927 | // maybe someone wants a special display (call it before page_header so that |
---|
928 | // they can add stylesheets) |
---|
929 | $element_content = trigger_event( |
---|
930 | 'render_element_content', |
---|
931 | '', |
---|
932 | $picture['current'] |
---|
933 | ); |
---|
934 | $template->assign( 'ELEMENT_CONTENT', $element_content ); |
---|
935 | |
---|
936 | if (isset($picture['next']) |
---|
937 | and $picture['next']['src_image']->is_original() |
---|
938 | and strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome/') === false) |
---|
939 | { |
---|
940 | $template->assign('U_PREFETCH', $picture['next']['derivatives'][pwg_get_session_var('picture_deriv', IMG_LARGE)]->get_url() ); |
---|
941 | } |
---|
942 | |
---|
943 | $template->assign('U_CANONICAL', make_picture_url( array('image_id'=>$picture['current']['id'], 'image_file'=>$picture['current']['file']) ) ); |
---|
944 | |
---|
945 | // +-----------------------------------------------------------------------+ |
---|
946 | // | sub pages | |
---|
947 | // +-----------------------------------------------------------------------+ |
---|
948 | |
---|
949 | include(PHPWG_ROOT_PATH.'include/picture_rate.inc.php'); |
---|
950 | if ($conf['activate_comments']) |
---|
951 | { |
---|
952 | include(PHPWG_ROOT_PATH.'include/picture_comment.inc.php'); |
---|
953 | } |
---|
954 | if ($metadata_showable and pwg_get_session_var('show_metadata') <> null ) |
---|
955 | { |
---|
956 | include(PHPWG_ROOT_PATH.'include/picture_metadata.inc.php'); |
---|
957 | } |
---|
958 | |
---|
959 | // include menubar |
---|
960 | $themeconf = $template->get_template_vars('themeconf'); |
---|
961 | if ($conf['picture_menu'] AND (!isset($themeconf['hide_menu_on']) OR !in_array('thePicturePage', $themeconf['hide_menu_on']))) |
---|
962 | { |
---|
963 | if (!isset($page['start'])) $page['start'] = 0; |
---|
964 | include( PHPWG_ROOT_PATH.'include/menubar.inc.php'); |
---|
965 | if (is_admin()) $template->assign('U_ADMIN', $url_admin); // overwrited by the menu |
---|
966 | } |
---|
967 | |
---|
968 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
969 | trigger_action('loc_end_picture'); |
---|
970 | if ($page['slideshow'] and $conf['light_slideshow']) |
---|
971 | { |
---|
972 | $template->pparse('slideshow'); |
---|
973 | } |
---|
974 | else |
---|
975 | { |
---|
976 | $template->pparse('picture'); |
---|
977 | } |
---|
978 | //------------------------------------------------------------ log informations |
---|
979 | pwg_log($picture['current']['id'], 'picture'); |
---|
980 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
981 | ?> |
---|