source: trunk/picture.php @ 511

Last change on this file since 511 was 511, checked in by z0rglub, 20 years ago
  • refactoring
  • adaptation of the URL for searching associated keywords to the new search URL string
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 26.5 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// |                              picture.php                              |
4// +-----------------------------------------------------------------------+
5// | application   : PhpWebGallery <http://phpwebgallery.net>              |
6// | branch        : BSF (Best So Far)                                     |
7// +-----------------------------------------------------------------------+
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-09-01 21:56:24 +0000 (Wed, 01 Sep 2004) $
10// | last modifier : $Author: z0rglub $
11// | revision      : $Revision: 511 $
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 = 'UPDATE '.IMAGES_TABLE.' SET hit=hit+1';
41$query.= ' WHERE id='.$_GET['image_id'];
42$query.= ';';
43@mysql_query( $query );
44//-------------------------------------------------------------- initialization
45initialize_category( 'picture' );
46// retrieving the number of the picture in its category (in order)
47$query = '
48SELECT DISTINCT(id)
49  FROM '.IMAGES_TABLE.'
50    INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
51  '.$page['where'].'
52  '.$conf['order_by'].'
53;';
54$result = mysql_query( $query );
55$page['num'] = 0;
56$belongs = false;
57while ($row = mysql_fetch_array($result))
58{
59  if ($row['id'] == $_GET['image_id'])
60  {
61    $belongs = true;
62    break;
63  }
64  $page['num']++;
65}
66// if this image_id doesn't correspond to this category, an error message is
67// displayed, and execution is stopped
68if (!$belongs)
69{
70  echo '<div style="text-align:center;">'.$lang['access_forbiden'].'<br />';
71  echo '<a href="'.add_session_id( PHPWG_ROOT_PATH.'category.php' ).'">';
72  echo $lang['thumbnails'].'</a></div>';
73  exit();
74}
75//------------------------------------- prev, current & next picture management
76$picture = array();
77
78if ($page['num'] == 0)
79{
80  $has_prev = false;
81}
82else
83{
84  $has_prev = true;
85}
86
87if ($page['num'] == $page['cat_nb_images'] - 1)
88{
89  $has_next = false;
90}
91else
92{
93  $has_next = true;
94}
95
96$query = '
97SELECT *
98  FROM '.IMAGES_TABLE.'
99    INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id=ic.image_id
100  '.$page['where'].'
101  '.$conf['order_by'].'
102  ';
103
104if ( !$has_prev )
105{
106  $query.= ' LIMIT 0,2';
107}
108else
109{
110  $query.= ' LIMIT '.($page['num'] - 1).',3';
111}
112$query.= ';';
113
114$result = mysql_query( $query );
115$indexes = array('prev', 'current', 'next');
116
117foreach (array('prev', 'current', 'next') as $i)
118{
119  if ($i == 'prev' and !$has_prev)
120  {
121    continue;
122  }
123  if ($i == 'next' and !$has_next)
124  {
125    break;
126  }
127
128  $row = mysql_fetch_array($result);
129  foreach (array_keys($row) as $key)
130  {
131    if (!is_numeric($key))
132    {
133      $picture[$i][$key] = $row[$key];
134    }
135  }
136
137  $picture[$i]['is_picture'] = false;
138  if (in_array(get_extension($row['file']), $conf['picture_ext']))
139  {
140    $picture[$i]['is_picture'] = true;
141  }
142 
143  if ( !isset($array_cat_directories[$row['storage_category_id']]))
144  {
145    $array_cat_directories[$row['storage_category_id']] =
146      get_complete_dir( $row['storage_category_id'] );
147  }
148  $cat_directory = $array_cat_directories[$row['storage_category_id']];
149  $file_wo_ext = get_filename_wo_extension($row['file']);
150
151  $icon = './template/'.$user['template'].'/mimetypes/';
152  $icon.= strtolower(get_extension($row['file'])).'.png';
153
154  if (isset($row['representative_ext']) and $row['representative_ext'] =! '')
155  {
156    $picture[$i]['src'] = $cat_directory.'representative/';
157    $picture[$i]['src'].= $file_wo_ext.'.'.$row['representative_ext'];
158  }
159  else
160  {
161    $picture[$i]['src'] = $icon;
162  }
163  // special case for picture files
164  if ($picture[$i]['is_picture'])
165  {
166    $picture[$i]['src'] = $cat_directory.$row['file'];
167  }
168
169  // if picture is not a file, we need the download link
170  if (!$picture[$i]['is_picture'])
171  {
172    $picture[$i]['download'] = $cat_directory.$row['file'];
173  }
174
175  if (isset($row['tn_ext']) and $row['tn_ext'] != '')
176  {
177    $picture[$i]['thumbnail'] = $cat_directory.'thumbnail/';
178    $picture[$i]['thumbnail'].= $conf['prefix_thumbnail'].$file_wo_ext;
179    $picture[$i]['thumbnail'].= '.'.$row['tn_ext'];
180  }
181  else
182  {
183    $picture[$i]['thumbnail'] = $icon;
184  }
185 
186  if ( !empty( $row['name'] ) )
187  {
188    $picture[$i]['name'] = $row['name'];
189  }
190  else
191  {
192    $picture[$i]['name'] = str_replace('_', ' ', $file_wo_ext);
193  }
194
195  $picture[$i]['url'] = PHPWG_ROOT_PATH.'picture.php';
196  $picture[$i]['url'].= get_query_string_diff(array('image_id','add_fav'));
197  $picture[$i]['url'].= '&amp;image_id='.$row['id'];
198}
199
200$url_home = PHPWG_ROOT_PATH.'category.php?cat='.$page['cat'].'&amp;';
201$url_home.= 'num='.$page['num']; 
202if ( $page['cat'] == 'search' )
203{
204  $url_home.= "&amp;search=".$_GET['search'];
205}
206
207$url_admin = PHPWG_ROOT_PATH.'admin.php?page=picture_modify';
208$url_admin.= '&amp;cat_id='.$page['cat'];
209$url_admin.= '&amp;image_id='.$_GET['image_id'];
210//----------------------------------------------------------- rate registration
211if (isset($_GET['rate'])
212    and $conf['rate']
213    and !$user['is_the_guest']
214    and in_array($_GET['rate'], $rate_items))
215{
216  $query = '
217DELETE
218  FROM '.RATE_TABLE.'
219  WHERE user_id = '.$user['id'].'
220    AND element_id = '.$_GET['image_id'].'
221;';
222  mysql_query($query);
223  $query = '
224INSERT INTO '.RATE_TABLE.'
225  (user_id,element_id,rate)
226  VALUES
227  ('.$user['id'].','.$_GET['image_id'].','.$_GET['rate'].')
228;';
229  mysql_query($query);
230
231  // update of images.average_rate field
232  $query = '
233SELECT ROUND(AVG(rate),2) AS average_rate
234  FROM '.RATE_TABLE.'
235  WHERE element_id = '.$_GET['image_id'].'
236;';
237  $row = mysql_fetch_array(mysql_query($query));
238  $query = '
239UPDATE '.IMAGES_TABLE.'
240  SET average_rate = '.$row['average_rate'].'
241  WHERE id = '.$_GET['image_id'].'
242;';
243  mysql_query($query);
244}
245//--------------------------------------------------------- favorite management
246if ( isset( $_GET['add_fav'] ) )
247{
248  $query = 'DELETE FROM '.FAVORITES_TABLE;
249  $query.= ' WHERE user_id = '.$user['id'];
250  $query.= ' AND image_id = '.$picture['current']['id'];
251  $query.= ';';
252  $result = mysql_query( $query );
253 
254  if ( $_GET['add_fav'] == 1 )
255  {
256    $query = 'INSERT INTO '.FAVORITES_TABLE;
257    $query.= ' (image_id,user_id) VALUES';
258    $query.= ' ('.$picture['current']['id'].','.$user['id'].')';
259    $query.= ';';
260    $result = mysql_query( $query );
261  }
262  if ( !$_GET['add_fav'] and $page['cat'] == 'fav' )
263  {
264    if (!$has_prev and $mysql_num_rows == 1)
265    {
266      // there is no favorite picture anymore we redirect the user to the
267      // category page
268      $url = add_session_id( $url_home );
269      redirect( $url );
270    }
271    else if (!$has_prev)
272    {
273      $url = str_replace( '&amp;', '&', $picture['next']['url'] );
274      $url = add_session_id( $url, true);
275    }
276    else
277    {
278      $url = str_replace('&amp;', '&', $picture['prev']['url'] );
279      $url = add_session_id( $url, true);
280    }
281    redirect( $url );
282  }
283}
284
285//------------------------------------------------------  comment registeration
286if ( isset( $_POST['content'] ) && !empty($_POST['content']) )
287{
288  $register_comment = true;
289  $author = !empty($_POST['author'])?$_POST['author']:$lang['guest'];
290  // if a guest try to use the name of an already existing user, he must be
291  // rejected
292  if ( $author != $user['username'] )
293  {
294    $query = 'SELECT COUNT(*) AS user_exists';
295    $query.= ' FROM '.USERS_TABLE;
296    $query.= " WHERE username = '".$author."'";
297    $query.= ';';
298    $row = mysql_fetch_array( mysql_query( $query ) );
299    if ( $row['user_exists'] == 1 )
300    {
301      $template->assign_block_vars(
302        'information',
303        array('INFORMATION'=>$lang['comment_user_exists']));
304      $register_comment = false;
305    }
306  }
307 
308  if ( $register_comment )
309  {
310    // anti-flood system
311    $reference_date = time() - $conf['anti-flood_time'];
312    $query = 'SELECT id FROM '.COMMENTS_TABLE;
313    $query.= ' WHERE date > FROM_UNIXTIME('.$reference_date.')';
314    $query.= " AND author = '".$author."'";
315    $query.= ';';
316    if ( mysql_num_rows( mysql_query( $query ) ) == 0
317         or $conf['anti-flood_time'] == 0 )
318    {
319      $query = 'INSERT INTO '.COMMENTS_TABLE;
320      $query.= ' (author,date,image_id,content,validated) VALUES (';
321      $query.= "'".$author."'";
322      $query.= ',NOW(),'.$_GET['image_id'];
323      $query.= ",'".htmlspecialchars( $_POST['content'], ENT_QUOTES)."'";
324      if ( !$conf['comments_validation'] or $user['status'] == 'admin' )
325      {       
326        $query.= ",'true'";
327      }
328      else
329      {
330        $query.= ",'false'";
331      }
332      $query.= ');';
333      mysql_query( $query );
334      // information message
335      $message = $lang['comment_added'];
336      if ( $conf['comments_validation'] and $user['status'] != 'admin' )
337      {
338        $message.= '<br />'.$lang['comment_to_validate'];
339      }
340      $template->assign_block_vars('information',
341                                   array('INFORMATION'=>$message));
342      // notification to the administrators
343      if ( $conf['mail_notification'] )
344      {
345        $cat_name = get_cat_display_name( $page['cat_name'], ' > ', '' );
346        $cat_name = strip_tags( $cat_name );
347        notify( 'comment', $cat_name.' > '.$picture['current']['name']);
348      }
349    }
350    else
351    {
352      // information message
353      $template->assign_block_vars(
354        'information',
355        array('INFORMATION'=>$lang['comment_anti-flood']));
356    }
357  }
358}
359// comment deletion
360if ( isset( $_GET['del'] )
361     and is_numeric( $_GET['del'] )
362     and $user['status'] == 'admin' )
363{
364  $query = 'DELETE FROM '.COMMENTS_TABLE;
365  $query.= ' WHERE id = '.$_GET['del'];
366  $query.= ';';
367  mysql_query( $query );
368}
369
370//
371// Start output of page
372//
373
374$title =  $picture['current']['name'];
375$refresh = 0;
376if ( isset( $_GET['slideshow'] ) and $next )
377{
378  $refresh= $_GET['slideshow'];
379  $url_link = $picture['next']['url'].'&amp;slideshow='.$refresh;
380}
381
382$title_img = $picture['current']['name'];
383$title_nb = '';
384if (is_numeric( $page['cat'] )) 
385{
386  $title_img = replace_space(get_cat_display_name( $page['cat_name'], " &gt; "));
387  $n = $page['num'] + 1;
388  $title_nb = "Photo".' '.$n.'/';
389  $title_nb.= $page['cat_nb_images'];
390  //$title_img.= $picture['current']['name'];
391}
392else if ( $page['cat'] == 'search' )
393{
394  $title_img = replace_search( $title_img, $_GET['search'] );
395}
396
397// calculation of width and height
398if (empty($picture['current']['width']))
399{
400  $taille_image = @getimagesize($picture['current']['src']);
401  $original_width = $taille_image[0];
402  $original_height = $taille_image[1];
403}
404else
405{
406  $original_width = $picture['current']['width'];
407  $original_height = $picture['current']['height'];
408}
409
410$picture_size = get_picture_size( $original_width, $original_height,
411                                  $user['maxwidth'], $user['maxheight'] );
412                                 
413include(PHPWG_ROOT_PATH.'include/page_header.php');
414$template->set_filenames(array('picture'=>'picture.tpl'));
415
416$template->assign_vars(array(
417  'CATEGORY' => $title_img,
418  'PHOTO' => $title_nb,
419  'TITLE' => $picture['current']['name'],
420  'SRC_IMG' => $picture['current']['src'],
421  'ALT_IMG' => $picture['current']['file'],
422  'WIDTH_IMG' => $picture_size[0],
423  'HEIGHT_IMG' => $picture_size[1],
424
425  'L_SLIDESHOW' => $lang['slideshow'],
426  'L_TIME' => $lang['period_seconds'],
427  'L_STOP_SLIDESHOW' => $lang['slideshow_stop'],
428  'L_PREV_IMG' =>$lang['previous_image'].' : ',
429  'L_ADMIN' =>$lang['link_info_image'],
430  'L_BACK' =>$lang['back'],
431  'L_COMMENT_TITLE' =>$lang['comments_title'],
432  'L_ADD_COMMENT' =>$lang['comments_add'],
433  'L_DELETE_COMMENT' =>$lang['comments_del'],
434  'L_DELETE' =>$lang['delete'],
435  'L_SUBMIT' =>$lang['submit'],
436  'L_AUTHOR' =>$lang['author'],
437  'L_COMMENT' =>$lang['comment'],
438  'L_DOWNLOAD' => $lang['download'],
439  'L_DOWNLOAD_HINT' => $lang['download_hint'],
440  'L_PICTURE_SHOW_METADATA' => $lang['picture_show_metadata'],
441  'L_PICTURE_HIDE_METADATA' => $lang['picture_hide_metadata'],
442 
443  'T_DEL_IMG' =>PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/delete.gif',
444 
445  'U_HOME' => add_session_id($url_home),
446  'U_ADMIN' => add_session_id($url_admin),
447  'U_ADD_COMMENT' => add_session_id(str_replace( '&', '&amp;', $_SERVER['REQUEST_URI'] ))
448  )
449);
450
451//-------------------------------------------------------- slideshow management
452if ( isset( $_GET['slideshow'] ) )
453{
454  if ( !is_numeric( $_GET['slideshow'] ) ) $_GET['slideshow'] = $conf['slideshow_period'][0];
455       
456  $template->assign_block_vars('stop_slideshow', array(
457  'U_SLIDESHOW'=>add_session_id( $picture['current']['url'] )
458  ));
459}
460else
461{
462  $template->assign_block_vars('start_slideshow', array());
463  foreach ( $conf['slideshow_period'] as $option ) 
464  {
465    $template->assign_block_vars('start_slideshow.second', array(
466          'SLIDESHOW_SPEED'=>$option,
467          'U_SLIDESHOW'=>add_session_id( $picture['current']['url'].'&amp;slideshow='.$option)
468          ));
469  }
470}
471
472if ($has_prev)
473{
474  $template->assign_block_vars(
475    'previous',
476    array(
477      'TITLE_IMG' => $picture['prev']['name'],
478      'IMG' => $picture['prev']['thumbnail'],
479      'U_IMG' => add_session_id($picture['prev']['url'])
480      ));
481}
482
483if ($has_next)
484{
485  $template->assign_block_vars(
486    'next',
487    array(
488      'TITLE_IMG' => $picture['next']['name'],
489      'IMG' => $picture['next']['thumbnail'],
490      'U_IMG' => add_session_id($picture['next']['url'])
491      ));
492}
493
494//--------------------------------------------------------- picture information
495// legend
496if (isset($picture['current']['comment'])
497    and !empty($picture['current']['comment']))
498{
499  $template->assign_block_vars(
500    'legend',
501    array(
502        'COMMENT_IMG' => $picture['current']['comment']
503      ));
504}
505// download link if file is not a picture
506if (!$picture['current']['is_picture'])
507{
508  $template->assign_block_vars(
509    'download',
510    array(
511        'U_DOWNLOAD' => $picture['current']['download']
512      ));
513}
514
515// author
516if ( !empty($picture['current']['author']) )
517{
518  $template->assign_block_vars(
519    'info_line',
520    array(
521      'INFO'=>$lang['author'],
522      'VALUE'=>$picture['current']['author']
523      ));
524}
525// creation date
526if ( !empty($picture['current']['date_creation']) )
527{
528  $template->assign_block_vars('info_line', array(
529          'INFO'=>$lang['creation_date'],
530          'VALUE'=>format_date( $picture['current']['date_creation'] ) 
531          ));
532}
533// date of availability
534$template->assign_block_vars('info_line', array(
535          'INFO'=>$lang['registration_date'],
536          'VALUE'=>format_date( $picture['current']['date_available'] ) 
537          ));
538// size in pixels
539if ($picture['current']['is_picture'])
540{
541  if ($original_width != $picture_size[0]
542      or $original_height != $picture_size[1])
543  {
544    $content = '[ <a href="'.$picture['current']['url'].'" ';
545    $content.= ' title="'.$lang['true_size'].'">';
546    $content.= $original_width.'*'.$original_height.'</a> ]';
547  }
548  else
549  {
550    $content = $original_width.'*'.$original_height;
551  }
552  $template->assign_block_vars(
553    'info_line',
554    array(
555      'INFO'=>$lang['size'],
556      'VALUE'=>$content 
557      ));
558}
559// file
560$template->assign_block_vars('info_line', array(
561          'INFO'=>$lang['file'],
562          'VALUE'=>$picture['current']['file'] 
563          ));
564// filesize
565if (empty($picture['current']['filesize']))
566{
567  if (!$picture['current']['is_picture'])
568  {
569    $filesize = floor(filesize($picture['current']['download'])/1024);
570  }
571  else
572  {
573    $filesize = floor(filesize($picture['current']['src'])/1024);
574  }
575}
576else
577{
578  $filesize = $picture['current']['filesize'];
579}
580
581$template->assign_block_vars('info_line', array(
582          'INFO'=>$lang['filesize'],
583          'VALUE'=>$filesize.' KB'
584          ));
585// keywords
586if (!empty($picture['current']['keywords']))
587{
588  $keywords = explode(',', $picture['current']['keywords']);
589  $content = '';
590  $url = PHPWG_ROOT_PATH.'category.php?cat=search&amp;search=keywords:';
591  foreach ($keywords as $i => $keyword)
592  {
593    $local_url = add_session_id($url.$keyword);
594    if ($i > 0)
595    {
596      $content.= ',';
597    }
598    $content.= '<a href="'.$local_url.'">'.$keyword.'</a>';
599  }
600  $template->assign_block_vars(
601    'info_line',
602    array(
603      'INFO'=>$lang['keywords'],
604      'VALUE'=>$content
605      ));
606}
607// number of visits
608$template->assign_block_vars(
609  'info_line',
610  array(
611    'INFO'=>$lang['visited'],
612    'VALUE'=>$picture['current']['hit'].' '.$lang['times']
613    ));
614// rate results
615if ($conf['rate'])
616{
617  $query = '
618SELECT COUNT(rate) AS count
619     , ROUND(AVG(rate),2) AS average
620     , ROUND(STD(rate),2) AS STD
621  FROM '.RATE_TABLE.'
622  WHERE element_id = '.$picture['current']['id'].'
623;';
624  $row = mysql_fetch_array(mysql_query($query));
625  if ($row['count'] == 0)
626  {
627    $value = $lang['no_rate'];
628  }
629  else
630  {
631    $value = $row['average'];
632    $value.= ' (';
633    $value.= $row['count'].' '.$lang['rates'];
634    $value.= ', '.$lang['standard_deviation'].' : '.$row['STD'];
635    $value.= ')';
636  }
637 
638  $template->assign_block_vars(
639    'info_line',
640    array(
641      'INFO'  => $lang['element_rate'],
642      'VALUE' => $value
643      ));
644}
645//-------------------------------------------------------------------- metadata
646if ($conf['show_exif'] or $conf['show_iptc'])
647{
648  $metadata_showable = true;
649}
650else
651{
652  $metadata_showable = false;
653}
654
655if ($metadata_showable and !isset($_GET['show_metadata']))
656{
657  $url = PHPWG_ROOT_PATH.'picture.php?'.$_SERVER['QUERY_STRING'];
658  $url.= '&amp;show_metadata=1';
659  $template->assign_block_vars('show_metadata', array('URL' => $url));
660}
661
662if ($metadata_showable and isset($_GET['show_metadata']))
663{
664  $url = PHPWG_ROOT_PATH.'picture.php';
665  $url.= get_query_string_diff(array('show_metadata','add_fav'));
666 
667  $template->assign_block_vars('hide_metadata', array('URL' => $url));
668 
669  include_once(PHPWG_ROOT_PATH.'/include/functions_metadata.inc.php');
670 
671  $template->assign_block_vars('metadata', array());
672 
673  if ($conf['show_exif'])
674  {
675    if ($exif = @read_exif_data($picture['current']['src']))
676    {
677      $template->assign_block_vars(
678        'metadata.headline',
679        array('TITLE' => 'EXIF Metadata')
680        );
681     
682      foreach ($conf['show_exif_fields'] as $field)
683      {
684        if (strpos($field, ';') === false)
685        {
686          if (isset($exif[$field]))
687          {
688            $key = $field;
689            if (isset($lang['exif_field_'.$field]))
690            {
691              $key = $lang['exif_field_'.$field];
692            }
693           
694            $template->assign_block_vars(
695              'metadata.line',
696              array(
697                'KEY' => $key,
698                'VALUE' => $exif[$field]
699                )
700              );
701          }
702        }
703        else
704        {
705          $tokens = explode(';', $field);
706          if (isset($exif[$tokens[0]][$tokens[1]]))
707          {
708            $key = $tokens[1];
709            if (isset($lang['exif_field_'.$tokens[1]]))
710            {
711              $key = $lang['exif_field_'.$tokens[1]];
712            }
713           
714            $template->assign_block_vars(
715              'metadata.line',
716              array(
717                'KEY' => $key,
718                'VALUE' => $exif[$tokens[0]][$tokens[1]]
719                )
720              );
721          }
722        }
723      }
724    }
725  }
726
727  if ($conf['show_iptc'])
728  {
729    $iptc = get_iptc_data($picture['current']['src'],
730                          $conf['show_iptc_mapping']);
731
732    if (count($iptc) > 0)
733    {
734      $template->assign_block_vars(
735        'metadata.headline',
736        array('TITLE' => 'IPTC Metadata')
737        );
738    }
739   
740    foreach ($iptc as $field => $value)
741    {
742      $key = $field;
743      if (isset($lang[$field]))
744      {
745        $key = $lang[$field];
746      }
747     
748      $template->assign_block_vars(
749        'metadata.line',
750        array(
751          'KEY' => $key,
752          'VALUE' => $value
753          )
754        );
755    }
756  }
757}
758//------------------------------------------------------------------- rate form
759if ($conf['rate'])
760{
761  $query = '
762SELECT rate
763  FROM '.RATE_TABLE.'
764  WHERE user_id = '.$user['id'].'
765    AND element_id = '.$_GET['image_id'].'
766;';
767  $result = mysql_query($query);
768  if (mysql_num_rows($result) > 0)
769  {
770    $row = mysql_fetch_array($result);
771    $sentence = $lang['already_rated'];
772    $sentence.= ' ('.$row['rate'].'). ';
773    $sentence.= $lang['update_rate'];
774  }
775  else
776  {
777    $sentence = $lang['never_rated'].'. '.$lang['to_rate'];
778  }
779  $template->assign_block_vars(
780    'rate',
781    array('SENTENCE' => $sentence)
782    );
783 
784 
785  foreach ($rate_items as $num => $mark)
786  {
787    if ($num > 0)
788    {
789      $separator = '|';
790    }
791    else
792    {
793      $separator = '';
794    }
795
796    $url = PHPWG_ROOT_PATH.'picture.php';
797    $url.= get_query_string_diff(array('rate','add_fav'));
798    $url.= '&amp;rate='.$mark;
799   
800    $template->assign_block_vars(
801      'rate.rate_option',
802      array(
803        'OPTION' => $mark,
804        'URL' => $url,
805        'SEPARATOR' => $separator
806        ));
807  }
808}
809//------------------------------------------------------- favorite manipulation
810if ( !$user['is_the_guest'] )
811{
812  // verify if the picture is already in the favorite of the user
813  $query = 'SELECT COUNT(*) AS nb_fav';
814  $query.= ' FROM '.FAVORITES_TABLE.' WHERE image_id = '.$_GET['image_id'];
815  $query.= ' AND user_id = '.$user['id'].';';
816  $result = mysql_query( $query );
817  $row = mysql_fetch_array( $result );
818  if (!$row['nb_fav'])
819  {
820    $url = PHPWG_ROOT_PATH.'picture.php';
821    $url.= get_query_string_diff(array('rate','add_fav'));
822    $url.= '&amp;add_fav=1';
823
824    $template->assign_block_vars(
825      'favorite',
826      array(
827        'FAVORITE_IMG' => PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/favorite.gif',
828        'FAVORITE_HINT' =>$lang['add_favorites_hint'],
829        'FAVORITE_ALT' =>'[ '.$lang['add_favorites_alt'].' ]',
830        'U_FAVORITE' => $url
831        ));
832  }
833  else
834  {
835    $url = PHPWG_ROOT_PATH.'picture.php';
836    $url.= get_query_string_diff(array('rate','add_fav'));
837    $url.= '&amp;add_fav=0';
838   
839    $template->assign_block_vars(
840      'favorite',
841      array(
842        'FAVORITE_IMG' => PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/del_favorite.gif',
843        'FAVORITE_HINT' =>$lang['del_favorites_hint'],
844        'FAVORITE_ALT' =>'[ '.$lang['del_favorites_alt'].' ]',
845        'U_FAVORITE'=> $url
846        ));
847  }
848}
849//------------------------------------ admin link for information modifications
850if ( $user['status'] == 'admin' )
851{
852  $template->assign_block_vars('modification', array());
853}
854
855//---------------------------------------------------- users's comments display
856if ( $conf['show_comments'] )
857{
858  // number of comment for this picture
859  $query = 'SELECT COUNT(*) AS nb_comments';
860  $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id'];
861  $query.= " AND validated = 'true'";
862  $query.= ';';
863  $row = mysql_fetch_array( mysql_query( $query ) );
864 
865  // navigation bar creation
866  $url = PHPWG_ROOT_PATH.'picture.php';
867  $url.= get_query_string_diff(array('rate','add_fav'));
868
869  if (!isset( $_GET['start'] )
870      or !is_numeric( $_GET['start'] )
871      or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) )
872  {
873    $page['start'] = 0;
874  }
875  else
876  {
877    $page['start'] = $_GET['start'];
878  }
879  $page['navigation_bar'] = create_navigation_bar( $url, $row['nb_comments'],
880                                                   $page['start'],
881                                                   $conf['nb_comment_page'],
882                                                   '' );
883  $template->assign_block_vars('comments', array(
884    'NB_COMMENT'=>$row['nb_comments'],
885    'NAV_BAR'=>$page['navigation_bar']));
886
887  $query = 'SELECT id,author,date,image_id,content';
888  $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id'];
889  $query.= " AND validated = 'true'";
890  $query.= ' ORDER BY date ASC';
891  $query.= ' LIMIT '.$page['start'].', '.$conf['nb_comment_page'].';';
892  $result = mysql_query( $query );
893               
894  while ( $row = mysql_fetch_array( $result ) )
895  {
896    $content = nl2br( $row['content'] );
897
898    // replace _word_ by an underlined word
899    $pattern = '/_([^\s]*)_/';
900    $replacement = '<span style="text-decoration:underline;">\1</span>';
901    $content = preg_replace( $pattern, $replacement, $content );
902
903    // replace *word* by a bolded word
904    $pattern = '/\*([^\s]*)\*/';
905    $replacement = '<span style="font-weight:bold;">\1</span>';
906    $content = preg_replace( $pattern, $replacement, $content );
907
908    // replace /word/ by an italic word
909    $pattern = '/\/([^\s]*)\//';
910    $replacement = '<span style="font-style:italic;">\1</span>';
911    $content = preg_replace( $pattern, $replacement, $content );
912       
913    $template->assign_block_vars('comments.comment', array(
914    'COMMENT_AUTHOR'=>empty($row['author'])?$lang['guest']:$row['author'],
915    'COMMENT_DATE'=>format_date( $row['date'], 'mysql_datetime', true ),
916        'COMMENT'=>$content
917        ));
918       
919    if ( $user['status'] == 'admin' )
920    {
921          $template->assign_block_vars('comments.comment.delete', array('U_COMMENT_DELETE'=>add_session_id( $url.'&amp;del='.$row['id'] )));
922    }
923  }
924
925  if ( !$user['is_the_guest']||( $user['is_the_guest'] and $conf['comments_forall'] ) )
926  {
927    $template->assign_block_vars('comments.add_comment', array());
928    // display author field if the user is not logged in
929    if ( !$user['is_the_guest'] )
930    {
931      $template->assign_block_vars('comments.add_comment.author_known', array('KNOWN_AUTHOR'=>$user['username']));
932        }
933    else
934    {
935      $template->assign_block_vars('comments.add_comment.author_field', array());
936    }
937  }
938}
939//------------------------------------------------------------ log informations
940pwg_log( 'picture', $title_img, $picture['current']['file'] );
941mysql_close();
942
943$template->pparse('picture');
944include(PHPWG_ROOT_PATH.'include/page_tail.php');
945?>
Note: See TracBrowser for help on using the repository browser.