source: trunk/picture.php @ 2469

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