source: branches/gettext/picture.php @ 30831

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