source: trunk/picture.php @ 850

Last change on this file since 850 was 850, checked in by plg, 19 years ago
  • new : HTML BODY identifier to let CSS stylesheets manage specific behaviour.
  • deletion : admin/search useless
  • improvement : in admin/user_list, special behaviour for true/false fields (expand, show_comments)
  • new : gallery_title and gallery_description are displayed at the top of each page.
  • improvement : simplification in HTML for categories menu.
  • improvement : standardization of presentation in all public pages (identification, registration, search, profile, notification, comments, etc.)

(not in ChangeLog, below this line)

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