source: trunk/picture.php @ 12920

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

feature 2548 multisize - code cleanup + better usage in category_cats + i.php logs memory usage peak

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