source: trunk/picture.php @ 535

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

bug correction : if you rate a picture and then launch the slideshow, all
pictures are rated with the same rate

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