source: trunk/picture.php @ 607

Last change on this file since 607 was 607, checked in by gweltas, 19 years ago

Unification of "Return to main page" entry in the language files.

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