source: trunk/picture.php @ 12958

Last change on this file since 12958 was 12958, checked in by rvelices, 12 years ago

feature 2548 multisize - small fixes

  • 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-2012 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    if ( array_key_exists($_COOKIE['picture_deriv'], ImageStdParams::get_defined_type_map()) )
160    {
161      pwg_set_session_var('picture_deriv', $_COOKIE['picture_deriv']);
162    }
163    setcookie('picture_deriv', false, 0, cookie_path() );
164  }
165  $deriv_type = pwg_get_session_var('picture_deriv', IMG_LARGE);
166  $selected_derivative = $element_info['derivatives'][$deriv_type];
167
168  $unique_derivatives = array();
169  $show_original = isset($element_info['element_url']);
170  $added = array();
171  foreach($element_info['derivatives'] as $type => $derivative)
172  {
173    $url = $derivative->get_url();
174    if (isset($added[$url]))
175      continue;
176    $added[$url] = 1;
177    $show_original &= !($derivative->same_as_source());
178    $unique_derivatives[$type]= $derivative;
179  }
180
181  global $page, $template;
182
183  if ($show_original)
184  {
185    $template->assign( 'U_ORIGINAL', $element_info['element_url'] );
186  }
187
188  $template->append('current', array(
189      'selected_derivative' => $selected_derivative,
190      'unique_derivatives' => $unique_derivatives,
191    ), true);
192
193
194  $template->set_filenames(
195    array('default_content'=>'picture_content.tpl')
196    );
197
198  $template->assign( array(
199      'ALT_IMG' => $element_info['file'],
200      'COOKIE_PATH' => cookie_path(),
201      )
202    );
203  return $template->parse( 'default_content', true);
204}
205
206// +-----------------------------------------------------------------------+
207// |                            initialization                             |
208// +-----------------------------------------------------------------------+
209
210// caching first_rank, last_rank, current_rank in the displayed
211// section. This should also help in readability.
212$page['first_rank']   = 0;
213$page['last_rank']    = count($page['items']) - 1;
214$page['current_rank'] = $page['rank_of'][ $page['image_id'] ];
215
216// caching current item : readability purpose
217$page['current_item'] = $page['image_id'];
218
219if ($page['current_rank'] != $page['first_rank'])
220{
221  // caching first & previous item : readability purpose
222  $page['previous_item'] = $page['items'][ $page['current_rank'] - 1 ];
223  $page['first_item'] = $page['items'][ $page['first_rank'] ];
224}
225
226if ($page['current_rank'] != $page['last_rank'])
227{
228  // caching next & last item : readability purpose
229  $page['next_item'] = $page['items'][ $page['current_rank'] + 1 ];
230  $page['last_item'] = $page['items'][ $page['last_rank'] ];
231}
232
233$url_up = duplicate_index_url(
234  array(
235    'start' =>
236      floor($page['current_rank'] / $page['nb_image_page'])
237      * $page['nb_image_page']
238    ),
239  array(
240    'start',
241    )
242  );
243
244$url_self = duplicate_picture_url();
245
246// +-----------------------------------------------------------------------+
247// |                                actions                                |
248// +-----------------------------------------------------------------------+
249
250/**
251 * Actions are favorite adding, user comment deletion, setting the picture
252 * as representative of the current category...
253 *
254 * Actions finish by a redirection
255 */
256
257if (isset($_GET['action']))
258{
259  switch ($_GET['action'])
260  {
261    case 'add_to_favorites' :
262    {
263      $query = '
264INSERT INTO '.FAVORITES_TABLE.'
265  (image_id,user_id)
266  VALUES
267  ('.$page['image_id'].','.$user['id'].')
268;';
269      pwg_query($query);
270
271      redirect($url_self);
272
273      break;
274    }
275    case 'remove_from_favorites' :
276    {
277      $query = '
278DELETE FROM '.FAVORITES_TABLE.'
279  WHERE user_id = '.$user['id'].'
280    AND image_id = '.$page['image_id'].'
281;';
282      pwg_query($query);
283
284      if ('favorites' == $page['section'])
285      {
286        redirect($url_up);
287      }
288      else
289      {
290        redirect($url_self);
291      }
292
293      break;
294    }
295    case 'set_as_representative' :
296    {
297      if (is_admin() and isset($page['category']))
298      {
299        $query = '
300UPDATE '.CATEGORIES_TABLE.'
301  SET representative_picture_id = '.$page['image_id'].'
302  WHERE id = '.$page['category']['id'].'
303;';
304        pwg_query($query);
305
306        $query = '
307UPDATE '.USER_CACHE_CATEGORIES_TABLE.'
308  SET user_representative_picture_id = NULL
309  WHERE user_id = '.$user['id'].'
310    AND cat_id = '.$page['category']['id'].'
311;';
312        pwg_query($query);
313      }
314
315      redirect($url_self);
316
317      break;
318    }
319    case 'add_to_caddie' :
320    {
321      fill_caddie(array($page['image_id']));
322      redirect($url_self);
323      break;
324    }
325    case 'rate' :
326    {
327      include_once(PHPWG_ROOT_PATH.'include/functions_rate.inc.php');
328      rate_picture($page['image_id'], $_POST['rate']);
329      redirect($url_self);
330    }
331    case 'edit_comment' :
332    {
333      check_pwg_token();
334      include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
335      check_input_parameter('comment_to_edit', $_GET, false, PATTERN_ID);
336      $author_id = get_comment_author_id($_GET['comment_to_edit']);
337
338      if (can_manage_comment('edit', $author_id))
339      {
340        if (!empty($_POST['content']))
341        {
342          $comment_action = update_user_comment(
343            array(
344              'comment_id' => $_GET['comment_to_edit'],
345              'image_id' => $page['image_id'],
346              'content' => $_POST['content']
347              ),
348            $_POST['key']
349            );
350
351          $perform_redirect = false;
352          switch ($comment_action)
353          {
354            case 'moderate':
355              $_SESSION['page_infos'][] = l10n('An administrator must authorize your comment before it is visible.');
356            case 'validate':
357              $_SESSION['page_infos'][] = l10n('Your comment has been registered');
358              $perform_redirect = true;
359              break;
360            case 'reject':
361              $_SESSION['page_errors'][] = l10n('Your comment has NOT been registered because it did not pass the validation rules');
362              $perform_redirect = true;
363              break;
364            default:
365              trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING);
366          }
367
368          if ($perform_redirect)
369          {
370            redirect($url_self);
371          }
372          unset($_POST['content']);
373          break;
374        }
375        else
376        {
377          $edit_comment = $_GET['comment_to_edit'];
378          break;
379        }
380      }
381    }
382    case 'delete_comment' :
383    {
384      check_pwg_token();
385
386      include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
387
388      check_input_parameter('comment_to_delete', $_GET, false, PATTERN_ID);
389
390      $author_id = get_comment_author_id($_GET['comment_to_delete']);
391
392      if (can_manage_comment('delete', $author_id))
393      {
394        delete_user_comment($_GET['comment_to_delete']);
395      }
396
397      redirect($url_self);
398    }
399    case 'validate_comment' :
400    {
401      check_pwg_token();
402
403      include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
404
405      check_input_parameter('comment_to_validate', $_GET, false, PATTERN_ID);
406
407      $author_id = get_comment_author_id($_GET['comment_to_validate']);
408
409      if (can_manage_comment('validate', $author_id))
410      {
411        validate_user_comment($_GET['comment_to_validate']);
412      }
413
414      redirect($url_self);
415    }
416
417  }
418}
419
420//---------- incrementation of the number of hits, we do this only if no action
421if (trigger_event('allow_increment_element_hit_count', !isset($_POST['content']) ) )
422{
423  $query = '
424UPDATE
425  '.IMAGES_TABLE.'
426  SET hit = hit+1
427  WHERE id = '.$page['image_id'].'
428;';
429  pwg_query($query);
430}
431//---------------------------------------------------------- related categories
432$query = '
433SELECT category_id,uppercats,commentable,global_rank
434  FROM '.IMAGE_CATEGORY_TABLE.'
435    INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id
436  WHERE image_id = '.$page['image_id'].'
437'.get_sql_condition_FandF
438  (
439    array
440      (
441        'forbidden_categories' => 'category_id',
442        'visible_categories' => 'category_id'
443      ),
444    'AND'
445  ).'
446;';
447$result = pwg_query($query);
448$related_categories = array();
449while ($row = pwg_db_fetch_assoc($result))
450{
451  $row['commentable'] = get_boolean($row['commentable']);
452  array_push($related_categories, $row);
453}
454usort($related_categories, 'global_rank_compare');
455//-------------------------first, prev, current, next & last picture management
456$picture = array();
457
458$ids = array($page['image_id']);
459if (isset($page['previous_item']))
460{
461  array_push($ids, $page['previous_item']);
462  array_push($ids, $page['first_item']);
463}
464if (isset($page['next_item']))
465{
466  array_push($ids, $page['next_item']);
467  array_push($ids, $page['last_item']);
468}
469
470$query = '
471SELECT *
472  FROM '.IMAGES_TABLE.'
473  WHERE id IN ('.implode(',', $ids).')
474;';
475
476$result = pwg_query($query);
477
478while ($row = pwg_db_fetch_assoc($result))
479{
480  if (isset($page['previous_item']) and $row['id'] == $page['previous_item'])
481  {
482    $i = 'previous';
483  }
484  elseif (isset($page['next_item']) and $row['id'] == $page['next_item'])
485  {
486    $i = 'next';
487  }
488  elseif (isset($page['first_item']) and $row['id'] == $page['first_item'])
489  {
490    $i = 'first';
491  }
492  elseif (isset($page['last_item']) and $row['id'] == $page['last_item'])
493  {
494    $i = 'last';
495  }
496  else
497  {
498    $i = 'current';
499  }
500
501  $row['src_image'] = new SrcImage($row);
502  $row['derivatives'] = DerivativeImage::get_all($row['src_image']);
503
504  if ($i=='current')
505  {
506    $row['element_path'] = get_element_path($row);
507
508    if ( $row['src_image']->is_original() )
509    {// we have a photo
510      if ( $user['enabled_high']=='true' )
511      {
512        $row['element_url'] = $row['src_image']->get_url();
513        $row['download_url'] = get_action_url($row['id'], 'e', true);
514      }
515    }
516    else
517    { // not a pic - need download link
518      $row['download_url'] = $row['element_url'] = get_element_url($row);;
519    }
520  }
521
522  $row['url'] = duplicate_picture_url(
523    array(
524      'image_id' => $row['id'],
525      'image_file' => $row['file'],
526      ),
527    array(
528      'start',
529      )
530    );
531
532  $picture[$i] = $row;
533  $picture[$i]['TITLE'] = render_element_name($row);
534
535  if ('previous'==$i and $page['previous_item']==$page['first_item'])
536  {
537    $picture['first'] = $picture[$i];
538  }
539  if ('next'==$i and $page['next_item']==$page['last_item'])
540  {
541    $picture['last'] = $picture[$i];
542  }
543}
544
545$slideshow_params = array();
546$slideshow_url_params = array();
547
548if (isset($_GET['slideshow']))
549{
550  $page['slideshow'] = true;
551  $page['meta_robots'] = array('noindex'=>1, 'nofollow'=>1);
552
553  $slideshow_params = decode_slideshow_params($_GET['slideshow']);
554  $slideshow_url_params['slideshow'] = encode_slideshow_params($slideshow_params);
555
556  if ($slideshow_params['play'])
557  {
558    $id_pict_redirect = '';
559    if (isset($page['next_item']))
560    {
561      $id_pict_redirect = 'next';
562    }
563    else
564    {
565      if ($slideshow_params['repeat'] and isset($page['first_item']))
566      {
567        $id_pict_redirect = 'first';
568      }
569    }
570
571    if (!empty($id_pict_redirect))
572    {
573      // $refresh, $url_link and $title are required for creating
574      // an automated refresh page in header.tpl
575      $refresh = $slideshow_params['period'];
576      $url_link = add_url_params(
577          $picture[$id_pict_redirect]['url'],
578          $slideshow_url_params
579        );
580    }
581  }
582}
583else
584{
585  $page['slideshow'] = false;
586}
587if ($page['slideshow'] and $conf['light_slideshow'])
588{
589  $template->set_filenames( array('slideshow' => 'slideshow.tpl'));
590}
591else
592{
593  $template->set_filenames( array('picture' => 'picture.tpl'));
594}
595
596$title =  $picture['current']['TITLE'];
597$title_nb = ($page['current_rank'] + 1).'/'.count($page['items']);
598
599// metadata
600$url_metadata = duplicate_picture_url();
601$url_metadata = add_url_params( $url_metadata, array('metadata'=>null) );
602
603
604// do we have a plugin that can show metadata for something else than images?
605$metadata_showable = trigger_event(
606  'get_element_metadata_available',
607  (
608    ($conf['show_exif'] or $conf['show_iptc'])
609    and !$picture['current']['src_image']->is_mimetype()
610    ),
611  $picture['current']
612  );
613
614if ( $metadata_showable and pwg_get_session_var('show_metadata') )
615{
616  $page['meta_robots']=array('noindex'=>1, 'nofollow'=>1);
617}
618
619
620$page['body_id'] = 'thePicturePage';
621
622// allow plugins to change what we computed before passing data to template
623$picture = trigger_event('picture_pictures_data', $picture);
624
625//------------------------------------------------------- navigation management
626foreach (array('first','previous','next','last', 'current') as $which_image)
627{
628  if (isset($picture[$which_image]))
629  {
630    $template->assign(
631      $which_image,
632      array_merge(
633        $picture[$which_image],
634        array(
635          'THUMB_SRC' => $picture[$which_image]['derivatives'][IMG_THUMB]->get_url(),
636          // Params slideshow was transmit to navigation buttons
637          'U_IMG' =>
638            add_url_params(
639              $picture[$which_image]['url'], $slideshow_url_params),
640          )
641        )
642      );
643  }
644}
645if ($conf['picture_download_icon'] and !empty($picture['current']['download_url']))
646{
647  $template->append('current', array('U_DOWNLOAD' => $picture['current']['download_url']), true);
648}
649
650
651if ($page['slideshow'])
652{
653  $tpl_slideshow = array();
654
655  //slideshow end
656  $template->assign(
657    array(
658      'U_SLIDESHOW_STOP' => $picture['current']['url'],
659      )
660    );
661
662  foreach (array('repeat', 'play') as $p)
663  {
664    $var_name =
665      'U_'
666      .($slideshow_params[$p] ? 'STOP_' : 'START_')
667      .strtoupper($p);
668
669    $tpl_slideshow[$var_name] =
670          add_url_params(
671            $picture['current']['url'],
672            array('slideshow' =>
673              encode_slideshow_params(
674                array_merge($slideshow_params,
675                  array($p => ! $slideshow_params[$p]))
676                )
677              )
678          );
679  }
680
681  foreach (array('dec', 'inc') as $op)
682  {
683    $new_period = $slideshow_params['period'] + ((($op == 'dec') ? -1 : 1) * $conf['slideshow_period_step']);
684    $new_slideshow_params =
685      correct_slideshow_params(
686        array_merge($slideshow_params,
687                  array('period' => $new_period)));
688
689    if ($new_slideshow_params['period'] === $new_period)
690    {
691      $var_name = 'U_'.strtoupper($op).'_PERIOD';
692      $tpl_slideshow[$var_name] =
693            add_url_params(
694              $picture['current']['url'],
695              array('slideshow' => encode_slideshow_params($new_slideshow_params)
696                  )
697          );
698    }
699  }
700  $template->assign('slideshow', $tpl_slideshow );
701}
702elseif ($conf['picture_slideshow_icon'])
703{
704  $template->assign(
705    array(
706      'U_SLIDESHOW_START' =>
707        add_url_params(
708          $picture['current']['url'],
709          array( 'slideshow'=>''))
710      )
711    );
712}
713
714$template->assign(
715  array(
716    'SECTION_TITLE' => $page['title'],
717    'PHOTO' => $title_nb,
718    'SHOW_PICTURE_NAME_ON_TITLE' => $conf['show_picture_name_on_title'],
719    'IS_HOME' => ('categories'==$page['section'] and !isset($page['category']) ),
720
721    'LEVEL_SEPARATOR' => $conf['level_separator'],
722
723    'U_UP' => $url_up,
724    'DISPLAY_NAV_BUTTONS' => $conf['picture_navigation_icons'],
725    'DISPLAY_NAV_THUMB' => $conf['picture_navigation_thumb']
726    )
727  );
728
729if ($conf['picture_metadata_icon'])
730{
731  $template->assign('U_METADATA', $url_metadata);
732}
733
734
735//------------------------------------------------------- upper menu management
736
737// admin links
738if (is_admin())
739{
740  if (isset($page['category']))
741  {
742    $template->assign(
743      array(
744        'U_SET_AS_REPRESENTATIVE' => add_url_params($url_self,
745                    array('action'=>'set_as_representative')
746                 )
747        )
748      );
749  }
750
751  $url_admin =
752    get_root_url().'admin.php?page=picture_modify'
753    .'&amp;cat_id='.(isset($page['category']) ? $page['category']['id'] : '')
754    .'&amp;image_id='.$page['image_id'];
755
756  $template->assign(
757    array(
758      'U_CADDIE' => add_url_params($url_self,
759                  array('action'=>'add_to_caddie')
760               ),
761      'U_ADMIN' => $url_admin,
762      )
763    );
764
765  $template->assign('available_permission_levels', get_privacy_level_options());
766}
767
768// favorite manipulation
769if (!is_a_guest() and $conf['picture_favorite_icon'])
770{
771  // verify if the picture is already in the favorite of the user
772  $query = '
773SELECT COUNT(*) AS nb_fav
774  FROM '.FAVORITES_TABLE.'
775  WHERE image_id = '.$page['image_id'].'
776    AND user_id = '.$user['id'].'
777;';
778  $row = pwg_db_fetch_assoc( pwg_query($query) );
779        $is_favorite = $row['nb_fav'] != 0;
780
781  $template->assign(
782    'favorite',
783    array(
784                        'IS_FAVORITE' => $is_favorite,
785      'U_FAVORITE'    => add_url_params(
786        $url_self,
787        array('action'=> !$is_favorite ? 'add_to_favorites' : 'remove_from_favorites' )
788        ),
789      )
790    );
791}
792
793//--------------------------------------------------------- picture information
794// legend
795if (isset($picture['current']['comment'])
796    and !empty($picture['current']['comment']))
797{
798  $template->assign(
799      'COMMENT_IMG',
800        trigger_event('render_element_description',
801          $picture['current']['comment'])
802      );
803}
804
805// author
806if (!empty($picture['current']['author']))
807{
808  $infos['INFO_AUTHOR'] =
809// FIXME because of search engine partial rewrite, giving the author
810// name threw GET is not supported anymore. This feature should come
811// back later, with a better design
812//     '<a href="'.
813//       PHPWG_ROOT_PATH.'category.php?cat=search'.
814//       '&amp;search=author:'.$picture['current']['author']
815//       .'">'.$picture['current']['author'].'</a>';
816    $picture['current']['author'];
817}
818
819// creation date
820if (!empty($picture['current']['date_creation']))
821{
822  $val = format_date($picture['current']['date_creation']);
823  $url = make_index_url(
824    array(
825      'chronology_field'=>'created',
826      'chronology_style'=>'monthly',
827      'chronology_view'=>'list',
828      'chronology_date' => explode('-', substr($picture['current']['date_creation'], 0, 10))
829      )
830    );
831  $infos['INFO_CREATION_DATE'] =
832    '<a href="'.$url.'" rel="nofollow">'.$val.'</a>';
833}
834
835// date of availability
836$val = format_date($picture['current']['date_available']);
837$url = make_index_url(
838  array(
839    'chronology_field'=>'posted',
840    'chronology_style'=>'monthly',
841    'chronology_view'=>'list',
842    'chronology_date' => explode(
843      '-',
844      substr($picture['current']['date_available'], 0, 10)
845      )
846    )
847  );
848$infos['INFO_POSTED_DATE'] = '<a href="'.$url.'" rel="nofollow">'.$val.'</a>';
849
850// size in pixels
851if ($picture['current']['src_image']->is_original() and isset($picture['current']['width']) )
852{
853  $infos['INFO_DIMENSIONS'] =
854    $picture['current']['width'].'*'.$picture['current']['height'];
855}
856
857// filesize
858if (!empty($picture['current']['filesize']))
859{
860  $infos['INFO_FILESIZE'] =
861    sprintf(l10n('%d Kb'), $picture['current']['filesize']);
862}
863
864// number of visits
865$infos['INFO_VISITS'] = $picture['current']['hit'];
866
867// file
868$infos['INFO_FILE'] = $picture['current']['file'];
869
870$template->assign($infos);
871$template->assign('display_info', unserialize($conf['picture_informations']));
872
873// related tags
874$tags = get_common_tags( array($page['image_id']), -1);
875if ( count($tags) )
876{
877  foreach ($tags as $tag)
878  {
879    $template->append(
880        'related_tags',
881        array_merge( $tag,
882          array(
883            'URL' => make_index_url(
884                      array(
885                        'tags' => array($tag)
886                        )
887                      ),
888            'U_TAG_IMAGE' => duplicate_picture_url(
889                      array(
890                        'section' => 'tags',
891                        'tags' => array($tag)
892                        )
893                    )
894          )
895        )
896      );
897  }
898}
899
900// related categories
901if ( count($related_categories)==1 and
902    isset($page['category']) and
903    $related_categories[0]['category_id']==$page['category']['id'] )
904{ // no need to go to db, we have all the info
905  $template->append(
906      'related_categories',
907      get_cat_display_name( $page['category']['upper_names'] )
908    );
909}
910else
911{ // use only 1 sql query to get names for all related categories
912  $ids = array();
913  foreach ($related_categories as $category)
914  {// add all uppercats to $ids
915    $ids = array_merge($ids, explode(',', $category['uppercats']) );
916  }
917  $ids = array_unique($ids);
918  $query = '
919SELECT id, name, permalink
920  FROM '.CATEGORIES_TABLE.'
921  WHERE id IN ('.implode(',',$ids).')';
922  $cat_map = hash_from_query($query, 'id');
923  foreach ($related_categories as $category)
924  {
925    $cats = array();
926    foreach ( explode(',', $category['uppercats']) as $id )
927    {
928      $cats[] = $cat_map[$id];
929    }
930    $template->append('related_categories', get_cat_display_name($cats) );
931  }
932}
933
934// maybe someone wants a special display (call it before page_header so that
935// they can add stylesheets)
936$element_content = trigger_event(
937  'render_element_content',
938  '',
939  $picture['current']
940  );
941$template->assign( 'ELEMENT_CONTENT', $element_content );
942
943if (isset($picture['next'])
944    and $picture['next']['src_image']->is_original()
945    and strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome/') === false)
946{
947  $template->assign('U_PREFETCH', $picture['next']['derivatives'][pwg_get_session_var('picture_deriv', IMG_LARGE)]->get_url() );
948}
949
950
951// +-----------------------------------------------------------------------+
952// |                               sub pages                               |
953// +-----------------------------------------------------------------------+
954
955include(PHPWG_ROOT_PATH.'include/picture_rate.inc.php');
956if ($conf['activate_comments'])
957{
958  include(PHPWG_ROOT_PATH.'include/picture_comment.inc.php');
959}
960if ($metadata_showable and pwg_get_session_var('show_metadata') <> null )
961{
962  include(PHPWG_ROOT_PATH.'include/picture_metadata.inc.php');
963}
964
965// include menubar
966$themeconf = $template->get_template_vars('themeconf');
967if ($conf['picture_menu'] AND (!isset($themeconf['hide_menu_on']) OR !in_array('thePicturePage', $themeconf['hide_menu_on'])))
968{
969  if (!isset($page['start'])) $page['start'] = 0;
970  include( PHPWG_ROOT_PATH.'include/menubar.inc.php');
971  if (is_admin()) $template->assign('U_ADMIN', $url_admin); // overwrited by the menu
972}
973
974include(PHPWG_ROOT_PATH.'include/page_header.php');
975trigger_action('loc_end_picture');
976if ($page['slideshow'] and $conf['light_slideshow'])
977{
978  $template->pparse('slideshow');
979}
980else
981{
982  $template->pparse('picture');
983}
984//------------------------------------------------------------ log informations
985pwg_log($picture['current']['id'], 'picture');
986include(PHPWG_ROOT_PATH.'include/page_tail.php');
987?>
Note: See TracBrowser for help on using the repository browser.