source: branches/1.6/include/category_default.inc.php @ 27047

Last change on this file since 27047 was 1386, checked in by chrisaga, 18 years ago

feature 434: split thumbnails in template so customization could be easyer (manual merge from trunk r:1384

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 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-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2006-06-24 09:19:40 +0000 (Sat, 24 Jun 2006) $
10// | last modifier : $Author: chrisaga $
11// | revision      : $Revision: 1386 $
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_array($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  $template->assign_block_vars('thumbnails', array());
67  // first line
68  $template->assign_block_vars('thumbnails.line', array());
69  // current row displayed
70  $row_number = 0;
71}
72
73foreach ($pictures as $row)
74{
75  $thumbnail_url = get_thumbnail_src($row['path'], @$row['tn_ext']);
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
107  if ($conf['show_thumbnail_caption'])
108  {
109    // name of the picture
110    if (isset($row['name']) and $row['name'] != '')
111    {
112      $name = $row['name'];
113    }
114    else
115    {
116      $name = str_replace('_', ' ', get_filename_wo_extension($row['file']));
117    }
118
119    switch ($page['section'])
120    {
121      case 'best_rated' :
122      {
123        $name = '('.$row['average_rate'].') '.$name;
124        break;
125      }
126      case 'most_visited' :
127      {
128        $name = '('.$row['hit'].') '.$name;
129        break;
130      }
131      case 'search' :
132      {
133        $name = replace_search($name, $page['search']);
134        break;
135      }
136    }
137
138    $template->assign_block_vars(
139      'thumbnails.line.thumbnail.element_name',
140      array(
141        'NAME' => $name
142        )
143      );
144  }
145
146  if ($user['show_nb_comments']
147      and isset($page['category'])
148      and $page['cat_commentable'])
149  {
150    $query = '
151SELECT COUNT(*) AS nb_comments
152  FROM '.COMMENTS_TABLE.'
153  WHERE image_id = '.$row['id'].'
154    AND validated = \'true\'
155;';
156    $row = mysql_fetch_array(pwg_query($query));
157    $template->assign_block_vars(
158      'thumbnails.line.thumbnail.nb_comments',
159      array('NB_COMMENTS'=>$row['nb_comments']));
160  }
161
162  // create a new line ?
163  if (++$row_number == $user['nb_image_line'])
164  {
165    $template->assign_block_vars('thumbnails.line', array());
166    $row_number = 0;
167  }
168}
169$template->assign_var_from_handle('THUMBNAILS', 'thumbnails');
170
171pwg_debug('end include/category_default.inc.php');
172?>
Note: See TracBrowser for help on using the repository browser.