source: trunk/picture.php @ 27

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