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

Last change on this file since 1861 was 1861, checked in by rvelices, 17 years ago
  • refactoring pagecategory before 1.7 release

pagecategory is not an id anymore, but an associative array of category info
all of pagecat_xxx or pageuppercats merged into one
simplifies calls to make_index_url
give plugins a clean start for page variables for version 1.7

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.4 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-2007 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | file          : $Id: category_default.inc.php 1861 2007-02-27 01:56:16Z rvelices $
8// | last update   : $Date: 2007-02-27 01:56:16 +0000 (Tue, 27 Feb 2007) $
9// | last modifier : $Author: rvelices $
10// | revision      : $Revision: 1861 $
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
71trigger_action('loc_begin_index_thumbnails', $pictures);
72
73foreach ($pictures as $row)
74{
75  $thumbnail_url = get_thumbnail_url($row);
76
77  // message in title for the thumbnail
78  $thumbnail_title = $row['file'];
79  if (isset($row['filesize']))
80  {
81    $thumbnail_title .= ' : '.$row['filesize'].' KB';
82  }
83
84  // link on picture.php page
85  $url = duplicate_picture_url(
86        array(
87          'image_id' => $row['id'],
88          'image_file' => $row['file']
89        ),
90        array('start')
91      );
92
93  $template->assign_block_vars(
94    'thumbnails.line.thumbnail',
95    array(
96      'IMAGE'              => $thumbnail_url,
97      'IMAGE_ALT'          => $row['file'],
98      'IMAGE_TITLE'        => $thumbnail_title,
99      'IMAGE_TS'           => get_icon($row['date_available']),
100
101      'U_IMG_LINK'         => $url,
102
103      'CLASS'              => 'thumbElmt',
104      )
105    );
106  if ($user['show_nb_hits']
107      and isset($page['category']))
108  {
109    $template->assign_block_vars(
110      'thumbnails.line.thumbnail.nb_hits',
111      array(
112      'HITS'=> l10n_dec('%d hit', '%d hits', $row['hit']),
113      'CLASS'=> set_span_class($row['hit']) . ' nb-hits',
114      )
115    );
116   
117  }
118
119  if ($conf['show_thumbnail_caption'])
120  {
121    // name of the picture
122    if (isset($row['name']) and $row['name'] != '')
123    {
124      $name = $row['name'];
125    }
126    else
127    {
128      $name = str_replace('_', ' ', get_filename_wo_extension($row['file']));
129    }
130
131    switch ($page['section'])
132    {
133      case 'best_rated' :
134      {
135        $name = '('.$row['average_rate'].') '.$name;
136        break;
137      }
138      case 'most_visited' :
139      {
140        $name = '('.$row['hit'].') '.$name;
141        break;
142      }
143      case 'search' :
144      {
145        $name = replace_search($name, $page['search']);
146        break;
147      }
148    }
149
150    $template->assign_block_vars(
151      'thumbnails.line.thumbnail.element_name',
152      array(
153        'NAME' => $name
154        )
155      );
156  }
157
158  if ($user['show_nb_comments']
159      and isset($page['category'])
160      and $page['category']['commentable'])
161  {
162    $query = '
163SELECT COUNT(*) AS nb_comments
164  FROM '.COMMENTS_TABLE.'
165  WHERE image_id = '.$row['id'].'
166    AND validated = \'true\'
167;';
168    $row = mysql_fetch_array(pwg_query($query));
169    $template->assign_block_vars(
170      'thumbnails.line.thumbnail.nb_comments',
171      array(
172        'NB_COMMENTS'=> l10n_dec('%d comment', '%d comments', 
173                        $row['nb_comments']),
174        'CLASS'=> set_span_class($row['nb_comments']) . ' nb-comments',
175      )
176    );
177  }
178
179  //plugins need to add/modify sth in this loop ?
180  trigger_action('loc_index_thumbnail', $row, 'thumbnails.line.thumbnail' );
181
182  // create a new line ?
183  if (++$row_number == $user['nb_image_line'])
184  {
185    $template->assign_block_vars('thumbnails.line', array());
186    $row_number = 0;
187  }
188}
189
190trigger_action('loc_end_index_thumbnails', $pictures);
191$template->assign_var_from_handle('THUMBNAILS', 'thumbnails');
192
193pwg_debug('end include/category_default.inc.php');
194?>
Note: See TracBrowser for help on using the repository browser.