source: trunk/picture.php @ 1247

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

Issue ID 0000346:

o Fix Picture slideshow not working

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