source: trunk/picture.php @ 1070

Last change on this file since 1070 was 1070, checked in by rub, 18 years ago

Step 1 improvement issue 0000301:

o Change status of table #_user_infos
o Don't send password to webmaster, guest, generic

Next Step:

o Functions Check of status
o Restricted Access for user generic

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 32.4 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-03-08 23:14:53 +0000 (Wed, 08 Mar 2006) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1070 $
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
33include(PHPWG_ROOT_PATH.'include/section_init.inc.php');
34//-------------------------------------------------- access authorization check
35if (isset($page['cat']) and is_numeric($page['cat']))
36{
37  check_restrictions($page['cat']);
38}
39//-------------------------------------------------------------- initialization
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 (is_admin() 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?';
366if ( isset($page['cat']) )
367{
368  $url_up .= 'cat='.$page['cat'];
369}
370elseif ( isset($_GET['calendar']) )
371{
372  $url_up .= 'calendar='.$_GET['calendar'];
373}
374
375$url_up_start = floor( $page['current_rank'] / $user['nb_image_page'] );
376$url_up_start *= $user['nb_image_page'];
377if ($url_up_start>0)
378{
379  $url_up .= '&amp;start='.$url_up_start;
380}
381
382if ( isset($page['cat']) )
383{
384  if ( $page['cat'] == 'search' )
385  {
386    $url_up.= '&amp;search='.$_GET['search'];
387  }
388  if ( $page['cat'] == 'list' )
389  {
390    $url_up.= '&amp;list='.$_GET['list'];
391  }
392}
393
394$url_admin =
395  PHPWG_ROOT_PATH.'admin.php?page=picture_modify'
396  .'&amp;cat_id='. ( isset($page['cat']) ? $page['cat'] : '' )
397  .'&amp;image_id='.$_GET['image_id'];
398
399$url_slide =
400  $picture['current']['url'].'&amp;slideshow='.$conf['slideshow_period'];
401
402//--------------------------------------------------------- favorite management
403if ( isset( $_GET['add_fav'] ) )
404{
405  $query = 'DELETE FROM '.FAVORITES_TABLE;
406  $query.= ' WHERE user_id = '.$user['id'];
407  $query.= ' AND image_id = '.$picture['current']['id'];
408  $query.= ';';
409  $result = pwg_query( $query );
410
411  if ( $_GET['add_fav'] == 1 )
412  {
413    $query = 'INSERT INTO '.FAVORITES_TABLE;
414    $query.= ' (image_id,user_id) VALUES';
415    $query.= ' ('.$picture['current']['id'].','.$user['id'].')';
416    $query.= ';';
417    $result = pwg_query( $query );
418  }
419  if ( !$_GET['add_fav'] and isset($page['cat']) and 'fav'==$page['cat'] )
420  {
421    if (!isset($page['previous_item']) and !isset($page['next_item']))
422    {
423      // there is no favorite picture anymore we redirect the user to the
424      // category page
425      redirect($url_up);
426    }
427    else if (!isset($page['previous_item']))
428    {
429      $url = str_replace( '&amp;', '&', $picture['next']['url'] );
430      redirect( $url );
431    }
432    else
433    {
434      $url = str_replace('&amp;', '&', $picture['prev']['url'] );
435      redirect( $url );
436    }
437    redirect( $url );
438  }
439}
440
441//------------------------------------------------------  comment registeration
442if ( isset( $_POST['content'] ) && !empty($_POST['content']) )
443{
444  $register_comment = true;
445  $author = !empty($_POST['author'])?$_POST['author']:$lang['guest'];
446  // if a guest try to use the name of an already existing user, he must be
447  // rejected
448  if ( $author != $user['username'] )
449  {
450    $query = 'SELECT COUNT(*) AS user_exists';
451    $query.= ' FROM '.USERS_TABLE;
452    $query.= ' WHERE '.$conf['user_fields']['username']." = '".$author."'";
453    $query.= ';';
454    $row = mysql_fetch_array( pwg_query( $query ) );
455    if ( $row['user_exists'] == 1 )
456    {
457      $template->assign_block_vars(
458        'information',
459        array('INFORMATION'=>$lang['comment_user_exists']));
460      $register_comment = false;
461    }
462  }
463
464  if ( $register_comment )
465  {
466    // anti-flood system
467    $reference_date = time() - $conf['anti-flood_time'];
468    $query = 'SELECT id FROM '.COMMENTS_TABLE;
469    $query.= ' WHERE date > FROM_UNIXTIME('.$reference_date.')';
470    $query.= " AND author = '".$author."'";
471    $query.= ';';
472    if ( mysql_num_rows( pwg_query( $query ) ) == 0
473         or $conf['anti-flood_time'] == 0 )
474    {
475      list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
476
477      $data = array();
478      $data{'author'} = $author;
479      $data{'date'} = $dbnow;
480      $data{'image_id'} = $_GET['image_id'];
481      $data{'content'} = htmlspecialchars( $_POST['content'], ENT_QUOTES);
482
483      if (!$conf['comments_validation'] or is_admin())
484      {
485        $data{'validated'} = 'true';
486        $data{'validation_date'} = $dbnow;
487      }
488      else
489      {
490        $data{'validated'} = 'false';
491      }
492
493      include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
494      $fields = array('author', 'date', 'image_id', 'content', 'validated',
495                      'validation_date');
496      mass_inserts(COMMENTS_TABLE, $fields, array($data));
497
498      // information message
499      $message = $lang['comment_added'];
500
501      if (!$conf['comments_validation'] or is_admin())
502
503      if ( $conf['comments_validation'] and !is_admin() )
504      {
505        $message.= '<br />'.$lang['comment_to_validate'];
506      }
507      $template->assign_block_vars('information',
508                                   array('INFORMATION'=>$message));
509    }
510    else
511    {
512      // information message
513      $template->assign_block_vars(
514        'information',
515        array('INFORMATION'=>$lang['comment_anti-flood']));
516    }
517  }
518}
519// comment deletion
520if ( isset( $_GET['del'] )
521     and is_numeric( $_GET['del'] )
522     and is_admin() )
523{
524  $query = 'DELETE FROM '.COMMENTS_TABLE;
525  $query.= ' WHERE id = '.$_GET['del'];
526  $query.= ';';
527  pwg_query( $query );
528}
529
530//
531// Start output of page
532//
533
534$title =  $picture['current']['name'];
535$refresh = 0;
536if ( isset( $_GET['slideshow'] ) and isset($page['next_item']) )
537{
538  $refresh= $_GET['slideshow'];
539  $url_link = $picture['next']['url'].'&amp;slideshow='.$refresh;
540}
541
542$title_img = $picture['current']['name'];
543if ( isset( $page['cat'] ) )
544{
545  if (is_numeric( $page['cat'] ))
546  {
547    $title_img = replace_space(get_cat_display_name($page['cat_name']));
548  }
549  else if ( $page['cat'] == 'search' )
550  {
551    $title_img = replace_search( $title_img, $_GET['search'] );
552  }
553}
554$title_nb = ($page['current_rank'] + 1).'/'.$page['cat_nb_images'];
555
556// calculation of width and height
557if (empty($picture['current']['width']))
558{
559  $taille_image = @getimagesize($picture['current']['src']);
560  $original_width = $taille_image[0];
561  $original_height = $taille_image[1];
562}
563else
564{
565  $original_width = $picture['current']['width'];
566  $original_height = $picture['current']['height'];
567}
568
569$picture_size = get_picture_size($original_width, $original_height,
570                                 @$user['maxwidth'], @$user['maxheight']);
571
572// metadata
573if ($conf['show_exif'] or $conf['show_iptc'])
574{
575  $metadata_showable = true;
576}
577else
578{
579  $metadata_showable = false;
580}
581
582$url_metadata = PHPWG_ROOT_PATH.'picture.php';
583$url_metadata .=  get_query_string_diff(array('add_fav', 'slideshow', 'show_metadata'));
584if ($metadata_showable and !isset($_GET['show_metadata']))
585{
586  $url_metadata.= '&amp;show_metadata=1';
587}
588
589$page['body_id'] = 'thePicturePage';
590//------------------------------------------------------- navigation management
591if (isset($page['previous_item']))
592{
593  $template->assign_block_vars(
594    'previous',
595    array(
596      'TITLE_IMG' => $picture['prev']['name'],
597      'IMG' => $picture['prev']['thumbnail'],
598      'U_IMG' => $picture['prev']['url'],
599      'U_IMG_SRC' => $picture['prev']['src']
600      )
601    );
602}
603
604if (isset($page['next_item']))
605{
606  $template->assign_block_vars(
607    'next',
608    array(
609      'TITLE_IMG' => $picture['next']['name'],
610      'IMG' => $picture['next']['thumbnail'],
611      'U_IMG' => $picture['next']['url'],
612      'U_IMG_SRC' => $picture['next']['src'] // allow navigator to preload
613      )
614    );
615}
616
617include(PHPWG_ROOT_PATH.'include/page_header.php');
618$template->set_filenames(array('picture'=>'picture.tpl'));
619
620$template->assign_vars(array(
621  'CATEGORY' => $title_img,
622  'PHOTO' => $title_nb,
623  'TITLE' => $picture['current']['name'],
624  'SRC_IMG' => $picture['current']['src'],
625  'ALT_IMG' => $picture['current']['file'],
626  'WIDTH_IMG' => $picture_size[0],
627  'HEIGHT_IMG' => $picture_size[1],
628
629  'LEVEL_SEPARATOR' => $conf['level_separator'],
630
631  'L_HOME' => $lang['home'],
632  'L_SLIDESHOW' => $lang['slideshow'],
633  'L_STOP_SLIDESHOW' => $lang['slideshow_stop'],
634  'L_PREV_IMG' =>$lang['previous_page'].' : ',
635  'L_NEXT_IMG' =>$lang['next_page'].' : ',
636  'L_ADMIN' =>$lang['link_info_image'],
637  'L_COMMENT_TITLE' =>$lang['comments_title'],
638  'L_ADD_COMMENT' =>$lang['comments_add'],
639  'L_DELETE_COMMENT' =>$lang['comments_del'],
640  'L_DELETE' =>$lang['delete'],
641  'L_SUBMIT' =>$lang['submit'],
642  'L_AUTHOR' =>  $lang['upload_author'],
643  'L_COMMENT' =>$lang['comment'],
644  'L_DOWNLOAD' => $lang['download'],
645  'L_DOWNLOAD_HINT' => $lang['download_hint'],
646  'L_PICTURE_METADATA' => $lang['picture_show_metadata'],
647  'L_PICTURE_HIGH' => $lang['picture_high'],
648  'L_UP_HINT' => $lang['home_hint'],
649  'L_UP_ALT' => $lang['home'],
650
651  'U_HOME' => (PHPWG_ROOT_PATH.'category.php'),
652  'U_UP' => $url_up,
653  'U_METADATA' => $url_metadata,
654  'U_ADMIN' => $url_admin,
655  'U_SLIDESHOW'=> $url_slide,
656  'U_ADD_COMMENT' => str_replace( '&', '&amp;', $_SERVER['REQUEST_URI'] )
657  )
658);
659
660if ($conf['show_picture_name_on_title'])
661{
662  $template->assign_block_vars('title', array());
663}
664
665//------------------------------------------------------- upper menu management
666// download link if file is not a picture
667if (!$picture['current']['is_picture'])
668{
669  $template->assign_block_vars(
670    'download',
671    array('U_DOWNLOAD' => $picture['current']['download']));
672}
673// display a high quality link if present
674if (isset($picture['current']['high']))
675{
676  $uuid = uniqid(rand());
677  $template->assign_block_vars('high', array(
678    'U_HIGH' => $picture['current']['high'],
679    'UUID'=>$uuid
680  ));
681  $template->assign_block_vars(
682    'download',
683    array('U_DOWNLOAD' => PHPWG_ROOT_PATH.'action.php?dwn='
684          .$picture['current']['high']
685    )
686  );
687}
688// button to set the current picture as representative
689if (is_admin() and
690    isset($page['cat']) and is_numeric($page['cat']))
691{
692  $template->assign_block_vars(
693    'representative',
694    array(
695      'URL' =>
696        PHPWG_ROOT_PATH.'picture.php'
697        .get_query_string_diff(array('add_fav'))
698        .'&amp;representative=1'
699      )
700    );
701}
702
703if (is_admin())
704{
705  $template->assign_block_vars(
706    'caddie',
707    array(
708      'URL' =>
709        PHPWG_ROOT_PATH.'picture.php'
710        .get_query_string_diff(array('add_fav')).'&amp;caddie=1')
711    );
712}
713
714//------------------------------------------------------- favorite manipulation
715if ( !$user['is_the_guest'] )
716{
717  // verify if the picture is already in the favorite of the user
718  $query = 'SELECT COUNT(*) AS nb_fav';
719  $query.= ' FROM '.FAVORITES_TABLE.' WHERE image_id = '.$_GET['image_id'];
720  $query.= ' AND user_id = '.$user['id'].';';
721  $result = pwg_query( $query );
722  $row = mysql_fetch_array( $result );
723  if (!$row['nb_fav'])
724  {
725    $url = PHPWG_ROOT_PATH.'picture.php';
726    $url.= get_query_string_diff(array('add_fav'));
727    $url.= '&amp;add_fav=1';
728
729    $template->assign_block_vars(
730      'favorite',
731      array(
732        'FAVORITE_IMG' => get_themeconf('icon_dir').'/favorite.png',
733        'FAVORITE_HINT' =>$lang['add_favorites_hint'],
734        'FAVORITE_ALT' =>$lang['add_favorites_alt'],
735        'U_FAVORITE' => $url
736        ));
737  }
738  else
739  {
740    $url = PHPWG_ROOT_PATH.'picture.php';
741    $url.= get_query_string_diff(array('add_fav'));
742    $url.= '&amp;add_fav=0';
743
744    $template->assign_block_vars(
745      'favorite',
746      array(
747        'FAVORITE_IMG' => get_themeconf('icon_dir').'/del_favorite.png',
748        'FAVORITE_HINT' =>$lang['del_favorites_hint'],
749        'FAVORITE_ALT' =>$lang['del_favorites_alt'],
750        'U_FAVORITE'=> $url
751        ));
752  }
753}
754//------------------------------------ admin link for information modifications
755if ( is_admin() )
756{
757  $template->assign_block_vars('admin', array());
758}
759
760//--------------------------------------------------------- picture information
761// legend
762if (isset($picture['current']['comment'])
763    and !empty($picture['current']['comment']))
764{
765  $template->assign_block_vars(
766    'legend',
767    array(
768      'COMMENT_IMG' => nl2br($picture['current']['comment'])
769      ));
770}
771
772$infos = array();
773
774// author
775if (!empty($picture['current']['author']))
776{
777  $infos['INFO_AUTHOR'] =
778    // FIXME because of search engine partial rewrite, giving the author
779    // name threw GET is not supported anymore. This feature should come
780    // back later, with a better design
781//     '<a href="'.
782//       PHPWG_ROOT_PATH.'category.php?cat=search'.
783//       '&amp;search=author:'.$picture['current']['author']
784//       .'">'.$picture['current']['author'].'</a>';
785    $picture['current']['author'];
786}
787else
788{
789  $infos['INFO_AUTHOR'] = l10n('N/A');
790}
791
792// creation date
793if (!empty($picture['current']['date_creation']))
794{
795  $val = format_date($picture['current']['date_creation']);
796  $infos['INFO_CREATION_DATE'] = '<a href="'.
797       PHPWG_ROOT_PATH.'category.php?calendar=created-c-'.
798       $picture['current']['date_creation'].'">'.$val.'</a>';
799}
800else
801{
802  $infos['INFO_CREATION_DATE'] = l10n('N/A');
803}
804
805// date of availability
806$val = format_date($picture['current']['date_available'], 'mysql_datetime');
807$infos['INFO_POSTED_DATE'] = '<a href="'.
808   PHPWG_ROOT_PATH.'category.php?calendar=posted-c-'.
809   substr($picture['current']['date_available'],0,10).'">'.$val.'</a>';
810
811// size in pixels
812if ($picture['current']['is_picture'])
813{
814  if ($original_width != $picture_size[0]
815      or $original_height != $picture_size[1])
816  {
817    $infos['INFO_DIMENSIONS'] =
818      '<a href="'.$picture['current']['src'].'" title="'.
819      l10n('Original dimensions').'">'.
820      $original_width.'*'.$original_height.'</a>';
821  }
822  else
823  {
824    $infos['INFO_DIMENSIONS'] = $original_width.'*'.$original_height;
825  }
826}
827else
828{
829  $infos['INFO_DIMENSIONS'] = l10n('N/A');
830}
831
832// filesize
833if (!empty($picture['current']['filesize']))
834{
835  $infos['INFO_FILESIZE'] =
836    sprintf(l10n('%d Kb'), $picture['current']['filesize']);
837}
838else
839{
840  $infos['INFO_FILESIZE'] = l10n('N/A');
841}
842
843// number of visits
844$infos['INFO_VISITS'] = $picture['current']['hit'];
845
846// file
847$infos['INFO_FILE'] = $picture['current']['file'];
848
849// keywords
850if (!empty($picture['current']['keywords']))
851{
852  $infos['INFO_KEYWORDS'] =
853    // FIXME because of search engine partial rewrite, giving the author
854    // name threw GET is not supported anymore. This feature should come
855    // back later, with a better design (tag classification).
856//     preg_replace(
857//       '/([^,]+)/',
858//       '<a href="'.
859//         PHPWG_ROOT_PATH.'category.php?cat=search&amp;search=keywords:$1'
860//         .'">$1</a>',
861//       $picture['current']['keywords']
862//       );
863    $picture['current']['keywords'];
864}
865else
866{
867  $infos['INFO_KEYWORDS'] = l10n('N/A');
868}
869
870$template->assign_vars($infos);
871
872// related categories
873foreach ($related_categories as $category)
874{
875  $template->assign_block_vars(
876    'category',
877    array(
878      'LINE' => count($related_categories) > 3
879        ? get_cat_display_name_cache($category['uppercats'])
880        : get_cat_display_name_from_id($category['category_id'])
881      )
882    );
883}
884
885//-------------------------------------------------------------------  metadata
886if ($metadata_showable and isset($_GET['show_metadata']))
887{
888  include_once(PHPWG_ROOT_PATH.'/include/functions_metadata.inc.php');
889  $template->assign_block_vars('metadata', array());
890  if ($conf['show_exif'])
891  {
892    if (!function_exists('read_exif_data'))
893    {
894      die('Exif extension not available, admin should disable exif display');
895    }
896
897    if ($exif = @read_exif_data($picture['current']['src']))
898    {
899      $template->assign_block_vars(
900        'metadata.headline',
901        array('TITLE' => 'EXIF Metadata')
902        );
903
904      foreach ($conf['show_exif_fields'] as $field)
905      {
906        if (strpos($field, ';') === false)
907        {
908          if (isset($exif[$field]))
909          {
910            $key = $field;
911            if (isset($lang['exif_field_'.$field]))
912            {
913              $key = $lang['exif_field_'.$field];
914            }
915
916            $template->assign_block_vars(
917              'metadata.line',
918              array(
919                'KEY' => $key,
920                'VALUE' => $exif[$field]
921                )
922              );
923          }
924        }
925        else
926        {
927          $tokens = explode(';', $field);
928          if (isset($exif[$tokens[0]][$tokens[1]]))
929          {
930            $key = $tokens[1];
931            if (isset($lang['exif_field_'.$tokens[1]]))
932            {
933              $key = $lang['exif_field_'.$tokens[1]];
934            }
935
936            $template->assign_block_vars(
937              'metadata.line',
938              array(
939                'KEY' => $key,
940                'VALUE' => $exif[$tokens[0]][$tokens[1]]
941                )
942              );
943          }
944        }
945      }
946    }
947  }
948  if ($conf['show_iptc'])
949  {
950    $iptc = get_iptc_data($picture['current']['src'],
951                          $conf['show_iptc_mapping']);
952
953    if (count($iptc) > 0)
954    {
955      $template->assign_block_vars(
956        'metadata.headline',
957        array('TITLE' => 'IPTC Metadata')
958        );
959    }
960
961    foreach ($iptc as $field => $value)
962    {
963      $key = $field;
964      if (isset($lang[$field]))
965      {
966        $key = $lang[$field];
967      }
968
969      $template->assign_block_vars(
970        'metadata.line',
971        array(
972          'KEY' => $key,
973          'VALUE' => $value
974          )
975        );
976    }
977  }
978}
979//slideshow end
980if ( isset( $_GET['slideshow'] ) )
981{
982  if ( !is_numeric( $_GET['slideshow'] ) ) $_GET['slideshow'] = $conf['slideshow_period'];
983
984  $template->assign_block_vars('stop_slideshow', array(
985  'U_SLIDESHOW'=>$picture['current']['url']
986  ));
987}
988
989//------------------------------------------------------------------- rating
990if ($conf['rate'])
991{
992  $query = '
993SELECT COUNT(rate) AS count
994     , ROUND(AVG(rate),2) AS average
995     , ROUND(STD(rate),2) AS STD
996  FROM '.RATE_TABLE.'
997  WHERE element_id = '.$picture['current']['id'].'
998;';
999  $row = mysql_fetch_array(pwg_query($query));
1000  if ($row['count'] == 0)
1001  {
1002    $value = $lang['no_rate'];
1003  }
1004  else
1005  {
1006    $value = sprintf(
1007      l10n('%.2f (rated %d times, standard deviation = %.2f)'),
1008      $row['average'],
1009      $row['count'],
1010      $row['STD']
1011      );
1012  }
1013
1014  if ($conf['rate_anonymous'] or !$user['is_the_guest'])
1015  {
1016    if ($row['count']>0)
1017    {
1018      $query = 'SELECT rate
1019      FROM '.RATE_TABLE.'
1020      WHERE element_id = '.$_GET['image_id'] . '
1021      AND user_id = '.$user['id'] ;
1022
1023      if ($user['is_the_guest'])
1024      {
1025        $ip_components = explode('.', $_SERVER['REMOTE_ADDR']);
1026        if ( count($ip_components)>3 )
1027        {
1028          array_pop($ip_components);
1029        }
1030        $anonymous_id = implode ('.', $ip_components);
1031        $query .= ' AND anonymous_id = \''.$anonymous_id . '\'';
1032      }
1033
1034      $result = pwg_query($query);
1035      if (mysql_num_rows($result) > 0)
1036      {
1037        $row = mysql_fetch_array($result);
1038        $sentence = $lang['already_rated'];
1039        $sentence.= ' ('.$row['rate'].'). ';
1040        $sentence.= $lang['update_rate'];
1041      }
1042      else
1043      {
1044        $sentence = $lang['never_rated'].'. '.$lang['Rate'];
1045      }
1046    }
1047    else
1048    {
1049      $sentence = $lang['never_rated'].'. '.$lang['Rate'];
1050    }
1051    $template->assign_block_vars(
1052      'rate',
1053      array(
1054        'CONTENT' => $value,
1055        'SENTENCE' => $sentence
1056        ));
1057
1058    $template->assign_block_vars('info_rate', array('CONTENT' => $value));
1059
1060    $template->assign_vars(
1061      array(
1062        'INFO_RATE' => $value
1063        )
1064      );
1065
1066    foreach ($rate_items as $num => $mark)
1067    {
1068      if ($num > 0)
1069      {
1070        $separator = '|';
1071      }
1072      else
1073      {
1074        $separator = '';
1075      }
1076
1077      $url = PHPWG_ROOT_PATH.'picture.php';
1078      $url.= get_query_string_diff(array('add_fav'));
1079      $url.= '&amp;rate='.$mark;
1080
1081      $template->assign_block_vars(
1082        'rate.rate_option',
1083        array(
1084          'OPTION' => $mark,
1085          'URL' => $url,
1086          'SEPARATOR' => $separator
1087          ));
1088    }
1089  }
1090}
1091
1092//---------------------------------------------------- users's comments display
1093
1094// the picture is commentable if it belongs at least to one category which
1095// is commentable
1096$page['show_comments'] = false;
1097foreach ($related_categories as $category)
1098{
1099  if ($category['commentable'] == 'true')
1100  {
1101    $page['show_comments'] = true;
1102  }
1103}
1104
1105if ($page['show_comments'])
1106{
1107  // number of comment for this picture
1108  $query = 'SELECT COUNT(*) AS nb_comments';
1109  $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id'];
1110  $query.= " AND validated = 'true'";
1111  $query.= ';';
1112  $row = mysql_fetch_array( pwg_query( $query ) );
1113
1114  // navigation bar creation
1115  $url = PHPWG_ROOT_PATH.'picture.php';
1116  $url.= get_query_string_diff(array('add_fav','start'));
1117
1118  if (!isset( $_GET['start'] )
1119      or !is_numeric( $_GET['start'] )
1120      or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) )
1121  {
1122    $page['start'] = 0;
1123  }
1124  else
1125  {
1126    $page['start'] = $_GET['start'];
1127  }
1128  $page['navigation_bar'] = create_navigation_bar( $url, $row['nb_comments'],
1129                                                   $page['start'],
1130                                                   $conf['nb_comment_page'],
1131                                                   '' );
1132  $template->assign_block_vars('comments', array(
1133    'NB_COMMENT'=>$row['nb_comments'],
1134    'NAV_BAR'=>$page['navigation_bar']));
1135
1136  if ($row['nb_comments']>0)
1137  {
1138    $query = 'SELECT id,author,date,image_id,content';
1139    $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id'];
1140    $query.= " AND validated = 'true'";
1141    $query.= ' ORDER BY date ASC';
1142    $query.= ' LIMIT '.$page['start'].', '.$conf['nb_comment_page'].';';
1143    $result = pwg_query( $query );
1144
1145    while ( $row = mysql_fetch_array( $result ) )
1146    {
1147      $template->assign_block_vars(
1148        'comments.comment',
1149        array(
1150          'COMMENT_AUTHOR'=>empty($row['author'])?$lang['guest']:$row['author'],
1151          'COMMENT_DATE'=>format_date($row['date'], 'mysql_datetime', true),
1152    'COMMENT'=>parse_comment_content($row['content'])
1153    ));
1154
1155      if ( is_admin() )
1156      {
1157        $template->assign_block_vars(
1158          'comments.comment.delete',
1159          array('U_COMMENT_DELETE'=> $url.'&amp;del='.$row['id']
1160            ));
1161      }
1162    }
1163  }
1164
1165  if (!$user['is_the_guest']
1166      or ($user['is_the_guest'] and $conf['comments_forall']))
1167  {
1168    $template->assign_block_vars('comments.add_comment', array());
1169    // display author field if the user is not logged in
1170    if (!$user['is_the_guest'])
1171    {
1172      $template->assign_block_vars(
1173        'comments.add_comment.author_known',
1174        array('KNOWN_AUTHOR'=>$user['username'])
1175        );
1176    }
1177    else
1178    {
1179      $template->assign_block_vars(
1180        'comments.add_comment.author_field', array()
1181        );
1182    }
1183  }
1184}
1185//------------------------------------------------------------ log informations
1186pwg_log( 'picture', $title_img, $picture['current']['file'] );
1187
1188$template->parse('picture');
1189include(PHPWG_ROOT_PATH.'include/page_tail.php');
1190?>
Note: See TracBrowser for help on using the repository browser.