source: branches/2.2/picture.php @ 11371

Last change on this file since 11371 was 10123, checked in by mistic100, 13 years ago

merge r10097 & r10122 from trunk

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