source: trunk/picture.php @ 30353

Last change on this file since 30353 was 29901, checked in by plg, 10 years ago

bug 3156 fixed: avoid warning on PHP 5.2 for nl2br second parameter

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