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

Last change on this file since 2218 was 2218, checked in by rub, 16 years ago

Resolved issue 0000807: New slideshow features

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