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

Last change on this file since 989 was 989, checked in by plg, 18 years ago

bug 247 fixed : image_id GET parameter was not checked for sanity before
usage in SQL queries. Now, image_id must be a numeric value.

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