source: tags/release-1_7_2/picture.php @ 26010

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