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

Last change on this file since 2297 was 2297, checked in by plg, 16 years ago

Modification: new header on PHP files, PhpWebGallery renamed Piwigo.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008      Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23// +-----------------------------------------------------------------------+
24// | PhpWebGallery - a PHP based picture gallery                           |
25// | Copyright (C) 2006-2007 PhpWebGallery Team - http://phpwebgallery.net |
26// +-----------------------------------------------------------------------+
27// | file          : $Id: filter.inc.php 2297 2008-04-04 22:57:23Z plg $
28// | last update   : $Date: 2008-04-04 22:57:23 +0000 (Fri, 04 Apr 2008) $
29// | last modifier : $Author: plg $
30// | revision      : $Revision: 2297 $
31// +-----------------------------------------------------------------------+
32// | This program is free software; you can redistribute it and/or modify  |
33// | it under the terms of the GNU General Public License as published by  |
34// | the Free Software Foundation                                          |
35// |                                                                       |
36// | This program is distributed in the hope that it will be useful, but   |
37// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
38// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
39// | General Public License for more details.                              |
40// |                                                                       |
41// | You should have received a copy of the GNU General Public License     |
42// | along with this program; if not, write to the Free Software           |
43// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
44// | USA.                                                                  |
45// +-----------------------------------------------------------------------+
46
47// $filter['enabled']: Filter is enabled
48// $filter['check_key']: Check key to valitade computed filter data
49// $filter['recent_period']: Recent period used to computed filter data
50// $filter['categories']: Computed data of filtered categories
51// $filter['visible_categories']:
52//  List of visible categories (count(visible) < count(forbidden) more often)
53// $filter['visible_images']: List of visible images
54
55if (!get_filter_page_value('cancel'))
56{
57  if (isset($_GET['filter']))
58  {
59    $filter['matches'] = array();
60    $filter['enabled'] = 
61      preg_match('/^start-recent-(\d+)$/', $_GET['filter'], $filter['matches']) === 1;
62  }
63  else
64  {
65    $filter['enabled'] = pwg_get_session_var('filter_enabled', false);
66  }
67}
68else
69{
70  $filter['enabled'] = false;
71}
72
73if ($filter['enabled'])
74{
75  if (isset($filter['matches']))
76  {
77    $filter['recent_period'] = $filter['matches'][1];
78  }
79  else
80  {
81    $filter['recent_period'] = pwg_get_session_var('filter_recent_period', $user['recent_period']);
82  }
83
84  if (
85      // New filter
86      !pwg_get_session_var('filter_enabled', false) or
87      // Cache data updated
88      $user['need_update_done'] or
89      // Date, period, user are changed
90      (pwg_get_session_var('filter_check_key', '') != get_filter_check_key())
91    )
92  {
93    // Need to compute dats
94    $filter['check_key'] = get_filter_check_key();
95    $filter['categories'] = get_computed_categories($user, (int)$filter['recent_period']);
96
97    $filter['visible_categories'] = implode(',', array_keys($filter['categories']));
98    if (empty($filter['visible_categories']))
99    {
100      // Must be not empty
101      $filter['visible_categories'] = -1;
102    }
103
104    $query ='
105SELECT
106  distinct image_id
107FROM '.
108  IMAGE_CATEGORY_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON image_id = id
109WHERE ';
110    if (!empty($filter['visible_categories']))
111    {
112    $query.= '
113  category_id  IN ('.$filter['visible_categories'].') and';
114    }
115  $query.= '
116    date_available >= SUBDATE(
117      CURRENT_DATE,INTERVAL '.$filter['recent_period'].' DAY)';
118
119    $filter['visible_images'] = implode(',', array_from_query($query, 'image_id'));
120
121    if (empty($filter['visible_images']))
122    {
123      // Must be not empty
124      $filter['visible_images'] = -1;
125    }
126
127    // Save filter data on session
128    pwg_set_session_var('filter_enabled', $filter['enabled']);
129    pwg_set_session_var('filter_check_key', $filter['check_key']);
130    pwg_set_session_var('filter_recent_period', $filter['recent_period']);
131    pwg_set_session_var('filter_categories', serialize($filter['categories']));
132    pwg_set_session_var('filter_visible_categories', $filter['visible_categories']);
133    pwg_set_session_var('filter_visible_images', $filter['visible_images']);
134
135  }
136  else
137  {
138    // Read only data
139    $filter['check_key'] = pwg_get_session_var('filter_check_key', '');
140    $filter['categories'] = unserialize(pwg_get_session_var('filter_categories', serialize(array())));
141    $filter['visible_categories'] = pwg_get_session_var('filter_visible_categories', '');
142    $filter['visible_images'] = pwg_get_session_var('filter_visible_images', '');
143  }
144
145  if (get_filter_page_value('add_notes'))
146  {
147    $header_notes[] = l10n_dec('note_filter_day', 'note_filter_days', $filter['recent_period']);
148  }
149}
150else
151{
152  if (pwg_get_session_var('filter_enabled', false))
153  {
154    pwg_unset_session_var('filter_enabled');
155    pwg_unset_session_var('filter_check_key');
156    pwg_unset_session_var('filter_recent_period');
157    pwg_unset_session_var('filter_categories');
158    pwg_unset_session_var('filter_visible_categories');
159    pwg_unset_session_var('filter_visible_images');
160  }
161}
162
163
164?>
Note: See TracBrowser for help on using the repository browser.