source: branches/2.4/include/filter.inc.php @ 18968

Last change on this file since 18968 was 12922, checked in by mistic100, 13 years ago

update Piwigo headers to 2012, last change before the expected (or not) apocalypse

  • Property svn:eol-style set to LF
File size: 5.3 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2012 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// $filter['enabled']: Filter is enabled
25// $filter['recent_period']: Recent period used to computed filter data
26// $filter['categories']: Computed data of filtered categories
27// $filter['visible_categories']:
28//  List of visible categories (count(visible) < count(forbidden) more often)
29// $filter['visible_images']: List of visible images
30
31if (!get_filter_page_value('cancel'))
32{
33  if (isset($_GET['filter']))
34  {
35    $filter['matches'] = array();
36    $filter['enabled'] =
37      preg_match('/^start-recent-(\d+)$/', $_GET['filter'], $filter['matches']) === 1;
38  }
39  else
40  {
41    $filter['enabled'] = pwg_get_session_var('filter_enabled', false);
42  }
43}
44else
45{
46  $filter['enabled'] = false;
47}
48
49if ($filter['enabled'])
50{
51  $filter_key = pwg_get_session_var('filter_check_key', array('user'=>0,'recent_period'=>-1, 'time'=>0, 'date'=> '') );
52
53  if (isset($filter['matches']))
54  {
55    $filter['recent_period'] = $filter['matches'][1];
56  }
57  else
58  {
59    $filter['recent_period'] = $filter_key['recent_period']>0 ? $filter_key['recent_period'] : $user['recent_period'];
60  }
61
62  if (
63      // New filter
64      !pwg_get_session_var('filter_enabled', false) or
65      // Cache data updated
66      $filter_key['time'] <= $user['cache_update_time'] or
67      // Date, period, user are changed
68      $filter_key['user'] != $user['id'] or
69      $filter_key['recent_period'] != $filter['recent_period'] or
70      $filter_key['date'] != date('Ymd')
71    )
72  {
73    // Need to compute dats
74    $filter_key = array(
75      'user'=>(int)$user['id'],'recent_period'=>(int)$filter['recent_period'], 'time'=>time(), 'date'=> date('Ymd')
76     );
77
78    $filter['categories'] = get_computed_categories($user, (int)$filter['recent_period']);
79
80    $filter['visible_categories'] = implode(',', array_keys($filter['categories']));
81    if (empty($filter['visible_categories']))
82    {
83      // Must be not empty
84      $filter['visible_categories'] = -1;
85    }
86
87    $query ='
88SELECT
89  distinct image_id
90FROM '.
91  IMAGE_CATEGORY_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON image_id = id
92WHERE ';
93    if (!empty($filter['visible_categories']))
94    {
95    $query.= '
96  category_id  IN ('.$filter['visible_categories'].') and';
97    }
98  $query.= '
99    date_available >= '.pwg_db_get_recent_period_expression($filter['recent_period']);
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_key);
112    pwg_set_session_var('filter_categories', serialize($filter['categories']));
113    pwg_set_session_var('filter_visible_categories', $filter['visible_categories']);
114    pwg_set_session_var('filter_visible_images', $filter['visible_images']);
115  }
116  else
117  {
118    // Read only data
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  unset($filter_key);
124  if (get_filter_page_value('add_notes'))
125  {
126    $header_notes[] = l10n_dec('Photos posted within the last %d day.', 'Photos posted within the last %d days.', $filter['recent_period']);
127  }
128  include_once(PHPWG_ROOT_PATH.'include/functions_filter.inc.php');
129}
130else
131{
132  if (pwg_get_session_var('filter_enabled', false))
133  {
134    pwg_unset_session_var('filter_enabled');
135    pwg_unset_session_var('filter_check_key');
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?>
Note: See TracBrowser for help on using the repository browser.