source: trunk/picture.php @ 598

Last change on this file since 598 was 598, checked in by plg, 19 years ago

when picture size exceeds user maximum display size, the link was on the
same page : now it shows the file in the browser

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 27.7 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2004 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-11-09 21:59:19 +0000 (Tue, 09 Nov 2004) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 598 $
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$rate_items = array(0,1,2,3,4,5);
29//--------------------------------------------------------------------- include
30define('PHPWG_ROOT_PATH','./');
31include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );   
32//-------------------------------------------------- access authorization check
33check_cat_id( $_GET['cat'] );
34check_login_authorization();
35if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) )
36{
37  check_restrictions( $page['cat'] );
38}
39//---------------------------------------- incrementation of the number of hits
40$query = '
41UPDATE '.IMAGES_TABLE.'
42  SET hit = hit+1
43  WHERE id = '.$_GET['image_id'].'
44;';
45@pwg_query( $query );
46//-------------------------------------------------------------- initialization
47initialize_category( 'picture' );
48// retrieving the number of the picture in its category (in order)
49$query = '
50SELECT DISTINCT(id)
51  FROM '.IMAGES_TABLE.'
52    INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
53  '.$page['where'].'
54  '.$conf['order_by'].'
55;';
56$result = pwg_query( $query );
57$page['num'] = 0;
58$belongs = false;
59while ($row = mysql_fetch_array($result))
60{
61  if ($row['id'] == $_GET['image_id'])
62  {
63    $belongs = true;
64    break;
65  }
66  $page['num']++;
67}
68// if this image_id doesn't correspond to this category, an error message is
69// displayed, and execution is stopped
70if (!$belongs)
71{
72  echo '<div style="text-align:center;">'.$lang['access_forbiden'].'<br />';
73  echo '<a href="'.add_session_id( PHPWG_ROOT_PATH.'category.php' ).'">';
74  echo $lang['thumbnails'].'</a></div>';
75  exit();
76}
77//------------------------------------- prev, current & next picture management
78$picture = array();
79
80if ($page['num'] == 0)
81{
82  $has_prev = false;
83}
84else
85{
86  $has_prev = true;
87}
88
89if ($page['num'] == $page['cat_nb_images'] - 1)
90{
91  $has_next = false;
92}
93else
94{
95  $has_next = true;
96}
97
98$query = '
99SELECT *
100  FROM '.IMAGES_TABLE.'
101    INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id=ic.image_id
102  '.$page['where'].'
103  '.$conf['order_by'].'
104  ';
105
106if ( !$has_prev )
107{
108  $query.= ' LIMIT 0,2';
109}
110else
111{
112  $query.= ' LIMIT '.($page['num'] - 1).',3';
113}
114$query.= ';';
115
116$result = pwg_query( $query );
117$indexes = array('prev', 'current', 'next');
118
119foreach (array('prev', 'current', 'next') as $i)
120{
121  if ($i == 'prev' and !$has_prev)
122  {
123    continue;
124  }
125  if ($i == 'next' and !$has_next)
126  {
127    break;
128  }
129
130  $row = mysql_fetch_array($result);
131  foreach (array_keys($row) as $key)
132  {
133    if (!is_numeric($key))
134    {
135      $picture[$i][$key] = $row[$key];
136    }
137  }
138
139  $picture[$i]['is_picture'] = false;
140  if (in_array(get_extension($row['file']), $conf['picture_ext']))
141  {
142    $picture[$i]['is_picture'] = true;
143  }
144 
145  if ( !isset($array_cat_directories[$row['storage_category_id']]))
146  {
147    $array_cat_directories[$row['storage_category_id']] =
148      get_complete_dir( $row['storage_category_id'] );
149  }
150  $cat_directory = $array_cat_directories[$row['storage_category_id']];
151  $file_wo_ext = get_filename_wo_extension($row['file']);
152
153  $icon = './template/'.$user['template'].'/mimetypes/';
154  $icon.= strtolower(get_extension($row['file'])).'.png';
155
156  if (isset($row['representative_ext']) and $row['representative_ext'] =! '')
157  {
158    $picture[$i]['src'] = $cat_directory.'pwg_representative/';
159    $picture[$i]['src'].= $file_wo_ext.'.'.$row['representative_ext'];
160  }
161  else
162  {
163    $picture[$i]['src'] = $icon;
164  }
165  // special case for picture files
166  if ($picture[$i]['is_picture'])
167  {
168    $picture[$i]['src'] = $cat_directory.$row['file'];
169    // if we are working on the "current" element, we search if there is a
170    // high quality picture
171    // FIXME : with remote pictures, this "remote fopen" takes long...
172    if ($i == 'current')
173    {
174      if (@fopen($cat_directory.'pwg_high/'.$row['file'], 'r'))
175      {
176        $picture[$i]['high'] = $cat_directory.'pwg_high/'.$row['file'];
177      }
178    }
179  }
180
181  // if picture is not a file, we need the download link
182  if (!$picture[$i]['is_picture'])
183  {
184    $picture[$i]['download'] = $cat_directory.$row['file'];
185  }
186
187  $picture[$i]['thumbnail'] = get_thumbnail_src($row['file'],
188                                                $row['storage_category_id'],
189                                                @$row['tn_ext']);
190 
191  if ( !empty( $row['name'] ) )
192  {
193    $picture[$i]['name'] = $row['name'];
194  }
195  else
196  {
197    $picture[$i]['name'] = str_replace('_', ' ', $file_wo_ext);
198  }
199
200  $picture[$i]['url'] = PHPWG_ROOT_PATH.'picture.php';
201  $picture[$i]['url'].= get_query_string_diff(array('image_id','add_fav',
202                                                    'slideshow','rate'));
203  $picture[$i]['url'].= '&amp;image_id='.$row['id'];
204}
205
206$url_up = PHPWG_ROOT_PATH.'category.php?cat='.$page['cat'].'&amp;';
207$url_up.= 'num='.$page['num']; 
208if ( $page['cat'] == 'search' )
209{
210  $url_up.= "&amp;search=".$_GET['search'];
211}
212
213$url_admin = PHPWG_ROOT_PATH.'admin.php?page=picture_modify';
214$url_admin.= '&amp;cat_id='.$page['cat'];
215$url_admin.= '&amp;image_id='.$_GET['image_id'];
216
217$url_slide = $picture['current']['url'];
218$url_slide.= '&amp;slideshow='.$conf['slideshow_period'];
219//----------------------------------------------------------- rate registration
220if (isset($_GET['rate'])
221    and $conf['rate']
222    and !$user['is_the_guest']
223    and in_array($_GET['rate'], $rate_items))
224{
225  $query = '
226DELETE
227  FROM '.RATE_TABLE.'
228  WHERE user_id = '.$user['id'].'
229    AND element_id = '.$_GET['image_id'].'
230;';
231  pwg_query($query);
232  $query = '
233INSERT INTO '.RATE_TABLE.'
234  (user_id,element_id,rate)
235  VALUES
236  ('.$user['id'].','.$_GET['image_id'].','.$_GET['rate'].')
237;';
238  pwg_query($query);
239
240  // update of images.average_rate field
241  $query = '
242SELECT ROUND(AVG(rate),2) AS average_rate
243  FROM '.RATE_TABLE.'
244  WHERE element_id = '.$_GET['image_id'].'
245;';
246  $row = mysql_fetch_array(pwg_query($query));
247  $query = '
248UPDATE '.IMAGES_TABLE.'
249  SET average_rate = '.$row['average_rate'].'
250  WHERE id = '.$_GET['image_id'].'
251;';
252  pwg_query($query);
253}
254//--------------------------------------------------------- favorite management
255if ( isset( $_GET['add_fav'] ) )
256{
257  $query = 'DELETE FROM '.FAVORITES_TABLE;
258  $query.= ' WHERE user_id = '.$user['id'];
259  $query.= ' AND image_id = '.$picture['current']['id'];
260  $query.= ';';
261  $result = pwg_query( $query );
262 
263  if ( $_GET['add_fav'] == 1 )
264  {
265    $query = 'INSERT INTO '.FAVORITES_TABLE;
266    $query.= ' (image_id,user_id) VALUES';
267    $query.= ' ('.$picture['current']['id'].','.$user['id'].')';
268    $query.= ';';
269    $result = pwg_query( $query );
270  }
271  if ( !$_GET['add_fav'] and $page['cat'] == 'fav' )
272  {
273    if (!$has_prev and $mysql_num_rows == 1)
274    {
275      // there is no favorite picture anymore we redirect the user to the
276      // category page
277      $url = add_session_id($url_up);
278      redirect($url);
279    }
280    else if (!$has_prev)
281    {
282      $url = str_replace( '&amp;', '&', $picture['next']['url'] );
283      $url = add_session_id( $url, true);
284    }
285    else
286    {
287      $url = str_replace('&amp;', '&', $picture['prev']['url'] );
288      $url = add_session_id( $url, true);
289    }
290    redirect( $url );
291  }
292}
293
294//------------------------------------------------------  comment registeration
295if ( isset( $_POST['content'] ) && !empty($_POST['content']) )
296{
297  $register_comment = true;
298  $author = !empty($_POST['author'])?$_POST['author']:$lang['guest'];
299  // if a guest try to use the name of an already existing user, he must be
300  // rejected
301  if ( $author != $user['username'] )
302  {
303    $query = 'SELECT COUNT(*) AS user_exists';
304    $query.= ' FROM '.USERS_TABLE;
305    $query.= " WHERE username = '".$author."'";
306    $query.= ';';
307    $row = mysql_fetch_array( pwg_query( $query ) );
308    if ( $row['user_exists'] == 1 )
309    {
310      $template->assign_block_vars(
311        'information',
312        array('INFORMATION'=>$lang['comment_user_exists']));
313      $register_comment = false;
314    }
315  }
316 
317  if ( $register_comment )
318  {
319    // anti-flood system
320    $reference_date = time() - $conf['anti-flood_time'];
321    $query = 'SELECT id FROM '.COMMENTS_TABLE;
322    $query.= ' WHERE date > FROM_UNIXTIME('.$reference_date.')';
323    $query.= " AND author = '".$author."'";
324    $query.= ';';
325    if ( mysql_num_rows( pwg_query( $query ) ) == 0
326         or $conf['anti-flood_time'] == 0 )
327    {
328      $query = 'INSERT INTO '.COMMENTS_TABLE;
329      $query.= ' (author,date,image_id,content,validated) VALUES (';
330      $query.= "'".$author."'";
331      $query.= ',NOW(),'.$_GET['image_id'];
332      $query.= ",'".htmlspecialchars( $_POST['content'], ENT_QUOTES)."'";
333      if ( !$conf['comments_validation'] or $user['status'] == 'admin' )
334      {       
335        $query.= ",'true'";
336      }
337      else
338      {
339        $query.= ",'false'";
340      }
341      $query.= ');';
342      pwg_query( $query );
343      // information message
344      $message = $lang['comment_added'];
345      if ( $conf['comments_validation'] and $user['status'] != 'admin' )
346      {
347        $message.= '<br />'.$lang['comment_to_validate'];
348      }
349      $template->assign_block_vars('information',
350                                   array('INFORMATION'=>$message));
351      // notification to the administrators
352      if ( $conf['mail_notification'] )
353      {
354        $cat_name = get_cat_display_name( $page['cat_name'], ' > ', '' );
355        $cat_name = strip_tags( $cat_name );
356        notify( 'comment', $cat_name.' > '.$picture['current']['name']);
357      }
358    }
359    else
360    {
361      // information message
362      $template->assign_block_vars(
363        'information',
364        array('INFORMATION'=>$lang['comment_anti-flood']));
365    }
366  }
367}
368// comment deletion
369if ( isset( $_GET['del'] )
370     and is_numeric( $_GET['del'] )
371     and $user['status'] == 'admin' )
372{
373  $query = 'DELETE FROM '.COMMENTS_TABLE;
374  $query.= ' WHERE id = '.$_GET['del'];
375  $query.= ';';
376  pwg_query( $query );
377}
378
379//
380// Start output of page
381//
382
383$title =  $picture['current']['name'];
384$refresh = 0;
385if ( isset( $_GET['slideshow'] ) and $has_next )
386{
387  $refresh= $_GET['slideshow'];
388  $url_link = $picture['next']['url'].'&amp;slideshow='.$refresh;
389}
390
391$title_img = $picture['current']['name'];
392$title_nb = '';
393if (is_numeric( $page['cat'] )) 
394{
395  $title_img = replace_space(get_cat_display_name($page['cat_name'],' &gt; '));
396  $n = $page['num'] + 1;
397  $title_nb = $n.'/'.$page['cat_nb_images'];
398}
399else if ( $page['cat'] == 'search' )
400{
401  $title_img = replace_search( $title_img, $_GET['search'] );
402}
403
404// calculation of width and height
405if (empty($picture['current']['width']))
406{
407  $taille_image = @getimagesize($picture['current']['src']);
408  $original_width = $taille_image[0];
409  $original_height = $taille_image[1];
410}
411else
412{
413  $original_width = $picture['current']['width'];
414  $original_height = $picture['current']['height'];
415}
416
417$picture_size = get_picture_size( $original_width, $original_height,
418                                  $user['maxwidth'], $user['maxheight'] );
419
420// metadata
421if ($conf['show_exif'] or $conf['show_iptc'])
422{
423  $metadata_showable = true;
424}
425else
426{
427  $metadata_showable = false;
428}
429
430$url_metadata = PHPWG_ROOT_PATH.'picture.php';
431$url_metadata .=  get_query_string_diff(array('add_fav', 'slideshow', 'show_metadata'));
432if ($metadata_showable and !isset($_GET['show_metadata']))
433{
434  $url_metadata.= '&amp;show_metadata=1';
435}
436                                 
437include(PHPWG_ROOT_PATH.'include/page_header.php');
438$template->set_filenames(array('picture'=>'picture.tpl'));
439
440$template->assign_vars(array(
441  'CATEGORY' => $title_img,
442  'PHOTO' => $title_nb,
443  'TITLE' => $picture['current']['name'],
444  'SRC_IMG' => $picture['current']['src'],
445  'ALT_IMG' => $picture['current']['file'],
446  'WIDTH_IMG' => $picture_size[0],
447  'HEIGHT_IMG' => $picture_size[1],
448
449  'L_HOME' => $lang['gallery_index'],
450  'L_SLIDESHOW' => $lang['slideshow'],
451  'L_STOP_SLIDESHOW' => $lang['slideshow_stop'],
452  'L_PREV_IMG' =>$lang['previous_image'].' : ',
453  'L_ADMIN' =>$lang['link_info_image'],
454  'L_COMMENT_TITLE' =>$lang['comments_title'],
455  'L_ADD_COMMENT' =>$lang['comments_add'],
456  'L_DELETE_COMMENT' =>$lang['comments_del'],
457  'L_DELETE' =>$lang['delete'],
458  'L_SUBMIT' =>$lang['submit'],
459  'L_AUTHOR' =>$lang['author'],
460  'L_COMMENT' =>$lang['comment'],
461  'L_DOWNLOAD' => $lang['download'],
462  'L_DOWNLOAD_HINT' => $lang['download_hint'],
463  'L_PICTURE_METADATA' => $lang['picture_show_metadata'],
464  'L_PICTURE_HIGH' => $lang['picture_high'],
465  'L_UP_HINT' => $lang['up_hint'],
466  'L_UP_ALT' => $lang['up_alt'],
467 
468  'U_HOME' => add_session_id(PHPWG_ROOT_PATH.'category.php'),
469  'U_UP' => add_session_id($url_up),
470  'U_METADATA' => add_session_id($url_metadata),
471  'U_ADMIN' => add_session_id($url_admin),
472  'U_SLIDESHOW'=> add_session_id($url_slide),
473  'U_ADD_COMMENT' => add_session_id(str_replace( '&', '&amp;', $_SERVER['REQUEST_URI'] ))
474  )
475);
476//------------------------------------------------------- upper menu management
477// download link if file is not a picture
478if (!$picture['current']['is_picture'])
479{
480  $template->assign_block_vars(
481    'download',
482    array('U_DOWNLOAD' => $picture['current']['download']));
483}
484else
485{
486  $template->assign_block_vars(
487    'ecard',
488    array('U_ECARD' => $picture['current']['url']));
489}
490// display a high quality link if present
491if (isset($picture['current']['high']))
492{
493  $full_size = @getimagesize($picture['current']['high']);
494  $full_width = $full_size[0];
495  $full_height = $full_size[1];
496  $uuid = uniqid(rand());
497  $template->assign_block_vars('high', array(
498    'U_HIGH' => $picture['current']['high'],
499        'UUID'=>$uuid,
500        'WIDTH_IMG'=>($full_width + 16),
501        'HEIGHT_IMG'=>($full_height + 16)
502        ));
503}
504//------------------------------------------------------- favorite manipulation
505if ( !$user['is_the_guest'] )
506{
507  // verify if the picture is already in the favorite of the user
508  $query = 'SELECT COUNT(*) AS nb_fav';
509  $query.= ' FROM '.FAVORITES_TABLE.' WHERE image_id = '.$_GET['image_id'];
510  $query.= ' AND user_id = '.$user['id'].';';
511  $result = pwg_query( $query );
512  $row = mysql_fetch_array( $result );
513  if (!$row['nb_fav'])
514  {
515    $url = PHPWG_ROOT_PATH.'picture.php';
516    $url.= get_query_string_diff(array('rate','add_fav'));
517    $url.= '&amp;add_fav=1';
518
519    $template->assign_block_vars(
520      'favorite',
521      array(
522        'FAVORITE_IMG' => PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/favorite.gif',
523        'FAVORITE_HINT' =>$lang['add_favorites_hint'],
524        'FAVORITE_ALT' =>$lang['add_favorites_alt'],
525        'U_FAVORITE' => $url
526        ));
527  }
528  else
529  {
530    $url = PHPWG_ROOT_PATH.'picture.php';
531    $url.= get_query_string_diff(array('rate','add_fav'));
532    $url.= '&amp;add_fav=0';
533   
534    $template->assign_block_vars(
535      'favorite',
536      array(
537        'FAVORITE_IMG' => PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/del_favorite.gif',
538        'FAVORITE_HINT' =>$lang['del_favorites_hint'],
539        'FAVORITE_ALT' =>$lang['del_favorites_alt'],
540        'U_FAVORITE'=> $url
541        ));
542  }
543}
544//------------------------------------ admin link for information modifications
545if ( $user['status'] == 'admin' )
546{
547  $template->assign_block_vars('admin', array());
548}
549
550//-------------------------------------------------------- navigation management
551if ($has_prev)
552{
553  $template->assign_block_vars(
554    'previous',
555    array(
556      'TITLE_IMG' => $picture['prev']['name'],
557      'IMG' => $picture['prev']['thumbnail'],
558      'U_IMG' => add_session_id($picture['prev']['url'])
559      ));
560}
561
562if ($has_next)
563{
564  $template->assign_block_vars(
565    'next',
566    array(
567      'TITLE_IMG' => $picture['next']['name'],
568      'IMG' => $picture['next']['thumbnail'],
569      'U_IMG' => add_session_id($picture['next']['url'])
570      ));
571}
572
573//--------------------------------------------------------- picture information
574// legend
575if (isset($picture['current']['comment'])
576    and !empty($picture['current']['comment']))
577{
578  $template->assign_block_vars(
579    'legend',
580    array(
581        'COMMENT_IMG' => $picture['current']['comment']
582      ));
583}
584
585// author
586if ( !empty($picture['current']['author']) )
587{
588  $search_url = PHPWG_ROOT_PATH.'category.php?cat=search';
589  $search_url.= '&amp;search=author:'.$picture['current']['author'];
590 
591  $value = '<a href="';
592  $value.= add_session_id($search_url);
593  $value.= '">'.$picture['current']['author'].'</a>';
594 
595  $template->assign_block_vars(
596    'info_line',
597    array(
598      'INFO'=>$lang['author'],
599      'VALUE'=>$value
600      ));
601}
602// creation date
603if ( !empty($picture['current']['date_creation']) )
604{
605  $search_url = PHPWG_ROOT_PATH.'category.php?cat=search';
606  $search_url.= '&amp;search=';
607  $search_url.= 'date_creation:'.$picture['current']['date_creation'];
608 
609  $value = '<a href="';
610  $value.= add_session_id($search_url);
611  $value.= '">'.format_date($picture['current']['date_creation']).'</a>';
612 
613  $template->assign_block_vars(
614    'info_line',
615    array(
616      'INFO'=>$lang['creation_date'],
617      'VALUE'=>$value
618      ));
619}
620// date of availability
621$search_url = PHPWG_ROOT_PATH.'category.php?cat=search';
622$search_url.= '&amp;search=';
623$search_url.= 'date_available:'.$picture['current']['date_available'];
624 
625$value = '<a href="';
626$value.= add_session_id($search_url);
627$value.= '">'.format_date($picture['current']['date_available']).'</a>';
628
629$template->assign_block_vars(
630  'info_line',
631  array(
632    'INFO'=>$lang['registration_date'],
633    'VALUE'=>$value
634    ));
635// size in pixels
636if ($picture['current']['is_picture'])
637{
638  if ($original_width != $picture_size[0]
639      or $original_height != $picture_size[1])
640  {
641    $content = '[ <a href="'.$picture['current']['src'].'" ';
642    $content.= ' title="'.$lang['true_size'].'">';
643    $content.= $original_width.'*'.$original_height.'</a> ]';
644  }
645  else
646  {
647    $content = $original_width.'*'.$original_height;
648  }
649  $template->assign_block_vars(
650    'info_line',
651    array(
652      'INFO'=>$lang['size'],
653      'VALUE'=>$content 
654      ));
655}
656// file
657$template->assign_block_vars('info_line', array(
658          'INFO'=>$lang['file'],
659          'VALUE'=>$picture['current']['file'] 
660          ));
661// filesize
662if (empty($picture['current']['filesize']))
663{
664  if (!$picture['current']['is_picture'])
665  {
666    $filesize = floor(filesize($picture['current']['download'])/1024);
667  }
668  else
669  {
670    $filesize = floor(filesize($picture['current']['src'])/1024);
671  }
672}
673else
674{
675  $filesize = $picture['current']['filesize'];
676}
677
678$template->assign_block_vars('info_line', array(
679          'INFO'=>$lang['filesize'],
680          'VALUE'=>$filesize.' KB'
681          ));
682// keywords
683if (!empty($picture['current']['keywords']))
684{
685  $keywords = explode(',', $picture['current']['keywords']);
686  $content = '';
687  $url = PHPWG_ROOT_PATH.'category.php?cat=search&amp;search=keywords:';
688  foreach ($keywords as $i => $keyword)
689  {
690    $local_url = add_session_id($url.$keyword);
691    if ($i > 0)
692    {
693      $content.= ',';
694    }
695    $content.= '<a href="'.$local_url.'">'.$keyword.'</a>';
696  }
697  $template->assign_block_vars(
698    'info_line',
699    array(
700      'INFO'=>$lang['keywords'],
701      'VALUE'=>$content
702      ));
703}
704// number of visits
705$template->assign_block_vars(
706  'info_line',
707  array(
708    'INFO'=>$lang['visited'],
709    'VALUE'=>$picture['current']['hit'].' '.$lang['times']
710    ));
711// rate results
712if ($conf['rate'])
713{
714  $query = '
715SELECT COUNT(rate) AS count
716     , ROUND(AVG(rate),2) AS average
717     , ROUND(STD(rate),2) AS STD
718  FROM '.RATE_TABLE.'
719  WHERE element_id = '.$picture['current']['id'].'
720;';
721  $row = mysql_fetch_array(pwg_query($query));
722  if ($row['count'] == 0)
723  {
724    $value = $lang['no_rate'];
725  }
726  else
727  {
728    $value = $row['average'];
729    $value.= ' (';
730    $value.= $row['count'].' '.$lang['rates'];
731    $value.= ', '.$lang['standard_deviation'].' : '.$row['STD'];
732    $value.= ')';
733  }
734 
735  $template->assign_block_vars(
736    'info_line',
737    array(
738      'INFO'  => $lang['element_rate'],
739      'VALUE' => $value
740      ));
741}
742// related categories
743$query = '
744SELECT category_id
745  FROM '.IMAGE_CATEGORY_TABLE.'
746  WHERE image_id = '.$_GET['image_id'];
747if ($user['forbidden_categories'] != '')
748{
749  $query.= '
750    AND category_id NOT IN ('.$user['forbidden_categories'].')';
751}
752$query.= '
753;';
754$result = pwg_query($query);
755$categories = '';
756while ($row = mysql_fetch_array($result))
757{
758  if ($categories != '')
759  {
760    $categories.= '<br />';
761  }
762  $cat_info = get_cat_info($row['category_id']);
763  $categories .= get_cat_display_name($cat_info['name'], ' &gt;');
764}
765$template->assign_block_vars(
766  'info_line',
767  array(
768    'INFO'  => $lang['categories'],
769    'VALUE' => $categories
770    ));
771// metadata
772if ($metadata_showable and isset($_GET['show_metadata']))
773{
774  include_once(PHPWG_ROOT_PATH.'/include/functions_metadata.inc.php');
775  $template->assign_block_vars('metadata', array());
776  if ($conf['show_exif'])
777  {
778    if ($exif = @read_exif_data($picture['current']['src']))
779    {
780      $template->assign_block_vars(
781        'metadata.headline',
782        array('TITLE' => 'EXIF Metadata')
783        );
784
785      foreach ($conf['show_exif_fields'] as $field)
786      {
787        if (strpos($field, ';') === false)
788        {
789          if (isset($exif[$field]))
790          {
791            $key = $field;
792            if (isset($lang['exif_field_'.$field]))
793            {
794              $key = $lang['exif_field_'.$field];
795            }
796           
797            $template->assign_block_vars(
798              'metadata.line',
799              array(
800                'KEY' => $key,
801                'VALUE' => $exif[$field]
802                )
803              );
804          }
805        }
806        else
807        {
808          $tokens = explode(';', $field);
809          if (isset($exif[$tokens[0]][$tokens[1]]))
810          {
811            $key = $tokens[1];
812            if (isset($lang['exif_field_'.$tokens[1]]))
813            {
814              $key = $lang['exif_field_'.$tokens[1]];
815            }
816           
817            $template->assign_block_vars(
818              'metadata.line',
819              array(
820                'KEY' => $key,
821                'VALUE' => $exif[$tokens[0]][$tokens[1]]
822                )
823              );
824          }
825        }
826      }
827    }
828  }
829  if ($conf['show_iptc'])
830  {
831    $iptc = get_iptc_data($picture['current']['src'],
832                          $conf['show_iptc_mapping']);
833
834    if (count($iptc) > 0)
835    {
836      $template->assign_block_vars(
837        'metadata.headline',
838        array('TITLE' => 'IPTC Metadata')
839        );
840    }
841   
842    foreach ($iptc as $field => $value)
843    {
844      $key = $field;
845      if (isset($lang[$field]))
846      {
847        $key = $lang[$field];
848      }
849     
850      $template->assign_block_vars(
851        'metadata.line',
852        array(
853          'KEY' => $key,
854          'VALUE' => $value
855          )
856        );
857    }
858  }
859}
860//slideshow end
861if ( isset( $_GET['slideshow'] ) )
862{
863  if ( !is_numeric( $_GET['slideshow'] ) ) $_GET['slideshow'] = $conf['slideshow_period'];
864       
865  $template->assign_block_vars('stop_slideshow', array(
866  'U_SLIDESHOW'=>add_session_id( $picture['current']['url'] )
867  ));
868}
869
870//------------------------------------------------------------------- rate form
871if ($conf['rate'])
872{
873  $query = '
874SELECT rate
875  FROM '.RATE_TABLE.'
876  WHERE user_id = '.$user['id'].'
877    AND element_id = '.$_GET['image_id'].'
878;';
879  $result = pwg_query($query);
880  if (mysql_num_rows($result) > 0)
881  {
882    $row = mysql_fetch_array($result);
883    $sentence = $lang['already_rated'];
884    $sentence.= ' ('.$row['rate'].'). ';
885    $sentence.= $lang['update_rate'];
886  }
887  else
888  {
889    $sentence = $lang['never_rated'].'. '.$lang['to_rate'];
890  }
891  $template->assign_block_vars(
892    'rate',
893    array('SENTENCE' => $sentence)
894    );
895 
896 
897  foreach ($rate_items as $num => $mark)
898  {
899    if ($num > 0)
900    {
901      $separator = '|';
902    }
903    else
904    {
905      $separator = '';
906    }
907
908    $url = PHPWG_ROOT_PATH.'picture.php';
909    $url.= get_query_string_diff(array('rate','add_fav'));
910    $url.= '&amp;rate='.$mark;
911   
912    $template->assign_block_vars(
913      'rate.rate_option',
914      array(
915        'OPTION' => $mark,
916        'URL' => $url,
917        'SEPARATOR' => $separator
918        ));
919  }
920}
921
922//---------------------------------------------------- users's comments display
923if ( $conf['show_comments'] )
924{
925  // number of comment for this picture
926  $query = 'SELECT COUNT(*) AS nb_comments';
927  $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id'];
928  $query.= " AND validated = 'true'";
929  $query.= ';';
930  $row = mysql_fetch_array( pwg_query( $query ) );
931 
932  // navigation bar creation
933  $url = PHPWG_ROOT_PATH.'picture.php';
934  $url.= get_query_string_diff(array('rate','add_fav'));
935
936  if (!isset( $_GET['start'] )
937      or !is_numeric( $_GET['start'] )
938      or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) )
939  {
940    $page['start'] = 0;
941  }
942  else
943  {
944    $page['start'] = $_GET['start'];
945  }
946  $page['navigation_bar'] = create_navigation_bar( $url, $row['nb_comments'],
947                                                   $page['start'],
948                                                   $conf['nb_comment_page'],
949                                                   '' );
950  $template->assign_block_vars('comments', array(
951    'NB_COMMENT'=>$row['nb_comments'],
952    'NAV_BAR'=>$page['navigation_bar']));
953
954  $query = 'SELECT id,author,date,image_id,content';
955  $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id'];
956  $query.= " AND validated = 'true'";
957  $query.= ' ORDER BY date ASC';
958  $query.= ' LIMIT '.$page['start'].', '.$conf['nb_comment_page'].';';
959  $result = pwg_query( $query );
960               
961  while ( $row = mysql_fetch_array( $result ) )
962  {
963    $template->assign_block_vars(
964      'comments.comment',
965      array(
966        'COMMENT_AUTHOR'=>empty($row['author'])?$lang['guest']:$row['author'],
967        'COMMENT_DATE'=>format_date($row['date'], 'mysql_datetime', true),
968        'COMMENT'=>parse_comment_content($row['content'])
969        ));
970       
971    if ( $user['status'] == 'admin' )
972    {
973      $template->assign_block_vars(
974        'comments.comment.delete',
975        array('U_COMMENT_DELETE'=>add_session_id( $url.'&amp;del='.$row['id'])
976          ));
977    }
978  }
979
980  if (!$user['is_the_guest']
981      or ($user['is_the_guest'] and $conf['comments_forall']))
982  {
983    $template->assign_block_vars('comments.add_comment', array());
984    // display author field if the user is not logged in
985    if (!$user['is_the_guest'])
986    {
987      $template->assign_block_vars(
988        'comments.add_comment.author_known',
989        array('KNOWN_AUTHOR'=>$user['username'])
990        );
991    }
992    else
993    {
994      $template->assign_block_vars(
995        'comments.add_comment.author_field', array()
996        );
997    }
998  }
999}
1000//------------------------------------------------------------ log informations
1001pwg_log( 'picture', $title_img, $picture['current']['file'] );
1002mysql_close();
1003
1004$template->pparse('picture');
1005include(PHPWG_ROOT_PATH.'include/page_tail.php');
1006?>
Note: See TracBrowser for help on using the repository browser.