1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | picture.php | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | application : PhpWebGallery <http://phpwebgallery.net> | |
---|
6 | // | branch : BSF (Best So Far) | |
---|
7 | // +-----------------------------------------------------------------------+ |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2004-08-25 22:25:58 +0000 (Wed, 25 Aug 2004) $ |
---|
10 | // | last modifier : $Author: gweltas $ |
---|
11 | // | revision : $Revision: 496 $ |
---|
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 | //----------------------------------------------------------- include |
---|
29 | define('PHPWG_ROOT_PATH','./'); |
---|
30 | include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
31 | //-------------------------------------------------- access authorization check |
---|
32 | check_cat_id( $_GET['cat'] ); |
---|
33 | check_login_authorization(); |
---|
34 | if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) ) |
---|
35 | { |
---|
36 | check_restrictions( $page['cat'] ); |
---|
37 | } |
---|
38 | //---------------------------------------- incrementation of the number of hits |
---|
39 | $query = 'UPDATE '.IMAGES_TABLE.' SET hit=hit+1'; |
---|
40 | $query.= ' WHERE id='.$_GET['image_id']; |
---|
41 | $query.= ';'; |
---|
42 | @mysql_query( $query ); |
---|
43 | //-------------------------------------------------------------- initialization |
---|
44 | initialize_category( 'picture' ); |
---|
45 | // retrieving the number of the picture in its category (in order) |
---|
46 | $query = ' |
---|
47 | SELECT DISTINCT(id) |
---|
48 | FROM '.IMAGES_TABLE.' |
---|
49 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id |
---|
50 | '.$page['where'].' |
---|
51 | '.$conf['order_by'].' |
---|
52 | ;'; |
---|
53 | $result = mysql_query( $query ); |
---|
54 | $page['num'] = 0; |
---|
55 | $belongs = false; |
---|
56 | while ($row = mysql_fetch_array($result)) |
---|
57 | { |
---|
58 | if ($row['id'] == $_GET['image_id']) |
---|
59 | { |
---|
60 | $belongs = true; |
---|
61 | break; |
---|
62 | } |
---|
63 | $page['num']++; |
---|
64 | } |
---|
65 | // if this image_id doesn't correspond to this category, an error message is |
---|
66 | // displayed, and execution is stopped |
---|
67 | if (!$belongs) |
---|
68 | { |
---|
69 | echo '<div style="text-align:center;">'.$lang['access_forbiden'].'<br />'; |
---|
70 | echo '<a href="'.add_session_id( PHPWG_ROOT_PATH.'category.php' ).'">'; |
---|
71 | echo $lang['thumbnails'].'</a></div>'; |
---|
72 | exit(); |
---|
73 | } |
---|
74 | //------------------------------------- prev, current & next picture management |
---|
75 | $picture = array(); |
---|
76 | |
---|
77 | if ($page['num'] == 0) |
---|
78 | { |
---|
79 | $has_prev = false; |
---|
80 | } |
---|
81 | else |
---|
82 | { |
---|
83 | $has_prev = true; |
---|
84 | } |
---|
85 | |
---|
86 | if ($page['num'] == $page['cat_nb_images'] - 1) |
---|
87 | { |
---|
88 | $has_next = false; |
---|
89 | } |
---|
90 | else |
---|
91 | { |
---|
92 | $has_next = true; |
---|
93 | } |
---|
94 | |
---|
95 | $query = ' |
---|
96 | SELECT * |
---|
97 | FROM '.IMAGES_TABLE.' |
---|
98 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id=ic.image_id |
---|
99 | '.$page['where'].' |
---|
100 | '.$conf['order_by'].' |
---|
101 | '; |
---|
102 | |
---|
103 | if ( !$has_prev ) |
---|
104 | { |
---|
105 | $query.= ' LIMIT 0,2'; |
---|
106 | } |
---|
107 | else |
---|
108 | { |
---|
109 | $query.= ' LIMIT '.($page['num'] - 1).',3'; |
---|
110 | } |
---|
111 | $query.= ';'; |
---|
112 | |
---|
113 | $result = mysql_query( $query ); |
---|
114 | $indexes = array('prev', 'current', 'next'); |
---|
115 | |
---|
116 | foreach (array('prev', 'current', 'next') as $i) |
---|
117 | { |
---|
118 | if ($i == 'prev' and !$has_prev) |
---|
119 | { |
---|
120 | continue; |
---|
121 | } |
---|
122 | if ($i == 'next' and !$has_next) |
---|
123 | { |
---|
124 | break; |
---|
125 | } |
---|
126 | |
---|
127 | $row = mysql_fetch_array($result); |
---|
128 | foreach (array_keys($row) as $key) |
---|
129 | { |
---|
130 | if (!is_numeric($key)) |
---|
131 | { |
---|
132 | $picture[$i][$key] = $row[$key]; |
---|
133 | } |
---|
134 | } |
---|
135 | |
---|
136 | $picture[$i]['is_picture'] = false; |
---|
137 | if (in_array(get_extension($row['file']), $conf['picture_ext'])) |
---|
138 | { |
---|
139 | $picture[$i]['is_picture'] = true; |
---|
140 | } |
---|
141 | |
---|
142 | if ( !isset($array_cat_directories[$row['storage_category_id']])) |
---|
143 | { |
---|
144 | $array_cat_directories[$row['storage_category_id']] = |
---|
145 | get_complete_dir( $row['storage_category_id'] ); |
---|
146 | } |
---|
147 | $cat_directory = $array_cat_directories[$row['storage_category_id']]; |
---|
148 | $file_wo_ext = get_filename_wo_extension($row['file']); |
---|
149 | |
---|
150 | $icon = './template/'.$user['template'].'/mimetypes/'; |
---|
151 | $icon.= strtolower(get_extension($row['file'])).'.png'; |
---|
152 | |
---|
153 | if (isset($row['representative_ext']) and $row['representative_ext'] =! '') |
---|
154 | { |
---|
155 | $picture[$i]['src'] = $cat_directory.'representative/'; |
---|
156 | $picture[$i]['src'].= $file_wo_ext.'.'.$row['representative_ext']; |
---|
157 | } |
---|
158 | else |
---|
159 | { |
---|
160 | $picture[$i]['src'] = $icon; |
---|
161 | } |
---|
162 | // special case for picture files |
---|
163 | if ($picture[$i]['is_picture']) |
---|
164 | { |
---|
165 | $picture[$i]['src'] = $cat_directory.$row['file']; |
---|
166 | } |
---|
167 | |
---|
168 | // if picture is not a file, we need the download link |
---|
169 | if (!$picture[$i]['is_picture']) |
---|
170 | { |
---|
171 | $picture[$i]['download'] = $cat_directory.$row['file']; |
---|
172 | } |
---|
173 | |
---|
174 | if (isset($row['tn_ext']) and $row['tn_ext'] != '') |
---|
175 | { |
---|
176 | $picture[$i]['thumbnail'] = $cat_directory.'thumbnail/'; |
---|
177 | $picture[$i]['thumbnail'].= $conf['prefix_thumbnail'].$file_wo_ext; |
---|
178 | $picture[$i]['thumbnail'].= '.'.$row['tn_ext']; |
---|
179 | } |
---|
180 | else |
---|
181 | { |
---|
182 | $picture[$i]['thumbnail'] = $icon; |
---|
183 | } |
---|
184 | |
---|
185 | if ( !empty( $row['name'] ) ) |
---|
186 | { |
---|
187 | $picture[$i]['name'] = $row['name']; |
---|
188 | } |
---|
189 | else |
---|
190 | { |
---|
191 | $picture[$i]['name'] = str_replace('_', ' ', $file_wo_ext); |
---|
192 | } |
---|
193 | |
---|
194 | $picture[$i]['url'] = PHPWG_ROOT_PATH.'picture.php?image_id='.$row['id']; |
---|
195 | $picture[$i]['url'].= '&cat='.$page['cat']; |
---|
196 | if ( $page['cat'] == 'search' ) |
---|
197 | { |
---|
198 | $picture[$i]['url'].= '&search='.$_GET['search']; |
---|
199 | } |
---|
200 | if (isset($_GET['show_metadata'])) |
---|
201 | { |
---|
202 | $picture[$i]['url'].= '&show_metadata=1'; |
---|
203 | } |
---|
204 | } |
---|
205 | |
---|
206 | $url_home = PHPWG_ROOT_PATH.'category.php?cat='.$page['cat'].'&'; |
---|
207 | $url_home.= 'num='.$page['num']; |
---|
208 | if ( $page['cat'] == 'search' ) |
---|
209 | { |
---|
210 | $url_home.= "&search=".$_GET['search']; |
---|
211 | } |
---|
212 | |
---|
213 | $url_admin = PHPWG_ROOT_PATH.'admin.php?page=picture_modify'; |
---|
214 | $url_admin.= '&cat_id='.$page['cat']; |
---|
215 | $url_admin.= '&image_id='.$_GET['image_id']; |
---|
216 | |
---|
217 | //--------------------------------------------------------- favorite management |
---|
218 | if ( isset( $_GET['add_fav'] ) ) |
---|
219 | { |
---|
220 | $query = 'DELETE FROM '.FAVORITES_TABLE; |
---|
221 | $query.= ' WHERE user_id = '.$user['id']; |
---|
222 | $query.= ' AND image_id = '.$picture['current']['id']; |
---|
223 | $query.= ';'; |
---|
224 | $result = mysql_query( $query ); |
---|
225 | |
---|
226 | if ( $_GET['add_fav'] == 1 ) |
---|
227 | { |
---|
228 | $query = 'INSERT INTO '.FAVORITES_TABLE; |
---|
229 | $query.= ' (image_id,user_id) VALUES'; |
---|
230 | $query.= ' ('.$picture['current']['id'].','.$user['id'].')'; |
---|
231 | $query.= ';'; |
---|
232 | $result = mysql_query( $query ); |
---|
233 | } |
---|
234 | if ( !$_GET['add_fav'] and $page['cat'] == 'fav' ) |
---|
235 | { |
---|
236 | if (!$has_prev and $mysql_num_rows == 1) |
---|
237 | { |
---|
238 | // there is no favorite picture anymore we redirect the user to the |
---|
239 | // category page |
---|
240 | $url = add_session_id( $url_home ); |
---|
241 | redirect( $url ); |
---|
242 | } |
---|
243 | else if (!$has_prev) |
---|
244 | { |
---|
245 | $url = str_replace( '&', '&', $picture['next']['url'] ); |
---|
246 | $url = add_session_id( $url, true); |
---|
247 | } |
---|
248 | else |
---|
249 | { |
---|
250 | $url = str_replace('&', '&', $picture['prev']['url'] ); |
---|
251 | $url = add_session_id( $url, true); |
---|
252 | } |
---|
253 | redirect( $url ); |
---|
254 | } |
---|
255 | } |
---|
256 | |
---|
257 | //------------------------------------------------------ comment registeration |
---|
258 | if ( isset( $_POST['content'] ) && !empty($_POST['content']) ) |
---|
259 | { |
---|
260 | $register_comment = true; |
---|
261 | $author = !empty($_POST['author'])?$_POST['author']:$lang['guest']; |
---|
262 | // if a guest try to use the name of an already existing user, he must be |
---|
263 | // rejected |
---|
264 | if ( $author != $user['username'] ) |
---|
265 | { |
---|
266 | $query = 'SELECT COUNT(*) AS user_exists'; |
---|
267 | $query.= ' FROM '.USERS_TABLE; |
---|
268 | $query.= " WHERE username = '".$author."'"; |
---|
269 | $query.= ';'; |
---|
270 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
271 | if ( $row['user_exists'] == 1 ) |
---|
272 | { |
---|
273 | $template->assign_block_vars( |
---|
274 | 'information', |
---|
275 | array('INFORMATION'=>$lang['comment_user_exists'])); |
---|
276 | $register_comment = false; |
---|
277 | } |
---|
278 | } |
---|
279 | |
---|
280 | if ( $register_comment ) |
---|
281 | { |
---|
282 | // anti-flood system |
---|
283 | $reference_date = time() - $conf['anti-flood_time']; |
---|
284 | $query = 'SELECT id FROM '.COMMENTS_TABLE; |
---|
285 | $query.= ' WHERE date > FROM_UNIXTIME('.$reference_date.')'; |
---|
286 | $query.= " AND author = '".$author."'"; |
---|
287 | $query.= ';'; |
---|
288 | if ( mysql_num_rows( mysql_query( $query ) ) == 0 |
---|
289 | or $conf['anti-flood_time'] == 0 ) |
---|
290 | { |
---|
291 | $query = 'INSERT INTO '.COMMENTS_TABLE; |
---|
292 | $query.= ' (author,date,image_id,content,validated) VALUES ('; |
---|
293 | $query.= "'".$author."'"; |
---|
294 | $query.= ',NOW(),'.$_GET['image_id']; |
---|
295 | $query.= ",'".htmlspecialchars( $_POST['content'], ENT_QUOTES)."'"; |
---|
296 | if ( !$conf['comments_validation'] or $user['status'] == 'admin' ) |
---|
297 | { |
---|
298 | $query.= ",'true'"; |
---|
299 | } |
---|
300 | else |
---|
301 | { |
---|
302 | $query.= ",'false'"; |
---|
303 | } |
---|
304 | $query.= ');'; |
---|
305 | mysql_query( $query ); |
---|
306 | // information message |
---|
307 | $message = $lang['comment_added']; |
---|
308 | if ( $conf['comments_validation'] and $user['status'] != 'admin' ) |
---|
309 | { |
---|
310 | $message.= '<br />'.$lang['comment_to_validate']; |
---|
311 | } |
---|
312 | $template->assign_block_vars('information', |
---|
313 | array('INFORMATION'=>$message)); |
---|
314 | // notification to the administrators |
---|
315 | if ( $conf['mail_notification'] ) |
---|
316 | { |
---|
317 | $cat_name = get_cat_display_name( $page['cat_name'], ' > ', '' ); |
---|
318 | $cat_name = strip_tags( $cat_name ); |
---|
319 | notify( 'comment', $cat_name.' > '.$picture['current']['name']); |
---|
320 | } |
---|
321 | } |
---|
322 | else |
---|
323 | { |
---|
324 | // information message |
---|
325 | $template->assign_block_vars( |
---|
326 | 'information', |
---|
327 | array('INFORMATION'=>$lang['comment_anti-flood'])); |
---|
328 | } |
---|
329 | } |
---|
330 | } |
---|
331 | // comment deletion |
---|
332 | if ( isset( $_GET['del'] ) |
---|
333 | and is_numeric( $_GET['del'] ) |
---|
334 | and $user['status'] == 'admin' ) |
---|
335 | { |
---|
336 | $query = 'DELETE FROM '.COMMENTS_TABLE; |
---|
337 | $query.= ' WHERE id = '.$_GET['del']; |
---|
338 | $query.= ';'; |
---|
339 | mysql_query( $query ); |
---|
340 | } |
---|
341 | |
---|
342 | // |
---|
343 | // Start output of page |
---|
344 | // |
---|
345 | |
---|
346 | $title = $picture['current']['name']; |
---|
347 | $refresh = 0; |
---|
348 | if ( isset( $_GET['slideshow'] ) and $next ) |
---|
349 | { |
---|
350 | $refresh= $_GET['slideshow']; |
---|
351 | $url_link = $picture['next']['url'].'&slideshow='.$refresh; |
---|
352 | } |
---|
353 | |
---|
354 | $title_img = $picture['current']['name']; |
---|
355 | $title_nb = ''; |
---|
356 | if (is_numeric( $page['cat'] )) |
---|
357 | { |
---|
358 | $title_img = replace_space(get_cat_display_name( $page['cat_name'], " > ")); |
---|
359 | $n = $page['num'] + 1; |
---|
360 | $title_nb = "Photo".' '.$n.'/'; |
---|
361 | $title_nb.= $page['cat_nb_images']; |
---|
362 | //$title_img.= $picture['current']['name']; |
---|
363 | } |
---|
364 | else if ( $page['cat'] == 'search' ) |
---|
365 | { |
---|
366 | $title_img = replace_search( $title_img, $_GET['search'] ); |
---|
367 | } |
---|
368 | |
---|
369 | // calculation of width and height |
---|
370 | if (empty($picture['current']['width'])) |
---|
371 | { |
---|
372 | $taille_image = @getimagesize($picture['current']['src']); |
---|
373 | $original_width = $taille_image[0]; |
---|
374 | $original_height = $taille_image[1]; |
---|
375 | } |
---|
376 | else |
---|
377 | { |
---|
378 | $original_width = $picture['current']['width']; |
---|
379 | $original_height = $picture['current']['height']; |
---|
380 | } |
---|
381 | |
---|
382 | $picture_size = get_picture_size( $original_width, $original_height, |
---|
383 | $user['maxwidth'], $user['maxheight'] ); |
---|
384 | |
---|
385 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
386 | $template->set_filenames(array('picture'=>'picture.tpl')); |
---|
387 | |
---|
388 | $template->assign_vars(array( |
---|
389 | 'CATEGORY' => $title_img, |
---|
390 | 'PHOTO' => $title_nb, |
---|
391 | 'TITLE' => $picture['current']['name'], |
---|
392 | 'SRC_IMG' => $picture['current']['src'], |
---|
393 | 'ALT_IMG' => $picture['current']['file'], |
---|
394 | 'WIDTH_IMG' => $picture_size[0], |
---|
395 | 'HEIGHT_IMG' => $picture_size[1], |
---|
396 | |
---|
397 | 'L_SLIDESHOW' => $lang['slideshow'], |
---|
398 | 'L_TIME' => $lang['period_seconds'], |
---|
399 | 'L_STOP_SLIDESHOW' => $lang['slideshow_stop'], |
---|
400 | 'L_PREV_IMG' =>$lang['previous_image'].' : ', |
---|
401 | 'L_ADMIN' =>$lang['link_info_image'], |
---|
402 | 'L_BACK' =>$lang['back'], |
---|
403 | 'L_COMMENT_TITLE' =>$lang['comments_title'], |
---|
404 | 'L_ADD_COMMENT' =>$lang['comments_add'], |
---|
405 | 'L_DELETE_COMMENT' =>$lang['comments_del'], |
---|
406 | 'L_DELETE' =>$lang['delete'], |
---|
407 | 'L_SUBMIT' =>$lang['submit'], |
---|
408 | 'L_AUTHOR' =>$lang['author'], |
---|
409 | 'L_COMMENT' =>$lang['comment'], |
---|
410 | 'L_DOWNLOAD' => $lang['download'], |
---|
411 | 'L_DOWNLOAD_HINT' => $lang['download_hint'], |
---|
412 | 'L_PICTURE_SHOW_METADATA' => $lang['picture_show_metadata'], |
---|
413 | 'L_PICTURE_HIDE_METADATA' => $lang['picture_hide_metadata'], |
---|
414 | |
---|
415 | 'T_DEL_IMG' =>PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/delete.gif', |
---|
416 | |
---|
417 | 'U_HOME' => add_session_id($url_home), |
---|
418 | 'U_ADMIN' => add_session_id($url_admin), |
---|
419 | 'U_ADD_COMMENT' => add_session_id(str_replace( '&', '&', $_SERVER['REQUEST_URI'] )) |
---|
420 | ) |
---|
421 | ); |
---|
422 | |
---|
423 | //-------------------------------------------------------- slideshow management |
---|
424 | if ( isset( $_GET['slideshow'] ) ) |
---|
425 | { |
---|
426 | if ( !is_numeric( $_GET['slideshow'] ) ) $_GET['slideshow'] = $conf['slideshow_period'][0]; |
---|
427 | |
---|
428 | $template->assign_block_vars('stop_slideshow', array( |
---|
429 | 'U_SLIDESHOW'=>add_session_id( $picture['current']['url'] ) |
---|
430 | )); |
---|
431 | } |
---|
432 | else |
---|
433 | { |
---|
434 | $template->assign_block_vars('start_slideshow', array()); |
---|
435 | foreach ( $conf['slideshow_period'] as $option ) |
---|
436 | { |
---|
437 | $template->assign_block_vars('start_slideshow.second', array( |
---|
438 | 'SLIDESHOW_SPEED'=>$option, |
---|
439 | 'U_SLIDESHOW'=>add_session_id( $picture['current']['url'].'&slideshow='.$option) |
---|
440 | )); |
---|
441 | } |
---|
442 | } |
---|
443 | |
---|
444 | if ($has_prev) |
---|
445 | { |
---|
446 | $template->assign_block_vars( |
---|
447 | 'previous', |
---|
448 | array( |
---|
449 | 'TITLE_IMG' => $picture['prev']['name'], |
---|
450 | 'IMG' => $picture['prev']['thumbnail'], |
---|
451 | 'U_IMG' => add_session_id($picture['prev']['url']) |
---|
452 | )); |
---|
453 | } |
---|
454 | |
---|
455 | if ($has_next) |
---|
456 | { |
---|
457 | $template->assign_block_vars( |
---|
458 | 'next', |
---|
459 | array( |
---|
460 | 'TITLE_IMG' => $picture['next']['name'], |
---|
461 | 'IMG' => $picture['next']['thumbnail'], |
---|
462 | 'U_IMG' => add_session_id($picture['next']['url']) |
---|
463 | )); |
---|
464 | } |
---|
465 | |
---|
466 | //--------------------------------------------------------- picture information |
---|
467 | // legend |
---|
468 | if (isset($picture['current']['comment']) |
---|
469 | and !empty($picture['current']['comment'])) |
---|
470 | { |
---|
471 | $template->assign_block_vars( |
---|
472 | 'legend', |
---|
473 | array( |
---|
474 | 'COMMENT_IMG' => $picture['current']['comment'] |
---|
475 | )); |
---|
476 | } |
---|
477 | // download link if file is not a picture |
---|
478 | if (!$picture['current']['is_picture']) |
---|
479 | { |
---|
480 | $template->assign_block_vars( |
---|
481 | 'download', |
---|
482 | array( |
---|
483 | 'U_DOWNLOAD' => $picture['current']['download'] |
---|
484 | )); |
---|
485 | } |
---|
486 | |
---|
487 | // author |
---|
488 | if ( !empty($picture['current']['author']) ) |
---|
489 | { |
---|
490 | $template->assign_block_vars( |
---|
491 | 'info_line', |
---|
492 | array( |
---|
493 | 'INFO'=>$lang['author'], |
---|
494 | 'VALUE'=>$picture['current']['author'] |
---|
495 | )); |
---|
496 | } |
---|
497 | // creation date |
---|
498 | if ( !empty($picture['current']['date_creation']) ) |
---|
499 | { |
---|
500 | $template->assign_block_vars('info_line', array( |
---|
501 | 'INFO'=>$lang['creation_date'], |
---|
502 | 'VALUE'=>format_date( $picture['current']['date_creation'] ) |
---|
503 | )); |
---|
504 | } |
---|
505 | // date of availability |
---|
506 | $template->assign_block_vars('info_line', array( |
---|
507 | 'INFO'=>$lang['registration_date'], |
---|
508 | 'VALUE'=>format_date( $picture['current']['date_available'] ) |
---|
509 | )); |
---|
510 | // size in pixels |
---|
511 | if ($picture['current']['is_picture']) |
---|
512 | { |
---|
513 | if ($original_width != $picture_size[0] |
---|
514 | or $original_height != $picture_size[1]) |
---|
515 | { |
---|
516 | $content = '[ <a href="'.$picture['current']['url'].'" '; |
---|
517 | $content.= ' title="'.$lang['true_size'].'">'; |
---|
518 | $content.= $original_width.'*'.$original_height.'</a> ]'; |
---|
519 | } |
---|
520 | else |
---|
521 | { |
---|
522 | $content = $original_width.'*'.$original_height; |
---|
523 | } |
---|
524 | $template->assign_block_vars( |
---|
525 | 'info_line', |
---|
526 | array( |
---|
527 | 'INFO'=>$lang['size'], |
---|
528 | 'VALUE'=>$content |
---|
529 | )); |
---|
530 | } |
---|
531 | // file |
---|
532 | $template->assign_block_vars('info_line', array( |
---|
533 | 'INFO'=>$lang['file'], |
---|
534 | 'VALUE'=>$picture['current']['file'] |
---|
535 | )); |
---|
536 | // filesize |
---|
537 | if (empty($picture['current']['filesize'])) |
---|
538 | { |
---|
539 | if (!$picture[$i]['is_picture']) |
---|
540 | { |
---|
541 | $filesize = floor(filesize($picture['current']['download'])/1024); |
---|
542 | } |
---|
543 | else |
---|
544 | { |
---|
545 | $filesize = floor(filesize($picture['current']['src'])/1024); |
---|
546 | } |
---|
547 | } |
---|
548 | else |
---|
549 | { |
---|
550 | $filesize = $picture['current']['filesize']; |
---|
551 | } |
---|
552 | |
---|
553 | $template->assign_block_vars('info_line', array( |
---|
554 | 'INFO'=>$lang['filesize'], |
---|
555 | 'VALUE'=>$filesize.' KB' |
---|
556 | )); |
---|
557 | // keywords |
---|
558 | if ( !empty($picture['current']['keywords'])) |
---|
559 | { |
---|
560 | $keywords = explode( ',', $picture['current']['keywords'] ); |
---|
561 | $content = ''; |
---|
562 | $url = PHPWG_ROOT_PATH.'category.php?cat=search'; |
---|
563 | $url.= '&mode=OR&search='; |
---|
564 | foreach ( $keywords as $i => $keyword ) { |
---|
565 | $local_url = add_session_id( $url.$keyword ); |
---|
566 | if ( $i > 0 ) $content.= ','; |
---|
567 | $content.= '<a href="'.$local_url.'">'.$keyword.'</a>'; |
---|
568 | } |
---|
569 | $template->assign_block_vars('info_line', array( |
---|
570 | 'INFO'=>$lang['keywords'], |
---|
571 | 'VALUE'=>$content |
---|
572 | )); |
---|
573 | } |
---|
574 | // number of visits |
---|
575 | $template->assign_block_vars('info_line', array( |
---|
576 | 'INFO'=>$lang['visited'], |
---|
577 | 'VALUE'=>$picture['current']['hit'].' '.$lang['times'] |
---|
578 | )); |
---|
579 | //-------------------------------------------------------------------- metadata |
---|
580 | if ($conf['show_exif'] or $conf['show_iptc']) |
---|
581 | { |
---|
582 | $metadata_showable = true; |
---|
583 | } |
---|
584 | else |
---|
585 | { |
---|
586 | $metadata_showable = false; |
---|
587 | } |
---|
588 | |
---|
589 | if ($metadata_showable and !isset($_GET['show_metadata'])) |
---|
590 | { |
---|
591 | $url = PHPWG_ROOT_PATH.'picture.php?'.$_SERVER['QUERY_STRING']; |
---|
592 | $url.= '&show_metadata=1'; |
---|
593 | $template->assign_block_vars('show_metadata', array('URL' => $url)); |
---|
594 | } |
---|
595 | |
---|
596 | if ($metadata_showable and isset($_GET['show_metadata'])) |
---|
597 | { |
---|
598 | $url = PHPWG_ROOT_PATH.'picture.php'; |
---|
599 | |
---|
600 | $str = $_SERVER['QUERY_STRING']; |
---|
601 | parse_str($str, $get_vars); |
---|
602 | $is_first = true; |
---|
603 | foreach ($get_vars as $key => $value) |
---|
604 | { |
---|
605 | if ($key != 'show_metadata') |
---|
606 | { |
---|
607 | if ($is_first) |
---|
608 | { |
---|
609 | $url.= '?'; |
---|
610 | $is_first = false; |
---|
611 | } |
---|
612 | else |
---|
613 | { |
---|
614 | $url.= '&'; |
---|
615 | } |
---|
616 | $url.= $key.'='.$value; |
---|
617 | } |
---|
618 | } |
---|
619 | |
---|
620 | $template->assign_block_vars('hide_metadata', array('URL' => $url)); |
---|
621 | |
---|
622 | include_once(PHPWG_ROOT_PATH.'/include/functions_metadata.inc.php'); |
---|
623 | |
---|
624 | $template->assign_block_vars('metadata', array()); |
---|
625 | |
---|
626 | if ($conf['show_exif']) |
---|
627 | { |
---|
628 | if ($exif = @read_exif_data($picture['current']['src'])) |
---|
629 | { |
---|
630 | $template->assign_block_vars( |
---|
631 | 'metadata.headline', |
---|
632 | array('TITLE' => 'EXIF Metadata') |
---|
633 | ); |
---|
634 | |
---|
635 | foreach ($conf['show_exif_fields'] as $field) |
---|
636 | { |
---|
637 | if (strpos($field, ';') === false) |
---|
638 | { |
---|
639 | if (isset($exif[$field])) |
---|
640 | { |
---|
641 | $key = $field; |
---|
642 | if (isset($lang['exif_field_'.$field])) |
---|
643 | { |
---|
644 | $key = $lang['exif_field_'.$field]; |
---|
645 | } |
---|
646 | |
---|
647 | $template->assign_block_vars( |
---|
648 | 'metadata.line', |
---|
649 | array( |
---|
650 | 'KEY' => $key, |
---|
651 | 'VALUE' => $exif[$field] |
---|
652 | ) |
---|
653 | ); |
---|
654 | } |
---|
655 | } |
---|
656 | else |
---|
657 | { |
---|
658 | $tokens = explode(';', $field); |
---|
659 | if (isset($exif[$tokens[0]][$tokens[1]])) |
---|
660 | { |
---|
661 | $key = $tokens[1]; |
---|
662 | if (isset($lang['exif_field_'.$tokens[1]])) |
---|
663 | { |
---|
664 | $key = $lang['exif_field_'.$tokens[1]]; |
---|
665 | } |
---|
666 | |
---|
667 | $template->assign_block_vars( |
---|
668 | 'metadata.line', |
---|
669 | array( |
---|
670 | 'KEY' => $key, |
---|
671 | 'VALUE' => $exif[$tokens[0]][$tokens[1]] |
---|
672 | ) |
---|
673 | ); |
---|
674 | } |
---|
675 | } |
---|
676 | } |
---|
677 | } |
---|
678 | } |
---|
679 | |
---|
680 | if ($conf['show_iptc']) |
---|
681 | { |
---|
682 | $iptc = get_iptc_data($picture['current']['src'], |
---|
683 | $conf['show_iptc_mapping']); |
---|
684 | |
---|
685 | if (count($iptc) > 0) |
---|
686 | { |
---|
687 | $template->assign_block_vars( |
---|
688 | 'metadata.headline', |
---|
689 | array('TITLE' => 'IPTC Metadata') |
---|
690 | ); |
---|
691 | } |
---|
692 | |
---|
693 | foreach ($iptc as $field => $value) |
---|
694 | { |
---|
695 | $key = $field; |
---|
696 | if (isset($lang[$field])) |
---|
697 | { |
---|
698 | $key = $lang[$field]; |
---|
699 | } |
---|
700 | |
---|
701 | $template->assign_block_vars( |
---|
702 | 'metadata.line', |
---|
703 | array( |
---|
704 | 'KEY' => $key, |
---|
705 | 'VALUE' => $value |
---|
706 | ) |
---|
707 | ); |
---|
708 | } |
---|
709 | } |
---|
710 | } |
---|
711 | //------------------------------------------------------- favorite manipulation |
---|
712 | if ( !$user['is_the_guest'] ) |
---|
713 | { |
---|
714 | // verify if the picture is already in the favorite of the user |
---|
715 | $query = 'SELECT COUNT(*) AS nb_fav'; |
---|
716 | $query.= ' FROM '.FAVORITES_TABLE.' WHERE image_id = '.$_GET['image_id']; |
---|
717 | $query.= ' AND user_id = '.$user['id'].';'; |
---|
718 | $result = mysql_query( $query ); |
---|
719 | $row = mysql_fetch_array( $result ); |
---|
720 | if (!$row['nb_fav']) |
---|
721 | { |
---|
722 | $url = PHPWG_ROOT_PATH.'picture.php?cat='.$page['cat'].'&image_id='.$_GET['image_id']; |
---|
723 | $url.='&add_fav=1'; |
---|
724 | if ( $page['cat'] == 'search' ) |
---|
725 | { |
---|
726 | $url.= '&search='.$_GET['search']; |
---|
727 | } |
---|
728 | $template->assign_block_vars('favorite', array( |
---|
729 | 'FAVORITE_IMG' => PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/favorite.gif', |
---|
730 | 'FAVORITE_HINT' =>$lang['add_favorites_hint'], |
---|
731 | 'FAVORITE_ALT' =>'[ '.$lang['add_favorites_alt'].' ]', |
---|
732 | 'U_FAVORITE'=> add_session_id( $url ) |
---|
733 | )); |
---|
734 | } |
---|
735 | else |
---|
736 | { |
---|
737 | $url = PHPWG_ROOT_PATH.'picture.php?cat='.$page['cat'].'&image_id='.$_GET['image_id']; |
---|
738 | $url.= '&add_fav=0'; |
---|
739 | $template->assign_block_vars('favorite', array( |
---|
740 | 'FAVORITE_IMG' => PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/del_favorite.gif', |
---|
741 | 'FAVORITE_HINT' =>$lang['del_favorites_hint'], |
---|
742 | 'FAVORITE_ALT' =>'[ '.$lang['del_favorites_alt'].' ]', |
---|
743 | 'U_FAVORITE'=> add_session_id( $url ) |
---|
744 | )); |
---|
745 | } |
---|
746 | } |
---|
747 | //------------------------------------ admin link for information modifications |
---|
748 | if ( $user['status'] == 'admin' ) |
---|
749 | { |
---|
750 | $template->assign_block_vars('modification', array()); |
---|
751 | } |
---|
752 | |
---|
753 | //---------------------------------------------------- users's comments display |
---|
754 | if ( $conf['show_comments'] ) |
---|
755 | { |
---|
756 | // number of comment for this picture |
---|
757 | $query = 'SELECT COUNT(*) AS nb_comments'; |
---|
758 | $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id']; |
---|
759 | $query.= " AND validated = 'true'"; |
---|
760 | $query.= ';'; |
---|
761 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
762 | |
---|
763 | // navigation bar creation |
---|
764 | $url = PHPWG_ROOT_PATH.'picture.php?cat='.$page['cat'].'&image_id='.$_GET['image_id']; |
---|
765 | if ( $page['cat'] == 'search' ) |
---|
766 | { |
---|
767 | $url.= '&search='.$_GET['search']; |
---|
768 | } |
---|
769 | if( !isset( $_GET['start'] ) |
---|
770 | or !is_numeric( $_GET['start'] ) |
---|
771 | or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) ) |
---|
772 | { |
---|
773 | $page['start'] = 0; |
---|
774 | } |
---|
775 | else |
---|
776 | { |
---|
777 | $page['start'] = $_GET['start']; |
---|
778 | } |
---|
779 | $page['navigation_bar'] = create_navigation_bar( $url, $row['nb_comments'], |
---|
780 | $page['start'], |
---|
781 | $conf['nb_comment_page'], |
---|
782 | '' ); |
---|
783 | $template->assign_block_vars('comments', array( |
---|
784 | 'NB_COMMENT'=>$row['nb_comments'], |
---|
785 | 'NAV_BAR'=>$page['navigation_bar'])); |
---|
786 | |
---|
787 | $query = 'SELECT id,author,date,image_id,content'; |
---|
788 | $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id']; |
---|
789 | $query.= " AND validated = 'true'"; |
---|
790 | $query.= ' ORDER BY date ASC'; |
---|
791 | $query.= ' LIMIT '.$page['start'].', '.$conf['nb_comment_page'].';'; |
---|
792 | $result = mysql_query( $query ); |
---|
793 | |
---|
794 | while ( $row = mysql_fetch_array( $result ) ) |
---|
795 | { |
---|
796 | $content = nl2br( $row['content'] ); |
---|
797 | |
---|
798 | // replace _word_ by an underlined word |
---|
799 | $pattern = '/_([^\s]*)_/'; |
---|
800 | $replacement = '<span style="text-decoration:underline;">\1</span>'; |
---|
801 | $content = preg_replace( $pattern, $replacement, $content ); |
---|
802 | |
---|
803 | // replace *word* by a bolded word |
---|
804 | $pattern = '/\*([^\s]*)\*/'; |
---|
805 | $replacement = '<span style="font-weight:bold;">\1</span>'; |
---|
806 | $content = preg_replace( $pattern, $replacement, $content ); |
---|
807 | |
---|
808 | // replace /word/ by an italic word |
---|
809 | $pattern = '/\/([^\s]*)\//'; |
---|
810 | $replacement = '<span style="font-style:italic;">\1</span>'; |
---|
811 | $content = preg_replace( $pattern, $replacement, $content ); |
---|
812 | |
---|
813 | $template->assign_block_vars('comments.comment', array( |
---|
814 | 'COMMENT_AUTHOR'=>empty($row['author'])?$lang['guest']:$row['author'], |
---|
815 | 'COMMENT_DATE'=>format_date( $row['date'], 'mysql_datetime', true ), |
---|
816 | 'COMMENT'=>$content |
---|
817 | )); |
---|
818 | |
---|
819 | if ( $user['status'] == 'admin' ) |
---|
820 | { |
---|
821 | $template->assign_block_vars('comments.comment.delete', array('U_COMMENT_DELETE'=>add_session_id( $url.'&del='.$row['id'] ))); |
---|
822 | } |
---|
823 | } |
---|
824 | |
---|
825 | if ( !$user['is_the_guest']||( $user['is_the_guest'] and $conf['comments_forall'] ) ) |
---|
826 | { |
---|
827 | $template->assign_block_vars('comments.add_comment', array()); |
---|
828 | // display author field if the user is not logged in |
---|
829 | if ( !$user['is_the_guest'] ) |
---|
830 | { |
---|
831 | $template->assign_block_vars('comments.add_comment.author_known', array('KNOWN_AUTHOR'=>$user['username'])); |
---|
832 | } |
---|
833 | else |
---|
834 | { |
---|
835 | $template->assign_block_vars('comments.add_comment.author_field', array()); |
---|
836 | } |
---|
837 | } |
---|
838 | } |
---|
839 | //------------------------------------------------------------ log informations |
---|
840 | pwg_log( 'picture', $title_img, $picture['current']['file'] ); |
---|
841 | mysql_close(); |
---|
842 | |
---|
843 | $template->pparse('picture'); |
---|
844 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
845 | ?> |
---|