source: trunk/picture.php @ 24423

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