source: trunk/picture.php @ 573

Last change on this file since 573 was 568, checked in by z0rglub, 20 years ago

new feature : related categories are displayed under the picture

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