source: trunk/picture.php @ 1046

Last change on this file since 1046 was 1046, checked in by rvelices, 18 years ago

fix: remote site decodes html entities from xml and addslashes

fix: picture displays "image rank/total" images even for non numeric categories

fix: category comment not transformed with nl2br if allow_html_descriptions and
comment already looks like html

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 32.9 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2006-02-17 02:41:57 +0000 (Fri, 17 Feb 2006) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1046 $
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
33if (isset($page['cat']) and is_numeric($page['cat']))
34{
35  check_restrictions($page['cat']);
36}
37//-------------------------------------------------------------- initialization
38include(PHPWG_ROOT_PATH.'include/section_init.inc.php');
39
40// if this image_id doesn't correspond to this category, an error message is
41// displayed, and execution is stopped
42if (!in_array($_GET['image_id'], $page['items']))
43{
44  echo '
45<div style="text-align:center;">'.$lang['access_forbiden'].'<br />
46  <a href="'.PHPWG_ROOT_PATH.'category.php'.'">'.$lang['thumbnails'].'</a>
47</div>';
48  exit();
49}
50
51$page['rank_of'] = array_flip($page['items']);
52
53// caching first_rank, last_rank, current_rank in the displayed
54// section. This should also help in readability.
55$page['first_rank']   = 0;
56$page['last_rank']    = count($page['items']) - 1;
57$page['current_rank'] = $page['rank_of'][ $_GET['image_id'] ];
58
59// caching current item : readability purpose
60$page['current_item'] = $_GET['image_id'];
61
62if ($page['current_rank'] != $page['first_rank'])
63{
64  // "go to first picture of this section" link is displayed only if the
65  // displayed item is not the first.
66  $template->assign_block_vars(
67    'first',
68    array(
69      'U_IMG' =>
70        PHPWG_ROOT_PATH.'picture.php'.
71        get_query_string_diff(
72          array('image_id', 'add_fav', 'slideshow')
73          ).
74        '&amp;image_id='.$page['items'][ $page['first_rank'] ],
75      )
76    );
77
78  // caching previous item : readability purpose
79  $page['previous_item'] = $page['items'][ $page['current_rank'] - 1 ];
80}
81
82if ($page['current_rank'] != $page['last_rank'])
83{
84  // "go to last picture of this section" link is displayed only if the
85  // displayed item is not the last.
86  $template->assign_block_vars(
87    'last',
88    array(
89      'U_IMG' =>
90        PHPWG_ROOT_PATH.'picture.php'.
91        get_query_string_diff(
92          array('image_id', 'add_fav', 'slideshow')
93          ).
94        '&amp;image_id='.$page['items'][ $page['last_rank'] ],
95      )
96    );
97
98  // caching next item : readability purpose
99  $page['next_item'] = $page['items'][ $page['current_rank'] + 1 ];
100}
101
102//---------------------------------------- incrementation of the number of hits
103if ( count(array_intersect(
104             array_keys($_GET),
105             array('add_fav', 'caddie', 'rate', 'representative', 'del') )
106          )==0 )
107{
108  $query = '
109  UPDATE '.IMAGES_TABLE.'
110    SET hit = hit+1
111    WHERE id = '.$_GET['image_id'].'
112  ;';
113  @pwg_query( $query );
114}
115
116//-------------------------------------------------------------- representative
117if ('admin' == $user['status'] and isset($_GET['representative']))
118{
119  $query = '
120UPDATE '.CATEGORIES_TABLE.'
121  SET representative_picture_id = '.$_GET['image_id'].'
122  WHERE id = '.$page['cat'].'
123;';
124  pwg_query($query);
125
126  $url =
127    PHPWG_ROOT_PATH
128    .'picture.php'
129    .get_query_string_diff(array('representative'));
130  redirect($url);
131}
132
133//-------------------------------------------------------------- caddie filling
134
135if (isset($_GET['caddie']))
136{
137  fill_caddie(array($_GET['image_id']));
138
139  $url =
140    PHPWG_ROOT_PATH
141    .'picture.php'
142    .get_query_string_diff(array('caddie'));
143  redirect($url);
144}
145
146
147//----------------------------------------------------------- rate registration
148if (isset($_GET['rate'])
149    and $conf['rate']
150    and ( !$user['is_the_guest'] or $conf['rate_anonymous'] )
151    and in_array($_GET['rate'], $rate_items))
152{
153  if ($user['is_the_guest'])
154  {
155    $ip_components = explode('.', $_SERVER["REMOTE_ADDR"]);
156    if ( count($ip_components)>3 )
157    {
158      array_pop($ip_components);
159    }
160    $anonymous_id = implode ('.', $ip_components);
161
162    if ( isset($_COOKIE['pwg_anonymous_rater']) )
163    {
164      if ($anonymous_id != $_COOKIE['pwg_anonymous_rater'] )
165      { // client has changed his IP adress or he's trying to fool us
166        $query = '
167SELECT element_id FROM '. RATE_TABLE . '
168  WHERE user_id=' . $user['id'] . '
169  AND anonymous_id=\'' . $anonymous_id . '\'';
170        $result = pwg_query($query);
171        $already_there = array();
172        while ( $row = mysql_fetch_array($result) )
173        {
174          array_push( $already_there, $row['element_id'] );
175        }
176       
177        if ( count($already_there)>0 )
178        {
179          $query = '
180DELETE FROM '. RATE_TABLE . '
181  WHERE user_id=' . $user['id'] . '
182  AND anonymous_id=\'' . $_COOKIE['pwg_anonymous_rater'] . '\'
183  AND element_id NOT IN (' . implode(',',$already_there) . ')';
184          pwg_query($query);
185        }
186       
187        $query = '
188UPDATE '. RATE_TABLE . '
189  SET anonymous_id=\'' . $anonymous_id . '\'
190  WHERE user_id=' . $user['id'] . '
191  AND anonymous_id=\'' . $_COOKIE['pwg_anonymous_rater'] . '\'';
192        pwg_query($query);
193
194        setcookie('pwg_anonymous_rater', $anonymous_id, 
195                   strtotime('+10 years'), cookie_path() );
196      }
197    }
198    else
199    {
200      setcookie('pwg_anonymous_rater', $anonymous_id, 
201                 strtotime('+10 years'), cookie_path() );
202    }
203  }
204
205  $query = '
206DELETE FROM '.RATE_TABLE.'
207  WHERE element_id = '.$_GET['image_id'] . '
208  AND user_id = '.$user['id']
209;
210  if (isset($anonymous_id))
211  {
212    $query.= ' AND anonymous_id=\'' . $anonymous_id .'\'';
213  }
214  pwg_query($query);
215  $query = '
216INSERT INTO '.RATE_TABLE.'
217  (user_id,anonymous_id,element_id,rate,date)
218  VALUES
219  ('.$user['id'].','.(isset($anonymous_id)?'\''.$anonymous_id.'\'':"''").','.
220   $_GET['image_id'].','.$_GET['rate'].',NOW())
221;';
222  pwg_query($query);
223
224  // update of images.average_rate field
225  $query = '
226SELECT ROUND(AVG(rate),2) AS average_rate
227  FROM '.RATE_TABLE.'
228  WHERE element_id = '.$_GET['image_id'].'
229;';
230  $row = mysql_fetch_array(pwg_query($query));
231  $query = '
232UPDATE '.IMAGES_TABLE.'
233  SET average_rate = '.$row['average_rate'].'
234  WHERE id = '.$_GET['image_id'].'
235;';
236  pwg_query($query);
237  $url =
238    PHPWG_ROOT_PATH
239    .'picture.php'
240    .get_query_string_diff(array('rate'));
241  redirect($url);
242}
243
244
245//---------------------------------------------------------- related categories
246$query = '
247SELECT category_id,uppercats,commentable,global_rank
248  FROM '.IMAGE_CATEGORY_TABLE.'
249    INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id
250  WHERE image_id = '.$_GET['image_id'].'
251    AND category_id NOT IN ('.$user['forbidden_categories'].')
252;';
253$result = pwg_query($query);
254$related_categories = array();
255while ($row = mysql_fetch_array($result))
256{
257  array_push($related_categories, $row);
258}
259usort($related_categories, 'global_rank_compare');
260//------------------------------------- prev, current & next picture management
261$picture = array();
262
263$ids = array($_GET['image_id']);
264if (isset($page['previous_item']))
265{
266  array_push($ids, $page['previous_item']);
267}
268if (isset($page['next_item']))
269{
270  array_push($ids, $page['next_item']);
271}
272
273$query = '
274SELECT *
275  FROM '.IMAGES_TABLE.'
276  WHERE id IN ('.implode(',', $ids).')
277;';
278
279$result = pwg_query($query);
280
281while ($row = mysql_fetch_array($result))
282{
283  if (isset($page['previous_item']) and $row['id'] == $page['previous_item'])
284  {
285    $i = 'prev';
286  }
287  else if (isset($page['next_item']) and $row['id'] == $page['next_item'])
288  {
289    $i = 'next';
290  }
291  else
292  {
293    $i = 'current';
294  }
295 
296  foreach (array_keys($row) as $key)
297  {
298    if (!is_numeric($key))
299    {
300      $picture[$i][$key] = $row[$key];
301    }
302  }
303
304  $picture[$i]['is_picture'] = false;
305  if (in_array(get_extension($row['file']), $conf['picture_ext']))
306  {
307    $picture[$i]['is_picture'] = true;
308  }
309 
310  $cat_directory = dirname($row['path']);
311  $file_wo_ext = get_filename_wo_extension($row['file']);
312
313  $icon = get_themeconf('mime_icon_dir');
314  $icon.= strtolower(get_extension($row['file'])).'.png';
315
316  if (isset($row['representative_ext']) and $row['representative_ext'] != '')
317  {
318    $picture[$i]['src'] =
319      $cat_directory.'/pwg_representative/'
320      .$file_wo_ext.'.'.$row['representative_ext'];
321  }
322  else
323  {
324    $picture[$i]['src'] = $icon;
325  }
326  // special case for picture files
327  if ($picture[$i]['is_picture'])
328  {
329    $picture[$i]['src'] = $row['path'];
330    // if we are working on the "current" element, we search if there is a
331    // high quality picture
332    if ($i == 'current')
333    {
334      if ($row['has_high']=='true')
335      {
336        $url_high=$cat_directory.'/pwg_high/'.$row['file'];
337        $picture[$i]['high'] = $url_high;
338      }
339    }
340  }
341
342  // if picture is not a file, we need the download link
343  if (!$picture[$i]['is_picture'])
344  {
345    $picture[$i]['download'] = $row['path'];
346  }
347
348  $picture[$i]['thumbnail'] = get_thumbnail_src($row['path'], @$row['tn_ext']);
349 
350  if ( !empty( $row['name'] ) )
351  {
352    $picture[$i]['name'] = $row['name'];
353  }
354  else
355  {
356    $picture[$i]['name'] = str_replace('_', ' ', $file_wo_ext);
357  }
358
359  $picture[$i]['url'] =
360    PHPWG_ROOT_PATH.'picture.php'
361    .get_query_string_diff(array('image_id', 'add_fav', 'slideshow'))
362    .'&amp;image_id='.$row['id'];
363}
364
365$url_up = PHPWG_ROOT_PATH.'category.php?cat='.$page['cat'];
366
367$url_up_start = floor( $page['current_rank'] / $user['nb_image_page'] );
368$url_up_start *= $user['nb_image_page'];
369if ($url_up_start>0)
370{
371  $url_up .= '&amp;start='.$url_up_start; 
372}
373
374if ( $page['cat'] == 'search' )
375{
376  $url_up.= "&amp;search=".$_GET['search'];
377}
378if ( $page['cat'] == 'list' )
379{
380  $url_up.= "&amp;list=".$_GET['list'];
381}
382
383$url_admin =
384  PHPWG_ROOT_PATH.'admin.php?page=picture_modify'
385  .'&amp;cat_id='.$page['cat']
386  .'&amp;image_id='.$_GET['image_id'];
387
388$url_slide =
389  $picture['current']['url'].'&amp;slideshow='.$conf['slideshow_period'];
390
391//--------------------------------------------------------- favorite management
392if ( isset( $_GET['add_fav'] ) )
393{
394  $query = 'DELETE FROM '.FAVORITES_TABLE;
395  $query.= ' WHERE user_id = '.$user['id'];
396  $query.= ' AND image_id = '.$picture['current']['id'];
397  $query.= ';';
398  $result = pwg_query( $query );
399 
400  if ( $_GET['add_fav'] == 1 )
401  {
402    $query = 'INSERT INTO '.FAVORITES_TABLE;
403    $query.= ' (image_id,user_id) VALUES';
404    $query.= ' ('.$picture['current']['id'].','.$user['id'].')';
405    $query.= ';';
406    $result = pwg_query( $query );
407  }
408  if ( !$_GET['add_fav'] and $page['cat'] == 'fav' )
409  {
410    if (!isset($page['previous_item']) and !isset($page['next_item']))
411    {
412      // there is no favorite picture anymore we redirect the user to the
413      // category page
414      redirect($url_up);
415    }
416    else if (!isset($page['previous_item']))
417    {
418      $url = str_replace( '&amp;', '&', $picture['next']['url'] );
419      redirect( $url );
420    }
421    else
422    {
423      $url = str_replace('&amp;', '&', $picture['prev']['url'] );
424      redirect( $url );
425    }
426    redirect( $url );
427  }
428}
429
430//------------------------------------------------------  comment registeration
431if ( isset( $_POST['content'] ) && !empty($_POST['content']) )
432{
433  $register_comment = true;
434  $author = !empty($_POST['author'])?$_POST['author']:$lang['guest'];
435  // if a guest try to use the name of an already existing user, he must be
436  // rejected
437  if ( $author != $user['username'] )
438  {
439    $query = 'SELECT COUNT(*) AS user_exists';
440    $query.= ' FROM '.USERS_TABLE;
441    $query.= ' WHERE '.$conf['user_fields']['username']." = '".$author."'";
442    $query.= ';';
443    $row = mysql_fetch_array( pwg_query( $query ) );
444    if ( $row['user_exists'] == 1 )
445    {
446      $template->assign_block_vars(
447        'information',
448        array('INFORMATION'=>$lang['comment_user_exists']));
449      $register_comment = false;
450    }
451  }
452 
453  if ( $register_comment )
454  {
455    // anti-flood system
456    $reference_date = time() - $conf['anti-flood_time'];
457    $query = 'SELECT id FROM '.COMMENTS_TABLE;
458    $query.= ' WHERE date > FROM_UNIXTIME('.$reference_date.')';
459    $query.= " AND author = '".$author."'";
460    $query.= ';';
461    if ( mysql_num_rows( pwg_query( $query ) ) == 0
462         or $conf['anti-flood_time'] == 0 )
463    {
464      list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
465
466      $data = array();
467      $data{'author'} = $author;
468      $data{'date'} = $dbnow;
469      $data{'image_id'} = $_GET['image_id'];
470      $data{'content'} = htmlspecialchars( $_POST['content'], ENT_QUOTES);
471     
472      if (!$conf['comments_validation'] or $user['status'] == 'admin')
473      {
474        $data{'validated'} = 'true';
475        $data{'validation_date'} = $dbnow;
476      }
477      else
478      {
479        $data{'validated'} = 'false';
480      }
481     
482      include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
483      $fields = array('author', 'date', 'image_id', 'content', 'validated',
484                      'validation_date');
485      mass_inserts(COMMENTS_TABLE, $fields, array($data));
486     
487      // information message
488      $message = $lang['comment_added'];
489
490      if (!$conf['comments_validation'] or $user['status'] == 'admin')
491     
492      if ( $conf['comments_validation'] and $user['status'] != 'admin' )
493      {
494        $message.= '<br />'.$lang['comment_to_validate'];
495      }
496      $template->assign_block_vars('information',
497                                   array('INFORMATION'=>$message));
498    }
499    else
500    {
501      // information message
502      $template->assign_block_vars(
503        'information',
504        array('INFORMATION'=>$lang['comment_anti-flood']));
505    }
506  }
507}
508// comment deletion
509if ( isset( $_GET['del'] )
510     and is_numeric( $_GET['del'] )
511     and $user['status'] == 'admin' )
512{
513  $query = 'DELETE FROM '.COMMENTS_TABLE;
514  $query.= ' WHERE id = '.$_GET['del'];
515  $query.= ';';
516  pwg_query( $query );
517}
518
519//
520// Start output of page
521//
522
523$title =  $picture['current']['name'];
524$refresh = 0;
525if ( isset( $_GET['slideshow'] ) and isset($page['next_item']) )
526{
527  $refresh= $_GET['slideshow'];
528  $url_link = $picture['next']['url'].'&amp;slideshow='.$refresh;
529}
530
531$title_img = $picture['current']['name'];
532if (is_numeric( $page['cat'] )) 
533{
534  $title_img = replace_space(get_cat_display_name($page['cat_name']));
535}
536else if ( $page['cat'] == 'search' )
537{
538  $title_img = replace_search( $title_img, $_GET['search'] );
539}
540$title_nb = ($page['current_rank'] + 1).'/'.$page['cat_nb_images'];
541
542// calculation of width and height
543if (empty($picture['current']['width']))
544{
545  $taille_image = @getimagesize($picture['current']['src']);
546  $original_width = $taille_image[0];
547  $original_height = $taille_image[1];
548}
549else
550{
551  $original_width = $picture['current']['width'];
552  $original_height = $picture['current']['height'];
553}
554
555$picture_size = get_picture_size($original_width, $original_height,
556                                 @$user['maxwidth'], @$user['maxheight']);
557
558// metadata
559if ($conf['show_exif'] or $conf['show_iptc'])
560{
561  $metadata_showable = true;
562}
563else
564{
565  $metadata_showable = false;
566}
567
568$url_metadata = PHPWG_ROOT_PATH.'picture.php';
569$url_metadata .=  get_query_string_diff(array('add_fav', 'slideshow', 'show_metadata'));
570if ($metadata_showable and !isset($_GET['show_metadata']))
571{
572  $url_metadata.= '&amp;show_metadata=1';
573}
574
575$page['body_id'] = 'thePicturePage';
576//------------------------------------------------------- navigation management
577if (isset($page['previous_item']))
578{
579  $template->assign_block_vars(
580    'previous',
581    array(
582      'TITLE_IMG' => $picture['prev']['name'],
583      'IMG' => $picture['prev']['thumbnail'],
584      'U_IMG' => $picture['prev']['url'],
585      'U_IMG_SRC' => $picture['prev']['src']
586      )
587    );
588}
589
590if (isset($page['next_item']))
591{
592  $template->assign_block_vars(
593    'next',
594    array(
595      'TITLE_IMG' => $picture['next']['name'],
596      'IMG' => $picture['next']['thumbnail'],
597      'U_IMG' => $picture['next']['url'],
598      'U_IMG_SRC' => $picture['next']['src'] // allow navigator to preload
599      )
600    );
601}
602
603include(PHPWG_ROOT_PATH.'include/page_header.php');
604$template->set_filenames(array('picture'=>'picture.tpl'));
605
606$template->assign_vars(array(
607  'CATEGORY' => $title_img,
608  'PHOTO' => $title_nb,
609  'TITLE' => $picture['current']['name'],
610  'SRC_IMG' => $picture['current']['src'],
611  'ALT_IMG' => $picture['current']['file'],
612  'WIDTH_IMG' => $picture_size[0],
613  'HEIGHT_IMG' => $picture_size[1],
614
615  'LEVEL_SEPARATOR' => $conf['level_separator'],
616
617  'L_HOME' => $lang['home'],
618  'L_SLIDESHOW' => $lang['slideshow'],
619  'L_STOP_SLIDESHOW' => $lang['slideshow_stop'],
620  'L_PREV_IMG' =>$lang['previous_page'].' : ',
621  'L_NEXT_IMG' =>$lang['next_page'].' : ',
622  'L_ADMIN' =>$lang['link_info_image'],
623  'L_COMMENT_TITLE' =>$lang['comments_title'],
624  'L_ADD_COMMENT' =>$lang['comments_add'],
625  'L_DELETE_COMMENT' =>$lang['comments_del'],
626  'L_DELETE' =>$lang['delete'],
627  'L_SUBMIT' =>$lang['submit'],
628  'L_AUTHOR' =>  $lang['upload_author'],
629  'L_COMMENT' =>$lang['comment'],
630  'L_DOWNLOAD' => $lang['download'],
631  'L_DOWNLOAD_HINT' => $lang['download_hint'],
632  'L_PICTURE_METADATA' => $lang['picture_show_metadata'],
633  'L_PICTURE_HIGH' => $lang['picture_high'],
634  'L_UP_HINT' => $lang['home_hint'],
635  'L_UP_ALT' => $lang['home'],
636 
637  'U_HOME' => (PHPWG_ROOT_PATH.'category.php'),
638  'U_UP' => $url_up,
639  'U_METADATA' => $url_metadata,
640  'U_ADMIN' => $url_admin,
641  'U_SLIDESHOW'=> $url_slide,
642  'U_ADD_COMMENT' => str_replace( '&', '&amp;', $_SERVER['REQUEST_URI'] )
643  )
644);
645
646if ($conf['show_picture_name_on_title'])
647{
648  $template->assign_block_vars('title', array());
649}
650
651//------------------------------------------------------- upper menu management
652// download link if file is not a picture
653if (!$picture['current']['is_picture'])
654{
655  $template->assign_block_vars(
656    'download',
657    array('U_DOWNLOAD' => $picture['current']['download']));
658}
659// display a high quality link if present
660if (isset($picture['current']['high']))
661{
662  $uuid = uniqid(rand());
663  $template->assign_block_vars('high', array(
664    'U_HIGH' => $picture['current']['high'],
665    'UUID'=>$uuid
666  ));
667  $template->assign_block_vars(
668    'download',
669    array('U_DOWNLOAD' => PHPWG_ROOT_PATH.'action.php?dwn='
670          .$picture['current']['high']
671    )
672  );
673}
674// button to set the current picture as representative
675if ('admin' == $user['status'] and is_numeric($page['cat']))
676{
677  $template->assign_block_vars(
678    'representative',
679    array(
680      'URL' =>
681        PHPWG_ROOT_PATH.'picture.php'
682        .get_query_string_diff(array('add_fav'))
683        .'&amp;representative=1'
684      )
685    );
686}
687
688if ('admin' == $user['status'])
689{
690  $template->assign_block_vars(
691    'caddie',
692    array(
693      'URL' =>
694        PHPWG_ROOT_PATH.'picture.php'
695        .get_query_string_diff(array('add_fav')).'&amp;caddie=1')
696    );
697}
698
699//------------------------------------------------------- favorite manipulation
700if ( !$user['is_the_guest'] )
701{
702  // verify if the picture is already in the favorite of the user
703  $query = 'SELECT COUNT(*) AS nb_fav';
704  $query.= ' FROM '.FAVORITES_TABLE.' WHERE image_id = '.$_GET['image_id'];
705  $query.= ' AND user_id = '.$user['id'].';';
706  $result = pwg_query( $query );
707  $row = mysql_fetch_array( $result );
708  if (!$row['nb_fav'])
709  {
710    $url = PHPWG_ROOT_PATH.'picture.php';
711    $url.= get_query_string_diff(array('add_fav'));
712    $url.= '&amp;add_fav=1';
713
714    $template->assign_block_vars(
715      'favorite',
716      array(
717        'FAVORITE_IMG' => get_themeconf('icon_dir').'/favorite.png',
718        'FAVORITE_HINT' =>$lang['add_favorites_hint'],
719        'FAVORITE_ALT' =>$lang['add_favorites_alt'],
720        'U_FAVORITE' => $url
721        ));
722  }
723  else
724  {
725    $url = PHPWG_ROOT_PATH.'picture.php';
726    $url.= get_query_string_diff(array('add_fav'));
727    $url.= '&amp;add_fav=0';
728   
729    $template->assign_block_vars(
730      'favorite',
731      array(
732        'FAVORITE_IMG' => get_themeconf('icon_dir').'/del_favorite.png',
733        'FAVORITE_HINT' =>$lang['del_favorites_hint'],
734        'FAVORITE_ALT' =>$lang['del_favorites_alt'],
735        'U_FAVORITE'=> $url
736        ));
737  }
738}
739//------------------------------------ admin link for information modifications
740if ( $user['status'] == 'admin' )
741{
742  $template->assign_block_vars('admin', array());
743}
744
745//--------------------------------------------------------- picture information
746// legend
747if (isset($picture['current']['comment'])
748    and !empty($picture['current']['comment']))
749{
750  $template->assign_block_vars(
751    'legend',
752    array(
753      'COMMENT_IMG' => nl2br($picture['current']['comment'])
754      ));
755}
756
757$infos = array();
758
759// author
760if (!empty($picture['current']['author']))
761{
762  $infos['INFO_AUTHOR'] =
763    // FIXME because of search engine partial rewrite, giving the author
764    // name threw GET is not supported anymore. This feature should come
765    // back later, with a better design
766//     '<a href="'.
767//       PHPWG_ROOT_PATH.'category.php?cat=search'.
768//       '&amp;search=author:'.$picture['current']['author']
769//       .'">'.$picture['current']['author'].'</a>';
770    $picture['current']['author'];
771}
772else
773{
774  $infos['INFO_AUTHOR'] = l10n('N/A');
775}
776
777// creation date
778if (!empty($picture['current']['date_creation']))
779{
780  $infos['INFO_CREATION_DATE'] =
781    // FIXME because of search engine partial rewrite, giving the author
782    // name threw GET is not supported anymore. This feature should come
783    // back later, with a better design (calendar view).
784//     '<a href="'.
785//       PHPWG_ROOT_PATH.'category.php?cat=search'.
786//       '&amp;search=date_creation:'.$picture['current']['date_creation']
787//       .'">'.format_date($picture['current']['date_creation']).'</a>';
788    format_date($picture['current']['date_creation']);
789}
790else
791{
792  $infos['INFO_CREATION_DATE'] = l10n('N/A');
793}
794
795// date of availability
796$infos['INFO_AVAILABILITY_DATE'] =
797// FIXME because of search engine partial rewrite, giving the author
798// name threw GET is not supported anymore. This feature should come
799// back later, with a better design (calendar view).
800//
801//   '<a href="'.
802//     PHPWG_ROOT_PATH.'category.php?cat=search'.
803//     '&amp;search=date_available:'.
804//     substr($picture['current']['date_available'], 0, 10)
805//     .'">'.
806//   format_date($picture['current']['date_available'], 'mysql_datetime').
807//   '</a>';
808format_date($picture['current']['date_available'], 'mysql_datetime');
809
810// size in pixels
811if ($picture['current']['is_picture'])
812{
813  if ($original_width != $picture_size[0]
814      or $original_height != $picture_size[1])
815  {
816    $infos['INFO_DIMENSIONS'] =
817      '<a href="'.$picture['current']['src'].'" title="'.
818      l10n('Original dimensions').'">'.
819      $original_width.'*'.$original_height.'</a>';
820  }
821  else
822  {
823    $infos['INFO_DIMENSIONS'] = $original_width.'*'.$original_height;
824  }
825}
826else
827{
828  $infos['INFO_DIMENSIONS'] = l10n('N/A');
829}
830
831// filesize
832if (!empty($picture['current']['filesize']))
833{
834  $infos['INFO_FILESIZE'] =
835    sprintf(l10n('%d Kb'), $picture['current']['filesize']);
836}
837else
838{
839  $infos['INFO_FILESIZE'] = l10n('N/A');
840}
841
842// number of visits
843$infos['INFO_VISITS'] = $picture['current']['hit'];
844
845// file
846$infos['INFO_FILE'] = $picture['current']['file'];
847
848// keywords
849if (!empty($picture['current']['keywords']))
850{
851  $infos['INFO_KEYWORDS'] =
852    // FIXME because of search engine partial rewrite, giving the author
853    // name threw GET is not supported anymore. This feature should come
854    // back later, with a better design (tag classification).
855//     preg_replace(
856//       '/([^,]+)/',
857//       '<a href="'.
858//         PHPWG_ROOT_PATH.'category.php?cat=search&amp;search=keywords:$1'
859//         .'">$1</a>',
860//       $picture['current']['keywords']
861//       );
862    $picture['current']['keywords'];
863}
864else
865{
866  $infos['INFO_KEYWORDS'] = l10n('N/A');
867}
868
869$template->assign_vars($infos);
870
871// related categories
872foreach ($related_categories as $category)
873{
874  $template->assign_block_vars(
875    'category',
876    array(
877      'LINE' => count($related_categories) > 3
878        ? get_cat_display_name_cache($category['uppercats'])
879        : get_cat_display_name_from_id($category['category_id'])
880      )
881    );
882}
883
884//-------------------------------------------------------------------  metadata
885if ($metadata_showable and isset($_GET['show_metadata']))
886{
887  include_once(PHPWG_ROOT_PATH.'/include/functions_metadata.inc.php');
888  $template->assign_block_vars('metadata', array());
889  if ($conf['show_exif'])
890  {
891    if (!function_exists('read_exif_data'))
892    {
893      die('Exif extension not available, admin should disable exif display');
894    }
895   
896    if ($exif = @read_exif_data($picture['current']['src']))
897    {
898      $template->assign_block_vars(
899        'metadata.headline',
900        array('TITLE' => 'EXIF Metadata')
901        );
902
903      foreach ($conf['show_exif_fields'] as $field)
904      {
905        if (strpos($field, ';') === false)
906        {
907          if (isset($exif[$field]))
908          {
909            $key = $field;
910            if (isset($lang['exif_field_'.$field]))
911            {
912              $key = $lang['exif_field_'.$field];
913            }
914           
915            $template->assign_block_vars(
916              'metadata.line',
917              array(
918                'KEY' => $key,
919                'VALUE' => $exif[$field]
920                )
921              );
922          }
923        }
924        else
925        {
926          $tokens = explode(';', $field);
927          if (isset($exif[$tokens[0]][$tokens[1]]))
928          {
929            $key = $tokens[1];
930            if (isset($lang['exif_field_'.$tokens[1]]))
931            {
932              $key = $lang['exif_field_'.$tokens[1]];
933            }
934           
935            $template->assign_block_vars(
936              'metadata.line',
937              array(
938                'KEY' => $key,
939                'VALUE' => $exif[$tokens[0]][$tokens[1]]
940                )
941              );
942          }
943        }
944      }
945    }
946  }
947  if ($conf['show_iptc'])
948  {
949    $iptc = get_iptc_data($picture['current']['src'],
950                          $conf['show_iptc_mapping']);
951
952    if (count($iptc) > 0)
953    {
954      $template->assign_block_vars(
955        'metadata.headline',
956        array('TITLE' => 'IPTC Metadata')
957        );
958    }
959   
960    foreach ($iptc as $field => $value)
961    {
962      $key = $field;
963      if (isset($lang[$field]))
964      {
965        $key = $lang[$field];
966      }
967     
968      $template->assign_block_vars(
969        'metadata.line',
970        array(
971          'KEY' => $key,
972          'VALUE' => $value
973          )
974        );
975    }
976  }
977}
978//slideshow end
979if ( isset( $_GET['slideshow'] ) )
980{
981  if ( !is_numeric( $_GET['slideshow'] ) ) $_GET['slideshow'] = $conf['slideshow_period'];
982 
983  $template->assign_block_vars('stop_slideshow', array(
984  'U_SLIDESHOW'=>$picture['current']['url']
985  ));
986}
987
988//------------------------------------------------------------------- rating
989if ($conf['rate'])
990{
991  $query = '
992SELECT COUNT(rate) AS count
993     , ROUND(AVG(rate),2) AS average
994     , ROUND(STD(rate),2) AS STD
995  FROM '.RATE_TABLE.'
996  WHERE element_id = '.$picture['current']['id'].'
997;';
998  $row = mysql_fetch_array(pwg_query($query));
999  if ($row['count'] == 0)
1000  {
1001    $value = $lang['no_rate'];
1002  }
1003  else
1004  {
1005    $value = sprintf(
1006      l10n('%.2f (rated %d times, standard deviation = %.2f)'),
1007      $row['average'],
1008      $row['count'],
1009      $row['STD']
1010      );
1011  }
1012
1013  if ($conf['rate_anonymous'] or !$user['is_the_guest'])
1014  {
1015    if ($row['count']>0)
1016    {
1017      $query = 'SELECT rate
1018      FROM '.RATE_TABLE.'
1019      WHERE element_id = '.$_GET['image_id'] . '
1020      AND user_id = '.$user['id'] ;
1021 
1022      if ($user['is_the_guest'])
1023      {
1024        $ip_components = explode('.', $_SERVER['REMOTE_ADDR']);
1025        if ( count($ip_components)>3 )
1026        {
1027          array_pop($ip_components);
1028        }
1029        $anonymous_id = implode ('.', $ip_components);
1030        $query .= ' AND anonymous_id = \''.$anonymous_id . '\'';
1031      }
1032     
1033      $result = pwg_query($query);
1034      if (mysql_num_rows($result) > 0)
1035      {
1036        $row = mysql_fetch_array($result);
1037        $sentence = $lang['already_rated'];
1038        $sentence.= ' ('.$row['rate'].'). ';
1039        $sentence.= $lang['update_rate'];
1040      }
1041      else
1042      {
1043        $sentence = $lang['never_rated'].'. '.$lang['Rate'];
1044      }
1045    }
1046    else 
1047    {
1048      $sentence = $lang['never_rated'].'. '.$lang['Rate'];
1049    }
1050    $template->assign_block_vars(
1051      'rate',
1052      array(
1053        'CONTENT' => $value,
1054        'SENTENCE' => $sentence
1055        ));
1056
1057    $template->assign_block_vars('info_rate', array('CONTENT' => $value));
1058
1059    $template->assign_vars(
1060      array(
1061        'INFO_RATE' => $value
1062        )
1063      );
1064
1065    foreach ($rate_items as $num => $mark)
1066    {
1067      if ($num > 0)
1068      {
1069        $separator = '|';
1070      }
1071      else
1072      {
1073        $separator = '';
1074      }
1075
1076      $url = PHPWG_ROOT_PATH.'picture.php';
1077      $url.= get_query_string_diff(array('add_fav'));
1078      $url.= '&amp;rate='.$mark;
1079
1080      $template->assign_block_vars(
1081        'rate.rate_option',
1082        array(
1083          'OPTION' => $mark,
1084          'URL' => $url,
1085          'SEPARATOR' => $separator
1086          ));
1087    }
1088  }
1089}
1090
1091//---------------------------------------------------- users's comments display
1092
1093// the picture is commentable if it belongs at least to one category which
1094// is commentable
1095$page['show_comments'] = false;
1096foreach ($related_categories as $category)
1097{
1098  if ($category['commentable'] == 'true')
1099  {
1100    $page['show_comments'] = true;
1101  }
1102}
1103
1104if ($page['show_comments'])
1105{
1106  // number of comment for this picture
1107  $query = 'SELECT COUNT(*) AS nb_comments';
1108  $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id'];
1109  $query.= " AND validated = 'true'";
1110  $query.= ';';
1111  $row = mysql_fetch_array( pwg_query( $query ) );
1112 
1113  // navigation bar creation
1114  $url = PHPWG_ROOT_PATH.'picture.php';
1115  $url.= get_query_string_diff(array('add_fav','start'));
1116
1117  if (!isset( $_GET['start'] )
1118      or !is_numeric( $_GET['start'] )
1119      or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) )
1120  {
1121    $page['start'] = 0;
1122  }
1123  else
1124  {
1125    $page['start'] = $_GET['start'];
1126  }
1127  $page['navigation_bar'] = create_navigation_bar( $url, $row['nb_comments'],
1128                                                   $page['start'],
1129                                                   $conf['nb_comment_page'],
1130                                                   '' );
1131  $template->assign_block_vars('comments', array(
1132    'NB_COMMENT'=>$row['nb_comments'],
1133    'NAV_BAR'=>$page['navigation_bar']));
1134
1135  if ($row['nb_comments']>0)
1136  {
1137    $query = 'SELECT id,author,date,image_id,content';
1138    $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id'];
1139    $query.= " AND validated = 'true'";
1140    $query.= ' ORDER BY date ASC';
1141    $query.= ' LIMIT '.$page['start'].', '.$conf['nb_comment_page'].';';
1142    $result = pwg_query( $query );
1143
1144    while ( $row = mysql_fetch_array( $result ) )
1145    {
1146      $template->assign_block_vars(
1147        'comments.comment',
1148        array(
1149          'COMMENT_AUTHOR'=>empty($row['author'])?$lang['guest']:$row['author'],
1150          'COMMENT_DATE'=>format_date($row['date'], 'mysql_datetime', true),
1151    'COMMENT'=>parse_comment_content($row['content'])
1152    ));
1153
1154      if ( $user['status'] == 'admin' )
1155      {
1156        $template->assign_block_vars(
1157          'comments.comment.delete',
1158          array('U_COMMENT_DELETE'=> $url.'&amp;del='.$row['id']
1159            ));
1160      }
1161    }
1162  }
1163 
1164  if (!$user['is_the_guest']
1165      or ($user['is_the_guest'] and $conf['comments_forall']))
1166  {
1167    $template->assign_block_vars('comments.add_comment', array());
1168    // display author field if the user is not logged in
1169    if (!$user['is_the_guest'])
1170    {
1171      $template->assign_block_vars(
1172        'comments.add_comment.author_known',
1173        array('KNOWN_AUTHOR'=>$user['username'])
1174        );
1175    }
1176    else
1177    {
1178      $template->assign_block_vars(
1179        'comments.add_comment.author_field', array()
1180        );
1181    }
1182  }
1183}
1184//------------------------------------------------------------ log informations
1185pwg_log( 'picture', $title_img, $picture['current']['file'] );
1186
1187$template->parse('picture');
1188include(PHPWG_ROOT_PATH.'include/page_tail.php');
1189?>
Note: See TracBrowser for help on using the repository browser.