source: trunk/include/category_cats.inc.php @ 1820

Last change on this file since 1820 was 1820, checked in by rvelices, 17 years ago
  • feature 642: display both subcategory thumbnails and element thumbnails (if a

category has both) in the index page

flat category view

  • web service fixes for categories.getList
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.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-2007 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $Id: category_cats.inc.php 1820 2007-02-15 00:10:41Z rvelices $
9// | last update   : $Date: 2007-02-15 00:10:41 +0000 (Thu, 15 Feb 2007) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1820 $
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 or to show recent categories
31 *
32 */
33
34if ($page['section']=='recent_cats')
35{
36  // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE
37  $query = '
38SELECT
39  id,name, representative_picture_id, comment, nb_images, uppercats,
40  date_last, max_date_last, count_images, count_categories, global_rank
41  FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
42  ON id = cat_id and user_id = '.$user['id'].'
43  WHERE date_last > SUBDATE(
44    CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY
45  )
46'.get_sql_condition_FandF
47  (
48    array
49      (
50        'visible_categories' => 'id',
51      ),
52    'AND'
53  ).'
54;';
55}
56else
57{
58  // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE
59  $query = '
60SELECT
61  id,name, representative_picture_id, comment, nb_images,
62  date_last, max_date_last, count_images, count_categories
63  FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
64  ON id = cat_id and user_id = '.$user['id'].'
65  WHERE id_uppercat '.
66  (!isset($page['category']) ? 'is NULL' : '= '.$page['category']).'
67'.get_sql_condition_FandF
68  (
69    array
70      (
71        'visible_categories' => 'id',
72      ),
73    'AND'
74  ).'
75  ORDER BY rank
76;';
77}
78
79$result = pwg_query($query);
80$categories = array();
81$image_ids = array();
82
83while ($row = mysql_fetch_assoc($result))
84{
85  $row['is_child_date_last'] = @$row['max_date_last']>@$row['date_last'];
86
87  if (isset($row['representative_picture_id'])
88      and is_numeric($row['representative_picture_id']))
89  { // if a representative picture is set, it has priority
90    $image_id = $row['representative_picture_id'];
91  }
92  else if ($conf['allow_random_representative'])
93  {// searching a random representant among elements in sub-categories
94    $query = '
95SELECT image_id
96  FROM '.CATEGORIES_TABLE.' AS c INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic
97    ON ic.category_id = c.id';
98    $query.= '
99  WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\'
100'.get_sql_condition_FandF
101  (
102    array
103      (
104        'forbidden_categories' => 'c.id',
105        'visible_categories' => 'c.id',
106        'visible_images' => 'image_id'
107      ),
108    'AND'
109  ).'
110  ORDER BY RAND()
111  LIMIT 0,1
112;';
113    $subresult = pwg_query($query);
114    if (mysql_num_rows($subresult) > 0)
115    {
116      list($image_id) = mysql_fetch_row($subresult);
117    }
118  }
119  else
120  { // searching a random representant among representant of sub-categories
121    $query = '
122SELECT representative_picture_id
123  FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
124  ON id = cat_id and user_id = '.$user['id'].'
125  WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\'
126    AND representative_picture_id IS NOT NULL
127'.get_sql_condition_FandF
128  (
129    array
130      (
131        'visible_categories' => 'id',
132      ),
133    'AND'
134  ).'
135  ORDER BY RAND()
136  LIMIT 0,1
137;';
138    $subresult = pwg_query($query);
139    if (mysql_num_rows($subresult) > 0)
140    {
141      list($image_id) = mysql_fetch_row($subresult);
142    }
143  }
144
145  if (isset($image_id))
146  {
147    $row['representative_picture_id'] = $image_id;
148    array_push($image_ids, $image_id);
149    array_push($categories, $row);
150  }
151  unset($image_id);
152}
153
154if ($page['section']=='recent_cats')
155{
156  usort($categories, 'global_rank_compare');
157}
158if (count($categories) > 0)
159{
160  $thumbnail_src_of = array();
161
162  $query = '
163SELECT id, path, tn_ext
164  FROM '.IMAGES_TABLE.'
165  WHERE id IN ('.implode(',', $image_ids).')
166;';
167  $result = pwg_query($query);
168  while ($row = mysql_fetch_assoc($result))
169  {
170    $thumbnail_src_of[$row['id']] = get_thumbnail_url($row);
171  }
172}
173
174if (count($categories) > 0)
175{
176  // Update filtered data
177  if (function_exists('update_cats_with_filtered_data'))
178  {
179    update_cats_with_filtered_data($categories);
180  }
181
182  if ($conf['subcatify'])
183  {
184    $template->set_filename('mainpage_categories', 'mainpage_categories.tpl');
185
186    foreach ($categories as $category)
187    {
188      $comment = strip_tags(@$category['comment'], '<a><br><p><b><i><small><strong><font>');
189      if ($page['section']=='recent_cats')
190      {
191        $name = get_cat_display_name_cache($category['uppercats'], null, false);
192      }
193      else
194      {
195        $name = $category['name'];
196      }
197
198      $icon_ts = get_icon($category['max_date_last'], $category['is_child_date_last']);
199
200      $template->assign_block_vars(
201        'categories.category',
202        array(
203          'SRC'   => $thumbnail_src_of[$category['representative_picture_id']],
204          'ALT'   => $category['name'],
205          'TITLE' => $lang['hint_category'],
206          'ICON'  => $icon_ts,
207
208          'URL'   => make_index_url(
209            array(
210              'category' => $category['id'],
211              'cat_name' => $category['name'],
212              )
213            ),
214          'CAPTION_NB_IMAGES' => get_display_images_count
215                                  (
216                                    $category['nb_images'],
217                                    $category['count_images'],
218                                    $category['count_categories']
219                                  ),
220          'DESCRIPTION' => @$comment,
221          'NAME'  => $name,
222          )
223        );
224    }
225
226    $template->assign_var_from_handle('CATEGORIES', 'mainpage_categories');
227  }
228  else
229  {
230    $template->set_filename( 'thumbnails', 'thumbnails.tpl');
231    // first line
232    $template->assign_block_vars('thumbnails.line', array());
233    // current row displayed
234    $row_number = 0;
235
236    if ($page['section']=='recent_cats')
237    {
238      $old_level_separator = $conf['level_separator'];
239      $conf['level_separator'] = '<br />';
240    }
241
242    foreach ($categories as $category)
243    {
244      $template->assign_block_vars(
245        'thumbnails.line.thumbnail',
246        array(
247          'IMAGE'       => $thumbnail_src_of[ $category['representative_picture_id'] ],
248          'IMAGE_ALT'   => $category['name'],
249          'IMAGE_TITLE' => $lang['hint_category'],
250
251          'U_IMG_LINK'  => make_index_url(
252            array(
253              'category' => $category['id'],
254              'cat_name' => $category['name'],
255              )
256            ),
257          'CLASS'       => 'thumbCat',
258          )
259        );
260      if ($page['section']=='recent_cats')
261      {
262        $name = get_cat_display_name_cache($category['uppercats'], null, false);
263      }
264      else
265      {
266        $name = $category['name'];
267        $template->merge_block_vars(
268          'thumbnails.line.thumbnail',
269          array(
270            'IMAGE_TS'    => get_icon($category['max_date_last'], $category['is_child_date_last']),
271           )
272         );
273      }
274      $template->assign_block_vars(
275        'thumbnails.line.thumbnail.category_name',
276        array(
277          'NAME' => $name
278          )
279        );
280
281      // create a new line ?
282      if (++$row_number == $user['nb_image_line'])
283      {
284        $template->assign_block_vars('thumbnails.line', array());
285        $row_number = 0;
286      }
287    }
288
289    if ( isset($old_level_separator) )
290    {
291      $conf['level_separator']=$old_level_separator;
292    }
293
294    $template->assign_var_from_handle('CATEGORIES', 'thumbnails');
295    unset( $template->_tpldata['thumbnails.'] );//maybe write a func for that
296  }
297}
298?>
Note: See TracBrowser for help on using the repository browser.