source: trunk/picture.php @ 2407

Last change on this file since 2407 was 2407, checked in by mathiasm, 16 years ago

Bug 817 (metadata display persistency) fixed for Butterfly

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 23.5 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008      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');
28include_once(PHPWG_ROOT_PATH.'include/functions_session.inc.php');
29
30// Check Access and exit when user status is not ok
31check_status(ACCESS_GUEST);
32
33// access authorization check
34if (isset($page['category']))
35{
36  check_restrictions($page['category']['id']);
37}
38
39$page['rank_of'] = array_flip($page['items']);
40
41// if this image_id doesn't correspond to this category, an error message is
42// displayed, and execution is stopped
43if ( !isset($page['rank_of'][$page['image_id']]) )
44{
45  page_not_found(
46    'The requested image does not belong to this image set',
47    duplicate_index_url()
48    );
49}
50
51// There is cookie, so we must handle it at the beginning
52if ( isset($_GET['metadata']) )
53{
54  if ( pwg_get_session_var('show_metadata') == null )
55        {
56                pwg_set_session_var('show_metadata', 1, 86400, cookie_path());
57        } else {
58        pwg_unset_session_var('show_metadata');
59
60        }
61
62}
63
64// add default event handler for rendering element content
65add_event_handler(
66  'render_element_content',
67  'default_picture_content',
68  EVENT_HANDLER_PRIORITY_NEUTRAL,
69  2
70  );
71// add default event handler for rendering element description
72add_event_handler('render_element_description', 'nl2br');
73
74trigger_action('loc_begin_picture');
75
76// this is the default handler that generates the display for the element
77function default_picture_content($content, $element_info)
78{
79  if ( !empty($content) )
80  {// someone hooked us - so we skip;
81    return $content;
82  }
83  if (!isset($element_info['image_url']))
84  { // nothing to do
85    return $content;
86  }
87
88  global $user, $page, $template;
89
90  $template->set_filenames(
91    array('default_content'=>'picture_content.tpl')
92    );
93
94  if ( !$page['slideshow'] and isset($element_info['high_url']) )
95  {
96    $uuid = uniqid(rand());
97    $template->assign(
98      'high',
99      array(
100        'U_HIGH' => $element_info['high_url'],
101        'UUID'   => $uuid,
102        )
103      );
104  }
105  $template->assign( array(
106      'SRC_IMG' => $element_info['image_url'],
107      'ALT_IMG' => $element_info['file'],
108      'WIDTH_IMG' => @$element_info['scaled_width'],
109      'HEIGHT_IMG' => @$element_info['scaled_height'],
110      )
111    );
112  return $template->parse( 'default_content', true);
113}
114
115// +-----------------------------------------------------------------------+
116// |                            initialization                             |
117// +-----------------------------------------------------------------------+
118
119// caching first_rank, last_rank, current_rank in the displayed
120// section. This should also help in readability.
121$page['first_rank']   = 0;
122$page['last_rank']    = count($page['items']) - 1;
123$page['current_rank'] = $page['rank_of'][ $page['image_id'] ];
124
125// caching current item : readability purpose
126$page['current_item'] = $page['image_id'];
127
128if ($page['current_rank'] != $page['first_rank'])
129{
130  // caching first & previous item : readability purpose
131  $page['previous_item'] = $page['items'][ $page['current_rank'] - 1 ];
132  $page['first_item'] = $page['items'][ $page['first_rank'] ];
133}
134
135if ($page['current_rank'] != $page['last_rank'])
136{
137  // caching next & last item : readability purpose
138  $page['next_item'] = $page['items'][ $page['current_rank'] + 1 ];
139  $page['last_item'] = $page['items'][ $page['last_rank'] ];
140}
141
142$url_up = duplicate_index_url(
143  array(
144    'start' =>
145      floor($page['current_rank'] / $user['nb_image_page'])
146      * $user['nb_image_page']
147    ),
148  array(
149    'start',
150    )
151  );
152
153$url_self = duplicate_picture_url();
154
155// +-----------------------------------------------------------------------+
156// |                                actions                                |
157// +-----------------------------------------------------------------------+
158
159/**
160 * Actions are favorite adding, user comment deletion, setting the picture
161 * as representative of the current category...
162 *
163 * Actions finish by a redirection
164 */
165
166if (isset($_GET['action']))
167{
168  switch ($_GET['action'])
169  {
170    case 'add_to_favorites' :
171    {
172      $query = '
173INSERT INTO '.FAVORITES_TABLE.'
174  (image_id,user_id)
175  VALUES
176  ('.$page['image_id'].','.$user['id'].')
177;';
178      pwg_query($query);
179
180      redirect($url_self);
181
182      break;
183    }
184    case 'remove_from_favorites' :
185    {
186      $query = '
187DELETE FROM '.FAVORITES_TABLE.'
188  WHERE user_id = '.$user['id'].'
189    AND image_id = '.$page['image_id'].'
190;';
191      pwg_query($query);
192
193      if ('favorites' == $page['section'])
194      {
195        redirect($url_up);
196      }
197      else
198      {
199        redirect($url_self);
200      }
201
202      break;
203    }
204    case 'set_as_representative' :
205    {
206      if (is_admin() and !is_adviser() and isset($page['category']))
207      {
208        $query = '
209UPDATE '.CATEGORIES_TABLE.'
210  SET representative_picture_id = '.$page['image_id'].'
211  WHERE id = '.$page['category']['id'].'
212;';
213        pwg_query($query);
214      }
215
216      redirect($url_self);
217
218      break;
219    }
220    case 'toggle_metadata' :
221    {
222      break;
223    }
224    case 'add_to_caddie' :
225    {
226      fill_caddie(array($page['image_id']));
227      redirect($url_self);
228      break;
229    }
230    case 'rate' :
231    {
232      include_once(PHPWG_ROOT_PATH.'include/functions_rate.inc.php');
233      rate_picture(
234        $page['image_id'],
235        isset($_POST['rate']) ? $_POST['rate'] : $_GET['rate']
236        );
237      redirect($url_self);
238    }
239    case 'delete_comment' :
240    {
241      if (isset($_GET['comment_to_delete'])
242          and is_numeric($_GET['comment_to_delete'])
243          and is_admin() and !is_adviser() )
244      {
245        $query = '
246DELETE FROM '.COMMENTS_TABLE.'
247  WHERE id = '.$_GET['comment_to_delete'].'
248;';
249        pwg_query( $query );
250      }
251
252      redirect($url_self);
253    }
254  }
255}
256
257// incrementation of the number of hits, we do this only if no action
258if (trigger_event('allow_increment_element_hit_count', !isset($_POST['content']) ) )
259{
260  $query = '
261UPDATE
262  '.IMAGES_TABLE.'
263  SET hit = hit+1
264  WHERE id = '.$page['image_id'].'
265;';
266  pwg_query($query);
267}
268//---------------------------------------------------------- related categories
269$query = '
270SELECT category_id,uppercats,commentable,global_rank
271  FROM '.IMAGE_CATEGORY_TABLE.'
272    INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id
273  WHERE image_id = '.$page['image_id'].'
274'.get_sql_condition_FandF
275  (
276    array
277      (
278        'forbidden_categories' => 'category_id',
279        'visible_categories' => 'category_id'
280      ),
281    'AND'
282  ).'
283;';
284$result = pwg_query($query);
285$related_categories = array();
286while ($row = mysql_fetch_array($result))
287{
288  array_push($related_categories, $row);
289}
290usort($related_categories, 'global_rank_compare');
291//-------------------------first, prev, current, next & last picture management
292$picture = array();
293
294$ids = array($page['image_id']);
295if (isset($page['previous_item']))
296{
297  array_push($ids, $page['previous_item']);
298  array_push($ids, $page['first_item']);
299}
300if (isset($page['next_item']))
301{
302  array_push($ids, $page['next_item']);
303  array_push($ids, $page['last_item']);
304}
305
306$query = '
307SELECT *
308  FROM '.IMAGES_TABLE.'
309  WHERE id IN ('.implode(',', $ids).')
310;';
311
312$result = pwg_query($query);
313
314while ($row = mysql_fetch_assoc($result))
315{
316  if (isset($page['previous_item']) and $row['id'] == $page['previous_item'])
317  {
318    $i = 'previous';
319  }
320  else if (isset($page['next_item']) and $row['id'] == $page['next_item'])
321  {
322    $i = 'next';
323  }
324  else if (isset($page['first_item']) and $row['id'] == $page['first_item'])
325  {
326    $i = 'first';
327  }
328  else if (isset($page['last_item']) and $row['id'] == $page['last_item'])
329  {
330    $i = 'last';
331  }
332  else
333  {
334    $i = 'current';
335  }
336
337  $picture[$i] = $row;
338
339  $picture[$i]['is_picture'] = false;
340  if (in_array(get_extension($row['file']), $conf['picture_ext']))
341  {
342    $picture[$i]['is_picture'] = true;
343  }
344
345  // ------ build element_path and element_url
346  $picture[$i]['element_path'] = get_element_path($picture[$i]);
347  $picture[$i]['element_url'] = get_element_url($picture[$i]);
348
349  // ------ build image_path and image_url
350  if ($i=='current' or $i=='next')
351  {
352    $picture[$i]['image_path'] = get_image_path( $picture[$i] );
353    $picture[$i]['image_url'] = get_image_url( $picture[$i] );
354  }
355
356  if ($i=='current')
357  {
358    if ( $picture[$i]['is_picture'] )
359    {
360      if ( $user['enabled_high']=='true' )
361      {
362        $hi_url=get_high_url($picture[$i]);
363        if ( !empty($hi_url) )
364        {
365          $picture[$i]['high_url'] = $hi_url;
366          $picture[$i]['download_url'] = get_download_url('h',$picture[$i]);
367        }
368      }
369    }
370    else
371    { // not a pic - need download link
372      $picture[$i]['download_url'] = get_download_url('e',$picture[$i]);
373    }
374  }
375
376  $picture[$i]['thumbnail'] = get_thumbnail_url($row);
377
378  if ( !empty( $row['name'] ) )
379  {
380    $picture[$i]['name'] = $row['name'];
381  }
382  else
383  {
384    $file_wo_ext = get_filename_wo_extension($row['file']);
385    $picture[$i]['name'] = str_replace('_', ' ', $file_wo_ext);
386  }
387
388  $picture[$i]['url'] = duplicate_picture_url(
389    array(
390      'image_id' => $row['id'],
391      'image_file' => $row['file'],
392      ),
393    array(
394      'start',
395      )
396    );
397
398  if ('previous'==$i and $page['previous_item']==$page['first_item'])
399  {
400    $picture['first'] = $picture[$i];
401  }
402  if ('next'==$i and $page['next_item']==$page['last_item'])
403  {
404    $picture['last'] = $picture[$i];
405  }
406}
407
408// calculation of width and height for the current picture
409if (empty($picture['current']['width']))
410{
411  $taille_image = @getimagesize($picture['current']['image_path']);
412  if ($taille_image!==false)
413  {
414    $picture['current']['width'] = $taille_image[0];
415    $picture['current']['height']= $taille_image[1];
416  }
417}
418
419if (!empty($picture['current']['width']))
420{
421  list(
422    $picture['current']['scaled_width'],
423    $picture['current']['scaled_height']
424    ) = get_picture_size(
425      $picture['current']['width'],
426      $picture['current']['height'],
427      @$user['maxwidth'],
428      @$user['maxheight']
429    );
430}
431
432$url_admin =
433  get_root_url().'admin.php?page=picture_modify'
434  .'&amp;cat_id='.(isset($page['category']) ? $page['category']['id'] : '')
435  .'&amp;image_id='.$page['image_id']
436;
437
438$slideshow_params = array();
439$slideshow_url_params = array();
440
441if (isset($_GET['slideshow']))
442{
443  $page['slideshow'] = true;
444  $page['meta_robots'] = array('noindex'=>1, 'nofollow'=>1);
445
446  $slideshow_params = decode_slideshow_params($_GET['slideshow']);
447  $slideshow_url_params['slideshow'] = encode_slideshow_params($slideshow_params);
448
449  if ($slideshow_params['play'])
450  {
451    $id_pict_redirect = '';
452    if (isset($page['next_item']))
453    {
454      $id_pict_redirect = 'next';
455    }
456    else
457    {
458      if ($slideshow_params['repeat'] and isset($page['first_item']))
459      {
460        $id_pict_redirect = 'first';
461      }
462    }
463
464    if (!empty($id_pict_redirect))
465    {
466      // $redirect_msg, $refresh, $url_link and $title are required for creating
467      // an automated refresh page in header.tpl
468      $refresh = $slideshow_params['period'];
469      $url_link = add_url_params(
470          $picture[$id_pict_redirect]['url'],
471          $slideshow_url_params
472        );
473      $redirect_msg = nl2br(l10n('redirect_msg'));
474    }
475  }
476}
477else
478{
479  $page['slideshow'] = false;
480}
481
482$template->set_filenames(
483  array(
484    'picture' =>
485      (($page['slideshow'] and $conf['light_slideshow']) ? 'slideshow.tpl' : 'picture.tpl'),
486    ));
487
488
489$title =  $picture['current']['name'];
490$title_nb = ($page['current_rank'] + 1).'/'.count($page['items']);
491
492// metadata
493$url_metadata = duplicate_picture_url();
494$url_metadata = add_url_params( $url_metadata, array('metadata'=>null) );
495
496
497// do we have a plugin that can show metadata for something else than images?
498$metadata_showable = trigger_event(
499  'get_element_metadata_available',
500  (
501    ($conf['show_exif'] or $conf['show_iptc'])
502    and isset($picture['current']['image_path'])
503    ),
504  $picture['current']['path']
505  );
506
507if ( $metadata_showable and pwg_get_session_var('show_metadata') )
508{
509  $page['meta_robots']=array('noindex'=>1, 'nofollow'=>1);
510}
511
512
513
514$page['body_id'] = 'thePicturePage';
515
516// allow plugins to change what we computed before passing data to template
517$picture = trigger_event('picture_pictures_data', $picture);
518
519
520if (isset($picture['next']['image_url'])
521    and $picture['next']['is_picture'] )
522{
523  $template->assign('U_PREFETCH', $picture['next']['image_url'] );
524}
525
526//------------------------------------------------------- navigation management
527foreach (array('first','previous','next','last', 'current') as $which_image)
528{
529  if (isset($picture[$which_image]))
530  {
531    $template->assign(
532      $which_image,
533      array(
534        'TITLE' => $picture[$which_image]['name'],
535        'THUMB_SRC' => $picture[$which_image]['thumbnail'],
536        // Params slideshow was transmit to navigation buttons
537        'U_IMG' =>
538          add_url_params(
539            $picture[$which_image]['url'], $slideshow_url_params),
540        'U_DOWNLOAD' => @$picture['current']['download_url'],
541        )
542      );
543  }
544}
545
546
547if ($page['slideshow'])
548{
549  // Add local-slideshow.css file if exists
550  // Not only for ligth
551  $css = PHPWG_ROOT_PATH . get_themeconf('template_dir') . '/theme/'
552       . get_themeconf('theme') . '/local-slideshow.css';
553  if (file_exists($css))
554  {
555    //TODO CORRECT THIS $template->assign_block_vars('slideshow', array());
556  }
557
558  $tpl_slideshow = array();
559
560  //slideshow end
561  $template->assign(
562    array(
563      'U_SLIDESHOW_STOP' => $picture['current']['url'],
564      )
565    );
566
567  foreach (array('repeat', 'play') as $p)
568  {
569    $var_name =
570      'U_'
571      .($slideshow_params[$p] ? 'STOP_' : 'START_')
572      .strtoupper($p);
573
574    $tpl_slideshow[$var_name] =
575          add_url_params(
576            $picture['current']['url'],
577            array('slideshow' =>
578              encode_slideshow_params(
579                array_merge($slideshow_params,
580                  array($p => ! $slideshow_params[$p]))
581                )
582              )
583          );
584  }
585
586  foreach (array('dec', 'inc') as $op)
587  {
588    $new_period = $slideshow_params['period'] + ((($op == 'dec') ? -1 : 1) * $conf['slideshow_period_step']);
589    $new_slideshow_params =
590      correct_slideshow_params(
591        array_merge($slideshow_params,
592                  array('period' => $new_period)));
593
594    if ($new_slideshow_params['period'] === $new_period)
595    {
596      $var_name = 'U_'.strtoupper($op).'_PERIOD';
597      $tpl_slideshow[$var_name] =
598            add_url_params(
599              $picture['current']['url'],
600              array('slideshow' => encode_slideshow_params($new_slideshow_params)
601                  )
602          );
603    }
604  }
605  $template->assign('slideshow', $tpl_slideshow );
606}
607else
608{
609  $template->assign(
610    array(
611      'U_SLIDESHOW_START' =>
612        add_url_params(
613          $picture['current']['url'],
614          array( 'slideshow'=>''))
615      )
616    );
617}
618
619$template->assign(
620  array(
621    'SECTION_TITLE' => $page['title'],
622    'PHOTO' => $title_nb,
623    'SHOW_PICTURE_NAME_ON_TITLE' => $conf['show_picture_name_on_title'],
624
625    'LEVEL_SEPARATOR' => $conf['level_separator'],
626
627    'FILE_PICTURE_NAV_BUTTONS' => 'picture_nav_buttons.tpl',
628
629    'U_HOME' => make_index_url(),
630    'U_UP' => $url_up,
631    'U_METADATA' => $url_metadata,
632    )
633  );
634
635
636//------------------------------------------------------- upper menu management
637
638// admin links
639if (is_admin())
640{
641  if (isset($page['category']))
642  {
643    $template->assign(
644      array(
645        'U_SET_AS_REPRESENTATIVE' => add_url_params($url_self,
646                    array('action'=>'set_as_representative')
647                 )
648        )
649      );
650  }
651
652  $template->assign(
653    array(
654      'U_CADDIE' => add_url_params($url_self,
655                  array('action'=>'add_to_caddie')
656               ),
657      'U_ADMIN' => $url_admin,
658      )
659    );
660}
661
662// favorite manipulation
663if (!is_a_guest())
664{
665  // verify if the picture is already in the favorite of the user
666  $query = '
667SELECT COUNT(*) AS nb_fav
668  FROM '.FAVORITES_TABLE.'
669  WHERE image_id = '.$page['image_id'].'
670    AND user_id = '.$user['id'].'
671;';
672  $result = pwg_query($query);
673  $row = mysql_fetch_array($result);
674
675  if ($row['nb_fav'] == 0)
676  {
677    $template->assign(
678      'favorite',
679      array(
680        'FAVORITE_IMG'  =>
681          get_root_url().get_themeconf('icon_dir').'/favorite.png',
682        'FAVORITE_HINT' => l10n('add_favorites_hint'),
683        'U_FAVORITE'    => add_url_params(
684          $url_self,
685          array('action'=>'add_to_favorites')
686          ),
687        )
688      );
689  }
690  else
691  {
692    $template->assign(
693      'favorite',
694      array(
695        'FAVORITE_IMG'  =>
696          get_root_url().get_themeconf('icon_dir').'/del_favorite.png',
697        'FAVORITE_HINT' => l10n('del_favorites_hint'),
698        'U_FAVORITE'    => add_url_params(
699          $url_self,
700          array('action'=>'remove_from_favorites')
701          ),
702        )
703      );
704  }
705}
706
707//--------------------------------------------------------- picture information
708$header_infos = array(); //for html header use
709// legend
710if (isset($picture['current']['comment'])
711    and !empty($picture['current']['comment']))
712{
713  $template->assign(
714      'COMMENT_IMG',
715        trigger_event('render_element_description',
716          $picture['current']['comment'])
717      );
718  $header_infos['COMMENT'] = strip_tags($picture['current']['comment']);
719}
720
721$infos = array();
722
723// author
724if (!empty($picture['current']['author']))
725{
726  $infos['INFO_AUTHOR'] =
727// FIXME because of search engine partial rewrite, giving the author
728// name threw GET is not supported anymore. This feature should come
729// back later, with a better design
730//     '<a href="'.
731//       PHPWG_ROOT_PATH.'category.php?cat=search'.
732//       '&amp;search=author:'.$picture['current']['author']
733//       .'">'.$picture['current']['author'].'</a>';
734    $picture['current']['author'];
735  $header_infos['INFO_AUTHOR'] = $picture['current']['author'];
736}
737
738// creation date
739if (!empty($picture['current']['date_creation']))
740{
741  $val = format_date($picture['current']['date_creation']);
742  $url = make_index_url(
743    array(
744      'chronology_field'=>'created',
745      'chronology_style'=>'monthly',
746      'chronology_view'=>'list',
747      'chronology_date' => explode('-', $picture['current']['date_creation'])
748      )
749    );
750  $infos['INFO_CREATION_DATE'] =
751    '<a href="'.$url.'" rel="nofollow">'.$val.'</a>';
752}
753
754// date of availability
755$val = format_date($picture['current']['date_available'], 'mysql_datetime');
756$url = make_index_url(
757  array(
758    'chronology_field'=>'posted',
759    'chronology_style'=>'monthly',
760    'chronology_view'=>'list',
761    'chronology_date' => explode(
762      '-',
763      substr($picture['current']['date_available'], 0, 10)
764      )
765    )
766  );
767$infos['INFO_POSTED_DATE'] = '<a href="'.$url.'" rel="nofollow">'.$val.'</a>';
768
769// size in pixels
770if ($picture['current']['is_picture'] and isset($picture['current']['width']) )
771{
772  if ($picture['current']['scaled_width'] !== $picture['current']['width'] )
773  {
774    $infos['INFO_DIMENSIONS'] =
775      '<a href="'.$picture['current']['image_url'].'" title="'.
776      l10n('Original dimensions').'">'.
777      $picture['current']['width'].'*'.$picture['current']['height'].'</a>';
778  }
779  else
780  {
781    $infos['INFO_DIMENSIONS'] =
782      $picture['current']['width'].'*'.$picture['current']['height'];
783  }
784}
785
786// filesize
787if (!empty($picture['current']['filesize']))
788{
789  $infos['INFO_FILESIZE'] =
790    sprintf(l10n('%d Kb'), $picture['current']['filesize']);
791}
792
793// number of visits
794$infos['INFO_VISITS'] = $picture['current']['hit'];
795
796// file
797$infos['INFO_FILE'] = $picture['current']['file'];
798
799$template->assign($infos);
800
801// related tags
802$tags = get_common_tags( array($page['image_id']), -1);
803if ( count($tags) )
804{
805  foreach ($tags as $tag)
806  {
807    $template->append(
808        'related_tags',
809        array(
810          'ID'    => $tag['id'],
811          'NAME'  => $tag['name'],
812          'U_TAG' => make_index_url(
813                      array(
814                        'tags' => array($tag)
815                        )
816                      ),
817          'U_TAG_IMAGE' => duplicate_picture_url(
818                      array(
819                        'section' => 'tags',
820                        'tags' => array($tag)
821                        )
822                    )
823          )
824      );
825  }
826}
827
828// related categories
829if ( count($related_categories)==1 and
830    isset($page['category']) and
831    $related_categories[0]['category_id']==$page['category']['id'] )
832{ // no need to go to db, we have all the info
833  $template->append(
834      'related_categories',
835      get_cat_display_name( $page['category']['upper_names'] )
836    );
837}
838else
839{ // use only 1 sql query to get names for all related categories
840  $ids = array();
841  foreach ($related_categories as $category)
842  {// add all uppercats to $ids
843    $ids = array_merge($ids, explode(',', $category['uppercats']) );
844  }
845  $ids = array_unique($ids);
846  $query = '
847SELECT id, name, permalink
848  FROM '.CATEGORIES_TABLE.'
849  WHERE id IN ('.implode(',',$ids).')';
850  $cat_map = hash_from_query($query, 'id');
851  foreach ($related_categories as $category)
852  {
853    $cats = array();
854    foreach ( explode(',', $category['uppercats']) as $id )
855    {
856      $cats[] = $cat_map[$id];
857    }
858    $template->append('related_categories', get_cat_display_name($cats) );
859  }
860}
861
862// maybe someone wants a special display (call it before page_header so that
863// they can add stylesheets)
864$element_content = trigger_event(
865  'render_element_content',
866  '',
867  $picture['current']
868  );
869$template->assign( 'ELEMENT_CONTENT', $element_content );
870
871// +-----------------------------------------------------------------------+
872// |                               sub pages                               |
873// +-----------------------------------------------------------------------+
874
875include(PHPWG_ROOT_PATH.'include/picture_rate.inc.php');
876include(PHPWG_ROOT_PATH.'include/picture_comment.inc.php');
877if ($metadata_showable and pwg_get_session_var('show_metadata') <> null )
878{
879  include(PHPWG_ROOT_PATH.'include/picture_metadata.inc.php');
880}
881
882include(PHPWG_ROOT_PATH.'include/page_header.php');
883trigger_action('loc_end_picture');
884$template->pparse('picture');
885//------------------------------------------------------------ log informations
886pwg_log($picture['current']['id'], 'picture');
887include(PHPWG_ROOT_PATH.'include/page_tail.php');
888?>
Note: See TracBrowser for help on using the repository browser.