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