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-2005 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | branch : BSF (Best So Far) |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2005-11-16 21:26:29 +0000 (Wed, 16 Nov 2005) $ |
---|
10 | // | last modifier : $Author: plg $ |
---|
11 | // | revision : $Revision: 936 $ |
---|
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 | $rate_items = array(0,1,2,3,4,5); |
---|
29 | //--------------------------------------------------------------------- include |
---|
30 | define('PHPWG_ROOT_PATH','./'); |
---|
31 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); |
---|
32 | //-------------------------------------------------- access authorization check |
---|
33 | check_cat_id( $_GET['cat'] ); |
---|
34 | |
---|
35 | if (!isset($page['cat'])) |
---|
36 | { |
---|
37 | die($lang['access_forbiden']); |
---|
38 | } |
---|
39 | |
---|
40 | check_login_authorization(); |
---|
41 | if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) ) |
---|
42 | { |
---|
43 | check_restrictions( $page['cat'] ); |
---|
44 | } |
---|
45 | //---------------------------------------- incrementation of the number of hits |
---|
46 | $query = ' |
---|
47 | UPDATE '.IMAGES_TABLE.' |
---|
48 | SET hit = hit+1 |
---|
49 | WHERE id = '.$_GET['image_id'].' |
---|
50 | ;'; |
---|
51 | @pwg_query( $query ); |
---|
52 | //-------------------------------------------------------------- initialization |
---|
53 | initialize_category( 'picture' ); |
---|
54 | // retrieving the number of the picture in its category (in order) |
---|
55 | $query = ' |
---|
56 | SELECT DISTINCT(id) |
---|
57 | FROM '.IMAGES_TABLE.' |
---|
58 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id |
---|
59 | '.$page['where'].' |
---|
60 | '.$conf['order_by'].' |
---|
61 | ;'; |
---|
62 | $result = pwg_query( $query ); |
---|
63 | $page['num'] = 0; |
---|
64 | $belongs = false; |
---|
65 | while ($row = mysql_fetch_array($result)) |
---|
66 | { |
---|
67 | if ($row['id'] == $_GET['image_id']) |
---|
68 | { |
---|
69 | $belongs = true; |
---|
70 | break; |
---|
71 | } |
---|
72 | $page['num']++; |
---|
73 | } |
---|
74 | // if this image_id doesn't correspond to this category, an error message is |
---|
75 | // displayed, and execution is stopped |
---|
76 | if (!$belongs) |
---|
77 | { |
---|
78 | echo '<div style="text-align:center;">'.$lang['access_forbiden'].'<br />'; |
---|
79 | echo '<a href="'.add_session_id( PHPWG_ROOT_PATH.'category.php' ).'">'; |
---|
80 | echo $lang['thumbnails'].'</a></div>'; |
---|
81 | exit(); |
---|
82 | } |
---|
83 | //---------------------------------------------------------- related categories |
---|
84 | $query = ' |
---|
85 | SELECT category_id,uppercats,commentable,global_rank |
---|
86 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
87 | INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id |
---|
88 | WHERE image_id = '.$_GET['image_id']; |
---|
89 | if ($user['forbidden_categories'] != '') |
---|
90 | { |
---|
91 | $query.= ' |
---|
92 | AND category_id NOT IN ('.$user['forbidden_categories'].')'; |
---|
93 | } |
---|
94 | $query.= ' |
---|
95 | ;'; |
---|
96 | $result = pwg_query($query); |
---|
97 | $related_categories = array(); |
---|
98 | while ($row = mysql_fetch_array($result)) |
---|
99 | { |
---|
100 | array_push($related_categories, $row); |
---|
101 | } |
---|
102 | usort($related_categories, 'global_rank_compare'); |
---|
103 | //------------------------------------- prev, current & next picture management |
---|
104 | $picture = array(); |
---|
105 | |
---|
106 | if ($page['num'] == 0) |
---|
107 | { |
---|
108 | $has_prev = false; |
---|
109 | } |
---|
110 | else |
---|
111 | { |
---|
112 | $has_prev = true; |
---|
113 | } |
---|
114 | |
---|
115 | if ($page['num'] == $page['cat_nb_images'] - 1) |
---|
116 | { |
---|
117 | $has_next = false; |
---|
118 | } |
---|
119 | else |
---|
120 | { |
---|
121 | $has_next = true; |
---|
122 | } |
---|
123 | |
---|
124 | $query = ' |
---|
125 | SELECT DISTINCT(i.id), i.* |
---|
126 | FROM '.IMAGES_TABLE.' AS i |
---|
127 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON i.id = ic.image_id |
---|
128 | '.$page['where'].' |
---|
129 | '.$conf['order_by'].' |
---|
130 | '; |
---|
131 | |
---|
132 | if ( !$has_prev ) |
---|
133 | { |
---|
134 | $query.= ' LIMIT 0,2'; |
---|
135 | } |
---|
136 | else |
---|
137 | { |
---|
138 | $query.= ' LIMIT '.($page['num'] - 1).',3'; |
---|
139 | } |
---|
140 | $query.= ';'; |
---|
141 | |
---|
142 | $result = pwg_query( $query ); |
---|
143 | $indexes = array('prev', 'current', 'next'); |
---|
144 | |
---|
145 | foreach (array('prev', 'current', 'next') as $i) |
---|
146 | { |
---|
147 | if ($i == 'prev' and !$has_prev) |
---|
148 | { |
---|
149 | continue; |
---|
150 | } |
---|
151 | if ($i == 'next' and !$has_next) |
---|
152 | { |
---|
153 | break; |
---|
154 | } |
---|
155 | |
---|
156 | $row = mysql_fetch_array($result); |
---|
157 | foreach (array_keys($row) as $key) |
---|
158 | { |
---|
159 | if (!is_numeric($key)) |
---|
160 | { |
---|
161 | $picture[$i][$key] = $row[$key]; |
---|
162 | } |
---|
163 | } |
---|
164 | |
---|
165 | $picture[$i]['is_picture'] = false; |
---|
166 | if (in_array(get_extension($row['file']), $conf['picture_ext'])) |
---|
167 | { |
---|
168 | $picture[$i]['is_picture'] = true; |
---|
169 | } |
---|
170 | |
---|
171 | $cat_directory = dirname($row['path']); |
---|
172 | $file_wo_ext = get_filename_wo_extension($row['file']); |
---|
173 | |
---|
174 | $icon = PHPWG_ROOT_PATH.'template/'.$user['template'].'/mimetypes/'; |
---|
175 | $icon.= strtolower(get_extension($row['file'])).'.png'; |
---|
176 | |
---|
177 | if (isset($row['representative_ext']) and $row['representative_ext'] != '') |
---|
178 | { |
---|
179 | $picture[$i]['src'] = $cat_directory.'/pwg_representative/'; |
---|
180 | $picture[$i]['src'].= $file_wo_ext.'.'.$row['representative_ext']; |
---|
181 | } |
---|
182 | else |
---|
183 | { |
---|
184 | $picture[$i]['src'] = $icon; |
---|
185 | } |
---|
186 | // special case for picture files |
---|
187 | if ($picture[$i]['is_picture']) |
---|
188 | { |
---|
189 | $picture[$i]['src'] = $row['path']; |
---|
190 | // if we are working on the "current" element, we search if there is a |
---|
191 | // high quality picture |
---|
192 | // FIXME : with remote pictures, this "remote fopen" takes long... |
---|
193 | if ($i == 'current') |
---|
194 | { |
---|
195 | if (@fopen($cat_directory.'/pwg_high/'.$row['file'], 'r')) |
---|
196 | { |
---|
197 | $picture[$i]['high'] = $cat_directory.'/pwg_high/'.$row['file']; |
---|
198 | } |
---|
199 | } |
---|
200 | } |
---|
201 | |
---|
202 | // if picture is not a file, we need the download link |
---|
203 | if (!$picture[$i]['is_picture']) |
---|
204 | { |
---|
205 | $picture[$i]['download'] = $row['path']; |
---|
206 | } |
---|
207 | |
---|
208 | $picture[$i]['thumbnail'] = get_thumbnail_src($row['path'], @$row['tn_ext']); |
---|
209 | |
---|
210 | if ( !empty( $row['name'] ) ) |
---|
211 | { |
---|
212 | $picture[$i]['name'] = $row['name']; |
---|
213 | } |
---|
214 | else |
---|
215 | { |
---|
216 | $picture[$i]['name'] = str_replace('_', ' ', $file_wo_ext); |
---|
217 | } |
---|
218 | |
---|
219 | $picture[$i]['url'] = PHPWG_ROOT_PATH.'picture.php'; |
---|
220 | $picture[$i]['url'].= get_query_string_diff(array('image_id','add_fav', |
---|
221 | 'slideshow','rate')); |
---|
222 | $picture[$i]['url'].= '&image_id='.$row['id']; |
---|
223 | } |
---|
224 | |
---|
225 | $url_up = PHPWG_ROOT_PATH.'category.php?cat='.$page['cat'].'&'; |
---|
226 | $url_up.= 'num='.$page['num']; |
---|
227 | if ( $page['cat'] == 'search' ) |
---|
228 | { |
---|
229 | $url_up.= "&search=".$_GET['search']; |
---|
230 | } |
---|
231 | if ( $page['cat'] == 'list' ) |
---|
232 | { |
---|
233 | $url_up.= "&list=".$_GET['list']; |
---|
234 | } |
---|
235 | |
---|
236 | $url_admin = PHPWG_ROOT_PATH.'admin.php?page=picture_modify'; |
---|
237 | $url_admin.= '&cat_id='.$page['cat']; |
---|
238 | $url_admin.= '&image_id='.$_GET['image_id']; |
---|
239 | |
---|
240 | $url_slide = $picture['current']['url']; |
---|
241 | $url_slide.= '&slideshow='.$conf['slideshow_period']; |
---|
242 | //----------------------------------------------------------- rate registration |
---|
243 | if (isset($_GET['rate']) |
---|
244 | and $conf['rate'] |
---|
245 | and !$user['is_the_guest'] |
---|
246 | and in_array($_GET['rate'], $rate_items)) |
---|
247 | { |
---|
248 | $query = ' |
---|
249 | DELETE |
---|
250 | FROM '.RATE_TABLE.' |
---|
251 | WHERE user_id = '.$user['id'].' |
---|
252 | AND element_id = '.$_GET['image_id'].' |
---|
253 | ;'; |
---|
254 | pwg_query($query); |
---|
255 | $query = ' |
---|
256 | INSERT INTO '.RATE_TABLE.' |
---|
257 | (user_id,element_id,rate) |
---|
258 | VALUES |
---|
259 | ('.$user['id'].','.$_GET['image_id'].','.$_GET['rate'].') |
---|
260 | ;'; |
---|
261 | pwg_query($query); |
---|
262 | |
---|
263 | // update of images.average_rate field |
---|
264 | $query = ' |
---|
265 | SELECT ROUND(AVG(rate),2) AS average_rate |
---|
266 | FROM '.RATE_TABLE.' |
---|
267 | WHERE element_id = '.$_GET['image_id'].' |
---|
268 | ;'; |
---|
269 | $row = mysql_fetch_array(pwg_query($query)); |
---|
270 | $query = ' |
---|
271 | UPDATE '.IMAGES_TABLE.' |
---|
272 | SET average_rate = '.$row['average_rate'].' |
---|
273 | WHERE id = '.$_GET['image_id'].' |
---|
274 | ;'; |
---|
275 | pwg_query($query); |
---|
276 | } |
---|
277 | //--------------------------------------------------------- favorite management |
---|
278 | if ( isset( $_GET['add_fav'] ) ) |
---|
279 | { |
---|
280 | $query = 'DELETE FROM '.FAVORITES_TABLE; |
---|
281 | $query.= ' WHERE user_id = '.$user['id']; |
---|
282 | $query.= ' AND image_id = '.$picture['current']['id']; |
---|
283 | $query.= ';'; |
---|
284 | $result = pwg_query( $query ); |
---|
285 | |
---|
286 | if ( $_GET['add_fav'] == 1 ) |
---|
287 | { |
---|
288 | $query = 'INSERT INTO '.FAVORITES_TABLE; |
---|
289 | $query.= ' (image_id,user_id) VALUES'; |
---|
290 | $query.= ' ('.$picture['current']['id'].','.$user['id'].')'; |
---|
291 | $query.= ';'; |
---|
292 | $result = pwg_query( $query ); |
---|
293 | } |
---|
294 | if ( !$_GET['add_fav'] and $page['cat'] == 'fav' ) |
---|
295 | { |
---|
296 | if (!$has_prev and !$has_next) |
---|
297 | { |
---|
298 | // there is no favorite picture anymore we redirect the user to the |
---|
299 | // category page |
---|
300 | $url = add_session_id($url_up); |
---|
301 | redirect($url); |
---|
302 | } |
---|
303 | else if (!$has_prev) |
---|
304 | { |
---|
305 | $url = str_replace( '&', '&', $picture['next']['url'] ); |
---|
306 | $url = add_session_id( $url, true); |
---|
307 | } |
---|
308 | else |
---|
309 | { |
---|
310 | $url = str_replace('&', '&', $picture['prev']['url'] ); |
---|
311 | $url = add_session_id( $url, true); |
---|
312 | } |
---|
313 | redirect( $url ); |
---|
314 | } |
---|
315 | } |
---|
316 | |
---|
317 | //------------------------------------------------------ comment registeration |
---|
318 | if ( isset( $_POST['content'] ) && !empty($_POST['content']) ) |
---|
319 | { |
---|
320 | $register_comment = true; |
---|
321 | $author = !empty($_POST['author'])?$_POST['author']:$lang['guest']; |
---|
322 | // if a guest try to use the name of an already existing user, he must be |
---|
323 | // rejected |
---|
324 | if ( $author != $user['username'] ) |
---|
325 | { |
---|
326 | $query = 'SELECT COUNT(*) AS user_exists'; |
---|
327 | $query.= ' FROM '.USERS_TABLE; |
---|
328 | $query.= " WHERE username = '".$author."'"; |
---|
329 | $query.= ';'; |
---|
330 | $row = mysql_fetch_array( pwg_query( $query ) ); |
---|
331 | if ( $row['user_exists'] == 1 ) |
---|
332 | { |
---|
333 | $template->assign_block_vars( |
---|
334 | 'information', |
---|
335 | array('INFORMATION'=>$lang['comment_user_exists'])); |
---|
336 | $register_comment = false; |
---|
337 | } |
---|
338 | } |
---|
339 | |
---|
340 | if ( $register_comment ) |
---|
341 | { |
---|
342 | // anti-flood system |
---|
343 | $reference_date = time() - $conf['anti-flood_time']; |
---|
344 | $query = 'SELECT id FROM '.COMMENTS_TABLE; |
---|
345 | $query.= ' WHERE date > FROM_UNIXTIME('.$reference_date.')'; |
---|
346 | $query.= " AND author = '".$author."'"; |
---|
347 | $query.= ';'; |
---|
348 | if ( mysql_num_rows( pwg_query( $query ) ) == 0 |
---|
349 | or $conf['anti-flood_time'] == 0 ) |
---|
350 | { |
---|
351 | $query = 'INSERT INTO '.COMMENTS_TABLE; |
---|
352 | $query.= ' (author,date,image_id,content,validated) VALUES ('; |
---|
353 | $query.= "'".$author."'"; |
---|
354 | $query.= ',NOW(),'.$_GET['image_id']; |
---|
355 | $query.= ",'".htmlspecialchars( $_POST['content'], ENT_QUOTES)."'"; |
---|
356 | if ( !$conf['comments_validation'] or $user['status'] == 'admin' ) |
---|
357 | { |
---|
358 | $query.= ",'true'"; |
---|
359 | } |
---|
360 | else |
---|
361 | { |
---|
362 | $query.= ",'false'"; |
---|
363 | } |
---|
364 | $query.= ');'; |
---|
365 | pwg_query( $query ); |
---|
366 | // information message |
---|
367 | $message = $lang['comment_added']; |
---|
368 | if ( $conf['comments_validation'] and $user['status'] != 'admin' ) |
---|
369 | { |
---|
370 | $message.= '<br />'.$lang['comment_to_validate']; |
---|
371 | } |
---|
372 | $template->assign_block_vars('information', |
---|
373 | array('INFORMATION'=>$message)); |
---|
374 | // notification to the administrators |
---|
375 | if ( $conf['mail_notification'] ) |
---|
376 | { |
---|
377 | // find any related category (can be unreachable to this admin) |
---|
378 | $category = $related_categories[0]; |
---|
379 | // locally, we change the $conf['level_separator'] |
---|
380 | $conf_separator = $conf['level_separator']; |
---|
381 | $conf['level_separator'] = ' > '; |
---|
382 | $cat_name = get_cat_display_name_cache($category['uppercats'], |
---|
383 | '', |
---|
384 | false); |
---|
385 | $conf['level_separator'] = $conf_separator; |
---|
386 | |
---|
387 | $cat_name = strip_tags( $cat_name ); |
---|
388 | notify( 'comment', $cat_name.' > '.$picture['current']['name']); |
---|
389 | } |
---|
390 | } |
---|
391 | else |
---|
392 | { |
---|
393 | // information message |
---|
394 | $template->assign_block_vars( |
---|
395 | 'information', |
---|
396 | array('INFORMATION'=>$lang['comment_anti-flood'])); |
---|
397 | } |
---|
398 | } |
---|
399 | } |
---|
400 | // comment deletion |
---|
401 | if ( isset( $_GET['del'] ) |
---|
402 | and is_numeric( $_GET['del'] ) |
---|
403 | and $user['status'] == 'admin' ) |
---|
404 | { |
---|
405 | $query = 'DELETE FROM '.COMMENTS_TABLE; |
---|
406 | $query.= ' WHERE id = '.$_GET['del']; |
---|
407 | $query.= ';'; |
---|
408 | pwg_query( $query ); |
---|
409 | } |
---|
410 | |
---|
411 | // |
---|
412 | // Start output of page |
---|
413 | // |
---|
414 | |
---|
415 | $title = $picture['current']['name']; |
---|
416 | $refresh = 0; |
---|
417 | if ( isset( $_GET['slideshow'] ) and $has_next ) |
---|
418 | { |
---|
419 | $refresh= $_GET['slideshow']; |
---|
420 | $url_link = $picture['next']['url'].'&slideshow='.$refresh; |
---|
421 | } |
---|
422 | |
---|
423 | $title_img = $picture['current']['name']; |
---|
424 | $title_nb = ''; |
---|
425 | if (is_numeric( $page['cat'] )) |
---|
426 | { |
---|
427 | $title_img = replace_space(get_cat_display_name($page['cat_name'])); |
---|
428 | $n = $page['num'] + 1; |
---|
429 | $title_nb = $n.'/'.$page['cat_nb_images']; |
---|
430 | } |
---|
431 | else if ( $page['cat'] == 'search' ) |
---|
432 | { |
---|
433 | $title_img = replace_search( $title_img, $_GET['search'] ); |
---|
434 | } |
---|
435 | |
---|
436 | // calculation of width and height |
---|
437 | if (empty($picture['current']['width'])) |
---|
438 | { |
---|
439 | $taille_image = @getimagesize($picture['current']['src']); |
---|
440 | $original_width = $taille_image[0]; |
---|
441 | $original_height = $taille_image[1]; |
---|
442 | } |
---|
443 | else |
---|
444 | { |
---|
445 | $original_width = $picture['current']['width']; |
---|
446 | $original_height = $picture['current']['height']; |
---|
447 | } |
---|
448 | |
---|
449 | $picture_size = get_picture_size($original_width, $original_height, |
---|
450 | @$user['maxwidth'], @$user['maxheight']); |
---|
451 | |
---|
452 | // metadata |
---|
453 | if ($conf['show_exif'] or $conf['show_iptc']) |
---|
454 | { |
---|
455 | $metadata_showable = true; |
---|
456 | } |
---|
457 | else |
---|
458 | { |
---|
459 | $metadata_showable = false; |
---|
460 | } |
---|
461 | |
---|
462 | $url_metadata = PHPWG_ROOT_PATH.'picture.php'; |
---|
463 | $url_metadata .= get_query_string_diff(array('add_fav', 'slideshow', 'show_metadata')); |
---|
464 | if ($metadata_showable and !isset($_GET['show_metadata'])) |
---|
465 | { |
---|
466 | $url_metadata.= '&show_metadata=1'; |
---|
467 | } |
---|
468 | |
---|
469 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
470 | $template->set_filenames(array('picture'=>'picture.tpl')); |
---|
471 | |
---|
472 | $template->assign_vars(array( |
---|
473 | 'CATEGORY' => $title_img, |
---|
474 | 'PHOTO' => $title_nb, |
---|
475 | 'TITLE' => $picture['current']['name'], |
---|
476 | 'SRC_IMG' => $picture['current']['src'], |
---|
477 | 'ALT_IMG' => $picture['current']['file'], |
---|
478 | 'WIDTH_IMG' => $picture_size[0], |
---|
479 | 'HEIGHT_IMG' => $picture_size[1], |
---|
480 | |
---|
481 | 'LEVEL_SEPARATOR' => $conf['level_separator'], |
---|
482 | |
---|
483 | 'L_HOME' => $lang['home'], |
---|
484 | 'L_SLIDESHOW' => $lang['slideshow'], |
---|
485 | 'L_STOP_SLIDESHOW' => $lang['slideshow_stop'], |
---|
486 | 'L_PREV_IMG' =>$lang['previous_page'].' : ', |
---|
487 | 'L_NEXT_IMG' =>$lang['next_page'].' : ', |
---|
488 | 'L_ADMIN' =>$lang['link_info_image'], |
---|
489 | 'L_COMMENT_TITLE' =>$lang['comments_title'], |
---|
490 | 'L_ADD_COMMENT' =>$lang['comments_add'], |
---|
491 | 'L_DELETE_COMMENT' =>$lang['comments_del'], |
---|
492 | 'L_DELETE' =>$lang['delete'], |
---|
493 | 'L_SUBMIT' =>$lang['submit'], |
---|
494 | 'L_AUTHOR' =>$lang['author'], |
---|
495 | 'L_COMMENT' =>$lang['comment'], |
---|
496 | 'L_DOWNLOAD' => $lang['download'], |
---|
497 | 'L_DOWNLOAD_HINT' => $lang['download_hint'], |
---|
498 | 'L_PICTURE_METADATA' => $lang['picture_show_metadata'], |
---|
499 | 'L_PICTURE_HIGH' => $lang['picture_high'], |
---|
500 | 'L_UP_HINT' => $lang['home_hint'], |
---|
501 | 'L_UP_ALT' => $lang['home'], |
---|
502 | |
---|
503 | 'U_HOME' => add_session_id(PHPWG_ROOT_PATH.'category.php'), |
---|
504 | 'U_UP' => add_session_id($url_up), |
---|
505 | 'U_METADATA' => add_session_id($url_metadata), |
---|
506 | 'U_ADMIN' => add_session_id($url_admin), |
---|
507 | 'U_SLIDESHOW'=> add_session_id($url_slide), |
---|
508 | 'U_ADD_COMMENT' => add_session_id(str_replace( '&', '&', $_SERVER['REQUEST_URI'] )) |
---|
509 | ) |
---|
510 | ); |
---|
511 | //------------------------------------------------------- upper menu management |
---|
512 | // download link if file is not a picture |
---|
513 | if (!$picture['current']['is_picture']) |
---|
514 | { |
---|
515 | $template->assign_block_vars( |
---|
516 | 'download', |
---|
517 | array('U_DOWNLOAD' => $picture['current']['download'])); |
---|
518 | } |
---|
519 | else |
---|
520 | { |
---|
521 | $template->assign_block_vars( |
---|
522 | 'ecard', |
---|
523 | array('U_ECARD' => $picture['current']['url'])); |
---|
524 | } |
---|
525 | // display a high quality link if present |
---|
526 | if (isset($picture['current']['high'])) |
---|
527 | { |
---|
528 | $full_size = @getimagesize($picture['current']['high']); |
---|
529 | $full_width = $full_size[0]; |
---|
530 | $full_height = $full_size[1]; |
---|
531 | $uuid = uniqid(rand()); |
---|
532 | $template->assign_block_vars('high', array( |
---|
533 | 'U_HIGH' => $picture['current']['high'], |
---|
534 | 'UUID'=>$uuid, |
---|
535 | 'WIDTH_IMG'=>($full_width + 16), |
---|
536 | 'HEIGHT_IMG'=>($full_height + 16) |
---|
537 | )); |
---|
538 | } |
---|
539 | //------------------------------------------------------- favorite manipulation |
---|
540 | if ( !$user['is_the_guest'] ) |
---|
541 | { |
---|
542 | // verify if the picture is already in the favorite of the user |
---|
543 | $query = 'SELECT COUNT(*) AS nb_fav'; |
---|
544 | $query.= ' FROM '.FAVORITES_TABLE.' WHERE image_id = '.$_GET['image_id']; |
---|
545 | $query.= ' AND user_id = '.$user['id'].';'; |
---|
546 | $result = pwg_query( $query ); |
---|
547 | $row = mysql_fetch_array( $result ); |
---|
548 | if (!$row['nb_fav']) |
---|
549 | { |
---|
550 | $url = PHPWG_ROOT_PATH.'picture.php'; |
---|
551 | $url.= get_query_string_diff(array('rate','add_fav')); |
---|
552 | $url.= '&add_fav=1'; |
---|
553 | |
---|
554 | $template->assign_block_vars( |
---|
555 | 'favorite', |
---|
556 | array( |
---|
557 | 'FAVORITE_IMG' => PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/favorite.gif', |
---|
558 | 'FAVORITE_HINT' =>$lang['add_favorites_hint'], |
---|
559 | 'FAVORITE_ALT' =>$lang['add_favorites_alt'], |
---|
560 | 'U_FAVORITE' => $url |
---|
561 | )); |
---|
562 | } |
---|
563 | else |
---|
564 | { |
---|
565 | $url = PHPWG_ROOT_PATH.'picture.php'; |
---|
566 | $url.= get_query_string_diff(array('rate','add_fav')); |
---|
567 | $url.= '&add_fav=0'; |
---|
568 | |
---|
569 | $template->assign_block_vars( |
---|
570 | 'favorite', |
---|
571 | array( |
---|
572 | 'FAVORITE_IMG' => PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/del_favorite.gif', |
---|
573 | 'FAVORITE_HINT' =>$lang['del_favorites_hint'], |
---|
574 | 'FAVORITE_ALT' =>$lang['del_favorites_alt'], |
---|
575 | 'U_FAVORITE'=> $url |
---|
576 | )); |
---|
577 | } |
---|
578 | } |
---|
579 | //------------------------------------ admin link for information modifications |
---|
580 | if ( $user['status'] == 'admin' ) |
---|
581 | { |
---|
582 | $template->assign_block_vars('admin', array()); |
---|
583 | } |
---|
584 | |
---|
585 | //-------------------------------------------------------- navigation management |
---|
586 | if ($has_prev) |
---|
587 | { |
---|
588 | $template->assign_block_vars( |
---|
589 | 'previous', |
---|
590 | array( |
---|
591 | 'TITLE_IMG' => $picture['prev']['name'], |
---|
592 | 'IMG' => $picture['prev']['thumbnail'], |
---|
593 | 'U_IMG' => add_session_id($picture['prev']['url']) |
---|
594 | )); |
---|
595 | } |
---|
596 | |
---|
597 | if ($has_next) |
---|
598 | { |
---|
599 | $template->assign_block_vars( |
---|
600 | 'next', |
---|
601 | array( |
---|
602 | 'TITLE_IMG' => $picture['next']['name'], |
---|
603 | 'IMG' => $picture['next']['thumbnail'], |
---|
604 | 'U_IMG' => add_session_id($picture['next']['url']) |
---|
605 | )); |
---|
606 | } |
---|
607 | |
---|
608 | //--------------------------------------------------------- picture information |
---|
609 | // legend |
---|
610 | if (isset($picture['current']['comment']) |
---|
611 | and !empty($picture['current']['comment'])) |
---|
612 | { |
---|
613 | $template->assign_block_vars( |
---|
614 | 'legend', |
---|
615 | array( |
---|
616 | 'COMMENT_IMG' => nl2br($picture['current']['comment']) |
---|
617 | )); |
---|
618 | } |
---|
619 | |
---|
620 | // author |
---|
621 | if ( !empty($picture['current']['author']) ) |
---|
622 | { |
---|
623 | $search_url = PHPWG_ROOT_PATH.'category.php?cat=search'; |
---|
624 | $search_url.= '&search=author:'.$picture['current']['author']; |
---|
625 | |
---|
626 | $value = '<a href="'; |
---|
627 | $value.= add_session_id($search_url); |
---|
628 | $value.= '">'.$picture['current']['author'].'</a>'; |
---|
629 | |
---|
630 | $template->assign_block_vars( |
---|
631 | 'info_line', |
---|
632 | array( |
---|
633 | 'INFO'=>$lang['author'], |
---|
634 | 'VALUE'=>$value |
---|
635 | )); |
---|
636 | } |
---|
637 | // creation date |
---|
638 | if ( !empty($picture['current']['date_creation']) ) |
---|
639 | { |
---|
640 | $search_url = PHPWG_ROOT_PATH.'category.php?cat=search'; |
---|
641 | $search_url.= '&search='; |
---|
642 | $search_url.= 'date_creation:'.$picture['current']['date_creation']; |
---|
643 | |
---|
644 | $value = '<a href="'; |
---|
645 | $value.= add_session_id($search_url); |
---|
646 | $value.= '">'.format_date($picture['current']['date_creation']).'</a>'; |
---|
647 | |
---|
648 | $template->assign_block_vars( |
---|
649 | 'info_line', |
---|
650 | array( |
---|
651 | 'INFO'=>$lang['creation_date'], |
---|
652 | 'VALUE'=>$value |
---|
653 | )); |
---|
654 | } |
---|
655 | // date of availability |
---|
656 | $search_url = PHPWG_ROOT_PATH.'category.php?cat=search'; |
---|
657 | $search_url.= '&search='; |
---|
658 | $search_url.= 'date_available:'.$picture['current']['date_available']; |
---|
659 | |
---|
660 | $value = '<a href="'; |
---|
661 | $value.= add_session_id($search_url); |
---|
662 | $value.= '">'.format_date($picture['current']['date_available']).'</a>'; |
---|
663 | |
---|
664 | $template->assign_block_vars( |
---|
665 | 'info_line', |
---|
666 | array( |
---|
667 | 'INFO'=>$lang['registration_date'], |
---|
668 | 'VALUE'=>$value |
---|
669 | )); |
---|
670 | // size in pixels |
---|
671 | if ($picture['current']['is_picture']) |
---|
672 | { |
---|
673 | if ($original_width != $picture_size[0] |
---|
674 | or $original_height != $picture_size[1]) |
---|
675 | { |
---|
676 | $content = '[ <a href="'.$picture['current']['src'].'" '; |
---|
677 | $content.= ' title="'.$lang['true_size'].'">'; |
---|
678 | $content.= $original_width.'*'.$original_height.'</a> ]'; |
---|
679 | } |
---|
680 | else |
---|
681 | { |
---|
682 | $content = $original_width.'*'.$original_height; |
---|
683 | } |
---|
684 | $template->assign_block_vars( |
---|
685 | 'info_line', |
---|
686 | array( |
---|
687 | 'INFO'=>$lang['size'], |
---|
688 | 'VALUE'=>$content |
---|
689 | )); |
---|
690 | } |
---|
691 | // file |
---|
692 | $template->assign_block_vars('info_line', array( |
---|
693 | 'INFO'=>$lang['file'], |
---|
694 | 'VALUE'=>$picture['current']['file'] |
---|
695 | )); |
---|
696 | // filesize |
---|
697 | if (empty($picture['current']['filesize'])) |
---|
698 | { |
---|
699 | if (!$picture['current']['is_picture']) |
---|
700 | { |
---|
701 | $filesize = floor(filesize($picture['current']['download'])/1024); |
---|
702 | } |
---|
703 | else |
---|
704 | { |
---|
705 | $filesize = floor(filesize($picture['current']['src'])/1024); |
---|
706 | } |
---|
707 | } |
---|
708 | else |
---|
709 | { |
---|
710 | $filesize = $picture['current']['filesize']; |
---|
711 | } |
---|
712 | |
---|
713 | $template->assign_block_vars('info_line', array( |
---|
714 | 'INFO'=>$lang['filesize'], |
---|
715 | 'VALUE'=>$filesize.' KB' |
---|
716 | )); |
---|
717 | // keywords |
---|
718 | if (!empty($picture['current']['keywords'])) |
---|
719 | { |
---|
720 | $keywords = explode(',', $picture['current']['keywords']); |
---|
721 | $content = ''; |
---|
722 | $url = PHPWG_ROOT_PATH.'category.php?cat=search&search=keywords:'; |
---|
723 | foreach ($keywords as $i => $keyword) |
---|
724 | { |
---|
725 | $local_url = add_session_id($url.$keyword); |
---|
726 | if ($i > 0) |
---|
727 | { |
---|
728 | $content.= ','; |
---|
729 | } |
---|
730 | $content.= '<a href="'.$local_url.'">'.$keyword.'</a>'; |
---|
731 | } |
---|
732 | $template->assign_block_vars( |
---|
733 | 'info_line', |
---|
734 | array( |
---|
735 | 'INFO'=>$lang['keywords'], |
---|
736 | 'VALUE'=>$content |
---|
737 | )); |
---|
738 | } |
---|
739 | // number of visits |
---|
740 | $template->assign_block_vars( |
---|
741 | 'info_line', |
---|
742 | array( |
---|
743 | 'INFO'=>$lang['visited'], |
---|
744 | 'VALUE'=>$picture['current']['hit'].' '.$lang['times'] |
---|
745 | )); |
---|
746 | // rate results |
---|
747 | if ($conf['rate']) |
---|
748 | { |
---|
749 | $query = ' |
---|
750 | SELECT COUNT(rate) AS count |
---|
751 | , ROUND(AVG(rate),2) AS average |
---|
752 | , ROUND(STD(rate),2) AS STD |
---|
753 | FROM '.RATE_TABLE.' |
---|
754 | WHERE element_id = '.$picture['current']['id'].' |
---|
755 | ;'; |
---|
756 | $row = mysql_fetch_array(pwg_query($query)); |
---|
757 | if ($row['count'] == 0) |
---|
758 | { |
---|
759 | $value = $lang['no_rate']; |
---|
760 | } |
---|
761 | else |
---|
762 | { |
---|
763 | $value = $row['average']; |
---|
764 | $value.= ' ('; |
---|
765 | $value.= $row['count'].' '.$lang['rates']; |
---|
766 | $value.= ', '.$lang['standard_deviation'].' : '.$row['STD']; |
---|
767 | $value.= ')'; |
---|
768 | } |
---|
769 | |
---|
770 | $template->assign_block_vars( |
---|
771 | 'info_line', |
---|
772 | array( |
---|
773 | 'INFO' => $lang['element_rate'], |
---|
774 | 'VALUE' => $value |
---|
775 | )); |
---|
776 | } |
---|
777 | // related categories |
---|
778 | $cat_output = ''; |
---|
779 | $page['show_comments'] = false; |
---|
780 | foreach ($related_categories as $category) |
---|
781 | { |
---|
782 | if ($cat_output != '') |
---|
783 | { |
---|
784 | $cat_output.= '<br />'; |
---|
785 | } |
---|
786 | |
---|
787 | if (count($related_categories) > 3) |
---|
788 | { |
---|
789 | $cat_output .= get_cat_display_name_cache($category['uppercats']); |
---|
790 | } |
---|
791 | else |
---|
792 | { |
---|
793 | $cat_info = get_cat_info($category['category_id']); |
---|
794 | $cat_output .= get_cat_display_name($cat_info['name']); |
---|
795 | } |
---|
796 | // the picture is commentable if it belongs at least to one category which |
---|
797 | // is commentable |
---|
798 | if ($category['commentable'] == 'true') |
---|
799 | { |
---|
800 | $page['show_comments'] = true; |
---|
801 | } |
---|
802 | } |
---|
803 | $template->assign_block_vars( |
---|
804 | 'info_line', |
---|
805 | array( |
---|
806 | 'INFO' => $lang['categories'], |
---|
807 | 'VALUE' => $cat_output |
---|
808 | )); |
---|
809 | // metadata |
---|
810 | if ($metadata_showable and isset($_GET['show_metadata'])) |
---|
811 | { |
---|
812 | include_once(PHPWG_ROOT_PATH.'/include/functions_metadata.inc.php'); |
---|
813 | $template->assign_block_vars('metadata', array()); |
---|
814 | if ($conf['show_exif']) |
---|
815 | { |
---|
816 | if (!function_exists('read_exif_data')) |
---|
817 | { |
---|
818 | die('Exif extension not available, admin should disable exif display'); |
---|
819 | } |
---|
820 | |
---|
821 | if ($exif = @read_exif_data($picture['current']['src'])) |
---|
822 | { |
---|
823 | $template->assign_block_vars( |
---|
824 | 'metadata.headline', |
---|
825 | array('TITLE' => 'EXIF Metadata') |
---|
826 | ); |
---|
827 | |
---|
828 | foreach ($conf['show_exif_fields'] as $field) |
---|
829 | { |
---|
830 | if (strpos($field, ';') === false) |
---|
831 | { |
---|
832 | if (isset($exif[$field])) |
---|
833 | { |
---|
834 | $key = $field; |
---|
835 | if (isset($lang['exif_field_'.$field])) |
---|
836 | { |
---|
837 | $key = $lang['exif_field_'.$field]; |
---|
838 | } |
---|
839 | |
---|
840 | $template->assign_block_vars( |
---|
841 | 'metadata.line', |
---|
842 | array( |
---|
843 | 'KEY' => $key, |
---|
844 | 'VALUE' => $exif[$field] |
---|
845 | ) |
---|
846 | ); |
---|
847 | } |
---|
848 | } |
---|
849 | else |
---|
850 | { |
---|
851 | $tokens = explode(';', $field); |
---|
852 | if (isset($exif[$tokens[0]][$tokens[1]])) |
---|
853 | { |
---|
854 | $key = $tokens[1]; |
---|
855 | if (isset($lang['exif_field_'.$tokens[1]])) |
---|
856 | { |
---|
857 | $key = $lang['exif_field_'.$tokens[1]]; |
---|
858 | } |
---|
859 | |
---|
860 | $template->assign_block_vars( |
---|
861 | 'metadata.line', |
---|
862 | array( |
---|
863 | 'KEY' => $key, |
---|
864 | 'VALUE' => $exif[$tokens[0]][$tokens[1]] |
---|
865 | ) |
---|
866 | ); |
---|
867 | } |
---|
868 | } |
---|
869 | } |
---|
870 | } |
---|
871 | } |
---|
872 | if ($conf['show_iptc']) |
---|
873 | { |
---|
874 | $iptc = get_iptc_data($picture['current']['src'], |
---|
875 | $conf['show_iptc_mapping']); |
---|
876 | |
---|
877 | if (count($iptc) > 0) |
---|
878 | { |
---|
879 | $template->assign_block_vars( |
---|
880 | 'metadata.headline', |
---|
881 | array('TITLE' => 'IPTC Metadata') |
---|
882 | ); |
---|
883 | } |
---|
884 | |
---|
885 | foreach ($iptc as $field => $value) |
---|
886 | { |
---|
887 | $key = $field; |
---|
888 | if (isset($lang[$field])) |
---|
889 | { |
---|
890 | $key = $lang[$field]; |
---|
891 | } |
---|
892 | |
---|
893 | $template->assign_block_vars( |
---|
894 | 'metadata.line', |
---|
895 | array( |
---|
896 | 'KEY' => $key, |
---|
897 | 'VALUE' => $value |
---|
898 | ) |
---|
899 | ); |
---|
900 | } |
---|
901 | } |
---|
902 | } |
---|
903 | //slideshow end |
---|
904 | if ( isset( $_GET['slideshow'] ) ) |
---|
905 | { |
---|
906 | if ( !is_numeric( $_GET['slideshow'] ) ) $_GET['slideshow'] = $conf['slideshow_period']; |
---|
907 | |
---|
908 | $template->assign_block_vars('stop_slideshow', array( |
---|
909 | 'U_SLIDESHOW'=>add_session_id( $picture['current']['url'] ) |
---|
910 | )); |
---|
911 | } |
---|
912 | |
---|
913 | //------------------------------------------------------------------- rate form |
---|
914 | if ($conf['rate'] and !$user['is_the_guest']) |
---|
915 | { |
---|
916 | $query = ' |
---|
917 | SELECT rate |
---|
918 | FROM '.RATE_TABLE.' |
---|
919 | WHERE user_id = '.$user['id'].' |
---|
920 | AND element_id = '.$_GET['image_id'].' |
---|
921 | ;'; |
---|
922 | $result = pwg_query($query); |
---|
923 | if (mysql_num_rows($result) > 0) |
---|
924 | { |
---|
925 | $row = mysql_fetch_array($result); |
---|
926 | $sentence = $lang['already_rated']; |
---|
927 | $sentence.= ' ('.$row['rate'].'). '; |
---|
928 | $sentence.= $lang['update_rate']; |
---|
929 | } |
---|
930 | else |
---|
931 | { |
---|
932 | $sentence = $lang['never_rated'].'. '.$lang['to_rate']; |
---|
933 | } |
---|
934 | $template->assign_block_vars( |
---|
935 | 'rate', |
---|
936 | array('SENTENCE' => $sentence) |
---|
937 | ); |
---|
938 | |
---|
939 | |
---|
940 | foreach ($rate_items as $num => $mark) |
---|
941 | { |
---|
942 | if ($num > 0) |
---|
943 | { |
---|
944 | $separator = '|'; |
---|
945 | } |
---|
946 | else |
---|
947 | { |
---|
948 | $separator = ''; |
---|
949 | } |
---|
950 | |
---|
951 | $url = PHPWG_ROOT_PATH.'picture.php'; |
---|
952 | $url.= get_query_string_diff(array('rate','add_fav')); |
---|
953 | $url.= '&rate='.$mark; |
---|
954 | |
---|
955 | $template->assign_block_vars( |
---|
956 | 'rate.rate_option', |
---|
957 | array( |
---|
958 | 'OPTION' => $mark, |
---|
959 | 'URL' => $url, |
---|
960 | 'SEPARATOR' => $separator |
---|
961 | )); |
---|
962 | } |
---|
963 | } |
---|
964 | //---------------------------------------------------- users's comments display |
---|
965 | if ($page['show_comments']) |
---|
966 | { |
---|
967 | // number of comment for this picture |
---|
968 | $query = 'SELECT COUNT(*) AS nb_comments'; |
---|
969 | $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id']; |
---|
970 | $query.= " AND validated = 'true'"; |
---|
971 | $query.= ';'; |
---|
972 | $row = mysql_fetch_array( pwg_query( $query ) ); |
---|
973 | |
---|
974 | // navigation bar creation |
---|
975 | $url = PHPWG_ROOT_PATH.'picture.php'; |
---|
976 | $url.= get_query_string_diff(array('rate','add_fav')); |
---|
977 | |
---|
978 | if (!isset( $_GET['start'] ) |
---|
979 | or !is_numeric( $_GET['start'] ) |
---|
980 | or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) ) |
---|
981 | { |
---|
982 | $page['start'] = 0; |
---|
983 | } |
---|
984 | else |
---|
985 | { |
---|
986 | $page['start'] = $_GET['start']; |
---|
987 | } |
---|
988 | $page['navigation_bar'] = create_navigation_bar( $url, $row['nb_comments'], |
---|
989 | $page['start'], |
---|
990 | $conf['nb_comment_page'], |
---|
991 | '' ); |
---|
992 | $template->assign_block_vars('comments', array( |
---|
993 | 'NB_COMMENT'=>$row['nb_comments'], |
---|
994 | 'NAV_BAR'=>$page['navigation_bar'])); |
---|
995 | |
---|
996 | $query = 'SELECT id,author,date,image_id,content'; |
---|
997 | $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id']; |
---|
998 | $query.= " AND validated = 'true'"; |
---|
999 | $query.= ' ORDER BY date ASC'; |
---|
1000 | $query.= ' LIMIT '.$page['start'].', '.$conf['nb_comment_page'].';'; |
---|
1001 | $result = pwg_query( $query ); |
---|
1002 | |
---|
1003 | while ( $row = mysql_fetch_array( $result ) ) |
---|
1004 | { |
---|
1005 | $template->assign_block_vars( |
---|
1006 | 'comments.comment', |
---|
1007 | array( |
---|
1008 | 'COMMENT_AUTHOR'=>empty($row['author'])?$lang['guest']:$row['author'], |
---|
1009 | 'COMMENT_DATE'=>format_date($row['date'], 'mysql_datetime', true), |
---|
1010 | 'COMMENT'=>parse_comment_content($row['content']) |
---|
1011 | )); |
---|
1012 | |
---|
1013 | if ( $user['status'] == 'admin' ) |
---|
1014 | { |
---|
1015 | $template->assign_block_vars( |
---|
1016 | 'comments.comment.delete', |
---|
1017 | array('U_COMMENT_DELETE'=>add_session_id( $url.'&del='.$row['id']) |
---|
1018 | )); |
---|
1019 | } |
---|
1020 | } |
---|
1021 | |
---|
1022 | if (!$user['is_the_guest'] |
---|
1023 | or ($user['is_the_guest'] and $conf['comments_forall'])) |
---|
1024 | { |
---|
1025 | $template->assign_block_vars('comments.add_comment', array()); |
---|
1026 | // display author field if the user is not logged in |
---|
1027 | if (!$user['is_the_guest']) |
---|
1028 | { |
---|
1029 | $template->assign_block_vars( |
---|
1030 | 'comments.add_comment.author_known', |
---|
1031 | array('KNOWN_AUTHOR'=>$user['username']) |
---|
1032 | ); |
---|
1033 | } |
---|
1034 | else |
---|
1035 | { |
---|
1036 | $template->assign_block_vars( |
---|
1037 | 'comments.add_comment.author_field', array() |
---|
1038 | ); |
---|
1039 | } |
---|
1040 | } |
---|
1041 | } |
---|
1042 | //------------------------------------------------------------ log informations |
---|
1043 | pwg_log( 'picture', $title_img, $picture['current']['file'] ); |
---|
1044 | mysql_close(); |
---|
1045 | |
---|
1046 | $template->parse('picture'); |
---|
1047 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
1048 | ?> |
---|