source: trunk/picture.php @ 587

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