source: trunk/picture.php @ 2512

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