source: trunk/picture.php @ 605

Last change on this file since 605 was 605, checked in by plg, 19 years ago

category random replaced by a more generic category : list. You give a list
of element identifiers and it creates a page virtual temporary
category. random.php generates a randomized list of element id visible to
the user (according to permissions) and redirects to category.php.

Major problem : elements order is in id ascending order, I don't know how to
change order when having id1,id2,id3 and id2,id3,id1 (the display order is
the same)

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