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