source: trunk/picture.php @ 10097

Last change on this file since 10097 was 10097, checked in by mistic100, 13 years ago

bug:2152 Comments revalidation when modified

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