source: trunk/picture.php @ 5021

Last change on this file since 5021 was 5021, checked in by nikrou, 14 years ago

Feature 1451 : localization with gettext
Use php-gettext (developpement version rev43, because of php5.3) as fallback
Use native language (english) instead of key for translation
Keep directory en_UK for english customization
Need some refactoring for plurals

Todo : managing plugins in the same way

File size: 26.2 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');
28include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
29
30// Check Access and exit when user status is not ok
31check_status(ACCESS_GUEST);
32
33// access authorization check
34if (isset($page['category']))
35{
36  check_restrictions($page['category']['id']);
37}
38
39$page['rank_of'] = array_flip($page['items']);
40
41// if this image_id doesn't correspond to this category, an error message is
42// displayed, and execution is stopped
43if ( !isset($page['rank_of'][$page['image_id']]) )
44{
45  $query = '
46SELECT id, file, level
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']) );
56    $query .= 'file LIKE "' .
57      str_replace(array('_','%'), array('/_','/%'), $page['image_file'] ).
58      '.%" ESCAPE "/" LIMIT 1';
59  }
60  if ( ! ( $row = pwg_db_fetch_assoc(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;
74    if ( !empty($filter['visible_images']) and
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 ( pwg_db_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  }
123}
124
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        {
130                pwg_set_session_var('show_metadata', 1 );
131        } else {
132        pwg_unset_session_var('show_metadata');
133        }
134}
135
136// add default event handler for rendering element content
137add_event_handler(
138  'render_element_content',
139  'default_picture_content',
140  EVENT_HANDLER_PRIORITY_NEUTRAL,
141  2
142  );
143// add default event handler for rendering element description
144add_event_handler('render_element_description', 'nl2br');
145
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  }
159
160  global $user, $page, $template;
161
162  $template->set_filenames(
163    array('default_content'=>'picture_content.tpl')
164    );
165
166  if ( !$page['slideshow'] and isset($element_info['high_url']) )
167  {
168    $uuid = uniqid(rand());
169    $template->assign(
170      'high',
171      array(
172        'U_HIGH' => $element_info['high_url'],
173        'UUID'   => $uuid,
174        )
175      );
176  }
177  $template->assign( array(
178      'SRC_IMG' => $element_info['image_url'],
179      'ALT_IMG' => $element_info['file'],
180      'WIDTH_IMG' => @$element_info['scaled_width'],
181      'HEIGHT_IMG' => @$element_info['scaled_height'],
182      )
183    );
184  return $template->parse( 'default_content', true);
185}
186
187// +-----------------------------------------------------------------------+
188// |                            initialization                             |
189// +-----------------------------------------------------------------------+
190
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;
195$page['current_rank'] = $page['rank_of'][ $page['image_id'] ];
196
197// caching current item : readability purpose
198$page['current_item'] = $page['image_id'];
199
200if ($page['current_rank'] != $page['first_rank'])
201{
202  // caching first & previous item : readability purpose
203  $page['previous_item'] = $page['items'][ $page['current_rank'] - 1 ];
204  $page['first_item'] = $page['items'][ $page['first_rank'] ];
205}
206
207if ($page['current_rank'] != $page['last_rank'])
208{
209  // caching next & last item : readability purpose
210  $page['next_item'] = $page['items'][ $page['current_rank'] + 1 ];
211  $page['last_item'] = $page['items'][ $page['last_rank'] ];
212}
213
214$url_up = duplicate_index_url(
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  );
224
225$url_self = duplicate_picture_url();
226
227// +-----------------------------------------------------------------------+
228// |                                actions                                |
229// +-----------------------------------------------------------------------+
230
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 */
237
238if (isset($_GET['action']))
239{
240  switch ($_GET['action'])
241  {
242    case 'add_to_favorites' :
243    {
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);
253
254      break;
255    }
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);
264
265      if ('favorites' == $page['section'])
266      {
267        redirect($url_up);
268      }
269      else
270      {
271        redirect($url_self);
272      }
273
274      break;
275    }
276    case 'set_as_representative' :
277    {
278      if (is_admin() and !is_adviser() and isset($page['category']))
279      {
280        $query = '
281UPDATE '.CATEGORIES_TABLE.'
282  SET representative_picture_id = '.$page['image_id'].'
283  WHERE id = '.$page['category']['id'].'
284;';
285        pwg_query($query);
286      }
287
288      redirect($url_self);
289
290      break;
291    }
292    case 'toggle_metadata' :
293    {
294      break;
295    }
296    case 'add_to_caddie' :
297    {
298      fill_caddie(array($page['image_id']));
299      redirect($url_self);
300      break;
301    }
302    case 'rate' :
303    {
304      include_once(PHPWG_ROOT_PATH.'include/functions_rate.inc.php');
305      rate_picture(
306        $page['image_id'],
307        isset($_POST['rate']) ? $_POST['rate'] : $_GET['rate']
308        );
309      redirect($url_self);
310    }
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    }
331    case 'delete_comment' :
332    {
333      if (isset($_GET['comment_to_delete'])
334          and is_numeric($_GET['comment_to_delete'])
335          and (is_admin() || $conf['user_can_delete_comment']))
336      {
337        delete_user_comment($_GET['comment_to_delete']);
338      }
339      redirect($url_self);
340    }
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
358  }
359}
360
361// incrementation of the number of hits, we do this only if no action
362if (trigger_event('allow_increment_element_hit_count', !isset($_POST['content']) ) )
363{
364  $query = '
365UPDATE
366  '.IMAGES_TABLE.'
367  SET hit = hit+1
368  WHERE id = '.$page['image_id'].'
369;';
370  pwg_query($query);
371}
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
377  WHERE image_id = '.$page['image_id'].'
378'.get_sql_condition_FandF
379  (
380    array
381      (
382        'forbidden_categories' => 'category_id',
383        'visible_categories' => 'category_id'
384      ),
385    'AND'
386  ).'
387;';
388$result = pwg_query($query);
389$related_categories = array();
390while ($row = pwg_db_fetch_assoc($result))
391{
392  array_push($related_categories, $row);
393}
394usort($related_categories, 'global_rank_compare');
395//-------------------------first, prev, current, next & last picture management
396$picture = array();
397
398$ids = array($page['image_id']);
399if (isset($page['previous_item']))
400{
401  array_push($ids, $page['previous_item']);
402  array_push($ids, $page['first_item']);
403}
404if (isset($page['next_item']))
405{
406  array_push($ids, $page['next_item']);
407  array_push($ids, $page['last_item']);
408}
409
410$query = '
411SELECT *
412  FROM '.IMAGES_TABLE.'
413  WHERE id IN ('.implode(',', $ids).')
414;';
415
416$result = pwg_query($query);
417
418while ($row = pwg_db_fetch_assoc($result))
419{
420  if (isset($page['previous_item']) and $row['id'] == $page['previous_item'])
421  {
422    $i = 'previous';
423  }
424  else if (isset($page['next_item']) and $row['id'] == $page['next_item'])
425  {
426    $i = 'next';
427  }
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  }
436  else
437  {
438    $i = 'current';
439  }
440
441  $picture[$i] = $row;
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  }
448
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]);
452
453  // ------ build image_path and image_url
454  if ($i=='current' or $i=='next')
455  {
456    $picture[$i]['image_path'] = get_image_path( $picture[$i] );
457    $picture[$i]['image_url'] = get_image_url( $picture[$i] );
458  }
459
460  if ($i=='current')
461  {
462    if ( $picture[$i]['is_picture'] )
463    {
464      if ( $user['enabled_high']=='true' )
465      {
466        $hi_url=get_high_url($picture[$i]);
467        if ( !empty($hi_url) )
468        {
469          $picture[$i]['high_url'] = $hi_url;
470          $picture[$i]['download_url'] = get_download_url('h',$picture[$i]);
471        }
472      }
473    }
474    else
475    { // not a pic - need download link
476      $picture[$i]['download_url'] = get_download_url('e',$picture[$i]);
477    }
478  }
479
480  $picture[$i]['thumbnail'] = get_thumbnail_url($row);
481
482  if ( !empty( $row['name'] ) )
483  {
484    $picture[$i]['name'] = $row['name'];
485  }
486  else
487  {
488    $file_wo_ext = get_filename_wo_extension($row['file']);
489    $picture[$i]['name'] = str_replace('_', ' ', $file_wo_ext);
490  }
491
492  $picture[$i]['url'] = duplicate_picture_url(
493    array(
494      'image_id' => $row['id'],
495      'image_file' => $row['file'],
496      ),
497    array(
498      'start',
499      )
500    );
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  }
510}
511
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{
525  list(
526    $picture['current']['scaled_width'],
527    $picture['current']['scaled_height']
528    ) = get_picture_size(
529      $picture['current']['width'],
530      $picture['current']['height'],
531      @$user['maxwidth'],
532      @$user['maxheight']
533    );
534}
535
536$slideshow_params = array();
537$slideshow_url_params = array();
538
539if (isset($_GET['slideshow']))
540{
541  $page['slideshow'] = true;
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']))
551    {
552      $id_pict_redirect = 'next';
553    }
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    {
564      // $refresh, $url_link and $title are required for creating
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    }
572  }
573}
574else
575{
576  $page['slideshow'] = false;
577}
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}
586
587$title =  $picture['current']['name'];
588$title_nb = ($page['current_rank'] + 1).'/'.count($page['items']);
589
590// metadata
591$url_metadata = duplicate_picture_url();
592$url_metadata = add_url_params( $url_metadata, array('metadata'=>null) );
593
594
595// do we have a plugin that can show metadata for something else than images?
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'])
601    ),
602  $picture['current']['path']
603  );
604
605if ( $metadata_showable and pwg_get_session_var('show_metadata') )
606{
607  $page['meta_robots']=array('noindex'=>1, 'nofollow'=>1);
608}
609
610
611$page['body_id'] = 'thePicturePage';
612
613// allow plugins to change what we computed before passing data to template
614$picture = trigger_event('picture_pictures_data', $picture);
615
616
617if (isset($picture['next']['image_url'])
618    and $picture['next']['is_picture'] )
619{
620  $template->assign('U_PREFETCH', $picture['next']['image_url'] );
621}
622
623//------------------------------------------------------- navigation management
624foreach (array('first','previous','next','last', 'current') as $which_image)
625{
626  if (isset($picture[$which_image]))
627  {
628    $template->assign(
629      $which_image,
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          )
641        )
642      );
643  }
644}
645
646
647if ($page['slideshow'])
648{
649  $tpl_slideshow = array();
650
651  //slideshow end
652  $template->assign(
653    array(
654      'U_SLIDESHOW_STOP' => $picture['current']['url'],
655      )
656    );
657
658  foreach (array('repeat', 'play') as $p)
659  {
660    $var_name =
661      'U_'
662      .($slideshow_params[$p] ? 'STOP_' : 'START_')
663      .strtoupper($p);
664
665    $tpl_slideshow[$var_name] =
666          add_url_params(
667            $picture['current']['url'],
668            array('slideshow' =>
669              encode_slideshow_params(
670                array_merge($slideshow_params,
671                  array($p => ! $slideshow_params[$p]))
672                )
673              )
674          );
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(
682        array_merge($slideshow_params,
683                  array('period' => $new_period)));
684
685    if ($new_slideshow_params['period'] === $new_period)
686    {
687      $var_name = 'U_'.strtoupper($op).'_PERIOD';
688      $tpl_slideshow[$var_name] =
689            add_url_params(
690              $picture['current']['url'],
691              array('slideshow' => encode_slideshow_params($new_slideshow_params)
692                  )
693          );
694    }
695  }
696  $template->assign('slideshow', $tpl_slideshow );
697}
698else
699{
700  $template->assign(
701    array(
702      'U_SLIDESHOW_START' =>
703        add_url_params(
704          $picture['current']['url'],
705          array( 'slideshow'=>''))
706      )
707    );
708}
709
710$template->assign(
711  array(
712    'SECTION_TITLE' => $page['title'],
713    'PHOTO' => $title_nb,
714    'SHOW_PICTURE_NAME_ON_TITLE' => $conf['show_picture_name_on_title'],
715    'IS_HOME' => ('categories'==$page['section'] and !isset($page['category']) ),
716
717    'LEVEL_SEPARATOR' => $conf['level_separator'],
718
719    'U_HOME' => make_index_url(),
720    'U_UP' => $url_up,
721    'U_METADATA' => $url_metadata,
722    )
723  );
724
725
726//------------------------------------------------------- upper menu management
727
728// admin links
729if (is_admin())
730{
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  }
741
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
747  $template->assign(
748    array(
749      'U_CADDIE' => add_url_params($url_self,
750                  array('action'=>'add_to_caddie')
751               ),
752      'U_ADMIN' => $url_admin,
753      )
754    );
755
756  $template->assign('available_permission_levels', $conf['available_permission_levels']);
757}
758
759// favorite manipulation
760if (!is_a_guest())
761{
762  // verify if the picture is already in the favorite of the user
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 = pwg_db_fetch_assoc($result);
771
772  if ($row['nb_fav'] == 0)
773  {
774    $template->assign(
775      'favorite',
776      array(
777        'FAVORITE_IMG'  =>
778          get_root_url().get_themeconf('icon_dir').'/favorite.png',
779        'FAVORITE_HINT' => l10n('add this image to your favorites'),
780        'U_FAVORITE'    => add_url_params(
781          $url_self,
782          array('action'=>'add_to_favorites')
783          ),
784        )
785      );
786  }
787  else
788  {
789    $template->assign(
790      'favorite',
791      array(
792        'FAVORITE_IMG'  =>
793          get_root_url().get_themeconf('icon_dir').'/del_favorite.png',
794        'FAVORITE_HINT' => l10n('delete this image from your favorites'),
795        'U_FAVORITE'    => add_url_params(
796          $url_self,
797          array('action'=>'remove_from_favorites')
798          ),
799        )
800      );
801  }
802}
803
804//--------------------------------------------------------- picture information
805// legend
806if (isset($picture['current']['comment'])
807    and !empty($picture['current']['comment']))
808{
809  $template->assign(
810      'COMMENT_IMG',
811        trigger_event('render_element_description',
812          $picture['current']['comment'])
813      );
814}
815
816$infos = array();
817
818// author
819if (!empty($picture['current']['author']))
820{
821  $infos['INFO_AUTHOR'] =
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
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'];
830}
831
832// creation date
833if (!empty($picture['current']['date_creation']))
834{
835  $val = format_date($picture['current']['date_creation']);
836  $url = make_index_url(
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>';
846}
847
848// date of availability
849$val = format_date($picture['current']['date_available']);
850$url = make_index_url(
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)
858      )
859    )
860  );
861$infos['INFO_POSTED_DATE'] = '<a href="'.$url.'" rel="nofollow">'.$val.'</a>';
862
863// size in pixels
864if ($picture['current']['is_picture'] and isset($picture['current']['width']) )
865{
866  if ($picture['current']['scaled_width'] !== $picture['current']['width'] )
867  {
868    $infos['INFO_DIMENSIONS'] =
869      '<a href="'.$picture['current']['image_url'].'" title="'.
870      l10n('Original dimensions').'">'.
871      $picture['current']['width'].'*'.$picture['current']['height'].'</a>';
872  }
873  else
874  {
875    $infos['INFO_DIMENSIONS'] =
876      $picture['current']['width'].'*'.$picture['current']['height'];
877  }
878}
879
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
893$template->assign($infos);
894
895// related tags
896$tags = get_common_tags( array($page['image_id']), -1);
897if ( count($tags) )
898{
899  foreach ($tags as $tag)
900  {
901    $template->append(
902        'related_tags',
903        array_merge( $tag,
904          array(
905            'URL' => make_index_url(
906                      array(
907                        'tags' => array($tag)
908                        )
909                      ),
910            'U_TAG_IMAGE' => duplicate_picture_url(
911                      array(
912                        'section' => 'tags',
913                        'tags' => array($tag)
914                        )
915                    )
916          )
917        )
918      );
919  }
920}
921
922// related categories
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
927  $template->append(
928      'related_categories',
929      get_cat_display_name( $page['category']['upper_names'] )
930    );
931}
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}
955
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  );
963$template->assign( 'ELEMENT_CONTENT', $element_content );
964
965// +-----------------------------------------------------------------------+
966// |                               sub pages                               |
967// +-----------------------------------------------------------------------+
968
969include(PHPWG_ROOT_PATH.'include/picture_rate.inc.php');
970include(PHPWG_ROOT_PATH.'include/picture_comment.inc.php');
971if ($metadata_showable and pwg_get_session_var('show_metadata') <> null )
972{
973  include(PHPWG_ROOT_PATH.'include/picture_metadata.inc.php');
974}
975
976include(PHPWG_ROOT_PATH.'include/page_header.php');
977trigger_action('loc_end_picture');
978if ($page['slideshow'] and $conf['light_slideshow'])
979{
980  $template->pparse('slideshow');
981}
982else
983{
984  $template->pparse('picture');
985}
986//------------------------------------------------------------ log informations
987pwg_log($picture['current']['id'], 'picture');
988include(PHPWG_ROOT_PATH.'include/page_tail.php');
989?>
Note: See TracBrowser for help on using the repository browser.