source: trunk/picture.php @ 1029

Last change on this file since 1029 was 1029, checked in by rvelices, 18 years ago
  • remake of Remote sites and Synchronize:
    • synchronization for remote and local sites are done by the same code
    • remote sites can update metadata now (not before) - bug 279
    • fixes bug 82: has_high column
  • improve feature 280: user sort by filename
  • fix path to template mimetypes icons
  • bug 284: session cookie lifetime, deletion on logout and corrected issue

when db upgrades were missing

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