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

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

Apply property svn:eol-style Value: LF

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Rev Revision URL
File size: 5.1 KB
Line 
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 1900 2007-03-12 22:33:53Z rub $
7// | last update   : $Date: 2007-03-12 22:33:53 +0000 (Mon, 12 Mar 2007) $
8// | last modifier : $Author: rub $
9// | revision      : $Revision: 1900 $
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// global variable for filter
27$filter = array();
28
29// $filter['enabled']: Filter is enabled
30// $filter['check_key']: Check key to valitade computed filter data
31// $filter['recent_period']: Recent period used to computed filter data
32// $filter['categories']: Computed data of filtered categories
33// $filter['visible_categories']:
34//  List of visible categories (count(visible) < count(forbidden) more often)
35// $filter['visible_images']: List of visible images
36
37if (!get_filter_page_value('cancel'))
38{
39  if (isset($_GET['filter']))
40  {
41    $filter['matches'] = array();
42    $filter['enabled'] = 
43      preg_match('/^start-recent-(\d+)$/', $_GET['filter'], $filter['matches']) === 1;
44  }
45  else
46  {
47    $filter['enabled'] = pwg_get_session_var('filter_enabled', false);
48  }
49}
50else
51{
52  $filter['enabled'] = false;
53}
54
55if ($filter['enabled'])
56{
57  if (isset($filter['matches']))
58  {
59    $filter['recent_period'] = $filter['matches'][1];
60  }
61  else
62  {
63    $filter['recent_period'] = pwg_get_session_var('filter_recent_period', $user['recent_period']);
64  }
65
66  if (
67      // New filter
68      !pwg_get_session_var('filter_enabled', false) or
69      // Cache data updated
70      $user['need_update_done'] or
71      // Date, period, user are changed
72      (pwg_get_session_var('filter_check_key', '') != get_filter_check_key())
73    )
74  {
75    // Need to compute dats
76    $filter['check_key'] = get_filter_check_key();
77    $filter['categories'] = get_computed_categories($user, (int)$filter['recent_period']);
78
79    $filter['visible_categories'] = implode(',', array_keys($filter['categories']));
80    if (empty($filter['visible_categories']))
81    {
82      // Must be not empty
83      $filter['visible_categories'] = -1;
84    }
85
86    $query ='
87SELECT
88  distinct image_id
89FROM '.
90  IMAGE_CATEGORY_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON image_id = id
91WHERE ';
92    if (!empty($filter['visible_categories']))
93    {
94    $query.= '
95  category_id  IN ('.$filter['visible_categories'].') and';
96    }
97  $query.= '
98    date_available >= SUBDATE(
99      CURRENT_DATE,INTERVAL '.$filter['recent_period'].' DAY)';
100
101    $filter['visible_images'] = implode(',', array_from_query($query, 'image_id'));
102
103    if (empty($filter['visible_images']))
104    {
105      // Must be not empty
106      $filter['visible_images'] = -1;
107    }
108
109    // Save filter data on session
110    pwg_set_session_var('filter_enabled', $filter['enabled']);
111    pwg_set_session_var('filter_check_key', $filter['check_key']);
112    pwg_set_session_var('filter_recent_period', $filter['recent_period']);
113    pwg_set_session_var('filter_categories', serialize($filter['categories']));
114    pwg_set_session_var('filter_visible_categories', $filter['visible_categories']);
115    pwg_set_session_var('filter_visible_images', $filter['visible_images']);
116
117  }
118  else
119  {
120    // Read only data
121    $filter['check_key'] = pwg_get_session_var('filter_check_key', '');
122    $filter['categories'] = unserialize(pwg_get_session_var('filter_categories', serialize(array())));
123    $filter['visible_categories'] = pwg_get_session_var('filter_visible_categories', '');
124    $filter['visible_images'] = pwg_get_session_var('filter_visible_images', '');
125  }
126
127  if (get_filter_page_value('add_notes'))
128  {
129    $header_notes[] = l10n_dec('note_filter_day', 'note_filter_days', $filter['recent_period']);
130  }
131}
132else
133{
134  if (pwg_get_session_var('filter_enabled', false))
135  {
136    pwg_unset_session_var('filter_enabled');
137    pwg_unset_session_var('filter_check_key');
138    pwg_unset_session_var('filter_recent_period');
139    pwg_unset_session_var('filter_categories');
140    pwg_unset_session_var('filter_visible_categories');
141    pwg_unset_session_var('filter_visible_images');
142  }
143}
144
145
146?>
Note: See TracBrowser for help on using the repository browser.