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

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

if category is best_rated : displays the average rate of the element before
its name

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 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-31 21:32:58 +0000 (Tue, 31 Aug 2004) $
10// | last modifier : $Author: z0rglub $
11// | revision      : $Revision: 508 $
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,average_rate
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  if ($page['cat'] == 'best_rated')
83  {
84    $name = '('.$row['average_rate'].') '.$name;
85  }
86
87  if ($page['cat'] == 'search')
88  {
89    $name = replace_search($name, $_GET['search']);
90  }
91  // thumbnail url
92  if (isset($row['tn_ext']) and $row['tn_ext'] != '')
93  {
94    $thumbnail_url = $cat_directory;
95    $thumbnail_url.= 'thumbnail/'.$conf['prefix_thumbnail'];
96    $thumbnail_url.= $file.'.'.$row['tn_ext'];
97  }
98  else
99  {
100    $thumbnail_url = './template/'.$user['template'].'/mimetypes/';
101    $thumbnail_url.= strtolower(get_extension($row['file'])).'.png';
102  }
103 
104  // message in title for the thumbnail
105  $thumbnail_title = $row['file'];
106  if (!isset($row['filesize']) or $row['filesize'] == '')
107  {
108    $filesize = floor(filesize($cat_directory.$row['file']) / 1024);
109  }
110  else
111  {
112    $filesize = $row['filesize'];
113  }
114  $thumbnail_title .= ' : '.$filesize.' KB';
115  // url link on picture.php page
116  $url_link = PHPWG_ROOT_PATH.'picture.php?cat='.$page['cat'];
117  $url_link.= '&amp;image_id='.$row['id'];
118  if ($page['cat'] == 'search')
119  {
120    $url_link.= '&amp;search='.$_GET['search'];
121  }
122   
123  $template->assign_block_vars(
124    'thumbnails.line.thumbnail',
125    array(
126      'IMAGE'              => $thumbnail_url,
127      'IMAGE_ALT'          => $row['file'],
128      'IMAGE_TITLE'        => $thumbnail_title,
129      'IMAGE_NAME'         => $name,
130      'IMAGE_TS'           => get_icon($row['date_available']),
131      'IMAGE_STYLE'        => 'thumb_picture',
132     
133      'U_IMG_LINK'         => add_session_id($url_link)
134      )
135    );
136   
137  if ($conf['show_comments'] and $user['show_nb_comments'])
138  {
139    $query = '
140SELECT COUNT(*) AS nb_comments
141  FROM '.COMMENTS_TABLE.'
142  WHERE image_id = '.$row['id'].'
143    AND validated = \'true\'
144;';
145    $row = mysql_fetch_array(mysql_query($query));
146    $template->assign_block_vars(
147      'thumbnails.line.thumbnail.nb_comments',
148      array('NB_COMMENTS'=>$row['nb_comments']));
149  }
150
151  // create a new line ?
152  if (++$row_number == $user['nb_image_line'])
153  {
154    $template->assign_block_vars('thumbnails.line', array());
155    $row_number = 0;
156  }
157}
158?>
Note: See TracBrowser for help on using the repository browser.