source: trunk/picture.php @ 3416

Last change on this file since 3416 was 3409, checked in by nikrou, 15 years ago

feature 1028 : Allow admin to validate comment from picture page

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