source: trunk/picture.php @ 1078

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

Step 1 improvement issue 0000127:

o Add field enabled_high of table #_user_infos
o Add $confnewuser_default_enabled_high
o Used field on picture.php

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