source: trunk/picture.php @ 12344

Last change on this file since 12344 was 11839, checked in by rvelices, 13 years ago

feature 2384: improve average rating calculation (final)

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