source: trunk/picture.php @ 642

Last change on this file since 642 was 642, checked in by plg, 19 years ago
  • in admin menu, status option for categories is not "permissions" but "private or public" choice = different language item
  • get_cat_display_name changed : use $conflevel_separator to unify presentation
  • default values for category properties commentable, uploadable, status and visible (set in include/config.inc.php) used for category creation (admin/update, admin/remote_site, admin/cat_list)
  • use mass_inserts in admin/update for inserting new categories
  • only one query for counting the number of sub categories in admin/cat_list
  • 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-2004 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-12-12 21:06:39 +0000 (Sun, 12 Dec 2004) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 642 $
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 DISTINCT(i.id), i.*
100  FROM '.IMAGES_TABLE.' AS i
101    INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON i.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  $cat_directory = dirname($row['path']);
146  $file_wo_ext = get_filename_wo_extension($row['file']);
147
148  $icon = './template/'.$user['template'].'/mimetypes/';
149  $icon.= strtolower(get_extension($row['file'])).'.png';
150
151  if (isset($row['representative_ext']) and $row['representative_ext'] =! '')
152  {
153    $picture[$i]['src'] = $cat_directory.'/pwg_representative/';
154    $picture[$i]['src'].= $file_wo_ext.'.'.$row['representative_ext'];
155  }
156  else
157  {
158    $picture[$i]['src'] = $icon;
159  }
160  // special case for picture files
161  if ($picture[$i]['is_picture'])
162  {
163    $picture[$i]['src'] = $row['path'];
164    // if we are working on the "current" element, we search if there is a
165    // high quality picture
166    // FIXME : with remote pictures, this "remote fopen" takes long...
167    if ($i == 'current')
168    {
169      if (@fopen($cat_directory.'/pwg_high/'.$row['file'], 'r'))
170      {
171        $picture[$i]['high'] = $cat_directory.'/pwg_high/'.$row['file'];
172      }
173    }
174  }
175
176  // if picture is not a file, we need the download link
177  if (!$picture[$i]['is_picture'])
178  {
179    $picture[$i]['download'] = $row['path'];
180  }
181
182  $picture[$i]['thumbnail'] = get_thumbnail_src($row['path'], @$row['tn_ext']);
183 
184  if ( !empty( $row['name'] ) )
185  {
186    $picture[$i]['name'] = $row['name'];
187  }
188  else
189  {
190    $picture[$i]['name'] = str_replace('_', ' ', $file_wo_ext);
191  }
192
193  $picture[$i]['url'] = PHPWG_ROOT_PATH.'picture.php';
194  $picture[$i]['url'].= get_query_string_diff(array('image_id','add_fav',
195                                                    'slideshow','rate'));
196  $picture[$i]['url'].= '&amp;image_id='.$row['id'];
197}
198
199$url_up = PHPWG_ROOT_PATH.'category.php?cat='.$page['cat'].'&amp;';
200$url_up.= 'num='.$page['num']; 
201if ( $page['cat'] == 'search' )
202{
203  $url_up.= "&amp;search=".$_GET['search'];
204}
205if ( $page['cat'] == 'list' )
206{
207  $url_up.= "&amp;list=".$_GET['list'];
208}
209
210$url_admin = PHPWG_ROOT_PATH.'admin.php?page=picture_modify';
211$url_admin.= '&amp;cat_id='.$page['cat'];
212$url_admin.= '&amp;image_id='.$_GET['image_id'];
213
214$url_slide = $picture['current']['url'];
215$url_slide.= '&amp;slideshow='.$conf['slideshow_period'];
216//----------------------------------------------------------- rate registration
217if (isset($_GET['rate'])
218    and $conf['rate']
219    and !$user['is_the_guest']
220    and in_array($_GET['rate'], $rate_items))
221{
222  $query = '
223DELETE
224  FROM '.RATE_TABLE.'
225  WHERE user_id = '.$user['id'].'
226    AND element_id = '.$_GET['image_id'].'
227;';
228  pwg_query($query);
229  $query = '
230INSERT INTO '.RATE_TABLE.'
231  (user_id,element_id,rate)
232  VALUES
233  ('.$user['id'].','.$_GET['image_id'].','.$_GET['rate'].')
234;';
235  pwg_query($query);
236
237  // update of images.average_rate field
238  $query = '
239SELECT ROUND(AVG(rate),2) AS average_rate
240  FROM '.RATE_TABLE.'
241  WHERE element_id = '.$_GET['image_id'].'
242;';
243  $row = mysql_fetch_array(pwg_query($query));
244  $query = '
245UPDATE '.IMAGES_TABLE.'
246  SET average_rate = '.$row['average_rate'].'
247  WHERE id = '.$_GET['image_id'].'
248;';
249  pwg_query($query);
250}
251//--------------------------------------------------------- favorite management
252if ( isset( $_GET['add_fav'] ) )
253{
254  $query = 'DELETE FROM '.FAVORITES_TABLE;
255  $query.= ' WHERE user_id = '.$user['id'];
256  $query.= ' AND image_id = '.$picture['current']['id'];
257  $query.= ';';
258  $result = pwg_query( $query );
259 
260  if ( $_GET['add_fav'] == 1 )
261  {
262    $query = 'INSERT INTO '.FAVORITES_TABLE;
263    $query.= ' (image_id,user_id) VALUES';
264    $query.= ' ('.$picture['current']['id'].','.$user['id'].')';
265    $query.= ';';
266    $result = pwg_query( $query );
267  }
268  if ( !$_GET['add_fav'] and $page['cat'] == 'fav' )
269  {
270    if (!$has_prev and $mysql_num_rows == 1)
271    {
272      // there is no favorite picture anymore we redirect the user to the
273      // category page
274      $url = add_session_id($url_up);
275      redirect($url);
276    }
277    else if (!$has_prev)
278    {
279      $url = str_replace( '&amp;', '&', $picture['next']['url'] );
280      $url = add_session_id( $url, true);
281    }
282    else
283    {
284      $url = str_replace('&amp;', '&', $picture['prev']['url'] );
285      $url = add_session_id( $url, true);
286    }
287    redirect( $url );
288  }
289}
290
291//------------------------------------------------------  comment registeration
292if ( isset( $_POST['content'] ) && !empty($_POST['content']) )
293{
294  $register_comment = true;
295  $author = !empty($_POST['author'])?$_POST['author']:$lang['guest'];
296  // if a guest try to use the name of an already existing user, he must be
297  // rejected
298  if ( $author != $user['username'] )
299  {
300    $query = 'SELECT COUNT(*) AS user_exists';
301    $query.= ' FROM '.USERS_TABLE;
302    $query.= " WHERE username = '".$author."'";
303    $query.= ';';
304    $row = mysql_fetch_array( pwg_query( $query ) );
305    if ( $row['user_exists'] == 1 )
306    {
307      $template->assign_block_vars(
308        'information',
309        array('INFORMATION'=>$lang['comment_user_exists']));
310      $register_comment = false;
311    }
312  }
313 
314  if ( $register_comment )
315  {
316    // anti-flood system
317    $reference_date = time() - $conf['anti-flood_time'];
318    $query = 'SELECT id FROM '.COMMENTS_TABLE;
319    $query.= ' WHERE date > FROM_UNIXTIME('.$reference_date.')';
320    $query.= " AND author = '".$author."'";
321    $query.= ';';
322    if ( mysql_num_rows( pwg_query( $query ) ) == 0
323         or $conf['anti-flood_time'] == 0 )
324    {
325      $query = 'INSERT INTO '.COMMENTS_TABLE;
326      $query.= ' (author,date,image_id,content,validated) VALUES (';
327      $query.= "'".$author."'";
328      $query.= ',NOW(),'.$_GET['image_id'];
329      $query.= ",'".htmlspecialchars( $_POST['content'], ENT_QUOTES)."'";
330      if ( !$conf['comments_validation'] or $user['status'] == 'admin' )
331      {       
332        $query.= ",'true'";
333      }
334      else
335      {
336        $query.= ",'false'";
337      }
338      $query.= ');';
339      pwg_query( $query );
340      // information message
341      $message = $lang['comment_added'];
342      if ( $conf['comments_validation'] and $user['status'] != 'admin' )
343      {
344        $message.= '<br />'.$lang['comment_to_validate'];
345      }
346      $template->assign_block_vars('information',
347                                   array('INFORMATION'=>$message));
348      // notification to the administrators
349      if ( $conf['mail_notification'] )
350      {
351        // locally, we change the $conf['level_separator']
352        $conf_separator = $conf['level_separator'];
353        $conf['level_separator'] = ' > ';
354        $cat_name = get_cat_display_name($page['cat_name'], '');
355        $conf['level_separator'] = $conf_separator;
356       
357        $cat_name = strip_tags( $cat_name );
358        notify( 'comment', $cat_name.' > '.$picture['current']['name']);
359      }
360    }
361    else
362    {
363      // information message
364      $template->assign_block_vars(
365        'information',
366        array('INFORMATION'=>$lang['comment_anti-flood']));
367    }
368  }
369}
370// comment deletion
371if ( isset( $_GET['del'] )
372     and is_numeric( $_GET['del'] )
373     and $user['status'] == 'admin' )
374{
375  $query = 'DELETE FROM '.COMMENTS_TABLE;
376  $query.= ' WHERE id = '.$_GET['del'];
377  $query.= ';';
378  pwg_query( $query );
379}
380
381//
382// Start output of page
383//
384
385$title =  $picture['current']['name'];
386$refresh = 0;
387if ( isset( $_GET['slideshow'] ) and $has_next )
388{
389  $refresh= $_GET['slideshow'];
390  $url_link = $picture['next']['url'].'&amp;slideshow='.$refresh;
391}
392
393$title_img = $picture['current']['name'];
394$title_nb = '';
395if (is_numeric( $page['cat'] )) 
396{
397  $title_img = replace_space(get_cat_display_name($page['cat_name']));
398  $n = $page['num'] + 1;
399  $title_nb = $n.'/'.$page['cat_nb_images'];
400}
401else if ( $page['cat'] == 'search' )
402{
403  $title_img = replace_search( $title_img, $_GET['search'] );
404}
405
406// calculation of width and height
407if (empty($picture['current']['width']))
408{
409  $taille_image = @getimagesize($picture['current']['src']);
410  $original_width = $taille_image[0];
411  $original_height = $taille_image[1];
412}
413else
414{
415  $original_width = $picture['current']['width'];
416  $original_height = $picture['current']['height'];
417}
418
419$picture_size = get_picture_size( $original_width, $original_height,
420                                  $user['maxwidth'], $user['maxheight'] );
421
422// metadata
423if ($conf['show_exif'] or $conf['show_iptc'])
424{
425  $metadata_showable = true;
426}
427else
428{
429  $metadata_showable = false;
430}
431
432$url_metadata = PHPWG_ROOT_PATH.'picture.php';
433$url_metadata .=  get_query_string_diff(array('add_fav', 'slideshow', 'show_metadata'));
434if ($metadata_showable and !isset($_GET['show_metadata']))
435{
436  $url_metadata.= '&amp;show_metadata=1';
437}
438                                 
439include(PHPWG_ROOT_PATH.'include/page_header.php');
440$template->set_filenames(array('picture'=>'picture.tpl'));
441
442$template->assign_vars(array(
443  'CATEGORY' => $title_img,
444  'PHOTO' => $title_nb,
445  'TITLE' => $picture['current']['name'],
446  'SRC_IMG' => $picture['current']['src'],
447  'ALT_IMG' => $picture['current']['file'],
448  'WIDTH_IMG' => $picture_size[0],
449  'HEIGHT_IMG' => $picture_size[1],
450
451  'LEVEL_SEPARATOR' => $conf['level_separator'],
452
453  'L_HOME' => $lang['home'],
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['home_hint'],
470  'L_UP_ALT' => $lang['home'],
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,uppercats,commentable,global_rank
749  FROM '.IMAGE_CATEGORY_TABLE.'
750    INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id
751  WHERE image_id = '.$_GET['image_id'];
752if ($user['forbidden_categories'] != '')
753{
754  $query.= '
755    AND category_id NOT IN ('.$user['forbidden_categories'].')';
756}
757$query.= '
758;';
759$result = pwg_query($query);
760$cat_array = array();
761while ($row = mysql_fetch_array($result))
762{
763  array_push($cat_array, $row);
764}
765usort($cat_array, 'global_rank_compare');
766
767$cat_output = '';
768$page['show_comments'] = false;
769foreach ($cat_array as $category)
770{
771  if ($cat_output != '')
772  {
773    $cat_output.= '<br />';
774  }
775 
776  if (count($cat_array) > 3)
777  {
778    $cat_output .= get_cat_display_name_cache($category['uppercats']);
779  }
780  else
781  {
782    $cat_info = get_cat_info($category['category_id']);
783    $cat_output .= get_cat_display_name($cat_info['name']);
784  }
785  // the picture is commentable if it belongs at least to one category which
786  // is commentable
787  if ($category['commentable'])
788  {
789    $page['show_comments'] = true;
790  }
791}
792$template->assign_block_vars(
793  'info_line',
794  array(
795    'INFO'  => $lang['categories'],
796    'VALUE' => $cat_output
797    ));
798// metadata
799if ($metadata_showable and isset($_GET['show_metadata']))
800{
801  include_once(PHPWG_ROOT_PATH.'/include/functions_metadata.inc.php');
802  $template->assign_block_vars('metadata', array());
803  if ($conf['show_exif'])
804  {
805    if ($exif = @read_exif_data($picture['current']['src']))
806    {
807      $template->assign_block_vars(
808        'metadata.headline',
809        array('TITLE' => 'EXIF Metadata')
810        );
811
812      foreach ($conf['show_exif_fields'] as $field)
813      {
814        if (strpos($field, ';') === false)
815        {
816          if (isset($exif[$field]))
817          {
818            $key = $field;
819            if (isset($lang['exif_field_'.$field]))
820            {
821              $key = $lang['exif_field_'.$field];
822            }
823           
824            $template->assign_block_vars(
825              'metadata.line',
826              array(
827                'KEY' => $key,
828                'VALUE' => $exif[$field]
829                )
830              );
831          }
832        }
833        else
834        {
835          $tokens = explode(';', $field);
836          if (isset($exif[$tokens[0]][$tokens[1]]))
837          {
838            $key = $tokens[1];
839            if (isset($lang['exif_field_'.$tokens[1]]))
840            {
841              $key = $lang['exif_field_'.$tokens[1]];
842            }
843           
844            $template->assign_block_vars(
845              'metadata.line',
846              array(
847                'KEY' => $key,
848                'VALUE' => $exif[$tokens[0]][$tokens[1]]
849                )
850              );
851          }
852        }
853      }
854    }
855  }
856  if ($conf['show_iptc'])
857  {
858    $iptc = get_iptc_data($picture['current']['src'],
859                          $conf['show_iptc_mapping']);
860
861    if (count($iptc) > 0)
862    {
863      $template->assign_block_vars(
864        'metadata.headline',
865        array('TITLE' => 'IPTC Metadata')
866        );
867    }
868   
869    foreach ($iptc as $field => $value)
870    {
871      $key = $field;
872      if (isset($lang[$field]))
873      {
874        $key = $lang[$field];
875      }
876     
877      $template->assign_block_vars(
878        'metadata.line',
879        array(
880          'KEY' => $key,
881          'VALUE' => $value
882          )
883        );
884    }
885  }
886}
887//slideshow end
888if ( isset( $_GET['slideshow'] ) )
889{
890  if ( !is_numeric( $_GET['slideshow'] ) ) $_GET['slideshow'] = $conf['slideshow_period'];
891       
892  $template->assign_block_vars('stop_slideshow', array(
893  'U_SLIDESHOW'=>add_session_id( $picture['current']['url'] )
894  ));
895}
896
897//------------------------------------------------------------------- rate form
898if ($conf['rate'])
899{
900  $query = '
901SELECT rate
902  FROM '.RATE_TABLE.'
903  WHERE user_id = '.$user['id'].'
904    AND element_id = '.$_GET['image_id'].'
905;';
906  $result = pwg_query($query);
907  if (mysql_num_rows($result) > 0)
908  {
909    $row = mysql_fetch_array($result);
910    $sentence = $lang['already_rated'];
911    $sentence.= ' ('.$row['rate'].'). ';
912    $sentence.= $lang['update_rate'];
913  }
914  else
915  {
916    $sentence = $lang['never_rated'].'. '.$lang['to_rate'];
917  }
918  $template->assign_block_vars(
919    'rate',
920    array('SENTENCE' => $sentence)
921    );
922 
923 
924  foreach ($rate_items as $num => $mark)
925  {
926    if ($num > 0)
927    {
928      $separator = '|';
929    }
930    else
931    {
932      $separator = '';
933    }
934
935    $url = PHPWG_ROOT_PATH.'picture.php';
936    $url.= get_query_string_diff(array('rate','add_fav'));
937    $url.= '&amp;rate='.$mark;
938   
939    $template->assign_block_vars(
940      'rate.rate_option',
941      array(
942        'OPTION' => $mark,
943        'URL' => $url,
944        'SEPARATOR' => $separator
945        ));
946  }
947}
948
949//---------------------------------------------------- users's comments display
950if ($page['show_comments'])
951{
952  // number of comment for this picture
953  $query = 'SELECT COUNT(*) AS nb_comments';
954  $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id'];
955  $query.= " AND validated = 'true'";
956  $query.= ';';
957  $row = mysql_fetch_array( pwg_query( $query ) );
958 
959  // navigation bar creation
960  $url = PHPWG_ROOT_PATH.'picture.php';
961  $url.= get_query_string_diff(array('rate','add_fav'));
962
963  if (!isset( $_GET['start'] )
964      or !is_numeric( $_GET['start'] )
965      or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) )
966  {
967    $page['start'] = 0;
968  }
969  else
970  {
971    $page['start'] = $_GET['start'];
972  }
973  $page['navigation_bar'] = create_navigation_bar( $url, $row['nb_comments'],
974                                                   $page['start'],
975                                                   $conf['nb_comment_page'],
976                                                   '' );
977  $template->assign_block_vars('comments', array(
978    'NB_COMMENT'=>$row['nb_comments'],
979    'NAV_BAR'=>$page['navigation_bar']));
980
981  $query = 'SELECT id,author,date,image_id,content';
982  $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id'];
983  $query.= " AND validated = 'true'";
984  $query.= ' ORDER BY date ASC';
985  $query.= ' LIMIT '.$page['start'].', '.$conf['nb_comment_page'].';';
986  $result = pwg_query( $query );
987               
988  while ( $row = mysql_fetch_array( $result ) )
989  {
990    $template->assign_block_vars(
991      'comments.comment',
992      array(
993        'COMMENT_AUTHOR'=>empty($row['author'])?$lang['guest']:$row['author'],
994        'COMMENT_DATE'=>format_date($row['date'], 'mysql_datetime', true),
995        'COMMENT'=>parse_comment_content($row['content'])
996        ));
997       
998    if ( $user['status'] == 'admin' )
999    {
1000      $template->assign_block_vars(
1001        'comments.comment.delete',
1002        array('U_COMMENT_DELETE'=>add_session_id( $url.'&amp;del='.$row['id'])
1003          ));
1004    }
1005  }
1006
1007  if (!$user['is_the_guest']
1008      or ($user['is_the_guest'] and $conf['comments_forall']))
1009  {
1010    $template->assign_block_vars('comments.add_comment', array());
1011    // display author field if the user is not logged in
1012    if (!$user['is_the_guest'])
1013    {
1014      $template->assign_block_vars(
1015        'comments.add_comment.author_known',
1016        array('KNOWN_AUTHOR'=>$user['username'])
1017        );
1018    }
1019    else
1020    {
1021      $template->assign_block_vars(
1022        'comments.add_comment.author_field', array()
1023        );
1024    }
1025  }
1026}
1027//------------------------------------------------------------ log informations
1028pwg_log( 'picture', $title_img, $picture['current']['file'] );
1029mysql_close();
1030
1031$template->pparse('picture');
1032include(PHPWG_ROOT_PATH.'include/page_tail.php');
1033?>
Note: See TracBrowser for help on using the repository browser.