source: trunk/picture.php @ 774

Last change on this file since 774 was 774, checked in by gweltas, 19 years ago

Bug 0000100: 'info_line' template code splited

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