source: trunk/picture.php @ 1036

Last change on this file since 1036 was 1036, checked in by plg, 18 years ago

improvement: $pagewhere string replaced by $pageitems.
$pagewhere was an SQL clause used to retrieve pictures in #images
table. $pageitems is the list of picture ids of the current section.

improvement: function initialize_category replaced by dedicated included PHP
script include/section_init.inc.php. Code was refactored to improve
readibility and maintenability. $pagenavigation_bar is now build in
category.php instead of initialize_category function. Function check_cat_id
was also replaced by a piece of code in the new file. The file to include to
display thumbnails from category.php is now set in section_init.inc.php
instead of calculated in category.php.

bug fix: the test for rel="up" link for standard HTML navigation links in
category menu was not working with non numeric categories, such as
"favorites".

improvement: function check_login_authorization removed because useless but
in profile.php.

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