1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
5 | // | Copyright (C) 2003-2008 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | file : $Id: picture.php 2265 2008-03-08 01:38:37Z rvelices $ |
---|
8 | // | last update : $Date: 2008-03-08 01:38:37 +0000 (Sat, 08 Mar 2008) $ |
---|
9 | // | last modifier : $Author: rvelices $ |
---|
10 | // | revision : $Revision: 2265 $ |
---|
11 | // +-----------------------------------------------------------------------+ |
---|
12 | // | This program is free software; you can redistribute it and/or modify | |
---|
13 | // | it under the terms of the GNU General Public License as published by | |
---|
14 | // | the Free Software Foundation | |
---|
15 | // | | |
---|
16 | // | This program is distributed in the hope that it will be useful, but | |
---|
17 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
18 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
19 | // | General Public License for more details. | |
---|
20 | // | | |
---|
21 | // | You should have received a copy of the GNU General Public License | |
---|
22 | // | along with this program; if not, write to the Free Software | |
---|
23 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
24 | // | USA. | |
---|
25 | // +-----------------------------------------------------------------------+ |
---|
26 | |
---|
27 | define('PHPWG_ROOT_PATH','./'); |
---|
28 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); |
---|
29 | include(PHPWG_ROOT_PATH.'include/section_init.inc.php'); |
---|
30 | include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); |
---|
31 | |
---|
32 | // Check Access and exit when user status is not ok |
---|
33 | check_status(ACCESS_GUEST); |
---|
34 | |
---|
35 | // access authorization check |
---|
36 | if (isset($page['category'])) |
---|
37 | { |
---|
38 | check_restrictions($page['category']['id']); |
---|
39 | } |
---|
40 | |
---|
41 | // if this image_id doesn't correspond to this category, an error message is |
---|
42 | // displayed, and execution is stopped |
---|
43 | if (!in_array($page['image_id'], $page['items'])) |
---|
44 | { |
---|
45 | page_not_found( |
---|
46 | 'The requested image does not belong to this image set', |
---|
47 | duplicate_index_url() |
---|
48 | ); |
---|
49 | } |
---|
50 | |
---|
51 | // add default event handler for rendering element content |
---|
52 | add_event_handler( |
---|
53 | 'render_element_content', |
---|
54 | 'default_picture_content', |
---|
55 | EVENT_HANDLER_PRIORITY_NEUTRAL, |
---|
56 | 2 |
---|
57 | ); |
---|
58 | // add default event handler for rendering element description |
---|
59 | add_event_handler('render_element_description', 'nl2br'); |
---|
60 | |
---|
61 | trigger_action('loc_begin_picture'); |
---|
62 | |
---|
63 | // this is the default handler that generates the display for the element |
---|
64 | function default_picture_content($content, $element_info) |
---|
65 | { |
---|
66 | if ( !empty($content) ) |
---|
67 | {// someone hooked us - so we skip; |
---|
68 | return $content; |
---|
69 | } |
---|
70 | if (!isset($element_info['image_url'])) |
---|
71 | { // nothing to do |
---|
72 | return $content; |
---|
73 | } |
---|
74 | |
---|
75 | global $user, $page, $template; |
---|
76 | |
---|
77 | $template->set_filenames( |
---|
78 | array('default_content'=>'picture_content.tpl') |
---|
79 | ); |
---|
80 | |
---|
81 | if ( !$page['slideshow'] and isset($element_info['high_url']) ) |
---|
82 | { |
---|
83 | $uuid = uniqid(rand()); |
---|
84 | $template->assign( |
---|
85 | 'high', |
---|
86 | array( |
---|
87 | 'U_HIGH' => $element_info['high_url'], |
---|
88 | 'UUID' => $uuid, |
---|
89 | ) |
---|
90 | ); |
---|
91 | } |
---|
92 | $template->assign( array( |
---|
93 | 'SRC_IMG' => $element_info['image_url'], |
---|
94 | 'ALT_IMG' => $element_info['file'], |
---|
95 | 'WIDTH_IMG' => @$element_info['scaled_width'], |
---|
96 | 'HEIGHT_IMG' => @$element_info['scaled_height'], |
---|
97 | ) |
---|
98 | ); |
---|
99 | return $template->parse( 'default_content', true); |
---|
100 | } |
---|
101 | |
---|
102 | // +-----------------------------------------------------------------------+ |
---|
103 | // | initialization | |
---|
104 | // +-----------------------------------------------------------------------+ |
---|
105 | |
---|
106 | $page['rank_of'] = array_flip($page['items']); |
---|
107 | |
---|
108 | // caching first_rank, last_rank, current_rank in the displayed |
---|
109 | // section. This should also help in readability. |
---|
110 | $page['first_rank'] = 0; |
---|
111 | $page['last_rank'] = count($page['items']) - 1; |
---|
112 | $page['current_rank'] = $page['rank_of'][ $page['image_id'] ]; |
---|
113 | |
---|
114 | // caching current item : readability purpose |
---|
115 | $page['current_item'] = $page['image_id']; |
---|
116 | |
---|
117 | if ($page['current_rank'] != $page['first_rank']) |
---|
118 | { |
---|
119 | // caching first & previous item : readability purpose |
---|
120 | $page['previous_item'] = $page['items'][ $page['current_rank'] - 1 ]; |
---|
121 | $page['first_item'] = $page['items'][ $page['first_rank'] ]; |
---|
122 | } |
---|
123 | |
---|
124 | if ($page['current_rank'] != $page['last_rank']) |
---|
125 | { |
---|
126 | // caching next & last item : readability purpose |
---|
127 | $page['next_item'] = $page['items'][ $page['current_rank'] + 1 ]; |
---|
128 | $page['last_item'] = $page['items'][ $page['last_rank'] ]; |
---|
129 | } |
---|
130 | |
---|
131 | $url_up = duplicate_index_url( |
---|
132 | array( |
---|
133 | 'start' => |
---|
134 | floor($page['current_rank'] / $user['nb_image_page']) |
---|
135 | * $user['nb_image_page'] |
---|
136 | ), |
---|
137 | array( |
---|
138 | 'start', |
---|
139 | ) |
---|
140 | ); |
---|
141 | |
---|
142 | $url_self = duplicate_picture_url(); |
---|
143 | |
---|
144 | // +-----------------------------------------------------------------------+ |
---|
145 | // | actions | |
---|
146 | // +-----------------------------------------------------------------------+ |
---|
147 | |
---|
148 | /** |
---|
149 | * Actions are favorite adding, user comment deletion, setting the picture |
---|
150 | * as representative of the current category... |
---|
151 | * |
---|
152 | * Actions finish by a redirection |
---|
153 | */ |
---|
154 | |
---|
155 | if (isset($_GET['action'])) |
---|
156 | { |
---|
157 | switch ($_GET['action']) |
---|
158 | { |
---|
159 | case 'add_to_favorites' : |
---|
160 | { |
---|
161 | $query = ' |
---|
162 | INSERT INTO '.FAVORITES_TABLE.' |
---|
163 | (image_id,user_id) |
---|
164 | VALUES |
---|
165 | ('.$page['image_id'].','.$user['id'].') |
---|
166 | ;'; |
---|
167 | pwg_query($query); |
---|
168 | |
---|
169 | redirect($url_self); |
---|
170 | |
---|
171 | break; |
---|
172 | } |
---|
173 | case 'remove_from_favorites' : |
---|
174 | { |
---|
175 | $query = ' |
---|
176 | DELETE FROM '.FAVORITES_TABLE.' |
---|
177 | WHERE user_id = '.$user['id'].' |
---|
178 | AND image_id = '.$page['image_id'].' |
---|
179 | ;'; |
---|
180 | pwg_query($query); |
---|
181 | |
---|
182 | if ('favorites' == $page['section']) |
---|
183 | { |
---|
184 | redirect($url_up); |
---|
185 | } |
---|
186 | else |
---|
187 | { |
---|
188 | redirect($url_self); |
---|
189 | } |
---|
190 | |
---|
191 | break; |
---|
192 | } |
---|
193 | case 'set_as_representative' : |
---|
194 | { |
---|
195 | if (is_admin() and !is_adviser() and isset($page['category'])) |
---|
196 | { |
---|
197 | $query = ' |
---|
198 | UPDATE '.CATEGORIES_TABLE.' |
---|
199 | SET representative_picture_id = '.$page['image_id'].' |
---|
200 | WHERE id = '.$page['category']['id'].' |
---|
201 | ;'; |
---|
202 | pwg_query($query); |
---|
203 | } |
---|
204 | |
---|
205 | redirect($url_self); |
---|
206 | |
---|
207 | break; |
---|
208 | } |
---|
209 | case 'toggle_metadata' : |
---|
210 | { |
---|
211 | break; |
---|
212 | } |
---|
213 | case 'add_to_caddie' : |
---|
214 | { |
---|
215 | fill_caddie(array($page['image_id'])); |
---|
216 | redirect($url_self); |
---|
217 | break; |
---|
218 | } |
---|
219 | case 'rate' : |
---|
220 | { |
---|
221 | include_once(PHPWG_ROOT_PATH.'include/functions_rate.inc.php'); |
---|
222 | rate_picture( |
---|
223 | $page['image_id'], |
---|
224 | isset($_POST['rate']) ? $_POST['rate'] : $_GET['rate'] |
---|
225 | ); |
---|
226 | redirect($url_self); |
---|
227 | } |
---|
228 | case 'delete_comment' : |
---|
229 | { |
---|
230 | if (isset($_GET['comment_to_delete']) |
---|
231 | and is_numeric($_GET['comment_to_delete']) |
---|
232 | and is_admin() and !is_adviser() ) |
---|
233 | { |
---|
234 | $query = ' |
---|
235 | DELETE FROM '.COMMENTS_TABLE.' |
---|
236 | WHERE id = '.$_GET['comment_to_delete'].' |
---|
237 | ;'; |
---|
238 | pwg_query( $query ); |
---|
239 | } |
---|
240 | |
---|
241 | redirect($url_self); |
---|
242 | } |
---|
243 | } |
---|
244 | } |
---|
245 | |
---|
246 | // incrementation of the number of hits, we do this only if no action |
---|
247 | if (trigger_event('allow_increment_element_hit_count', !isset($_POST['content']) ) ) |
---|
248 | { |
---|
249 | $query = ' |
---|
250 | UPDATE |
---|
251 | '.IMAGES_TABLE.' |
---|
252 | SET hit = hit+1 |
---|
253 | WHERE id = '.$page['image_id'].' |
---|
254 | ;'; |
---|
255 | pwg_query($query); |
---|
256 | } |
---|
257 | //---------------------------------------------------------- related categories |
---|
258 | $query = ' |
---|
259 | SELECT category_id,uppercats,commentable,global_rank |
---|
260 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
261 | INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id |
---|
262 | WHERE image_id = '.$page['image_id'].' |
---|
263 | '.get_sql_condition_FandF |
---|
264 | ( |
---|
265 | array |
---|
266 | ( |
---|
267 | 'forbidden_categories' => 'category_id', |
---|
268 | 'visible_categories' => 'category_id' |
---|
269 | ), |
---|
270 | 'AND' |
---|
271 | ).' |
---|
272 | ;'; |
---|
273 | $result = pwg_query($query); |
---|
274 | $related_categories = array(); |
---|
275 | while ($row = mysql_fetch_array($result)) |
---|
276 | { |
---|
277 | array_push($related_categories, $row); |
---|
278 | } |
---|
279 | usort($related_categories, 'global_rank_compare'); |
---|
280 | //-------------------------first, prev, current, next & last picture management |
---|
281 | $picture = array(); |
---|
282 | |
---|
283 | $ids = array($page['image_id']); |
---|
284 | if (isset($page['previous_item'])) |
---|
285 | { |
---|
286 | array_push($ids, $page['previous_item']); |
---|
287 | array_push($ids, $page['first_item']); |
---|
288 | } |
---|
289 | if (isset($page['next_item'])) |
---|
290 | { |
---|
291 | array_push($ids, $page['next_item']); |
---|
292 | array_push($ids, $page['last_item']); |
---|
293 | } |
---|
294 | |
---|
295 | $query = ' |
---|
296 | SELECT * |
---|
297 | FROM '.IMAGES_TABLE.' |
---|
298 | WHERE id IN ('.implode(',', $ids).') |
---|
299 | ;'; |
---|
300 | |
---|
301 | $result = pwg_query($query); |
---|
302 | |
---|
303 | while ($row = mysql_fetch_assoc($result)) |
---|
304 | { |
---|
305 | if (isset($page['previous_item']) and $row['id'] == $page['previous_item']) |
---|
306 | { |
---|
307 | $i = 'previous'; |
---|
308 | } |
---|
309 | else if (isset($page['next_item']) and $row['id'] == $page['next_item']) |
---|
310 | { |
---|
311 | $i = 'next'; |
---|
312 | } |
---|
313 | else if (isset($page['first_item']) and $row['id'] == $page['first_item']) |
---|
314 | { |
---|
315 | $i = 'first'; |
---|
316 | } |
---|
317 | else if (isset($page['last_item']) and $row['id'] == $page['last_item']) |
---|
318 | { |
---|
319 | $i = 'last'; |
---|
320 | } |
---|
321 | else |
---|
322 | { |
---|
323 | $i = 'current'; |
---|
324 | } |
---|
325 | |
---|
326 | $picture[$i] = $row; |
---|
327 | |
---|
328 | $picture[$i]['is_picture'] = false; |
---|
329 | if (in_array(get_extension($row['file']), $conf['picture_ext'])) |
---|
330 | { |
---|
331 | $picture[$i]['is_picture'] = true; |
---|
332 | } |
---|
333 | |
---|
334 | // ------ build element_path and element_url |
---|
335 | $picture[$i]['element_path'] = get_element_path($picture[$i]); |
---|
336 | $picture[$i]['element_url'] = get_element_url($picture[$i]); |
---|
337 | |
---|
338 | // ------ build image_path and image_url |
---|
339 | if ($i=='current' or $i=='next') |
---|
340 | { |
---|
341 | $picture[$i]['image_path'] = get_image_path( $picture[$i] ); |
---|
342 | $picture[$i]['image_url'] = get_image_url( $picture[$i] ); |
---|
343 | } |
---|
344 | |
---|
345 | if ($i=='current') |
---|
346 | { |
---|
347 | if ( $picture[$i]['is_picture'] ) |
---|
348 | { |
---|
349 | if ( $user['enabled_high']=='true' ) |
---|
350 | { |
---|
351 | $hi_url=get_high_url($picture[$i]); |
---|
352 | if ( !empty($hi_url) ) |
---|
353 | { |
---|
354 | $picture[$i]['high_url'] = $hi_url; |
---|
355 | $picture[$i]['download_url'] = get_download_url('h',$picture[$i]); |
---|
356 | } |
---|
357 | } |
---|
358 | } |
---|
359 | else |
---|
360 | { // not a pic - need download link |
---|
361 | $picture[$i]['download_url'] = get_download_url('e',$picture[$i]); |
---|
362 | } |
---|
363 | } |
---|
364 | |
---|
365 | $picture[$i]['thumbnail'] = get_thumbnail_url($row); |
---|
366 | |
---|
367 | if ( !empty( $row['name'] ) ) |
---|
368 | { |
---|
369 | $picture[$i]['name'] = $row['name']; |
---|
370 | } |
---|
371 | else |
---|
372 | { |
---|
373 | $file_wo_ext = get_filename_wo_extension($row['file']); |
---|
374 | $picture[$i]['name'] = str_replace('_', ' ', $file_wo_ext); |
---|
375 | } |
---|
376 | |
---|
377 | $picture[$i]['url'] = duplicate_picture_url( |
---|
378 | array( |
---|
379 | 'image_id' => $row['id'], |
---|
380 | 'image_file' => $row['file'], |
---|
381 | ), |
---|
382 | array( |
---|
383 | 'start', |
---|
384 | ) |
---|
385 | ); |
---|
386 | |
---|
387 | if ('previous'==$i and $page['previous_item']==$page['first_item']) |
---|
388 | { |
---|
389 | $picture['first'] = $picture[$i]; |
---|
390 | } |
---|
391 | if ('next'==$i and $page['next_item']==$page['last_item']) |
---|
392 | { |
---|
393 | $picture['last'] = $picture[$i]; |
---|
394 | } |
---|
395 | } |
---|
396 | |
---|
397 | // calculation of width and height for the current picture |
---|
398 | if (empty($picture['current']['width'])) |
---|
399 | { |
---|
400 | $taille_image = @getimagesize($picture['current']['image_path']); |
---|
401 | if ($taille_image!==false) |
---|
402 | { |
---|
403 | $picture['current']['width'] = $taille_image[0]; |
---|
404 | $picture['current']['height']= $taille_image[1]; |
---|
405 | } |
---|
406 | } |
---|
407 | |
---|
408 | if (!empty($picture['current']['width'])) |
---|
409 | { |
---|
410 | list( |
---|
411 | $picture['current']['scaled_width'], |
---|
412 | $picture['current']['scaled_height'] |
---|
413 | ) = get_picture_size( |
---|
414 | $picture['current']['width'], |
---|
415 | $picture['current']['height'], |
---|
416 | @$user['maxwidth'], |
---|
417 | @$user['maxheight'] |
---|
418 | ); |
---|
419 | } |
---|
420 | |
---|
421 | $url_admin = |
---|
422 | get_root_url().'admin.php?page=picture_modify' |
---|
423 | .'&cat_id='.(isset($page['category']) ? $page['category']['id'] : '') |
---|
424 | .'&image_id='.$page['image_id'] |
---|
425 | ; |
---|
426 | |
---|
427 | $slideshow_params = array(); |
---|
428 | $slideshow_url_params = array(); |
---|
429 | |
---|
430 | if (isset($_GET['slideshow'])) |
---|
431 | { |
---|
432 | $page['slideshow'] = true; |
---|
433 | $page['meta_robots'] = array('noindex'=>1, 'nofollow'=>1); |
---|
434 | |
---|
435 | $slideshow_params = decode_slideshow_params($_GET['slideshow']); |
---|
436 | $slideshow_url_params['slideshow'] = encode_slideshow_params($slideshow_params); |
---|
437 | |
---|
438 | if ($slideshow_params['play']) |
---|
439 | { |
---|
440 | $id_pict_redirect = ''; |
---|
441 | if (isset($page['next_item'])) |
---|
442 | { |
---|
443 | $id_pict_redirect = 'next'; |
---|
444 | } |
---|
445 | else |
---|
446 | { |
---|
447 | if ($slideshow_params['repeat'] and isset($page['first_item'])) |
---|
448 | { |
---|
449 | $id_pict_redirect = 'first'; |
---|
450 | } |
---|
451 | } |
---|
452 | |
---|
453 | if (!empty($id_pict_redirect)) |
---|
454 | { |
---|
455 | // $redirect_msg, $refresh, $url_link and $title are required for creating |
---|
456 | // an automated refresh page in header.tpl |
---|
457 | $refresh = $slideshow_params['period']; |
---|
458 | $url_link = add_url_params( |
---|
459 | $picture[$id_pict_redirect]['url'], |
---|
460 | $slideshow_url_params |
---|
461 | ); |
---|
462 | $redirect_msg = nl2br(l10n('redirect_msg')); |
---|
463 | } |
---|
464 | } |
---|
465 | } |
---|
466 | else |
---|
467 | { |
---|
468 | $page['slideshow'] = false; |
---|
469 | } |
---|
470 | |
---|
471 | $template->set_filenames( |
---|
472 | array( |
---|
473 | 'picture' => |
---|
474 | (($page['slideshow'] and $conf['light_slideshow']) ? 'slideshow.tpl' : 'picture.tpl'), |
---|
475 | )); |
---|
476 | |
---|
477 | |
---|
478 | $title = $picture['current']['name']; |
---|
479 | $title_nb = ($page['current_rank'] + 1).'/'.count($page['items']); |
---|
480 | |
---|
481 | // metadata |
---|
482 | $url_metadata = duplicate_picture_url(); |
---|
483 | |
---|
484 | // do we have a plugin that can show metadata for something else than images? |
---|
485 | $metadata_showable = trigger_event( |
---|
486 | 'get_element_metadata_available', |
---|
487 | ( |
---|
488 | ($conf['show_exif'] or $conf['show_iptc']) |
---|
489 | and isset($picture['current']['image_path']) |
---|
490 | ), |
---|
491 | $picture['current']['path'] |
---|
492 | ); |
---|
493 | |
---|
494 | if ($metadata_showable) |
---|
495 | { |
---|
496 | if ( !isset($_GET['metadata']) ) |
---|
497 | { |
---|
498 | $url_metadata = add_url_params( $url_metadata, array('metadata'=>null) ); |
---|
499 | } |
---|
500 | else |
---|
501 | { |
---|
502 | $page['meta_robots']=array('noindex'=>1, 'nofollow'=>1); |
---|
503 | } |
---|
504 | } |
---|
505 | |
---|
506 | $page['body_id'] = 'thePicturePage'; |
---|
507 | |
---|
508 | // allow plugins to change what we computed before passing data to template |
---|
509 | $picture = trigger_event('picture_pictures_data', $picture); |
---|
510 | |
---|
511 | |
---|
512 | if (isset($picture['next']['image_url']) |
---|
513 | and $picture['next']['is_picture'] ) |
---|
514 | { |
---|
515 | $template->assign('U_PREFETCH', $picture['next']['image_url'] ); |
---|
516 | } |
---|
517 | |
---|
518 | //------------------------------------------------------- navigation management |
---|
519 | foreach (array('first','previous','next','last', 'current') as $which_image) |
---|
520 | { |
---|
521 | if (isset($picture[$which_image])) |
---|
522 | { |
---|
523 | $template->assign( |
---|
524 | $which_image, |
---|
525 | array( |
---|
526 | 'TITLE' => $picture[$which_image]['name'], |
---|
527 | 'THUMB_SRC' => $picture[$which_image]['thumbnail'], |
---|
528 | // Params slideshow was transmit to navigation buttons |
---|
529 | 'U_IMG' => |
---|
530 | add_url_params( |
---|
531 | $picture[$which_image]['url'], $slideshow_url_params), |
---|
532 | 'U_DOWNLOAD' => @$picture['current']['download_url'], |
---|
533 | ) |
---|
534 | ); |
---|
535 | } |
---|
536 | } |
---|
537 | |
---|
538 | |
---|
539 | if ($page['slideshow']) |
---|
540 | { |
---|
541 | // Add local-slideshow.css file if exists |
---|
542 | // Not only for ligth |
---|
543 | $css = PHPWG_ROOT_PATH . get_themeconf('template_dir') . '/theme/' |
---|
544 | . get_themeconf('theme') . '/local-slideshow.css'; |
---|
545 | if (file_exists($css)) |
---|
546 | { |
---|
547 | //TODO CORRECT THIS $template->assign_block_vars('slideshow', array()); |
---|
548 | } |
---|
549 | |
---|
550 | $tpl_slideshow = array(); |
---|
551 | |
---|
552 | //slideshow end |
---|
553 | $template->assign( |
---|
554 | array( |
---|
555 | 'U_SLIDESHOW_STOP' => $picture['current']['url'], |
---|
556 | ) |
---|
557 | ); |
---|
558 | |
---|
559 | foreach (array('repeat', 'play') as $p) |
---|
560 | { |
---|
561 | $var_name = |
---|
562 | 'U_' |
---|
563 | .($slideshow_params[$p] ? 'STOP_' : 'START_') |
---|
564 | .strtoupper($p); |
---|
565 | |
---|
566 | $tpl_slideshow[$var_name] = |
---|
567 | add_url_params( |
---|
568 | $picture['current']['url'], |
---|
569 | array('slideshow' => |
---|
570 | encode_slideshow_params( |
---|
571 | array_merge($slideshow_params, |
---|
572 | array($p => ! $slideshow_params[$p])) |
---|
573 | ) |
---|
574 | ) |
---|
575 | ); |
---|
576 | } |
---|
577 | |
---|
578 | foreach (array('dec', 'inc') as $op) |
---|
579 | { |
---|
580 | $new_period = $slideshow_params['period'] + ((($op == 'dec') ? -1 : 1) * $conf['slideshow_period_step']); |
---|
581 | $new_slideshow_params = |
---|
582 | correct_slideshow_params( |
---|
583 | array_merge($slideshow_params, |
---|
584 | array('period' => $new_period))); |
---|
585 | |
---|
586 | if ($new_slideshow_params['period'] === $new_period) |
---|
587 | { |
---|
588 | $var_name = 'U_'.strtoupper($op).'_PERIOD'; |
---|
589 | $tpl_slideshow[$var_name] = |
---|
590 | add_url_params( |
---|
591 | $picture['current']['url'], |
---|
592 | array('slideshow' => encode_slideshow_params($new_slideshow_params) |
---|
593 | ) |
---|
594 | ); |
---|
595 | } |
---|
596 | } |
---|
597 | $template->assign('slideshow', $tpl_slideshow ); |
---|
598 | } |
---|
599 | else |
---|
600 | { |
---|
601 | $template->assign( |
---|
602 | array( |
---|
603 | 'U_SLIDESHOW_START' => |
---|
604 | add_url_params( |
---|
605 | $picture['current']['url'], |
---|
606 | array( 'slideshow'=>'')) |
---|
607 | ) |
---|
608 | ); |
---|
609 | } |
---|
610 | |
---|
611 | $template->assign( |
---|
612 | array( |
---|
613 | 'SECTION_TITLE' => $page['title'], |
---|
614 | 'PHOTO' => $title_nb, |
---|
615 | 'SHOW_PICTURE_NAME_ON_TITLE' => $conf['show_picture_name_on_title'], |
---|
616 | |
---|
617 | 'LEVEL_SEPARATOR' => $conf['level_separator'], |
---|
618 | |
---|
619 | 'FILE_PICTURE_NAV_BUTTONS' => 'picture_nav_buttons.tpl', |
---|
620 | |
---|
621 | 'U_HOME' => make_index_url(), |
---|
622 | 'U_UP' => $url_up, |
---|
623 | 'U_METADATA' => $url_metadata, |
---|
624 | ) |
---|
625 | ); |
---|
626 | |
---|
627 | |
---|
628 | //------------------------------------------------------- upper menu management |
---|
629 | |
---|
630 | // admin links |
---|
631 | if (is_admin()) |
---|
632 | { |
---|
633 | if (isset($page['category'])) |
---|
634 | { |
---|
635 | $template->assign( |
---|
636 | array( |
---|
637 | 'U_SET_AS_REPRESENTATIVE' => add_url_params($url_self, |
---|
638 | array('action'=>'set_as_representative') |
---|
639 | ) |
---|
640 | ) |
---|
641 | ); |
---|
642 | } |
---|
643 | |
---|
644 | $template->assign( |
---|
645 | array( |
---|
646 | 'U_CADDIE' => add_url_params($url_self, |
---|
647 | array('action'=>'add_to_caddie') |
---|
648 | ), |
---|
649 | 'U_ADMIN' => $url_admin, |
---|
650 | ) |
---|
651 | ); |
---|
652 | } |
---|
653 | |
---|
654 | // favorite manipulation |
---|
655 | if (!is_a_guest()) |
---|
656 | { |
---|
657 | // verify if the picture is already in the favorite of the user |
---|
658 | $query = ' |
---|
659 | SELECT COUNT(*) AS nb_fav |
---|
660 | FROM '.FAVORITES_TABLE.' |
---|
661 | WHERE image_id = '.$page['image_id'].' |
---|
662 | AND user_id = '.$user['id'].' |
---|
663 | ;'; |
---|
664 | $result = pwg_query($query); |
---|
665 | $row = mysql_fetch_array($result); |
---|
666 | |
---|
667 | if ($row['nb_fav'] == 0) |
---|
668 | { |
---|
669 | $template->assign( |
---|
670 | 'favorite', |
---|
671 | array( |
---|
672 | 'FAVORITE_IMG' => |
---|
673 | get_root_url().get_themeconf('icon_dir').'/favorite.png', |
---|
674 | 'FAVORITE_HINT' => l10n('add_favorites_hint'), |
---|
675 | 'U_FAVORITE' => add_url_params( |
---|
676 | $url_self, |
---|
677 | array('action'=>'add_to_favorites') |
---|
678 | ), |
---|
679 | ) |
---|
680 | ); |
---|
681 | } |
---|
682 | else |
---|
683 | { |
---|
684 | $template->assign( |
---|
685 | 'favorite', |
---|
686 | array( |
---|
687 | 'FAVORITE_IMG' => |
---|
688 | get_root_url().get_themeconf('icon_dir').'/del_favorite.png', |
---|
689 | 'FAVORITE_HINT' => l10n('del_favorites_hint'), |
---|
690 | 'U_FAVORITE' => add_url_params( |
---|
691 | $url_self, |
---|
692 | array('action'=>'remove_from_favorites') |
---|
693 | ), |
---|
694 | ) |
---|
695 | ); |
---|
696 | } |
---|
697 | } |
---|
698 | |
---|
699 | //--------------------------------------------------------- picture information |
---|
700 | $header_infos = array(); //for html header use |
---|
701 | // legend |
---|
702 | if (isset($picture['current']['comment']) |
---|
703 | and !empty($picture['current']['comment'])) |
---|
704 | { |
---|
705 | $template->assign( |
---|
706 | 'COMMENT_IMG', |
---|
707 | trigger_event('render_element_description', |
---|
708 | $picture['current']['comment']) |
---|
709 | ); |
---|
710 | $header_infos['COMMENT'] = strip_tags($picture['current']['comment']); |
---|
711 | } |
---|
712 | |
---|
713 | $infos = array(); |
---|
714 | |
---|
715 | // author |
---|
716 | if (!empty($picture['current']['author'])) |
---|
717 | { |
---|
718 | $infos['INFO_AUTHOR'] = |
---|
719 | // FIXME because of search engine partial rewrite, giving the author |
---|
720 | // name threw GET is not supported anymore. This feature should come |
---|
721 | // back later, with a better design |
---|
722 | // '<a href="'. |
---|
723 | // PHPWG_ROOT_PATH.'category.php?cat=search'. |
---|
724 | // '&search=author:'.$picture['current']['author'] |
---|
725 | // .'">'.$picture['current']['author'].'</a>'; |
---|
726 | $picture['current']['author']; |
---|
727 | $header_infos['INFO_AUTHOR'] = $picture['current']['author']; |
---|
728 | } |
---|
729 | |
---|
730 | // creation date |
---|
731 | if (!empty($picture['current']['date_creation'])) |
---|
732 | { |
---|
733 | $val = format_date($picture['current']['date_creation']); |
---|
734 | $url = make_index_url( |
---|
735 | array( |
---|
736 | 'chronology_field'=>'created', |
---|
737 | 'chronology_style'=>'monthly', |
---|
738 | 'chronology_view'=>'list', |
---|
739 | 'chronology_date' => explode('-', $picture['current']['date_creation']) |
---|
740 | ) |
---|
741 | ); |
---|
742 | $infos['INFO_CREATION_DATE'] = |
---|
743 | '<a href="'.$url.'" rel="nofollow">'.$val.'</a>'; |
---|
744 | } |
---|
745 | |
---|
746 | // date of availability |
---|
747 | $val = format_date($picture['current']['date_available'], 'mysql_datetime'); |
---|
748 | $url = make_index_url( |
---|
749 | array( |
---|
750 | 'chronology_field'=>'posted', |
---|
751 | 'chronology_style'=>'monthly', |
---|
752 | 'chronology_view'=>'list', |
---|
753 | 'chronology_date' => explode( |
---|
754 | '-', |
---|
755 | substr($picture['current']['date_available'], 0, 10) |
---|
756 | ) |
---|
757 | ) |
---|
758 | ); |
---|
759 | $infos['INFO_POSTED_DATE'] = '<a href="'.$url.'" rel="nofollow">'.$val.'</a>'; |
---|
760 | |
---|
761 | // size in pixels |
---|
762 | if ($picture['current']['is_picture'] and isset($picture['current']['width']) ) |
---|
763 | { |
---|
764 | if ($picture['current']['scaled_width'] !== $picture['current']['width'] ) |
---|
765 | { |
---|
766 | $infos['INFO_DIMENSIONS'] = |
---|
767 | '<a href="'.$picture['current']['image_url'].'" title="'. |
---|
768 | l10n('Original dimensions').'">'. |
---|
769 | $picture['current']['width'].'*'.$picture['current']['height'].'</a>'; |
---|
770 | } |
---|
771 | else |
---|
772 | { |
---|
773 | $infos['INFO_DIMENSIONS'] = |
---|
774 | $picture['current']['width'].'*'.$picture['current']['height']; |
---|
775 | } |
---|
776 | } |
---|
777 | |
---|
778 | // filesize |
---|
779 | if (!empty($picture['current']['filesize'])) |
---|
780 | { |
---|
781 | $infos['INFO_FILESIZE'] = |
---|
782 | sprintf(l10n('%d Kb'), $picture['current']['filesize']); |
---|
783 | } |
---|
784 | |
---|
785 | // number of visits |
---|
786 | $infos['INFO_VISITS'] = $picture['current']['hit']; |
---|
787 | |
---|
788 | // file |
---|
789 | $infos['INFO_FILE'] = $picture['current']['file']; |
---|
790 | |
---|
791 | $template->assign($infos); |
---|
792 | |
---|
793 | // related tags |
---|
794 | $tags = get_common_tags( array($page['image_id']), -1); |
---|
795 | if ( count($tags) ) |
---|
796 | { |
---|
797 | foreach ($tags as $tag) |
---|
798 | { |
---|
799 | $template->append( |
---|
800 | 'related_tags', |
---|
801 | array( |
---|
802 | 'ID' => $tag['id'], |
---|
803 | 'NAME' => $tag['name'], |
---|
804 | 'U_TAG' => make_index_url( |
---|
805 | array( |
---|
806 | 'tags' => array($tag) |
---|
807 | ) |
---|
808 | ), |
---|
809 | 'U_TAG_IMAGE' => duplicate_picture_url( |
---|
810 | array( |
---|
811 | 'section' => 'tags', |
---|
812 | 'tags' => array($tag) |
---|
813 | ) |
---|
814 | ) |
---|
815 | ) |
---|
816 | ); |
---|
817 | } |
---|
818 | } |
---|
819 | |
---|
820 | // related categories |
---|
821 | foreach ($related_categories as $category) |
---|
822 | { |
---|
823 | $template->append( |
---|
824 | 'related_categories', |
---|
825 | count($related_categories) > 3 |
---|
826 | ? get_cat_display_name_cache($category['uppercats']) |
---|
827 | : get_cat_display_name_from_id($category['category_id']) |
---|
828 | ); |
---|
829 | } |
---|
830 | |
---|
831 | // maybe someone wants a special display (call it before page_header so that |
---|
832 | // they can add stylesheets) |
---|
833 | $element_content = trigger_event( |
---|
834 | 'render_element_content', |
---|
835 | '', |
---|
836 | $picture['current'] |
---|
837 | ); |
---|
838 | $template->assign( 'ELEMENT_CONTENT', $element_content ); |
---|
839 | |
---|
840 | // +-----------------------------------------------------------------------+ |
---|
841 | // | sub pages | |
---|
842 | // +-----------------------------------------------------------------------+ |
---|
843 | |
---|
844 | include(PHPWG_ROOT_PATH.'include/picture_rate.inc.php'); |
---|
845 | include(PHPWG_ROOT_PATH.'include/picture_comment.inc.php'); |
---|
846 | if ($metadata_showable and isset($_GET['metadata'])) |
---|
847 | { |
---|
848 | include(PHPWG_ROOT_PATH.'include/picture_metadata.inc.php'); |
---|
849 | } |
---|
850 | //------------------------------------------------------------ log informations |
---|
851 | pwg_log($picture['current']['id'], 'picture'); |
---|
852 | |
---|
853 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
854 | trigger_action('loc_end_picture'); |
---|
855 | $template->pparse('picture'); |
---|
856 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
857 | ?> |
---|