source: tags/build-Alligator02/include/category_default.inc.php @ 14518

Last change on this file since 14518 was 1769, checked in by vdigital, 17 years ago

Issue 0000614: Display hits under thumbnails like comments counter

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