source: branches/branch-1_5/picture.php @ 947

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