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-05 17:31:36 +0000 (Thu, 05 Aug 2004) $ |
---|
10 | // | last modifier : $Author: z0rglub $ |
---|
11 | // | revision : $Revision: 465 $ |
---|
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 | } |
---|
201 | |
---|
202 | $url_home = PHPWG_ROOT_PATH.'category.php?cat='.$page['cat'].'&'; |
---|
203 | $url_home.= 'num='.$page['num']; |
---|
204 | if ( $page['cat'] == 'search' ) |
---|
205 | { |
---|
206 | $url_home.= "&search=".$_GET['search']; |
---|
207 | } |
---|
208 | |
---|
209 | $url_admin = PHPWG_ROOT_PATH.'admin.php?page=picture_modify'; |
---|
210 | $url_admin.= '&cat_id='.$page['cat']; |
---|
211 | $url_admin.= '&image_id='.$_GET['image_id']; |
---|
212 | |
---|
213 | //--------------------------------------------------------- favorite management |
---|
214 | if ( isset( $_GET['add_fav'] ) ) |
---|
215 | { |
---|
216 | $query = 'DELETE FROM '.FAVORITES_TABLE; |
---|
217 | $query.= ' WHERE user_id = '.$user['id']; |
---|
218 | $query.= ' AND image_id = '.$picture['current']['id']; |
---|
219 | $query.= ';'; |
---|
220 | $result = mysql_query( $query ); |
---|
221 | |
---|
222 | if ( $_GET['add_fav'] == 1 ) |
---|
223 | { |
---|
224 | $query = 'INSERT INTO '.FAVORITES_TABLE; |
---|
225 | $query.= ' (image_id,user_id) VALUES'; |
---|
226 | $query.= ' ('.$picture['current']['id'].','.$user['id'].')'; |
---|
227 | $query.= ';'; |
---|
228 | $result = mysql_query( $query ); |
---|
229 | } |
---|
230 | if ( !$_GET['add_fav'] and $page['cat'] == 'fav' ) |
---|
231 | { |
---|
232 | if (!$has_prev and $mysql_num_rows == 1) |
---|
233 | { |
---|
234 | // there is no favorite picture anymore we redirect the user to the |
---|
235 | // category page |
---|
236 | $url = add_session_id( $url_home ); |
---|
237 | redirect( $url ); |
---|
238 | } |
---|
239 | else if (!$has_prev) |
---|
240 | { |
---|
241 | $url = str_replace( '&', '&', $picture['next']['url'] ); |
---|
242 | $url = add_session_id( $url, true); |
---|
243 | } |
---|
244 | else |
---|
245 | { |
---|
246 | $url = str_replace('&', '&', $picture['prev']['url'] ); |
---|
247 | $url = add_session_id( $url, true); |
---|
248 | } |
---|
249 | redirect( $url ); |
---|
250 | } |
---|
251 | } |
---|
252 | |
---|
253 | //------------------------------------------------------ comment registeration |
---|
254 | if ( isset( $_POST['content'] ) && !empty($_POST['content']) ) |
---|
255 | { |
---|
256 | $register_comment = true; |
---|
257 | $author = !empty($_POST['author'])?$_POST['author']:$lang['guest']; |
---|
258 | // if a guest try to use the name of an already existing user, he must be |
---|
259 | // rejected |
---|
260 | if ( $author != $user['username'] ) |
---|
261 | { |
---|
262 | $query = 'SELECT COUNT(*) AS user_exists'; |
---|
263 | $query.= ' FROM '.USERS_TABLE; |
---|
264 | $query.= " WHERE username = '".$author."'"; |
---|
265 | $query.= ';'; |
---|
266 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
267 | if ( $row['user_exists'] == 1 ) |
---|
268 | { |
---|
269 | $template->assign_block_vars( |
---|
270 | 'information', |
---|
271 | array('INFORMATION'=>$lang['comment_user_exists'])); |
---|
272 | $register_comment = false; |
---|
273 | } |
---|
274 | } |
---|
275 | |
---|
276 | if ( $register_comment ) |
---|
277 | { |
---|
278 | // anti-flood system |
---|
279 | $reference_date = time() - $conf['anti-flood_time']; |
---|
280 | $query = 'SELECT id FROM '.COMMENTS_TABLE; |
---|
281 | $query.= ' WHERE date > FROM_UNIXTIME('.$reference_date.')'; |
---|
282 | $query.= " AND author = '".$author."'"; |
---|
283 | $query.= ';'; |
---|
284 | if ( mysql_num_rows( mysql_query( $query ) ) == 0 |
---|
285 | or $conf['anti-flood_time'] == 0 ) |
---|
286 | { |
---|
287 | $query = 'INSERT INTO '.COMMENTS_TABLE; |
---|
288 | $query.= ' (author,date,image_id,content,validated) VALUES ('; |
---|
289 | $query.= "'".$author."'"; |
---|
290 | $query.= ',NOW(),'.$_GET['image_id']; |
---|
291 | $query.= ",'".htmlspecialchars( $_POST['content'], ENT_QUOTES)."'"; |
---|
292 | if ( !$conf['comments_validation'] or $user['status'] == 'admin' ) |
---|
293 | { |
---|
294 | $query.= ",'true'"; |
---|
295 | } |
---|
296 | else |
---|
297 | { |
---|
298 | $query.= ",'false'"; |
---|
299 | } |
---|
300 | $query.= ');'; |
---|
301 | mysql_query( $query ); |
---|
302 | // information message |
---|
303 | $message = $lang['comment_added']; |
---|
304 | if ( $conf['comments_validation'] and $user['status'] != 'admin' ) |
---|
305 | { |
---|
306 | $message.= '<br />'.$lang['comment_to_validate']; |
---|
307 | } |
---|
308 | $template->assign_block_vars('information', |
---|
309 | array('INFORMATION'=>$message)); |
---|
310 | // notification to the administrators |
---|
311 | if ( $conf['mail_notification'] ) |
---|
312 | { |
---|
313 | $cat_name = get_cat_display_name( $page['cat_name'], ' > ', '' ); |
---|
314 | $cat_name = strip_tags( $cat_name ); |
---|
315 | notify( 'comment', $cat_name.' > '.$picture['current']['name']); |
---|
316 | } |
---|
317 | } |
---|
318 | else |
---|
319 | { |
---|
320 | // information message |
---|
321 | $template->assign_block_vars( |
---|
322 | 'information', |
---|
323 | array('INFORMATION'=>$lang['comment_anti-flood'])); |
---|
324 | } |
---|
325 | } |
---|
326 | } |
---|
327 | // comment deletion |
---|
328 | if ( isset( $_GET['del'] ) |
---|
329 | and is_numeric( $_GET['del'] ) |
---|
330 | and $user['status'] == 'admin' ) |
---|
331 | { |
---|
332 | $query = 'DELETE FROM '.COMMENTS_TABLE; |
---|
333 | $query.= ' WHERE id = '.$_GET['del']; |
---|
334 | $query.= ';'; |
---|
335 | mysql_query( $query ); |
---|
336 | } |
---|
337 | |
---|
338 | // |
---|
339 | // Start output of page |
---|
340 | // |
---|
341 | |
---|
342 | $title = $picture['current']['name']; |
---|
343 | $refresh = 0; |
---|
344 | if ( isset( $_GET['slideshow'] ) and $next ) |
---|
345 | { |
---|
346 | $refresh= $_GET['slideshow']; |
---|
347 | $url_link = $picture['next']['url'].'&slideshow='.$refresh; |
---|
348 | } |
---|
349 | |
---|
350 | $title_img = $picture['current']['name']; |
---|
351 | $title_nb = ''; |
---|
352 | if (is_numeric( $page['cat'] )) |
---|
353 | { |
---|
354 | $title_img = replace_space(get_cat_display_name( $page['cat_name'], " > ")); |
---|
355 | $n = $page['num'] + 1; |
---|
356 | $title_nb = "Photo".' '.$n.'/'; |
---|
357 | $title_nb.= $page['cat_nb_images']; |
---|
358 | //$title_img.= $picture['current']['name']; |
---|
359 | } |
---|
360 | else if ( $page['cat'] == 'search' ) |
---|
361 | { |
---|
362 | $title_img = replace_search( $title_img, $_GET['search'] ); |
---|
363 | } |
---|
364 | |
---|
365 | // calculation of width and height |
---|
366 | if ( empty($picture['current']['width'])) |
---|
367 | { |
---|
368 | $taille_image = @getimagesize( $lien_image ); |
---|
369 | $original_width = $taille_image[0]; |
---|
370 | $original_height = $taille_image[1]; |
---|
371 | } |
---|
372 | else |
---|
373 | { |
---|
374 | $original_width = $picture['current']['width']; |
---|
375 | $original_height = $picture['current']['height']; |
---|
376 | } |
---|
377 | |
---|
378 | $picture_size = get_picture_size( $original_width, $original_height, |
---|
379 | $user['maxwidth'], $user['maxheight'] ); |
---|
380 | |
---|
381 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
382 | $template->set_filenames(array('picture'=>'picture.tpl')); |
---|
383 | |
---|
384 | $template->assign_vars(array( |
---|
385 | 'CATEGORY' => $title_img, |
---|
386 | 'PHOTO' => $title_nb, |
---|
387 | 'TITLE' => $picture['current']['name'], |
---|
388 | 'SRC_IMG' => $picture['current']['src'], |
---|
389 | 'ALT_IMG' => $picture['current']['file'], |
---|
390 | 'WIDTH_IMG' => $picture_size[0], |
---|
391 | 'HEIGHT_IMG' => $picture_size[1], |
---|
392 | |
---|
393 | 'L_SLIDESHOW' => $lang['slideshow'], |
---|
394 | 'L_TIME' => $lang['period_seconds'], |
---|
395 | 'L_STOP_SLIDESHOW' => $lang['slideshow_stop'], |
---|
396 | 'L_PREV_IMG' =>$lang['previous_image'].' : ', |
---|
397 | 'L_ADMIN' =>$lang['link_info_image'], |
---|
398 | 'L_BACK' =>$lang['back'], |
---|
399 | 'L_COMMENT_TITLE' =>$lang['comments_title'], |
---|
400 | 'L_ADD_COMMENT' =>$lang['comments_add'], |
---|
401 | 'L_DELETE_COMMENT' =>$lang['comments_del'], |
---|
402 | 'L_DELETE' =>$lang['delete'], |
---|
403 | 'L_SUBMIT' =>$lang['submit'], |
---|
404 | 'L_AUTHOR' =>$lang['author'], |
---|
405 | 'L_COMMENT' =>$lang['comment'], |
---|
406 | 'L_DOWNLOAD' => $lang['download'], |
---|
407 | 'L_DOWNLOAD_HINT' => $lang['download_hint'], |
---|
408 | |
---|
409 | 'T_DEL_IMG' =>PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/delete.gif', |
---|
410 | |
---|
411 | 'U_HOME' => add_session_id($url_home), |
---|
412 | 'U_ADMIN' => add_session_id($url_admin), |
---|
413 | 'U_ADD_COMMENT' => add_session_id(str_replace( '&', '&', $_SERVER['REQUEST_URI'] )) |
---|
414 | ) |
---|
415 | ); |
---|
416 | |
---|
417 | //-------------------------------------------------------- slideshow management |
---|
418 | if ( isset( $_GET['slideshow'] ) ) |
---|
419 | { |
---|
420 | if ( !is_numeric( $_GET['slideshow'] ) ) $_GET['slideshow'] = $conf['slideshow_period'][0]; |
---|
421 | |
---|
422 | $template->assign_block_vars('stop_slideshow', array( |
---|
423 | 'U_SLIDESHOW'=>add_session_id( $picture['current']['url'] ) |
---|
424 | )); |
---|
425 | } |
---|
426 | else |
---|
427 | { |
---|
428 | $template->assign_block_vars('start_slideshow', array()); |
---|
429 | foreach ( $conf['slideshow_period'] as $option ) |
---|
430 | { |
---|
431 | $template->assign_block_vars('start_slideshow.second', array( |
---|
432 | 'SLIDESHOW_SPEED'=>$option, |
---|
433 | 'U_SLIDESHOW'=>add_session_id( $picture['current']['url'].'&slideshow='.$option) |
---|
434 | )); |
---|
435 | } |
---|
436 | } |
---|
437 | |
---|
438 | if ($has_prev) |
---|
439 | { |
---|
440 | $template->assign_block_vars( |
---|
441 | 'previous', |
---|
442 | array( |
---|
443 | 'TITLE_IMG' => $picture['prev']['name'], |
---|
444 | 'IMG' => $picture['prev']['thumbnail'], |
---|
445 | 'U_IMG' => add_session_id($picture['prev']['url']) |
---|
446 | )); |
---|
447 | } |
---|
448 | |
---|
449 | if ($has_next) |
---|
450 | { |
---|
451 | $template->assign_block_vars( |
---|
452 | 'next', |
---|
453 | array( |
---|
454 | 'TITLE_IMG' => $picture['next']['name'], |
---|
455 | 'IMG' => $picture['next']['thumbnail'], |
---|
456 | 'U_IMG' => add_session_id($picture['next']['url']) |
---|
457 | )); |
---|
458 | } |
---|
459 | |
---|
460 | //--------------------------------------------------------- picture information |
---|
461 | // legend |
---|
462 | if (isset($picture['current']['comment']) |
---|
463 | and !empty($picture['current']['comment'])) |
---|
464 | { |
---|
465 | $template->assign_block_vars( |
---|
466 | 'legend', |
---|
467 | array( |
---|
468 | 'COMMENT_IMG' => $picture['current']['comment'] |
---|
469 | )); |
---|
470 | } |
---|
471 | // download link if file is not a picture |
---|
472 | if (!$picture['current']['is_picture']) |
---|
473 | { |
---|
474 | $template->assign_block_vars( |
---|
475 | 'download', |
---|
476 | array( |
---|
477 | 'U_DOWNLOAD' => $picture['current']['download'] |
---|
478 | )); |
---|
479 | } |
---|
480 | |
---|
481 | // author |
---|
482 | if ( !empty($picture['current']['author']) ) |
---|
483 | { |
---|
484 | $template->assign_block_vars( |
---|
485 | 'info_line', |
---|
486 | array( |
---|
487 | 'INFO'=>$lang['author'], |
---|
488 | 'VALUE'=>$picture['current']['author'] |
---|
489 | )); |
---|
490 | } |
---|
491 | // creation date |
---|
492 | if ( !empty($picture['current']['date_creation']) ) |
---|
493 | { |
---|
494 | $template->assign_block_vars('info_line', array( |
---|
495 | 'INFO'=>$lang['creation_date'], |
---|
496 | 'VALUE'=>format_date( $picture['current']['date_creation'] ) |
---|
497 | )); |
---|
498 | } |
---|
499 | // date of availability |
---|
500 | $template->assign_block_vars('info_line', array( |
---|
501 | 'INFO'=>$lang['registration_date'], |
---|
502 | 'VALUE'=>format_date( $picture['current']['date_available'] ) |
---|
503 | )); |
---|
504 | // size in pixels |
---|
505 | if ($picture['current']['is_picture']) |
---|
506 | { |
---|
507 | if ($original_width != $picture_size[0] |
---|
508 | or $original_height != $picture_size[1]) |
---|
509 | { |
---|
510 | $content = '[ <a href="'.$picture['current']['url'].'" '; |
---|
511 | $content.= ' title="'.$lang['true_size'].'">'; |
---|
512 | $content.= $original_width.'*'.$original_height.'</a> ]'; |
---|
513 | } |
---|
514 | else |
---|
515 | { |
---|
516 | $content = $original_width.'*'.$original_height; |
---|
517 | } |
---|
518 | $template->assign_block_vars( |
---|
519 | 'info_line', |
---|
520 | array( |
---|
521 | 'INFO'=>$lang['size'], |
---|
522 | 'VALUE'=>$content |
---|
523 | )); |
---|
524 | } |
---|
525 | // file |
---|
526 | $template->assign_block_vars('info_line', array( |
---|
527 | 'INFO'=>$lang['file'], |
---|
528 | 'VALUE'=>$picture['current']['file'] |
---|
529 | )); |
---|
530 | // filesize |
---|
531 | if ( empty($picture['current']['filesize'])) |
---|
532 | { |
---|
533 | $poids = floor ( filesize( $picture['current']['url'] ) / 1024 ); |
---|
534 | } |
---|
535 | else |
---|
536 | { |
---|
537 | $poids = $picture['current']['filesize']; |
---|
538 | } |
---|
539 | |
---|
540 | $template->assign_block_vars('info_line', array( |
---|
541 | 'INFO'=>$lang['filesize'], |
---|
542 | 'VALUE'=>$poids.' KB' |
---|
543 | )); |
---|
544 | // keywords |
---|
545 | if ( !empty($picture['current']['keywords'])) |
---|
546 | { |
---|
547 | $keywords = explode( ',', $picture['current']['keywords'] ); |
---|
548 | $content = ''; |
---|
549 | $url = PHPWG_ROOT_PATH.'category.php?cat=search'; |
---|
550 | $url.= '&mode=OR&search='; |
---|
551 | foreach ( $keywords as $i => $keyword ) { |
---|
552 | $local_url = add_session_id( $url.$keyword ); |
---|
553 | if ( $i > 0 ) $content.= ','; |
---|
554 | $content.= '<a href="'.$local_url.'">'.$keyword.'</a>'; |
---|
555 | } |
---|
556 | $template->assign_block_vars('info_line', array( |
---|
557 | 'INFO'=>$lang['keywords'], |
---|
558 | 'VALUE'=>$content |
---|
559 | )); |
---|
560 | } |
---|
561 | // number of visits |
---|
562 | $template->assign_block_vars('info_line', array( |
---|
563 | 'INFO'=>$lang['visited'], |
---|
564 | 'VALUE'=>$picture['current']['hit'].' '.$lang['times'] |
---|
565 | )); |
---|
566 | |
---|
567 | //------------------------------------------------------- favorite manipulation |
---|
568 | if ( !$user['is_the_guest'] ) |
---|
569 | { |
---|
570 | // verify if the picture is already in the favorite of the user |
---|
571 | $query = 'SELECT COUNT(*) AS nb_fav'; |
---|
572 | $query.= ' FROM '.FAVORITES_TABLE.' WHERE image_id = '.$_GET['image_id']; |
---|
573 | $query.= ' AND user_id = '.$user['id'].';'; |
---|
574 | $result = mysql_query( $query ); |
---|
575 | $row = mysql_fetch_array( $result ); |
---|
576 | if (!$row['nb_fav']) |
---|
577 | { |
---|
578 | $url = PHPWG_ROOT_PATH.'picture.php?cat='.$page['cat'].'&image_id='.$_GET['image_id']; |
---|
579 | $url.='&add_fav=1'; |
---|
580 | if ( $page['cat'] == 'search' ) |
---|
581 | { |
---|
582 | $url.= '&search='.$_GET['search'].'&mode='.$_GET['mode']; |
---|
583 | } |
---|
584 | $template->assign_block_vars('favorite', array( |
---|
585 | 'FAVORITE_IMG' => PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/favorite.gif', |
---|
586 | 'FAVORITE_HINT' =>$lang['add_favorites_hint'], |
---|
587 | 'FAVORITE_ALT' =>'[ '.$lang['add_favorites_alt'].' ]', |
---|
588 | 'U_FAVORITE'=> add_session_id( $url ) |
---|
589 | )); |
---|
590 | } |
---|
591 | else |
---|
592 | { |
---|
593 | $url = PHPWG_ROOT_PATH.'picture.php?cat='.$page['cat'].'&image_id='.$_GET['image_id']; |
---|
594 | $url.= '&add_fav=0'; |
---|
595 | $template->assign_block_vars('favorite', array( |
---|
596 | 'FAVORITE_IMG' => PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/del_favorite.gif', |
---|
597 | 'FAVORITE_HINT' =>$lang['del_favorites_hint'], |
---|
598 | 'FAVORITE_ALT' =>'[ '.$lang['del_favorites_alt'].' ]', |
---|
599 | 'U_FAVORITE'=> add_session_id( $url ) |
---|
600 | )); |
---|
601 | } |
---|
602 | } |
---|
603 | //------------------------------------ admin link for information modifications |
---|
604 | if ( $user['status'] == 'admin' ) |
---|
605 | { |
---|
606 | $template->assign_block_vars('modification', array()); |
---|
607 | } |
---|
608 | |
---|
609 | //---------------------------------------------------- users's comments display |
---|
610 | if ( $conf['show_comments'] ) |
---|
611 | { |
---|
612 | // number of comment for this picture |
---|
613 | $query = 'SELECT COUNT(*) AS nb_comments'; |
---|
614 | $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id']; |
---|
615 | $query.= " AND validated = 'true'"; |
---|
616 | $query.= ';'; |
---|
617 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
618 | |
---|
619 | // navigation bar creation |
---|
620 | $url = PHPWG_ROOT_PATH.'picture.php?cat='.$page['cat'].'&image_id='.$_GET['image_id']; |
---|
621 | if ( $page['cat'] == 'search' ) |
---|
622 | { |
---|
623 | $url.= '&search='.$_GET['search']; |
---|
624 | } |
---|
625 | if( !isset( $_GET['start'] ) |
---|
626 | or !is_numeric( $_GET['start'] ) |
---|
627 | or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) ) |
---|
628 | { |
---|
629 | $page['start'] = 0; |
---|
630 | } |
---|
631 | else |
---|
632 | { |
---|
633 | $page['start'] = $_GET['start']; |
---|
634 | } |
---|
635 | $page['navigation_bar'] = create_navigation_bar( $url, $row['nb_comments'], |
---|
636 | $page['start'], |
---|
637 | $conf['nb_comment_page'], |
---|
638 | '' ); |
---|
639 | $template->assign_block_vars('comments', array( |
---|
640 | 'NB_COMMENT'=>$row['nb_comments'], |
---|
641 | 'NAV_BAR'=>$page['navigation_bar'])); |
---|
642 | |
---|
643 | $query = 'SELECT id,author,date,image_id,content'; |
---|
644 | $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id']; |
---|
645 | $query.= " AND validated = 'true'"; |
---|
646 | $query.= ' ORDER BY date ASC'; |
---|
647 | $query.= ' LIMIT '.$page['start'].', '.$conf['nb_comment_page'].';'; |
---|
648 | $result = mysql_query( $query ); |
---|
649 | |
---|
650 | while ( $row = mysql_fetch_array( $result ) ) |
---|
651 | { |
---|
652 | $content = nl2br( $row['content'] ); |
---|
653 | |
---|
654 | // replace _word_ by an underlined word |
---|
655 | $pattern = '/_([^\s]*)_/'; |
---|
656 | $replacement = '<span style="text-decoration:underline;">\1</span>'; |
---|
657 | $content = preg_replace( $pattern, $replacement, $content ); |
---|
658 | |
---|
659 | // replace *word* by a bolded word |
---|
660 | $pattern = '/\*([^\s]*)\*/'; |
---|
661 | $replacement = '<span style="font-weight:bold;">\1</span>'; |
---|
662 | $content = preg_replace( $pattern, $replacement, $content ); |
---|
663 | |
---|
664 | // replace /word/ by an italic word |
---|
665 | $pattern = '/\/([^\s]*)\//'; |
---|
666 | $replacement = '<span style="font-style:italic;">\1</span>'; |
---|
667 | $content = preg_replace( $pattern, $replacement, $content ); |
---|
668 | |
---|
669 | $template->assign_block_vars('comments.comment', array( |
---|
670 | 'COMMENT_AUTHOR'=>empty($row['author'])?$lang['guest']:$row['author'], |
---|
671 | 'COMMENT_DATE'=>format_date( $row['date'], 'mysql_datetime', true ), |
---|
672 | 'COMMENT'=>$content |
---|
673 | )); |
---|
674 | |
---|
675 | if ( $user['status'] == 'admin' ) |
---|
676 | { |
---|
677 | $template->assign_block_vars('comments.comment.delete', array('U_COMMENT_DELETE'=>add_session_id( $url.'&del='.$row['id'] ))); |
---|
678 | } |
---|
679 | } |
---|
680 | |
---|
681 | if ( !$user['is_the_guest']||( $user['is_the_guest'] and $conf['comments_forall'] ) ) |
---|
682 | { |
---|
683 | $template->assign_block_vars('comments.add_comment', array()); |
---|
684 | // display author field if the user is not logged in |
---|
685 | if ( !$user['is_the_guest'] ) |
---|
686 | { |
---|
687 | $template->assign_block_vars('comments.add_comment.author_known', array('KNOWN_AUTHOR'=>$user['username'])); |
---|
688 | } |
---|
689 | else |
---|
690 | { |
---|
691 | $template->assign_block_vars('comments.add_comment.author_field', array()); |
---|
692 | } |
---|
693 | } |
---|
694 | } |
---|
695 | //------------------------------------------------------------ log informations |
---|
696 | pwg_log( 'picture', $title_img, $picture['current']['file'] ); |
---|
697 | mysql_close(); |
---|
698 | |
---|
699 | $template->pparse('picture'); |
---|
700 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
701 | ?> |
---|