source: trunk/picture.php @ 577

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

search links in picture informations : author, date_available, date_creation

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