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-03-26 17:08:09 +0000 (Fri, 26 Mar 2004) $ |
---|
10 | // | last modifier : $Author: gweltas $ |
---|
11 | // | revision : $Revision: 394 $ |
---|
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 | //----------------------------------------------------------- include |
---|
28 | define('PHPWG_ROOT_PATH','./'); |
---|
29 | include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
30 | //-------------------------------------------------- access authorization check |
---|
31 | check_cat_id( $_GET['cat'] ); |
---|
32 | check_login_authorization(); |
---|
33 | if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) ) |
---|
34 | { |
---|
35 | check_restrictions( $page['cat'] ); |
---|
36 | } |
---|
37 | //---------------------------------------- incrementation of the number of hits |
---|
38 | $query = 'UPDATE '.IMAGES_TABLE.' SET hit=hit+1'; |
---|
39 | $query.= ' WHERE id='.$_GET['image_id']; |
---|
40 | $query.= ';'; |
---|
41 | @mysql_query( $query ); |
---|
42 | //-------------------------------------------------------------- initialization |
---|
43 | initialize_category( 'picture' ); |
---|
44 | |
---|
45 | // if this image_id doesn't correspond to this category, an error message is |
---|
46 | // displayed, and execution is stopped |
---|
47 | if ( 0 ) |
---|
48 | { |
---|
49 | echo '<div style="text-align:center;">'.$lang['access_forbiden'].'<br />'; |
---|
50 | echo '<a href="'.add_session_id( PHPWG_ROOT_PATH.'category.php' ).'">'; |
---|
51 | echo $lang['thumbnails'].'</a></div>'; |
---|
52 | exit(); |
---|
53 | } |
---|
54 | |
---|
55 | // retrieving the number of the picture in its category (in order) |
---|
56 | $query = 'SELECT DISTINCT(id)'; |
---|
57 | $query.= ' FROM '.IMAGES_TABLE; |
---|
58 | $query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic'; |
---|
59 | $query.= ' ON id = ic.image_id'; |
---|
60 | $query.= $page['where']; |
---|
61 | $query.= $conf['order_by']; |
---|
62 | $query.= ';'; |
---|
63 | $result = mysql_query( $query ); |
---|
64 | $page['num'] = 0; |
---|
65 | $row = mysql_fetch_array( $result ); |
---|
66 | while ( $row['id'] != $_GET['image_id'] ) |
---|
67 | { |
---|
68 | $page['num']++; |
---|
69 | $row = mysql_fetch_array( $result ); |
---|
70 | } |
---|
71 | |
---|
72 | //---------------------------------------- prev, current & next picture management |
---|
73 | $picture=array(); |
---|
74 | $picture['prev']['name']=''; |
---|
75 | $picture['next']['name']=''; |
---|
76 | $picture['prev']['thumbnail']=''; |
---|
77 | $picture['next']['thumbnail']=''; |
---|
78 | $picture['prev']['url']=''; |
---|
79 | $picture['next']['url']=''; |
---|
80 | |
---|
81 | $next = $page['num'] + 1; |
---|
82 | $prev = $page['num'] - 1; |
---|
83 | |
---|
84 | if ( $page['num'] == $page['cat_nb_images']-1) |
---|
85 | { |
---|
86 | $next = 0; |
---|
87 | } |
---|
88 | |
---|
89 | $query = 'SELECT * FROM '.IMAGES_TABLE; |
---|
90 | $query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic'; |
---|
91 | $query.= ' ON id=ic.image_id'; |
---|
92 | $query.= $page['where']; |
---|
93 | $query.= $conf['order_by']; |
---|
94 | |
---|
95 | if ($prev <0) |
---|
96 | $query.= ' LIMIT 0,2'; |
---|
97 | else |
---|
98 | $query.= ' LIMIT '.$prev.',3'; |
---|
99 | |
---|
100 | $query.= ';'; |
---|
101 | |
---|
102 | $result = mysql_query( $query ); |
---|
103 | $nb_row = mysql_num_rows($result); |
---|
104 | $index = array('prev','current','next'); |
---|
105 | for ($i=0; $i<$nb_row;$i++) |
---|
106 | { |
---|
107 | $j=($prev<0)?$index[$i+1]:$index[$i]; |
---|
108 | $row = mysql_fetch_array($result); |
---|
109 | $picture[$j] = $row; |
---|
110 | |
---|
111 | if ( !isset($array_cat_directories[$row['storage_category_id']])) |
---|
112 | { |
---|
113 | $array_cat_directories[$row['storage_category_id']] = |
---|
114 | get_complete_dir( $row['storage_category_id'] ); |
---|
115 | } |
---|
116 | $cat_directory = $array_cat_directories[$row['storage_category_id']]; |
---|
117 | $file = substr ( $row['file'], 0, strrpos ( $row['file'], ".") ); |
---|
118 | $picture[$j]['src'] = $cat_directory.$row['file']; |
---|
119 | $picture[$j]['thumbnail'] = $cat_directory.'thumbnail/'; |
---|
120 | $picture[$j]['thumbnail'].= $conf['prefix_thumbnail'].$file.".".$row['tn_ext']; |
---|
121 | |
---|
122 | if (!empty($row['name'])) |
---|
123 | { |
---|
124 | $picture[$j]['name'] = $row['name']; |
---|
125 | } |
---|
126 | else |
---|
127 | { |
---|
128 | $picture[$j]['name'] = str_replace( "_", " ",$file); |
---|
129 | } |
---|
130 | |
---|
131 | $picture[$j]['url'] = PHPWG_ROOT_PATH.'picture.php?image_id='.$row['id']; |
---|
132 | $picture[$j]['url'].= '&cat='.$page['cat']; |
---|
133 | if ( $page['cat'] == 'search' ) |
---|
134 | { |
---|
135 | $picture[$j]['url'].= "&search=".$_GET['search'].'&mode='.$_GET['mode']; |
---|
136 | } |
---|
137 | } |
---|
138 | |
---|
139 | $url_home = PHPWG_ROOT_PATH.'category.php?cat='.$page['cat'].'&'; |
---|
140 | $url_home.= 'num='.$page['num']; |
---|
141 | if ( $page['cat'] == 'search' ) |
---|
142 | { |
---|
143 | $url_home.= "&search=".$_GET['search'].'&mode='.$_GET['mode']; |
---|
144 | } |
---|
145 | |
---|
146 | $url_admin = PHPWG_ROOT_PATH.'admin.php?page=picture_modify&cat_id='.$page['cat']; |
---|
147 | $url_admin.= '&image_id='.$_GET['image_id']; |
---|
148 | |
---|
149 | //--------------------------------------------------------- favorite management |
---|
150 | if ( isset( $_GET['add_fav'] ) ) |
---|
151 | { |
---|
152 | $query = 'DELETE FROM '.FAVORITES_TABLE.' WHERE user_id = '.$user['id']; |
---|
153 | $query.= ' AND image_id = '.$picture['current']['id'].';'; |
---|
154 | $result = mysql_query( $query ); |
---|
155 | |
---|
156 | if ( $_GET['add_fav'] == 1 ) |
---|
157 | { |
---|
158 | $query = 'INSERT INTO '.FAVORITES_TABLE.' (image_id,user_id) VALUES'; |
---|
159 | $query.= ' ('.$picture['current']['id'].','.$user['id'].');'; |
---|
160 | $result = mysql_query( $query ); |
---|
161 | } |
---|
162 | if ( !$_GET['add_fav'] && $page['cat']=='fav') |
---|
163 | { |
---|
164 | if ( $prev < 0 && $nb_row==1 ) |
---|
165 | { |
---|
166 | // there is no favorite picture anymore |
---|
167 | // we redirect the user to the category page |
---|
168 | $url = add_session_id( $url_home ); |
---|
169 | header( 'Request-URI: '.$url ); |
---|
170 | header( 'Content-Location: '.$url ); |
---|
171 | header( 'Location: '.$url ); |
---|
172 | exit(); |
---|
173 | } |
---|
174 | else if ( $prev < 0 ) |
---|
175 | { |
---|
176 | $url = add_session_id( str_replace('&','&',$picture['next']['url']), true); |
---|
177 | } |
---|
178 | else |
---|
179 | { |
---|
180 | $url = add_session_id( str_replace('&','&',$picture['prev']['url']), true); |
---|
181 | } |
---|
182 | header( 'Request-URI: '.$url ); |
---|
183 | header( 'Content-Location: '.$url ); |
---|
184 | header( 'Location: '.$url ); |
---|
185 | exit(); |
---|
186 | } |
---|
187 | } |
---|
188 | |
---|
189 | //--------------------------------------------------------- comment registeration |
---|
190 | if ( isset( $_POST['content'] ) && !empty($_POST['content']) ) |
---|
191 | { |
---|
192 | $register_comment = true; |
---|
193 | $author = !empty($_POST['author'])?$_POST['author']:$lang['guest']; |
---|
194 | // if a guest try to use the name of an already existing user, he must |
---|
195 | // be rejected |
---|
196 | if ( $author != $user['username'] ) |
---|
197 | { |
---|
198 | $query = 'SELECT COUNT(*) AS user_exists'; |
---|
199 | $query.= ' FROM '.USERS_TABLE; |
---|
200 | $query.= " WHERE username = '".$author."'"; |
---|
201 | $query.= ';'; |
---|
202 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
203 | if ( $row['user_exists'] == 1 ) |
---|
204 | { |
---|
205 | $template->assign_block_vars('information', array('INFORMATION'=>$lang['comment_user_exists'])); |
---|
206 | $register_comment = false; |
---|
207 | } |
---|
208 | } |
---|
209 | |
---|
210 | if ( $register_comment ) |
---|
211 | { |
---|
212 | // anti-flood system |
---|
213 | $reference_date = time() - $conf['anti-flood_time']; |
---|
214 | $query = 'SELECT id FROM '.COMMENTS_TABLE; |
---|
215 | $query.= ' WHERE date > '.$reference_date; |
---|
216 | $query.= " AND author = '".$author."'"; |
---|
217 | $query.= ';'; |
---|
218 | if ( mysql_num_rows( mysql_query( $query ) ) == 0 |
---|
219 | || $conf['anti-flood_time'] == 0 ) |
---|
220 | { |
---|
221 | $query = 'INSERT INTO '.COMMENTS_TABLE; |
---|
222 | $query.= ' (author,date,image_id,content,validated) VALUES ('; |
---|
223 | $query.= "'".$author."'"; |
---|
224 | $query.= ','.time().','.$_GET['image_id']; |
---|
225 | $query.= ",'".htmlspecialchars( $_POST['content'], ENT_QUOTES)."'"; |
---|
226 | if ( !$conf['comments_validation'] || $user['status'] == 'admin' ) |
---|
227 | $query.= ",'true'"; |
---|
228 | else |
---|
229 | $query.= ",'false'"; |
---|
230 | $query.= ');'; |
---|
231 | mysql_query( $query ); |
---|
232 | // information message |
---|
233 | $message = $lang['comment_added']; |
---|
234 | if ( $conf['comments_validation'] and $user['status'] != 'admin' ) |
---|
235 | { |
---|
236 | $message.= '<br />'.$lang['comment_to_validate']; |
---|
237 | } |
---|
238 | $template->assign_block_vars('information', array('INFORMATION'=>$message)); |
---|
239 | // notification to the administrators |
---|
240 | if ( $conf['mail_notification'] ) |
---|
241 | { |
---|
242 | $cat_name = get_cat_display_name( $page['cat_name'], ' > ', '' ); |
---|
243 | $cat_name = strip_tags( $cat_name ); |
---|
244 | notify( 'comment', $cat_name.' > '.$picture['current']['name']); |
---|
245 | } |
---|
246 | } |
---|
247 | else |
---|
248 | { |
---|
249 | // information message |
---|
250 | $template->assign_block_vars('information', array('INFORMATION'=>$lang['comment_anti-flood'])); |
---|
251 | } |
---|
252 | } |
---|
253 | } |
---|
254 | // comment deletion |
---|
255 | if ( isset( $_GET['del'] ) |
---|
256 | && is_numeric( $_GET['del'] ) |
---|
257 | && $user['status'] == 'admin' ) |
---|
258 | { |
---|
259 | $query = 'DELETE FROM '.COMMENTS_TABLE.' WHERE id = '.$_GET['del'].';'; |
---|
260 | mysql_query( $query ); |
---|
261 | } |
---|
262 | |
---|
263 | // |
---|
264 | // Start output of page |
---|
265 | // |
---|
266 | |
---|
267 | $title = $picture['current']['name']; |
---|
268 | $refresh = 0; |
---|
269 | if ( isset( $_GET['slideshow'] ) && $next) |
---|
270 | { |
---|
271 | $refresh= $_GET['slideshow']; |
---|
272 | $url_link = $picture['next']['url']; |
---|
273 | } |
---|
274 | |
---|
275 | $title_img = $picture['current']['name']; |
---|
276 | $title_nb = ''; |
---|
277 | if (is_numeric( $page['cat'] )) |
---|
278 | { |
---|
279 | $title_img = replace_space(get_cat_display_name( $page['cat_name'], " > ")); |
---|
280 | $n = $page['num'] + 1; |
---|
281 | $title_nb = "Photo".' '.$n.'/'; |
---|
282 | $title_nb.= $page['cat_nb_images']; |
---|
283 | //$title_img.= $picture['current']['name']; |
---|
284 | } |
---|
285 | else if ( $page['cat'] == 'search' ) |
---|
286 | { |
---|
287 | $title_img = replace_search( $title_img, $_GET['search'] ); |
---|
288 | } |
---|
289 | |
---|
290 | // calculation of width and height |
---|
291 | if ( empty($picture['current']['width'])) |
---|
292 | { |
---|
293 | $taille_image = @getimagesize( $lien_image ); |
---|
294 | $original_width = $taille_image[0]; |
---|
295 | $original_height = $taille_image[1]; |
---|
296 | } |
---|
297 | else |
---|
298 | { |
---|
299 | $original_width = $picture['current']['width']; |
---|
300 | $original_height = $picture['current']['height']; |
---|
301 | } |
---|
302 | |
---|
303 | $picture_size = get_picture_size( $original_width, $original_height, |
---|
304 | $user['maxwidth'], $user['maxheight'] ); |
---|
305 | |
---|
306 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
307 | $template->set_filenames(array('picture'=>'picture.tpl')); |
---|
308 | |
---|
309 | $template->assign_vars(array( |
---|
310 | 'CATEGORY' => $title_img, |
---|
311 | 'PHOTO' => $title_nb, |
---|
312 | 'TITLE' => $picture['current']['name'], |
---|
313 | 'PREV_TITLE_IMG' => $picture['prev']['name'], |
---|
314 | 'NEXT_TITLE_IMG' => $picture['next']['name'], |
---|
315 | 'PREV_IMG' => $picture['prev']['thumbnail'], |
---|
316 | 'NEXT_IMG' => $picture['next']['thumbnail'], |
---|
317 | 'SRC_IMG' => $picture['current']['src'], |
---|
318 | 'ALT_IMG' => $picture['current']['file'], |
---|
319 | 'WIDTH_IMG' => $picture_size[0], |
---|
320 | 'HEIGHT_IMG' => $picture_size[1], |
---|
321 | 'COMMENT_IMG' => $picture['current']['comment'], |
---|
322 | |
---|
323 | 'L_SLIDESHOW' => $lang['slideshow'], |
---|
324 | 'L_TIME' => $lang['period_seconds'], |
---|
325 | 'L_STOP_SLIDESHOW' => $lang['slideshow_stop'], |
---|
326 | 'L_PREV_IMG' =>$lang['previous_image'].' : ', |
---|
327 | 'L_ADMIN' =>$lang['link_info_image'], |
---|
328 | 'L_BACK' =>$lang['back'], |
---|
329 | 'L_COMMENT_TITLE' =>$lang['comments_title'], |
---|
330 | 'L_ADD_COMMENT' =>$lang['comments_add'], |
---|
331 | 'L_DELETE_COMMENT' =>$lang['comments_del'], |
---|
332 | 'L_DELETE' =>$lang['delete'], |
---|
333 | 'L_SUBMIT' =>$lang['submit'], |
---|
334 | 'L_AUTHOR' =>$lang['author'], |
---|
335 | 'L_COMMENT' =>$lang['comment'], |
---|
336 | |
---|
337 | 'T_DEL_IMG' =>PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/delete.gif', |
---|
338 | |
---|
339 | 'U_PREV_IMG' => add_session_id($picture['prev']['url']), |
---|
340 | 'U_NEXT_IMG' => add_session_id($picture['next']['url']), |
---|
341 | 'U_HOME' => add_session_id($url_home), |
---|
342 | 'U_ADMIN' => add_session_id($url_admin), |
---|
343 | 'U_ADD_COMMENT' => add_session_id(str_replace( '&', '&', $_SERVER['REQUEST_URI'] )) |
---|
344 | ) |
---|
345 | ); |
---|
346 | |
---|
347 | //-------------------------------------------------------- slideshow management |
---|
348 | if ( isset( $_GET['slideshow'] ) ) |
---|
349 | { |
---|
350 | if ( !is_numeric( $_GET['slideshow'] ) ) $_GET['slideshow'] = $conf['slideshow_period'][0]; |
---|
351 | |
---|
352 | $template->assign_block_vars('stop_slideshow', array( |
---|
353 | 'U_SLIDESHOW'=>add_session_id( $picture['current']['url'] ) |
---|
354 | )); |
---|
355 | } |
---|
356 | else |
---|
357 | { |
---|
358 | $template->assign_block_vars('start_slideshow', array()); |
---|
359 | foreach ( $conf['slideshow_period'] as $option ) |
---|
360 | { |
---|
361 | $template->assign_block_vars('start_slideshow.second', array( |
---|
362 | 'SLIDESHOW_SPEED'=>$option, |
---|
363 | 'U_SLIDESHOW'=>add_session_id( $picture['current']['url'].'&slideshow='.$option) |
---|
364 | )); |
---|
365 | } |
---|
366 | } |
---|
367 | |
---|
368 | if ($prev>=0) $template->assign_block_vars('previous', array()); |
---|
369 | if ($next) $template->assign_block_vars('next', array()); |
---|
370 | |
---|
371 | //--------------------------------------------------------- picture information |
---|
372 | // legend |
---|
373 | if ( !empty($picture['current']['comment']) ) |
---|
374 | { |
---|
375 | $template->assign_block_vars('legend', array()); |
---|
376 | } |
---|
377 | |
---|
378 | // author |
---|
379 | if ( !empty($picture['current']['author']) ) |
---|
380 | { |
---|
381 | $template->assign_block_vars('info_line', array( |
---|
382 | 'INFO'=>$lang['author'], |
---|
383 | 'VALUE'=>$picture['current']['author'] |
---|
384 | )); |
---|
385 | } |
---|
386 | // creation date |
---|
387 | if ( !empty($picture['current']['date_creation']) ) |
---|
388 | { |
---|
389 | $template->assign_block_vars('info_line', array( |
---|
390 | 'INFO'=>$lang['creation_date'], |
---|
391 | 'VALUE'=>format_date( $picture['current']['date_creation'] ) |
---|
392 | )); |
---|
393 | } |
---|
394 | // date of availability |
---|
395 | $template->assign_block_vars('info_line', array( |
---|
396 | 'INFO'=>$lang['registration_date'], |
---|
397 | 'VALUE'=>format_date( $picture['current']['date_available'] ) |
---|
398 | )); |
---|
399 | // size in pixels |
---|
400 | if ( $original_width != $picture_size[0] or $original_height != $picture_size[1] ) |
---|
401 | { |
---|
402 | $content = '[ <a href="'.$picture['current']['url'].'" title="'.$lang['true_size'].'">'; |
---|
403 | $content.= $original_width.'*'.$original_height.'</a> ]'; |
---|
404 | } |
---|
405 | else |
---|
406 | { |
---|
407 | $content = $original_width.'*'.$original_height; |
---|
408 | } |
---|
409 | $template->assign_block_vars('info_line', array( |
---|
410 | 'INFO'=>$lang['size'], |
---|
411 | 'VALUE'=>$content |
---|
412 | )); |
---|
413 | // file |
---|
414 | $template->assign_block_vars('info_line', array( |
---|
415 | 'INFO'=>$lang['file'], |
---|
416 | 'VALUE'=>$picture['current']['file'] |
---|
417 | )); |
---|
418 | // filesize |
---|
419 | if ( empty($picture['current']['filesize'])) |
---|
420 | { |
---|
421 | $poids = floor ( filesize( $picture['current']['url'] ) / 1024 ); |
---|
422 | } |
---|
423 | else |
---|
424 | { |
---|
425 | $poids = $picture['current']['filesize']; |
---|
426 | } |
---|
427 | |
---|
428 | $template->assign_block_vars('info_line', array( |
---|
429 | 'INFO'=>$lang['filesize'], |
---|
430 | 'VALUE'=>$poids.' KB' |
---|
431 | )); |
---|
432 | // keywords |
---|
433 | if ( !empty($picture['current']['keywords'])) |
---|
434 | { |
---|
435 | $keywords = explode( ',', $picture['current']['keywords'] ); |
---|
436 | $content = ''; |
---|
437 | $url = PHPWG_ROOT_PATH.'category.php?cat=search'; |
---|
438 | $url.= '&mode=OR&search='; |
---|
439 | foreach ( $keywords as $i => $keyword ) { |
---|
440 | $local_url = add_session_id( $url.$keyword ); |
---|
441 | if ( $i > 0 ) $content.= ','; |
---|
442 | $content.= '<a href="'.$local_url.'">'.$keyword.'</a>'; |
---|
443 | } |
---|
444 | $template->assign_block_vars('info_line', array( |
---|
445 | 'INFO'=>$lang['keywords'], |
---|
446 | 'VALUE'=>$content |
---|
447 | )); |
---|
448 | } |
---|
449 | // number of visits |
---|
450 | $template->assign_block_vars('info_line', array( |
---|
451 | 'INFO'=>$lang['visited'], |
---|
452 | 'VALUE'=>$picture['current']['hit'].' '.$lang['times'] |
---|
453 | )); |
---|
454 | |
---|
455 | //------------------------------------------------------- favorite manipulation |
---|
456 | if ( !$user['is_the_guest'] ) |
---|
457 | { |
---|
458 | // verify if the picture is already in the favorite of the user |
---|
459 | $query = 'SELECT COUNT(*) AS nb_fav'; |
---|
460 | $query.= ' FROM '.FAVORITES_TABLE.' WHERE image_id = '.$_GET['image_id']; |
---|
461 | $query.= ' AND user_id = '.$user['id'].';'; |
---|
462 | $result = mysql_query( $query ); |
---|
463 | $row = mysql_fetch_array( $result ); |
---|
464 | if (!$row['nb_fav']) |
---|
465 | { |
---|
466 | $url = PHPWG_ROOT_PATH.'picture.php?cat='.$page['cat'].'&image_id='.$_GET['image_id']; |
---|
467 | $url.='&add_fav=1'; |
---|
468 | if ( $page['cat'] == 'search' ) |
---|
469 | { |
---|
470 | $url.= '&search='.$_GET['search'].'&mode='.$_GET['mode']; |
---|
471 | } |
---|
472 | $template->assign_block_vars('favorite', array( |
---|
473 | 'FAVORITE_IMG' => PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/favorite.gif', |
---|
474 | 'FAVORITE_HINT' =>$lang['add_favorites_hint'], |
---|
475 | 'FAVORITE_ALT' =>'[ '.$lang['add_favorites_alt'].' ]', |
---|
476 | 'U_FAVORITE'=> add_session_id( $url ) |
---|
477 | )); |
---|
478 | } |
---|
479 | else |
---|
480 | { |
---|
481 | $url = PHPWG_ROOT_PATH.'picture.php?cat='.$page['cat'].'&image_id='.$_GET['image_id']; |
---|
482 | $url.= '&add_fav=0'; |
---|
483 | $template->assign_block_vars('favorite', array( |
---|
484 | 'FAVORITE_IMG' => PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/del_favorite.gif', |
---|
485 | 'FAVORITE_HINT' =>$lang['del_favorites_hint'], |
---|
486 | 'FAVORITE_ALT' =>'[ '.$lang['del_favorites_alt'].' ]', |
---|
487 | 'U_FAVORITE'=> add_session_id( $url ) |
---|
488 | )); |
---|
489 | } |
---|
490 | } |
---|
491 | //------------------------------------ admin link for information modifications |
---|
492 | if ( $user['status'] == 'admin' ) |
---|
493 | { |
---|
494 | $template->assign_block_vars('modification', array()); |
---|
495 | } |
---|
496 | |
---|
497 | //---------------------------------------------------- users's comments display |
---|
498 | if ( $conf['show_comments'] ) |
---|
499 | { |
---|
500 | // number of comment for this picture |
---|
501 | $query = 'SELECT COUNT(*) AS nb_comments'; |
---|
502 | $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id']; |
---|
503 | $query.= " AND validated = 'true'"; |
---|
504 | $query.= ';'; |
---|
505 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
506 | |
---|
507 | // navigation bar creation |
---|
508 | $url = PHPWG_ROOT_PATH.'picture.php?cat='.$page['cat'].'&image_id='.$_GET['image_id']; |
---|
509 | if ( $page['cat'] == 'search' ) |
---|
510 | { |
---|
511 | $url.= '&search='.$_GET['search'].'&mode='.$_GET['mode']; |
---|
512 | } |
---|
513 | if( !isset( $_GET['start'] ) |
---|
514 | or !is_numeric( $_GET['start'] ) |
---|
515 | or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) ) |
---|
516 | { |
---|
517 | $page['start'] = 0; |
---|
518 | } |
---|
519 | else |
---|
520 | { |
---|
521 | $page['start'] = $_GET['start']; |
---|
522 | } |
---|
523 | $page['navigation_bar'] = create_navigation_bar( $url, $row['nb_comments'], |
---|
524 | $page['start'], |
---|
525 | $conf['nb_comment_page'], |
---|
526 | '' ); |
---|
527 | $template->assign_block_vars('comments', array( |
---|
528 | 'NB_COMMENT'=>$row['nb_comments'], |
---|
529 | 'NAV_BAR'=>$page['navigation_bar'])); |
---|
530 | |
---|
531 | $query = 'SELECT id,author,date,image_id,content'; |
---|
532 | $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id']; |
---|
533 | $query.= " AND validated = 'true'"; |
---|
534 | $query.= ' ORDER BY date ASC'; |
---|
535 | $query.= ' LIMIT '.$page['start'].', '.$conf['nb_comment_page'].';'; |
---|
536 | $result = mysql_query( $query ); |
---|
537 | |
---|
538 | while ( $row = mysql_fetch_array( $result ) ) |
---|
539 | { |
---|
540 | $content = nl2br( $row['content'] ); |
---|
541 | |
---|
542 | // replace _word_ by an underlined word |
---|
543 | $pattern = '/_([^\s]*)_/'; |
---|
544 | $replacement = '<span style="text-decoration:underline;">\1</span>'; |
---|
545 | $content = preg_replace( $pattern, $replacement, $content ); |
---|
546 | |
---|
547 | // replace *word* by a bolded word |
---|
548 | $pattern = '/\*([^\s]*)\*/'; |
---|
549 | $replacement = '<span style="font-weight:bold;">\1</span>'; |
---|
550 | $content = preg_replace( $pattern, $replacement, $content ); |
---|
551 | |
---|
552 | // replace /word/ by an italic word |
---|
553 | $pattern = '/\/([^\s]*)\//'; |
---|
554 | $replacement = '<span style="font-style:italic;">\1</span>'; |
---|
555 | $content = preg_replace( $pattern, $replacement, $content ); |
---|
556 | |
---|
557 | $template->assign_block_vars('comments.comment', array( |
---|
558 | 'COMMENT_AUTHOR'=>empty($row['author'])?$lang['guest']:$row['author'], |
---|
559 | 'COMMENT_DATE'=>format_date( $row['date'], 'unix', true ), |
---|
560 | 'COMMENT'=>$content |
---|
561 | )); |
---|
562 | |
---|
563 | if ( $user['status'] == 'admin' ) |
---|
564 | { |
---|
565 | $template->assign_block_vars('comments.comment.delete', array('U_COMMENT_DELETE'=>add_session_id( $url.'&del='.$row['id'] ))); |
---|
566 | } |
---|
567 | } |
---|
568 | |
---|
569 | if ( !$user['is_the_guest']||( $user['is_the_guest'] and $conf['comments_forall'] ) ) |
---|
570 | { |
---|
571 | $template->assign_block_vars('comments.add_comment', array()); |
---|
572 | // display author field if the user is not logged in |
---|
573 | if ( !$user['is_the_guest'] ) |
---|
574 | { |
---|
575 | $template->assign_block_vars('comments.add_comment.author_known', array('KNOWN_AUTHOR'=>$user['username'])); |
---|
576 | } |
---|
577 | else |
---|
578 | { |
---|
579 | $template->assign_block_vars('comments.add_comment.author_field', array()); |
---|
580 | } |
---|
581 | } |
---|
582 | } |
---|
583 | //------------------------------------------------------------ log informations |
---|
584 | pwg_log( 'picture', $title_img, $picture['current']['file'] ); |
---|
585 | mysql_close(); |
---|
586 | |
---|
587 | $template->pparse('picture'); |
---|
588 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
589 | ?> |
---|