source: trunk/picture.php @ 902

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