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

Last change on this file since 1690 was 1677, checked in by rub, 18 years ago

Feature Issue ID 0000601: Filter all public pages with only recent elements

It's a finalized version.
Obsolete code of draft are removed.

You can filter categories and images with recent date period on your screen selection.
In the future, filter could be easy done on other type data (plugin?)

You can flat categories and sub-categories with a recent date period of your choice.

Next, perhaps, a panel to choice recent date for the 2 features.

On draft, there have problem with MySql 5, be careful!

Css problem not resolved:

  • Menu "Categories" is bad centered
  • Icon on dark too on the top
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.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-2006 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $Id: category_cats.inc.php 1677 2006-12-21 21:38:20Z rub $
9// | last update   : $Date: 2006-12-21 21:38:20 +0000 (Thu, 21 Dec 2006) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1677 $
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
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 (count($categories) > 0)
155{
156  $thumbnail_src_of = array();
157
158  $query = '
159SELECT id, path, tn_ext
160  FROM '.IMAGES_TABLE.'
161  WHERE id IN ('.implode(',', $image_ids).')
162;';
163  $result = pwg_query($query);
164  while ($row = mysql_fetch_assoc($result))
165  {
166    $thumbnail_src_of[$row['id']] = get_thumbnail_url($row);
167  }
168}
169
170if (count($categories) > 0)
171{
172  // Update filtered data
173  update_cats_with_filtered_data($categories);
174
175  if ($conf['subcatify'])
176  {
177    $template->set_filenames(
178      array(
179        'mainpage_categories' => 'mainpage_categories.tpl',
180        )
181      );
182
183    foreach ($categories as $category)
184    {
185      $comment = strip_tags(@$category['comment'], '<a><br><p><b><i><small><strong><font>');
186      if ($page['section']=='recent_cats')
187      {
188        $name = get_cat_display_name_cache($category['uppercats'], null, false);
189      }
190      else
191      {
192        $name = $category['name'];
193      }
194
195      $icon_ts = get_icon($category['max_date_last'], $category['is_child_date_last']);
196
197      $template->assign_block_vars(
198        'categories.category',
199        array(
200          'SRC'   => $thumbnail_src_of[$category['representative_picture_id']],
201          'ALT'   => $category['name'],
202          'TITLE' => $lang['hint_category'],
203          'ICON'  => $icon_ts,
204
205          'URL'   => make_index_url(
206            array(
207              'category' => $category['id'],
208              'cat_name' => $category['name'],
209              )
210            ),
211          'CAPTION_NB_IMAGES' => get_display_images_count
212                                  (
213                                    $category['nb_images'],
214                                    $category['count_images'],
215                                    $category['count_categories']
216                                  ),
217          'DESCRIPTION' => @$comment,
218          'NAME'  => $name,
219          )
220        );
221    }
222
223    $template->assign_var_from_handle('CATEGORIES', 'mainpage_categories');
224  }
225  else
226  {
227    $template->set_filenames( array( 'thumbnails' => 'thumbnails.tpl',));
228    // first line
229    $template->assign_block_vars('thumbnails.line', array());
230    // current row displayed
231    $row_number = 0;
232
233    if ($page['section']=='recent_cats')
234    {
235      $old_level_separator = $conf['level_separator'];
236      $conf['level_separator'] = '<br />';
237    }
238
239    foreach ($categories as $category)
240    {
241      $template->assign_block_vars(
242        'thumbnails.line.thumbnail',
243        array(
244          'IMAGE'       => $thumbnail_src_of[ $category['representative_picture_id'] ],
245          'IMAGE_ALT'   => $category['name'],
246          'IMAGE_TITLE' => $lang['hint_category'],
247
248          'U_IMG_LINK'  => make_index_url(
249            array(
250              'category' => $category['id'],
251              'cat_name' => $category['name'],
252              )
253            ),
254          'CLASS'       => 'thumbCat',
255          )
256        );
257      if ($page['section']=='recent_cats')
258      {
259        $name = get_cat_display_name_cache($category['uppercats'], null, false);
260      }
261      else
262      {
263        $name = $category['name'];
264        $template->merge_block_vars(
265          'thumbnails.line.thumbnail',
266          array(
267            'IMAGE_TS'    => get_icon($category['max_date_last'], $category['is_child_date_last']),
268           )
269         );
270      }
271      $template->assign_block_vars(
272        'thumbnails.line.thumbnail.category_name',
273        array(
274          'NAME' => $name
275          )
276        );
277
278      // create a new line ?
279      if (++$row_number == $user['nb_image_line'])
280      {
281        $template->assign_block_vars('thumbnails.line', array());
282        $row_number = 0;
283      }
284    }
285
286    if ( isset($old_level_separator) )
287    {
288      $conf['level_separator']=$old_level_separator;
289    }
290
291    $template->assign_var_from_handle('THUMBNAILS', 'thumbnails');
292  }
293}
294?>
Note: See TracBrowser for help on using the repository browser.