source: trunk/picture.php @ 13777

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