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-2004 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | branch : BSF (Best So Far) |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2004-12-06 21:49:32 +0000 (Mon, 06 Dec 2004) $ |
---|
10 | // | last modifier : $Author: plg $ |
---|
11 | // | revision : $Revision: 639 $ |
---|
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 = './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 | $cat_name = get_cat_display_name( $page['cat_name'], ' > ', '' ); |
---|
352 | $cat_name = strip_tags( $cat_name ); |
---|
353 | notify( 'comment', $cat_name.' > '.$picture['current']['name']); |
---|
354 | } |
---|
355 | } |
---|
356 | else |
---|
357 | { |
---|
358 | // information message |
---|
359 | $template->assign_block_vars( |
---|
360 | 'information', |
---|
361 | array('INFORMATION'=>$lang['comment_anti-flood'])); |
---|
362 | } |
---|
363 | } |
---|
364 | } |
---|
365 | // comment deletion |
---|
366 | if ( isset( $_GET['del'] ) |
---|
367 | and is_numeric( $_GET['del'] ) |
---|
368 | and $user['status'] == 'admin' ) |
---|
369 | { |
---|
370 | $query = 'DELETE FROM '.COMMENTS_TABLE; |
---|
371 | $query.= ' WHERE id = '.$_GET['del']; |
---|
372 | $query.= ';'; |
---|
373 | pwg_query( $query ); |
---|
374 | } |
---|
375 | |
---|
376 | // |
---|
377 | // Start output of page |
---|
378 | // |
---|
379 | |
---|
380 | $title = $picture['current']['name']; |
---|
381 | $refresh = 0; |
---|
382 | if ( isset( $_GET['slideshow'] ) and $has_next ) |
---|
383 | { |
---|
384 | $refresh= $_GET['slideshow']; |
---|
385 | $url_link = $picture['next']['url'].'&slideshow='.$refresh; |
---|
386 | } |
---|
387 | |
---|
388 | $title_img = $picture['current']['name']; |
---|
389 | $title_nb = ''; |
---|
390 | if (is_numeric( $page['cat'] )) |
---|
391 | { |
---|
392 | $title_img = replace_space(get_cat_display_name($page['cat_name'],' > ')); |
---|
393 | $n = $page['num'] + 1; |
---|
394 | $title_nb = $n.'/'.$page['cat_nb_images']; |
---|
395 | } |
---|
396 | else if ( $page['cat'] == 'search' ) |
---|
397 | { |
---|
398 | $title_img = replace_search( $title_img, $_GET['search'] ); |
---|
399 | } |
---|
400 | |
---|
401 | // calculation of width and height |
---|
402 | if (empty($picture['current']['width'])) |
---|
403 | { |
---|
404 | $taille_image = @getimagesize($picture['current']['src']); |
---|
405 | $original_width = $taille_image[0]; |
---|
406 | $original_height = $taille_image[1]; |
---|
407 | } |
---|
408 | else |
---|
409 | { |
---|
410 | $original_width = $picture['current']['width']; |
---|
411 | $original_height = $picture['current']['height']; |
---|
412 | } |
---|
413 | |
---|
414 | $picture_size = get_picture_size( $original_width, $original_height, |
---|
415 | $user['maxwidth'], $user['maxheight'] ); |
---|
416 | |
---|
417 | // metadata |
---|
418 | if ($conf['show_exif'] or $conf['show_iptc']) |
---|
419 | { |
---|
420 | $metadata_showable = true; |
---|
421 | } |
---|
422 | else |
---|
423 | { |
---|
424 | $metadata_showable = false; |
---|
425 | } |
---|
426 | |
---|
427 | $url_metadata = PHPWG_ROOT_PATH.'picture.php'; |
---|
428 | $url_metadata .= get_query_string_diff(array('add_fav', 'slideshow', 'show_metadata')); |
---|
429 | if ($metadata_showable and !isset($_GET['show_metadata'])) |
---|
430 | { |
---|
431 | $url_metadata.= '&show_metadata=1'; |
---|
432 | } |
---|
433 | |
---|
434 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
435 | $template->set_filenames(array('picture'=>'picture.tpl')); |
---|
436 | |
---|
437 | $template->assign_vars(array( |
---|
438 | 'CATEGORY' => $title_img, |
---|
439 | 'PHOTO' => $title_nb, |
---|
440 | 'TITLE' => $picture['current']['name'], |
---|
441 | 'SRC_IMG' => $picture['current']['src'], |
---|
442 | 'ALT_IMG' => $picture['current']['file'], |
---|
443 | 'WIDTH_IMG' => $picture_size[0], |
---|
444 | 'HEIGHT_IMG' => $picture_size[1], |
---|
445 | |
---|
446 | 'L_HOME' => $lang['home'], |
---|
447 | 'L_SLIDESHOW' => $lang['slideshow'], |
---|
448 | 'L_STOP_SLIDESHOW' => $lang['slideshow_stop'], |
---|
449 | 'L_PREV_IMG' =>$lang['previous_image'].' : ', |
---|
450 | 'L_ADMIN' =>$lang['link_info_image'], |
---|
451 | 'L_COMMENT_TITLE' =>$lang['comments_title'], |
---|
452 | 'L_ADD_COMMENT' =>$lang['comments_add'], |
---|
453 | 'L_DELETE_COMMENT' =>$lang['comments_del'], |
---|
454 | 'L_DELETE' =>$lang['delete'], |
---|
455 | 'L_SUBMIT' =>$lang['submit'], |
---|
456 | 'L_AUTHOR' =>$lang['author'], |
---|
457 | 'L_COMMENT' =>$lang['comment'], |
---|
458 | 'L_DOWNLOAD' => $lang['download'], |
---|
459 | 'L_DOWNLOAD_HINT' => $lang['download_hint'], |
---|
460 | 'L_PICTURE_METADATA' => $lang['picture_show_metadata'], |
---|
461 | 'L_PICTURE_HIGH' => $lang['picture_high'], |
---|
462 | 'L_UP_HINT' => $lang['home_hint'], |
---|
463 | 'L_UP_ALT' => $lang['home'], |
---|
464 | |
---|
465 | 'U_HOME' => add_session_id(PHPWG_ROOT_PATH.'category.php'), |
---|
466 | 'U_UP' => add_session_id($url_up), |
---|
467 | 'U_METADATA' => add_session_id($url_metadata), |
---|
468 | 'U_ADMIN' => add_session_id($url_admin), |
---|
469 | 'U_SLIDESHOW'=> add_session_id($url_slide), |
---|
470 | 'U_ADD_COMMENT' => add_session_id(str_replace( '&', '&', $_SERVER['REQUEST_URI'] )) |
---|
471 | ) |
---|
472 | ); |
---|
473 | //------------------------------------------------------- upper menu management |
---|
474 | // download link if file is not a picture |
---|
475 | if (!$picture['current']['is_picture']) |
---|
476 | { |
---|
477 | $template->assign_block_vars( |
---|
478 | 'download', |
---|
479 | array('U_DOWNLOAD' => $picture['current']['download'])); |
---|
480 | } |
---|
481 | else |
---|
482 | { |
---|
483 | $template->assign_block_vars( |
---|
484 | 'ecard', |
---|
485 | array('U_ECARD' => $picture['current']['url'])); |
---|
486 | } |
---|
487 | // display a high quality link if present |
---|
488 | if (isset($picture['current']['high'])) |
---|
489 | { |
---|
490 | $full_size = @getimagesize($picture['current']['high']); |
---|
491 | $full_width = $full_size[0]; |
---|
492 | $full_height = $full_size[1]; |
---|
493 | $uuid = uniqid(rand()); |
---|
494 | $template->assign_block_vars('high', array( |
---|
495 | 'U_HIGH' => $picture['current']['high'], |
---|
496 | 'UUID'=>$uuid, |
---|
497 | 'WIDTH_IMG'=>($full_width + 16), |
---|
498 | 'HEIGHT_IMG'=>($full_height + 16) |
---|
499 | )); |
---|
500 | } |
---|
501 | //------------------------------------------------------- favorite manipulation |
---|
502 | if ( !$user['is_the_guest'] ) |
---|
503 | { |
---|
504 | // verify if the picture is already in the favorite of the user |
---|
505 | $query = 'SELECT COUNT(*) AS nb_fav'; |
---|
506 | $query.= ' FROM '.FAVORITES_TABLE.' WHERE image_id = '.$_GET['image_id']; |
---|
507 | $query.= ' AND user_id = '.$user['id'].';'; |
---|
508 | $result = pwg_query( $query ); |
---|
509 | $row = mysql_fetch_array( $result ); |
---|
510 | if (!$row['nb_fav']) |
---|
511 | { |
---|
512 | $url = PHPWG_ROOT_PATH.'picture.php'; |
---|
513 | $url.= get_query_string_diff(array('rate','add_fav')); |
---|
514 | $url.= '&add_fav=1'; |
---|
515 | |
---|
516 | $template->assign_block_vars( |
---|
517 | 'favorite', |
---|
518 | array( |
---|
519 | 'FAVORITE_IMG' => PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/favorite.gif', |
---|
520 | 'FAVORITE_HINT' =>$lang['add_favorites_hint'], |
---|
521 | 'FAVORITE_ALT' =>$lang['add_favorites_alt'], |
---|
522 | 'U_FAVORITE' => $url |
---|
523 | )); |
---|
524 | } |
---|
525 | else |
---|
526 | { |
---|
527 | $url = PHPWG_ROOT_PATH.'picture.php'; |
---|
528 | $url.= get_query_string_diff(array('rate','add_fav')); |
---|
529 | $url.= '&add_fav=0'; |
---|
530 | |
---|
531 | $template->assign_block_vars( |
---|
532 | 'favorite', |
---|
533 | array( |
---|
534 | 'FAVORITE_IMG' => PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/del_favorite.gif', |
---|
535 | 'FAVORITE_HINT' =>$lang['del_favorites_hint'], |
---|
536 | 'FAVORITE_ALT' =>$lang['del_favorites_alt'], |
---|
537 | 'U_FAVORITE'=> $url |
---|
538 | )); |
---|
539 | } |
---|
540 | } |
---|
541 | //------------------------------------ admin link for information modifications |
---|
542 | if ( $user['status'] == 'admin' ) |
---|
543 | { |
---|
544 | $template->assign_block_vars('admin', array()); |
---|
545 | } |
---|
546 | |
---|
547 | //-------------------------------------------------------- navigation management |
---|
548 | if ($has_prev) |
---|
549 | { |
---|
550 | $template->assign_block_vars( |
---|
551 | 'previous', |
---|
552 | array( |
---|
553 | 'TITLE_IMG' => $picture['prev']['name'], |
---|
554 | 'IMG' => $picture['prev']['thumbnail'], |
---|
555 | 'U_IMG' => add_session_id($picture['prev']['url']) |
---|
556 | )); |
---|
557 | } |
---|
558 | |
---|
559 | if ($has_next) |
---|
560 | { |
---|
561 | $template->assign_block_vars( |
---|
562 | 'next', |
---|
563 | array( |
---|
564 | 'TITLE_IMG' => $picture['next']['name'], |
---|
565 | 'IMG' => $picture['next']['thumbnail'], |
---|
566 | 'U_IMG' => add_session_id($picture['next']['url']) |
---|
567 | )); |
---|
568 | } |
---|
569 | |
---|
570 | //--------------------------------------------------------- picture information |
---|
571 | // legend |
---|
572 | if (isset($picture['current']['comment']) |
---|
573 | and !empty($picture['current']['comment'])) |
---|
574 | { |
---|
575 | $template->assign_block_vars( |
---|
576 | 'legend', |
---|
577 | array( |
---|
578 | 'COMMENT_IMG' => $picture['current']['comment'] |
---|
579 | )); |
---|
580 | } |
---|
581 | |
---|
582 | // author |
---|
583 | if ( !empty($picture['current']['author']) ) |
---|
584 | { |
---|
585 | $search_url = PHPWG_ROOT_PATH.'category.php?cat=search'; |
---|
586 | $search_url.= '&search=author:'.$picture['current']['author']; |
---|
587 | |
---|
588 | $value = '<a href="'; |
---|
589 | $value.= add_session_id($search_url); |
---|
590 | $value.= '">'.$picture['current']['author'].'</a>'; |
---|
591 | |
---|
592 | $template->assign_block_vars( |
---|
593 | 'info_line', |
---|
594 | array( |
---|
595 | 'INFO'=>$lang['author'], |
---|
596 | 'VALUE'=>$value |
---|
597 | )); |
---|
598 | } |
---|
599 | // creation date |
---|
600 | if ( !empty($picture['current']['date_creation']) ) |
---|
601 | { |
---|
602 | $search_url = PHPWG_ROOT_PATH.'category.php?cat=search'; |
---|
603 | $search_url.= '&search='; |
---|
604 | $search_url.= 'date_creation:'.$picture['current']['date_creation']; |
---|
605 | |
---|
606 | $value = '<a href="'; |
---|
607 | $value.= add_session_id($search_url); |
---|
608 | $value.= '">'.format_date($picture['current']['date_creation']).'</a>'; |
---|
609 | |
---|
610 | $template->assign_block_vars( |
---|
611 | 'info_line', |
---|
612 | array( |
---|
613 | 'INFO'=>$lang['creation_date'], |
---|
614 | 'VALUE'=>$value |
---|
615 | )); |
---|
616 | } |
---|
617 | // date of availability |
---|
618 | $search_url = PHPWG_ROOT_PATH.'category.php?cat=search'; |
---|
619 | $search_url.= '&search='; |
---|
620 | $search_url.= 'date_available:'.$picture['current']['date_available']; |
---|
621 | |
---|
622 | $value = '<a href="'; |
---|
623 | $value.= add_session_id($search_url); |
---|
624 | $value.= '">'.format_date($picture['current']['date_available']).'</a>'; |
---|
625 | |
---|
626 | $template->assign_block_vars( |
---|
627 | 'info_line', |
---|
628 | array( |
---|
629 | 'INFO'=>$lang['registration_date'], |
---|
630 | 'VALUE'=>$value |
---|
631 | )); |
---|
632 | // size in pixels |
---|
633 | if ($picture['current']['is_picture']) |
---|
634 | { |
---|
635 | if ($original_width != $picture_size[0] |
---|
636 | or $original_height != $picture_size[1]) |
---|
637 | { |
---|
638 | $content = '[ <a href="'.$picture['current']['src'].'" '; |
---|
639 | $content.= ' title="'.$lang['true_size'].'">'; |
---|
640 | $content.= $original_width.'*'.$original_height.'</a> ]'; |
---|
641 | } |
---|
642 | else |
---|
643 | { |
---|
644 | $content = $original_width.'*'.$original_height; |
---|
645 | } |
---|
646 | $template->assign_block_vars( |
---|
647 | 'info_line', |
---|
648 | array( |
---|
649 | 'INFO'=>$lang['size'], |
---|
650 | 'VALUE'=>$content |
---|
651 | )); |
---|
652 | } |
---|
653 | // file |
---|
654 | $template->assign_block_vars('info_line', array( |
---|
655 | 'INFO'=>$lang['file'], |
---|
656 | 'VALUE'=>$picture['current']['file'] |
---|
657 | )); |
---|
658 | // filesize |
---|
659 | if (empty($picture['current']['filesize'])) |
---|
660 | { |
---|
661 | if (!$picture['current']['is_picture']) |
---|
662 | { |
---|
663 | $filesize = floor(filesize($picture['current']['download'])/1024); |
---|
664 | } |
---|
665 | else |
---|
666 | { |
---|
667 | $filesize = floor(filesize($picture['current']['src'])/1024); |
---|
668 | } |
---|
669 | } |
---|
670 | else |
---|
671 | { |
---|
672 | $filesize = $picture['current']['filesize']; |
---|
673 | } |
---|
674 | |
---|
675 | $template->assign_block_vars('info_line', array( |
---|
676 | 'INFO'=>$lang['filesize'], |
---|
677 | 'VALUE'=>$filesize.' KB' |
---|
678 | )); |
---|
679 | // keywords |
---|
680 | if (!empty($picture['current']['keywords'])) |
---|
681 | { |
---|
682 | $keywords = explode(',', $picture['current']['keywords']); |
---|
683 | $content = ''; |
---|
684 | $url = PHPWG_ROOT_PATH.'category.php?cat=search&search=keywords:'; |
---|
685 | foreach ($keywords as $i => $keyword) |
---|
686 | { |
---|
687 | $local_url = add_session_id($url.$keyword); |
---|
688 | if ($i > 0) |
---|
689 | { |
---|
690 | $content.= ','; |
---|
691 | } |
---|
692 | $content.= '<a href="'.$local_url.'">'.$keyword.'</a>'; |
---|
693 | } |
---|
694 | $template->assign_block_vars( |
---|
695 | 'info_line', |
---|
696 | array( |
---|
697 | 'INFO'=>$lang['keywords'], |
---|
698 | 'VALUE'=>$content |
---|
699 | )); |
---|
700 | } |
---|
701 | // number of visits |
---|
702 | $template->assign_block_vars( |
---|
703 | 'info_line', |
---|
704 | array( |
---|
705 | 'INFO'=>$lang['visited'], |
---|
706 | 'VALUE'=>$picture['current']['hit'].' '.$lang['times'] |
---|
707 | )); |
---|
708 | // rate results |
---|
709 | if ($conf['rate']) |
---|
710 | { |
---|
711 | $query = ' |
---|
712 | SELECT COUNT(rate) AS count |
---|
713 | , ROUND(AVG(rate),2) AS average |
---|
714 | , ROUND(STD(rate),2) AS STD |
---|
715 | FROM '.RATE_TABLE.' |
---|
716 | WHERE element_id = '.$picture['current']['id'].' |
---|
717 | ;'; |
---|
718 | $row = mysql_fetch_array(pwg_query($query)); |
---|
719 | if ($row['count'] == 0) |
---|
720 | { |
---|
721 | $value = $lang['no_rate']; |
---|
722 | } |
---|
723 | else |
---|
724 | { |
---|
725 | $value = $row['average']; |
---|
726 | $value.= ' ('; |
---|
727 | $value.= $row['count'].' '.$lang['rates']; |
---|
728 | $value.= ', '.$lang['standard_deviation'].' : '.$row['STD']; |
---|
729 | $value.= ')'; |
---|
730 | } |
---|
731 | |
---|
732 | $template->assign_block_vars( |
---|
733 | 'info_line', |
---|
734 | array( |
---|
735 | 'INFO' => $lang['element_rate'], |
---|
736 | 'VALUE' => $value |
---|
737 | )); |
---|
738 | } |
---|
739 | // related categories |
---|
740 | $query = ' |
---|
741 | SELECT category_id,uppercats,commentable,global_rank |
---|
742 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
743 | INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id |
---|
744 | WHERE image_id = '.$_GET['image_id']; |
---|
745 | if ($user['forbidden_categories'] != '') |
---|
746 | { |
---|
747 | $query.= ' |
---|
748 | AND category_id NOT IN ('.$user['forbidden_categories'].')'; |
---|
749 | } |
---|
750 | $query.= ' |
---|
751 | ;'; |
---|
752 | $result = pwg_query($query); |
---|
753 | $cat_array = array(); |
---|
754 | while ($row = mysql_fetch_array($result)) |
---|
755 | { |
---|
756 | array_push($cat_array, $row); |
---|
757 | } |
---|
758 | usort($cat_array, 'global_rank_compare'); |
---|
759 | |
---|
760 | $cat_output = ''; |
---|
761 | $page['show_comments'] = false; |
---|
762 | foreach ($cat_array as $category) |
---|
763 | { |
---|
764 | if ($cat_output != '') |
---|
765 | { |
---|
766 | $cat_output.= '<br />'; |
---|
767 | } |
---|
768 | |
---|
769 | if (count($cat_array) > 3) |
---|
770 | { |
---|
771 | $cat_output .= get_cat_display_name_cache($category['uppercats'], |
---|
772 | ' → '); |
---|
773 | } |
---|
774 | else |
---|
775 | { |
---|
776 | $cat_info = get_cat_info($category['category_id']); |
---|
777 | $cat_output .= get_cat_display_name($cat_info['name'], ' → '); |
---|
778 | } |
---|
779 | // the picture is commentable if it belongs at least to one category which |
---|
780 | // is commentable |
---|
781 | if ($category['commentable']) |
---|
782 | { |
---|
783 | $page['show_comments'] = true; |
---|
784 | } |
---|
785 | } |
---|
786 | $template->assign_block_vars( |
---|
787 | 'info_line', |
---|
788 | array( |
---|
789 | 'INFO' => $lang['categories'], |
---|
790 | 'VALUE' => $cat_output |
---|
791 | )); |
---|
792 | // metadata |
---|
793 | if ($metadata_showable and isset($_GET['show_metadata'])) |
---|
794 | { |
---|
795 | include_once(PHPWG_ROOT_PATH.'/include/functions_metadata.inc.php'); |
---|
796 | $template->assign_block_vars('metadata', array()); |
---|
797 | if ($conf['show_exif']) |
---|
798 | { |
---|
799 | if ($exif = @read_exif_data($picture['current']['src'])) |
---|
800 | { |
---|
801 | $template->assign_block_vars( |
---|
802 | 'metadata.headline', |
---|
803 | array('TITLE' => 'EXIF Metadata') |
---|
804 | ); |
---|
805 | |
---|
806 | foreach ($conf['show_exif_fields'] as $field) |
---|
807 | { |
---|
808 | if (strpos($field, ';') === false) |
---|
809 | { |
---|
810 | if (isset($exif[$field])) |
---|
811 | { |
---|
812 | $key = $field; |
---|
813 | if (isset($lang['exif_field_'.$field])) |
---|
814 | { |
---|
815 | $key = $lang['exif_field_'.$field]; |
---|
816 | } |
---|
817 | |
---|
818 | $template->assign_block_vars( |
---|
819 | 'metadata.line', |
---|
820 | array( |
---|
821 | 'KEY' => $key, |
---|
822 | 'VALUE' => $exif[$field] |
---|
823 | ) |
---|
824 | ); |
---|
825 | } |
---|
826 | } |
---|
827 | else |
---|
828 | { |
---|
829 | $tokens = explode(';', $field); |
---|
830 | if (isset($exif[$tokens[0]][$tokens[1]])) |
---|
831 | { |
---|
832 | $key = $tokens[1]; |
---|
833 | if (isset($lang['exif_field_'.$tokens[1]])) |
---|
834 | { |
---|
835 | $key = $lang['exif_field_'.$tokens[1]]; |
---|
836 | } |
---|
837 | |
---|
838 | $template->assign_block_vars( |
---|
839 | 'metadata.line', |
---|
840 | array( |
---|
841 | 'KEY' => $key, |
---|
842 | 'VALUE' => $exif[$tokens[0]][$tokens[1]] |
---|
843 | ) |
---|
844 | ); |
---|
845 | } |
---|
846 | } |
---|
847 | } |
---|
848 | } |
---|
849 | } |
---|
850 | if ($conf['show_iptc']) |
---|
851 | { |
---|
852 | $iptc = get_iptc_data($picture['current']['src'], |
---|
853 | $conf['show_iptc_mapping']); |
---|
854 | |
---|
855 | if (count($iptc) > 0) |
---|
856 | { |
---|
857 | $template->assign_block_vars( |
---|
858 | 'metadata.headline', |
---|
859 | array('TITLE' => 'IPTC Metadata') |
---|
860 | ); |
---|
861 | } |
---|
862 | |
---|
863 | foreach ($iptc as $field => $value) |
---|
864 | { |
---|
865 | $key = $field; |
---|
866 | if (isset($lang[$field])) |
---|
867 | { |
---|
868 | $key = $lang[$field]; |
---|
869 | } |
---|
870 | |
---|
871 | $template->assign_block_vars( |
---|
872 | 'metadata.line', |
---|
873 | array( |
---|
874 | 'KEY' => $key, |
---|
875 | 'VALUE' => $value |
---|
876 | ) |
---|
877 | ); |
---|
878 | } |
---|
879 | } |
---|
880 | } |
---|
881 | //slideshow end |
---|
882 | if ( isset( $_GET['slideshow'] ) ) |
---|
883 | { |
---|
884 | if ( !is_numeric( $_GET['slideshow'] ) ) $_GET['slideshow'] = $conf['slideshow_period']; |
---|
885 | |
---|
886 | $template->assign_block_vars('stop_slideshow', array( |
---|
887 | 'U_SLIDESHOW'=>add_session_id( $picture['current']['url'] ) |
---|
888 | )); |
---|
889 | } |
---|
890 | |
---|
891 | //------------------------------------------------------------------- rate form |
---|
892 | if ($conf['rate']) |
---|
893 | { |
---|
894 | $query = ' |
---|
895 | SELECT rate |
---|
896 | FROM '.RATE_TABLE.' |
---|
897 | WHERE user_id = '.$user['id'].' |
---|
898 | AND element_id = '.$_GET['image_id'].' |
---|
899 | ;'; |
---|
900 | $result = pwg_query($query); |
---|
901 | if (mysql_num_rows($result) > 0) |
---|
902 | { |
---|
903 | $row = mysql_fetch_array($result); |
---|
904 | $sentence = $lang['already_rated']; |
---|
905 | $sentence.= ' ('.$row['rate'].'). '; |
---|
906 | $sentence.= $lang['update_rate']; |
---|
907 | } |
---|
908 | else |
---|
909 | { |
---|
910 | $sentence = $lang['never_rated'].'. '.$lang['to_rate']; |
---|
911 | } |
---|
912 | $template->assign_block_vars( |
---|
913 | 'rate', |
---|
914 | array('SENTENCE' => $sentence) |
---|
915 | ); |
---|
916 | |
---|
917 | |
---|
918 | foreach ($rate_items as $num => $mark) |
---|
919 | { |
---|
920 | if ($num > 0) |
---|
921 | { |
---|
922 | $separator = '|'; |
---|
923 | } |
---|
924 | else |
---|
925 | { |
---|
926 | $separator = ''; |
---|
927 | } |
---|
928 | |
---|
929 | $url = PHPWG_ROOT_PATH.'picture.php'; |
---|
930 | $url.= get_query_string_diff(array('rate','add_fav')); |
---|
931 | $url.= '&rate='.$mark; |
---|
932 | |
---|
933 | $template->assign_block_vars( |
---|
934 | 'rate.rate_option', |
---|
935 | array( |
---|
936 | 'OPTION' => $mark, |
---|
937 | 'URL' => $url, |
---|
938 | 'SEPARATOR' => $separator |
---|
939 | )); |
---|
940 | } |
---|
941 | } |
---|
942 | |
---|
943 | //---------------------------------------------------- users's comments display |
---|
944 | if ($page['show_comments']) |
---|
945 | { |
---|
946 | // number of comment for this picture |
---|
947 | $query = 'SELECT COUNT(*) AS nb_comments'; |
---|
948 | $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id']; |
---|
949 | $query.= " AND validated = 'true'"; |
---|
950 | $query.= ';'; |
---|
951 | $row = mysql_fetch_array( pwg_query( $query ) ); |
---|
952 | |
---|
953 | // navigation bar creation |
---|
954 | $url = PHPWG_ROOT_PATH.'picture.php'; |
---|
955 | $url.= get_query_string_diff(array('rate','add_fav')); |
---|
956 | |
---|
957 | if (!isset( $_GET['start'] ) |
---|
958 | or !is_numeric( $_GET['start'] ) |
---|
959 | or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) ) |
---|
960 | { |
---|
961 | $page['start'] = 0; |
---|
962 | } |
---|
963 | else |
---|
964 | { |
---|
965 | $page['start'] = $_GET['start']; |
---|
966 | } |
---|
967 | $page['navigation_bar'] = create_navigation_bar( $url, $row['nb_comments'], |
---|
968 | $page['start'], |
---|
969 | $conf['nb_comment_page'], |
---|
970 | '' ); |
---|
971 | $template->assign_block_vars('comments', array( |
---|
972 | 'NB_COMMENT'=>$row['nb_comments'], |
---|
973 | 'NAV_BAR'=>$page['navigation_bar'])); |
---|
974 | |
---|
975 | $query = 'SELECT id,author,date,image_id,content'; |
---|
976 | $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id']; |
---|
977 | $query.= " AND validated = 'true'"; |
---|
978 | $query.= ' ORDER BY date ASC'; |
---|
979 | $query.= ' LIMIT '.$page['start'].', '.$conf['nb_comment_page'].';'; |
---|
980 | $result = pwg_query( $query ); |
---|
981 | |
---|
982 | while ( $row = mysql_fetch_array( $result ) ) |
---|
983 | { |
---|
984 | $template->assign_block_vars( |
---|
985 | 'comments.comment', |
---|
986 | array( |
---|
987 | 'COMMENT_AUTHOR'=>empty($row['author'])?$lang['guest']:$row['author'], |
---|
988 | 'COMMENT_DATE'=>format_date($row['date'], 'mysql_datetime', true), |
---|
989 | 'COMMENT'=>parse_comment_content($row['content']) |
---|
990 | )); |
---|
991 | |
---|
992 | if ( $user['status'] == 'admin' ) |
---|
993 | { |
---|
994 | $template->assign_block_vars( |
---|
995 | 'comments.comment.delete', |
---|
996 | array('U_COMMENT_DELETE'=>add_session_id( $url.'&del='.$row['id']) |
---|
997 | )); |
---|
998 | } |
---|
999 | } |
---|
1000 | |
---|
1001 | if (!$user['is_the_guest'] |
---|
1002 | or ($user['is_the_guest'] and $conf['comments_forall'])) |
---|
1003 | { |
---|
1004 | $template->assign_block_vars('comments.add_comment', array()); |
---|
1005 | // display author field if the user is not logged in |
---|
1006 | if (!$user['is_the_guest']) |
---|
1007 | { |
---|
1008 | $template->assign_block_vars( |
---|
1009 | 'comments.add_comment.author_known', |
---|
1010 | array('KNOWN_AUTHOR'=>$user['username']) |
---|
1011 | ); |
---|
1012 | } |
---|
1013 | else |
---|
1014 | { |
---|
1015 | $template->assign_block_vars( |
---|
1016 | 'comments.add_comment.author_field', array() |
---|
1017 | ); |
---|
1018 | } |
---|
1019 | } |
---|
1020 | } |
---|
1021 | //------------------------------------------------------------ log informations |
---|
1022 | pwg_log( 'picture', $title_img, $picture['current']['file'] ); |
---|
1023 | mysql_close(); |
---|
1024 | |
---|
1025 | $template->pparse('picture'); |
---|
1026 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
1027 | ?> |
---|