source: trunk/picture.php @ 1085

Last change on this file since 1085 was 1085, checked in by rub, 18 years ago

Step 7 improvement issue 0000301:

o can attribute status <= current user
o define mode adviser

=> buttons disabled (gray on IE, not on FF)
=> truncated actions
=> display info mode adviser

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 19.8 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2006-03-16 22:58:16 +0000 (Thu, 16 Mar 2006) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1085 $
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
28define('PHPWG_ROOT_PATH','./');
29include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
30include_once(PHPWG_ROOT_PATH.'include/functions_rate.inc.php');
31include(PHPWG_ROOT_PATH.'include/section_init.inc.php');
32
33// Check Access and exit when user status is not ok
34check_status(ACCESS_GUEST);
35
36// access authorization check
37if (isset($page['category']))
38{
39  check_restrictions($page['category']);
40}
41
42// if this image_id doesn't correspond to this category, an error message is
43// displayed, and execution is stopped
44if (!in_array($page['image_id'], $page['items']))
45{
46  die('Fatal: this picture does not belong to this section');
47}
48
49// +-----------------------------------------------------------------------+
50// |                            initialization                             |
51// +-----------------------------------------------------------------------+
52
53$page['rank_of'] = array_flip($page['items']);
54
55// caching first_rank, last_rank, current_rank in the displayed
56// section. This should also help in readability.
57$page['first_rank']   = 0;
58$page['last_rank']    = count($page['items']) - 1;
59$page['current_rank'] = $page['rank_of'][ $page['image_id'] ];
60
61// caching current item : readability purpose
62$page['current_item'] = $page['image_id'];
63
64if ($page['current_rank'] != $page['first_rank'])
65{
66  // "go to first picture of this section" link is displayed only if the
67  // displayed item is not the first.
68  $template->assign_block_vars(
69    'first',
70    array(
71      'U_IMG' => duplicate_picture_URL(
72        // redefinitions
73        array(
74          'image_id' => $page['items'][ $page['first_rank'] ],
75          ),
76        // removes
77        array()
78        )
79      )
80    );
81
82  // caching previous item : readability purpose
83  $page['previous_item'] = $page['items'][ $page['current_rank'] - 1 ];
84}
85
86if ($page['current_rank'] != $page['last_rank'])
87{
88  // "go to last picture of this section" link is displayed only if the
89  // displayed item is not the last.
90  $template->assign_block_vars(
91    'last',
92    array(
93      'U_IMG' => duplicate_picture_URL(
94        // redefinitions
95        array(
96          'image_id' => $page['items'][ $page['last_rank'] ],
97          ),
98        // removes
99        array()
100        )
101      )
102    );
103
104  // caching next item : readability purpose
105  $page['next_item'] = $page['items'][ $page['current_rank'] + 1 ];
106}
107
108$url_up = duplicate_index_URL(
109  array(
110    'start' =>
111      floor($page['current_rank'] / $user['nb_image_page'])
112      * $user['nb_image_page']
113    ),
114  array(
115    'start',
116    )
117  );
118
119$url_self = duplicate_picture_URL();
120
121// +-----------------------------------------------------------------------+
122// |                                actions                                |
123// +-----------------------------------------------------------------------+
124
125/**
126 * Actions are favorite adding, user comment deletion, setting the picture
127 * as representative of the current category...
128 *
129 * Actions finish by a redirection
130 */
131
132if (isset($_GET['action']))
133{
134  switch ($_GET['action'])
135  {
136    case 'add_to_favorites' :
137    {
138      $query = '
139INSERT INTO '.FAVORITES_TABLE.'
140  (image_id,user_id)
141  VALUES
142  ('.$page['image_id'].','.$user['id'].')
143;';
144      pwg_query($query);
145
146      redirect($url_self);
147     
148      break;
149    }
150    case 'remove_from_favorites' :
151    {
152      $query = '
153DELETE FROM '.FAVORITES_TABLE.'
154  WHERE user_id = '.$user['id'].'
155    AND image_id = '.$page['image_id'].'
156;';
157      pwg_query($query);
158
159      if ('favorites' == $page['section'])
160      {
161        redirect($url_up);
162      }
163      else
164      {
165        redirect($url_self);
166      }
167     
168      break;
169    }
170    case 'set_as_representative' :
171    {
172      if (is_admin() and isset($page['category']) and !is_adviser())
173      {
174        $query = '
175UPDATE '.CATEGORIES_TABLE.'
176  SET representative_picture_id = '.$page['image_id'].'
177  WHERE id = '.$page['category'].'
178;';
179        pwg_query($query);
180      }
181     
182      redirect($url_self);
183 
184      break;
185    }
186    case 'toggle_metadata' :
187    {
188      break;
189    }
190    case 'add_to_caddie' :
191    {
192      if (!is_adviser())
193      {
194        fill_caddie(array($page['image_id']));
195      }
196      redirect($url_self);
197      break;
198    }
199    case 'rate' :
200    {
201      rate_picture($user['id'], $page['image_id'], $_GET['rate']);
202      redirect($url_self);
203    }
204    case 'delete_comment' :
205    {
206      if (isset($_GET['comment_to_delete'])
207          and is_numeric($_GET['comment_to_delete'])
208          and is_admin())
209      {
210        $query = '
211DELETE FROM '.COMMENTS_TABLE.'
212  WHERE id = '.$_GET['comment_to_delete'].'
213;';
214        pwg_query( $query );
215      }
216
217      redirect($url_self);
218    }
219  }
220}
221
222// incrementation of the number of hits, we do this only if no action
223$query = '
224UPDATE
225  '.IMAGES_TABLE.'
226  SET hit = hit+1
227  WHERE id = '.$page['image_id'].'
228;';
229pwg_query($query);
230
231//---------------------------------------------------------- related categories
232$query = '
233SELECT category_id,uppercats,commentable,global_rank
234  FROM '.IMAGE_CATEGORY_TABLE.'
235    INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id
236  WHERE image_id = '.$page['image_id'].'
237    AND category_id NOT IN ('.$user['forbidden_categories'].')
238;';
239$result = pwg_query($query);
240$related_categories = array();
241while ($row = mysql_fetch_array($result))
242{
243  array_push($related_categories, $row);
244}
245usort($related_categories, 'global_rank_compare');
246//------------------------------------- prev, current & next picture management
247$picture = array();
248
249$ids = array($page['image_id']);
250if (isset($page['previous_item']))
251{
252  array_push($ids, $page['previous_item']);
253}
254if (isset($page['next_item']))
255{
256  array_push($ids, $page['next_item']);
257}
258
259$query = '
260SELECT *
261  FROM '.IMAGES_TABLE.'
262  WHERE id IN ('.implode(',', $ids).')
263;';
264
265$result = pwg_query($query);
266
267while ($row = mysql_fetch_array($result))
268{
269  if (isset($page['previous_item']) and $row['id'] == $page['previous_item'])
270  {
271    $i = 'prev';
272  }
273  else if (isset($page['next_item']) and $row['id'] == $page['next_item'])
274  {
275    $i = 'next';
276  }
277  else
278  {
279    $i = 'current';
280  }
281
282  foreach (array_keys($row) as $key)
283  {
284    if (!is_numeric($key))
285    {
286      $picture[$i][$key] = $row[$key];
287    }
288  }
289
290  $picture[$i]['is_picture'] = false;
291  if (in_array(get_extension($row['file']), $conf['picture_ext']))
292  {
293    $picture[$i]['is_picture'] = true;
294  }
295
296  $cat_directory = dirname($row['path']);
297  $file_wo_ext = get_filename_wo_extension($row['file']);
298
299  $icon = get_themeconf('mime_icon_dir');
300  $icon.= strtolower(get_extension($row['file'])).'.png';
301
302  if (isset($row['representative_ext']) and $row['representative_ext'] != '')
303  {
304    $picture[$i]['src'] =
305      $cat_directory.'/pwg_representative/'
306      .$file_wo_ext.'.'.$row['representative_ext'];
307  }
308  else
309  {
310    $picture[$i]['src'] = $icon;
311  }
312  // special case for picture files
313  if ($picture[$i]['is_picture'])
314  {
315    $picture[$i]['src'] = $row['path'];
316    // if we are working on the "current" element, we search if there is a
317    // high quality picture
318    if ($i == 'current')
319    {
320      if (($row['has_high'] == 'true') and ($user['enabled_high'] == 'true'))
321      {
322        $url_high=$cat_directory.'/pwg_high/'.$row['file'];
323        $picture[$i]['high'] = $url_high;
324      }
325    }
326  }
327
328  // if picture is not a file, we need the download link
329  if (!$picture[$i]['is_picture'])
330  {
331    $picture[$i]['download'] = $row['path'];
332  }
333
334  $picture[$i]['thumbnail'] = get_thumbnail_src($row['path'], @$row['tn_ext']);
335
336  if ( !empty( $row['name'] ) )
337  {
338    $picture[$i]['name'] = $row['name'];
339  }
340  else
341  {
342    $picture[$i]['name'] = str_replace('_', ' ', $file_wo_ext);
343  }
344
345  $picture[$i]['url'] = duplicate_picture_URL(
346    array(
347      'image_id' => $row['id'],
348      ),
349    array(
350      'start',
351      )
352    );
353}
354
355$url_admin =
356  PHPWG_ROOT_PATH.'admin.php?page=picture_modify'
357  .'&amp;cat_id='.(isset($page['category']) ? $page['category'] : '')
358  .'&amp;image_id='.$page['image_id']
359;
360
361$url_slide =
362  $picture['current']['url']
363  .'&amp;slideshow='.$conf['slideshow_period']
364;
365
366$title =  $picture['current']['name'];
367$refresh = 0;
368if ( isset( $_GET['slideshow'] ) and isset($page['next_item']) )
369{
370  $refresh= $_GET['slideshow'];
371  $url_link = $picture['next']['url'].'&amp;slideshow='.$refresh;
372}
373
374$title_img = $picture['current']['name'];
375if ( isset( $page['cat'] ) )
376{
377  if (is_numeric( $page['cat'] ))
378  {
379    $title_img = replace_space(get_cat_display_name($page['cat_name']));
380  }
381  else if ( $page['cat'] == 'search' )
382  {
383    $title_img = replace_search( $title_img, $_GET['search'] );
384  }
385}
386$title_nb = ($page['current_rank'] + 1).'/'.$page['cat_nb_images'];
387
388// calculation of width and height
389if (empty($picture['current']['width']))
390{
391  $taille_image = @getimagesize($picture['current']['src']);
392  $original_width = $taille_image[0];
393  $original_height = $taille_image[1];
394}
395else
396{
397  $original_width = $picture['current']['width'];
398  $original_height = $picture['current']['height'];
399}
400
401$picture_size = get_picture_size(
402  $original_width,
403  $original_height,
404  @$user['maxwidth'],
405  @$user['maxheight']
406  );
407
408// metadata
409if ($conf['show_exif'] or $conf['show_iptc'])
410{
411  $metadata_showable = true;
412}
413else
414{
415  $metadata_showable = false;
416}
417
418// $url_metadata = PHPWG_ROOT_PATH.'picture.php';
419// $url_metadata .=  get_query_string_diff(array('add_fav', 'slideshow', 'show_metadata'));
420// if ($metadata_showable and !isset($_GET['show_metadata']))
421// {
422//   $url_metadata.= '&amp;show_metadata=1';
423// }
424
425// TODO: rewrite metadata display to toggle on/off user_infos.show_metadata
426$url_metadata = duplicate_picture_URL();
427
428$page['body_id'] = 'thePicturePage';
429//------------------------------------------------------- navigation management
430if (isset($page['previous_item']))
431{
432  $template->assign_block_vars(
433    'previous',
434    array(
435      'TITLE_IMG' => $picture['prev']['name'],
436      'IMG' => $picture['prev']['thumbnail'],
437      'U_IMG' => $picture['prev']['url'],
438      'U_IMG_SRC' => $picture['prev']['src']
439      )
440    );
441}
442
443if (isset($page['next_item']))
444{
445  $template->assign_block_vars(
446    'next',
447    array(
448      'TITLE_IMG' => $picture['next']['name'],
449      'IMG' => $picture['next']['thumbnail'],
450      'U_IMG' => $picture['next']['url'],
451      'U_IMG_SRC' => $picture['next']['src'] // allow navigator to preload
452      )
453    );
454}
455
456include(PHPWG_ROOT_PATH.'include/page_header.php');
457$template->set_filenames(array('picture'=>'picture.tpl'));
458
459$template->assign_vars(
460  array(
461    'CATEGORY' => $title_img,
462    'PHOTO' => $title_nb,
463    'TITLE' => $picture['current']['name'],
464    'SRC_IMG' => $picture['current']['src'],
465    'ALT_IMG' => $picture['current']['file'],
466    'WIDTH_IMG' => $picture_size[0],
467    'HEIGHT_IMG' => $picture_size[1],
468
469    'LEVEL_SEPARATOR' => $conf['level_separator'],
470
471    'L_HOME' => $lang['home'],
472    'L_SLIDESHOW' => $lang['slideshow'],
473    'L_STOP_SLIDESHOW' => $lang['slideshow_stop'],
474    'L_PREV_IMG' =>$lang['previous_page'].' : ',
475    'L_NEXT_IMG' =>$lang['next_page'].' : ',
476    'L_ADMIN' =>$lang['link_info_image'],
477    'L_COMMENT_TITLE' =>$lang['comments_title'],
478    'L_ADD_COMMENT' =>$lang['comments_add'],
479    'L_DELETE_COMMENT' =>$lang['comments_del'],
480    'L_DELETE' =>$lang['delete'],
481    'L_SUBMIT' =>$lang['submit'],
482    'L_AUTHOR' =>  $lang['upload_author'],
483    'L_COMMENT' =>$lang['comment'],
484    'L_DOWNLOAD' => $lang['download'],
485    'L_DOWNLOAD_HINT' => $lang['download_hint'],
486    'L_PICTURE_METADATA' => $lang['picture_show_metadata'],
487    'L_PICTURE_HIGH' => $lang['picture_high'],
488    'L_UP_HINT' => $lang['home_hint'],
489    'L_UP_ALT' => $lang['home'],
490
491    'U_HOME' => make_index_URL(),
492    'U_UP' => $url_up,
493    'U_METADATA' => $url_metadata,
494    'U_ADMIN' => $url_admin,
495    'U_SLIDESHOW'=> $url_slide,
496    'U_ADD_COMMENT' => $url_self,
497    )
498  );
499
500if ($conf['show_picture_name_on_title'])
501{
502  $template->assign_block_vars('title', array());
503}
504
505//------------------------------------------------------- upper menu management
506
507// download link if file is not a picture
508if (!$picture['current']['is_picture'])
509{
510  $template->assign_block_vars(
511    'download',
512    array(
513      'U_DOWNLOAD' => $picture['current']['download']
514      )
515    );
516}
517
518// display a high quality link if present
519if (isset($picture['current']['high']))
520{
521  $uuid = uniqid(rand());
522 
523  $template->assign_block_vars(
524    'high',
525    array(
526      'U_HIGH' => $picture['current']['high'],
527      'UUID'   => $uuid,
528      )
529    );
530 
531  $template->assign_block_vars(
532    'download',
533    array(
534      'U_DOWNLOAD' => PHPWG_ROOT_PATH.'action.php?dwn='
535      .$picture['current']['high']
536      )
537    );
538}
539
540// button to set the current picture as representative
541if (is_admin() and isset($page['category']))
542{
543  $template->assign_block_vars(
544    'representative',
545    array(
546      'URL' => $url_self.'&amp;action=set_as_representative'
547      )
548    );
549}
550
551// caddie button
552if (is_admin())
553{
554  $template->assign_block_vars(
555    'caddie',
556    array(
557      'URL' => $url_self.'&amp;action=add_to_caddie'
558      )
559    );
560}
561
562// favorite manipulation
563if (!$user['is_the_guest'])
564{
565  // verify if the picture is already in the favorite of the user
566  $query = '
567SELECT COUNT(*) AS nb_fav
568  FROM '.FAVORITES_TABLE.'
569  WHERE image_id = '.$page['image_id'].'
570    AND user_id = '.$user['id'].'
571;';
572  $result = pwg_query($query);
573  $row = mysql_fetch_array($result);
574 
575  if ($row['nb_fav'] == 0)
576  {
577    $url = $url_self.'&amp;action=add_to_favorites';
578
579    $template->assign_block_vars(
580      'favorite',
581      array(
582        'FAVORITE_IMG'  => get_themeconf('icon_dir').'/favorite.png',
583        'FAVORITE_HINT' => $lang['add_favorites_hint'],
584        'FAVORITE_ALT'  => $lang['add_favorites_alt'],
585        'U_FAVORITE'    => $url_self.'&amp;action=add_to_favorites',
586        )
587      );
588  }
589  else
590  {
591    $template->assign_block_vars(
592      'favorite',
593      array(
594        'FAVORITE_IMG'  => get_themeconf('icon_dir').'/del_favorite.png',
595        'FAVORITE_HINT' => $lang['del_favorites_hint'],
596        'FAVORITE_ALT'  => $lang['del_favorites_alt'],
597        'U_FAVORITE'    => $url_self.'&amp;action=remove_from_favorites',
598        )
599      );
600  }
601}
602//------------------------------------ admin link for information modifications
603if ( is_admin() )
604{
605  $template->assign_block_vars('admin', array());
606}
607
608//--------------------------------------------------------- picture information
609// legend
610if (isset($picture['current']['comment'])
611    and !empty($picture['current']['comment']))
612{
613  $template->assign_block_vars(
614    'legend',
615    array(
616      'COMMENT_IMG' => nl2br($picture['current']['comment'])
617      ));
618}
619
620$infos = array();
621
622// author
623if (!empty($picture['current']['author']))
624{
625  $infos['INFO_AUTHOR'] =
626    // FIXME because of search engine partial rewrite, giving the author
627    // name threw GET is not supported anymore. This feature should come
628    // back later, with a better design
629//     '<a href="'.
630//       PHPWG_ROOT_PATH.'category.php?cat=search'.
631//       '&amp;search=author:'.$picture['current']['author']
632//       .'">'.$picture['current']['author'].'</a>';
633    $picture['current']['author'];
634}
635else
636{
637  $infos['INFO_AUTHOR'] = l10n('N/A');
638}
639
640// creation date
641if (!empty($picture['current']['date_creation']))
642{
643  $val = format_date($picture['current']['date_creation']);
644  $infos['INFO_CREATION_DATE'] = '<a href="'.
645       PHPWG_ROOT_PATH.'category.php?calendar=created-c-'.
646       $picture['current']['date_creation'].'">'.$val.'</a>';
647}
648else
649{
650  $infos['INFO_CREATION_DATE'] = l10n('N/A');
651}
652
653// date of availability
654$val = format_date($picture['current']['date_available'], 'mysql_datetime');
655$infos['INFO_POSTED_DATE'] = '<a href="'.
656   PHPWG_ROOT_PATH.'category.php?calendar=posted-c-'.
657   substr($picture['current']['date_available'],0,10).'">'.$val.'</a>';
658
659// size in pixels
660if ($picture['current']['is_picture'])
661{
662  if ($original_width != $picture_size[0]
663      or $original_height != $picture_size[1])
664  {
665    $infos['INFO_DIMENSIONS'] =
666      '<a href="'.$picture['current']['src'].'" title="'.
667      l10n('Original dimensions').'">'.
668      $original_width.'*'.$original_height.'</a>';
669  }
670  else
671  {
672    $infos['INFO_DIMENSIONS'] = $original_width.'*'.$original_height;
673  }
674}
675else
676{
677  $infos['INFO_DIMENSIONS'] = l10n('N/A');
678}
679
680// filesize
681if (!empty($picture['current']['filesize']))
682{
683  $infos['INFO_FILESIZE'] =
684    sprintf(l10n('%d Kb'), $picture['current']['filesize']);
685}
686else
687{
688  $infos['INFO_FILESIZE'] = l10n('N/A');
689}
690
691// number of visits
692$infos['INFO_VISITS'] = $picture['current']['hit'];
693
694// file
695$infos['INFO_FILE'] = $picture['current']['file'];
696
697// keywords
698if (!empty($picture['current']['keywords']))
699{
700  $infos['INFO_KEYWORDS'] =
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 (tag classification).
704//     preg_replace(
705//       '/([^,]+)/',
706//       '<a href="'.
707//         PHPWG_ROOT_PATH.'category.php?cat=search&amp;search=keywords:$1'
708//         .'">$1</a>',
709//       $picture['current']['keywords']
710//       );
711    $picture['current']['keywords'];
712}
713else
714{
715  $infos['INFO_KEYWORDS'] = l10n('N/A');
716}
717
718$template->assign_vars($infos);
719
720// related categories
721foreach ($related_categories as $category)
722{
723  $template->assign_block_vars(
724    'category',
725    array(
726      'LINE' => count($related_categories) > 3
727        ? get_cat_display_name_cache($category['uppercats'])
728        : get_cat_display_name_from_id($category['category_id'])
729      )
730    );
731}
732
733//slideshow end
734if (isset($_GET['slideshow']))
735{
736  if (!is_numeric($_GET['slideshow']))
737  {
738    $_GET['slideshow'] = $conf['slideshow_period'];
739  }
740
741  $template->assign_block_vars(
742    'stop_slideshow',
743    array(
744      'U_SLIDESHOW' => $picture['current']['url'],
745      )
746    );
747}
748
749// +-----------------------------------------------------------------------+
750// |                               sub pages                               |
751// +-----------------------------------------------------------------------+
752
753include(PHPWG_ROOT_PATH.'include/picture_rate.inc.php');
754include(PHPWG_ROOT_PATH.'include/picture_comment.inc.php');
755include(PHPWG_ROOT_PATH.'include/picture_metadata.inc.php');
756
757//------------------------------------------------------------ log informations
758pwg_log( 'picture', $title_img, $picture['current']['file'] );
759
760$template->parse('picture');
761include(PHPWG_ROOT_PATH.'include/page_tail.php');
762?>
Note: See TracBrowser for help on using the repository browser.