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

Last change on this file since 1876 was 1876, checked in by rub, 17 years ago

0000662: Recent elements don't use sometimes time and not truncated datetime
&
Standardize system date used

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.1 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// | file          : $Id: category_cats.inc.php 1876 2007-03-07 18:51:58Z rub $
8// | last update   : $Date: 2007-03-07 18:51:58 +0000 (Wed, 07 Mar 2007) $
9// | last modifier : $Author: rub $
10// | revision      : $Revision: 1876 $
11// +-----------------------------------------------------------------------+
12// | This program is free software; you can redistribute it and/or modify  |
13// | it under the terms of the GNU General Public License as published by  |
14// | the Free Software Foundation                                          |
15// |                                                                       |
16// | This program is distributed in the hope that it will be useful, but   |
17// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
18// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
19// | General Public License for more details.                              |
20// |                                                                       |
21// | You should have received a copy of the GNU General Public License     |
22// | along with this program; if not, write to the Free Software           |
23// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
24// | USA.                                                                  |
25// +-----------------------------------------------------------------------+
26
27/**
28 * This file is included by the main page to show thumbnails for a category
29 * that have only subcategories or to show recent categories
30 *
31 */
32
33if ($page['section']=='recent_cats')
34{
35  // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE
36  $query = '
37SELECT
38  id, name, permalink, representative_picture_id, comment, nb_images, uppercats,
39  date_last, max_date_last, count_images, count_categories, global_rank
40  FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
41  ON id = cat_id and user_id = '.$user['id'].'
42  WHERE date_last >= SUBDATE(
43    CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY
44  )
45'.get_sql_condition_FandF
46  (
47    array
48      (
49        'visible_categories' => 'id',
50      ),
51    'AND'
52  ).'
53;';
54}
55else
56{
57  // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE
58  $query = '
59SELECT
60  id, name, permalink, representative_picture_id, comment, nb_images,
61  date_last, max_date_last, count_images, count_categories
62  FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
63  ON id = cat_id and user_id = '.$user['id'].'
64  WHERE id_uppercat '.
65  (!isset($page['category']) ? 'is NULL' : '= '.$page['category']['id']).'
66'.get_sql_condition_FandF
67  (
68    array
69      (
70        'visible_categories' => 'id',
71      ),
72    'AND'
73  ).'
74  ORDER BY rank
75;';
76}
77
78$result = pwg_query($query);
79$categories = array();
80$image_ids = array();
81
82while ($row = mysql_fetch_assoc($result))
83{
84  $row['is_child_date_last'] = @$row['max_date_last']>@$row['date_last'];
85
86  if (isset($row['representative_picture_id'])
87      and is_numeric($row['representative_picture_id']))
88  { // if a representative picture is set, it has priority
89    $image_id = $row['representative_picture_id'];
90  }
91  else if ($conf['allow_random_representative'])
92  {// searching a random representant among elements in sub-categories
93    $query = '
94SELECT image_id
95  FROM '.CATEGORIES_TABLE.' AS c INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic
96    ON ic.category_id = c.id';
97    $query.= '
98  WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\'
99'.get_sql_condition_FandF
100  (
101    array
102      (
103        'forbidden_categories' => 'c.id',
104        'visible_categories' => 'c.id',
105        'visible_images' => 'image_id'
106      ),
107    'AND'
108  ).'
109  ORDER BY RAND()
110  LIMIT 0,1
111;';
112    $subresult = pwg_query($query);
113    if (mysql_num_rows($subresult) > 0)
114    {
115      list($image_id) = mysql_fetch_row($subresult);
116    }
117  }
118  else
119  { // searching a random representant among representant of sub-categories
120    $query = '
121SELECT representative_picture_id
122  FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
123  ON id = cat_id and user_id = '.$user['id'].'
124  WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\'
125    AND representative_picture_id IS NOT NULL
126'.get_sql_condition_FandF
127  (
128    array
129      (
130        'visible_categories' => 'id',
131      ),
132    'AND'
133  ).'
134  ORDER BY RAND()
135  LIMIT 0,1
136;';
137    $subresult = pwg_query($query);
138    if (mysql_num_rows($subresult) > 0)
139    {
140      list($image_id) = mysql_fetch_row($subresult);
141    }
142  }
143
144  if (isset($image_id))
145  {
146    $row['representative_picture_id'] = $image_id;
147    array_push($image_ids, $image_id);
148    array_push($categories, $row);
149  }
150  unset($image_id);
151}
152
153if ($page['section']=='recent_cats')
154{
155  usort($categories, 'global_rank_compare');
156}
157if (count($categories) > 0)
158{
159  $thumbnail_src_of = array();
160
161  $query = '
162SELECT id, path, tn_ext
163  FROM '.IMAGES_TABLE.'
164  WHERE id IN ('.implode(',', $image_ids).')
165;';
166  $result = pwg_query($query);
167  while ($row = mysql_fetch_assoc($result))
168  {
169    $thumbnail_src_of[$row['id']] = get_thumbnail_url($row);
170  }
171}
172
173if (count($categories) > 0)
174{
175  // Update filtered data
176  if (function_exists('update_cats_with_filtered_data'))
177  {
178    update_cats_with_filtered_data($categories);
179  }
180  trigger_action('loc_begin_index_categories');
181  if ($conf['subcatify'])
182  {
183    $template->set_filename('mainpage_categories', 'mainpage_categories.tpl');
184
185    foreach ($categories as $category)
186    {
187      $comment = strip_tags(@$category['comment'], '<a><br><p><b><i><small><strong><font>');
188      if ($page['section']=='recent_cats')
189      {
190        $name = get_cat_display_name_cache($category['uppercats'], null, false);
191      }
192      else
193      {
194        $name = $category['name'];
195      }
196
197      $icon_ts = get_icon($category['max_date_last'], $category['is_child_date_last']);
198
199      $template->assign_block_vars(
200        'categories.category',
201        array(
202          'SRC'   => $thumbnail_src_of[$category['representative_picture_id']],
203          'ALT'   => $category['name'],
204          'TITLE' => $lang['hint_category'],
205          'ICON'  => $icon_ts,
206
207          'URL'   => make_index_url(
208            array(
209              'category' => $category
210              )
211            ),
212          'CAPTION_NB_IMAGES' => get_display_images_count
213                                  (
214                                    $category['nb_images'],
215                                    $category['count_images'],
216                                    $category['count_categories'],
217                                    true,
218                                    '<br />'
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' => get_display_images_count
250                                  (
251                                    $category['nb_images'],
252                                    $category['count_images'],
253                                    $category['count_categories'],
254                                    true,
255                                    '<BR>'
256                                  ),
257
258          'U_IMG_LINK'  => make_index_url(
259            array(
260              'category' => $category
261              )
262            ),
263          'CLASS'       => 'thumbCat',
264          )
265        );
266      if ($page['section']=='recent_cats')
267      {
268        $name = get_cat_display_name_cache($category['uppercats'], null, false);
269      }
270      else
271      {
272        $name = $category['name'];
273        $template->merge_block_vars(
274          'thumbnails.line.thumbnail',
275          array(
276            'IMAGE_TS'    => get_icon($category['max_date_last'], $category['is_child_date_last']),
277           )
278         );
279      }
280      $template->assign_block_vars(
281        'thumbnails.line.thumbnail.category_name',
282        array(
283          'NAME' => $name
284          )
285        );
286
287      // create a new line ?
288      if (++$row_number == $user['nb_image_line'])
289      {
290        $template->assign_block_vars('thumbnails.line', array());
291        $row_number = 0;
292      }
293    }
294
295    if ( isset($old_level_separator) )
296    {
297      $conf['level_separator']=$old_level_separator;
298    }
299
300    $template->assign_var_from_handle('CATEGORIES', 'thumbnails');
301    unset( $template->_tpldata['thumbnails.'] );//maybe write a func for that
302  }
303}
304?>
Note: See TracBrowser for help on using the repository browser.