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

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

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

Fix problem with 0 category on filtered result

Big error on my last commit for $filtervisible_images

File size: 4.9 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
74    $filter['visible_categories'] = implode(',', array_keys($filter['categories']));
75    if (empty($filter['visible_categories']))
76    {
77      // Must be not empty
78      $filter['visible_categories'] = -1;
79    }
80
81    $query ='
82SELECT
83  distinct image_id
84FROM '.
85  IMAGE_CATEGORY_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON image_id = id
86WHERE ';
87    if (!empty($filter['visible_categories']))
88    {
89    $query.= '
90  category_id  IN ('.$filter['visible_categories'].') and';
91    }
92  $query.= '
93    date_available  > SUBDATE(
94      CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY)';
95
96    $filter['visible_images'] = implode(',', array_from_query($query, 'image_id'));
97
98    if (empty($filter['visible_images']))
99    {
100      // Must be not empty
101      $filter['visible_images'] = -1;
102    }
103
104  }
105  else
106  {
107    // Read only data
108    $filter['check_key'] = pwg_get_session_var('filter_check_key', '');
109    $filter['categories'] = unserialize(pwg_get_session_var('filter_categories', serialize(array())));
110    $filter['visible_categories'] = pwg_get_session_var('filter_visible_categories', '');
111    $filter['visible_images'] = pwg_get_session_var('filter_visible_images', '');
112  }
113
114  $header_notes[] = l10n_dec('note_filter_day', 'note_filter_days', $user['recent_period']);
115}
116else
117{
118  $filter['check_key'] = '';
119  $filter['categories'] = array();
120  $filter['visible_categories'] = '';
121  $filter['visible_images'] = '';
122}
123
124pwg_set_session_var('filter_enabled', $filter['enabled']);
125pwg_set_session_var('filter_check_key', $filter['check_key']);
126pwg_set_session_var('filter_categories', serialize($filter['categories']));
127pwg_set_session_var('filter_visible_categories', $filter['visible_categories']);
128pwg_set_session_var('filter_visible_images', $filter['visible_images']);
129
130?>
Note: See TracBrowser for help on using the repository browser.