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