source: trunk/include/category_default.inc.php @ 18164

Last change on this file since 18164 was 16987, checked in by rvelices, 12 years ago

refactor code when selected derivative on index page is changed by a plugin ...

  • Property svn:eol-style set to LF
File size: 5.0 KB
RevLine 
[440]1<?php
2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[12908]5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
[2297]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// +-----------------------------------------------------------------------+
[440]23
24/**
[1082]25 * This file is included by the main page to show thumbnails for the default
[440]26 * case
[1090]27 *
[440]28 */
29
[1036]30$pictures = array();
31
32$selection = array_slice(
33  $page['items'],
34  $page['start'],
35  $page['nb_image_page']
36  );
37
[13234]38$selection = trigger_event('loc_index_thumbnails_selection', $selection);
39
[1036]40if (count($selection) > 0)
41{
[13115]42  $rank_of = array_flip($selection);
[3126]43
[1036]44  $query = '
45SELECT *
46  FROM '.IMAGES_TABLE.'
[1677]47  WHERE id IN ('.implode(',', $selection).')
48;';
[1036]49  $result = pwg_query($query);
[4325]50  while ($row = pwg_db_fetch_assoc($result))
[1036]51  {
[3128]52    $row['rank'] = $rank_of[ $row['id'] ];
[13115]53    $pictures[] = $row;
[1036]54  }
[440]55
[1036]56  usort($pictures, 'rank_compare');
[3126]57  unset($rank_of);
[1036]58}
59
60if (count($pictures) > 0)
[440]61{
[2218]62  // define category slideshow url
63  $row = reset($pictures);
64  $page['cat_slideshow_url'] =
65    add_url_params(
66      duplicate_picture_url(
67        array(
68          'image_id' => $row['id'],
69          'image_file' => $row['file']
70        ),
71        array('start')
72      ),
73      array('slideshow' =>
74        (isset($_GET['slideshow']) ? $_GET['slideshow']
75                                   : '' ))
76    );
[2234]77
[12887]78  if ($conf['activate_comments'] and $user['show_nb_comments'])
[2274]79  {
80    $query = '
81SELECT image_id, COUNT(*) AS nb_comments
82  FROM '.COMMENTS_TABLE.'
83  WHERE validated = \'true\'
84    AND image_id IN ('.implode(',', $selection).')
85  GROUP BY image_id
86;';
87    $nb_comments_of = simple_hash_from_query($query, 'image_id', 'nb_comments');
88  }
[440]89}
90
[2274]91// template thumbnail initialization
92$template->set_filenames( array( 'index_thumbnails' => 'thumbnails.tpl',));
93
[1596]94trigger_action('loc_begin_index_thumbnails', $pictures);
[3124]95$tpl_thumbnails_var = array();
[1596]96
[1036]97foreach ($pictures as $row)
[440]98{
[1090]99  // link on picture.php page
100  $url = duplicate_picture_url(
101        array(
102          'image_id' => $row['id'],
103          'image_file' => $row['file']
[1094]104        ),
105        array('start')
[1090]106      );
[3491]107
[12908]108  if (isset($nb_comments_of))
[11996]109  {
[12908]110    $row['NB_COMMENTS'] = $row['nb_comments'] = (int)@$nb_comments_of[$row['id']];
[11996]111  }
112
[12920]113  $name = render_element_name($row);
114  $desc = render_element_description($row);
[12451]115
[12908]116  $tpl_var = array_merge( $row, array(
[12546]117    'TN_ALT' => htmlspecialchars(strip_tags($name)),
[12920]118    'TN_TITLE' => get_thumbnail_title($row, $name, $desc),
[12546]119    'URL' => $url,
[12920]120    'DESCRIPTION' => $desc,
[12908]121    'src_image' => new SrcImage($row),
122    ) );
[2841]123
[11285]124  if ($conf['index_new_icon'])
125  {
[11591]126    $tpl_var['icon_ts'] = get_icon($row['date_available']);
[11285]127  }
[2234]128
[1864]129  if ($user['show_nb_hits'])
[1763]130  {
[2274]131    $tpl_var['NB_HITS'] = $row['hit'];
[1763]132  }
[12908]133
[11981]134  switch ($page['section'])
135  {
136    case 'best_rated' :
137    {
138      $name = '('.$row['rating_score'].') '.$name;
139      break;
140    }
141    case 'most_visited' :
142    {
143      if ( !$user['show_nb_hits'])
144      {
145        $name = '('.$row['hit'].') '.$name;
146      }
147      break;
148    }
149  }
150  $tpl_var['NAME'] = $name;
[3124]151  $tpl_thumbnails_var[] = $tpl_var;
[440]152}
[1596]153
[12908]154$template->assign( array(
[16987]155  'derivative_params' => trigger_event('get_index_derivative_params', ImageStdParams::get_by_type( pwg_get_session_var('index_deriv', IMG_THUMB) ) ),
[12908]156  'SHOW_THUMBNAIL_CAPTION' =>$conf['show_thumbnail_caption'],
157    ) );
[3124]158$tpl_thumbnails_var = trigger_event('loc_end_index_thumbnails', $tpl_thumbnails_var, $pictures);
159$template->assign('thumbnails', $tpl_thumbnails_var);
[12391]160
[2274]161$template->assign_var_from_handle('THUMBNAILS', 'index_thumbnails');
[12908]162unset($pictures, $selection, $tpl_thumbnails_var);
[16987]163$template->clear_assign( 'thumbnails' );
[1036]164pwg_debug('end include/category_default.inc.php');
[3120]165?>
Note: See TracBrowser for help on using the repository browser.