source: trunk/picture.php @ 745

Last change on this file since 745 was 745, checked in by plg, 19 years ago
  • bug fixed : there was no category name displayed in notification mails for new comment in special categories (other than numeric categories). Solution was to search related categories at the beginning of picture.php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 28.8 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-03-12 10:27:43 +0000 (Sat, 12 Mar 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 745 $
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                                 
463include(PHPWG_ROOT_PATH.'include/page_header.php');
464$template->set_filenames(array('picture'=>'picture.tpl'));
465
466$template->assign_vars(array(
467  'CATEGORY' => $title_img,
468  'PHOTO' => $title_nb,
469  'TITLE' => $picture['current']['name'],
470  'SRC_IMG' => $picture['current']['src'],
471  'ALT_IMG' => $picture['current']['file'],
472  'WIDTH_IMG' => $picture_size[0],
473  'HEIGHT_IMG' => $picture_size[1],
474
475  'LEVEL_SEPARATOR' => $conf['level_separator'],
476
477  'L_HOME' => $lang['home'],
478  'L_SLIDESHOW' => $lang['slideshow'],
479  'L_STOP_SLIDESHOW' => $lang['slideshow_stop'],
480  'L_PREV_IMG' =>$lang['previous_page'].' : ',
481  'L_NEXT_IMG' =>$lang['next_page'].' : ',
482  'L_ADMIN' =>$lang['link_info_image'],
483  'L_COMMENT_TITLE' =>$lang['comments_title'],
484  'L_ADD_COMMENT' =>$lang['comments_add'],
485  'L_DELETE_COMMENT' =>$lang['comments_del'],
486  'L_DELETE' =>$lang['delete'],
487  'L_SUBMIT' =>$lang['submit'],
488  'L_AUTHOR' =>$lang['author'],
489  'L_COMMENT' =>$lang['comment'],
490  'L_DOWNLOAD' => $lang['download'],
491  'L_DOWNLOAD_HINT' => $lang['download_hint'],
492  'L_PICTURE_METADATA' => $lang['picture_show_metadata'],
493  'L_PICTURE_HIGH' => $lang['picture_high'],
494  'L_UP_HINT' => $lang['home_hint'],
495  'L_UP_ALT' => $lang['home'],
496 
497  'U_HOME' => add_session_id(PHPWG_ROOT_PATH.'category.php'),
498  'U_UP' => add_session_id($url_up),
499  'U_METADATA' => add_session_id($url_metadata),
500  'U_ADMIN' => add_session_id($url_admin),
501  'U_SLIDESHOW'=> add_session_id($url_slide),
502  'U_ADD_COMMENT' => add_session_id(str_replace( '&', '&amp;', $_SERVER['REQUEST_URI'] ))
503  )
504);
505//------------------------------------------------------- upper menu management
506// download link if file is not a picture
507if (!$picture['current']['is_picture'])
508{
509  $template->assign_block_vars(
510    'download',
511    array('U_DOWNLOAD' => $picture['current']['download']));
512}
513else
514{
515  $template->assign_block_vars(
516    'ecard',
517    array('U_ECARD' => $picture['current']['url']));
518}
519// display a high quality link if present
520if (isset($picture['current']['high']))
521{
522  $full_size = @getimagesize($picture['current']['high']);
523  $full_width = $full_size[0];
524  $full_height = $full_size[1];
525  $uuid = uniqid(rand());
526  $template->assign_block_vars('high', array(
527    'U_HIGH' => $picture['current']['high'],
528        'UUID'=>$uuid,
529        'WIDTH_IMG'=>($full_width + 16),
530        'HEIGHT_IMG'=>($full_height + 16)
531        ));
532}
533//------------------------------------------------------- favorite manipulation
534if ( !$user['is_the_guest'] )
535{
536  // verify if the picture is already in the favorite of the user
537  $query = 'SELECT COUNT(*) AS nb_fav';
538  $query.= ' FROM '.FAVORITES_TABLE.' WHERE image_id = '.$_GET['image_id'];
539  $query.= ' AND user_id = '.$user['id'].';';
540  $result = pwg_query( $query );
541  $row = mysql_fetch_array( $result );
542  if (!$row['nb_fav'])
543  {
544    $url = PHPWG_ROOT_PATH.'picture.php';
545    $url.= get_query_string_diff(array('rate','add_fav'));
546    $url.= '&amp;add_fav=1';
547
548    $template->assign_block_vars(
549      'favorite',
550      array(
551        'FAVORITE_IMG' => PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/favorite.gif',
552        'FAVORITE_HINT' =>$lang['add_favorites_hint'],
553        'FAVORITE_ALT' =>$lang['add_favorites_alt'],
554        'U_FAVORITE' => $url
555        ));
556  }
557  else
558  {
559    $url = PHPWG_ROOT_PATH.'picture.php';
560    $url.= get_query_string_diff(array('rate','add_fav'));
561    $url.= '&amp;add_fav=0';
562   
563    $template->assign_block_vars(
564      'favorite',
565      array(
566        'FAVORITE_IMG' => PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/del_favorite.gif',
567        'FAVORITE_HINT' =>$lang['del_favorites_hint'],
568        'FAVORITE_ALT' =>$lang['del_favorites_alt'],
569        'U_FAVORITE'=> $url
570        ));
571  }
572}
573//------------------------------------ admin link for information modifications
574if ( $user['status'] == 'admin' )
575{
576  $template->assign_block_vars('admin', array());
577}
578
579//-------------------------------------------------------- navigation management
580if ($has_prev)
581{
582  $template->assign_block_vars(
583    'previous',
584    array(
585      'TITLE_IMG' => $picture['prev']['name'],
586      'IMG' => $picture['prev']['thumbnail'],
587      'U_IMG' => add_session_id($picture['prev']['url'])
588      ));
589}
590
591if ($has_next)
592{
593  $template->assign_block_vars(
594    'next',
595    array(
596      'TITLE_IMG' => $picture['next']['name'],
597      'IMG' => $picture['next']['thumbnail'],
598      'U_IMG' => add_session_id($picture['next']['url'])
599      ));
600}
601
602//--------------------------------------------------------- picture information
603// legend
604if (isset($picture['current']['comment'])
605    and !empty($picture['current']['comment']))
606{
607  $template->assign_block_vars(
608    'legend',
609    array(
610      'COMMENT_IMG' => nl2br($picture['current']['comment'])
611      ));
612}
613
614// author
615if ( !empty($picture['current']['author']) )
616{
617  $search_url = PHPWG_ROOT_PATH.'category.php?cat=search';
618  $search_url.= '&amp;search=author:'.$picture['current']['author'];
619 
620  $value = '<a href="';
621  $value.= add_session_id($search_url);
622  $value.= '">'.$picture['current']['author'].'</a>';
623 
624  $template->assign_block_vars(
625    'info_line',
626    array(
627      'INFO'=>$lang['author'],
628      'VALUE'=>$value
629      ));
630}
631// creation date
632if ( !empty($picture['current']['date_creation']) )
633{
634  $search_url = PHPWG_ROOT_PATH.'category.php?cat=search';
635  $search_url.= '&amp;search=';
636  $search_url.= 'date_creation:'.$picture['current']['date_creation'];
637 
638  $value = '<a href="';
639  $value.= add_session_id($search_url);
640  $value.= '">'.format_date($picture['current']['date_creation']).'</a>';
641 
642  $template->assign_block_vars(
643    'info_line',
644    array(
645      'INFO'=>$lang['creation_date'],
646      'VALUE'=>$value
647      ));
648}
649// date of availability
650$search_url = PHPWG_ROOT_PATH.'category.php?cat=search';
651$search_url.= '&amp;search=';
652$search_url.= 'date_available:'.$picture['current']['date_available'];
653 
654$value = '<a href="';
655$value.= add_session_id($search_url);
656$value.= '">'.format_date($picture['current']['date_available']).'</a>';
657
658$template->assign_block_vars(
659  'info_line',
660  array(
661    'INFO'=>$lang['registration_date'],
662    'VALUE'=>$value
663    ));
664// size in pixels
665if ($picture['current']['is_picture'])
666{
667  if ($original_width != $picture_size[0]
668      or $original_height != $picture_size[1])
669  {
670    $content = '[ <a href="'.$picture['current']['src'].'" ';
671    $content.= ' title="'.$lang['true_size'].'">';
672    $content.= $original_width.'*'.$original_height.'</a> ]';
673  }
674  else
675  {
676    $content = $original_width.'*'.$original_height;
677  }
678  $template->assign_block_vars(
679    'info_line',
680    array(
681      'INFO'=>$lang['size'],
682      'VALUE'=>$content 
683      ));
684}
685// file
686$template->assign_block_vars('info_line', array(
687          'INFO'=>$lang['file'],
688          'VALUE'=>$picture['current']['file'] 
689          ));
690// filesize
691if (empty($picture['current']['filesize']))
692{
693  if (!$picture['current']['is_picture'])
694  {
695    $filesize = floor(filesize($picture['current']['download'])/1024);
696  }
697  else
698  {
699    $filesize = floor(filesize($picture['current']['src'])/1024);
700  }
701}
702else
703{
704  $filesize = $picture['current']['filesize'];
705}
706
707$template->assign_block_vars('info_line', array(
708          'INFO'=>$lang['filesize'],
709          'VALUE'=>$filesize.' KB'
710          ));
711// keywords
712if (!empty($picture['current']['keywords']))
713{
714  $keywords = explode(',', $picture['current']['keywords']);
715  $content = '';
716  $url = PHPWG_ROOT_PATH.'category.php?cat=search&amp;search=keywords:';
717  foreach ($keywords as $i => $keyword)
718  {
719    $local_url = add_session_id($url.$keyword);
720    if ($i > 0)
721    {
722      $content.= ',';
723    }
724    $content.= '<a href="'.$local_url.'">'.$keyword.'</a>';
725  }
726  $template->assign_block_vars(
727    'info_line',
728    array(
729      'INFO'=>$lang['keywords'],
730      'VALUE'=>$content
731      ));
732}
733// number of visits
734$template->assign_block_vars(
735  'info_line',
736  array(
737    'INFO'=>$lang['visited'],
738    'VALUE'=>$picture['current']['hit'].' '.$lang['times']
739    ));
740// rate results
741if ($conf['rate'])
742{
743  $query = '
744SELECT COUNT(rate) AS count
745     , ROUND(AVG(rate),2) AS average
746     , ROUND(STD(rate),2) AS STD
747  FROM '.RATE_TABLE.'
748  WHERE element_id = '.$picture['current']['id'].'
749;';
750  $row = mysql_fetch_array(pwg_query($query));
751  if ($row['count'] == 0)
752  {
753    $value = $lang['no_rate'];
754  }
755  else
756  {
757    $value = $row['average'];
758    $value.= ' (';
759    $value.= $row['count'].' '.$lang['rates'];
760    $value.= ', '.$lang['standard_deviation'].' : '.$row['STD'];
761    $value.= ')';
762  }
763 
764  $template->assign_block_vars(
765    'info_line',
766    array(
767      'INFO'  => $lang['element_rate'],
768      'VALUE' => $value
769      ));
770}
771// related categories
772$cat_output = '';
773$page['show_comments'] = false;
774foreach ($related_categories as $category)
775{
776  if ($cat_output != '')
777  {
778    $cat_output.= '<br />';
779  }
780 
781  if (count($related_categories) > 3)
782  {
783    $cat_output .= get_cat_display_name_cache($category['uppercats']);
784  }
785  else
786  {
787    $cat_info = get_cat_info($category['category_id']);
788    $cat_output .= get_cat_display_name($cat_info['name']);
789  }
790  // the picture is commentable if it belongs at least to one category which
791  // is commentable
792  if ($category['commentable'] == 'true')
793  {
794    $page['show_comments'] = true;
795  }
796}
797$template->assign_block_vars(
798  'info_line',
799  array(
800    'INFO'  => $lang['categories'],
801    'VALUE' => $cat_output
802    ));
803// metadata
804if ($metadata_showable and isset($_GET['show_metadata']))
805{
806  include_once(PHPWG_ROOT_PATH.'/include/functions_metadata.inc.php');
807  $template->assign_block_vars('metadata', array());
808  if ($conf['show_exif'])
809  {
810    if (!function_exists('read_exif_data'))
811    {
812      die('Exif extension not available, admin should disable exif display');
813    }
814   
815    if ($exif = @read_exif_data($picture['current']['src']))
816    {
817      $template->assign_block_vars(
818        'metadata.headline',
819        array('TITLE' => 'EXIF Metadata')
820        );
821
822      foreach ($conf['show_exif_fields'] as $field)
823      {
824        if (strpos($field, ';') === false)
825        {
826          if (isset($exif[$field]))
827          {
828            $key = $field;
829            if (isset($lang['exif_field_'.$field]))
830            {
831              $key = $lang['exif_field_'.$field];
832            }
833           
834            $template->assign_block_vars(
835              'metadata.line',
836              array(
837                'KEY' => $key,
838                'VALUE' => $exif[$field]
839                )
840              );
841          }
842        }
843        else
844        {
845          $tokens = explode(';', $field);
846          if (isset($exif[$tokens[0]][$tokens[1]]))
847          {
848            $key = $tokens[1];
849            if (isset($lang['exif_field_'.$tokens[1]]))
850            {
851              $key = $lang['exif_field_'.$tokens[1]];
852            }
853           
854            $template->assign_block_vars(
855              'metadata.line',
856              array(
857                'KEY' => $key,
858                'VALUE' => $exif[$tokens[0]][$tokens[1]]
859                )
860              );
861          }
862        }
863      }
864    }
865  }
866  if ($conf['show_iptc'])
867  {
868    $iptc = get_iptc_data($picture['current']['src'],
869                          $conf['show_iptc_mapping']);
870
871    if (count($iptc) > 0)
872    {
873      $template->assign_block_vars(
874        'metadata.headline',
875        array('TITLE' => 'IPTC Metadata')
876        );
877    }
878   
879    foreach ($iptc as $field => $value)
880    {
881      $key = $field;
882      if (isset($lang[$field]))
883      {
884        $key = $lang[$field];
885      }
886     
887      $template->assign_block_vars(
888        'metadata.line',
889        array(
890          'KEY' => $key,
891          'VALUE' => $value
892          )
893        );
894    }
895  }
896}
897//slideshow end
898if ( isset( $_GET['slideshow'] ) )
899{
900  if ( !is_numeric( $_GET['slideshow'] ) ) $_GET['slideshow'] = $conf['slideshow_period'];
901       
902  $template->assign_block_vars('stop_slideshow', array(
903  'U_SLIDESHOW'=>add_session_id( $picture['current']['url'] )
904  ));
905}
906
907//------------------------------------------------------------------- rate form
908if ($conf['rate'] and !$user['is_the_guest'])
909{
910  $query = '
911SELECT rate
912  FROM '.RATE_TABLE.'
913  WHERE user_id = '.$user['id'].'
914    AND element_id = '.$_GET['image_id'].'
915;';
916  $result = pwg_query($query);
917  if (mysql_num_rows($result) > 0)
918  {
919    $row = mysql_fetch_array($result);
920    $sentence = $lang['already_rated'];
921    $sentence.= ' ('.$row['rate'].'). ';
922    $sentence.= $lang['update_rate'];
923  }
924  else
925  {
926    $sentence = $lang['never_rated'].'. '.$lang['to_rate'];
927  }
928  $template->assign_block_vars(
929    'rate',
930    array('SENTENCE' => $sentence)
931    );
932 
933 
934  foreach ($rate_items as $num => $mark)
935  {
936    if ($num > 0)
937    {
938      $separator = '|';
939    }
940    else
941    {
942      $separator = '';
943    }
944
945    $url = PHPWG_ROOT_PATH.'picture.php';
946    $url.= get_query_string_diff(array('rate','add_fav'));
947    $url.= '&amp;rate='.$mark;
948   
949    $template->assign_block_vars(
950      'rate.rate_option',
951      array(
952        'OPTION' => $mark,
953        'URL' => $url,
954        'SEPARATOR' => $separator
955        ));
956  }
957}
958//---------------------------------------------------- users's comments display
959if ($page['show_comments'])
960{
961  // number of comment for this picture
962  $query = 'SELECT COUNT(*) AS nb_comments';
963  $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id'];
964  $query.= " AND validated = 'true'";
965  $query.= ';';
966  $row = mysql_fetch_array( pwg_query( $query ) );
967 
968  // navigation bar creation
969  $url = PHPWG_ROOT_PATH.'picture.php';
970  $url.= get_query_string_diff(array('rate','add_fav'));
971
972  if (!isset( $_GET['start'] )
973      or !is_numeric( $_GET['start'] )
974      or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) )
975  {
976    $page['start'] = 0;
977  }
978  else
979  {
980    $page['start'] = $_GET['start'];
981  }
982  $page['navigation_bar'] = create_navigation_bar( $url, $row['nb_comments'],
983                                                   $page['start'],
984                                                   $conf['nb_comment_page'],
985                                                   '' );
986  $template->assign_block_vars('comments', array(
987    'NB_COMMENT'=>$row['nb_comments'],
988    'NAV_BAR'=>$page['navigation_bar']));
989
990  $query = 'SELECT id,author,date,image_id,content';
991  $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id'];
992  $query.= " AND validated = 'true'";
993  $query.= ' ORDER BY date ASC';
994  $query.= ' LIMIT '.$page['start'].', '.$conf['nb_comment_page'].';';
995  $result = pwg_query( $query );
996               
997  while ( $row = mysql_fetch_array( $result ) )
998  {
999    $template->assign_block_vars(
1000      'comments.comment',
1001      array(
1002        'COMMENT_AUTHOR'=>empty($row['author'])?$lang['guest']:$row['author'],
1003        'COMMENT_DATE'=>format_date($row['date'], 'mysql_datetime', true),
1004        'COMMENT'=>parse_comment_content($row['content'])
1005        ));
1006       
1007    if ( $user['status'] == 'admin' )
1008    {
1009      $template->assign_block_vars(
1010        'comments.comment.delete',
1011        array('U_COMMENT_DELETE'=>add_session_id( $url.'&amp;del='.$row['id'])
1012          ));
1013    }
1014  }
1015
1016  if (!$user['is_the_guest']
1017      or ($user['is_the_guest'] and $conf['comments_forall']))
1018  {
1019    $template->assign_block_vars('comments.add_comment', array());
1020    // display author field if the user is not logged in
1021    if (!$user['is_the_guest'])
1022    {
1023      $template->assign_block_vars(
1024        'comments.add_comment.author_known',
1025        array('KNOWN_AUTHOR'=>$user['username'])
1026        );
1027    }
1028    else
1029    {
1030      $template->assign_block_vars(
1031        'comments.add_comment.author_field', array()
1032        );
1033    }
1034  }
1035}
1036//------------------------------------------------------------ log informations
1037pwg_log( 'picture', $title_img, $picture['current']['file'] );
1038mysql_close();
1039
1040$template->parse('picture');
1041include(PHPWG_ROOT_PATH.'include/page_tail.php');
1042?>
Note: See TracBrowser for help on using the repository browser.