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