source: trunk/picture.php @ 858

Last change on this file since 858 was 858, checked in by plg, 19 years ago
  • modification : less configuration parameters in administration screen. These parameters are move to include/config_default.inc.php.
  • new : ability to add a single picture to caddie from picture.php
  • new : contextual help, only a few pages are available.
  • new : ability to delete users from admin/user_list
  • modification : reorganization of configuration file
  • new : configuration parameter use_exif_mapping
  • improvement : MOD hidemail added to standard
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 28.7 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2005-09-03 16:36:05 +0000 (Sat, 03 Sep 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 858 $
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 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_COMMENT' =>$lang['comment'],
511  'L_DOWNLOAD' => $lang['download'],
512  'L_DOWNLOAD_HINT' => $lang['download_hint'],
513  'L_PICTURE_METADATA' => $lang['picture_show_metadata'],
514  'L_PICTURE_HIGH' => $lang['picture_high'],
515  'L_UP_HINT' => $lang['home_hint'],
516  'L_UP_ALT' => $lang['home'],
517 
518  'U_HOME' => add_session_id(PHPWG_ROOT_PATH.'category.php'),
519  'U_UP' => add_session_id($url_up),
520  'U_METADATA' => add_session_id($url_metadata),
521  'U_ADMIN' => add_session_id($url_admin),
522  'U_SLIDESHOW'=> add_session_id($url_slide),
523  'U_ADD_COMMENT' => add_session_id(str_replace( '&', '&amp;', $_SERVER['REQUEST_URI'] ))
524  )
525);
526
527if ($conf['show_picture_name_on_title'])
528{
529  $template->assign_block_vars('title', array());
530}
531
532//------------------------------------------------------- upper menu management
533// download link if file is not a picture
534if (!$picture['current']['is_picture'])
535{
536  $template->assign_block_vars(
537    'download',
538    array('U_DOWNLOAD' => $picture['current']['download']));
539}
540else
541{
542  $template->assign_block_vars(
543    'ecard',
544    array('U_ECARD' => $picture['current']['url']));
545}
546// display a high quality link if present
547if (isset($picture['current']['high']))
548{
549  $full_size = @getimagesize($picture['current']['high']);
550  $full_width = $full_size[0];
551  $full_height = $full_size[1];
552  $uuid = uniqid(rand());
553  $template->assign_block_vars('high', array(
554    'U_HIGH' => $picture['current']['high'],
555        'UUID'=>$uuid,
556        'WIDTH_IMG'=>($full_width + 16),
557        'HEIGHT_IMG'=>($full_height + 16)
558        ));
559}
560// button to set the current picture as representative
561if ('admin' == $user['status'] and is_numeric($page['cat']))
562{
563  $template->assign_block_vars(
564    'representative',
565    array(
566      'URL' =>
567        PHPWG_ROOT_PATH.'picture.php'
568        .get_query_string_diff(array())
569        .'&amp;representative=1'
570      )
571    );
572}
573
574if ('admin' == $user['status'])
575{
576  $template->assign_block_vars(
577    'caddie',
578    array(
579      'URL' =>
580      add_session_id(
581        PHPWG_ROOT_PATH.'picture.php'
582        .get_query_string_diff(array('caddie')).'&amp;caddie=1')
583      )
584    );
585}
586
587//------------------------------------------------------- favorite manipulation
588if ( !$user['is_the_guest'] )
589{
590  // verify if the picture is already in the favorite of the user
591  $query = 'SELECT COUNT(*) AS nb_fav';
592  $query.= ' FROM '.FAVORITES_TABLE.' WHERE image_id = '.$_GET['image_id'];
593  $query.= ' AND user_id = '.$user['id'].';';
594  $result = pwg_query( $query );
595  $row = mysql_fetch_array( $result );
596  if (!$row['nb_fav'])
597  {
598    $url = PHPWG_ROOT_PATH.'picture.php';
599    $url.= get_query_string_diff(array('rate','add_fav'));
600    $url.= '&amp;add_fav=1';
601
602    $template->assign_block_vars(
603      'favorite',
604      array(
605        'FAVORITE_IMG' => PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/favorite.gif',
606        'FAVORITE_HINT' =>$lang['add_favorites_hint'],
607        'FAVORITE_ALT' =>$lang['add_favorites_alt'],
608        'U_FAVORITE' => $url
609        ));
610  }
611  else
612  {
613    $url = PHPWG_ROOT_PATH.'picture.php';
614    $url.= get_query_string_diff(array('rate','add_fav'));
615    $url.= '&amp;add_fav=0';
616   
617    $template->assign_block_vars(
618      'favorite',
619      array(
620        'FAVORITE_IMG' => PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/del_favorite.gif',
621        'FAVORITE_HINT' =>$lang['del_favorites_hint'],
622        'FAVORITE_ALT' =>$lang['del_favorites_alt'],
623        'U_FAVORITE'=> $url
624        ));
625  }
626}
627//------------------------------------ admin link for information modifications
628if ( $user['status'] == 'admin' )
629{
630  $template->assign_block_vars('admin', array());
631}
632
633//-------------------------------------------------------- navigation management
634if ($has_prev)
635{
636  $template->assign_block_vars(
637    'previous',
638    array(
639      'TITLE_IMG' => $picture['prev']['name'],
640      'IMG' => $picture['prev']['thumbnail'],
641      'U_IMG' => add_session_id($picture['prev']['url'])
642      ));
643}
644
645if ($has_next)
646{
647  $template->assign_block_vars(
648    'next',
649    array(
650      'TITLE_IMG' => $picture['next']['name'],
651      'IMG' => $picture['next']['thumbnail'],
652      'U_IMG' => add_session_id($picture['next']['url'])
653      ));
654}
655
656//--------------------------------------------------------- picture information
657// legend
658if (isset($picture['current']['comment'])
659    and !empty($picture['current']['comment']))
660{
661  $template->assign_block_vars(
662    'legend',
663    array(
664      'COMMENT_IMG' => nl2br($picture['current']['comment'])
665      ));
666}
667
668$infos = array();
669
670// author
671if (!empty($picture['current']['author']))
672{
673  $infos['INFO_AUTHOR'] =
674    '<a href="'.
675    add_session_id(
676      PHPWG_ROOT_PATH.'category.php?cat=search'.
677      '&amp;search=author:'.$picture['current']['author']
678      ).
679    '">'.$picture['current']['author'].'</a>';
680}
681else
682{
683  $infos['INFO_AUTHOR'] = l10n('N/A');
684}
685
686// creation date
687if (!empty($picture['current']['date_creation']))
688{
689  $infos['INFO_CREATION_DATE'] =
690    '<a href="'.
691    add_session_id(
692      PHPWG_ROOT_PATH.'category.php?cat=search'.
693      '&amp;search=date_creation:'.$picture['current']['date_creation']
694      ).
695    '">'.format_date($picture['current']['date_creation']).'</a>';
696}
697else
698{
699  $infos['INFO_CREATION_DATE'] = l10n('N/A');
700}
701
702// date of availability
703$infos['INFO_AVAILABILITY_DATE'] =
704  '<a href="'.
705  add_session_id(
706    PHPWG_ROOT_PATH.'category.php?cat=search'.
707    '&amp;search=date_available:'.
708    substr($picture['current']['date_available'], 0, 10)
709    ).
710    '">'.
711  format_date($picture['current']['date_available'], 'mysql_datetime').
712  '</a>';
713
714// size in pixels
715if ($picture['current']['is_picture'])
716{
717  if ($original_width != $picture_size[0]
718      or $original_height != $picture_size[1])
719  {
720    $infos['INFO_DIMENSIONS'] =
721      '<a href="'.$picture['current']['src'].'" title="'.
722      l10n('Original dimensions').'">'.
723      $original_width.'*'.$original_height.'</a>';
724  }
725  else
726  {
727    $infos['INFO_DIMENSIONS'] = $original_width.'*'.$original_height;
728  }
729}
730else
731{
732  $infos['INFO_DIMENSIONS'] = l10n('N/A');
733}
734
735// filesize
736if (!empty($picture['current']['filesize']))
737{
738  $infos['INFO_FILESIZE'] =
739    sprintf(l10n('%d Kb'), $picture['current']['filesize']);
740}
741else
742{
743  $infos['INFO_FILESIZE'] = l10n('N/A');
744}
745
746// number of visits
747$infos['INFO_VISITS'] = $picture['current']['hit'];
748
749// file
750$infos['INFO_FILE'] = $picture['current']['file'];
751
752// keywords
753if (!empty($picture['current']['keywords']))
754{
755  $infos['INFO_KEYWORDS'] =
756    preg_replace(
757      '/([^,]+)/',
758      '<a href="'.
759      add_session_id(
760        PHPWG_ROOT_PATH.'category.php?cat=search&amp;search=keywords:$1'
761        ).
762      '">$1</a>',
763      $picture['current']['keywords']
764      );
765}
766else
767{
768  $infos['INFO_KEYWORDS'] = l10n('N/A');
769}
770
771$template->assign_vars($infos);
772
773// related categories
774foreach ($related_categories as $category)
775{
776  $template->assign_block_vars(
777    'category',
778    array(
779      'LINE' => count($related_categories) > 3
780        ? get_cat_display_name_cache($category['uppercats'])
781        : get_cat_display_name_from_id($category['category_id'])
782      )
783    );
784}
785
786//-------------------------------------------------------------------  metadata
787if ($metadata_showable and isset($_GET['show_metadata']))
788{
789  include_once(PHPWG_ROOT_PATH.'/include/functions_metadata.inc.php');
790  $template->assign_block_vars('metadata', array());
791  if ($conf['show_exif'])
792  {
793    if (!function_exists('read_exif_data'))
794    {
795      die('Exif extension not available, admin should disable exif display');
796    }
797   
798    if ($exif = @read_exif_data($picture['current']['src']))
799    {
800      $template->assign_block_vars(
801        'metadata.headline',
802        array('TITLE' => 'EXIF Metadata')
803        );
804
805      foreach ($conf['show_exif_fields'] as $field)
806      {
807        if (strpos($field, ';') === false)
808        {
809          if (isset($exif[$field]))
810          {
811            $key = $field;
812            if (isset($lang['exif_field_'.$field]))
813            {
814              $key = $lang['exif_field_'.$field];
815            }
816           
817            $template->assign_block_vars(
818              'metadata.line',
819              array(
820                'KEY' => $key,
821                'VALUE' => $exif[$field]
822                )
823              );
824          }
825        }
826        else
827        {
828          $tokens = explode(';', $field);
829          if (isset($exif[$tokens[0]][$tokens[1]]))
830          {
831            $key = $tokens[1];
832            if (isset($lang['exif_field_'.$tokens[1]]))
833            {
834              $key = $lang['exif_field_'.$tokens[1]];
835            }
836           
837            $template->assign_block_vars(
838              'metadata.line',
839              array(
840                'KEY' => $key,
841                'VALUE' => $exif[$tokens[0]][$tokens[1]]
842                )
843              );
844          }
845        }
846      }
847    }
848  }
849  if ($conf['show_iptc'])
850  {
851    $iptc = get_iptc_data($picture['current']['src'],
852                          $conf['show_iptc_mapping']);
853
854    if (count($iptc) > 0)
855    {
856      $template->assign_block_vars(
857        'metadata.headline',
858        array('TITLE' => 'IPTC Metadata')
859        );
860    }
861   
862    foreach ($iptc as $field => $value)
863    {
864      $key = $field;
865      if (isset($lang[$field]))
866      {
867        $key = $lang[$field];
868      }
869     
870      $template->assign_block_vars(
871        'metadata.line',
872        array(
873          'KEY' => $key,
874          'VALUE' => $value
875          )
876        );
877    }
878  }
879}
880//slideshow end
881if ( isset( $_GET['slideshow'] ) )
882{
883  if ( !is_numeric( $_GET['slideshow'] ) ) $_GET['slideshow'] = $conf['slideshow_period'];
884       
885  $template->assign_block_vars('stop_slideshow', array(
886  'U_SLIDESHOW'=>add_session_id( $picture['current']['url'] )
887  ));
888}
889
890//------------------------------------------------------------------- rating
891if ($conf['rate'])
892{
893  $query = '
894SELECT COUNT(rate) AS count
895     , ROUND(AVG(rate),2) AS average
896     , ROUND(STD(rate),2) AS STD
897  FROM '.RATE_TABLE.'
898  WHERE element_id = '.$picture['current']['id'].'
899;';
900  $row = mysql_fetch_array(pwg_query($query));
901  if ($row['count'] == 0)
902  {
903    $value = $lang['no_rate'];
904  }
905  else
906  {
907    $value = sprintf(
908      l10n('%.2f (rated %d times, standard deviation = %.2f)'),
909      $row['average'],
910      $row['count'],
911      $row['STD']
912      );
913  }
914 
915  if (!$user['is_the_guest'])
916  {
917    $query = 'SELECT rate
918    FROM '.RATE_TABLE.'
919    WHERE user_id = '.$user['id'].'
920    AND element_id = '.$_GET['image_id'].';';
921  $result = pwg_query($query);
922  if (mysql_num_rows($result) > 0)
923  {
924    $row = mysql_fetch_array($result);
925    $sentence = $lang['already_rated'];
926    $sentence.= ' ('.$row['rate'].'). ';
927    $sentence.= $lang['update_rate'];
928  }
929  else
930  {
931    $sentence = $lang['never_rated'].'. '.$lang['to_rate'];
932  } 
933  $template->assign_block_vars(
934    'rate',
935    array(
936      'CONTENT' => $value,
937      'SENTENCE' => $sentence
938      ));
939
940  $template->assign_block_vars('info_rate', array('CONTENT' => $value));
941 
942  $template->assign_vars(
943    array(
944      'INFO_RATE' => $value
945      )
946    );
947 
948  foreach ($rate_items as $num => $mark)
949  {
950    if ($num > 0)
951    {
952      $separator = '|';
953    }
954    else
955    {
956      $separator = '';
957    }
958
959    $url = PHPWG_ROOT_PATH.'picture.php';
960    $url.= get_query_string_diff(array('rate','add_fav'));
961    $url.= '&amp;rate='.$mark;
962   
963    $template->assign_block_vars(
964      'rate.rate_option',
965      array(
966        'OPTION' => $mark,
967        'URL' => $url,
968        'SEPARATOR' => $separator
969        ));
970    }
971  }
972}
973
974//---------------------------------------------------- users's comments display
975
976// the picture is commentable if it belongs at least to one category which
977// is commentable
978$page['show_comments'] = false;
979foreach ($related_categories as $category)
980{
981  if ($category['commentable'] == 'true')
982  {
983    $page['show_comments'] = true;
984  }
985}
986
987if ($page['show_comments'])
988{
989  // number of comment for this picture
990  $query = 'SELECT COUNT(*) AS nb_comments';
991  $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id'];
992  $query.= " AND validated = 'true'";
993  $query.= ';';
994  $row = mysql_fetch_array( pwg_query( $query ) );
995 
996  // navigation bar creation
997  $url = PHPWG_ROOT_PATH.'picture.php';
998  $url.= get_query_string_diff(array('rate','add_fav'));
999
1000  if (!isset( $_GET['start'] )
1001      or !is_numeric( $_GET['start'] )
1002      or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) )
1003  {
1004    $page['start'] = 0;
1005  }
1006  else
1007  {
1008    $page['start'] = $_GET['start'];
1009  }
1010  $page['navigation_bar'] = create_navigation_bar( $url, $row['nb_comments'],
1011                                                   $page['start'],
1012                                                   $conf['nb_comment_page'],
1013                                                   '' );
1014  $template->assign_block_vars('comments', array(
1015    'NB_COMMENT'=>$row['nb_comments'],
1016    'NAV_BAR'=>$page['navigation_bar']));
1017
1018  $query = 'SELECT id,author,date,image_id,content';
1019  $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id'];
1020  $query.= " AND validated = 'true'";
1021  $query.= ' ORDER BY date ASC';
1022  $query.= ' LIMIT '.$page['start'].', '.$conf['nb_comment_page'].';';
1023  $result = pwg_query( $query );
1024               
1025  while ( $row = mysql_fetch_array( $result ) )
1026  {
1027    $template->assign_block_vars(
1028      'comments.comment',
1029      array(
1030        'COMMENT_AUTHOR'=>empty($row['author'])?$lang['guest']:$row['author'],
1031        'COMMENT_DATE'=>format_date($row['date'], 'mysql_datetime', true),
1032        'COMMENT'=>parse_comment_content($row['content'])
1033        ));
1034       
1035    if ( $user['status'] == 'admin' )
1036    {
1037      $template->assign_block_vars(
1038        'comments.comment.delete',
1039        array('U_COMMENT_DELETE'=>add_session_id( $url.'&amp;del='.$row['id'])
1040          ));
1041    }
1042  }
1043
1044  if (!$user['is_the_guest']
1045      or ($user['is_the_guest'] and $conf['comments_forall']))
1046  {
1047    $template->assign_block_vars('comments.add_comment', array());
1048    // display author field if the user is not logged in
1049    if (!$user['is_the_guest'])
1050    {
1051      $template->assign_block_vars(
1052        'comments.add_comment.author_known',
1053        array('KNOWN_AUTHOR'=>$user['username'])
1054        );
1055    }
1056    else
1057    {
1058      $template->assign_block_vars(
1059        'comments.add_comment.author_field', array()
1060        );
1061    }
1062  }
1063}
1064//------------------------------------------------------------ log informations
1065pwg_log( 'picture', $title_img, $picture['current']['file'] );
1066
1067$template->parse('picture');
1068include(PHPWG_ROOT_PATH.'include/page_tail.php');
1069?>
Note: See TracBrowser for help on using the repository browser.