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