source: trunk/picture.php @ 801

Last change on this file since 801 was 801, checked in by plg, 19 years ago
  • new feature : RSS notification feed. Feed generator is an external tool (FeedCreator class v1.7.2). New file feed.php
  • new database field : comments.validation_date (datetime). This field is required for notification feed.
  • new database field : users.feed_id (varchar(50)). users.feed_id is an alias of users.id but is much more complicated to find (50 characters, figures or letters, case sensitive) : the purpose is to keep it secret (as far as possible).
  • new database field : users.last_feed_check (datetime)
  • new database field : users.registration_date (datetime)
  • bug fixed : no need to add the (unavailable) session id to install.php in the installation form.
  • modified database field : images.date_available become more precise (date to datetime). This precision is needed for notification feed.
  • new index : comments_i1 (validation_date). Might be useful for feed queries.
  • new index : comments_i2 (image_id). Useful each time you want to have informations about an element and its associated comments.
  • version 9.11 of mysqldump outputs database field names and table names with backquote "`" (didn't find how to take them off)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 28.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: 2005-07-16 14:29:35 +0000 (Sat, 16 Jul 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 801 $
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'] );
34check_login_authorization();
35if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) )
36{
37  check_restrictions( $page['cat'] );
38}
39//---------------------------------------- incrementation of the number of hits
40$query = '
41UPDATE '.IMAGES_TABLE.'
42  SET hit = hit+1
43  WHERE id = '.$_GET['image_id'].'
44;';
45@pwg_query( $query );
46//-------------------------------------------------------------- initialization
47initialize_category( 'picture' );
48// retrieving the number of the picture in its category (in order)
49$query = '
50SELECT DISTINCT(id)
51  FROM '.IMAGES_TABLE.'
52    INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
53  '.$page['where'].'
54  '.$conf['order_by'].'
55;';
56$result = pwg_query( $query );
57$page['num'] = 0;
58$belongs = false;
59while ($row = mysql_fetch_array($result))
60{
61  if ($row['id'] == $_GET['image_id'])
62  {
63    $belongs = true;
64    break;
65  }
66  $page['num']++;
67}
68// if this image_id doesn't correspond to this category, an error message is
69// displayed, and execution is stopped
70if (!$belongs)
71{
72  echo '<div style="text-align:center;">'.$lang['access_forbiden'].'<br />';
73  echo '<a href="'.add_session_id( PHPWG_ROOT_PATH.'category.php' ).'">';
74  echo $lang['thumbnails'].'</a></div>';
75  exit();
76}
77//---------------------------------------------------------- related categories
78$query = '
79SELECT category_id,uppercats,commentable,global_rank
80  FROM '.IMAGE_CATEGORY_TABLE.'
81    INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id
82  WHERE image_id = '.$_GET['image_id'];
83if ($user['forbidden_categories'] != '')
84{
85  $query.= '
86    AND category_id NOT IN ('.$user['forbidden_categories'].')';
87}
88$query.= '
89;';
90$result = pwg_query($query);
91$related_categories = array();
92while ($row = mysql_fetch_array($result))
93{
94  array_push($related_categories, $row);
95}
96usort($related_categories, 'global_rank_compare');
97//------------------------------------- prev, current & next picture management
98$picture = array();
99
100if ($page['num'] == 0)
101{
102  $has_prev = false;
103}
104else
105{
106  $has_prev = true;
107}
108
109if ($page['num'] == $page['cat_nb_images'] - 1)
110{
111  $has_next = false;
112}
113else
114{
115  $has_next = true;
116}
117
118$query = '
119SELECT DISTINCT(i.id), i.*
120  FROM '.IMAGES_TABLE.' AS i
121    INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON i.id = ic.image_id
122  '.$page['where'].'
123  '.$conf['order_by'].'
124  ';
125
126if ( !$has_prev )
127{
128  $query.= ' LIMIT 0,2';
129}
130else
131{
132  $query.= ' LIMIT '.($page['num'] - 1).',3';
133}
134$query.= ';';
135
136$result = pwg_query( $query );
137$indexes = array('prev', 'current', 'next');
138
139foreach (array('prev', 'current', 'next') as $i)
140{
141  if ($i == 'prev' and !$has_prev)
142  {
143    continue;
144  }
145  if ($i == 'next' and !$has_next)
146  {
147    break;
148  }
149
150  $row = mysql_fetch_array($result);
151  foreach (array_keys($row) as $key)
152  {
153    if (!is_numeric($key))
154    {
155      $picture[$i][$key] = $row[$key];
156    }
157  }
158
159  $picture[$i]['is_picture'] = false;
160  if (in_array(get_extension($row['file']), $conf['picture_ext']))
161  {
162    $picture[$i]['is_picture'] = true;
163  }
164 
165  $cat_directory = dirname($row['path']);
166  $file_wo_ext = get_filename_wo_extension($row['file']);
167
168  $icon = PHPWG_ROOT_PATH.'template/'.$user['template'].'/mimetypes/';
169  $icon.= strtolower(get_extension($row['file'])).'.png';
170
171  if (isset($row['representative_ext']) and $row['representative_ext'] != '')
172  {
173    $picture[$i]['src'] = $cat_directory.'/pwg_representative/';
174    $picture[$i]['src'].= $file_wo_ext.'.'.$row['representative_ext'];
175  }
176  else
177  {
178    $picture[$i]['src'] = $icon;
179  }
180  // special case for picture files
181  if ($picture[$i]['is_picture'])
182  {
183    $picture[$i]['src'] = $row['path'];
184    // if we are working on the "current" element, we search if there is a
185    // high quality picture
186    // FIXME : with remote pictures, this "remote fopen" takes long...
187    if ($i == 'current')
188    {
189      if (@fopen($cat_directory.'/pwg_high/'.$row['file'], 'r'))
190      {
191        $picture[$i]['high'] = $cat_directory.'/pwg_high/'.$row['file'];
192      }
193    }
194  }
195
196  // if picture is not a file, we need the download link
197  if (!$picture[$i]['is_picture'])
198  {
199    $picture[$i]['download'] = $row['path'];
200  }
201
202  $picture[$i]['thumbnail'] = get_thumbnail_src($row['path'], @$row['tn_ext']);
203 
204  if ( !empty( $row['name'] ) )
205  {
206    $picture[$i]['name'] = $row['name'];
207  }
208  else
209  {
210    $picture[$i]['name'] = str_replace('_', ' ', $file_wo_ext);
211  }
212
213  $picture[$i]['url'] = PHPWG_ROOT_PATH.'picture.php';
214  $picture[$i]['url'].= get_query_string_diff(array('image_id','add_fav',
215                                                    'slideshow','rate'));
216  $picture[$i]['url'].= '&amp;image_id='.$row['id'];
217}
218
219$url_up = PHPWG_ROOT_PATH.'category.php?cat='.$page['cat'].'&amp;';
220$url_up.= 'num='.$page['num']; 
221if ( $page['cat'] == 'search' )
222{
223  $url_up.= "&amp;search=".$_GET['search'];
224}
225if ( $page['cat'] == 'list' )
226{
227  $url_up.= "&amp;list=".$_GET['list'];
228}
229
230$url_admin = PHPWG_ROOT_PATH.'admin.php?page=picture_modify';
231$url_admin.= '&amp;cat_id='.$page['cat'];
232$url_admin.= '&amp;image_id='.$_GET['image_id'];
233
234$url_slide = $picture['current']['url'];
235$url_slide.= '&amp;slideshow='.$conf['slideshow_period'];
236//----------------------------------------------------------- rate registration
237if (isset($_GET['rate'])
238    and $conf['rate']
239    and !$user['is_the_guest']
240    and in_array($_GET['rate'], $rate_items))
241{
242  $query = '
243DELETE
244  FROM '.RATE_TABLE.'
245  WHERE user_id = '.$user['id'].'
246    AND element_id = '.$_GET['image_id'].'
247;';
248  pwg_query($query);
249  $query = '
250INSERT INTO '.RATE_TABLE.'
251  (user_id,element_id,rate)
252  VALUES
253  ('.$user['id'].','.$_GET['image_id'].','.$_GET['rate'].')
254;';
255  pwg_query($query);
256
257  // update of images.average_rate field
258  $query = '
259SELECT ROUND(AVG(rate),2) AS average_rate
260  FROM '.RATE_TABLE.'
261  WHERE element_id = '.$_GET['image_id'].'
262;';
263  $row = mysql_fetch_array(pwg_query($query));
264  $query = '
265UPDATE '.IMAGES_TABLE.'
266  SET average_rate = '.$row['average_rate'].'
267  WHERE id = '.$_GET['image_id'].'
268;';
269  pwg_query($query);
270}
271//--------------------------------------------------------- favorite management
272if ( isset( $_GET['add_fav'] ) )
273{
274  $query = 'DELETE FROM '.FAVORITES_TABLE;
275  $query.= ' WHERE user_id = '.$user['id'];
276  $query.= ' AND image_id = '.$picture['current']['id'];
277  $query.= ';';
278  $result = pwg_query( $query );
279 
280  if ( $_GET['add_fav'] == 1 )
281  {
282    $query = 'INSERT INTO '.FAVORITES_TABLE;
283    $query.= ' (image_id,user_id) VALUES';
284    $query.= ' ('.$picture['current']['id'].','.$user['id'].')';
285    $query.= ';';
286    $result = pwg_query( $query );
287  }
288  if ( !$_GET['add_fav'] and $page['cat'] == 'fav' )
289  {
290    if (!$has_prev and !$has_next)
291    {
292      // there is no favorite picture anymore we redirect the user to the
293      // category page
294      $url = add_session_id($url_up);
295      redirect($url);
296    }
297    else if (!$has_prev)
298    {
299      $url = str_replace( '&amp;', '&', $picture['next']['url'] );
300      $url = add_session_id( $url, true);
301    }
302    else
303    {
304      $url = str_replace('&amp;', '&', $picture['prev']['url'] );
305      $url = add_session_id( $url, true);
306    }
307    redirect( $url );
308  }
309}
310
311//------------------------------------------------------  comment registeration
312if ( isset( $_POST['content'] ) && !empty($_POST['content']) )
313{
314  $register_comment = true;
315  $author = !empty($_POST['author'])?$_POST['author']:$lang['guest'];
316  // if a guest try to use the name of an already existing user, he must be
317  // rejected
318  if ( $author != $user['username'] )
319  {
320    $query = 'SELECT COUNT(*) AS user_exists';
321    $query.= ' FROM '.USERS_TABLE;
322    $query.= " WHERE username = '".$author."'";
323    $query.= ';';
324    $row = mysql_fetch_array( pwg_query( $query ) );
325    if ( $row['user_exists'] == 1 )
326    {
327      $template->assign_block_vars(
328        'information',
329        array('INFORMATION'=>$lang['comment_user_exists']));
330      $register_comment = false;
331    }
332  }
333 
334  if ( $register_comment )
335  {
336    // anti-flood system
337    $reference_date = time() - $conf['anti-flood_time'];
338    $query = 'SELECT id FROM '.COMMENTS_TABLE;
339    $query.= ' WHERE date > FROM_UNIXTIME('.$reference_date.')';
340    $query.= " AND author = '".$author."'";
341    $query.= ';';
342    if ( mysql_num_rows( pwg_query( $query ) ) == 0
343         or $conf['anti-flood_time'] == 0 )
344    {
345      list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
346
347      $data = array();
348      $data{'author'} = $author;
349      $data{'date'} = $dbnow;
350      $data{'image_id'} = $_GET['image_id'];
351      $data{'content'} = htmlspecialchars( $_POST['content'], ENT_QUOTES);
352     
353      if (!$conf['comments_validation'] or $user['status'] == 'admin')
354      {
355        $data{'validated'} = 'true';
356        $data{'validation_date'} = $dbnow;
357      }
358      else
359      {
360        $data{'validated'} = 'false';
361      }
362     
363      include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
364      $fields = array('author', 'date', 'image_id', 'content', 'validated',
365                      'validation_date');
366      mass_inserts(COMMENTS_TABLE, $fields, array($data));
367     
368      // information message
369      $message = $lang['comment_added'];
370
371      if (!$conf['comments_validation'] or $user['status'] == 'admin')
372     
373      if ( $conf['comments_validation'] and $user['status'] != 'admin' )
374      {
375        $message.= '<br />'.$lang['comment_to_validate'];
376      }
377      $template->assign_block_vars('information',
378                                   array('INFORMATION'=>$message));
379      // notification to the administrators
380      if ( $conf['mail_notification'] )
381      {
382        // find any related category (can be unreachable to this admin)
383        $category = $related_categories[0];
384        // locally, we change the $conf['level_separator']
385        $conf_separator = $conf['level_separator'];
386        $conf['level_separator'] = ' > ';
387        $cat_name = get_cat_display_name_cache($category['uppercats'],
388                                               '',
389                                               false);
390        $conf['level_separator'] = $conf_separator;
391       
392        $cat_name = strip_tags( $cat_name );
393        notify( 'comment', $cat_name.' > '.$picture['current']['name']);
394      }
395    }
396    else
397    {
398      // information message
399      $template->assign_block_vars(
400        'information',
401        array('INFORMATION'=>$lang['comment_anti-flood']));
402    }
403  }
404}
405// comment deletion
406if ( isset( $_GET['del'] )
407     and is_numeric( $_GET['del'] )
408     and $user['status'] == 'admin' )
409{
410  $query = 'DELETE FROM '.COMMENTS_TABLE;
411  $query.= ' WHERE id = '.$_GET['del'];
412  $query.= ';';
413  pwg_query( $query );
414}
415
416//
417// Start output of page
418//
419
420$title =  $picture['current']['name'];
421$refresh = 0;
422if ( isset( $_GET['slideshow'] ) and $has_next )
423{
424  $refresh= $_GET['slideshow'];
425  $url_link = $picture['next']['url'].'&amp;slideshow='.$refresh;
426}
427
428$title_img = $picture['current']['name'];
429$title_nb = '';
430if (is_numeric( $page['cat'] )) 
431{
432  $title_img = replace_space(get_cat_display_name($page['cat_name']));
433  $n = $page['num'] + 1;
434  $title_nb = $n.'/'.$page['cat_nb_images'];
435}
436else if ( $page['cat'] == 'search' )
437{
438  $title_img = replace_search( $title_img, $_GET['search'] );
439}
440
441// calculation of width and height
442if (empty($picture['current']['width']))
443{
444  $taille_image = @getimagesize($picture['current']['src']);
445  $original_width = $taille_image[0];
446  $original_height = $taille_image[1];
447}
448else
449{
450  $original_width = $picture['current']['width'];
451  $original_height = $picture['current']['height'];
452}
453
454$picture_size = get_picture_size($original_width, $original_height,
455                                 @$user['maxwidth'], @$user['maxheight']);
456
457// metadata
458if ($conf['show_exif'] or $conf['show_iptc'])
459{
460  $metadata_showable = true;
461}
462else
463{
464  $metadata_showable = false;
465}
466
467$url_metadata = PHPWG_ROOT_PATH.'picture.php';
468$url_metadata .=  get_query_string_diff(array('add_fav', 'slideshow', 'show_metadata'));
469if ($metadata_showable and !isset($_GET['show_metadata']))
470{
471  $url_metadata.= '&amp;show_metadata=1';
472}
473
474// author
475$author = $creation_date = $size = $filesize = $lang['unavailable'];
476if ( !empty($picture['current']['author']) )
477{
478  $search_url = PHPWG_ROOT_PATH.'category.php?cat=search';
479  $search_url.= '&amp;search=author:'.$picture['current']['author'];
480 
481  $author = '<a href="';
482  $author .= add_session_id($search_url);
483  $author .= '">'.$picture['current']['author'].'</a>';
484}
485
486// creation date
487if ( !empty($picture['current']['date_creation']) )
488{
489  $creation_date = format_date($picture['current']['date_creation']);
490}
491
492// date of availability
493$availability_date = format_date($picture['current']['date_available'],
494                                 'mysql_datetime');
495
496// size in pixels
497if ($picture['current']['is_picture'])
498{
499  if ($original_width != $picture_size[0]
500      or $original_height != $picture_size[1])
501  {
502    $size = '[ <a href="'.$picture['current']['src'].'" ';
503    $size .= ' title="'.$lang['true_size'].'">';
504    $size .= $original_width.'*'.$original_height.'</a> ]';
505  }
506  else
507  {
508    $size = $original_width.'*'.$original_height;
509  }
510}
511
512// filesize
513if (empty($picture['current']['filesize']))
514{
515  if (!$picture['current']['is_picture'])
516  {
517    $filesize = floor(filesize($picture['current']['download'])/1024);
518  }
519  else
520  {
521    $filesize = floor(filesize($picture['current']['src'])/1024);
522  }
523}
524else
525{
526  $filesize = $picture['current']['filesize'];
527}
528
529// number of visits
530$template->assign_block_vars(
531  'info_line',
532  array(
533    'INFO'=>$lang['visited'],
534    'VALUE'=>$picture['current']['hit'].' '.$lang['times']
535    ));
536                         
537include(PHPWG_ROOT_PATH.'include/page_header.php');
538$template->set_filenames(array('picture'=>'picture.tpl'));
539
540$template->assign_vars(array(
541  'CATEGORY' => $title_img,
542  'PHOTO' => $title_nb,
543  'TITLE' => $picture['current']['name'],
544  'SRC_IMG' => $picture['current']['src'],
545  'ALT_IMG' => $picture['current']['file'],
546  'WIDTH_IMG' => $picture_size[0],
547  'HEIGHT_IMG' => $picture_size[1],
548  'AUTHOR' => $author,
549  'CREATION_DATE' => $creation_date,
550  'AVAILABILITY_DATE' => $availability_date,
551  'SIZE' => $size,
552  'FILE_SIZE' => $filesize,
553
554  'LEVEL_SEPARATOR' => $conf['level_separator'],
555
556  'L_HOME' => $lang['home'],
557  'L_SLIDESHOW' => $lang['slideshow'],
558  'L_STOP_SLIDESHOW' => $lang['slideshow_stop'],
559  'L_PREV_IMG' =>$lang['previous_page'].' : ',
560  'L_NEXT_IMG' =>$lang['next_page'].' : ',
561  'L_ADMIN' =>$lang['link_info_image'],
562  'L_COMMENT_TITLE' =>$lang['comments_title'],
563  'L_ADD_COMMENT' =>$lang['comments_add'],
564  'L_DELETE_COMMENT' =>$lang['comments_del'],
565  'L_DELETE' =>$lang['delete'],
566  'L_SUBMIT' =>$lang['submit'],
567  'L_AUTHOR' =>$lang['author'],
568  'L_COMMENT' =>$lang['comment'],
569  'L_DOWNLOAD' => $lang['download'],
570  'L_DOWNLOAD_HINT' => $lang['download_hint'],
571  'L_PICTURE_METADATA' => $lang['picture_show_metadata'],
572  'L_PICTURE_HIGH' => $lang['picture_high'],
573  'L_UP_HINT' => $lang['home_hint'],
574  'L_UP_ALT' => $lang['home'],
575  'L_CREATION_DATE' => $lang['creation_date'],
576  'L_AVAILABILITY_DATE' => $lang['registration_date'],
577  'L_SIZE' => $lang['size'],
578  'L_FILE' => $lang['file'],
579  'L_FILE_SIZE' => $lang['size'],
580 
581  'U_HOME' => add_session_id(PHPWG_ROOT_PATH.'category.php'),
582  'U_UP' => add_session_id($url_up),
583  'U_METADATA' => add_session_id($url_metadata),
584  'U_ADMIN' => add_session_id($url_admin),
585  'U_SLIDESHOW'=> add_session_id($url_slide),
586  'U_ADD_COMMENT' => add_session_id(str_replace( '&', '&amp;', $_SERVER['REQUEST_URI'] ))
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}
597else
598{
599  $template->assign_block_vars(
600    'ecard',
601    array('U_ECARD' => $picture['current']['url']));
602}
603// display a high quality link if present
604if (isset($picture['current']['high']))
605{
606  $full_size = @getimagesize($picture['current']['high']);
607  $full_width = $full_size[0];
608  $full_height = $full_size[1];
609  $uuid = uniqid(rand());
610  $template->assign_block_vars('high', array(
611    'U_HIGH' => $picture['current']['high'],
612        'UUID'=>$uuid,
613        'WIDTH_IMG'=>($full_width + 16),
614        'HEIGHT_IMG'=>($full_height + 16)
615        ));
616}
617//------------------------------------------------------- favorite manipulation
618if ( !$user['is_the_guest'] )
619{
620  // verify if the picture is already in the favorite of the user
621  $query = 'SELECT COUNT(*) AS nb_fav';
622  $query.= ' FROM '.FAVORITES_TABLE.' WHERE image_id = '.$_GET['image_id'];
623  $query.= ' AND user_id = '.$user['id'].';';
624  $result = pwg_query( $query );
625  $row = mysql_fetch_array( $result );
626  if (!$row['nb_fav'])
627  {
628    $url = PHPWG_ROOT_PATH.'picture.php';
629    $url.= get_query_string_diff(array('rate','add_fav'));
630    $url.= '&amp;add_fav=1';
631
632    $template->assign_block_vars(
633      'favorite',
634      array(
635        'FAVORITE_IMG' => PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/favorite.gif',
636        'FAVORITE_HINT' =>$lang['add_favorites_hint'],
637        'FAVORITE_ALT' =>$lang['add_favorites_alt'],
638        'U_FAVORITE' => $url
639        ));
640  }
641  else
642  {
643    $url = PHPWG_ROOT_PATH.'picture.php';
644    $url.= get_query_string_diff(array('rate','add_fav'));
645    $url.= '&amp;add_fav=0';
646   
647    $template->assign_block_vars(
648      'favorite',
649      array(
650        'FAVORITE_IMG' => PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/del_favorite.gif',
651        'FAVORITE_HINT' =>$lang['del_favorites_hint'],
652        'FAVORITE_ALT' =>$lang['del_favorites_alt'],
653        'U_FAVORITE'=> $url
654        ));
655  }
656}
657//------------------------------------ admin link for information modifications
658if ( $user['status'] == 'admin' )
659{
660  $template->assign_block_vars('admin', array());
661}
662
663//-------------------------------------------------------- navigation management
664if ($has_prev)
665{
666  $template->assign_block_vars(
667    'previous',
668    array(
669      'TITLE_IMG' => $picture['prev']['name'],
670      'IMG' => $picture['prev']['thumbnail'],
671      'U_IMG' => add_session_id($picture['prev']['url'])
672      ));
673}
674
675if ($has_next)
676{
677  $template->assign_block_vars(
678    'next',
679    array(
680      'TITLE_IMG' => $picture['next']['name'],
681      'IMG' => $picture['next']['thumbnail'],
682      'U_IMG' => add_session_id($picture['next']['url'])
683      ));
684}
685
686//--------------------------------------------------------- picture information
687// legend
688if (isset($picture['current']['comment'])
689    and !empty($picture['current']['comment']))
690{
691  $template->assign_block_vars(
692    'legend',
693    array(
694      'COMMENT_IMG' => nl2br($picture['current']['comment'])
695      ));
696}
697
698// keywords
699if (!empty($picture['current']['keywords']))
700{
701  $keywords = explode(',', $picture['current']['keywords']);
702  $content = '';
703  $url = PHPWG_ROOT_PATH.'category.php?cat=search&amp;search=keywords:';
704  foreach ($keywords as $i => $keyword)
705  {
706    $local_url = add_session_id($url.$keyword);
707    if ($i > 0)
708    {
709      $content.= ',';
710    }
711    $content.= '<a href="'.$local_url.'">'.$keyword.'</a>';
712  }
713  $template->assign_block_vars(
714    'keywords',
715    array(
716      'INFO'=>$lang['keywords'],
717      'VALUE'=>$content
718      ));
719}
720
721// related categories
722$cat_output = '';
723$page['show_comments'] = false;
724foreach ($related_categories as $category)
725{
726  if ($cat_output != '')
727  {
728    $cat_output.= '<br />';
729  }
730 
731  if (count($related_categories) > 3)
732  {
733    $cat_output .= get_cat_display_name_cache($category['uppercats']);
734  }
735  else
736  {
737    $cat_info = get_cat_info($category['category_id']);
738    $cat_output .= get_cat_display_name($cat_info['name']);
739  }
740  // the picture is commentable if it belongs at least to one category which
741  // is commentable
742  if ($category['commentable'] == 'true')
743  {
744    $page['show_comments'] = true;
745  }
746}
747$template->assign_block_vars(
748  'associated',
749  array(
750    'INFO'  => $lang['categories'],
751    'VALUE' => $cat_output
752    ));
753
754//-------------------------------------------------------------------  metadata
755if ($metadata_showable and isset($_GET['show_metadata']))
756{
757  include_once(PHPWG_ROOT_PATH.'/include/functions_metadata.inc.php');
758  $template->assign_block_vars('metadata', array());
759  if ($conf['show_exif'])
760  {
761    if (!function_exists('read_exif_data'))
762    {
763      die('Exif extension not available, admin should disable exif display');
764    }
765   
766    if ($exif = @read_exif_data($picture['current']['src']))
767    {
768      $template->assign_block_vars(
769        'metadata.headline',
770        array('TITLE' => 'EXIF Metadata')
771        );
772
773      foreach ($conf['show_exif_fields'] as $field)
774      {
775        if (strpos($field, ';') === false)
776        {
777          if (isset($exif[$field]))
778          {
779            $key = $field;
780            if (isset($lang['exif_field_'.$field]))
781            {
782              $key = $lang['exif_field_'.$field];
783            }
784           
785            $template->assign_block_vars(
786              'metadata.line',
787              array(
788                'KEY' => $key,
789                'VALUE' => $exif[$field]
790                )
791              );
792          }
793        }
794        else
795        {
796          $tokens = explode(';', $field);
797          if (isset($exif[$tokens[0]][$tokens[1]]))
798          {
799            $key = $tokens[1];
800            if (isset($lang['exif_field_'.$tokens[1]]))
801            {
802              $key = $lang['exif_field_'.$tokens[1]];
803            }
804           
805            $template->assign_block_vars(
806              'metadata.line',
807              array(
808                'KEY' => $key,
809                'VALUE' => $exif[$tokens[0]][$tokens[1]]
810                )
811              );
812          }
813        }
814      }
815    }
816  }
817  if ($conf['show_iptc'])
818  {
819    $iptc = get_iptc_data($picture['current']['src'],
820                          $conf['show_iptc_mapping']);
821
822    if (count($iptc) > 0)
823    {
824      $template->assign_block_vars(
825        'metadata.headline',
826        array('TITLE' => 'IPTC Metadata')
827        );
828    }
829   
830    foreach ($iptc as $field => $value)
831    {
832      $key = $field;
833      if (isset($lang[$field]))
834      {
835        $key = $lang[$field];
836      }
837     
838      $template->assign_block_vars(
839        'metadata.line',
840        array(
841          'KEY' => $key,
842          'VALUE' => $value
843          )
844        );
845    }
846  }
847}
848//slideshow end
849if ( isset( $_GET['slideshow'] ) )
850{
851  if ( !is_numeric( $_GET['slideshow'] ) ) $_GET['slideshow'] = $conf['slideshow_period'];
852       
853  $template->assign_block_vars('stop_slideshow', array(
854  'U_SLIDESHOW'=>add_session_id( $picture['current']['url'] )
855  ));
856}
857
858//------------------------------------------------------------------- rating
859if ($conf['rate'])
860{
861  $query = 'SELECT COUNT(rate) AS count
862     , ROUND(AVG(rate),2) AS average
863     , ROUND(STD(rate),2) AS STD
864  FROM '.RATE_TABLE.'
865  WHERE element_id = '.$picture['current']['id'].'
866;';
867  $row = mysql_fetch_array(pwg_query($query));
868  if ($row['count'] == 0)
869  {
870    $value = $lang['no_rate'];
871  }
872  else
873  {
874    $value = $row['average'];
875    $value.= ' (';
876    $value.= $row['count'].' '.$lang['rates'];
877    $value.= ', '.$lang['standard_deviation'].' : '.$row['STD'];
878    $value.= ')';
879  }
880 
881  if (!$user['is_the_guest'])
882  {
883    $query = 'SELECT rate
884    FROM '.RATE_TABLE.'
885    WHERE user_id = '.$user['id'].'
886    AND element_id = '.$_GET['image_id'].';';
887  $result = pwg_query($query);
888  if (mysql_num_rows($result) > 0)
889  {
890    $row = mysql_fetch_array($result);
891    $sentence = $lang['already_rated'];
892    $sentence.= ' ('.$row['rate'].'). ';
893    $sentence.= $lang['update_rate'];
894  }
895  else
896  {
897    $sentence = $lang['never_rated'].'. '.$lang['to_rate'];
898  } 
899  $template->assign_block_vars(
900    'rate',
901    array(
902      'INFO'  => $lang['element_rate'],
903      'VALUE' => $value,
904      'SENTENCE' => $sentence
905      ));
906 
907  foreach ($rate_items as $num => $mark)
908  {
909    if ($num > 0)
910    {
911      $separator = '|';
912    }
913    else
914    {
915      $separator = '';
916    }
917
918    $url = PHPWG_ROOT_PATH.'picture.php';
919    $url.= get_query_string_diff(array('rate','add_fav'));
920    $url.= '&amp;rate='.$mark;
921   
922    $template->assign_block_vars(
923      'rate.rate_option',
924      array(
925        'OPTION' => $mark,
926        'URL' => $url,
927        'SEPARATOR' => $separator
928        ));
929    }
930  }
931}
932
933//---------------------------------------------------- users's comments display
934if ($page['show_comments'])
935{
936  // number of comment for this picture
937  $query = 'SELECT COUNT(*) AS nb_comments';
938  $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id'];
939  $query.= " AND validated = 'true'";
940  $query.= ';';
941  $row = mysql_fetch_array( pwg_query( $query ) );
942 
943  // navigation bar creation
944  $url = PHPWG_ROOT_PATH.'picture.php';
945  $url.= get_query_string_diff(array('rate','add_fav'));
946
947  if (!isset( $_GET['start'] )
948      or !is_numeric( $_GET['start'] )
949      or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) )
950  {
951    $page['start'] = 0;
952  }
953  else
954  {
955    $page['start'] = $_GET['start'];
956  }
957  $page['navigation_bar'] = create_navigation_bar( $url, $row['nb_comments'],
958                                                   $page['start'],
959                                                   $conf['nb_comment_page'],
960                                                   '' );
961  $template->assign_block_vars('comments', array(
962    'NB_COMMENT'=>$row['nb_comments'],
963    'NAV_BAR'=>$page['navigation_bar']));
964
965  $query = 'SELECT id,author,date,image_id,content';
966  $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id'];
967  $query.= " AND validated = 'true'";
968  $query.= ' ORDER BY date ASC';
969  $query.= ' LIMIT '.$page['start'].', '.$conf['nb_comment_page'].';';
970  $result = pwg_query( $query );
971               
972  while ( $row = mysql_fetch_array( $result ) )
973  {
974    $template->assign_block_vars(
975      'comments.comment',
976      array(
977        'COMMENT_AUTHOR'=>empty($row['author'])?$lang['guest']:$row['author'],
978        'COMMENT_DATE'=>format_date($row['date'], 'mysql_datetime', true),
979        'COMMENT'=>parse_comment_content($row['content'])
980        ));
981       
982    if ( $user['status'] == 'admin' )
983    {
984      $template->assign_block_vars(
985        'comments.comment.delete',
986        array('U_COMMENT_DELETE'=>add_session_id( $url.'&amp;del='.$row['id'])
987          ));
988    }
989  }
990
991  if (!$user['is_the_guest']
992      or ($user['is_the_guest'] and $conf['comments_forall']))
993  {
994    $template->assign_block_vars('comments.add_comment', array());
995    // display author field if the user is not logged in
996    if (!$user['is_the_guest'])
997    {
998      $template->assign_block_vars(
999        'comments.add_comment.author_known',
1000        array('KNOWN_AUTHOR'=>$user['username'])
1001        );
1002    }
1003    else
1004    {
1005      $template->assign_block_vars(
1006        'comments.add_comment.author_field', array()
1007        );
1008    }
1009  }
1010}
1011//------------------------------------------------------------ log informations
1012pwg_log( 'picture', $title_img, $picture['current']['file'] );
1013mysql_close();
1014
1015$template->parse('picture');
1016include(PHPWG_ROOT_PATH.'include/page_tail.php');
1017?>
Note: See TracBrowser for help on using the repository browser.