source: branches/1.6/include/category_subcats.inc.php @ 27558

Last change on this file since 27558 was 1406, checked in by rvelices, 18 years ago

bug 436: Category thumbnail display not ok if subcatify is false

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.6 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-27 00:37:18 +0000 (Tue, 27 Jun 2006) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1406 $
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 a category
30 * that have only subcategories
31 *
32 */
33
34$query = '
35SELECT id, name, date_last, representative_picture_id, comment, nb_images
36  FROM '.CATEGORIES_TABLE.'
37  WHERE id_uppercat '.
38  (!isset($page['category']) ? 'is NULL' : '= '.$page['category']).'
39    AND id NOT IN ('.$user['forbidden_categories'].')
40  ORDER BY rank
41;';
42$result = pwg_query($query);
43
44// $conf['allow_random_representative']
45
46$categories = array();
47$image_ids = array();
48
49while ($row = mysql_fetch_array($result))
50{
51  if (isset($row['representative_picture_id'])
52      and is_numeric($row['representative_picture_id']))
53  {
54    // if a representative picture is set, it has priority
55    $image_id = $row['representative_picture_id'];
56  }
57  else if ($conf['allow_random_representative'])
58  {
59    // searching a random representant among elements in sub-categories
60    $query = '
61SELECT image_id
62  FROM '.CATEGORIES_TABLE.' AS c INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic
63    ON ic.category_id = c.id
64  WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\'
65    AND c.id NOT IN ('.$user['forbidden_categories'].')
66  ORDER BY RAND()
67  LIMIT 0,1
68;';
69    $subresult = pwg_query($query);
70    if (mysql_num_rows($result) > 0)
71    {
72      list($image_id) = mysql_fetch_row($subresult);
73    }
74  }
75  else
76  {
77    // searching a random representant among representant of sub-categories
78    $query = '
79SELECT representative_picture_id
80  FROM '.CATEGORIES_TABLE.'
81  WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\'
82    AND id NOT IN ('.$user['forbidden_categories'].')
83    AND representative_picture_id IS NOT NULL
84  ORDER BY RAND()
85  LIMIT 0,1
86;';
87    $subresult = pwg_query($query);
88    if (mysql_num_rows($subresult) > 0)
89    {
90      list($image_id) = mysql_fetch_row($subresult);
91    }
92  }
93
94  $comment = null;
95  if (isset($row['comment']))
96  {
97    $comment = strip_tags($row['comment'], '<a><br><p><b><i><small><strong><font>');
98  }
99
100  if (isset($image_id))
101  {
102    array_push(
103      $categories,
104      array(
105        'category'    => $row['id'],
106        'picture'     => $image_id,
107        'name'        => $row['name'],
108        'date_last'   => @$row['date_last'],
109        'comment'     => $comment,
110        'nb_images'   => $row['nb_images'],
111        )
112      );
113
114    array_push($image_ids, $image_id);
115  }
116
117  unset($image_id);
118}
119
120if (count($image_ids) > 0)
121{
122  $thumbnail_src_of = array();
123
124  $query = '
125SELECT id, path, tn_ext
126  FROM '.IMAGES_TABLE.'
127  WHERE id IN ('.implode(',', $image_ids).')
128;';
129  $result = pwg_query($query);
130  while ($row = mysql_fetch_array($result))
131  {
132    $thumbnail_src_of[$row['id']] =
133      get_thumbnail_src($row['path'], @$row['tn_ext']);
134  }
135
136  if ($conf['subcatify'])
137  {
138    $template->set_filenames(
139      array(
140        'mainpage_categories' => 'mainpage_categories.tpl',
141        )
142      );
143
144    $template->assign_block_vars('categories', array());
145
146    foreach ($categories as $category)
147    {
148      $template->assign_block_vars(
149        'categories.category',
150        array(
151          'SRC'   => $thumbnail_src_of[ $category['picture'] ],
152          'ALT'   => $category['name'],
153          'TITLE' => $lang['hint_category'],
154          'ICON'  => get_icon(@$category['date_last']),
155
156          'URL' => make_index_url(
157            array(
158              'category' => $category['category'],
159              'cat_name' => $category['name'],
160              )
161            ),
162          'NAME' => $category['name'],
163          'CAPTION_NB_IMAGES' => (($category['nb_images'] == 0) ? '' : sprintf("%d ".l10n('pictures'), $category['nb_images'])),
164          'DESCRIPTION' => @$category['comment'],
165          )
166        );
167    }
168
169    $template->assign_var_from_handle('CATEGORIES', 'mainpage_categories');
170  }
171  else
172  {
173    $template->set_filenames( array( 'thumbnails' => 'thumbnails.tpl',));
174    $template->assign_block_vars('thumbnails', array());
175    // first line
176    $template->assign_block_vars('thumbnails.line', array());
177    // current row displayed
178    $row_number = 0;
179
180    foreach ($categories as $category)
181    {
182      $template->assign_block_vars(
183        'thumbnails.line.thumbnail',
184        array(
185          'IMAGE'       => $thumbnail_src_of[ $category['picture'] ],
186          'IMAGE_ALT'   => $category['name'],
187          'IMAGE_TITLE' => $lang['hint_category'],
188          'IMAGE_TS'    => get_icon(@$category['date_last']),
189
190          'U_IMG_LINK'  => make_index_url(
191            array(
192              'category' => $category['category'],
193              'cat_name' => $category['name'],
194              )
195            ),
196          'CLASS'       => 'thumbCat',
197          )
198        );
199
200      $template->assign_block_vars(
201        'thumbnails.line.thumbnail.category_name',
202        array(
203          'NAME' => $category['name']
204          )
205        );
206
207      // create a new line ?
208      if (++$row_number == $user['nb_image_line'])
209      {
210        $template->assign_block_vars('thumbnails.line', array());
211        $row_number = 0;
212      }
213    }
214    $template->assign_var_from_handle('THUMBNAILS', 'thumbnails');
215  }
216}
217?>
Note: See TracBrowser for help on using the repository browser.