source: trunk/include/filter.inc.php @ 1677

Last change on this file since 1677 was 1677, checked in by rub, 17 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
File size: 4.6 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2006-2007 PhpWebGallery Team - http://phpwebgallery.net |
5// +-----------------------------------------------------------------------+
6// | branch        : BSF (Best So Far)
7// | file          : $Id: filter.inc.php 1651 2006-12-13 00:05:16Z rub $
8// | last update   : $Date: 2006-12-13 01:05:16 +0100 (mer., 13 déc. 2006) $
9// | last modifier : $Author: rub $
10// | revision      : $Revision: 1651 $
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// global variable for filter
28$filter = array();
29
30// $filter['enabled']: Filter is enabled
31// $filter['categories']: Computed data of filtered categories
32// $filter['visible_categories']: List of visible categories (count(visible) < count(forbidden) more often)
33// $filter['visible_images']: List of visible images
34
35
36$filter['enabled'] = 
37  (in_array(basename($_SERVER['SCRIPT_FILENAME']), $conf['filter_pages'])) and
38  (
39    (isset($_GET['filter']) and ($_GET['filter'] == 'start')) or
40    pwg_get_session_var('filter_enabled', false)
41  );
42
43if (in_array(basename($_SERVER['SCRIPT_FILENAME']), $conf['filter_pages']))
44{
45  if (isset($_GET['filter']))
46  {
47    $filter['enabled'] = ($_GET['filter'] == 'start');
48  }
49  else
50  {
51    $filter['enabled'] = pwg_get_session_var('filter_enabled', false);
52  }
53}
54else
55{
56  $filter['enabled'] = false;
57}
58
59if ($filter['enabled'])
60{
61  if (
62      // New filter
63      !pwg_get_session_var('filter_enabled', false) or
64      // Cache data updated
65      $user['need_update_done'] or
66      // Date, period, user are changed
67      (pwg_get_session_var('filter_check_key', '') != get_filter_check_key())
68    )
69  {
70    // Need to compute dats
71    $filter['check_key'] = get_filter_check_key();
72    $filter['categories'] = get_computed_categories($user['id'], $user['forbidden_categories'], true, $user['recent_period']);
73    $filter['visible_categories'] = implode(',', array_keys($filter['categories']));
74
75    $query ='
76SELECT
77  distinct image_id
78FROM '.
79  IMAGE_CATEGORY_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON image_id = id
80WHERE ';
81    if (!empty($filter['visible_categories']))
82    {
83    $query.= '
84  category_id  IN ('.$filter['visible_categories'].') and';
85    }
86  $query.= '
87    date_available  > SUBDATE(
88      CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY)';
89
90    $filter['visible_images'] = implode(',', array_from_query($query, 'image_id'));
91  }
92  else
93  {
94    // Read only data
95    $filter['check_key'] = pwg_get_session_var('filter_check_key', '');
96    $filter['categories'] = unserialize(pwg_get_session_var('filter_categories', serialize(array())));
97    $filter['visible_categories'] = pwg_get_session_var('filter_visible_categories', '');
98    $filter['visible_images'] = pwg_get_session_var('filter_visible_images', '');
99  }
100
101  $header_notes[] = l10n_dec($lang['note_filter_day'], $lang['note_filter_days'], $user['recent_period']);
102}
103else
104{
105  $filter['check_key'] = '';
106  $filter['categories'] = array();
107  $filter['visible_categories'] = '';
108  $filter['visible_images'] = '';
109}
110
111pwg_set_session_var('filter_enabled', $filter['enabled']);
112pwg_set_session_var('filter_check_key', $filter['check_key']);
113pwg_set_session_var('filter_categories', serialize($filter['categories']));
114pwg_set_session_var('filter_visible_categories', $filter['visible_categories']);
115pwg_set_session_var('filter_visible_images', $filter['visible_images']);
116
117?>
Note: See TracBrowser for help on using the repository browser.