source: trunk/picture.php @ 15224

Revision 13865, 26.9 KB checked in by rvelices, 8 years ago (diff)
  • comment edit form looks ok now with the new comment layout
  • removed unused css / simplify it
  • simplified jquery drop boxes ...
  • Property svn:eol-style set to LF
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2012 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
157  if (isset($_COOKIE['picture_deriv']))
158  {
159    if ( array_key_exists($_COOKIE['picture_deriv'], ImageStdParams::get_defined_type_map()) )
160    {
161      pwg_set_session_var('picture_deriv', $_COOKIE['picture_deriv']);
162    }
163    setcookie('picture_deriv', false, 0, cookie_path() );
164  }
165  $deriv_type = pwg_get_session_var('picture_deriv', IMG_LARGE);
166  $selected_derivative = $element_info['derivatives'][$deriv_type];
167
168  $unique_derivatives = array();
169  $show_original = isset($element_info['element_url']);
170  $added = array();
171  foreach($element_info['derivatives'] as $type => $derivative)
172  {
173    if ($type==IMG_SQUARE || $type==IMG_THUMB)
174      continue;
175    if (!array_key_exists($type, ImageStdParams::get_defined_type_map()))
176      continue;
177    $url = $derivative->get_url();
178    if (isset($added[$url]))
179      continue;
180    $added[$url] = 1;
181    $show_original &= !($derivative->same_as_source());
182    $unique_derivatives[$type]= $derivative;
183  }
184
185  global $page, $template;
186
187  if ($show_original)
188  {
189    $template->assign( 'U_ORIGINAL', $element_info['element_url'] );
190  }
191
192  $template->append('current', array(
193      'selected_derivative' => $selected_derivative,
194      'unique_derivatives' => $unique_derivatives,
195    ), true);
196
197
198  $template->set_filenames(
199    array('default_content'=>'picture_content.tpl')
200    );
201
202  $template->assign( array(
203      'ALT_IMG' => $element_info['file'],
204      'COOKIE_PATH' => cookie_path(),
205      )
206    );
207  return $template->parse( 'default_content', true);
208}
209
210// +-----------------------------------------------------------------------+
211// |                            initialization                             |
212// +-----------------------------------------------------------------------+
213
214// caching first_rank, last_rank, current_rank in the displayed
215// section. This should also help in readability.
216$page['first_rank']   = 0;
217$page['last_rank']    = count($page['items']) - 1;
218$page['current_rank'] = $page['rank_of'][ $page['image_id'] ];
219
220// caching current item : readability purpose
221$page['current_item'] = $page['image_id'];
222
223if ($page['current_rank'] != $page['first_rank'])
224{
225  // caching first & previous item : readability purpose
226  $page['previous_item'] = $page['items'][ $page['current_rank'] - 1 ];
227  $page['first_item'] = $page['items'][ $page['first_rank'] ];
228}
229
230if ($page['current_rank'] != $page['last_rank'])
231{
232  // caching next & last item : readability purpose
233  $page['next_item'] = $page['items'][ $page['current_rank'] + 1 ];
234  $page['last_item'] = $page['items'][ $page['last_rank'] ];
235}
236
237$url_up = duplicate_index_url(
238  array(
239    'start' =>
240      floor($page['current_rank'] / $page['nb_image_page'])
241      * $page['nb_image_page']
242    ),
243  array(
244    'start',
245    )
246  );
247
248$url_self = duplicate_picture_url();
249
250// +-----------------------------------------------------------------------+
251// |                                actions                                |
252// +-----------------------------------------------------------------------+
253
254/**
255 * Actions are favorite adding, user comment deletion, setting the picture
256 * as representative of the current category...
257 *
258 * Actions finish by a redirection
259 */
260
261if (isset($_GET['action']))
262{
263  switch ($_GET['action'])
264  {
265    case 'add_to_favorites' :
266    {
267      $query = '
268INSERT INTO '.FAVORITES_TABLE.'
269  (image_id,user_id)
270  VALUES
271  ('.$page['image_id'].','.$user['id'].')
272;';
273      pwg_query($query);
274
275      redirect($url_self);
276
277      break;
278    }
279    case 'remove_from_favorites' :
280    {
281      $query = '
282DELETE FROM '.FAVORITES_TABLE.'
283  WHERE user_id = '.$user['id'].'
284    AND image_id = '.$page['image_id'].'
285;';
286      pwg_query($query);
287
288      if ('favorites' == $page['section'])
289      {
290        redirect($url_up);
291      }
292      else
293      {
294        redirect($url_self);
295      }
296
297      break;
298    }
299    case 'set_as_representative' :
300    {
301      if (is_admin() and isset($page['category']))
302      {
303        $query = '
304UPDATE '.CATEGORIES_TABLE.'
305  SET representative_picture_id = '.$page['image_id'].'
306  WHERE id = '.$page['category']['id'].'
307;';
308        pwg_query($query);
309
310        $query = '
311UPDATE '.USER_CACHE_CATEGORIES_TABLE.'
312  SET user_representative_picture_id = NULL
313  WHERE user_id = '.$user['id'].'
314    AND cat_id = '.$page['category']['id'].'
315;';
316        pwg_query($query);
317      }
318
319      redirect($url_self);
320
321      break;
322    }
323    case 'add_to_caddie' :
324    {
325      fill_caddie(array($page['image_id']));
326      redirect($url_self);
327      break;
328    }
329    case 'rate' :
330    {
331      include_once(PHPWG_ROOT_PATH.'include/functions_rate.inc.php');
332      rate_picture($page['image_id'], $_POST['rate']);
333      redirect($url_self);
334    }
335    case 'edit_comment':
336    {
337      include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
338      check_input_parameter('comment_to_edit', $_GET, false, PATTERN_ID);
339      $author_id = get_comment_author_id($_GET['comment_to_edit']);
340
341      if (can_manage_comment('edit', $author_id))
342      {
343        if (!empty($_POST['content']))
344        {
345          check_pwg_token();
346          $comment_action = update_user_comment(
347            array(
348              'comment_id' => $_GET['comment_to_edit'],
349              'image_id' => $page['image_id'],
350              'content' => $_POST['content']
351              ),
352            $_POST['key']
353            );
354
355          $perform_redirect = false;
356          switch ($comment_action)
357          {
358            case 'moderate':
359              $_SESSION['page_infos'][] = l10n('An administrator must authorize your comment before it is visible.');
360            case 'validate':
361              $_SESSION['page_infos'][] = l10n('Your comment has been registered');
362              $perform_redirect = true;
363              break;
364            case 'reject':
365              $_SESSION['page_errors'][] = l10n('Your comment has NOT been registered because it did not pass the validation rules');
366              $perform_redirect = true;
367              break;
368            default:
369              trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING);
370          }
371
372          if ($perform_redirect)
373          {
374            redirect($url_self);
375          }
376          unset($_POST['content']);
377        }
378        else
379        {
380          $edit_comment = $_GET['comment_to_edit'];
381        }
382      }
383      break;
384    }
385    case 'delete_comment' :
386    {
387      check_pwg_token();
388
389      include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
390
391      check_input_parameter('comment_to_delete', $_GET, false, PATTERN_ID);
392
393      $author_id = get_comment_author_id($_GET['comment_to_delete']);
394
395      if (can_manage_comment('delete', $author_id))
396      {
397        delete_user_comment($_GET['comment_to_delete']);
398      }
399
400      redirect($url_self);
401    }
402    case 'validate_comment' :
403    {
404      check_pwg_token();
405
406      include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
407
408      check_input_parameter('comment_to_validate', $_GET, false, PATTERN_ID);
409
410      $author_id = get_comment_author_id($_GET['comment_to_validate']);
411
412      if (can_manage_comment('validate', $author_id))
413      {
414        validate_user_comment($_GET['comment_to_validate']);
415      }
416
417      redirect($url_self);
418    }
419
420  }
421}
422
423//---------- incrementation of the number of hits, we do this only if no action
424if (trigger_event('allow_increment_element_hit_count', !isset($_POST['content']) ) )
425{
426  $query = '
427UPDATE
428  '.IMAGES_TABLE.'
429  SET hit = hit+1
430  WHERE id = '.$page['image_id'].'
431;';
432  pwg_query($query);
433}
434//---------------------------------------------------------- related categories
435$query = '
436SELECT category_id,uppercats,commentable,global_rank
437  FROM '.IMAGE_CATEGORY_TABLE.'
438    INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id
439  WHERE image_id = '.$page['image_id'].'
440'.get_sql_condition_FandF
441  (
442    array
443      (
444        'forbidden_categories' => 'category_id',
445        'visible_categories' => 'category_id'
446      ),
447    'AND'
448  ).'
449;';
450$result = pwg_query($query);
451$related_categories = array();
452while ($row = pwg_db_fetch_assoc($result))
453{
454  $row['commentable'] = get_boolean($row['commentable']);
455  array_push($related_categories, $row);
456}
457usort($related_categories, 'global_rank_compare');
458//-------------------------first, prev, current, next & last picture management
459$picture = array();
460
461$ids = array($page['image_id']);
462if (isset($page['previous_item']))
463{
464  array_push($ids, $page['previous_item']);
465  array_push($ids, $page['first_item']);
466}
467if (isset($page['next_item']))
468{
469  array_push($ids, $page['next_item']);
470  array_push($ids, $page['last_item']);
471}
472
473$query = '
474SELECT *
475  FROM '.IMAGES_TABLE.'
476  WHERE id IN ('.implode(',', $ids).')
477;';
478
479$result = pwg_query($query);
480
481while ($row = pwg_db_fetch_assoc($result))
482{
483  if (isset($page['previous_item']) and $row['id'] == $page['previous_item'])
484  {
485    $i = 'previous';
486  }
487  elseif (isset($page['next_item']) and $row['id'] == $page['next_item'])
488  {
489    $i = 'next';
490  }
491  elseif (isset($page['first_item']) and $row['id'] == $page['first_item'])
492  {
493    $i = 'first';
494  }
495  elseif (isset($page['last_item']) and $row['id'] == $page['last_item'])
496  {
497    $i = 'last';
498  }
499  else
500  {
501    $i = 'current';
502  }
503
504  $row['src_image'] = new SrcImage($row);
505  $row['derivatives'] = DerivativeImage::get_all($row['src_image']);
506
507  if ($i=='current')
508  {
509    $row['element_path'] = get_element_path($row);
510
511    if ( $row['src_image']->is_original() )
512    {// we have a photo
513      if ( $user['enabled_high']=='true' )
514      {
515        $row['element_url'] = $row['src_image']->get_url();
516        $row['download_url'] = get_action_url($row['id'], 'e', true);
517      }
518    }
519    else
520    { // not a pic - need download link
521      $row['download_url'] = $row['element_url'] = get_element_url($row);;
522    }
523  }
524
525  $row['url'] = duplicate_picture_url(
526    array(
527      'image_id' => $row['id'],
528      'image_file' => $row['file'],
529      ),
530    array(
531      'start',
532      )
533    );
534
535  $picture[$i] = $row;
536  $picture[$i]['TITLE'] = render_element_name($row);
537
538  if ('previous'==$i and $page['previous_item']==$page['first_item'])
539  {
540    $picture['first'] = $picture[$i];
541  }
542  if ('next'==$i and $page['next_item']==$page['last_item'])
543  {
544    $picture['last'] = $picture[$i];
545  }
546}
547
548$slideshow_params = array();
549$slideshow_url_params = array();
550
551if (isset($_GET['slideshow']))
552{
553  $page['slideshow'] = true;
554  $page['meta_robots'] = array('noindex'=>1, 'nofollow'=>1);
555
556  $slideshow_params = decode_slideshow_params($_GET['slideshow']);
557  $slideshow_url_params['slideshow'] = encode_slideshow_params($slideshow_params);
558
559  if ($slideshow_params['play'])
560  {
561    $id_pict_redirect = '';
562    if (isset($page['next_item']))
563    {
564      $id_pict_redirect = 'next';
565    }
566    else
567    {
568      if ($slideshow_params['repeat'] and isset($page['first_item']))
569      {
570        $id_pict_redirect = 'first';
571      }
572    }
573
574    if (!empty($id_pict_redirect))
575    {
576      // $refresh, $url_link and $title are required for creating
577      // an automated refresh page in header.tpl
578      $refresh = $slideshow_params['period'];
579      $url_link = add_url_params(
580          $picture[$id_pict_redirect]['url'],
581          $slideshow_url_params
582        );
583    }
584  }
585}
586else
587{
588  $page['slideshow'] = false;
589}
590if ($page['slideshow'] and $conf['light_slideshow'])
591{
592  $template->set_filenames( array('slideshow' => 'slideshow.tpl'));
593}
594else
595{
596  $template->set_filenames( array('picture' => 'picture.tpl'));
597}
598
599$title =  $picture['current']['TITLE'];
600$title_nb = ($page['current_rank'] + 1).'/'.count($page['items']);
601
602// metadata
603$url_metadata = duplicate_picture_url();
604$url_metadata = add_url_params( $url_metadata, array('metadata'=>null) );
605
606
607// do we have a plugin that can show metadata for something else than images?
608$metadata_showable = trigger_event(
609  'get_element_metadata_available',
610  (
611    ($conf['show_exif'] or $conf['show_iptc'])
612    and !$picture['current']['src_image']->is_mimetype()
613    ),
614  $picture['current']
615  );
616
617if ( $metadata_showable and pwg_get_session_var('show_metadata') )
618{
619  $page['meta_robots']=array('noindex'=>1, 'nofollow'=>1);
620}
621
622
623$page['body_id'] = 'thePicturePage';
624
625// allow plugins to change what we computed before passing data to template
626$picture = trigger_event('picture_pictures_data', $picture);
627
628//------------------------------------------------------- navigation management
629foreach (array('first','previous','next','last', 'current') as $which_image)
630{
631  if (isset($picture[$which_image]))
632  {
633    $template->assign(
634      $which_image,
635      array_merge(
636        $picture[$which_image],
637        array(
638          'THUMB_SRC' => $picture[$which_image]['derivatives'][IMG_THUMB]->get_url(),
639          // Params slideshow was transmit to navigation buttons
640          'U_IMG' =>
641            add_url_params(
642              $picture[$which_image]['url'], $slideshow_url_params),
643          )
644        )
645      );
646  }
647}
648if ($conf['picture_download_icon'] and !empty($picture['current']['download_url']))
649{
650  $template->append('current', array('U_DOWNLOAD' => $picture['current']['download_url']), true);
651}
652
653
654if ($page['slideshow'])
655{
656  $tpl_slideshow = array();
657
658  //slideshow end
659  $template->assign(
660    array(
661      'U_SLIDESHOW_STOP' => $picture['current']['url'],
662      )
663    );
664
665  foreach (array('repeat', 'play') as $p)
666  {
667    $var_name =
668      'U_'
669      .($slideshow_params[$p] ? 'STOP_' : 'START_')
670      .strtoupper($p);
671
672    $tpl_slideshow[$var_name] =
673          add_url_params(
674            $picture['current']['url'],
675            array('slideshow' =>
676              encode_slideshow_params(
677                array_merge($slideshow_params,
678                  array($p => ! $slideshow_params[$p]))
679                )
680              )
681          );
682  }
683
684  foreach (array('dec', 'inc') as $op)
685  {
686    $new_period = $slideshow_params['period'] + ((($op == 'dec') ? -1 : 1) * $conf['slideshow_period_step']);
687    $new_slideshow_params =
688      correct_slideshow_params(
689        array_merge($slideshow_params,
690                  array('period' => $new_period)));
691
692    if ($new_slideshow_params['period'] === $new_period)
693    {
694      $var_name = 'U_'.strtoupper($op).'_PERIOD';
695      $tpl_slideshow[$var_name] =
696            add_url_params(
697              $picture['current']['url'],
698              array('slideshow' => encode_slideshow_params($new_slideshow_params)
699                  )
700          );
701    }
702  }
703  $template->assign('slideshow', $tpl_slideshow );
704}
705elseif ($conf['picture_slideshow_icon'])
706{
707  $template->assign(
708    array(
709      'U_SLIDESHOW_START' =>
710        add_url_params(
711          $picture['current']['url'],
712          array( 'slideshow'=>''))
713      )
714    );
715}
716
717$template->assign(
718  array(
719    'SECTION_TITLE' => $page['title'],
720    'PHOTO' => $title_nb,
721    'IS_HOME' => ('categories'==$page['section'] and !isset($page['category']) ),
722
723    'LEVEL_SEPARATOR' => $conf['level_separator'],
724
725    'U_UP' => $url_up,
726    'DISPLAY_NAV_BUTTONS' => $conf['picture_navigation_icons'],
727    'DISPLAY_NAV_THUMB' => $conf['picture_navigation_thumb']
728    )
729  );
730
731if ($conf['picture_metadata_icon'])
732{
733  $template->assign('U_METADATA', $url_metadata);
734}
735
736
737//------------------------------------------------------- upper menu management
738
739// admin links
740if (is_admin())
741{
742  if (isset($page['category']))
743  {
744    $template->assign(
745      array(
746        'U_SET_AS_REPRESENTATIVE' => add_url_params($url_self,
747                    array('action'=>'set_as_representative')
748                 )
749        )
750      );
751  }
752
753  $url_admin =
754    get_root_url().'admin.php?page=photo-'.$page['image_id']
755    .(isset($page['category']) ? '&amp;cat_id='.$page['category']['id'] : '')
756    ;
757
758  $template->assign(
759    array(
760      'U_CADDIE' => add_url_params($url_self,
761                  array('action'=>'add_to_caddie')
762               ),
763      'U_ADMIN' => $url_admin,
764      )
765    );
766
767  $template->assign('available_permission_levels', get_privacy_level_options());
768}
769
770// favorite manipulation
771if (!is_a_guest() and $conf['picture_favorite_icon'])
772{
773  // verify if the picture is already in the favorite of the user
774  $query = '
775SELECT COUNT(*) AS nb_fav
776  FROM '.FAVORITES_TABLE.'
777  WHERE image_id = '.$page['image_id'].'
778    AND user_id = '.$user['id'].'
779;';
780  $row = pwg_db_fetch_assoc( pwg_query($query) );
781        $is_favorite = $row['nb_fav'] != 0;
782
783  $template->assign(
784    'favorite',
785    array(
786                        'IS_FAVORITE' => $is_favorite,
787      'U_FAVORITE'    => add_url_params(
788        $url_self,
789        array('action'=> !$is_favorite ? 'add_to_favorites' : 'remove_from_favorites' )
790        ),
791      )
792    );
793}
794
795//--------------------------------------------------------- picture information
796// legend
797if (isset($picture['current']['comment'])
798    and !empty($picture['current']['comment']))
799{
800  $template->assign(
801      'COMMENT_IMG',
802        trigger_event('render_element_description',
803          $picture['current']['comment'])
804      );
805}
806
807// author
808if (!empty($picture['current']['author']))
809{
810  $infos['INFO_AUTHOR'] = $picture['current']['author'];
811}
812
813// creation date
814if (!empty($picture['current']['date_creation']))
815{
816  $val = format_date($picture['current']['date_creation']);
817  $url = make_index_url(
818    array(
819      'chronology_field'=>'created',
820      'chronology_style'=>'monthly',
821      'chronology_view'=>'list',
822      'chronology_date' => explode('-', substr($picture['current']['date_creation'], 0, 10))
823      )
824    );
825  $infos['INFO_CREATION_DATE'] =
826    '<a href="'.$url.'" rel="nofollow">'.$val.'</a>';
827}
828
829// date of availability
830$val = format_date($picture['current']['date_available']);
831$url = make_index_url(
832  array(
833    'chronology_field'=>'posted',
834    'chronology_style'=>'monthly',
835    'chronology_view'=>'list',
836    'chronology_date' => explode(
837      '-',
838      substr($picture['current']['date_available'], 0, 10)
839      )
840    )
841  );
842$infos['INFO_POSTED_DATE'] = '<a href="'.$url.'" rel="nofollow">'.$val.'</a>';
843
844// size in pixels
845if ($picture['current']['src_image']->is_original() and isset($picture['current']['width']) )
846{
847  $infos['INFO_DIMENSIONS'] =
848    $picture['current']['width'].'*'.$picture['current']['height'];
849}
850
851// filesize
852if (!empty($picture['current']['filesize']))
853{
854  $infos['INFO_FILESIZE'] =
855    sprintf(l10n('%d Kb'), $picture['current']['filesize']);
856}
857
858// number of visits
859$infos['INFO_VISITS'] = $picture['current']['hit'];
860
861// file
862$infos['INFO_FILE'] = $picture['current']['file'];
863
864$template->assign($infos);
865$template->assign('display_info', unserialize($conf['picture_informations']));
866
867// related tags
868$tags = get_common_tags( array($page['image_id']), -1);
869if ( count($tags) )
870{
871  foreach ($tags as $tag)
872  {
873    $template->append(
874        'related_tags',
875        array_merge( $tag,
876          array(
877            'URL' => make_index_url(
878                      array(
879                        'tags' => array($tag)
880                        )
881                      ),
882            'U_TAG_IMAGE' => duplicate_picture_url(
883                      array(
884                        'section' => 'tags',
885                        'tags' => array($tag)
886                        )
887                    )
888          )
889        )
890      );
891  }
892}
893
894// related categories
895if ( count($related_categories)==1 and
896    isset($page['category']) and
897    $related_categories[0]['category_id']==$page['category']['id'] )
898{ // no need to go to db, we have all the info
899  $template->append(
900      'related_categories',
901      get_cat_display_name( $page['category']['upper_names'] )
902    );
903}
904else
905{ // use only 1 sql query to get names for all related categories
906  $ids = array();
907  foreach ($related_categories as $category)
908  {// add all uppercats to $ids
909    $ids = array_merge($ids, explode(',', $category['uppercats']) );
910  }
911  $ids = array_unique($ids);
912  $query = '
913SELECT id, name, permalink
914  FROM '.CATEGORIES_TABLE.'
915  WHERE id IN ('.implode(',',$ids).')';
916  $cat_map = hash_from_query($query, 'id');
917  foreach ($related_categories as $category)
918  {
919    $cats = array();
920    foreach ( explode(',', $category['uppercats']) as $id )
921    {
922      $cats[] = $cat_map[$id];
923    }
924    $template->append('related_categories', get_cat_display_name($cats) );
925  }
926}
927
928// maybe someone wants a special display (call it before page_header so that
929// they can add stylesheets)
930$element_content = trigger_event(
931  'render_element_content',
932  '',
933  $picture['current']
934  );
935$template->assign( 'ELEMENT_CONTENT', $element_content );
936
937if (isset($picture['next'])
938    and $picture['next']['src_image']->is_original()
939    and strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome/') === false)
940{
941  $template->assign('U_PREFETCH', $picture['next']['derivatives'][pwg_get_session_var('picture_deriv', IMG_LARGE)]->get_url() );
942}
943
944$template->assign('U_CANONICAL', make_picture_url( array('image_id'=>$picture['current']['id'], 'image_file'=>$picture['current']['file']) ) );
945
946// +-----------------------------------------------------------------------+
947// |                               sub pages                               |
948// +-----------------------------------------------------------------------+
949
950include(PHPWG_ROOT_PATH.'include/picture_rate.inc.php');
951if ($conf['activate_comments'])
952{
953  include(PHPWG_ROOT_PATH.'include/picture_comment.inc.php');
954}
955if ($metadata_showable and pwg_get_session_var('show_metadata') <> null )
956{
957  include(PHPWG_ROOT_PATH.'include/picture_metadata.inc.php');
958}
959
960// include menubar
961$themeconf = $template->get_template_vars('themeconf');
962if ($conf['picture_menu'] AND (!isset($themeconf['hide_menu_on']) OR !in_array('thePicturePage', $themeconf['hide_menu_on'])))
963{
964  if (!isset($page['start'])) $page['start'] = 0;
965  include( PHPWG_ROOT_PATH.'include/menubar.inc.php');
966  if (is_admin()) $template->assign('U_ADMIN', $url_admin); // overwrited by the menu
967}
968
969include(PHPWG_ROOT_PATH.'include/page_header.php');
970trigger_action('loc_end_picture');
971if ($page['slideshow'] and $conf['light_slideshow'])
972{
973  $template->pparse('slideshow');
974}
975else
976{
977  $template->pparse('picture');
978}
979//------------------------------------------------------------ log informations
980pwg_log($picture['current']['id'], 'picture');
981include(PHPWG_ROOT_PATH.'include/page_tail.php');
982?>
Note: See TracBrowser for help on using the repository browser.