source: trunk/picture.php @ 12797

Last change on this file since 12797 was 12797, checked in by rvelices, 9 years ago

feature 2541 multisize

  • nicer presentation on picture.php
  • added a maintenance purge derivatives action
  • Property svn:eol-style set to LF
File size: 27.1 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24define('PHPWG_ROOT_PATH','');
25include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
26include(PHPWG_ROOT_PATH.'include/section_init.inc.php');
27include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
28
29// Check Access and exit when user status is not ok
30check_status(ACCESS_GUEST);
31
32// access authorization check
33if (isset($page['category']))
34{
35  check_restrictions($page['category']['id']);
36}
37
38$page['rank_of'] = array_flip($page['items']);
39
40// if this image_id doesn't correspond to this category, an error message is
41// displayed, and execution is stopped
42if ( !isset($page['rank_of'][$page['image_id']]) )
43{
44  $query = '
45SELECT id, file, level
46  FROM '.IMAGES_TABLE.'
47  WHERE ';
48  if ($page['image_id']>0)
49  {
50    $query .= 'id = '.$page['image_id'];
51  }
52  else
53  {// url given by file name
54    assert( !empty($page['image_file']) );
55    $query .= 'file LIKE \'' .
56      str_replace(array('_','%'), array('/_','/%'), $page['image_file'] ).
57      '.%\' ESCAPE \'/\' LIMIT 1';
58  }
59  if ( ! ( $row = pwg_db_fetch_assoc(pwg_query($query)) ) )
60  {// element does not exist
61    page_not_found( 'The requested image does not exist',
62      duplicate_index_url()
63      );
64  }
65  if ($row['level']>$user['level'])
66  {
67    access_denied();
68  }
69
70  $page['image_id'] = $row['id'];
71  $page['image_file'] =  $row['file'];
72  if ( !isset($page['rank_of'][$page['image_id']]) )
73  {// the image can still be non accessible (filter/cat perm) and/or not in the set
74    global $filter;
75    if ( !empty($filter['visible_images']) and
76      !in_array($page['image_id'], explode(',',$filter['visible_images']) ) )
77    {
78      page_not_found( 'The requested image is filtered',
79          duplicate_index_url()
80        );
81    }
82    if ('categories'==$page['section'] and !isset($page['category']) )
83    {// flat view - all items
84      access_denied();
85    }
86    else
87    {// try to see if we can access it differently
88      $query = '
89SELECT id
90  FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id
91  WHERE id='.$page['image_id']
92        . get_sql_condition_FandF(
93            array('forbidden_categories' => 'category_id'),
94            " AND"
95          ).'
96  LIMIT 1';
97      if ( pwg_db_num_rows( pwg_query($query) ) == 0 )
98      {
99        access_denied();
100      }
101      else
102      {
103        if ('best_rated'==$page['section'])
104        {
105          $page['rank_of'][$page['image_id']] = count($page['items']);
106          array_push($page['items'], $page['image_id'] );
107        }
108        else
109        {
110          $url = make_picture_url(
111              array(
112                'image_id' => $page['image_id'],
113                'image_file' => $page['image_file'],
114                'section' => 'categories',
115                'flat' => true,
116              )
117            );
118          set_status_header( 'recent_pics'==$page['section'] ? 301 : 302);
119          redirect_http( $url );
120        }
121      }
122    }
123  }
124}
125
126// There is cookie, so we must handle it at the beginning
127if ( isset($_GET['metadata']) )
128{
129  if ( pwg_get_session_var('show_metadata') == null )
130        {
131                pwg_set_session_var('show_metadata', 1 );
132        } else {
133        pwg_unset_session_var('show_metadata');
134        }
135}
136
137// add default event handler for rendering element content
138add_event_handler(
139  'render_element_content',
140  'default_picture_content',
141  EVENT_HANDLER_PRIORITY_NEUTRAL,
142  2
143  );
144// add default event handler for rendering element description
145add_event_handler('render_element_description', 'nl2br');
146
147trigger_action('loc_begin_picture');
148
149// this is the default handler that generates the display for the element
150function default_picture_content($content, $element_info)
151{
152  if ( !empty($content) )
153  {// someone hooked us - so we skip;
154    return $content;
155  }
156
157  if (isset($_COOKIE['picture_deriv']))
158  {
159    pwg_set_session_var('picture_deriv', $_COOKIE['picture_deriv']);
160    setcookie('picture_deriv', false, 0);
161  }
162  $deriv_type = pwg_get_session_var('picture_deriv', IMG_LARGE);
163  $selected_derivative = $element_info['derivatives'][$deriv_type];
164
165  $available_derivatives = array();
166  $added = array();
167  foreach($element_info['derivatives'] as $type => $derivative)
168  {
169    $url = $derivative->get_url();
170    if (isset($added[$url]))
171      continue;
172    $added[$url] = 1;
173    $available_derivatives[] = $type;
174  }
175
176  global $user, $page, $template;
177 
178  $template->append('current', array(
179      'selected_derivative' => $selected_derivative,
180      'available_derivative_types' => $available_derivatives,
181    ), true);
182
183
184  $template->set_filenames(
185    array('default_content'=>'picture_content.tpl')
186    );
187
188  $template->assign( array(
189      'ALT_IMG' => $element_info['file'],
190      )
191    );
192  return $template->parse( 'default_content', true);
193}
194
195// +-----------------------------------------------------------------------+
196// |                            initialization                             |
197// +-----------------------------------------------------------------------+
198
199// caching first_rank, last_rank, current_rank in the displayed
200// section. This should also help in readability.
201$page['first_rank']   = 0;
202$page['last_rank']    = count($page['items']) - 1;
203$page['current_rank'] = $page['rank_of'][ $page['image_id'] ];
204
205// caching current item : readability purpose
206$page['current_item'] = $page['image_id'];
207
208if ($page['current_rank'] != $page['first_rank'])
209{
210  // caching first & previous item : readability purpose
211  $page['previous_item'] = $page['items'][ $page['current_rank'] - 1 ];
212  $page['first_item'] = $page['items'][ $page['first_rank'] ];
213}
214
215if ($page['current_rank'] != $page['last_rank'])
216{
217  // caching next & last item : readability purpose
218  $page['next_item'] = $page['items'][ $page['current_rank'] + 1 ];
219  $page['last_item'] = $page['items'][ $page['last_rank'] ];
220}
221
222$url_up = duplicate_index_url(
223  array(
224    'start' =>
225      floor($page['current_rank'] / $page['nb_image_page'])
226      * $page['nb_image_page']
227    ),
228  array(
229    'start',
230    )
231  );
232
233$url_self = duplicate_picture_url();
234
235// +-----------------------------------------------------------------------+
236// |                                actions                                |
237// +-----------------------------------------------------------------------+
238
239/**
240 * Actions are favorite adding, user comment deletion, setting the picture
241 * as representative of the current category...
242 *
243 * Actions finish by a redirection
244 */
245
246if (isset($_GET['action']))
247{
248  switch ($_GET['action'])
249  {
250    case 'add_to_favorites' :
251    {
252      $query = '
253INSERT INTO '.FAVORITES_TABLE.'
254  (image_id,user_id)
255  VALUES
256  ('.$page['image_id'].','.$user['id'].')
257;';
258      pwg_query($query);
259
260      redirect($url_self);
261
262      break;
263    }
264    case 'remove_from_favorites' :
265    {
266      $query = '
267DELETE FROM '.FAVORITES_TABLE.'
268  WHERE user_id = '.$user['id'].'
269    AND image_id = '.$page['image_id'].'
270;';
271      pwg_query($query);
272
273      if ('favorites' == $page['section'])
274      {
275        redirect($url_up);
276      }
277      else
278      {
279        redirect($url_self);
280      }
281
282      break;
283    }
284    case 'set_as_representative' :
285    {
286      if (is_admin() and isset($page['category']))
287      {
288        $query = '
289UPDATE '.CATEGORIES_TABLE.'
290  SET representative_picture_id = '.$page['image_id'].'
291  WHERE id = '.$page['category']['id'].'
292;';
293        pwg_query($query);
294
295        $query = '
296UPDATE '.USER_CACHE_CATEGORIES_TABLE.'
297  SET user_representative_picture_id = NULL
298  WHERE user_id = '.$user['id'].'
299    AND cat_id = '.$page['category']['id'].'
300;';
301        pwg_query($query);
302      }
303
304      redirect($url_self);
305
306      break;
307    }
308    case 'toggle_metadata' :
309    {
310      break;
311    }
312    case 'add_to_caddie' :
313    {
314      fill_caddie(array($page['image_id']));
315      redirect($url_self);
316      break;
317    }
318    case 'rate' :
319    {
320      include_once(PHPWG_ROOT_PATH.'include/functions_rate.inc.php');
321      rate_picture($page['image_id'], $_POST['rate']);
322      redirect($url_self);
323    }
324    case 'edit_comment' :
325    {
326      check_pwg_token();
327      include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
328      check_input_parameter('comment_to_edit', $_GET, false, PATTERN_ID);
329      $author_id = get_comment_author_id($_GET['comment_to_edit']);
330     
331      if (can_manage_comment('edit', $author_id))
332      {
333        if (!empty($_POST['content']))
334        {
335          $comment_action = update_user_comment(
336            array(
337              'comment_id' => $_GET['comment_to_edit'],
338              'image_id' => $page['image_id'],
339              'content' => $_POST['content']
340              ),
341            $_POST['key']
342            );
343
344          $perform_redirect = false;
345          switch ($comment_action)
346          {
347            case 'moderate':
348              $_SESSION['page_infos'][] = l10n('An administrator must authorize your comment before it is visible.');
349            case 'validate':
350              $_SESSION['page_infos'][] = l10n('Your comment has been registered');
351              $perform_redirect = true;
352              break;
353            case 'reject':
354              $_SESSION['page_errors'][] = l10n('Your comment has NOT been registered because it did not pass the validation rules');
355              $perform_redirect = true;
356              break;
357            default:
358              trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING);
359          }
360         
361          if ($perform_redirect)
362          {
363            redirect($url_self);
364          }
365          unset($_POST['content']);
366          break;
367        }
368        else
369        {
370          $edit_comment = $_GET['comment_to_edit'];
371          break;
372        }
373      }
374    }
375    case 'delete_comment' :
376    {
377      check_pwg_token();
378
379      include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
380
381      check_input_parameter('comment_to_delete', $_GET, false, PATTERN_ID);
382
383      $author_id = get_comment_author_id($_GET['comment_to_delete']);
384
385      if (can_manage_comment('delete', $author_id))
386      {
387        delete_user_comment($_GET['comment_to_delete']);
388      }
389
390      redirect($url_self);
391    }
392    case 'validate_comment' :
393    {
394      check_pwg_token();
395
396      include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
397
398      check_input_parameter('comment_to_validate', $_GET, false, PATTERN_ID);
399
400      $author_id = get_comment_author_id($_GET['comment_to_validate']);
401
402      if (can_manage_comment('validate', $author_id))
403      {
404        validate_user_comment($_GET['comment_to_validate']);
405      }
406
407      redirect($url_self);
408    }
409
410  }
411}
412
413//---------- incrementation of the number of hits, we do this only if no action
414if (trigger_event('allow_increment_element_hit_count', !isset($_POST['content']) ) )
415{
416  $query = '
417UPDATE
418  '.IMAGES_TABLE.'
419  SET hit = hit+1
420  WHERE id = '.$page['image_id'].'
421;';
422  pwg_query($query);
423}
424//---------------------------------------------------------- related categories
425$query = '
426SELECT category_id,uppercats,commentable,global_rank
427  FROM '.IMAGE_CATEGORY_TABLE.'
428    INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id
429  WHERE image_id = '.$page['image_id'].'
430'.get_sql_condition_FandF
431  (
432    array
433      (
434        'forbidden_categories' => 'category_id',
435        'visible_categories' => 'category_id'
436      ),
437    'AND'
438  ).'
439;';
440$result = pwg_query($query);
441$related_categories = array();
442while ($row = pwg_db_fetch_assoc($result))
443{
444  $row['commentable'] = get_boolean($row['commentable']);
445  array_push($related_categories, $row);
446}
447usort($related_categories, 'global_rank_compare');
448//-------------------------first, prev, current, next & last picture management
449$picture = array();
450
451$ids = array($page['image_id']);
452if (isset($page['previous_item']))
453{
454  array_push($ids, $page['previous_item']);
455  array_push($ids, $page['first_item']);
456}
457if (isset($page['next_item']))
458{
459  array_push($ids, $page['next_item']);
460  array_push($ids, $page['last_item']);
461}
462
463$query = '
464SELECT *
465  FROM '.IMAGES_TABLE.'
466  WHERE id IN ('.implode(',', $ids).')
467;';
468
469$result = pwg_query($query);
470
471while ($row = pwg_db_fetch_assoc($result))
472{
473  if (isset($page['previous_item']) and $row['id'] == $page['previous_item'])
474  {
475    $i = 'previous';
476  }
477  elseif (isset($page['next_item']) and $row['id'] == $page['next_item'])
478  {
479    $i = 'next';
480  }
481  elseif (isset($page['first_item']) and $row['id'] == $page['first_item'])
482  {
483    $i = 'first';
484  }
485  elseif (isset($page['last_item']) and $row['id'] == $page['last_item'])
486  {
487    $i = 'last';
488  }
489  else
490  {
491    $i = 'current';
492  }
493
494
495
496  $row['derivatives'] = DerivativeImage::get_all($row);
497  $row['src_image'] = $row['derivatives'][IMG_THUMB]->src_image;
498 
499  // ------ build element_path and element_url
500  $row['element_path'] = get_element_path($row);
501  $row['element_url'] = get_element_url($row);
502
503  if ($i=='current')
504  {
505    if ( $row['src_image']->is_original() )
506    {
507      if ( $user['enabled_high']=='true' )
508      {
509        $row['download_url'] = get_download_url('e',$row);
510      }
511    }
512    else
513    { // not a pic - need download link
514      $row['download_url'] = $row['element_url'];
515    }
516  }
517
518  $row['url'] = duplicate_picture_url(
519    array(
520      'image_id' => $row['id'],
521      'image_file' => $row['file'],
522      ),
523    array(
524      'start',
525      )
526    );
527
528  $picture[$i] = $row;
529
530  if ( !empty( $row['name'] ) )
531  {
532    $picture[$i]['name'] = $row['name'];
533  }
534  else
535  {
536    $file_wo_ext = get_filename_wo_extension($row['file']);
537    $picture[$i]['name'] = str_replace('_', ' ', $file_wo_ext);
538  }
539
540  $picture[$i]['name'] = trigger_event('render_element_description', $picture[$i]['name']);
541
542  if ('previous'==$i and $page['previous_item']==$page['first_item'])
543  {
544    $picture['first'] = $picture[$i];
545  }
546  if ('next'==$i and $page['next_item']==$page['last_item'])
547  {
548    $picture['last'] = $picture[$i];
549  }
550}
551
552$slideshow_params = array();
553$slideshow_url_params = array();
554
555if (isset($_GET['slideshow']))
556{
557  $page['slideshow'] = true;
558  $page['meta_robots'] = array('noindex'=>1, 'nofollow'=>1);
559
560  $slideshow_params = decode_slideshow_params($_GET['slideshow']);
561  $slideshow_url_params['slideshow'] = encode_slideshow_params($slideshow_params);
562
563  if ($slideshow_params['play'])
564  {
565    $id_pict_redirect = '';
566    if (isset($page['next_item']))
567    {
568      $id_pict_redirect = 'next';
569    }
570    else
571    {
572      if ($slideshow_params['repeat'] and isset($page['first_item']))
573      {
574        $id_pict_redirect = 'first';
575      }
576    }
577
578    if (!empty($id_pict_redirect))
579    {
580      // $refresh, $url_link and $title are required for creating
581      // an automated refresh page in header.tpl
582      $refresh = $slideshow_params['period'];
583      $url_link = add_url_params(
584          $picture[$id_pict_redirect]['url'],
585          $slideshow_url_params
586        );
587    }
588  }
589}
590else
591{
592  $page['slideshow'] = false;
593}
594if ($page['slideshow'] and $conf['light_slideshow'])
595{
596  $template->set_filenames( array('slideshow' => 'slideshow.tpl'));
597}
598else
599{
600  $template->set_filenames( array('picture' => 'picture.tpl'));
601}
602
603$title =  $picture['current']['name'];
604$title_nb = ($page['current_rank'] + 1).'/'.count($page['items']);
605
606// metadata
607$url_metadata = duplicate_picture_url();
608$url_metadata = add_url_params( $url_metadata, array('metadata'=>null) );
609
610
611// do we have a plugin that can show metadata for something else than images?
612$metadata_showable = trigger_event(
613  'get_element_metadata_available',
614  (
615    ($conf['show_exif'] or $conf['show_iptc'])
616    and !$picture['current']['src_image']->is_mimetype()
617    ),
618  $picture['current']
619  );
620
621if ( $metadata_showable and pwg_get_session_var('show_metadata') )
622{
623  $page['meta_robots']=array('noindex'=>1, 'nofollow'=>1);
624}
625
626
627$page['body_id'] = 'thePicturePage';
628
629// allow plugins to change what we computed before passing data to template
630$picture = trigger_event('picture_pictures_data', $picture);
631
632//------------------------------------------------------- navigation management
633foreach (array('first','previous','next','last', 'current') as $which_image)
634{
635  if (isset($picture[$which_image]))
636  {
637    $template->assign(
638      $which_image,
639      array_merge(
640        $picture[$which_image],
641        array(
642          'TITLE' => $picture[$which_image]['name'],
643          'THUMB_SRC' => $picture[$which_image]['derivatives'][IMG_THUMB]->get_url(),
644          // Params slideshow was transmit to navigation buttons
645          'U_IMG' =>
646            add_url_params(
647              $picture[$which_image]['url'], $slideshow_url_params),
648          )
649        )
650      );
651    if ($conf['picture_download_icon'] and !empty($picture['current']['download_url']))
652    {
653      $template->append($which_image, array('U_DOWNLOAD' => $picture['current']['download_url']), true);
654    }
655  }
656}
657
658
659if ($page['slideshow'])
660{
661  $tpl_slideshow = array();
662
663  //slideshow end
664  $template->assign(
665    array(
666      'U_SLIDESHOW_STOP' => $picture['current']['url'],
667      )
668    );
669
670  foreach (array('repeat', 'play') as $p)
671  {
672    $var_name =
673      'U_'
674      .($slideshow_params[$p] ? 'STOP_' : 'START_')
675      .strtoupper($p);
676
677    $tpl_slideshow[$var_name] =
678          add_url_params(
679            $picture['current']['url'],
680            array('slideshow' =>
681              encode_slideshow_params(
682                array_merge($slideshow_params,
683                  array($p => ! $slideshow_params[$p]))
684                )
685              )
686          );
687  }
688
689  foreach (array('dec', 'inc') as $op)
690  {
691    $new_period = $slideshow_params['period'] + ((($op == 'dec') ? -1 : 1) * $conf['slideshow_period_step']);
692    $new_slideshow_params =
693      correct_slideshow_params(
694        array_merge($slideshow_params,
695                  array('period' => $new_period)));
696
697    if ($new_slideshow_params['period'] === $new_period)
698    {
699      $var_name = 'U_'.strtoupper($op).'_PERIOD';
700      $tpl_slideshow[$var_name] =
701            add_url_params(
702              $picture['current']['url'],
703              array('slideshow' => encode_slideshow_params($new_slideshow_params)
704                  )
705          );
706    }
707  }
708  $template->assign('slideshow', $tpl_slideshow );
709}
710elseif ($conf['picture_slideshow_icon'])
711{
712  $template->assign(
713    array(
714      'U_SLIDESHOW_START' =>
715        add_url_params(
716          $picture['current']['url'],
717          array( 'slideshow'=>''))
718      )
719    );
720}
721
722$template->assign(
723  array(
724    'SECTION_TITLE' => $page['title'],
725    'PHOTO' => $title_nb,
726    'SHOW_PICTURE_NAME_ON_TITLE' => $conf['show_picture_name_on_title'],
727    'IS_HOME' => ('categories'==$page['section'] and !isset($page['category']) ),
728
729    'LEVEL_SEPARATOR' => $conf['level_separator'],
730
731    'U_UP' => $url_up,
732    'DISPLAY_NAV_BUTTONS' => $conf['picture_navigation_icons'],
733    'DISPLAY_NAV_THUMB' => $conf['picture_navigation_thumb']
734    )
735  );
736
737if ($conf['picture_metadata_icon'])
738{
739  $template->assign('U_METADATA', $url_metadata);
740}
741
742
743//------------------------------------------------------- upper menu management
744
745// admin links
746if (is_admin())
747{
748  if (isset($page['category']))
749  {
750    $template->assign(
751      array(
752        'U_SET_AS_REPRESENTATIVE' => add_url_params($url_self,
753                    array('action'=>'set_as_representative')
754                 )
755        )
756      );
757  }
758
759  $url_admin =
760    get_root_url().'admin.php?page=picture_modify'
761    .'&amp;cat_id='.(isset($page['category']) ? $page['category']['id'] : '')
762    .'&amp;image_id='.$page['image_id'];
763
764  $template->assign(
765    array(
766      'U_CADDIE' => add_url_params($url_self,
767                  array('action'=>'add_to_caddie')
768               ),
769      'U_ADMIN' => $url_admin,
770      )
771    );
772
773  $template->assign('available_permission_levels', get_privacy_level_options());
774}
775
776// favorite manipulation
777if (!is_a_guest() and $conf['picture_favorite_icon'])
778{
779  // verify if the picture is already in the favorite of the user
780  $query = '
781SELECT COUNT(*) AS nb_fav
782  FROM '.FAVORITES_TABLE.'
783  WHERE image_id = '.$page['image_id'].'
784    AND user_id = '.$user['id'].'
785;';
786  $row = pwg_db_fetch_assoc( pwg_query($query) );
787        $is_favorite = $row['nb_fav'] != 0;
788
789  $template->assign(
790    'favorite',
791    array(
792                        'IS_FAVORITE' => $is_favorite,
793      'U_FAVORITE'    => add_url_params(
794        $url_self,
795        array('action'=> !$is_favorite ? 'add_to_favorites' : 'remove_from_favorites' )
796        ),
797      )
798    );
799}
800
801//--------------------------------------------------------- picture information
802// legend
803if (isset($picture['current']['comment'])
804    and !empty($picture['current']['comment']))
805{
806  $template->assign(
807      'COMMENT_IMG',
808        trigger_event('render_element_description',
809          $picture['current']['comment'])
810      );
811}
812
813// author
814if (!empty($picture['current']['author']))
815{
816  $infos['INFO_AUTHOR'] =
817// FIXME because of search engine partial rewrite, giving the author
818// name threw GET is not supported anymore. This feature should come
819// back later, with a better design
820//     '<a href="'.
821//       PHPWG_ROOT_PATH.'category.php?cat=search'.
822//       '&amp;search=author:'.$picture['current']['author']
823//       .'">'.$picture['current']['author'].'</a>';
824    $picture['current']['author'];
825}
826
827// creation date
828if (!empty($picture['current']['date_creation']))
829{
830  $val = format_date($picture['current']['date_creation']);
831  $url = make_index_url(
832    array(
833      'chronology_field'=>'created',
834      'chronology_style'=>'monthly',
835      'chronology_view'=>'list',
836      'chronology_date' => explode('-', substr($picture['current']['date_creation'], 0, 10))
837      )
838    );
839  $infos['INFO_CREATION_DATE'] =
840    '<a href="'.$url.'" rel="nofollow">'.$val.'</a>';
841}
842
843// date of availability
844$val = format_date($picture['current']['date_available']);
845$url = make_index_url(
846  array(
847    'chronology_field'=>'posted',
848    'chronology_style'=>'monthly',
849    'chronology_view'=>'list',
850    'chronology_date' => explode(
851      '-',
852      substr($picture['current']['date_available'], 0, 10)
853      )
854    )
855  );
856$infos['INFO_POSTED_DATE'] = '<a href="'.$url.'" rel="nofollow">'.$val.'</a>';
857
858// size in pixels
859if ($picture['current']['src_image']->is_original() and isset($picture['current']['width']) )
860{
861  $infos['INFO_DIMENSIONS'] =
862    $picture['current']['width'].'*'.$picture['current']['height'];
863}
864
865// filesize
866if (!empty($picture['current']['filesize']))
867{
868  $infos['INFO_FILESIZE'] =
869    sprintf(l10n('%d Kb'), $picture['current']['filesize']);
870}
871
872// number of visits
873$infos['INFO_VISITS'] = $picture['current']['hit'];
874
875// file
876$infos['INFO_FILE'] = $picture['current']['file'];
877
878$template->assign($infos);
879$template->assign('display_info', unserialize($conf['picture_informations']));
880
881// related tags
882$tags = get_common_tags( array($page['image_id']), -1);
883if ( count($tags) )
884{
885  foreach ($tags as $tag)
886  {
887    $template->append(
888        'related_tags',
889        array_merge( $tag,
890          array(
891            'URL' => make_index_url(
892                      array(
893                        'tags' => array($tag)
894                        )
895                      ),
896            'U_TAG_IMAGE' => duplicate_picture_url(
897                      array(
898                        'section' => 'tags',
899                        'tags' => array($tag)
900                        )
901                    )
902          )
903        )
904      );
905  }
906}
907
908// related categories
909if ( count($related_categories)==1 and
910    isset($page['category']) and
911    $related_categories[0]['category_id']==$page['category']['id'] )
912{ // no need to go to db, we have all the info
913  $template->append(
914      'related_categories',
915      get_cat_display_name( $page['category']['upper_names'] )
916    );
917}
918else
919{ // use only 1 sql query to get names for all related categories
920  $ids = array();
921  foreach ($related_categories as $category)
922  {// add all uppercats to $ids
923    $ids = array_merge($ids, explode(',', $category['uppercats']) );
924  }
925  $ids = array_unique($ids);
926  $query = '
927SELECT id, name, permalink
928  FROM '.CATEGORIES_TABLE.'
929  WHERE id IN ('.implode(',',$ids).')';
930  $cat_map = hash_from_query($query, 'id');
931  foreach ($related_categories as $category)
932  {
933    $cats = array();
934    foreach ( explode(',', $category['uppercats']) as $id )
935    {
936      $cats[] = $cat_map[$id];
937    }
938    $template->append('related_categories', get_cat_display_name($cats) );
939  }
940}
941
942// maybe someone wants a special display (call it before page_header so that
943// they can add stylesheets)
944$element_content = trigger_event(
945  'render_element_content',
946  '',
947  $picture['current']
948  );
949$template->assign( 'ELEMENT_CONTENT', $element_content );
950
951if (isset($picture['next'])
952    and $picture['next']['src_image']->is_original()
953    and strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome/') === false)
954{
955  $template->assign('U_PREFETCH', $picture['next']['derivatives'][pwg_get_session_var('picture_deriv', IMG_LARGE)]->get_url() );
956}
957
958
959// +-----------------------------------------------------------------------+
960// |                               sub pages                               |
961// +-----------------------------------------------------------------------+
962
963include(PHPWG_ROOT_PATH.'include/picture_rate.inc.php');
964include(PHPWG_ROOT_PATH.'include/picture_comment.inc.php');
965if ($metadata_showable and pwg_get_session_var('show_metadata') <> null )
966{
967  include(PHPWG_ROOT_PATH.'include/picture_metadata.inc.php');
968}
969
970// include menubar
971$themeconf = $template->get_template_vars('themeconf');
972if ($conf['picture_menu'] AND (!isset($themeconf['hide_menu_on']) OR !in_array('thePicturePage', $themeconf['hide_menu_on'])))
973{
974  if (!isset($page['start'])) $page['start'] = 0;
975  include( PHPWG_ROOT_PATH.'include/menubar.inc.php');
976  if (is_admin()) $template->assign('U_ADMIN', $url_admin); // overwrited by the menu
977}
978
979include(PHPWG_ROOT_PATH.'include/page_header.php');
980trigger_action('loc_end_picture');
981if ($page['slideshow'] and $conf['light_slideshow'])
982{
983  $template->pparse('slideshow');
984}
985else
986{
987  $template->pparse('picture');
988}
989//------------------------------------------------------------ log informations
990pwg_log($picture['current']['id'], 'picture');
991include(PHPWG_ROOT_PATH.'include/page_tail.php');
992?>
Note: See TracBrowser for help on using the repository browser.