source: trunk/picture.php @ 21

Last change on this file since 21 was 21, checked in by z0rglub, 21 years ago

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 20.6 KB
Line 
1<?php
2/***************************************************************************
3 *                                picture.php                              *
4 *                            -------------------                          *
5 *   application          : PhpWebGallery 1.3                              *
6 *   author               : Pierrick LE GALL <pierrick@z0rglub.com>        *
7 *                                                                         *
8 ***************************************************************************/
9
10/***************************************************************************
11 *                                                                         *
12 *   This program is free software; you can redistribute it and/or modify  *
13 *   it under the terms of the GNU General Public License as published by  *
14 *   the Free Software Foundation;                                         *
15 *                                                                         *
16 ***************************************************************************/
17
18// this page shows the image full size
19// (or resized to the max size the user has chosen)
20// and two thumbnail : previous and next picture of your gallery
21//----------------------------------------------------------- personnal include
22include_once( './include/init.inc.php' );       
23//-------------------------------------------------- access authorization check
24check_cat_id( $_GET['cat'] );
25check_login_authorization();
26if ( isset( $page['cat'] ) && is_numeric( $page['cat'] ) )
27{
28  check_restrictions( $page['cat'] );
29}
30//---------------------------------------- incrementation of the number of hits
31$query = 'UPDATE '.PREFIX_TABLE.'images';
32$query.= ' SET hit=hit+1';
33$query.= ' WHERE id='.$_GET['image_id'];
34$query.= ';';
35@mysql_query( $query );
36//-------------------------------------------------------------- initialization
37initialize_category( 'picture' );
38$cat_directory = $page['cat_dir']; // by default
39//------------------------------------- main picture information initialization
40$query = 'SELECT id,date_available,comment,hit';
41$query.= ',author,name,file,date_creation,filesize,width,height,cat_id';
42$query.= ' FROM '.PREFIX_TABLE.'images';
43$query.= $page['where'];
44$query.= ' AND id = '.$_GET['image_id'];
45$query.= $conf['order_by'];
46$query.= ';';
47$result = mysql_query( $query );
48$row = mysql_fetch_array( $result );
49$page['id']             = $row['id'];
50$page['file']           = $row['file'];
51$page['name']           = $row['name'];
52$page['date_available'] = $row['date_available'];
53$page['comment']        = $row['comment'];
54$page['hit']            = $row['hit'];
55$page['author']         = $row['author'];
56$page['date_creation']  = $row['date_creation'];
57$page['filesize']       = $row['filesize'];
58$page['width']          = $row['width'];
59$page['height']         = $row['height'];
60$page['cat_id']         = $row['cat_id'];
61// retrieving the number of the picture in its category (in order)
62$query = 'SELECT id';
63$query.= ' FROM '.PREFIX_TABLE.'images';
64$query.= $page['where'];
65$query.= $conf['order_by'];
66$query.= ';';
67$result = mysql_query( $query );
68$page['num'] = 0;
69$row = mysql_fetch_array( $result );
70while ( $row['id'] != $page['id'] )
71{
72  $page['num']++;
73  $row = mysql_fetch_array( $result );
74}
75//--------------------------------------------------------- favorite management
76if ( isset( $_GET['add_fav'] ) )
77{
78  if ( $_GET['add_fav'] == 1 )
79  {
80    // verify if the picture is already in the favorite of the user
81    $query = 'SELECT COUNT(*) AS nb_fav';
82    $query.= ' FROM '.PREFIX_TABLE.'favorites';
83    $query.= ' WHERE image_id = '.$page['id'];
84    $query.= ' AND user_id = '.$user['id'];
85    $query.= ';';
86    $result = mysql_query( $query );
87    $row = mysql_fetch_array( $result );
88    if ( $row['nb_fav'] == 0 )
89    {
90      $query = 'INSERT INTO '.PREFIX_TABLE.'favorites';
91      $query.= ' (image_id,user_id) VALUES';
92      $query.= ' ('.$page['id'].','.$user['id'].')';
93      $query.= ';';
94      $result = mysql_query( $query );
95    }
96  }
97  if ( $_GET['add_fav'] == 0 )
98  {
99    $query = 'DELETE FROM '.PREFIX_TABLE.'favorites';
100    $query.= ' WHERE user_id = '.$user['id'];
101    $query.= ' AND image_id = '.$page['id'];
102    $query.= ';';
103    $result = mysql_query( $query );
104   
105    $page['cat_nb_images'] = $page['cat_nb_images'] - 1;
106    if ( $page['cat_nb_images'] <= 0 )
107    {
108      // there is no favorite picture anymore
109      // we redirect the user to the category page
110      $url = add_session_id( 'category.php' );
111      header( 'Request-URI: '.$url );
112      header( 'Content-Location: '.$url ); 
113      header( 'Location: '.$url );
114      exit();
115    }
116    // redirection of the user to the picture.php page
117    // with the right picture
118    $page['num'] = $page['num'] - 1;
119    if ( $page['num'] == -1 )
120    {
121      $page['num'] = 0;
122    }
123    $query = 'SELECT id';
124    $query.= ' FROM '.PREFIX_TABLE.'images';
125    $query.= $page['where'];
126    $query.= $conf['order_by'];
127    $query.= ' LIMIT '.$page['num'].',1';
128    $query.= ';';
129    $result = mysql_query( $query );
130    $row = mysql_fetch_array( $result );
131    $redirect = './picture.php?image_id='.$row['id'].'&cat='.$page['cat'];
132    $redirect.= '&expand='.$_GET['expand'];
133    if ( $page['cat'] == 'search' )
134    {
135      $redirect.= '&search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
136    }
137    $url = add_session_id( $redirect, true );
138    header( 'Request-URI: '.$url );
139    header( 'Content-Location: '.$url ); 
140    header( 'Location: '.$url );
141    exit();
142  }
143}
144//----------------------------------------------------- template initialization
145$vtp = new VTemplate;
146$handle = $vtp->Open( './template/'.$user['template'].'/picture.vtp' );
147initialize_template();
148
149$tpl = array( 'back','submit','comments_title','comments_del','delete',
150              'comments_add','author' );
151templatize_array( $tpl, 'lang', $handle );
152$vtp->setGlobalVar( $handle, 'text_color', $user['couleur_text'] );
153//------------------------------------------------------------------ page title
154if ( $page['name'] != '' )
155{
156  $vtp->setGlobalVar( $handle, 'page_title', $page['name'] );
157}
158else
159{
160  $vtp->setGlobalVar( $handle, 'page_title', $page['file'] );
161}
162//-------------------------------------------------- previous picture thumbnail
163if ( $page['num'] >= 1 )
164{
165  $prev = $page['num'] - 1;
166  $query = 'SELECT id,name,file,tn_ext,cat_id';
167  $query.= ' FROM '.PREFIX_TABLE.'images';
168  $query.= $page['where'];
169  $query.= $conf['order_by'];
170  $query.= ' LIMIT '.$prev.',1';
171  $query.= ';';
172  $result = mysql_query( $query );
173  $row = mysql_fetch_array( $result );
174
175  if ( !is_numeric( $page['cat'] ) )
176  {
177    if ( $array_cat_directories[$row['cat_id']] == '' )
178    {
179      $cat_result = get_cat_info( $row['cat_id'] );
180      $array_cat_directories[$row['cat_id']] = $cat_result['dir'];
181    }
182    $cat_directory = $array_cat_directories[$row['cat_id']];
183  }
184               
185  $file = substr ( $row['file'], 0, strrpos ( $row['file'], '.' ) );
186  $lien_thumbnail = $cat_directory.'/thumbnail/';
187  $lien_thumbnail.= $conf['prefix_thumbnail'].$file.".".$row['tn_ext'];
188               
189  $prev_title = $lang['previous_image'].' : ';
190  $alt_thumbnaill = '';
191  if ( $row['name'] != '' ) $alt_thumbnail = $row['name'];
192  else                      $alt_thumbnail = $file;
193  $prev_title.= $alt_thumbnail;
194 
195  $url_link = './picture.php?image_id='.$row['id'].'&amp;cat='.$page['cat'];
196  $url_link.= '&amp;expand='.$_GET['expand'];
197  if ( $page['cat'] == 'search' )
198  {
199    $url_link.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
200  }
201  // sending vars for display
202  $vtp->addSession( $handle, 'previous' );
203  $vtp->setGlobalVar( $handle, 'previous.url', add_session_id( $url_link ) );
204  $vtp->setGlobalVar( $handle, 'previous.title', $prev_title );
205  $vtp->setGlobalVar( $handle, 'previous.src', $lien_thumbnail );
206  $vtp->setGlobalVar( $handle, 'previous.alt', $alt_thumbnail );
207  $vtp->closeSession( $handle, 'previous' );
208}
209else
210{
211  $vtp->addSession( $handle, 'previous_empty' );
212  $vtp->closeSession( $handle, 'previous_empty' );
213}
214//-------------------------------------------------------- main picture display
215if ( is_numeric( $page['cat'] ) )
216{
217  $intitule_cat = get_cat_display_name( $page['cat_name'], " - ",
218                                        "font-style:italic;" );
219}
220else
221{
222  $cat_result = get_cat_info( $page['cat_id'] );
223  if ( $array_cat_directories[$page['cat_id']] == "" )
224  {
225    $array_cat_directories[$page['cat_id']] = $cat_result['dir'];
226  }
227  $cat_directory = $array_cat_directories[$page['cat_id']];
228  $intitule_cat = $page['title'];
229}
230$n = $page['num'] + 1;
231$intitule_titre = replace_space( $intitule_cat." - " ).$n.'/'.
232$intitule_titre.= $page['cat_nb_images']."<br />";
233if ( $page['name'] != "" )
234{
235  $intitule_file = $page['name'];
236}
237else
238{
239  $intitule_file = str_replace( "_", " ",
240                                substr( $page['file'], 0,
241                                        strrpos ( $page['file'], ".") ) );
242}
243if ( $page['cat'] == 'search' )
244{
245  $intitule_file = replace_search( $intitule_file, $_GET['search'] );
246}
247$vtp->setGlobalVar( $handle, 'title', $intitule_titre.$intitule_file );
248
249$lien_image = $cat_directory.$page['file'];
250
251// calcul de la largeur et de la hauteur
252if ( $page['width'] == "" )
253{
254  $taille_image = @getimagesize( $lien_image );
255  $original_width = $taille_image[0];
256  $original_height = $taille_image[1];
257}
258else
259{
260  $original_width = $page['width'];
261  $original_height = $page['height'];
262}
263
264$picture_size = get_picture_size( $original_width, $original_height,
265                                  $user['maxwidth'], $user['maxheight'] );
266$final_width  = $picture_size[0];
267$final_height = $picture_size[1];
268       
269$url_link = './category.php?cat='.$page['cat'].'&amp;';
270$url_link.= 'num='.$page['num'].'&amp;expand='.$_GET['expand'];
271if ( $page['cat'] == 'search' )
272{
273  $url_link.= "&amp;search=".$_GET['search'].'&amp;mode='.$_GET['mode'];
274}
275$vtp->setGlobalVar( $handle, 'picture_link', add_session_id( $url_link ) );
276$vtp->setGlobalVar( $handle, 'picture_width', $final_width );
277$vtp->setGlobalVar( $handle, 'picture_height', $final_height );
278$vtp->setGlobalVar( $handle, 'picture_border_color', $user['couleur_text'] );
279$vtp->setGlobalVar( $handle, 'picture_src', $lien_image );
280$vtp->setGlobalVar( $handle, 'picture_alt', $page['file'] );
281
282if ( $page['comment'] != '' )
283{
284  if ( $page['cat'] == 'search' )
285  {
286    $picture_comment = replace_search( $page['comment'], $_GET['search'] );
287    $vtp->setGlobalVar( $handle, 'picture_comment', $picture_comment );
288  }
289  else
290  {
291    $vtp->setGlobalVar( $handle, 'picture_comment', $page['comment'] );
292  }
293}
294//--------------------------------------------------------- picture information
295// author
296if ( $page['author'] != "" )
297{
298  $vtp->addSession( $handle, 'info_line' );
299  $vtp->setVar( $handle, 'info_line.name', $lang['author'].' : ' );
300  $vtp->setVar( $handle, 'info_line.content', $page['author'] );
301  $vtp->closeSession( $handle, 'info_line' );
302}
303// creation date
304if ( $page['date_creation'] != "" )
305{
306  $vtp->addSession( $handle, 'info_line' );
307  $vtp->setVar( $handle, 'info_line.name', $lang['creation_date'].' : ' );
308  list( $year,$month,$day ) = explode( '-', $page['date_creation'] );
309  $vtp->setVar( $handle, 'info_line.content',
310                $day.'/'.$month.'/'.$year );
311  $vtp->closeSession( $handle, 'info_line' );
312}
313// date of availability
314$vtp->addSession( $handle, 'info_line' );
315$vtp->setVar( $handle, 'info_line.name', $lang['registration_date'].' : ' );
316list( $year,$month,$day ) = explode( '-', $page['date_available'] );
317$vtp->setVar( $handle, 'info_line.content',
318              $day.'/'.$month.'/'.$year );
319$vtp->closeSession( $handle, 'info_line' );
320// size in pixels
321$vtp->addSession( $handle, 'info_line' );
322$vtp->setVar( $handle, 'info_line.name', $lang['size'].' : ' );
323if ( $original_width != $final_width or $original_height != $final_height )
324{
325  $content = '[ <a href="'.$lien_image.'" title="'.$lang['true_size'].'">';
326  $content.= $original_width.'*'.$original_height.'</a> ]';
327  $vtp->setVar( $handle, 'info_line.content', $content );
328}
329else
330{
331  $content = $original_width.'*'.$original_height;
332  $vtp->setVar( $handle, 'info_line.content', $content );
333}
334$vtp->closeSession( $handle, 'info_line' );
335// file
336$vtp->addSession( $handle, 'info_line' );
337$vtp->setVar( $handle, 'info_line.name', $lang['file'].' : ' );
338if ( $page['cat'] == 'search' )
339{
340  $content = replace_search( $page['file'], $_GET['search'] );
341  $vtp->setVar( $handle, 'info_line.content', $content );
342}
343else
344{
345  $vtp->setVar( $handle, 'info_line.content', $page['file'] );
346}
347$vtp->closeSession( $handle, 'info_line' );
348// filesize
349if ( $page['filesize'] == "" )
350{
351  $poids = floor ( filesize( $lien_image ) / 1024 );
352}
353else
354{
355  $poids = $page['filesize'];
356}
357$vtp->addSession( $handle, 'info_line' );
358$vtp->setVar( $handle, 'info_line.name', $lang['filesize'].' : ' );
359$vtp->setVar( $handle, 'info_line.content', $poids.' KB' );
360$vtp->closeSession( $handle, 'info_line' );
361// number of visits
362$vtp->addSession( $handle, 'info_line' );
363$vtp->setVar( $handle, 'info_line.name', $lang['visited'].' : ' );
364$vtp->setVar( $handle, 'info_line.content', $page['hit'].' '.$lang['times'] );
365$vtp->closeSession( $handle, 'info_line' );
366//------------------------------------------------------- favorite manipulation
367if ( $page['cat'] != 'fav' and !$user['is_the_guest'] )
368{
369  $url = './picture.php?cat='.$page['cat'].'&amp;image_id='.$page['id'];
370  $url.= '&amp;expand='.$_GET['expand'].'&amp;add_fav=1';
371  if ( $page['cat'] == 'search' )
372  {
373    $url.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
374  }
375  $vtp->addSession( $handle, 'favorite' );
376  $vtp->setVar( $handle, 'favorite.link', add_session_id( $url ) );
377  $vtp->setVar( $handle, 'favorite.title', $lang['add_favorites_hint'] );
378  $vtp->setVar( $handle, 'favorite.src',
379                './theme/'.$user['theme'].'/favorite.gif' );
380  $vtp->setVar( $handle, 'favorite.alt','[ '.$lang['add_favorites_alt'].' ]' );
381  $vtp->closeSession( $handle, 'favorite' );
382}
383if ( $page['cat'] == 'fav' )
384{
385  $url = './picture.php?cat='.$page['cat'].'&amp;image_id='.$page['id'];
386  $url.= '&amp;expand='.$_GET['expand'].'&amp;add_fav=0';
387  $vtp->addSession( $handle, 'favorite' );
388  $vtp->setVar( $handle, 'favorite.link', add_session_id( $url ) );
389  $vtp->setVar( $handle, 'favorite.title', $lang['del_favorites_hint'] );
390  $vtp->setVar( $handle, 'favorite.src',
391                './theme/'.$user['theme'].'/del_favorite.gif' );
392  $vtp->setVar( $handle, 'favorite.alt','[ '.$lang['del_favorites_alt'].' ]' );
393  $vtp->closeSession( $handle, 'favorite' );
394}
395//------------------------------------ admin link for information modifications
396if ( $user['status'] == "admin" && is_numeric( $page['cat'] ) )
397{
398  $vtp->addSession( $handle, 'modification' );
399  $url = './admin/admin.php?page=infos_images&amp;cat_id='.$page['cat'];
400  $url.= '&amp;num='.$page['num'];
401  $vtp->setVar( $handle, 'modification.link',
402                add_session_id( $url )."#".$page['id'] );
403  $vtp->setVar( $handle, 'modification.name', $lang['link_info_image'] );
404}
405//---------------------------------------------- next picture thumbnail display
406if ( $page['num'] < $page['cat_nb_images']-1 )
407{
408  $next = $page['num'] + 1;
409  $query = 'SELECT id,name,file,tn_ext,cat_id';
410  $query.= ' FROM '.PREFIX_TABLE.'images';
411  $query.= $page['where'];
412  $query.= $conf['order_by'];
413  $query.= ' LIMIT '.$next.',1';
414  $query.= ';';
415  $result = mysql_query( $query );
416  $row = mysql_fetch_array( $result );
417               
418  if ( !is_numeric( $page['cat'] ) )
419  {
420    if ( $array_cat_directories[$row['cat_id']] == "" )
421    {
422      $cat_result = get_cat_info( $row['cat_id'] );
423      $array_cat_directories[$row['cat_id']] = $cat_result['dir'];
424    }
425    $cat_directory = $array_cat_directories[$row['cat_id']];
426  }
427
428  $file = substr ( $row['file'], 0, strrpos ( $row['file'], ".") );
429  $lien_thumbnail = $cat_directory.'thumbnail/';
430  $lien_thumbnail.= $conf['prefix_thumbnail'].$file.".".$row['tn_ext'];
431 
432  if ( $row['name'] != "" )
433  {
434    $alt_thumbnail = $row['name'];
435  }
436  else
437  {
438    $alt_thumbnail = $file;
439  }
440  $next_title = $lang['next_image']." : ".$alt_thumbnail;
441
442  $url_link = './picture.php?image_id='.$row['id'].'&amp;cat='.$page['cat'];
443  $url_link.= '&amp;expand='.$_GET['expand'];
444  if ( $page['cat'] == 'search' )
445  {
446    $url_link.= "&amp;search=".$_GET['search'].'&amp;mode='.$_GET['mode'];
447  }
448  // sending vars for display
449  $vtp->addSession( $handle,   'next' );
450  $vtp->setGlobalVar( $handle, 'next.url', add_session_id( $url_link ) );
451  $vtp->setGlobalVar( $handle, 'next.title', $next_title );
452  $vtp->setGlobalVar( $handle, 'next.src', $lien_thumbnail );
453  $vtp->setGlobalVar( $handle, 'next.alt', $alt_thumbnail );
454  $vtp->closeSession( $handle, 'next' );
455}
456else
457{
458  $vtp->addSession( $handle, 'previous_empty' );
459  $vtp->closeSession( $handle, 'previous_empty' );
460}
461//---------------------------------------------------- users's comments display
462if ( $conf['show_comments'] )
463{
464  $vtp->addSession( $handle, 'comments' );
465  // comment registeration
466  if ( isset( $_POST['content'] ) && $_POST['content'] != '' )
467  {
468    $author = $user['username'];
469    if ( $_POST['author'] != '' )
470    {
471      $author = $_POST['author'];
472    }
473    $query = 'INSERT INTO '.PREFIX_TABLE.'comments';
474    $query.= ' (author,date,image_id,content) VALUES';
475    $query.= " ('".$author."',".time().",".$page['id'];
476    $query.= ",'".htmlspecialchars( $_POST['content'], ENT_QUOTES)."');";
477    mysql_query( $query );
478  }
479  // comment deletion
480  if ( isset( $_GET['del'] )
481       && is_numeric( $_GET['del'] )
482       && $user['status'] == 'admin' )
483  {
484    $query = 'DELETE FROM '.PREFIX_TABLE.'comments';
485    $query.= ' WHERE id = '.$_GET['del'].';';
486    mysql_query( $query );
487  }
488  // number of comment for this picture
489  $query = 'SELECT COUNT(*) AS nb_comments';
490  $query.= ' FROM '.PREFIX_TABLE.'comments';
491  $query.= ' WHERE image_id = '.$page['id'].';';
492  $row = mysql_fetch_array( mysql_query( $query ) );
493  $page['nb_comments'] = $row['nb_comments'];
494  // navigation bar creation
495  $url = './picture.php?cat='.$page['cat'].'&amp;image_id='.$page['id'];
496  $url.= '&amp;expand='.$_GET['expand'];
497  if ( $page['cat'] == 'search' )
498  {
499    $url.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
500  }
501  if( !isset( $_GET['start'] )
502      or !is_numeric( $_GET['start'] )
503      or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) )
504  {
505    $page['start'] = 0;
506  }
507  else
508  {
509    $page['start'] = $_GET['start'];
510  }
511  $page['navigation_bar'] = create_navigation_bar( $url, $page['nb_comments'],
512                                                   $page['start'],
513                                                   $conf['nb_comment_page'],
514                                                   '' );
515  // sending vars for display
516  $vtp->setGlobalVar( $handle, 'navigation_bar', $page['navigation_bar'] );
517  $vtp->setGlobalVar( $handle, 'nb_comments', $page['nb_comments'] );
518
519  $query = 'SELECT id,author,date,image_id,content';
520  $query.= ' FROM '.PREFIX_TABLE.'comments';
521  $query.= ' WHERE image_id = '.$page['id'];
522  $query.= ' ORDER BY date ASC';
523  $query.= ' LIMIT '.$page['start'].', '.$conf['nb_comment_page'].';';
524  $result = mysql_query( $query );
525               
526  while ( $row = mysql_fetch_array( $result ) )
527  {
528    $vtp->addSession( $handle, 'comment' );
529    $vtp->setVar( $handle, 'comment.author', $row['author'] );
530    $displayed_date = $lang['day'][date( "w", $row['date'] )];
531    $displayed_date.= date( " j ", $row['date'] );
532    $displayed_date.= $lang['month'][date( "n", $row['date'] )];
533    $displayed_date.= date( " Y G:i", $row['date'] );
534    $vtp->setVar( $handle, 'comment.date', $displayed_date );
535    $vtp->setVar( $handle, 'comment.content', nl2br( $row['content'] ) );
536    if ( $user['status'] == 'admin' )
537    {
538      $vtp->addSession( $handle, 'delete' );
539      $vtp->setVar( $handle, 'delete.link',
540                    add_session_id( $url.'&amp;del='.$row['id'] ) );
541      $vtp->closeSession( $handle, 'delete' );
542    }
543    $vtp->closeSession( $handle, 'comment' );
544  }
545  // form action
546  $action = str_replace( '&', '&amp;', $_SERVER['REQUEST_URI'] );
547  $vtp->setGlobalVar( $handle, 'form_action', $action );
548  // display author field if the user is not logged in
549  if ( !$user['is_the_guest'] )
550  {
551    $vtp->addSession( $handle, 'author_known' );
552    $vtp->setVar( $handle, 'author_known.value', $user['pseudo'] );
553    $vtp->closeSession( $handle, 'author_known' );
554  }
555  else
556  {
557    $vtp->addSession( $handle, 'author_field' );
558    $vtp->closeSession( $handle, 'author_field' );
559  }
560  $vtp->closeSession( $handle, 'comments' );
561}
562//------------------------------------------------------------ log informations
563pwg_log( 'picture', $intitule_cat, $page['file'] );
564mysql_close();
565//----------------------------------------------------------- html code display
566$code = $vtp->Display( $handle, 0 );
567echo $code;
568?>
Note: See TracBrowser for help on using the repository browser.