source: trunk/picture.php @ 12764

Last change on this file since 12764 was 12764, checked in by mistic100, 12 years ago

feature:2538 Make a unified messages management
use only $pageinfos and $pageerrors vars and and necessary template to all main pages

  • Property svn:eol-style set to LF
File size: 28.7 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2011 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'] / $page['nb_image_page'])
219      * $page['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 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        $query = '
289UPDATE '.USER_CACHE_CATEGORIES_TABLE.'
290  SET user_representative_picture_id = NULL
291  WHERE user_id = '.$user['id'].'
292    AND cat_id = '.$page['category']['id'].'
293;';
294        pwg_query($query);
295      }
296
297      redirect($url_self);
298
299      break;
300    }
301    case 'toggle_metadata' :
302    {
303      break;
304    }
305    case 'add_to_caddie' :
306    {
307      fill_caddie(array($page['image_id']));
308      redirect($url_self);
309      break;
310    }
311    case 'rate' :
312    {
313      include_once(PHPWG_ROOT_PATH.'include/functions_rate.inc.php');
314      rate_picture($page['image_id'], $_POST['rate']);
315      redirect($url_self);
316    }
317    case 'edit_comment' :
318    {
319      check_pwg_token();
320      include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
321      check_input_parameter('comment_to_edit', $_GET, false, PATTERN_ID);
322      $author_id = get_comment_author_id($_GET['comment_to_edit']);
323      if (can_manage_comment('edit', $author_id))
324      {
325        if (!empty($_POST['content']))
326        {
327          $comment_action = update_user_comment(
328            array(
329              'comment_id' => $_GET['comment_to_edit'],
330              'image_id' => $page['image_id'],
331              'content' => $_POST['content']
332              ),
333            $_POST['key']
334            );
335
336          switch ($comment_action)
337          {
338            case 'moderate':
339              array_push($page['infos'], l10n('An administrator must authorize your comment before it is visible.'));
340            case 'validate':
341              array_push($page['infos'], l10n('Your comment has been registered'));
342              break;
343            case 'reject':
344              set_status_header(403);
345              array_push($page['errors'], l10n('Your comment has NOT been registered because it did not pass the validation rules'));
346              break;
347            default:
348              trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING);
349          }
350           
351          unset($_POST['content']);
352          break;
353        }
354        else
355        {
356          $edit_comment = $_GET['comment_to_edit'];
357          break;
358        }
359      }
360    }
361    case 'delete_comment' :
362    {
363      check_pwg_token();
364
365      include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
366
367      check_input_parameter('comment_to_delete', $_GET, false, PATTERN_ID);
368
369      $author_id = get_comment_author_id($_GET['comment_to_delete']);
370
371      if (can_manage_comment('delete', $author_id))
372      {
373        delete_user_comment($_GET['comment_to_delete']);
374      }
375
376      redirect($url_self);
377    }
378    case 'validate_comment' :
379    {
380      check_pwg_token();
381
382      include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
383
384      check_input_parameter('comment_to_validate', $_GET, false, PATTERN_ID);
385
386      $author_id = get_comment_author_id($_GET['comment_to_validate']);
387
388      if (can_manage_comment('validate', $author_id))
389      {
390        validate_user_comment($_GET['comment_to_validate']);
391      }
392
393      redirect($url_self);
394    }
395
396  }
397}
398
399// incrementation of the number of hits, we do this only if no action
400if (trigger_event('allow_increment_element_hit_count', !isset($_POST['content']) ) )
401{
402  $query = '
403UPDATE
404  '.IMAGES_TABLE.'
405  SET hit = hit+1
406  WHERE id = '.$page['image_id'].'
407;';
408  pwg_query($query);
409}
410//---------------------------------------------------------- related categories
411$query = '
412SELECT category_id,uppercats,commentable,global_rank
413  FROM '.IMAGE_CATEGORY_TABLE.'
414    INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id
415  WHERE image_id = '.$page['image_id'].'
416'.get_sql_condition_FandF
417  (
418    array
419      (
420        'forbidden_categories' => 'category_id',
421        'visible_categories' => 'category_id'
422      ),
423    'AND'
424  ).'
425;';
426$result = pwg_query($query);
427$related_categories = array();
428while ($row = pwg_db_fetch_assoc($result))
429{
430  $row['commentable'] = get_boolean($row['commentable']);
431  array_push($related_categories, $row);
432}
433usort($related_categories, 'global_rank_compare');
434//-------------------------first, prev, current, next & last picture management
435$picture = array();
436
437$ids = array($page['image_id']);
438if (isset($page['previous_item']))
439{
440  array_push($ids, $page['previous_item']);
441  array_push($ids, $page['first_item']);
442}
443if (isset($page['next_item']))
444{
445  array_push($ids, $page['next_item']);
446  array_push($ids, $page['last_item']);
447}
448
449$query = '
450SELECT *
451  FROM '.IMAGES_TABLE.'
452  WHERE id IN ('.implode(',', $ids).')
453;';
454
455$result = pwg_query($query);
456
457while ($row = pwg_db_fetch_assoc($result))
458{
459  if (isset($page['previous_item']) and $row['id'] == $page['previous_item'])
460  {
461    $i = 'previous';
462  }
463  else if (isset($page['next_item']) and $row['id'] == $page['next_item'])
464  {
465    $i = 'next';
466  }
467  else if (isset($page['first_item']) and $row['id'] == $page['first_item'])
468  {
469    $i = 'first';
470  }
471  else if (isset($page['last_item']) and $row['id'] == $page['last_item'])
472  {
473    $i = 'last';
474  }
475  else
476  {
477    $i = 'current';
478  }
479
480  $picture[$i] = $row;
481
482  $picture[$i]['is_picture'] = false;
483  if (in_array(get_extension($row['file']), $conf['picture_ext']))
484  {
485    $picture[$i]['is_picture'] = true;
486  }
487
488  // ------ build element_path and element_url
489  $picture[$i]['element_path'] = get_element_path($picture[$i]);
490  $picture[$i]['element_url'] = get_element_url($picture[$i]);
491
492  // ------ build image_path and image_url
493  if ($i=='current' or $i=='next')
494  {
495    $picture[$i]['image_path'] = get_image_path( $picture[$i] );
496    $picture[$i]['image_url'] = get_image_url( $picture[$i] );
497  }
498
499  if ($i=='current')
500  {
501    if ( $picture[$i]['is_picture'] )
502    {
503      if ( $user['enabled_high']=='true' )
504      {
505        $hi_url=get_high_url($picture[$i]);
506        if ( !empty($hi_url) )
507        {
508          $picture[$i]['high_url'] = $hi_url;
509          $picture[$i]['download_url'] = get_download_url('h',$picture[$i]);
510        }
511      }
512    }
513    else
514    { // not a pic - need download link
515      $picture[$i]['download_url'] = get_download_url('e',$picture[$i]);
516    }
517  }
518
519  $picture[$i]['thumbnail'] = get_thumbnail_url($row);
520
521  if ( !empty( $row['name'] ) )
522  {
523    $picture[$i]['name'] = $row['name'];
524  }
525  else
526  {
527    $file_wo_ext = get_filename_wo_extension($row['file']);
528    $picture[$i]['name'] = str_replace('_', ' ', $file_wo_ext);
529  }
530
531  $picture[$i]['name'] = trigger_event('render_element_description', $picture[$i]['name']);
532
533  $picture[$i]['url'] = duplicate_picture_url(
534    array(
535      'image_id' => $row['id'],
536      'image_file' => $row['file'],
537      ),
538    array(
539      'start',
540      )
541    );
542
543  if ('previous'==$i and $page['previous_item']==$page['first_item'])
544  {
545    $picture['first'] = $picture[$i];
546  }
547  if ('next'==$i and $page['next_item']==$page['last_item'])
548  {
549    $picture['last'] = $picture[$i];
550  }
551}
552
553// calculation of width and height for the current picture
554if (empty($picture['current']['width']))
555{
556  $taille_image = @getimagesize($picture['current']['image_path']);
557  if ($taille_image!==false)
558  {
559    $picture['current']['width'] = $taille_image[0];
560    $picture['current']['height']= $taille_image[1];
561  }
562}
563
564if (!empty($picture['current']['width']))
565{
566  list(
567    $picture['current']['scaled_width'],
568    $picture['current']['scaled_height']
569    ) = get_picture_size(
570      $picture['current']['width'],
571      $picture['current']['height'],
572      @$user['maxwidth'],
573      @$user['maxheight']
574    );
575}
576
577$slideshow_params = array();
578$slideshow_url_params = array();
579
580if (isset($_GET['slideshow']))
581{
582  $page['slideshow'] = true;
583  $page['meta_robots'] = array('noindex'=>1, 'nofollow'=>1);
584
585  $slideshow_params = decode_slideshow_params($_GET['slideshow']);
586  $slideshow_url_params['slideshow'] = encode_slideshow_params($slideshow_params);
587
588  if ($slideshow_params['play'])
589  {
590    $id_pict_redirect = '';
591    if (isset($page['next_item']))
592    {
593      $id_pict_redirect = 'next';
594    }
595    else
596    {
597      if ($slideshow_params['repeat'] and isset($page['first_item']))
598      {
599        $id_pict_redirect = 'first';
600      }
601    }
602
603    if (!empty($id_pict_redirect))
604    {
605      // $refresh, $url_link and $title are required for creating
606      // an automated refresh page in header.tpl
607      $refresh = $slideshow_params['period'];
608      $url_link = add_url_params(
609          $picture[$id_pict_redirect]['url'],
610          $slideshow_url_params
611        );
612    }
613  }
614}
615else
616{
617  $page['slideshow'] = false;
618}
619if ($page['slideshow'] and $conf['light_slideshow'])
620{
621  $template->set_filenames( array('slideshow' => 'slideshow.tpl'));
622}
623else
624{
625  $template->set_filenames( array('picture' => 'picture.tpl'));
626}
627
628$title =  $picture['current']['name'];
629$title_nb = ($page['current_rank'] + 1).'/'.count($page['items']);
630
631// metadata
632$url_metadata = duplicate_picture_url();
633$url_metadata = add_url_params( $url_metadata, array('metadata'=>null) );
634
635
636// do we have a plugin that can show metadata for something else than images?
637$metadata_showable = trigger_event(
638  'get_element_metadata_available',
639  (
640    ($conf['show_exif'] or $conf['show_iptc'])
641    and isset($picture['current']['image_path'])
642    ),
643  $picture['current']['path']
644  );
645
646if ( $metadata_showable and pwg_get_session_var('show_metadata') )
647{
648  $page['meta_robots']=array('noindex'=>1, 'nofollow'=>1);
649}
650
651
652$page['body_id'] = 'thePicturePage';
653
654// allow plugins to change what we computed before passing data to template
655$picture = trigger_event('picture_pictures_data', $picture);
656
657
658if (isset($picture['next']['image_url'])
659    and $picture['next']['is_picture']
660    and strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome/') === false)
661{
662  $template->assign('U_PREFETCH', $picture['next']['image_url'] );
663}
664
665//------------------------------------------------------- navigation management
666foreach (array('first','previous','next','last', 'current') as $which_image)
667{
668  if (isset($picture[$which_image]))
669  {
670    $template->assign(
671      $which_image,
672      array_merge(
673        $picture[$which_image],
674        array(
675          'TITLE' => $picture[$which_image]['name'],
676          'THUMB_SRC' => $picture[$which_image]['thumbnail'],
677          // Params slideshow was transmit to navigation buttons
678          'U_IMG' =>
679            add_url_params(
680              $picture[$which_image]['url'], $slideshow_url_params),
681          )
682        )
683      );
684    if ($conf['picture_download_icon'] and !empty($picture['current']['download_url']))
685    {
686      $template->append($which_image, array('U_DOWNLOAD' => $picture['current']['download_url']), true);
687    }
688  }
689}
690
691
692if ($page['slideshow'])
693{
694  $tpl_slideshow = array();
695
696  //slideshow end
697  $template->assign(
698    array(
699      'U_SLIDESHOW_STOP' => $picture['current']['url'],
700      )
701    );
702
703  foreach (array('repeat', 'play') as $p)
704  {
705    $var_name =
706      'U_'
707      .($slideshow_params[$p] ? 'STOP_' : 'START_')
708      .strtoupper($p);
709
710    $tpl_slideshow[$var_name] =
711          add_url_params(
712            $picture['current']['url'],
713            array('slideshow' =>
714              encode_slideshow_params(
715                array_merge($slideshow_params,
716                  array($p => ! $slideshow_params[$p]))
717                )
718              )
719          );
720  }
721
722  foreach (array('dec', 'inc') as $op)
723  {
724    $new_period = $slideshow_params['period'] + ((($op == 'dec') ? -1 : 1) * $conf['slideshow_period_step']);
725    $new_slideshow_params =
726      correct_slideshow_params(
727        array_merge($slideshow_params,
728                  array('period' => $new_period)));
729
730    if ($new_slideshow_params['period'] === $new_period)
731    {
732      $var_name = 'U_'.strtoupper($op).'_PERIOD';
733      $tpl_slideshow[$var_name] =
734            add_url_params(
735              $picture['current']['url'],
736              array('slideshow' => encode_slideshow_params($new_slideshow_params)
737                  )
738          );
739    }
740  }
741  $template->assign('slideshow', $tpl_slideshow );
742}
743elseif ($conf['picture_slideshow_icon'])
744{
745  $template->assign(
746    array(
747      'U_SLIDESHOW_START' =>
748        add_url_params(
749          $picture['current']['url'],
750          array( 'slideshow'=>''))
751      )
752    );
753}
754
755$template->assign(
756  array(
757    'SECTION_TITLE' => $page['title'],
758    'PHOTO' => $title_nb,
759    'SHOW_PICTURE_NAME_ON_TITLE' => $conf['show_picture_name_on_title'],
760    'IS_HOME' => ('categories'==$page['section'] and !isset($page['category']) ),
761
762    'LEVEL_SEPARATOR' => $conf['level_separator'],
763
764    'U_UP' => $url_up,
765    'DISPLAY_NAV_BUTTONS' => $conf['picture_navigation_icons'],
766    'DISPLAY_NAV_THUMB' => $conf['picture_navigation_thumb']
767    )
768  );
769
770if ($conf['picture_metadata_icon'])
771{
772  $template->assign('U_METADATA', $url_metadata);
773}
774
775
776//------------------------------------------------------- upper menu management
777
778// admin links
779if (is_admin())
780{
781  if (isset($page['category']))
782  {
783    $template->assign(
784      array(
785        'U_SET_AS_REPRESENTATIVE' => add_url_params($url_self,
786                    array('action'=>'set_as_representative')
787                 )
788        )
789      );
790  }
791
792  $url_admin =
793    get_root_url().'admin.php?page=picture_modify'
794    .'&amp;cat_id='.(isset($page['category']) ? $page['category']['id'] : '')
795    .'&amp;image_id='.$page['image_id'];
796
797  $template->assign(
798    array(
799      'U_CADDIE' => add_url_params($url_self,
800                  array('action'=>'add_to_caddie')
801               ),
802      'U_ADMIN' => $url_admin,
803      )
804    );
805
806  $template->assign('available_permission_levels', get_privacy_level_options());
807}
808
809// favorite manipulation
810if (!is_a_guest() and $conf['picture_favorite_icon'])
811{
812  // verify if the picture is already in the favorite of the user
813  $query = '
814SELECT COUNT(*) AS nb_fav
815  FROM '.FAVORITES_TABLE.'
816  WHERE image_id = '.$page['image_id'].'
817    AND user_id = '.$user['id'].'
818;';
819  $row = pwg_db_fetch_assoc( pwg_query($query) );
820        $is_favorite = $row['nb_fav'] != 0;
821
822  $template->assign(
823    'favorite',
824    array(
825                        'IS_FAVORITE' => $is_favorite,
826      'U_FAVORITE'    => add_url_params(
827        $url_self,
828        array('action'=> !$is_favorite ? 'add_to_favorites' : 'remove_from_favorites' )
829        ),
830      )
831    );
832}
833
834//--------------------------------------------------------- picture information
835// legend
836if (isset($picture['current']['comment'])
837    and !empty($picture['current']['comment']))
838{
839  $template->assign(
840      'COMMENT_IMG',
841        trigger_event('render_element_description',
842          $picture['current']['comment'])
843      );
844}
845
846// author
847if (!empty($picture['current']['author']))
848{
849  $infos['INFO_AUTHOR'] =
850// FIXME because of search engine partial rewrite, giving the author
851// name threw GET is not supported anymore. This feature should come
852// back later, with a better design
853//     '<a href="'.
854//       PHPWG_ROOT_PATH.'category.php?cat=search'.
855//       '&amp;search=author:'.$picture['current']['author']
856//       .'">'.$picture['current']['author'].'</a>';
857    $picture['current']['author'];
858}
859
860// creation date
861if (!empty($picture['current']['date_creation']))
862{
863  $val = format_date($picture['current']['date_creation']);
864  $url = make_index_url(
865    array(
866      'chronology_field'=>'created',
867      'chronology_style'=>'monthly',
868      'chronology_view'=>'list',
869      'chronology_date' => explode('-', substr($picture['current']['date_creation'], 0, 10))
870      )
871    );
872  $infos['INFO_CREATION_DATE'] =
873    '<a href="'.$url.'" rel="nofollow">'.$val.'</a>';
874}
875
876// date of availability
877$val = format_date($picture['current']['date_available']);
878$url = make_index_url(
879  array(
880    'chronology_field'=>'posted',
881    'chronology_style'=>'monthly',
882    'chronology_view'=>'list',
883    'chronology_date' => explode(
884      '-',
885      substr($picture['current']['date_available'], 0, 10)
886      )
887    )
888  );
889$infos['INFO_POSTED_DATE'] = '<a href="'.$url.'" rel="nofollow">'.$val.'</a>';
890
891// size in pixels
892if ($picture['current']['is_picture'] AND $picture['current']['has_high'])
893{
894  if (!empty($picture['current']['high_width']))
895  {
896    $infos['INFO_DIMENSIONS'] = $picture['current']['high_width'].'*'.$picture['current']['high_height'];
897  }
898  else if ($hi_size = @getimagesize($hi_url))
899  {
900    pwg_query('
901      UPDATE ' . IMAGES_TABLE . '
902      SET
903        high_width = \'' . $hi_size[0].'\',
904        high_height = \''.$hi_size[1] .'\'
905      WHERE id = ' . $picture['current']['id'] . ';
906    ');
907   
908    $infos['INFO_DIMENSIONS'] = $hi_size[0].'*'.$hi_size[1];
909  }
910}
911else if ($picture['current']['is_picture'] and isset($picture['current']['width']) )
912{
913  if ($picture['current']['scaled_width'] !== $picture['current']['width'] )
914  {
915    $infos['INFO_DIMENSIONS'] =
916      '<a href="'.$picture['current']['image_url'].'" title="'.
917      l10n('Original dimensions').'">'.
918      $picture['current']['width'].'*'.$picture['current']['height'].'</a>';
919  }
920  else
921  {
922    $infos['INFO_DIMENSIONS'] =
923      $picture['current']['width'].'*'.$picture['current']['height'];
924  }
925}
926
927// filesize
928if ($picture['current']['has_high'] and !empty($picture['current']['high_filesize']))
929{
930  $infos['INFO_FILESIZE'] =
931    sprintf(l10n('%d Kb'), $picture['current']['high_filesize']);
932}
933else if (!empty($picture['current']['filesize']))
934{
935  $infos['INFO_FILESIZE'] =
936    sprintf(l10n('%d Kb'), $picture['current']['filesize']);
937}
938
939// number of visits
940$infos['INFO_VISITS'] = $picture['current']['hit'];
941
942// file
943$infos['INFO_FILE'] = $picture['current']['file'];
944
945$template->assign($infos);
946$template->assign('display_info', unserialize($conf['picture_informations']));
947
948// related tags
949$tags = get_common_tags( array($page['image_id']), -1);
950if ( count($tags) )
951{
952  foreach ($tags as $tag)
953  {
954    $template->append(
955        'related_tags',
956        array_merge( $tag,
957          array(
958            'URL' => make_index_url(
959                      array(
960                        'tags' => array($tag)
961                        )
962                      ),
963            'U_TAG_IMAGE' => duplicate_picture_url(
964                      array(
965                        'section' => 'tags',
966                        'tags' => array($tag)
967                        )
968                    )
969          )
970        )
971      );
972  }
973}
974
975// related categories
976if ( count($related_categories)==1 and
977    isset($page['category']) and
978    $related_categories[0]['category_id']==$page['category']['id'] )
979{ // no need to go to db, we have all the info
980  $template->append(
981      'related_categories',
982      get_cat_display_name( $page['category']['upper_names'] )
983    );
984}
985else
986{ // use only 1 sql query to get names for all related categories
987  $ids = array();
988  foreach ($related_categories as $category)
989  {// add all uppercats to $ids
990    $ids = array_merge($ids, explode(',', $category['uppercats']) );
991  }
992  $ids = array_unique($ids);
993  $query = '
994SELECT id, name, permalink
995  FROM '.CATEGORIES_TABLE.'
996  WHERE id IN ('.implode(',',$ids).')';
997  $cat_map = hash_from_query($query, 'id');
998  foreach ($related_categories as $category)
999  {
1000    $cats = array();
1001    foreach ( explode(',', $category['uppercats']) as $id )
1002    {
1003      $cats[] = $cat_map[$id];
1004    }
1005    $template->append('related_categories', get_cat_display_name($cats) );
1006  }
1007}
1008
1009// maybe someone wants a special display (call it before page_header so that
1010// they can add stylesheets)
1011$element_content = trigger_event(
1012  'render_element_content',
1013  '',
1014  $picture['current']
1015  );
1016$template->assign( 'ELEMENT_CONTENT', $element_content );
1017
1018// +-----------------------------------------------------------------------+
1019// |                               sub pages                               |
1020// +-----------------------------------------------------------------------+
1021
1022include(PHPWG_ROOT_PATH.'include/picture_rate.inc.php');
1023include(PHPWG_ROOT_PATH.'include/picture_comment.inc.php');
1024if ($metadata_showable and pwg_get_session_var('show_metadata') <> null )
1025{
1026  include(PHPWG_ROOT_PATH.'include/picture_metadata.inc.php');
1027}
1028
1029// include menubar
1030$themeconf = $template->get_template_vars('themeconf');
1031if ($conf['picture_menu'] AND (!isset($themeconf['hide_menu_on']) OR !in_array('thePicturePage', $themeconf['hide_menu_on'])))
1032{
1033  if (!isset($page['start'])) $page['start'] = 0;
1034  include( PHPWG_ROOT_PATH.'include/menubar.inc.php');
1035  if (is_admin()) $template->assign('U_ADMIN', $url_admin); // overwrited by the menu
1036}
1037
1038include(PHPWG_ROOT_PATH.'include/page_header.php');
1039trigger_action('loc_end_picture');
1040if ($page['slideshow'] and $conf['light_slideshow'])
1041{
1042  $template->pparse('slideshow');
1043}
1044else
1045{
1046  $template->pparse('picture');
1047}
1048//------------------------------------------------------------ log informations
1049pwg_log($picture['current']['id'], 'picture');
1050include(PHPWG_ROOT_PATH.'include/page_tail.php');
1051?>
Note: See TracBrowser for help on using the repository browser.