source: trunk/picture.php @ 3600

Last change on this file since 3600 was 3445, checked in by nikrou, 15 years ago

Feature 1026 : Modify / delete comments for users

+ update config table content
+ minor modification of Sylvia theme
+ need refactoring

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