1 | <?php |
---|
2 | /*************************************************************************** |
---|
3 | * picture.php * |
---|
4 | * ------------------- * |
---|
5 | * application : PhpWebGallery 1.3 <http://phpwebgallery.net> * |
---|
6 | * author : Pierrick LE GALL <pierrick@z0rglub.com> * |
---|
7 | * * |
---|
8 | * $Id: picture.php 350 2004-02-05 23:18:05Z z0rglub $ |
---|
9 | * * |
---|
10 | ***************************************************************************/ |
---|
11 | |
---|
12 | /*************************************************************************** |
---|
13 | * * |
---|
14 | * This program is free software; you can redistribute it and/or modify * |
---|
15 | * it under the terms of the GNU General Public License as published by * |
---|
16 | * the Free Software Foundation; * |
---|
17 | * * |
---|
18 | ***************************************************************************/ |
---|
19 | // this page shows the image full size |
---|
20 | //----------------------------------------------------------- personnal include |
---|
21 | include_once( './include/init.inc.php' ); |
---|
22 | //-------------------------------------------------- access authorization check |
---|
23 | check_cat_id( $_GET['cat'] ); |
---|
24 | check_login_authorization(); |
---|
25 | if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) ) |
---|
26 | { |
---|
27 | check_restrictions( $page['cat'] ); |
---|
28 | } |
---|
29 | //---------------------------------------- incrementation of the number of hits |
---|
30 | $query = 'UPDATE '.PREFIX_TABLE.'images'; |
---|
31 | $query.= ' SET hit=hit+1'; |
---|
32 | $query.= ' WHERE id='.$_GET['image_id']; |
---|
33 | $query.= ';'; |
---|
34 | @mysql_query( $query ); |
---|
35 | //-------------------------------------------------------------- initialization |
---|
36 | initialize_category( 'picture' ); |
---|
37 | //------------------------------------- main picture information initialization |
---|
38 | $infos = array( 'id','date_available','comment','hit','keywords','author' |
---|
39 | ,'name','file','date_creation','filesize','width','height' |
---|
40 | ,'storage_category_id' ); |
---|
41 | |
---|
42 | $query = 'SELECT '.implode( ',', $infos ); |
---|
43 | if ( is_numeric( $page['cat'] ) ) $query.= ',category_id'; |
---|
44 | $query.= ' FROM '.PREFIX_TABLE.'images'; |
---|
45 | $query.= ' INNER JOIN '.PREFIX_TABLE.'image_category AS ic'; |
---|
46 | $query.= ' ON id = ic.image_id'; |
---|
47 | $query.= $page['where']; |
---|
48 | $query.= ' AND id = '.$_GET['image_id']; |
---|
49 | $query.= $conf['order_by']; |
---|
50 | $query.= ';'; |
---|
51 | $result = mysql_query( $query ); |
---|
52 | // if this image_id doesn't correspond to this category, an error message is |
---|
53 | // displayed, and execution is stopped |
---|
54 | if ( mysql_num_rows( $result ) == 0 ) |
---|
55 | { |
---|
56 | echo '<div style="text-align:center;">'.$lang['access_forbiden'].'<br />'; |
---|
57 | echo '<a href="'.add_session_id( './category.php' ).'">'; |
---|
58 | echo $lang['thumbnails'].'</a></div>'; |
---|
59 | exit(); |
---|
60 | } |
---|
61 | $row = mysql_fetch_array( $result ); |
---|
62 | |
---|
63 | foreach ( $infos as $info ) { |
---|
64 | if ( isset( $row[$info] ) ) $page[$info] = $row[$info]; |
---|
65 | else $page[$info] = ''; |
---|
66 | } |
---|
67 | if ( is_numeric( $page['cat'] ) ) $page['category_id'] = $row['category_id']; |
---|
68 | // retrieving the number of the picture in its category (in order) |
---|
69 | $query = 'SELECT DISTINCT(id)'; |
---|
70 | $query.= ' FROM '.PREFIX_TABLE.'images'; |
---|
71 | $query.= ' INNER JOIN '.PREFIX_TABLE.'image_category AS ic'; |
---|
72 | $query.= ' ON id = ic.image_id'; |
---|
73 | $query.= $page['where']; |
---|
74 | $query.= $conf['order_by']; |
---|
75 | $query.= ';'; |
---|
76 | $result = mysql_query( $query ); |
---|
77 | $page['num'] = 0; |
---|
78 | $row = mysql_fetch_array( $result ); |
---|
79 | while ( $row['id'] != $page['id'] ) |
---|
80 | { |
---|
81 | $page['num']++; |
---|
82 | $row = mysql_fetch_array( $result ); |
---|
83 | } |
---|
84 | //--------------------------------------------------------- favorite management |
---|
85 | if ( isset( $_GET['add_fav'] ) ) |
---|
86 | { |
---|
87 | if ( $_GET['add_fav'] == 1 ) |
---|
88 | { |
---|
89 | // verify if the picture is already in the favorite of the user |
---|
90 | $query = 'SELECT COUNT(*) AS nb_fav'; |
---|
91 | $query.= ' FROM '.PREFIX_TABLE.'favorites'; |
---|
92 | $query.= ' WHERE image_id = '.$page['id']; |
---|
93 | $query.= ' AND user_id = '.$user['id']; |
---|
94 | $query.= ';'; |
---|
95 | $result = mysql_query( $query ); |
---|
96 | $row = mysql_fetch_array( $result ); |
---|
97 | if ( $row['nb_fav'] == 0 ) |
---|
98 | { |
---|
99 | $query = 'INSERT INTO '.PREFIX_TABLE.'favorites'; |
---|
100 | $query.= ' (image_id,user_id) VALUES'; |
---|
101 | $query.= ' ('.$page['id'].','.$user['id'].')'; |
---|
102 | $query.= ';'; |
---|
103 | $result = mysql_query( $query ); |
---|
104 | } |
---|
105 | } |
---|
106 | if ( $_GET['add_fav'] == 0 ) |
---|
107 | { |
---|
108 | $query = 'DELETE FROM '.PREFIX_TABLE.'favorites'; |
---|
109 | $query.= ' WHERE user_id = '.$user['id']; |
---|
110 | $query.= ' AND image_id = '.$page['id']; |
---|
111 | $query.= ';'; |
---|
112 | $result = mysql_query( $query ); |
---|
113 | |
---|
114 | $page['cat_nb_images'] = $page['cat_nb_images'] - 1; |
---|
115 | if ( $page['cat_nb_images'] <= 0 ) |
---|
116 | { |
---|
117 | // there is no favorite picture anymore |
---|
118 | // we redirect the user to the category page |
---|
119 | $url = add_session_id( 'category.php' ); |
---|
120 | header( 'Request-URI: '.$url ); |
---|
121 | header( 'Content-Location: '.$url ); |
---|
122 | header( 'Location: '.$url ); |
---|
123 | exit(); |
---|
124 | } |
---|
125 | // redirection of the user to the picture.php page |
---|
126 | // with the right picture |
---|
127 | $page['num'] = $page['num'] - 1; |
---|
128 | if ( $page['num'] == -1 ) |
---|
129 | { |
---|
130 | $page['num'] = 0; |
---|
131 | } |
---|
132 | $query = 'SELECT id'; |
---|
133 | $query.= ' FROM '.PREFIX_TABLE.'images'; |
---|
134 | $query.= ' INNER JOIN '.PREFIX_TABLE.'image_category AS ic'; |
---|
135 | $query.= ' ON id = ic.image_id'; |
---|
136 | $query.= $page['where']; |
---|
137 | $query.= $conf['order_by']; |
---|
138 | $query.= ' LIMIT '.$page['num'].',1'; |
---|
139 | $query.= ';'; |
---|
140 | $result = mysql_query( $query ); |
---|
141 | $row = mysql_fetch_array( $result ); |
---|
142 | $redirect = './picture.php?image_id='.$row['id'].'&cat='.$page['cat']; |
---|
143 | $redirect.= '&expand='.$_GET['expand']; |
---|
144 | if ( $page['cat'] == 'search' ) |
---|
145 | { |
---|
146 | $redirect.= '&search='.$_GET['search'].'&mode='.$_GET['mode']; |
---|
147 | } |
---|
148 | $url = add_session_id( $redirect, true ); |
---|
149 | header( 'Request-URI: '.$url ); |
---|
150 | header( 'Content-Location: '.$url ); |
---|
151 | header( 'Location: '.$url ); |
---|
152 | exit(); |
---|
153 | } |
---|
154 | } |
---|
155 | |
---|
156 | //---------------------------------------------- next picture thumbnail display |
---|
157 | $next = 0; |
---|
158 | if ( $page['num'] < $page['cat_nb_images']-1 ) |
---|
159 | { |
---|
160 | $next = $page['num'] + 1; |
---|
161 | $query = 'SELECT DISTINCT(id),name,file,tn_ext,storage_category_id'; |
---|
162 | $query.= ' FROM '.PREFIX_TABLE.'images'; |
---|
163 | $query.= ' INNER JOIN '.PREFIX_TABLE.'image_category AS ic'; |
---|
164 | $query.= ' ON id=ic.image_id'; |
---|
165 | $query.= $page['where']; |
---|
166 | $query.= $conf['order_by']; |
---|
167 | $query.= ' LIMIT '.$next.',1'; |
---|
168 | $query.= ';'; |
---|
169 | $result = mysql_query( $query ); |
---|
170 | $row = mysql_fetch_array( $result ); |
---|
171 | |
---|
172 | if ( !isset($array_cat_directories[$row['storage_category_id']])) |
---|
173 | { |
---|
174 | $array_cat_directories[$row['storage_category_id']] = |
---|
175 | get_complete_dir( $row['storage_category_id'] ); |
---|
176 | } |
---|
177 | $cat_directory = $array_cat_directories[$row['storage_category_id']]; |
---|
178 | |
---|
179 | $file = substr ( $row['file'], 0, strrpos ( $row['file'], ".") ); |
---|
180 | $next_lien_thumbnail = $cat_directory.'thumbnail/'; |
---|
181 | $next_lien_thumbnail.= $conf['prefix_thumbnail'].$file.".".$row['tn_ext']; |
---|
182 | |
---|
183 | if ( isset( $row['name'] ) and $row['name'] != '' ) |
---|
184 | { |
---|
185 | $next_alt_thumbnail = $row['name']; |
---|
186 | } |
---|
187 | else |
---|
188 | { |
---|
189 | $next_alt_thumbnail = $file; |
---|
190 | } |
---|
191 | $next_title = $lang['next_image']." : ".$next_alt_thumbnail; |
---|
192 | |
---|
193 | $next_url_link = './picture.php?image_id='.$row['id']; |
---|
194 | $next_url_link.= '&cat='.$page['cat']; |
---|
195 | if ( isset( $_GET['expand'] ) ) |
---|
196 | $next_url_link.= '&expand='.$_GET['expand']; |
---|
197 | if ( $page['cat'] == 'search' ) |
---|
198 | { |
---|
199 | $next_url_link.= "&search=".$_GET['search'].'&mode='.$_GET['mode']; |
---|
200 | } |
---|
201 | } |
---|
202 | //----------------------------------------------------- template initialization |
---|
203 | // |
---|
204 | // Start output of page |
---|
205 | // |
---|
206 | //------------------------------------------------------------------ page title |
---|
207 | $title = $page['name']; |
---|
208 | if ( $title == '') |
---|
209 | { |
---|
210 | $title = str_replace("_"," ",get_filename_wo_extension($page['file'])); |
---|
211 | } |
---|
212 | $refresh = 0; |
---|
213 | if ( isset( $_GET['slideshow'] ) && isset($next_url_link)) |
---|
214 | { |
---|
215 | $refresh= $_GET['slideshow']; |
---|
216 | $url_link = $next_url_link; |
---|
217 | } |
---|
218 | include('include/page_header.php'); |
---|
219 | |
---|
220 | $handle = $vtp->Open( './template/'.$user['template'].'/picture.vtp' ); |
---|
221 | initialize_template(); |
---|
222 | |
---|
223 | $tpl = array( 'back','submit','comments_title','comments_del','delete', |
---|
224 | 'comments_add','author','slideshow','slideshow_stop', |
---|
225 | 'period_seconds' ); |
---|
226 | templatize_array( $tpl, 'lang', $handle ); |
---|
227 | //-------------------------------------------------------- slideshow management |
---|
228 | if ( isset( $_GET['slideshow'] ) ) |
---|
229 | { |
---|
230 | if ( !is_numeric( $_GET['slideshow'] ) ) |
---|
231 | $_GET['slideshow'] = $conf['slideshow_period'][0]; |
---|
232 | $vtp->addSession( $handle, 'stop_slideshow' ); |
---|
233 | $url = './picture.php'; |
---|
234 | $url.= '?image_id='.$page['id']; |
---|
235 | $url.= '&cat='.$page['cat']; |
---|
236 | $url.= '&expand='.$_GET['expand']; |
---|
237 | if ( $page['cat'] == 'search' ) |
---|
238 | { |
---|
239 | $url.= '&search='.$_GET['search']; |
---|
240 | $url.= '&mode='.$_GET['mode']; |
---|
241 | } |
---|
242 | $vtp->setVar( $handle, 'stop_slideshow.url', add_session_id( $url ) ); |
---|
243 | $vtp->closeSession( $handle, 'stop_slideshow' ); |
---|
244 | } |
---|
245 | else |
---|
246 | { |
---|
247 | $vtp->addSession( $handle, 'start_slideshow' ); |
---|
248 | foreach ( $conf['slideshow_period'] as $option ) { |
---|
249 | $vtp->addSession( $handle, 'second' ); |
---|
250 | $vtp->setVar( $handle, 'second.option', $option ); |
---|
251 | $url = './picture.php'; |
---|
252 | $url.= '?image_id='.$page['id']; |
---|
253 | $url.= '&cat='.$page['cat']; |
---|
254 | if (isset($_GET['expand'])) |
---|
255 | $url.= '&expand='.$_GET['expand']; |
---|
256 | if ( $page['cat'] == 'search' ) |
---|
257 | { |
---|
258 | $url.= '&search='.$_GET['search']; |
---|
259 | $url.= '&mode='.$_GET['mode']; |
---|
260 | } |
---|
261 | $url.= '&slideshow='.$option; |
---|
262 | $vtp->setVar( $handle, 'second.url', add_session_id( $url ) ); |
---|
263 | $vtp->closeSession( $handle, 'second' ); |
---|
264 | } |
---|
265 | $vtp->closeSession( $handle, 'start_slideshow' ); |
---|
266 | } |
---|
267 | |
---|
268 | //-------------------------------------------------- previous picture thumbnail |
---|
269 | if ( $page['num'] >= 1 ) |
---|
270 | { |
---|
271 | $prev = $page['num'] - 1; |
---|
272 | $query = 'SELECT DISTINCT(id),name,file,tn_ext,storage_category_id'; |
---|
273 | $query.= ' FROM '.PREFIX_TABLE.'images'; |
---|
274 | $query.= ' INNER JOIN '.PREFIX_TABLE.'image_category AS ic'; |
---|
275 | $query.= ' ON id=ic.image_id'; |
---|
276 | $query.= $page['where']; |
---|
277 | $query.= $conf['order_by']; |
---|
278 | $query.= ' LIMIT '.$prev.',1'; |
---|
279 | $query.= ';'; |
---|
280 | $result = mysql_query( $query ); |
---|
281 | $row = mysql_fetch_array( $result ); |
---|
282 | |
---|
283 | if ( !isset($array_cat_directories[$row['storage_category_id']]) ) |
---|
284 | { |
---|
285 | $array_cat_directories[$row['storage_category_id']] = |
---|
286 | get_complete_dir( $row['storage_category_id'] ); |
---|
287 | } |
---|
288 | $cat_directory = $array_cat_directories[$row['storage_category_id']]; |
---|
289 | |
---|
290 | $file = substr( $row['file'], 0, strrpos ( $row['file'], '.' ) ); |
---|
291 | $lien_thumbnail = $cat_directory.'thumbnail/'; |
---|
292 | $lien_thumbnail.= $conf['prefix_thumbnail'].$file.".".$row['tn_ext']; |
---|
293 | |
---|
294 | $prev_title = $lang['previous_image'].' : '; |
---|
295 | |
---|
296 | if ( isset( $row['name'] ) and $row['name'] != '' ) |
---|
297 | $alt_thumbnail = $row['name']; |
---|
298 | else |
---|
299 | $alt_thumbnail = $file; |
---|
300 | |
---|
301 | $prev_title.= $alt_thumbnail; |
---|
302 | |
---|
303 | $url_link = './picture.php?image_id='.$row['id'].'&cat='.$page['cat']; |
---|
304 | if ( isset( $_GET['expand'] ) ) $url_link.= '&expand='.$_GET['expand']; |
---|
305 | if ( $page['cat'] == 'search' ) |
---|
306 | { |
---|
307 | $url_link.= '&search='.$_GET['search'].'&mode='.$_GET['mode']; |
---|
308 | } |
---|
309 | // sending vars for display |
---|
310 | $vtp->addSession( $handle, 'previous' ); |
---|
311 | $vtp->setGlobalVar( $handle, 'previous.url', add_session_id( $url_link ) ); |
---|
312 | $vtp->setGlobalVar( $handle, 'previous.title', $prev_title ); |
---|
313 | $vtp->setGlobalVar( $handle, 'previous.src', $lien_thumbnail ); |
---|
314 | $vtp->setGlobalVar( $handle, 'previous.alt', $alt_thumbnail ); |
---|
315 | $vtp->closeSession( $handle, 'previous' ); |
---|
316 | } |
---|
317 | else |
---|
318 | { |
---|
319 | $vtp->addSession( $handle, 'previous_empty' ); |
---|
320 | $vtp->closeSession( $handle, 'previous_empty' ); |
---|
321 | } |
---|
322 | //-------------------------------------------------------- main picture display |
---|
323 | if ( is_numeric( $page['cat'] ) ) |
---|
324 | { |
---|
325 | $intitule_cat = get_cat_display_name( $page['cat_name'], " - ", |
---|
326 | "font-style:italic;" ); |
---|
327 | } |
---|
328 | else |
---|
329 | { |
---|
330 | $intitule_cat = $page['title']; |
---|
331 | } |
---|
332 | |
---|
333 | if ( !isset($array_cat_directories[$page['storage_category_id']]) ) |
---|
334 | { |
---|
335 | $array_cat_directories[$page['storage_category_id']] = |
---|
336 | get_complete_dir( $page['storage_category_id'] ); |
---|
337 | } |
---|
338 | $cat_directory = $array_cat_directories[$page['storage_category_id']]; |
---|
339 | |
---|
340 | $n = $page['num'] + 1; |
---|
341 | $intitule_titre = replace_space( $intitule_cat." - " ).$n.'/'; |
---|
342 | $intitule_titre.= $page['cat_nb_images']."<br />"; |
---|
343 | if ( $page['name'] != "" ) |
---|
344 | { |
---|
345 | $intitule_file = $page['name']; |
---|
346 | } |
---|
347 | else |
---|
348 | { |
---|
349 | $intitule_file = str_replace( "_", " ", |
---|
350 | substr( $page['file'], 0, |
---|
351 | strrpos ( $page['file'], ".") ) ); |
---|
352 | } |
---|
353 | if ( $page['cat'] == 'search' ) |
---|
354 | { |
---|
355 | $intitule_file = replace_search( $intitule_file, $_GET['search'] ); |
---|
356 | } |
---|
357 | $vtp->setGlobalVar( $handle, 'title', $intitule_titre.$intitule_file ); |
---|
358 | |
---|
359 | $lien_image = $cat_directory.$page['file']; |
---|
360 | |
---|
361 | // calculation of width and height |
---|
362 | if ( $page['width'] == "" ) |
---|
363 | { |
---|
364 | $taille_image = @getimagesize( $lien_image ); |
---|
365 | $original_width = $taille_image[0]; |
---|
366 | $original_height = $taille_image[1]; |
---|
367 | } |
---|
368 | else |
---|
369 | { |
---|
370 | $original_width = $page['width']; |
---|
371 | $original_height = $page['height']; |
---|
372 | } |
---|
373 | |
---|
374 | $picture_size = get_picture_size( $original_width, $original_height, |
---|
375 | $user['maxwidth'], $user['maxheight'] ); |
---|
376 | $final_width = $picture_size[0]; |
---|
377 | $final_height = $picture_size[1]; |
---|
378 | |
---|
379 | $url_link = './category.php?cat='.$page['cat'].'&'; |
---|
380 | $url_link.= 'num='.$page['num']; |
---|
381 | if (isset($_GET['expand'])) |
---|
382 | $url_link.='&expand='.$_GET['expand']; |
---|
383 | if ( $page['cat'] == 'search' ) |
---|
384 | { |
---|
385 | $url_link.= "&search=".$_GET['search'].'&mode='.$_GET['mode']; |
---|
386 | } |
---|
387 | $vtp->setGlobalVar( $handle, 'picture_link', add_session_id( $url_link ) ); |
---|
388 | $vtp->setGlobalVar( $handle, 'picture_width', $final_width ); |
---|
389 | $vtp->setGlobalVar( $handle, 'picture_height', $final_height ); |
---|
390 | $vtp->setGlobalVar( $handle, 'picture_src', $lien_image ); |
---|
391 | $vtp->setGlobalVar( $handle, 'picture_alt', $page['file'] ); |
---|
392 | |
---|
393 | if ( $page['comment'] != '' ) |
---|
394 | { |
---|
395 | if ( $page['cat'] == 'search' ) |
---|
396 | { |
---|
397 | $picture_comment = replace_search( $page['comment'], $_GET['search'] ); |
---|
398 | $vtp->setGlobalVar( $handle, 'picture_comment', $picture_comment ); |
---|
399 | } |
---|
400 | else |
---|
401 | { |
---|
402 | $vtp->setGlobalVar( $handle, 'picture_comment', $page['comment'] ); |
---|
403 | } |
---|
404 | } |
---|
405 | //--------------------------------------------------------- picture information |
---|
406 | // author |
---|
407 | if ( $page['author'] != "" ) |
---|
408 | { |
---|
409 | $vtp->addSession( $handle, 'info_line' ); |
---|
410 | $vtp->setVar( $handle, 'info_line.name', $lang['author'].' : ' ); |
---|
411 | $vtp->setVar( $handle, 'info_line.content', $page['author'] ); |
---|
412 | $vtp->closeSession( $handle, 'info_line' ); |
---|
413 | } |
---|
414 | // creation date |
---|
415 | if ( $page['date_creation'] != "" ) |
---|
416 | { |
---|
417 | $vtp->addSession( $handle, 'info_line' ); |
---|
418 | $vtp->setVar( $handle, 'info_line.name', $lang['creation_date'].' : ' ); |
---|
419 | $vtp->setVar( $handle, 'info_line.content', |
---|
420 | format_date( $page['date_creation'] ) ); |
---|
421 | $vtp->closeSession( $handle, 'info_line' ); |
---|
422 | } |
---|
423 | // date of availability |
---|
424 | $vtp->addSession( $handle, 'info_line' ); |
---|
425 | $vtp->setVar( $handle, 'info_line.name', $lang['registration_date'].' : ' ); |
---|
426 | list( $year,$month,$day ) = explode( '-', $page['date_available'] ); |
---|
427 | $vtp->setVar( $handle, 'info_line.content', |
---|
428 | format_date( $page['date_available'] ) ); |
---|
429 | $vtp->closeSession( $handle, 'info_line' ); |
---|
430 | // size in pixels |
---|
431 | $vtp->addSession( $handle, 'info_line' ); |
---|
432 | $vtp->setVar( $handle, 'info_line.name', $lang['size'].' : ' ); |
---|
433 | if ( $original_width != $final_width or $original_height != $final_height ) |
---|
434 | { |
---|
435 | $content = '[ <a href="'.$lien_image.'" title="'.$lang['true_size'].'">'; |
---|
436 | $content.= $original_width.'*'.$original_height.'</a> ]'; |
---|
437 | $vtp->setVar( $handle, 'info_line.content', $content ); |
---|
438 | } |
---|
439 | else |
---|
440 | { |
---|
441 | $content = $original_width.'*'.$original_height; |
---|
442 | $vtp->setVar( $handle, 'info_line.content', $content ); |
---|
443 | } |
---|
444 | $vtp->closeSession( $handle, 'info_line' ); |
---|
445 | // file |
---|
446 | $vtp->addSession( $handle, 'info_line' ); |
---|
447 | $vtp->setVar( $handle, 'info_line.name', $lang['file'].' : ' ); |
---|
448 | if ( $page['cat'] == 'search' ) |
---|
449 | { |
---|
450 | $content = replace_search( $page['file'], $_GET['search'] ); |
---|
451 | $vtp->setVar( $handle, 'info_line.content', $content ); |
---|
452 | } |
---|
453 | else |
---|
454 | { |
---|
455 | $vtp->setVar( $handle, 'info_line.content', $page['file'] ); |
---|
456 | } |
---|
457 | $vtp->closeSession( $handle, 'info_line' ); |
---|
458 | // filesize |
---|
459 | if ( $page['filesize'] == "" ) |
---|
460 | { |
---|
461 | $poids = floor ( filesize( $lien_image ) / 1024 ); |
---|
462 | } |
---|
463 | else |
---|
464 | { |
---|
465 | $poids = $page['filesize']; |
---|
466 | } |
---|
467 | $vtp->addSession( $handle, 'info_line' ); |
---|
468 | $vtp->setVar( $handle, 'info_line.name', $lang['filesize'].' : ' ); |
---|
469 | $vtp->setVar( $handle, 'info_line.content', $poids.' KB' ); |
---|
470 | $vtp->closeSession( $handle, 'info_line' ); |
---|
471 | // keywords |
---|
472 | if ( $page['keywords'] != '' ) |
---|
473 | { |
---|
474 | $vtp->addSession( $handle, 'info_line' ); |
---|
475 | $vtp->setVar( $handle, 'info_line.name', $lang['keywords'].' : ' ); |
---|
476 | $keywords = explode( ',', $page['keywords'] ); |
---|
477 | $content = ''; |
---|
478 | $url = './category.php?cat=search'; |
---|
479 | if ( isset( $_GET['expand'] ) ) $url.= '&expand='.$_GET['expand']; |
---|
480 | $url.= '&mode=OR&search='; |
---|
481 | foreach ( $keywords as $i => $keyword ) { |
---|
482 | $local_url = add_session_id( $url.$keyword ); |
---|
483 | if ( $i > 0 ) $content.= ','; |
---|
484 | $content.= '<a href="'.$local_url.'">'.$keyword.'</a>'; |
---|
485 | } |
---|
486 | $vtp->setVar( $handle, 'info_line.content', $content ); |
---|
487 | $vtp->closeSession( $handle, 'info_line' ); |
---|
488 | } |
---|
489 | // number of visits |
---|
490 | $vtp->addSession( $handle, 'info_line' ); |
---|
491 | $vtp->setVar( $handle, 'info_line.name', $lang['visited'].' : ' ); |
---|
492 | $vtp->setVar( $handle, 'info_line.content', $page['hit'].' '.$lang['times'] ); |
---|
493 | $vtp->closeSession( $handle, 'info_line' ); |
---|
494 | //------------------------------------------------------- favorite manipulation |
---|
495 | if ( !$user['is_the_guest'] ) |
---|
496 | { |
---|
497 | // verify if the picture is already in the favorite of the user |
---|
498 | $query = 'SELECT COUNT(*) AS nb_fav'; |
---|
499 | $query.= ' FROM '.PREFIX_TABLE.'favorites'; |
---|
500 | $query.= ' WHERE image_id = '.$page['id']; |
---|
501 | $query.= ' AND user_id = '.$user['id'].';'; |
---|
502 | $result = mysql_query( $query ); |
---|
503 | $row = mysql_fetch_array( $result ); |
---|
504 | if (!$row['nb_fav']) |
---|
505 | { |
---|
506 | $url = './picture.php?cat='.$page['cat'].'&image_id='.$page['id']; |
---|
507 | if (isset($_GET['expand'])) |
---|
508 | $url.= '&expand='.$_GET['expand']; |
---|
509 | $url.='&add_fav=1'; |
---|
510 | if ( $page['cat'] == 'search' ) |
---|
511 | { |
---|
512 | $url.= '&search='.$_GET['search'].'&mode='.$_GET['mode']; |
---|
513 | } |
---|
514 | $vtp->addSession( $handle, 'favorite' ); |
---|
515 | $vtp->setVar( $handle, 'favorite.link', add_session_id( $url ) ); |
---|
516 | $vtp->setVar( $handle, 'favorite.title', $lang['add_favorites_hint'] ); |
---|
517 | $vtp->setVar( $handle, 'favorite.src', |
---|
518 | './template/'.$user['template'].'/theme/favorite.gif' ); |
---|
519 | $vtp->setVar($handle,'favorite.alt','[ '.$lang['add_favorites_alt'].' ]'); |
---|
520 | $vtp->closeSession( $handle, 'favorite' ); |
---|
521 | } |
---|
522 | else |
---|
523 | { |
---|
524 | $url = './picture.php?cat='.$page['cat'].'&image_id='.$page['id']; |
---|
525 | $url.= '&expand='.$_GET['expand'].'&add_fav=0'; |
---|
526 | $vtp->addSession( $handle, 'favorite' ); |
---|
527 | $vtp->setVar( $handle, 'favorite.link', add_session_id( $url ) ); |
---|
528 | $vtp->setVar( $handle, 'favorite.title', $lang['del_favorites_hint'] ); |
---|
529 | $vtp->setVar( $handle, 'favorite.src', |
---|
530 | './template/'.$user['template'].'/theme/del_favorite.gif' ); |
---|
531 | $vtp->setVar($handle,'favorite.alt','[ '.$lang['del_favorites_alt'].' ]'); |
---|
532 | $vtp->closeSession( $handle, 'favorite' ); |
---|
533 | } |
---|
534 | } |
---|
535 | //------------------------------------ admin link for information modifications |
---|
536 | if ( $user['status'] == 'admin' ) |
---|
537 | { |
---|
538 | $vtp->addSession( $handle, 'modification' ); |
---|
539 | $url = './admin/admin.php?page=picture_modify&cat_id='.$page['cat']; |
---|
540 | $url.= '&image_id='.$page['id']; |
---|
541 | $vtp->setVar( $handle, 'modification.link', add_session_id( $url ) ); |
---|
542 | $vtp->setVar( $handle, 'modification.name', $lang['link_info_image'] ); |
---|
543 | } |
---|
544 | |
---|
545 | if ( $next ) |
---|
546 | { |
---|
547 | // sending vars for display |
---|
548 | $vtp->addSession( $handle, 'next' ); |
---|
549 | $vtp->setGlobalVar( $handle, 'next.url', add_session_id( $next_url_link ) ); |
---|
550 | $vtp->setGlobalVar( $handle, 'next.title', $next_title ); |
---|
551 | $vtp->setGlobalVar( $handle, 'next.src', $next_lien_thumbnail ); |
---|
552 | $vtp->setGlobalVar( $handle, 'next.alt', $next_alt_thumbnail ); |
---|
553 | $vtp->closeSession( $handle, 'next' ); |
---|
554 | } |
---|
555 | else |
---|
556 | { |
---|
557 | $vtp->addSession( $handle, 'next_empty' ); |
---|
558 | $vtp->closeSession( $handle, 'next_empty' ); |
---|
559 | } |
---|
560 | //---------------------------------------------------- users's comments display |
---|
561 | if ( $conf['show_comments'] ) |
---|
562 | { |
---|
563 | $vtp->addSession( $handle, 'comments' ); |
---|
564 | // comment registeration |
---|
565 | if ( isset( $_POST['content'] ) and $_POST['content'] != '' ) |
---|
566 | { |
---|
567 | $register_comment = true; |
---|
568 | |
---|
569 | if ( !$user['is_the_guest'] ) $author = $user['username']; |
---|
570 | if ( $_POST['author'] != '' ) $author = $_POST['author']; |
---|
571 | // if a guest try to use the name of an already existing user, he must |
---|
572 | // be rejected |
---|
573 | if ( isset( $author ) and $author != $user['username'] ) |
---|
574 | { |
---|
575 | $query = 'SELECT COUNT(*) AS user_exists'; |
---|
576 | $query.= ' FROM '.PREFIX_TABLE.'users'; |
---|
577 | $query.= " WHERE username = '".$author."'"; |
---|
578 | $query.= ';'; |
---|
579 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
580 | if ( $row['user_exists'] == 1 ) |
---|
581 | { |
---|
582 | $vtp->addSession( $handle, 'information' ); |
---|
583 | $message = $lang['comment_user_exists']; |
---|
584 | $vtp->setVar( $handle, 'information.content', $message ); |
---|
585 | $vtp->closeSession( $handle, 'information' ); |
---|
586 | $register_comment = false; |
---|
587 | } |
---|
588 | } |
---|
589 | |
---|
590 | if ( $register_comment ) |
---|
591 | { |
---|
592 | // anti-flood system |
---|
593 | $reference_date = time() - $conf['anti-flood_time']; |
---|
594 | $query = 'SELECT id'; |
---|
595 | $query.= ' FROM '.PREFIX_TABLE.'comments'; |
---|
596 | $query.= ' WHERE date > '.$reference_date; |
---|
597 | $query.= " AND author = '".$author."'"; |
---|
598 | $query.= ';'; |
---|
599 | if ( mysql_num_rows( mysql_query( $query ) ) == 0 |
---|
600 | or $conf['anti-flood_time'] == 0 ) |
---|
601 | { |
---|
602 | $query = 'INSERT INTO '.PREFIX_TABLE.'comments'; |
---|
603 | $query.= ' (author,date,image_id,content,validated) VALUES'; |
---|
604 | $query.= ' ('; |
---|
605 | if ( !isset( $author ) ) $query.= 'NULL'; |
---|
606 | else $query.= "'".$author."'"; |
---|
607 | $query.= ','.time().','.$page['id']; |
---|
608 | $query.= ",'".htmlspecialchars( $_POST['content'], ENT_QUOTES)."'"; |
---|
609 | if ( !$conf['comments_validation'] or $user['status'] == 'admin' ) |
---|
610 | $query.= ",'true'"; |
---|
611 | else |
---|
612 | $query.= ",'false'"; |
---|
613 | $query.= ');'; |
---|
614 | mysql_query( $query ); |
---|
615 | // information message |
---|
616 | $vtp->addSession( $handle, 'information' ); |
---|
617 | $message = $lang['comment_added']; |
---|
618 | if ( $conf['comments_validation'] and $user['status'] != 'admin' ) |
---|
619 | { |
---|
620 | $message.= '<br />'.$lang['comment_to_validate']; |
---|
621 | } |
---|
622 | $vtp->setVar( $handle, 'information.content', $message ); |
---|
623 | $vtp->closeSession( $handle, 'information' ); |
---|
624 | // notification to the administrators |
---|
625 | if ( $conf['mail_notification'] ) |
---|
626 | { |
---|
627 | $cat_name = get_cat_display_name( $page['cat_name'], ' > ', '' ); |
---|
628 | $cat_name = strip_tags( $cat_name ); |
---|
629 | if ( $page['name'] == '' ) $picture = $page['file']; |
---|
630 | else $picture = $page['name']; |
---|
631 | notify( 'comment', $cat_name.' > '.$picture ); |
---|
632 | } |
---|
633 | } |
---|
634 | else |
---|
635 | { |
---|
636 | // information message |
---|
637 | $vtp->addSession( $handle, 'information' ); |
---|
638 | $message = $lang['comment_anti-flood']; |
---|
639 | $vtp->setVar( $handle, 'information.content', $message ); |
---|
640 | $vtp->closeSession( $handle, 'information' ); |
---|
641 | } |
---|
642 | } |
---|
643 | } |
---|
644 | // comment deletion |
---|
645 | if ( isset( $_GET['del'] ) |
---|
646 | and is_numeric( $_GET['del'] ) |
---|
647 | and $user['status'] == 'admin' ) |
---|
648 | { |
---|
649 | $query = 'DELETE FROM '.PREFIX_TABLE.'comments'; |
---|
650 | $query.= ' WHERE id = '.$_GET['del'].';'; |
---|
651 | mysql_query( $query ); |
---|
652 | } |
---|
653 | // number of comment for this picture |
---|
654 | $query = 'SELECT COUNT(*) AS nb_comments'; |
---|
655 | $query.= ' FROM '.PREFIX_TABLE.'comments'; |
---|
656 | $query.= ' WHERE image_id = '.$page['id']; |
---|
657 | $query.= " AND validated = 'true'"; |
---|
658 | $query.= ';'; |
---|
659 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
660 | $page['nb_comments'] = $row['nb_comments']; |
---|
661 | // navigation bar creation |
---|
662 | $url = './picture.php?cat='.$page['cat'].'&image_id='.$page['id']; |
---|
663 | if (isset($_GET['expand'])) |
---|
664 | $url.= '&expand='.$_GET['expand']; |
---|
665 | if ( $page['cat'] == 'search' ) |
---|
666 | { |
---|
667 | $url.= '&search='.$_GET['search'].'&mode='.$_GET['mode']; |
---|
668 | } |
---|
669 | if( !isset( $_GET['start'] ) |
---|
670 | or !is_numeric( $_GET['start'] ) |
---|
671 | or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) ) |
---|
672 | { |
---|
673 | $page['start'] = 0; |
---|
674 | } |
---|
675 | else |
---|
676 | { |
---|
677 | $page['start'] = $_GET['start']; |
---|
678 | } |
---|
679 | $page['navigation_bar'] = create_navigation_bar( $url, $page['nb_comments'], |
---|
680 | $page['start'], |
---|
681 | $conf['nb_comment_page'], |
---|
682 | '' ); |
---|
683 | // sending vars for display |
---|
684 | $vtp->setGlobalVar( $handle, 'navigation_bar', $page['navigation_bar'] ); |
---|
685 | $vtp->setGlobalVar( $handle, 'nb_comments', $page['nb_comments'] ); |
---|
686 | |
---|
687 | $query = 'SELECT id,author,date,image_id,content'; |
---|
688 | $query.= ' FROM '.PREFIX_TABLE.'comments'; |
---|
689 | $query.= ' WHERE image_id = '.$page['id']; |
---|
690 | $query.= " AND validated = 'true'"; |
---|
691 | $query.= ' ORDER BY date ASC'; |
---|
692 | $query.= ' LIMIT '.$page['start'].', '.$conf['nb_comment_page'].';'; |
---|
693 | $result = mysql_query( $query ); |
---|
694 | |
---|
695 | while ( $row = mysql_fetch_array( $result ) ) |
---|
696 | { |
---|
697 | $vtp->addSession( $handle, 'comment' ); |
---|
698 | $author = $row['author']; |
---|
699 | if ( $row['author'] == '' ) $author = $lang['guest']; |
---|
700 | $vtp->setVar( $handle, 'comment.author', $author ); |
---|
701 | $vtp->setVar( $handle, 'comment.date', |
---|
702 | format_date( $row['date'], 'unix', true ) ); |
---|
703 | $content = nl2br( $row['content'] ); |
---|
704 | |
---|
705 | // replace _word_ by an underlined word |
---|
706 | $pattern = '/_([^\s]*)_/'; |
---|
707 | $replacement = '<span style="text-decoration:underline;">\1</span>'; |
---|
708 | $content = preg_replace( $pattern, $replacement, $content ); |
---|
709 | |
---|
710 | // replace *word* by a bolded word |
---|
711 | $pattern = '/\*([^\s]*)\*/'; |
---|
712 | $replacement = '<span style="font-weight:bold;">\1</span>'; |
---|
713 | $content = preg_replace( $pattern, $replacement, $content ); |
---|
714 | |
---|
715 | // replace /word/ by an italic word |
---|
716 | $pattern = '/\/([^\s]*)\//'; |
---|
717 | $replacement = '<span style="font-style:italic;">\1</span>'; |
---|
718 | $content = preg_replace( $pattern, $replacement, $content ); |
---|
719 | |
---|
720 | $vtp->setVar( $handle, 'comment.content', $content ); |
---|
721 | if ( $user['status'] == 'admin' ) |
---|
722 | { |
---|
723 | $vtp->addSession( $handle, 'delete' ); |
---|
724 | $vtp->setVar( $handle, 'delete.link', |
---|
725 | add_session_id( $url.'&del='.$row['id'] ) ); |
---|
726 | $vtp->closeSession( $handle, 'delete' ); |
---|
727 | } |
---|
728 | $vtp->closeSession( $handle, 'comment' ); |
---|
729 | } |
---|
730 | |
---|
731 | if ( !$user['is_the_guest'] |
---|
732 | or ( $user['is_the_guest'] and $conf['comments_forall'] ) ) |
---|
733 | { |
---|
734 | $vtp->addSession( $handle, 'add_comment' ); |
---|
735 | // form action |
---|
736 | $action = str_replace( '&', '&', $_SERVER['REQUEST_URI'] ); |
---|
737 | $vtp->setGlobalVar( $handle, 'form_action', $action ); |
---|
738 | // display author field if the user is not logged in |
---|
739 | if ( !$user['is_the_guest'] ) |
---|
740 | { |
---|
741 | $vtp->addSession( $handle, 'author_known' ); |
---|
742 | if (isset($user['pseudo'])) |
---|
743 | $vtp->setVar( $handle, 'author_known.value', $user['pseudo'] ); |
---|
744 | $vtp->closeSession( $handle, 'author_known' ); |
---|
745 | } |
---|
746 | else |
---|
747 | { |
---|
748 | $vtp->addSession( $handle, 'author_field' ); |
---|
749 | $vtp->closeSession( $handle, 'author_field' ); |
---|
750 | } |
---|
751 | $vtp->closeSession( $handle, 'add_comment' ); |
---|
752 | } |
---|
753 | $vtp->closeSession( $handle, 'comments' ); |
---|
754 | } |
---|
755 | //------------------------------------------------------------ log informations |
---|
756 | pwg_log( 'picture', $intitule_cat, $page['file'] ); |
---|
757 | mysql_close(); |
---|
758 | //----------------------------------------------------------- html code display |
---|
759 | $output.= $vtp->Display( $handle, 0 ); |
---|
760 | |
---|
761 | include('include/page_tail.php'); |
---|
762 | ?> |
---|