source: trunk/picture.php @ 28826

Last change on this file since 28826 was 28714, checked in by rvelices, 10 years ago

since number of accepted args not required for add_event_handler, simplify calls

  • Property svn:eol-style set to LF
File size: 27.3 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2014 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          $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('render_element_content', 'default_picture_content');
139// add default event handler for rendering element description
140add_event_handler('render_element_description', 'nl2br');
141
142trigger_notify('loc_begin_picture');
143
144// this is the default handler that generates the display for the element
145function default_picture_content($content, $element_info)
146{
147  global $conf;
148
149  if ( !empty($content) )
150  {// someone hooked us - so we skip;
151    return $content;
152  }
153
154  if (isset($_COOKIE['picture_deriv']))
155  {
156    if ( array_key_exists($_COOKIE['picture_deriv'], ImageStdParams::get_defined_type_map()) )
157    {
158      pwg_set_session_var('picture_deriv', $_COOKIE['picture_deriv']);
159    }
160    setcookie('picture_deriv', false, 0, cookie_path() );
161  }
162  $deriv_type = pwg_get_session_var('picture_deriv', $conf['derivative_default_size']);
163  $selected_derivative = $element_info['derivatives'][$deriv_type];
164
165  $unique_derivatives = array();
166  $show_original = isset($element_info['element_url']);
167  $added = array();
168  foreach($element_info['derivatives'] as $type => $derivative)
169  {
170    if ($type==IMG_SQUARE || $type==IMG_THUMB)
171      continue;
172    if (!array_key_exists($type, ImageStdParams::get_defined_type_map()))
173      continue;
174    $url = $derivative->get_url();
175    if (isset($added[$url]))
176      continue;
177    $added[$url] = 1;
178    $show_original &= !($derivative->same_as_source());
179    $unique_derivatives[$type]= $derivative;
180  }
181
182  global $page, $template;
183
184  if ($show_original)
185  {
186    $template->assign( 'U_ORIGINAL', $element_info['element_url'] );
187  }
188
189  $template->append('current', array(
190      'selected_derivative' => $selected_derivative,
191      'unique_derivatives' => $unique_derivatives,
192    ), true);
193
194
195  $template->set_filenames(
196    array('default_content'=>'picture_content.tpl')
197    );
198
199  $template->assign( array(
200      'ALT_IMG' => $element_info['file'],
201      'COOKIE_PATH' => cookie_path(),
202      )
203    );
204  return $template->parse( 'default_content', true);
205}
206
207// +-----------------------------------------------------------------------+
208// |                            initialization                             |
209// +-----------------------------------------------------------------------+
210
211// caching first_rank, last_rank, current_rank in the displayed
212// section. This should also help in readability.
213$page['first_rank']   = 0;
214$page['last_rank']    = count($page['items']) - 1;
215$page['current_rank'] = $page['rank_of'][ $page['image_id'] ];
216
217// caching current item : readability purpose
218$page['current_item'] = $page['image_id'];
219
220if ($page['current_rank'] != $page['first_rank'])
221{
222  // caching first & previous item : readability purpose
223  $page['previous_item'] = $page['items'][ $page['current_rank'] - 1 ];
224  $page['first_item'] = $page['items'][ $page['first_rank'] ];
225}
226
227if ($page['current_rank'] != $page['last_rank'])
228{
229  // caching next & last item : readability purpose
230  $page['next_item'] = $page['items'][ $page['current_rank'] + 1 ];
231  $page['last_item'] = $page['items'][ $page['last_rank'] ];
232}
233
234$url_up = duplicate_index_url(
235  array(
236    'start' =>
237      floor($page['current_rank'] / $page['nb_image_page'])
238      * $page['nb_image_page']
239    ),
240  array(
241    'start',
242    )
243  );
244
245$url_self = duplicate_picture_url();
246
247// +-----------------------------------------------------------------------+
248// |                                actions                                |
249// +-----------------------------------------------------------------------+
250
251/**
252 * Actions are favorite adding, user comment deletion, setting the picture
253 * as representative of the current category...
254 *
255 * Actions finish by a redirection
256 */
257
258if (isset($_GET['action']))
259{
260  switch ($_GET['action'])
261  {
262    case 'add_to_favorites' :
263    {
264      $query = '
265INSERT INTO '.FAVORITES_TABLE.'
266  (image_id,user_id)
267  VALUES
268  ('.$page['image_id'].','.$user['id'].')
269;';
270      pwg_query($query);
271
272      redirect($url_self);
273
274      break;
275    }
276    case 'remove_from_favorites' :
277    {
278      $query = '
279DELETE FROM '.FAVORITES_TABLE.'
280  WHERE user_id = '.$user['id'].'
281    AND image_id = '.$page['image_id'].'
282;';
283      pwg_query($query);
284
285      if ('favorites' == $page['section'])
286      {
287        redirect($url_up);
288      }
289      else
290      {
291        redirect($url_self);
292      }
293
294      break;
295    }
296    case 'set_as_representative' :
297    {
298      if (is_admin() and isset($page['category']))
299      {
300        $query = '
301UPDATE '.CATEGORIES_TABLE.'
302  SET representative_picture_id = '.$page['image_id'].'
303  WHERE id = '.$page['category']['id'].'
304;';
305        pwg_query($query);
306
307        include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
308        invalidate_user_cache();
309      }
310
311      redirect($url_self);
312
313      break;
314    }
315    case 'add_to_caddie' :
316    {
317      fill_caddie(array($page['image_id']));
318      redirect($url_self);
319      break;
320    }
321    case 'rate' :
322    {
323      include_once(PHPWG_ROOT_PATH.'include/functions_rate.inc.php');
324      rate_picture($page['image_id'], $_POST['rate']);
325      redirect($url_self);
326    }
327    case 'edit_comment':
328    {
329      include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
330      check_input_parameter('comment_to_edit', $_GET, false, PATTERN_ID);
331      $author_id = get_comment_author_id($_GET['comment_to_edit']);
332
333      if (can_manage_comment('edit', $author_id))
334      {
335        if (!empty($_POST['content']))
336        {
337          check_pwg_token();
338          $comment_action = update_user_comment(
339            array(
340              'comment_id' => $_GET['comment_to_edit'],
341              'image_id' => $page['image_id'],
342              'content' => $_POST['content'],
343              'website_url' => @$_POST['website_url'],
344              ),
345            $_POST['key']
346            );
347
348          $perform_redirect = false;
349          switch ($comment_action)
350          {
351            case 'moderate':
352              $_SESSION['page_infos'][] = l10n('An administrator must authorize your comment before it is visible.');
353            case 'validate':
354              $_SESSION['page_infos'][] = l10n('Your comment has been registered');
355              $perform_redirect = true;
356              break;
357            case 'reject':
358              $_SESSION['page_errors'][] = l10n('Your comment has NOT been registered because it did not pass the validation rules');
359              break;
360            default:
361              trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING);
362          }
363
364          if ($perform_redirect)
365          {
366            redirect($url_self);
367          }
368          unset($_POST['content']);
369        }
370
371        $edit_comment = $_GET['comment_to_edit'];
372      }
373      break;
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
414//---------- incrementation of the number of hits
415$inc_hit_count = !isset($_POST['content']);
416// don't increment counter if in the Mozilla Firefox prefetch
417if (isset($_SERVER['HTTP_X_MOZ']) and $_SERVER['HTTP_X_MOZ'] == 'prefetch')
418{
419  $inc_hit_count = false;
420}
421else
422{
423  // don't increment counter if comming from the same picture (actions)
424  if (pwg_get_session_var('referer_image_id',0) == $page['image_id'])
425  {
426    $inc_hit_count = false;
427  }
428  pwg_set_session_var('referer_image_id', $page['image_id']);
429}
430
431// don't increment if adding a comment
432if (trigger_change('allow_increment_element_hit_count', $inc_hit_count, $page['image_id'] ) )
433{
434  // avoiding auto update of "lastmodified" field
435  $query = '
436UPDATE
437  '.IMAGES_TABLE.'
438  SET hit = hit+1, lastmodified = lastmodified
439  WHERE id = '.$page['image_id'].'
440;';
441  pwg_query($query);
442}
443
444//---------------------------------------------------------- related categories
445$query = '
446SELECT id,uppercats,commentable,visible,status,global_rank
447  FROM '.IMAGE_CATEGORY_TABLE.'
448    INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id
449  WHERE image_id = '.$page['image_id'].'
450'.get_sql_condition_FandF
451  (
452    array
453      (
454        'forbidden_categories' => 'id',
455        'visible_categories' => 'id'
456      ),
457    'AND'
458  ).'
459;';
460$related_categories = array_from_query($query);
461usort($related_categories, 'global_rank_compare');
462//-------------------------first, prev, current, next & last picture management
463$picture = array();
464
465$ids = array($page['image_id']);
466if (isset($page['previous_item']))
467{
468  $ids[] = $page['previous_item'];
469  $ids[] = $page['first_item'];
470}
471if (isset($page['next_item']))
472{
473  $ids[] = $page['next_item'];
474  $ids[] = $page['last_item'];
475}
476
477$query = '
478SELECT *
479  FROM '.IMAGES_TABLE.'
480  WHERE id IN ('.implode(',', $ids).')
481;';
482
483$result = pwg_query($query);
484
485while ($row = pwg_db_fetch_assoc($result))
486{
487  if (isset($page['previous_item']) and $row['id'] == $page['previous_item'])
488  {
489    $i = 'previous';
490  }
491  elseif (isset($page['next_item']) and $row['id'] == $page['next_item'])
492  {
493    $i = 'next';
494  }
495  elseif (isset($page['first_item']) and $row['id'] == $page['first_item'])
496  {
497    $i = 'first';
498  }
499  elseif (isset($page['last_item']) and $row['id'] == $page['last_item'])
500  {
501    $i = 'last';
502  }
503  else
504  {
505    $i = 'current';
506  }
507
508  $row['src_image'] = new SrcImage($row);
509  $row['derivatives'] = DerivativeImage::get_all($row['src_image']);
510
511  if ($i=='current')
512  {
513    $row['element_path'] = get_element_path($row);
514
515    if ( $row['src_image']->is_original() )
516    {// we have a photo
517      if ( $user['enabled_high']=='true' )
518      {
519        $row['element_url'] = $row['src_image']->get_url();
520        $row['download_url'] = get_action_url($row['id'], 'e', true);
521      }
522    }
523    else
524    { // not a pic - need download link
525      $row['download_url'] = $row['element_url'] = get_element_url($row);;
526    }
527  }
528
529  $row['url'] = duplicate_picture_url(
530    array(
531      'image_id' => $row['id'],
532      'image_file' => $row['file'],
533      ),
534    array(
535      'start',
536      )
537    );
538
539  $picture[$i] = $row;
540  $picture[$i]['TITLE'] = render_element_name($row);
541  $picture[$i]['TITLE_ESC'] = str_replace('"', '&quot;', $picture[$i]['TITLE']);
542
543  if ('previous'==$i and $page['previous_item']==$page['first_item'])
544  {
545    $picture['first'] = $picture[$i];
546  }
547  if ('next'==$i and $page['next_item']==$page['last_item'])
548  {
549    $picture['last'] = $picture[$i];
550  }
551}
552
553$slideshow_params = array();
554$slideshow_url_params = array();
555
556if (isset($_GET['slideshow']))
557{
558  $page['slideshow'] = true;
559  $page['meta_robots'] = array('noindex'=>1, 'nofollow'=>1);
560
561  $slideshow_params = decode_slideshow_params($_GET['slideshow']);
562  $slideshow_url_params['slideshow'] = encode_slideshow_params($slideshow_params);
563
564  if ($slideshow_params['play'])
565  {
566    $id_pict_redirect = '';
567    if (isset($page['next_item']))
568    {
569      $id_pict_redirect = 'next';
570    }
571    else
572    {
573      if ($slideshow_params['repeat'] and isset($page['first_item']))
574      {
575        $id_pict_redirect = 'first';
576      }
577    }
578
579    if (!empty($id_pict_redirect))
580    {
581      // $refresh, $url_link and $title are required for creating
582      // an automated refresh page in header.tpl
583      $refresh = $slideshow_params['period'];
584      $url_link = add_url_params(
585          $picture[$id_pict_redirect]['url'],
586          $slideshow_url_params
587        );
588    }
589  }
590}
591else
592{
593  $page['slideshow'] = false;
594}
595if ($page['slideshow'] and $conf['light_slideshow'])
596{
597  $template->set_filenames( array('slideshow' => 'slideshow.tpl'));
598}
599else
600{
601  $template->set_filenames( array('picture' => 'picture.tpl'));
602}
603
604$title =  $picture['current']['TITLE'];
605$title_nb = ($page['current_rank'] + 1).'/'.count($page['items']);
606
607// metadata
608$url_metadata = duplicate_picture_url();
609$url_metadata = add_url_params( $url_metadata, array('metadata'=>null) );
610
611
612// do we have a plugin that can show metadata for something else than images?
613$metadata_showable = trigger_change(
614  'get_element_metadata_available',
615  (
616    ($conf['show_exif'] or $conf['show_iptc'])
617    and !$picture['current']['src_image']->is_mimetype()
618    ),
619  $picture['current']
620  );
621
622if ( $metadata_showable and pwg_get_session_var('show_metadata') )
623{
624  $page['meta_robots']=array('noindex'=>1, 'nofollow'=>1);
625}
626
627
628$page['body_id'] = 'thePicturePage';
629
630// allow plugins to change what we computed before passing data to template
631$picture = trigger_change('picture_pictures_data', $picture);
632
633//------------------------------------------------------- navigation management
634foreach (array('first','previous','next','last', 'current') as $which_image)
635{
636  if (isset($picture[$which_image]))
637  {
638    $template->assign(
639      $which_image,
640      array_merge(
641        $picture[$which_image],
642        array(
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  }
652}
653if ($conf['picture_download_icon'] and !empty($picture['current']['download_url']))
654{
655  $template->append('current', array('U_DOWNLOAD' => $picture['current']['download_url']), true);
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['section_title'],
725    'PHOTO' => $title_nb,
726    'IS_HOME' => ('categories'==$page['section'] and !isset($page['category']) ),
727
728    'LEVEL_SEPARATOR' => $conf['level_separator'],
729
730    'U_UP' => $url_up,
731    'DISPLAY_NAV_BUTTONS' => $conf['picture_navigation_icons'],
732    'DISPLAY_NAV_THUMB' => $conf['picture_navigation_thumb']
733    )
734  );
735
736if ($conf['picture_metadata_icon'])
737{
738  $template->assign('U_METADATA', $url_metadata);
739}
740
741
742//------------------------------------------------------- upper menu management
743
744// admin links
745if (is_admin())
746{
747  if (isset($page['category']))
748  {
749    $template->assign(
750      array(
751        'U_SET_AS_REPRESENTATIVE' => add_url_params($url_self,
752                    array('action'=>'set_as_representative')
753                 )
754        )
755      );
756  }
757
758  $url_admin =
759    get_root_url().'admin.php?page=photo-'.$page['image_id']
760    .(isset($page['category']) ? '&amp;cat_id='.$page['category']['id'] : '')
761    ;
762
763  $template->assign(
764    array(
765      'U_CADDIE' => add_url_params($url_self,
766                  array('action'=>'add_to_caddie')
767               ),
768      'U_PHOTO_ADMIN' => $url_admin,
769      )
770    );
771
772  $template->assign('available_permission_levels', get_privacy_level_options());
773}
774
775// favorite manipulation
776if (!is_a_guest() and $conf['picture_favorite_icon'])
777{
778  // verify if the picture is already in the favorite of the user
779  $query = '
780SELECT COUNT(*) AS nb_fav
781  FROM '.FAVORITES_TABLE.'
782  WHERE image_id = '.$page['image_id'].'
783    AND user_id = '.$user['id'].'
784;';
785  $row = pwg_db_fetch_assoc( pwg_query($query) );
786        $is_favorite = $row['nb_fav'] != 0;
787
788  $template->assign(
789    'favorite',
790    array(
791                        'IS_FAVORITE' => $is_favorite,
792      'U_FAVORITE'    => add_url_params(
793        $url_self,
794        array('action'=> !$is_favorite ? 'add_to_favorites' : 'remove_from_favorites' )
795        ),
796      )
797    );
798}
799
800//--------------------------------------------------------- picture information
801// legend
802if (isset($picture['current']['comment'])
803    and !empty($picture['current']['comment']))
804{
805  $template->assign(
806      'COMMENT_IMG',
807        trigger_change('render_element_description',
808          $picture['current']['comment'],
809          'picture_page_element_description'
810          )
811      );
812}
813
814// author
815if (!empty($picture['current']['author']))
816{
817  $infos['INFO_AUTHOR'] = $picture['current']['author'];
818}
819
820// creation date
821if (!empty($picture['current']['date_creation']))
822{
823  $val = format_date($picture['current']['date_creation']);
824  $url = make_index_url(
825    array(
826      'chronology_field'=>'created',
827      'chronology_style'=>'monthly',
828      'chronology_view'=>'list',
829      'chronology_date' => explode('-', substr($picture['current']['date_creation'], 0, 10))
830      )
831    );
832  $infos['INFO_CREATION_DATE'] =
833    '<a href="'.$url.'" rel="nofollow">'.$val.'</a>';
834}
835
836// date of availability
837$val = format_date($picture['current']['date_available']);
838$url = make_index_url(
839  array(
840    'chronology_field'=>'posted',
841    'chronology_style'=>'monthly',
842    'chronology_view'=>'list',
843    'chronology_date' => explode(
844      '-',
845      substr($picture['current']['date_available'], 0, 10)
846      )
847    )
848  );
849$infos['INFO_POSTED_DATE'] = '<a href="'.$url.'" rel="nofollow">'.$val.'</a>';
850
851// size in pixels
852if ($picture['current']['src_image']->is_original() and isset($picture['current']['width']) )
853{
854  $infos['INFO_DIMENSIONS'] =
855    $picture['current']['width'].'*'.$picture['current']['height'];
856}
857
858// filesize
859if (!empty($picture['current']['filesize']))
860{
861  $infos['INFO_FILESIZE'] = 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]['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_change(
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 $template->get_template_vars('U_PREFETCH') == null
946    and strpos(@$_SERVER['HTTP_USER_AGENT'], 'Chrome/') === false)
947{
948  $template->assign(
949    'U_PREFETCH',
950    $picture['next']['derivatives'][pwg_get_session_var('picture_deriv', $conf['derivative_default_size'])]->get_url()
951    );
952}
953
954$template->assign(
955  'U_CANONICAL',
956  make_picture_url(
957    array(
958      'image_id' => $picture['current']['id'],
959      'image_file' => $picture['current']['file'])
960    )
961  );
962
963// +-----------------------------------------------------------------------+
964// |                               sub pages                               |
965// +-----------------------------------------------------------------------+
966
967include(PHPWG_ROOT_PATH.'include/picture_rate.inc.php');
968if ($conf['activate_comments'])
969{
970  include(PHPWG_ROOT_PATH.'include/picture_comment.inc.php');
971}
972if ($metadata_showable and pwg_get_session_var('show_metadata') <> null )
973{
974  include(PHPWG_ROOT_PATH.'include/picture_metadata.inc.php');
975}
976
977// include menubar
978$themeconf = $template->get_template_vars('themeconf');
979if ($conf['picture_menu'] AND (!isset($themeconf['hide_menu_on']) OR !in_array('thePicturePage', $themeconf['hide_menu_on'])))
980{
981  if (!isset($page['start'])) $page['start'] = 0;
982  include( PHPWG_ROOT_PATH.'include/menubar.inc.php');
983}
984
985include(PHPWG_ROOT_PATH.'include/page_header.php');
986trigger_notify('loc_end_picture');
987flush_page_messages();
988if ($page['slideshow'] and $conf['light_slideshow'])
989{
990  $template->pparse('slideshow');
991}
992else
993{
994  $template->parse_picture_buttons();
995  $template->pparse('picture');
996}
997//------------------------------------------------------------ log informations
998pwg_log($picture['current']['id'], 'picture');
999include(PHPWG_ROOT_PATH.'include/page_tail.php');
1000?>
Note: See TracBrowser for help on using the repository browser.