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

Last change on this file since 485 was 485, checked in by z0rglub, 20 years ago

bug correction : in case of filesize metadata not registered into database,
it couldn't be calculated

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.1 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// |                        category_default.inc.php                       |
4// +-----------------------------------------------------------------------+
5// | application   : PhpWebGallery <http://phpwebgallery.net>              |
6// | branch        : BSF (Best So Far)                                     |
7// +-----------------------------------------------------------------------+
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-08-16 21:44:19 +0000 (Mon, 16 Aug 2004) $
10// | last modifier : $Author: z0rglub $
11// | revision      : $Revision: 485 $
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 category.php to show thumbnails for the default
30 * case
31 *
32 */
33
34/**
35 * $array_cat_directories is a cache hash associating category id with their
36 * complete directory
37 */
38$array_cat_directories = array();
39 
40$query = '
41SELECT DISTINCT(id),file,date_available
42       ,tn_ext,name,filesize,storage_category_id
43  FROM '.IMAGES_TABLE.' AS i
44    INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id=ic.image_id
45  '.$page['where'].'
46  '.$conf['order_by'].'
47  LIMIT '.$page['start'].','.$page['nb_image_page'].'
48;';
49// echo '<pre>'.$query.'</pre>';
50$result = mysql_query($query);
51
52// template thumbnail initialization
53if ( mysql_num_rows($result) > 0 )
54{
55  $template->assign_block_vars('thumbnails', array());
56  // first line
57  $template->assign_block_vars('thumbnails.line', array());
58  // current row displayed
59  $row_number = 0;
60}
61
62while ($row = mysql_fetch_array($result))
63{
64  // retrieving the storage dir of the picture
65  if (!isset($array_cat_directories[$row['storage_category_id']]))
66  {
67    $array_cat_directories[$row['storage_category_id']] =
68      get_complete_dir($row['storage_category_id']);
69  }
70  $cat_directory = $array_cat_directories[$row['storage_category_id']];
71
72  $file = get_filename_wo_extension($row['file']);
73  // name of the picture
74  if (isset($row['name']) and $row['name'] != '')
75  {
76    $name = $row['name'];
77  }
78  else
79  {
80    $name = str_replace('_', ' ', $file);
81  }
82
83  if ($page['cat'] == 'search')
84  {
85    $name = replace_search($name, $_GET['search']);
86  }
87  // thumbnail url
88  if (isset($row['tn_ext']) and $row['tn_ext'] != '')
89  {
90    $thumbnail_url = $cat_directory;
91    $thumbnail_url.= 'thumbnail/'.$conf['prefix_thumbnail'];
92    $thumbnail_url.= $file.'.'.$row['tn_ext'];
93  }
94  else
95  {
96    $thumbnail_url = './template/'.$user['template'].'/mimetypes/';
97    $thumbnail_url.= strtolower(get_extension($row['file'])).'.png';
98  }
99 
100  // message in title for the thumbnail
101  $thumbnail_title = $row['file'];
102  if (!isset($row['filesize']) or $row['filesize'] == '')
103  {
104    $filesize = floor(filesize($cat_directory.$row['file']) / 1024);
105  }
106  else
107  {
108    $filesize = $row['filesize'];
109  }
110  $thumbnail_title .= ' : '.$filesize.' KB';
111  // url link on picture.php page
112  $url_link = PHPWG_ROOT_PATH.'picture.php?cat='.$page['cat'];
113  $url_link.= '&amp;image_id='.$row['id'];
114  if ($page['cat'] == 'search')
115  {
116    $url_link.= '&amp;search='.$_GET['search'];
117  }
118   
119  $template->assign_block_vars(
120    'thumbnails.line.thumbnail',
121    array(
122      'IMAGE'              => $thumbnail_url,
123      'IMAGE_ALT'          => $row['file'],
124      'IMAGE_TITLE'        => $thumbnail_title,
125      'IMAGE_NAME'         => $name,
126      'IMAGE_TS'           => get_icon($row['date_available']),
127      'IMAGE_STYLE'        => 'thumb_picture',
128     
129      'U_IMG_LINK'         => add_session_id($url_link)
130      )
131    );
132   
133  if ($conf['show_comments'] and $user['show_nb_comments'])
134  {
135    $query = '
136SELECT COUNT(*) AS nb_comments
137  FROM '.COMMENTS_TABLE.'
138  WHERE image_id = '.$row['id'].'
139    AND validated = \'true\'
140;';
141    $row = mysql_fetch_array(mysql_query($query));
142    $template->assign_block_vars(
143      'thumbnails.line.thumbnail.nb_comments',
144      array('NB_COMMENTS'=>$row['nb_comments']));
145  }
146
147  // create a new line ?
148  if (++$row_number == $user['nb_image_line'])
149  {
150    $template->assign_block_vars('thumbnails.line', array());
151    $row_number = 0;
152  }
153}
154?>
Note: See TracBrowser for help on using the repository browser.