source: trunk/picture.php @ 1014

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

improvement: got rid of num= _GET param in category.php (use only start=) so
that links to category for search engines are the same as in category
pagination

feature 77: standard navigation link : HTML Link types

improvement: add go to first and last image buttons in picture page

improvement: do not increase image hit in picture.php when rating, adding to
favorites, caddie, ...

improvement: show number of hits in most_visited (as best_rated shows the rate)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 30.8 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-01-27 01:11:43 +0000 (Fri, 27 Jan 2006) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1014 $
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    // FIXME : with remote pictures, this "remote fopen" takes long...
251    if ($i == 'current')
252    {
253      if (@fopen($cat_directory.'/pwg_high/'.$row['file'], 'r'))
254      {
255        $picture[$i]['high'] = $cat_directory.'/pwg_high/'.$row['file'];
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';
529include(PHPWG_ROOT_PATH.'include/page_header.php');
530$template->set_filenames(array('picture'=>'picture.tpl'));
531
532$template->assign_vars(array(
533  'CATEGORY' => $title_img,
534  'PHOTO' => $title_nb,
535  'TITLE' => $picture['current']['name'],
536  'SRC_IMG' => $picture['current']['src'],
537  'ALT_IMG' => $picture['current']['file'],
538  'WIDTH_IMG' => $picture_size[0],
539  'HEIGHT_IMG' => $picture_size[1],
540
541  'LEVEL_SEPARATOR' => $conf['level_separator'],
542
543  'L_HOME' => $lang['home'],
544  'L_SLIDESHOW' => $lang['slideshow'],
545  'L_STOP_SLIDESHOW' => $lang['slideshow_stop'],
546  'L_PREV_IMG' =>$lang['previous_page'].' : ',
547  'L_NEXT_IMG' =>$lang['next_page'].' : ',
548  'L_ADMIN' =>$lang['link_info_image'],
549  'L_COMMENT_TITLE' =>$lang['comments_title'],
550  'L_ADD_COMMENT' =>$lang['comments_add'],
551  'L_DELETE_COMMENT' =>$lang['comments_del'],
552  'L_DELETE' =>$lang['delete'],
553  'L_SUBMIT' =>$lang['submit'],
554  'L_AUTHOR' =>  $lang['upload_author'],
555  'L_COMMENT' =>$lang['comment'],
556  'L_DOWNLOAD' => $lang['download'],
557  'L_DOWNLOAD_HINT' => $lang['download_hint'],
558  'L_PICTURE_METADATA' => $lang['picture_show_metadata'],
559  'L_PICTURE_HIGH' => $lang['picture_high'],
560  'L_UP_HINT' => $lang['home_hint'],
561  'L_UP_ALT' => $lang['home'],
562 
563  'U_HOME' => (PHPWG_ROOT_PATH.'category.php'),
564  'U_UP' => $url_up,
565  'U_METADATA' => $url_metadata,
566  'U_ADMIN' => $url_admin,
567  'U_SLIDESHOW'=> $url_slide,
568  'U_ADD_COMMENT' => str_replace( '&', '&amp;', $_SERVER['REQUEST_URI'] )
569  )
570);
571
572if ($conf['show_picture_name_on_title'])
573{
574  $template->assign_block_vars('title', array());
575}
576
577//------------------------------------------------------- upper menu management
578// download link if file is not a picture
579if (!$picture['current']['is_picture'])
580{
581  $template->assign_block_vars(
582    'download',
583    array('U_DOWNLOAD' => $picture['current']['download']));
584}
585// display a high quality link if present
586if (isset($picture['current']['high']))
587{
588  $full_size = @getimagesize($picture['current']['high']);
589  $full_width = $full_size[0];
590  $full_height = $full_size[1];
591  $uuid = uniqid(rand());
592  $template->assign_block_vars('high', array(
593    'U_HIGH' => $picture['current']['high'],
594        'UUID'=>$uuid,
595        'WIDTH_IMG'=>($full_width + 40),
596        'HEIGHT_IMG'=>($full_height + 40)
597        ));
598  $template->assign_block_vars(
599    'download',
600    array('U_DOWNLOAD' => PHPWG_ROOT_PATH.'action.php?dwn='
601          .$picture['current']['high']
602    )
603  );
604}
605// button to set the current picture as representative
606if ('admin' == $user['status'] and is_numeric($page['cat']))
607{
608  $template->assign_block_vars(
609    'representative',
610    array(
611      'URL' =>
612        PHPWG_ROOT_PATH.'picture.php'
613        .get_query_string_diff(array())
614        .'&amp;representative=1'
615      )
616    );
617}
618
619if ('admin' == $user['status'])
620{
621  $template->assign_block_vars(
622    'caddie',
623    array(
624      'URL' =>
625        PHPWG_ROOT_PATH.'picture.php'
626        .get_query_string_diff(array('caddie')).'&amp;caddie=1')
627    );
628}
629
630//------------------------------------------------------- favorite manipulation
631if ( !$user['is_the_guest'] )
632{
633  // verify if the picture is already in the favorite of the user
634  $query = 'SELECT COUNT(*) AS nb_fav';
635  $query.= ' FROM '.FAVORITES_TABLE.' WHERE image_id = '.$_GET['image_id'];
636  $query.= ' AND user_id = '.$user['id'].';';
637  $result = pwg_query( $query );
638  $row = mysql_fetch_array( $result );
639  if (!$row['nb_fav'])
640  {
641    $url = PHPWG_ROOT_PATH.'picture.php';
642    $url.= get_query_string_diff(array('rate','add_fav'));
643    $url.= '&amp;add_fav=1';
644
645    $template->assign_block_vars(
646      'favorite',
647      array(
648        'FAVORITE_IMG' => get_themeconf('icon_dir').'/favorite.png',
649        'FAVORITE_HINT' =>$lang['add_favorites_hint'],
650        'FAVORITE_ALT' =>$lang['add_favorites_alt'],
651        'U_FAVORITE' => $url
652        ));
653  }
654  else
655  {
656    $url = PHPWG_ROOT_PATH.'picture.php';
657    $url.= get_query_string_diff(array('rate','add_fav'));
658    $url.= '&amp;add_fav=0';
659   
660    $template->assign_block_vars(
661      'favorite',
662      array(
663        'FAVORITE_IMG' => get_themeconf('icon_dir').'/del_favorite.png',
664        'FAVORITE_HINT' =>$lang['del_favorites_hint'],
665        'FAVORITE_ALT' =>$lang['del_favorites_alt'],
666        'U_FAVORITE'=> $url
667        ));
668  }
669}
670//------------------------------------ admin link for information modifications
671if ( $user['status'] == 'admin' )
672{
673  $template->assign_block_vars('admin', array());
674}
675
676//-------------------------------------------------------- navigation management
677if ($has_prev)
678{
679  $template->assign_block_vars(
680    'previous',
681    array(
682      'TITLE_IMG' => $picture['prev']['name'],
683      'IMG' => $picture['prev']['thumbnail'],
684      'U_IMG' => $picture['prev']['url'],
685      'U_IMG_SRC' => $picture['prev']['src']
686      ));
687}
688
689if ($has_next)
690{
691  $template->assign_block_vars(
692    'next',
693    array(
694      'TITLE_IMG' => $picture['next']['name'],
695      'IMG' => $picture['next']['thumbnail'],
696      'U_IMG' => $picture['next']['url'],
697      'U_IMG_SRC' => $picture['next']['src'] // allow navigator to preload
698      ));
699}
700
701//--------------------------------------------------------- picture information
702// legend
703if (isset($picture['current']['comment'])
704    and !empty($picture['current']['comment']))
705{
706  $template->assign_block_vars(
707    'legend',
708    array(
709      'COMMENT_IMG' => nl2br($picture['current']['comment'])
710      ));
711}
712
713$infos = array();
714
715// author
716if (!empty($picture['current']['author']))
717{
718  $infos['INFO_AUTHOR'] =
719    // FIXME because of search engine partial rewrite, giving the author
720    // name threw GET is not supported anymore. This feature should come
721    // back later, with a better design
722//     '<a href="'.
723//       PHPWG_ROOT_PATH.'category.php?cat=search'.
724//       '&amp;search=author:'.$picture['current']['author']
725//       .'">'.$picture['current']['author'].'</a>';
726    $picture['current']['author'];
727}
728else
729{
730  $infos['INFO_AUTHOR'] = l10n('N/A');
731}
732
733// creation date
734if (!empty($picture['current']['date_creation']))
735{
736  $infos['INFO_CREATION_DATE'] =
737    // FIXME because of search engine partial rewrite, giving the author
738    // name threw GET is not supported anymore. This feature should come
739    // back later, with a better design (calendar view).
740//     '<a href="'.
741//       PHPWG_ROOT_PATH.'category.php?cat=search'.
742//       '&amp;search=date_creation:'.$picture['current']['date_creation']
743//       .'">'.format_date($picture['current']['date_creation']).'</a>';
744    format_date($picture['current']['date_creation']);
745}
746else
747{
748  $infos['INFO_CREATION_DATE'] = l10n('N/A');
749}
750
751// date of availability
752$infos['INFO_AVAILABILITY_DATE'] =
753// FIXME because of search engine partial rewrite, giving the author
754// name threw GET is not supported anymore. This feature should come
755// back later, with a better design (calendar view).
756//
757//   '<a href="'.
758//     PHPWG_ROOT_PATH.'category.php?cat=search'.
759//     '&amp;search=date_available:'.
760//     substr($picture['current']['date_available'], 0, 10)
761//     .'">'.
762//   format_date($picture['current']['date_available'], 'mysql_datetime').
763//   '</a>';
764format_date($picture['current']['date_available'], 'mysql_datetime');
765
766// size in pixels
767if ($picture['current']['is_picture'])
768{
769  if ($original_width != $picture_size[0]
770      or $original_height != $picture_size[1])
771  {
772    $infos['INFO_DIMENSIONS'] =
773      '<a href="'.$picture['current']['src'].'" title="'.
774      l10n('Original dimensions').'">'.
775      $original_width.'*'.$original_height.'</a>';
776  }
777  else
778  {
779    $infos['INFO_DIMENSIONS'] = $original_width.'*'.$original_height;
780  }
781}
782else
783{
784  $infos['INFO_DIMENSIONS'] = l10n('N/A');
785}
786
787// filesize
788if (!empty($picture['current']['filesize']))
789{
790  $infos['INFO_FILESIZE'] =
791    sprintf(l10n('%d Kb'), $picture['current']['filesize']);
792}
793else
794{
795  $infos['INFO_FILESIZE'] = l10n('N/A');
796}
797
798// number of visits
799$infos['INFO_VISITS'] = $picture['current']['hit'];
800
801// file
802$infos['INFO_FILE'] = $picture['current']['file'];
803
804// keywords
805if (!empty($picture['current']['keywords']))
806{
807  $infos['INFO_KEYWORDS'] =
808    // FIXME because of search engine partial rewrite, giving the author
809    // name threw GET is not supported anymore. This feature should come
810    // back later, with a better design (tag classification).
811//     preg_replace(
812//       '/([^,]+)/',
813//       '<a href="'.
814//         PHPWG_ROOT_PATH.'category.php?cat=search&amp;search=keywords:$1'
815//         .'">$1</a>',
816//       $picture['current']['keywords']
817//       );
818    $picture['current']['keywords'];
819}
820else
821{
822  $infos['INFO_KEYWORDS'] = l10n('N/A');
823}
824
825$template->assign_vars($infos);
826
827// related categories
828foreach ($related_categories as $category)
829{
830  $template->assign_block_vars(
831    'category',
832    array(
833      'LINE' => count($related_categories) > 3
834        ? get_cat_display_name_cache($category['uppercats'])
835        : get_cat_display_name_from_id($category['category_id'])
836      )
837    );
838}
839
840//-------------------------------------------------------------------  metadata
841if ($metadata_showable and isset($_GET['show_metadata']))
842{
843  include_once(PHPWG_ROOT_PATH.'/include/functions_metadata.inc.php');
844  $template->assign_block_vars('metadata', array());
845  if ($conf['show_exif'])
846  {
847    if (!function_exists('read_exif_data'))
848    {
849      die('Exif extension not available, admin should disable exif display');
850    }
851   
852    if ($exif = @read_exif_data($picture['current']['src']))
853    {
854      $template->assign_block_vars(
855        'metadata.headline',
856        array('TITLE' => 'EXIF Metadata')
857        );
858
859      foreach ($conf['show_exif_fields'] as $field)
860      {
861        if (strpos($field, ';') === false)
862        {
863          if (isset($exif[$field]))
864          {
865            $key = $field;
866            if (isset($lang['exif_field_'.$field]))
867            {
868              $key = $lang['exif_field_'.$field];
869            }
870           
871            $template->assign_block_vars(
872              'metadata.line',
873              array(
874                'KEY' => $key,
875                'VALUE' => $exif[$field]
876                )
877              );
878          }
879        }
880        else
881        {
882          $tokens = explode(';', $field);
883          if (isset($exif[$tokens[0]][$tokens[1]]))
884          {
885            $key = $tokens[1];
886            if (isset($lang['exif_field_'.$tokens[1]]))
887            {
888              $key = $lang['exif_field_'.$tokens[1]];
889            }
890           
891            $template->assign_block_vars(
892              'metadata.line',
893              array(
894                'KEY' => $key,
895                'VALUE' => $exif[$tokens[0]][$tokens[1]]
896                )
897              );
898          }
899        }
900      }
901    }
902  }
903  if ($conf['show_iptc'])
904  {
905    $iptc = get_iptc_data($picture['current']['src'],
906                          $conf['show_iptc_mapping']);
907
908    if (count($iptc) > 0)
909    {
910      $template->assign_block_vars(
911        'metadata.headline',
912        array('TITLE' => 'IPTC Metadata')
913        );
914    }
915   
916    foreach ($iptc as $field => $value)
917    {
918      $key = $field;
919      if (isset($lang[$field]))
920      {
921        $key = $lang[$field];
922      }
923     
924      $template->assign_block_vars(
925        'metadata.line',
926        array(
927          'KEY' => $key,
928          'VALUE' => $value
929          )
930        );
931    }
932  }
933}
934//slideshow end
935if ( isset( $_GET['slideshow'] ) )
936{
937  if ( !is_numeric( $_GET['slideshow'] ) ) $_GET['slideshow'] = $conf['slideshow_period'];
938       
939  $template->assign_block_vars('stop_slideshow', array(
940  'U_SLIDESHOW'=>$picture['current']['url']
941  ));
942}
943
944//------------------------------------------------------------------- rating
945if ($conf['rate'])
946{
947  $query = '
948SELECT COUNT(rate) AS count
949     , ROUND(AVG(rate),2) AS average
950     , ROUND(STD(rate),2) AS STD
951  FROM '.RATE_TABLE.'
952  WHERE element_id = '.$picture['current']['id'].'
953;';
954  $row = mysql_fetch_array(pwg_query($query));
955  if ($row['count'] == 0)
956  {
957    $value = $lang['no_rate'];
958  }
959  else
960  {
961    $value = sprintf(
962      l10n('%.2f (rated %d times, standard deviation = %.2f)'),
963      $row['average'],
964      $row['count'],
965      $row['STD']
966      );
967  }
968 
969  if (!$user['is_the_guest'])
970  {
971    $query = 'SELECT rate
972    FROM '.RATE_TABLE.'
973    WHERE user_id = '.$user['id'].'
974    AND element_id = '.$_GET['image_id'].';';
975  $result = pwg_query($query);
976  if (mysql_num_rows($result) > 0)
977  {
978    $row = mysql_fetch_array($result);
979    $sentence = $lang['already_rated'];
980    $sentence.= ' ('.$row['rate'].'). ';
981    $sentence.= $lang['update_rate'];
982  }
983  else
984  {
985    $sentence = $lang['never_rated'].'. '.$lang['to_rate'];
986  } 
987  $template->assign_block_vars(
988    'rate',
989    array(
990      'CONTENT' => $value,
991      'SENTENCE' => $sentence
992      ));
993
994  $template->assign_block_vars('info_rate', array('CONTENT' => $value));
995 
996  $template->assign_vars(
997    array(
998      'INFO_RATE' => $value
999      )
1000    );
1001 
1002  foreach ($rate_items as $num => $mark)
1003  {
1004    if ($num > 0)
1005    {
1006      $separator = '|';
1007    }
1008    else
1009    {
1010      $separator = '';
1011    }
1012
1013    $url = PHPWG_ROOT_PATH.'picture.php';
1014    $url.= get_query_string_diff(array('rate','add_fav'));
1015    $url.= '&amp;rate='.$mark;
1016   
1017    $template->assign_block_vars(
1018      'rate.rate_option',
1019      array(
1020        'OPTION' => $mark,
1021        'URL' => $url,
1022        'SEPARATOR' => $separator
1023        ));
1024    }
1025  }
1026}
1027
1028//---------------------------------------------------- users's comments display
1029
1030// the picture is commentable if it belongs at least to one category which
1031// is commentable
1032$page['show_comments'] = false;
1033foreach ($related_categories as $category)
1034{
1035  if ($category['commentable'] == 'true')
1036  {
1037    $page['show_comments'] = true;
1038  }
1039}
1040
1041if ($page['show_comments'])
1042{
1043  // number of comment for this picture
1044  $query = 'SELECT COUNT(*) AS nb_comments';
1045  $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id'];
1046  $query.= " AND validated = 'true'";
1047  $query.= ';';
1048  $row = mysql_fetch_array( pwg_query( $query ) );
1049 
1050  // navigation bar creation
1051  $url = PHPWG_ROOT_PATH.'picture.php';
1052  $url.= get_query_string_diff(array('rate','add_fav'));
1053
1054  if (!isset( $_GET['start'] )
1055      or !is_numeric( $_GET['start'] )
1056      or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) )
1057  {
1058    $page['start'] = 0;
1059  }
1060  else
1061  {
1062    $page['start'] = $_GET['start'];
1063  }
1064  $page['navigation_bar'] = create_navigation_bar( $url, $row['nb_comments'],
1065                                                   $page['start'],
1066                                                   $conf['nb_comment_page'],
1067                                                   '' );
1068  $template->assign_block_vars('comments', array(
1069    'NB_COMMENT'=>$row['nb_comments'],
1070    'NAV_BAR'=>$page['navigation_bar']));
1071
1072  $query = 'SELECT id,author,date,image_id,content';
1073  $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id'];
1074  $query.= " AND validated = 'true'";
1075  $query.= ' ORDER BY date ASC';
1076  $query.= ' LIMIT '.$page['start'].', '.$conf['nb_comment_page'].';';
1077  $result = pwg_query( $query );
1078               
1079  while ( $row = mysql_fetch_array( $result ) )
1080  {
1081    $template->assign_block_vars(
1082      'comments.comment',
1083      array(
1084        'COMMENT_AUTHOR'=>empty($row['author'])?$lang['guest']:$row['author'],
1085        'COMMENT_DATE'=>format_date($row['date'], 'mysql_datetime', true),
1086        'COMMENT'=>parse_comment_content($row['content'])
1087        ));
1088       
1089    if ( $user['status'] == 'admin' )
1090    {
1091      $template->assign_block_vars(
1092        'comments.comment.delete',
1093        array('U_COMMENT_DELETE'=> $url.'&amp;del='.$row['id']
1094          ));
1095    }
1096  }
1097
1098  if (!$user['is_the_guest']
1099      or ($user['is_the_guest'] and $conf['comments_forall']))
1100  {
1101    $template->assign_block_vars('comments.add_comment', array());
1102    // display author field if the user is not logged in
1103    if (!$user['is_the_guest'])
1104    {
1105      $template->assign_block_vars(
1106        'comments.add_comment.author_known',
1107        array('KNOWN_AUTHOR'=>$user['username'])
1108        );
1109    }
1110    else
1111    {
1112      $template->assign_block_vars(
1113        'comments.add_comment.author_field', array()
1114        );
1115    }
1116  }
1117}
1118//------------------------------------------------------------ log informations
1119pwg_log( 'picture', $title_img, $picture['current']['file'] );
1120
1121$template->parse('picture');
1122include(PHPWG_ROOT_PATH.'include/page_tail.php');
1123?>
Note: See TracBrowser for help on using the repository browser.