[1711] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[2297] | 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
[5196] | 5 | // | Copyright(C) 2008-2010 Piwigo Team http://piwigo.org | |
---|
[2297] | 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 | // +-----------------------------------------------------------------------+ |
---|
[1711] | 23 | |
---|
| 24 | // $filter['enabled']: Filter is enabled |
---|
[1722] | 25 | // $filter['recent_period']: Recent period used to computed filter data |
---|
[1711] | 26 | // $filter['categories']: Computed data of filtered categories |
---|
[1722] | 27 | // $filter['visible_categories']: |
---|
| 28 | // List of visible categories (count(visible) < count(forbidden) more often) |
---|
[1711] | 29 | // $filter['visible_images']: List of visible images |
---|
| 30 | |
---|
[1722] | 31 | if (!get_filter_page_value('cancel')) |
---|
[1715] | 32 | { |
---|
[1711] | 33 | if (isset($_GET['filter'])) |
---|
| 34 | { |
---|
[1722] | 35 | $filter['matches'] = array(); |
---|
[2448] | 36 | $filter['enabled'] = |
---|
[1723] | 37 | preg_match('/^start-recent-(\d+)$/', $_GET['filter'], $filter['matches']) === 1; |
---|
[1711] | 38 | } |
---|
| 39 | else |
---|
| 40 | { |
---|
| 41 | $filter['enabled'] = pwg_get_session_var('filter_enabled', false); |
---|
| 42 | } |
---|
[1715] | 43 | } |
---|
| 44 | else |
---|
| 45 | { |
---|
| 46 | $filter['enabled'] = false; |
---|
| 47 | } |
---|
[1711] | 48 | |
---|
[1715] | 49 | if ($filter['enabled']) |
---|
| 50 | { |
---|
[2448] | 51 | $filter_key = pwg_get_session_var('filter_check_key', array('user'=>0,'recent_period'=>-1, 'time'=>0, 'date'=> '') ); |
---|
| 52 | |
---|
[1722] | 53 | if (isset($filter['matches'])) |
---|
| 54 | { |
---|
| 55 | $filter['recent_period'] = $filter['matches'][1]; |
---|
| 56 | } |
---|
| 57 | else |
---|
| 58 | { |
---|
[2448] | 59 | $filter['recent_period'] = $filter_key['recent_period']>0 ? $filter_key['recent_period'] : $user['recent_period']; |
---|
[1722] | 60 | } |
---|
| 61 | |
---|
[1715] | 62 | if ( |
---|
| 63 | // New filter |
---|
| 64 | !pwg_get_session_var('filter_enabled', false) or |
---|
| 65 | // Cache data updated |
---|
[2448] | 66 | $filter_key['time'] <= $user['cache_update_time'] or |
---|
[1715] | 67 | // Date, period, user are changed |
---|
[2448] | 68 | $filter_key['user'] != $user['id'] or |
---|
| 69 | $filter_key['recent_period'] != $filter['recent_period'] or |
---|
| 70 | $filter_key['date'] != date('Ymd') |
---|
[1715] | 71 | ) |
---|
[1711] | 72 | { |
---|
[1715] | 73 | // Need to compute dats |
---|
[2448] | 74 | $filter_key = array( |
---|
| 75 | 'user'=>(int)$user['id'],'recent_period'=>(int)$filter['recent_period'], 'time'=>time(), 'date'=> date('Ymd') |
---|
| 76 | ); |
---|
| 77 | |
---|
[1860] | 78 | $filter['categories'] = get_computed_categories($user, (int)$filter['recent_period']); |
---|
[1715] | 79 | |
---|
| 80 | $filter['visible_categories'] = implode(',', array_keys($filter['categories'])); |
---|
| 81 | if (empty($filter['visible_categories'])) |
---|
[1711] | 82 | { |
---|
[1715] | 83 | // Must be not empty |
---|
| 84 | $filter['visible_categories'] = -1; |
---|
| 85 | } |
---|
[1711] | 86 | |
---|
[1715] | 87 | $query =' |
---|
| 88 | SELECT |
---|
| 89 | distinct image_id |
---|
| 90 | FROM '. |
---|
| 91 | IMAGE_CATEGORY_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON image_id = id |
---|
| 92 | WHERE '; |
---|
| 93 | if (!empty($filter['visible_categories'])) |
---|
| 94 | { |
---|
| 95 | $query.= ' |
---|
| 96 | category_id IN ('.$filter['visible_categories'].') and'; |
---|
| 97 | } |
---|
| 98 | $query.= ' |
---|
[4367] | 99 | date_available >= '.pwg_db_get_recent_period_expression($filter['recent_period']); |
---|
[1711] | 100 | |
---|
[1715] | 101 | $filter['visible_images'] = implode(',', array_from_query($query, 'image_id')); |
---|
[1711] | 102 | |
---|
[1715] | 103 | if (empty($filter['visible_images'])) |
---|
| 104 | { |
---|
| 105 | // Must be not empty |
---|
| 106 | $filter['visible_images'] = -1; |
---|
| 107 | } |
---|
[1711] | 108 | |
---|
[1715] | 109 | // Save filter data on session |
---|
| 110 | pwg_set_session_var('filter_enabled', $filter['enabled']); |
---|
[2448] | 111 | pwg_set_session_var('filter_check_key', $filter_key); |
---|
[1715] | 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 | } |
---|
[2448] | 123 | unset($filter_key); |
---|
[1722] | 124 | if (get_filter_page_value('add_notes')) |
---|
| 125 | { |
---|
[5206] | 126 | $header_notes[] = l10n_dec('Elements posted within the last %d day.', 'Elements posted within the last %d days.', $filter['recent_period']); |
---|
[1722] | 127 | } |
---|
[2476] | 128 | include_once(PHPWG_ROOT_PATH.'include/functions_filter.inc.php'); |
---|
[1715] | 129 | } |
---|
| 130 | else |
---|
| 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 | |
---|
[5206] | 143 | ?> |
---|