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