source: trunk/picture.php @ 8927

Last change on this file since 8927 was 8802, checked in by plg, 13 years ago

bug 937 fixed: makes sure a user won't see the thumbnail of a photo that has a
higher privacy level than user privacy level.

For an acceptable solution at performance level, I have implemented a cache:
for a given user, each album has a representative_picture_id. This cache also
avoids to perform numerous "order by rand()" SQL queries which is the case
when $confallow_random_representative = true;

  • Property svn:eol-style set to LF
File size: 26.9 KB
RevLine 
[2]1<?php
[354]2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[8728]5// | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
[2297]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// +-----------------------------------------------------------------------+
[420]23
[364]24define('PHPWG_ROOT_PATH','./');
[613]25include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
[1082]26include(PHPWG_ROOT_PATH.'include/section_init.inc.php');
[1612]27include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
[1052]28
[1082]29// Check Access and exit when user status is not ok
[1072]30check_status(ACCESS_GUEST);
31
[1082]32// access authorization check
33if (isset($page['category']))
[1036]34{
[1861]35  check_restrictions($page['category']['id']);
[1036]36}
[1082]37
[2327]38$page['rank_of'] = array_flip($page['items']);
39
[1036]40// if this image_id doesn't correspond to this category, an error message is
41// displayed, and execution is stopped
[2327]42if ( !isset($page['rank_of'][$page['image_id']]) )
[934]43{
[2430]44  $query = '
[2446]45SELECT id, file, level
[2430]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']) );
[6654]55    $query .= 'file LIKE \'' .
[2512]56      str_replace(array('_','%'), array('/_','/%'), $page['image_file'] ).
[6654]57      '.%\' ESCAPE \'/\' LIMIT 1';
[2430]58  }
[4325]59  if ( ! ( $row = pwg_db_fetch_assoc(pwg_query($query)) ) )
[2430]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  }
[5127]69
70  $page['image_id'] = $row['id'];
71  $page['image_file'] =  $row['file'];
[2430]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;
[2446]75    if ( !empty($filter['visible_images']) and
[2430]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';
[4325]97      if ( pwg_db_num_rows( pwg_query($query) ) == 0 )
[2430]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  }
[934]124}
125
[2407]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        {
[2572]131                pwg_set_session_var('show_metadata', 1 );
[2407]132        } else {
133        pwg_unset_session_var('show_metadata');
134        }
135}
136
[1590]137// add default event handler for rendering element content
[1787]138add_event_handler(
139  'render_element_content',
140  'default_picture_content',
141  EVENT_HANDLER_PRIORITY_NEUTRAL,
142  2
143  );
[2079]144// add default event handler for rendering element description
145add_event_handler('render_element_description', 'nl2br');
146
[1590]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  if (!isset($element_info['image_url']))
157  { // nothing to do
158    return $content;
159  }
[1793]160
[1882]161  global $user, $page, $template;
[1793]162
[1882]163  $template->set_filenames(
[1787]164    array('default_content'=>'picture_content.tpl')
165    );
[1590]166
[2218]167  if ( !$page['slideshow'] and isset($element_info['high_url']) )
[1590]168  {
169    $uuid = uniqid(rand());
[2227]170    $template->assign(
[1590]171      'high',
172      array(
173        'U_HIGH' => $element_info['high_url'],
174        'UUID'   => $uuid,
175        )
176      );
177  }
[2227]178  $template->assign( array(
[1590]179      'SRC_IMG' => $element_info['image_url'],
180      'ALT_IMG' => $element_info['file'],
[1596]181      'WIDTH_IMG' => @$element_info['scaled_width'],
182      'HEIGHT_IMG' => @$element_info['scaled_height'],
[1590]183      )
184    );
[1882]185  return $template->parse( 'default_content', true);
[1590]186}
187
[1082]188// +-----------------------------------------------------------------------+
189// |                            initialization                             |
190// +-----------------------------------------------------------------------+
191
[1036]192// caching first_rank, last_rank, current_rank in the displayed
193// section. This should also help in readability.
194$page['first_rank']   = 0;
195$page['last_rank']    = count($page['items']) - 1;
[1082]196$page['current_rank'] = $page['rank_of'][ $page['image_id'] ];
[1036]197
198// caching current item : readability purpose
[1082]199$page['current_item'] = $page['image_id'];
[1036]200
201if ($page['current_rank'] != $page['first_rank'])
[2]202{
[1086]203  // caching first & previous item : readability purpose
[1036]204  $page['previous_item'] = $page['items'][ $page['current_rank'] - 1 ];
[1086]205  $page['first_item'] = $page['items'][ $page['first_rank'] ];
[2]206}
[1036]207
208if ($page['current_rank'] != $page['last_rank'])
209{
[1086]210  // caching next & last item : readability purpose
[1036]211  $page['next_item'] = $page['items'][ $page['current_rank'] + 1 ];
[1086]212  $page['last_item'] = $page['items'][ $page['last_rank'] ];
[1036]213}
214
[1503]215$url_up = duplicate_index_url(
[1082]216  array(
217    'start' =>
[8634]218      floor($page['current_rank'] / $page['nb_image_page'])
219      * $page['nb_image_page']
[1082]220    ),
221  array(
222    'start',
223    )
224  );
[1014]225
[1503]226$url_self = duplicate_picture_url();
[811]227
[1082]228// +-----------------------------------------------------------------------+
229// |                                actions                                |
230// +-----------------------------------------------------------------------+
[858]231
[1082]232/**
233 * Actions are favorite adding, user comment deletion, setting the picture
234 * as representative of the current category...
235 *
236 * Actions finish by a redirection
237 */
[858]238
[1590]239if (isset($_GET['action']))
[858]240{
[1082]241  switch ($_GET['action'])
[1041]242  {
[1082]243    case 'add_to_favorites' :
[1041]244    {
[1082]245      $query = '
246INSERT INTO '.FAVORITES_TABLE.'
247  (image_id,user_id)
248  VALUES
249  ('.$page['image_id'].','.$user['id'].')
250;';
251      pwg_query($query);
252
253      redirect($url_self);
[1086]254
[1082]255      break;
[1041]256    }
[1082]257    case 'remove_from_favorites' :
258    {
259      $query = '
260DELETE FROM '.FAVORITES_TABLE.'
261  WHERE user_id = '.$user['id'].'
262    AND image_id = '.$page['image_id'].'
263;';
264      pwg_query($query);
[1041]265
[1082]266      if ('favorites' == $page['section'])
267      {
268        redirect($url_up);
269      }
270      else
271      {
272        redirect($url_self);
273      }
[1086]274
[1082]275      break;
276    }
277    case 'set_as_representative' :
[1041]278    {
[8126]279      if (is_admin() and isset($page['category']))
[1082]280      {
[1041]281        $query = '
[1082]282UPDATE '.CATEGORIES_TABLE.'
283  SET representative_picture_id = '.$page['image_id'].'
[1861]284  WHERE id = '.$page['category']['id'].'
[1082]285;';
286        pwg_query($query);
[8802]287
288        $query = '
289UPDATE '.USER_CACHE_CATEGORIES_TABLE.'
290  SET user_representative_picture_id = NULL
291  WHERE user_id = '.$user['id'].'
292    AND cat_id = '.$page['category']['id'].'
293;';
294        pwg_query($query);
[1082]295      }
[1086]296
[1082]297      redirect($url_self);
[1086]298
[1082]299      break;
300    }
301    case 'toggle_metadata' :
302    {
303      break;
304    }
305    case 'add_to_caddie' :
306    {
[1106]307      fill_caddie(array($page['image_id']));
[1082]308      redirect($url_self);
309      break;
310    }
311    case 'rate' :
312    {
[1107]313      include_once(PHPWG_ROOT_PATH.'include/functions_rate.inc.php');
[1787]314      rate_picture(
315        $page['image_id'],
316        isset($_POST['rate']) ? $_POST['rate'] : $_GET['rate']
317        );
[1082]318      redirect($url_self);
319    }
[3445]320    case 'edit_comment' :
321    {
[5195]322      check_pwg_token();
[6615]323
[5127]324      include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
[5195]325
326      check_input_parameter('comment_to_edit', $_GET, false, PATTERN_ID);
327
328      $author_id = get_comment_author_id($_GET['comment_to_edit']);
[6615]329
[5195]330      if (can_manage_comment('edit', $author_id))
[3445]331      {
[5127]332        if (!empty($_POST['content']))
333        {
[5195]334          update_user_comment(
335            array(
336              'comment_id' => $_GET['comment_to_edit'],
337              'image_id' => $page['image_id'],
338              'content' => $_POST['content']
339              ),
340            $_POST['key']
341            );
[6615]342
[5127]343          redirect($url_self);
[5195]344        }
345        else
346        {
[5127]347          $edit_comment = $_GET['comment_to_edit'];
348          break;
349        }
[3445]350      }
351    }
[1082]352    case 'delete_comment' :
353    {
[5195]354      check_pwg_token();
[6615]355
[5127]356      include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
[6615]357
[5195]358      check_input_parameter('comment_to_delete', $_GET, false, PATTERN_ID);
359
360      $author_id = get_comment_author_id($_GET['comment_to_delete']);
[6615]361
[5195]362      if (can_manage_comment('delete', $author_id))
[1082]363      {
[5127]364        delete_user_comment($_GET['comment_to_delete']);
[1082]365      }
[6615]366
[1082]367      redirect($url_self);
368    }
[3409]369    case 'validate_comment' :
370    {
[5195]371      check_pwg_token();
[6615]372
[5127]373      include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
[5195]374
375      check_input_parameter('comment_to_validate', $_GET, false, PATTERN_ID);
[6615]376
[5653]377      $author_id = get_comment_author_id($_GET['comment_to_validate']);
[6615]378
[5195]379      if (can_manage_comment('validate', $author_id))
[3409]380      {
[5195]381        validate_user_comment($_GET['comment_to_validate']);
[3409]382      }
[6615]383
[3409]384      redirect($url_self);
385    }
386
[1082]387  }
[1041]388}
389
[1082]390// incrementation of the number of hits, we do this only if no action
[2155]391if (trigger_event('allow_increment_element_hit_count', !isset($_POST['content']) ) )
[2048]392{
393  $query = '
[1082]394UPDATE
395  '.IMAGES_TABLE.'
396  SET hit = hit+1
397  WHERE id = '.$page['image_id'].'
398;';
[2048]399  pwg_query($query);
400}
[745]401//---------------------------------------------------------- related categories
402$query = '
403SELECT category_id,uppercats,commentable,global_rank
404  FROM '.IMAGE_CATEGORY_TABLE.'
405    INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id
[1082]406  WHERE image_id = '.$page['image_id'].'
[1677]407'.get_sql_condition_FandF
408  (
409    array
410      (
411        'forbidden_categories' => 'category_id',
412        'visible_categories' => 'category_id'
413      ),
414    'AND'
415  ).'
[745]416;';
417$result = pwg_query($query);
418$related_categories = array();
[4325]419while ($row = pwg_db_fetch_assoc($result))
[745]420{
[6591]421  $row['commentable'] = boolean_to_string($row['commentable']);
[745]422  array_push($related_categories, $row);
423}
424usort($related_categories, 'global_rank_compare');
[1086]425//-------------------------first, prev, current, next & last picture management
[402]426$picture = array();
[368]427
[1082]428$ids = array($page['image_id']);
[1036]429if (isset($page['previous_item']))
[465]430{
[1036]431  array_push($ids, $page['previous_item']);
[1086]432  array_push($ids, $page['first_item']);
[465]433}
[1036]434if (isset($page['next_item']))
[465]435{
[1036]436  array_push($ids, $page['next_item']);
[1086]437  array_push($ids, $page['last_item']);
[465]438}
[368]439
[454]440$query = '
[1036]441SELECT *
442  FROM '.IMAGES_TABLE.'
443  WHERE id IN ('.implode(',', $ids).')
444;';
[368]445
[1036]446$result = pwg_query($query);
[368]447
[4325]448while ($row = pwg_db_fetch_assoc($result))
[345]449{
[1036]450  if (isset($page['previous_item']) and $row['id'] == $page['previous_item'])
[465]451  {
[1086]452    $i = 'previous';
[465]453  }
[1036]454  else if (isset($page['next_item']) and $row['id'] == $page['next_item'])
[465]455  {
[1036]456    $i = 'next';
[465]457  }
[1086]458  else if (isset($page['first_item']) and $row['id'] == $page['first_item'])
459  {
460    $i = 'first';
461  }
462  else if (isset($page['last_item']) and $row['id'] == $page['last_item'])
463  {
464    $i = 'last';
465  }
[1036]466  else
467  {
468    $i = 'current';
469  }
[1059]470
[1596]471  $picture[$i] = $row;
[465]472
473  $picture[$i]['is_picture'] = false;
474  if (in_array(get_extension($row['file']), $conf['picture_ext']))
475  {
476    $picture[$i]['is_picture'] = true;
477  }
[1059]478
[1612]479  // ------ build element_path and element_url
480  $picture[$i]['element_path'] = get_element_path($picture[$i]);
481  $picture[$i]['element_url'] = get_element_url($picture[$i]);
[402]482
[1612]483  // ------ build image_path and image_url
484  if ($i=='current' or $i=='next')
[465]485  {
[1612]486    $picture[$i]['image_path'] = get_image_path( $picture[$i] );
487    $picture[$i]['image_url'] = get_image_url( $picture[$i] );
[465]488  }
[1590]489
[1612]490  if ($i=='current')
[465]491  {
[1612]492    if ( $picture[$i]['is_picture'] )
[536]493    {
[1612]494      if ( $user['enabled_high']=='true' )
[536]495      {
[1612]496        $hi_url=get_high_url($picture[$i]);
497        if ( !empty($hi_url) )
[1090]498        {
[1612]499          $picture[$i]['high_url'] = $hi_url;
500          $picture[$i]['download_url'] = get_download_url('h',$picture[$i]);
[1090]501        }
[536]502      }
503    }
[1590]504    else
[1612]505    { // not a pic - need download link
506      $picture[$i]['download_url'] = get_download_url('e',$picture[$i]);
[1590]507    }
508  }
509
[1596]510  $picture[$i]['thumbnail'] = get_thumbnail_url($row);
[1059]511
[402]512  if ( !empty( $row['name'] ) )
[345]513  {
[465]514    $picture[$i]['name'] = $row['name'];
[345]515  }
516  else
517  {
[1612]518    $file_wo_ext = get_filename_wo_extension($row['file']);
[465]519    $picture[$i]['name'] = str_replace('_', ' ', $file_wo_ext);
[345]520  }
521
[6712]522  $picture[$i]['name'] = trigger_event('render_element_description', $picture[$i]['name']);
523
[1503]524  $picture[$i]['url'] = duplicate_picture_url(
[1082]525    array(
526      'image_id' => $row['id'],
[1090]527      'image_file' => $row['file'],
[1082]528      ),
529    array(
530      'start',
531      )
532    );
[1086]533
534  if ('previous'==$i and $page['previous_item']==$page['first_item'])
535  {
536    $picture['first'] = $picture[$i];
537  }
538  if ('next'==$i and $page['next_item']==$page['last_item'])
539  {
540    $picture['last'] = $picture[$i];
541  }
[345]542}
[368]543
[1590]544// calculation of width and height for the current picture
545if (empty($picture['current']['width']))
546{
547  $taille_image = @getimagesize($picture['current']['image_path']);
548  if ($taille_image!==false)
549  {
550    $picture['current']['width'] = $taille_image[0];
551    $picture['current']['height']= $taille_image[1];
552  }
553}
554
555if (!empty($picture['current']['width']))
556{
[1787]557  list(
558    $picture['current']['scaled_width'],
559    $picture['current']['scaled_height']
560    ) = get_picture_size(
[1590]561      $picture['current']['width'],
562      $picture['current']['height'],
563      @$user['maxwidth'],
564      @$user['maxheight']
565    );
566}
567
[2218]568$slideshow_params = array();
569$slideshow_url_params = array();
[858]570
[2218]571if (isset($_GET['slideshow']))
[2]572{
[1793]573  $page['slideshow'] = true;
[2218]574  $page['meta_robots'] = array('noindex'=>1, 'nofollow'=>1);
575
576  $slideshow_params = decode_slideshow_params($_GET['slideshow']);
577  $slideshow_url_params['slideshow'] = encode_slideshow_params($slideshow_params);
578
579  if ($slideshow_params['play'])
580  {
581    $id_pict_redirect = '';
582    if (isset($page['next_item']))
[2169]583    {
[2218]584      $id_pict_redirect = 'next';
[2169]585    }
[2218]586    else
587    {
588      if ($slideshow_params['repeat'] and isset($page['first_item']))
589      {
590        $id_pict_redirect = 'first';
591      }
592    }
593
594    if (!empty($id_pict_redirect))
595    {
[2521]596      // $refresh, $url_link and $title are required for creating
[2218]597      // an automated refresh page in header.tpl
598      $refresh = $slideshow_params['period'];
599      $url_link = add_url_params(
600          $picture[$id_pict_redirect]['url'],
601          $slideshow_url_params
602        );
603    }
[1793]604  }
[2218]605}
606else
607{
608  $page['slideshow'] = false;
609}
[2549]610if ($page['slideshow'] and $conf['light_slideshow'])
611{
612  $template->set_filenames( array('slideshow' => 'slideshow.tpl'));
613}
614else
615{
616  $template->set_filenames( array('picture' => 'picture.tpl'));
617}
[2218]618
[1793]619$title =  $picture['current']['name'];
[1820]620$title_nb = ($page['current_rank'] + 1).'/'.count($page['items']);
[2]621
[531]622// metadata
[1503]623$url_metadata = duplicate_picture_url();
[2407]624$url_metadata = add_url_params( $url_metadata, array('metadata'=>null) );
[1590]625
[2407]626
[1590]627// do we have a plugin that can show metadata for something else than images?
[1787]628$metadata_showable = trigger_event(
629  'get_element_metadata_available',
630  (
631    ($conf['show_exif'] or $conf['show_iptc'])
632    and isset($picture['current']['image_path'])
[1590]633    ),
[1787]634  $picture['current']['path']
635  );
636
[2407]637if ( $metadata_showable and pwg_get_session_var('show_metadata') )
[531]638{
[2407]639  $page['meta_robots']=array('noindex'=>1, 'nofollow'=>1);
[531]640}
[1590]641
[2407]642
[1590]643$page['body_id'] = 'thePicturePage';
644
[1882]645// allow plugins to change what we computed before passing data to template
646$picture = trigger_event('picture_pictures_data', $picture);
[1787]647
[1882]648
[1787]649if (isset($picture['next']['image_url'])
[2204]650    and $picture['next']['is_picture'] )
[531]651{
[2227]652  $template->assign('U_PREFETCH', $picture['next']['image_url'] );
[531]653}
654
[1036]655//------------------------------------------------------- navigation management
[2227]656foreach (array('first','previous','next','last', 'current') as $which_image)
[1020]657{
[1086]658  if (isset($picture[$which_image]))
659  {
[2227]660    $template->assign(
[1086]661      $which_image,
[2413]662      array_merge(
663        $picture[$which_image],
664        array(
665          'TITLE' => $picture[$which_image]['name'],
666          'THUMB_SRC' => $picture[$which_image]['thumbnail'],
667          // Params slideshow was transmit to navigation buttons
668          'U_IMG' =>
669            add_url_params(
670              $picture[$which_image]['url'], $slideshow_url_params),
671          )
[1086]672        )
673      );
[5304]674    if ($conf['picture_download_icon'] and !empty($picture['current']['download_url']))
675    {
676      $template->append($which_image, array('U_DOWNLOAD' => $picture['current']['download_url']), true);
677    }
[1086]678  }
[1020]679}
680
[2218]681
682if ($page['slideshow'])
683{
[2227]684  $tpl_slideshow = array();
685
[2218]686  //slideshow end
[2227]687  $template->assign(
[2218]688    array(
[2227]689      'U_SLIDESHOW_STOP' => $picture['current']['url'],
[2218]690      )
691    );
692
693  foreach (array('repeat', 'play') as $p)
694  {
[2227]695    $var_name =
696      'U_'
697      .($slideshow_params[$p] ? 'STOP_' : 'START_')
698      .strtoupper($p);
699
700    $tpl_slideshow[$var_name] =
[2218]701          add_url_params(
702            $picture['current']['url'],
703            array('slideshow' =>
704              encode_slideshow_params(
[2227]705                array_merge($slideshow_params,
[2218]706                  array($p => ! $slideshow_params[$p]))
707                )
708              )
[2227]709          );
[2218]710  }
711
712  foreach (array('dec', 'inc') as $op)
713  {
714    $new_period = $slideshow_params['period'] + ((($op == 'dec') ? -1 : 1) * $conf['slideshow_period_step']);
715    $new_slideshow_params =
716      correct_slideshow_params(
[2227]717        array_merge($slideshow_params,
[2218]718                  array('period' => $new_period)));
719
720    if ($new_slideshow_params['period'] === $new_period)
721    {
[2227]722      $var_name = 'U_'.strtoupper($op).'_PERIOD';
723      $tpl_slideshow[$var_name] =
[2218]724            add_url_params(
725              $picture['current']['url'],
726              array('slideshow' => encode_slideshow_params($new_slideshow_params)
727                  )
728          );
729    }
730  }
[2227]731  $template->assign('slideshow', $tpl_slideshow );
[2218]732}
[5293]733elseif ($conf['picture_slideshow_icon'])
[2218]734{
[2227]735  $template->assign(
[2218]736    array(
[2227]737      'U_SLIDESHOW_START' =>
[2218]738        add_url_params(
739          $picture['current']['url'],
740          array( 'slideshow'=>''))
741      )
742    );
743}
744
[2227]745$template->assign(
[1082]746  array(
[1128]747    'SECTION_TITLE' => $page['title'],
[1082]748    'PHOTO' => $title_nb,
[2227]749    'SHOW_PICTURE_NAME_ON_TITLE' => $conf['show_picture_name_on_title'],
[2759]750    'IS_HOME' => ('categories'==$page['section'] and !isset($page['category']) ),
[368]751
[1082]752    'LEVEL_SEPARATOR' => $conf['level_separator'],
[2309]753
[2227]754    'U_UP' => $url_up,
[5293]755    'DISPLAY_NAV_BUTTONS' => $conf['picture_navigation_icons'],
756    'DISPLAY_NAV_THUMB' => $conf['picture_navigation_thumb']
[1082]757    )
758  );
[803]759
[5293]760if ($conf['picture_metadata_icon'])
761{
762  $template->assign('U_METADATA', $url_metadata);
763}
[803]764
[5293]765
[536]766//------------------------------------------------------- upper menu management
[1082]767
[2227]768// admin links
[1070]769if (is_admin())
[858]770{
[2227]771  if (isset($page['category']))
772  {
773    $template->assign(
774      array(
775        'U_SET_AS_REPRESENTATIVE' => add_url_params($url_self,
776                    array('action'=>'set_as_representative')
777                 )
778        )
779      );
780  }
[2309]781
[3167]782  $url_admin =
783    get_root_url().'admin.php?page=picture_modify'
784    .'&amp;cat_id='.(isset($page['category']) ? $page['category']['id'] : '')
785    .'&amp;image_id='.$page['image_id'];
786
[2227]787  $template->assign(
[858]788    array(
[2227]789      'U_CADDIE' => add_url_params($url_self,
[1094]790                  array('action'=>'add_to_caddie')
[2227]791               ),
792      'U_ADMIN' => $url_admin,
[1082]793      )
[858]794    );
[3167]795
[6025]796  $template->assign('available_permission_levels', get_privacy_level_options());
[858]797}
798
[1082]799// favorite manipulation
[5305]800if (!is_a_guest() and $conf['picture_favorite_icon'])
[531]801{
802  // verify if the picture is already in the favorite of the user
[1082]803  $query = '
804SELECT COUNT(*) AS nb_fav
805  FROM '.FAVORITES_TABLE.'
806  WHERE image_id = '.$page['image_id'].'
807    AND user_id = '.$user['id'].'
808;';
[6615]809  $row = pwg_db_fetch_assoc( pwg_query($query) );
810        $is_favorite = $row['nb_fav'] != 0;
[1086]811
[6615]812  $template->assign(
813    'favorite',
814    array(
815                        'IS_FAVORITE' => $is_favorite,
816      'U_FAVORITE'    => add_url_params(
817        $url_self,
818        array('action'=> !$is_favorite ? 'add_to_favorites' : 'remove_from_favorites' )
819        ),
820      )
821    );
[2]822}
[368]823
[2]824//--------------------------------------------------------- picture information
[393]825// legend
[465]826if (isset($picture['current']['comment'])
827    and !empty($picture['current']['comment']))
[393]828{
[2227]829  $template->assign(
830      'COMMENT_IMG',
[2079]831        trigger_event('render_element_description',
832          $picture['current']['comment'])
[2227]833      );
[393]834}
835
[847]836$infos = array();
837
838// author
839if (!empty($picture['current']['author']))
[51]840{
[847]841  $infos['INFO_AUTHOR'] =
[1825]842// FIXME because of search engine partial rewrite, giving the author
843// name threw GET is not supported anymore. This feature should come
844// back later, with a better design
[1008]845//     '<a href="'.
846//       PHPWG_ROOT_PATH.'category.php?cat=search'.
847//       '&amp;search=author:'.$picture['current']['author']
848//       .'">'.$picture['current']['author'].'</a>';
849    $picture['current']['author'];
[51]850}
[774]851
[847]852// creation date
853if (!empty($picture['current']['date_creation']))
[635]854{
[1051]855  $val = format_date($picture['current']['date_creation']);
[1503]856  $url = make_index_url(
[1825]857    array(
858      'chronology_field'=>'created',
859      'chronology_style'=>'monthly',
860      'chronology_view'=>'list',
861      'chronology_date' => explode('-', $picture['current']['date_creation'])
862      )
863    );
864  $infos['INFO_CREATION_DATE'] =
865    '<a href="'.$url.'" rel="nofollow">'.$val.'</a>';
[847]866}
867
868// date of availability
[3122]869$val = format_date($picture['current']['date_available']);
[1503]870$url = make_index_url(
[1825]871  array(
872    'chronology_field'=>'posted',
873    'chronology_style'=>'monthly',
874    'chronology_view'=>'list',
875    'chronology_date' => explode(
876      '-',
877      substr($picture['current']['date_available'], 0, 10)
[1090]878      )
[1825]879    )
880  );
[1135]881$infos['INFO_POSTED_DATE'] = '<a href="'.$url.'" rel="nofollow">'.$val.'</a>';
[847]882
883// size in pixels
[1590]884if ($picture['current']['is_picture'] and isset($picture['current']['width']) )
[847]885{
[1590]886  if ($picture['current']['scaled_width'] !== $picture['current']['width'] )
[568]887  {
[847]888    $infos['INFO_DIMENSIONS'] =
[1590]889      '<a href="'.$picture['current']['image_url'].'" title="'.
[847]890      l10n('Original dimensions').'">'.
[1590]891      $picture['current']['width'].'*'.$picture['current']['height'].'</a>';
[568]892  }
[635]893  else
894  {
[1590]895    $infos['INFO_DIMENSIONS'] =
896      $picture['current']['width'].'*'.$picture['current']['height'];
[635]897  }
[568]898}
[774]899
[847]900// filesize
901if (!empty($picture['current']['filesize']))
902{
903  $infos['INFO_FILESIZE'] =
904    sprintf(l10n('%d Kb'), $picture['current']['filesize']);
905}
906
907// number of visits
908$infos['INFO_VISITS'] = $picture['current']['hit'];
909
910// file
911$infos['INFO_FILE'] = $picture['current']['file'];
912
[2227]913$template->assign($infos);
[5304]914$template->assign('display_info', unserialize($conf['picture_informations']));
[2227]915
916// related tags
[1827]917$tags = get_common_tags( array($page['image_id']), -1);
918if ( count($tags) )
[847]919{
[2227]920  foreach ($tags as $tag)
[1119]921  {
[2227]922    $template->append(
923        'related_tags',
[2413]924        array_merge( $tag,
925          array(
926            'URL' => make_index_url(
[2227]927                      array(
928                        'tags' => array($tag)
929                        )
930                      ),
[2413]931            'U_TAG_IMAGE' => duplicate_picture_url(
[2227]932                      array(
933                        'section' => 'tags',
934                        'tags' => array($tag)
935                        )
936                    )
[1119]937          )
[2413]938        )
[2227]939      );
[1119]940  }
[847]941}
942
943// related categories
[2309]944if ( count($related_categories)==1 and
945    isset($page['category']) and
946    $related_categories[0]['category_id']==$page['category']['id'] )
947{ // no need to go to db, we have all the info
[2227]948  $template->append(
[2309]949      'related_categories',
950      get_cat_display_name( $page['category']['upper_names'] )
[847]951    );
952}
[2309]953else
954{ // use only 1 sql query to get names for all related categories
955  $ids = array();
956  foreach ($related_categories as $category)
957  {// add all uppercats to $ids
958    $ids = array_merge($ids, explode(',', $category['uppercats']) );
959  }
960  $ids = array_unique($ids);
961  $query = '
962SELECT id, name, permalink
963  FROM '.CATEGORIES_TABLE.'
964  WHERE id IN ('.implode(',',$ids).')';
965  $cat_map = hash_from_query($query, 'id');
966  foreach ($related_categories as $category)
967  {
968    $cats = array();
969    foreach ( explode(',', $category['uppercats']) as $id )
970    {
971      $cats[] = $cat_map[$id];
972    }
973    $template->append('related_categories', get_cat_display_name($cats) );
974  }
975}
[847]976
[1882]977// maybe someone wants a special display (call it before page_header so that
978// they can add stylesheets)
979$element_content = trigger_event(
980  'render_element_content',
981  '',
982  $picture['current']
983  );
[2227]984$template->assign( 'ELEMENT_CONTENT', $element_content );
[1882]985
[1082]986// +-----------------------------------------------------------------------+
987// |                               sub pages                               |
988// +-----------------------------------------------------------------------+
[847]989
[1082]990include(PHPWG_ROOT_PATH.'include/picture_rate.inc.php');
991include(PHPWG_ROOT_PATH.'include/picture_comment.inc.php');
[2407]992if ($metadata_showable and pwg_get_session_var('show_metadata') <> null )
[1107]993{
994  include(PHPWG_ROOT_PATH.'include/picture_metadata.inc.php');
995}
[345]996
[1627]997include(PHPWG_ROOT_PATH.'include/page_header.php');
[1793]998trigger_action('loc_end_picture');
[2549]999if ($page['slideshow'] and $conf['light_slideshow'])
1000{
1001  $template->pparse('slideshow');
1002}
1003else
1004{
1005  $template->pparse('picture');
1006}
[2327]1007//------------------------------------------------------------ log informations
1008pwg_log($picture['current']['id'], 'picture');
[369]1009include(PHPWG_ROOT_PATH.'include/page_tail.php');
[6615]1010?>
Note: See TracBrowser for help on using the repository browser.