source: trunk/picture.php @ 985

Last change on this file since 985 was 985, checked in by chrisaga, 18 years ago
  • feature 232 : icon tool to download big image in pwg_high if exists
  • cosmetic : adjust big image popup to avoid unwanted scrolbars

no toolbar or status-bar in this popup

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