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

Last change on this file since 2297 was 2297, checked in by plg, 16 years ago

Modification: new header on PHP files, PhpWebGallery renamed Piwigo.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 6.4 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008      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// +-----------------------------------------------------------------------+
24// | PhpWebGallery - a PHP based picture gallery                           |
25// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
26// | Copyright (C) 2003-2008 PhpWebGallery Team - http://phpwebgallery.net |
27// +-----------------------------------------------------------------------+
28// | file          : $Id: category_default.inc.php 2297 2008-04-04 22:57:23Z plg $
29// | last update   : $Date: 2008-04-04 22:57:23 +0000 (Fri, 04 Apr 2008) $
30// | last modifier : $Author: plg $
31// | revision      : $Revision: 2297 $
32// +-----------------------------------------------------------------------+
33// | This program is free software; you can redistribute it and/or modify  |
34// | it under the terms of the GNU General Public License as published by  |
35// | the Free Software Foundation                                          |
36// |                                                                       |
37// | This program is distributed in the hope that it will be useful, but   |
38// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
39// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
40// | General Public License for more details.                              |
41// |                                                                       |
42// | You should have received a copy of the GNU General Public License     |
43// | along with this program; if not, write to the Free Software           |
44// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
45// | USA.                                                                  |
46// +-----------------------------------------------------------------------+
47
48/**
49 * This file is included by the main page to show thumbnails for the default
50 * case
51 *
52 */
53
54$page['rank_of'] = array_flip($page['items']);
55
56$pictures = array();
57
58$selection = array_slice(
59  $page['items'],
60  $page['start'],
61  $page['nb_image_page']
62  );
63
64if (count($selection) > 0)
65{
66  $query = '
67SELECT *
68  FROM '.IMAGES_TABLE.'
69  WHERE id IN ('.implode(',', $selection).')
70;';
71  $result = pwg_query($query);
72  while ($row = mysql_fetch_assoc($result))
73  {
74    $row['rank'] = $page['rank_of'][ $row['id'] ];
75
76    array_push($pictures, $row);
77  }
78
79  usort($pictures, 'rank_compare');
80}
81
82if (count($pictures) > 0)
83{
84  // define category slideshow url
85  $row = reset($pictures);
86  $page['cat_slideshow_url'] =
87    add_url_params(
88      duplicate_picture_url(
89        array(
90          'image_id' => $row['id'],
91          'image_file' => $row['file']
92        ),
93        array('start')
94      ),
95      array('slideshow' =>
96        (isset($_GET['slideshow']) ? $_GET['slideshow']
97                                   : '' ))
98    );
99
100  if ($user['show_nb_comments'])
101  {
102    $query = '
103SELECT image_id, COUNT(*) AS nb_comments
104  FROM '.COMMENTS_TABLE.'
105  WHERE validated = \'true\'
106    AND image_id IN ('.implode(',', $selection).')
107  GROUP BY image_id
108;';
109    $nb_comments_of = simple_hash_from_query($query, 'image_id', 'nb_comments');
110  }
111}
112
113// template thumbnail initialization
114$template->set_filenames( array( 'index_thumbnails' => 'thumbnails.tpl',));
115
116trigger_action('loc_begin_index_thumbnails', $pictures);
117
118foreach ($pictures as $row)
119{
120  $thumbnail_url = get_thumbnail_url($row);
121
122  // link on picture.php page
123  $url = duplicate_picture_url(
124        array(
125          'image_id' => $row['id'],
126          'image_file' => $row['file']
127        ),
128        array('start')
129      );
130
131  $tpl_var =
132    array(
133      'ID'            => $row['id'],
134      'IMAGE'         => $thumbnail_url,
135      'IMAGE_ALT'     => $row['file'],
136      'IMAGE_TITLE'   => get_thumbnail_title($row),
137      'IMAGE_TS'      => get_icon($row['date_available']),
138      'U_IMG_LINK'    => $url,
139    );
140
141  if ($user['show_nb_hits'])
142  {
143    $tpl_var['NB_HITS'] = $row['hit'];
144  }
145
146  if ($conf['show_thumbnail_caption'])
147  {
148    // name of the picture
149    if (isset($row['name']) and $row['name'] != '')
150    {
151      $name = $row['name'];
152    }
153    else
154    {
155      $name = str_replace('_', ' ', get_filename_wo_extension($row['file']));
156    }
157
158    switch ($page['section'])
159    {
160      case 'best_rated' :
161      {
162        $name = '('.$row['average_rate'].') '.$name;
163        break;
164      }
165      case 'most_visited' :
166      {
167        if ( !$user['show_nb_hits']) {
168          $name = '('.$row['hit'].') '.$name;
169        }
170        break;
171      }
172    }
173
174    $tpl_var['ELEMENT_NAME'] = $name;
175  }
176
177  if ( isset($nb_comments_of) )
178  {
179    $row['nb_comments'] = isset($nb_comments_of[$row['id']])
180        ? (int)$nb_comments_of[$row['id']] : 0;
181    $tpl_var['NB_COMMENTS'] = $row['nb_comments'];
182  }
183
184  //plugins need to add/modify sth in this loop ?
185  $tpl_var = trigger_event('loc_index_thumbnail', $tpl_var, $row);
186
187  $template->append('thumbnails', $tpl_var);
188}
189
190trigger_action('loc_end_index_thumbnails', $pictures);
191$template->assign_var_from_handle('THUMBNAILS', 'index_thumbnails');
192
193pwg_debug('end include/category_default.inc.php');
194?>
Note: See TracBrowser for help on using the repository browser.