source: trunk/picture.php @ 579

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