diff options
author | rub <rub@piwigo.org> | 2006-12-21 21:38:20 +0000 |
---|---|---|
committer | rub <rub@piwigo.org> | 2006-12-21 21:38:20 +0000 |
commit | cab8f98c4ab88a0ad05f2359099c883675319084 (patch) | |
tree | a8224615d63c1330fd8744e3abd5195eb5763476 | |
parent | a7ce26153185c274a08fb52b07402c8afba6f128 (diff) |
Feature Issue ID 0000601: Filter all public pages with only recent elements
It's a finalized version.
Obsolete code of draft are removed.
You can filter categories and images with recent date period on your screen selection.
In the future, filter could be easy done on other type data (plugin?)
You can flat categories and sub-categories with a recent date period of your choice.
Next, perhaps, a panel to choice recent date for the 2 features.
On draft, there have problem with MySql 5, be careful!
Css problem not resolved:
- Menu "Categories" is bad centered
- Icon on dark too on the top
git-svn-id: http://piwigo.org/svn/trunk@1677 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
40 files changed, 889 insertions, 344 deletions
diff --git a/action.php b/action.php index 2d347f8be..c0cab23de 100644 --- a/action.php +++ b/action.php @@ -80,13 +80,15 @@ if ( empty($element_info) ) { do_error(404, 'Requested id not found'); } - +
+// $filter['visible_categories'] and $filter['visible_images']
+// are not used because it's not necessary (filter <> restriction) $query=' SELECT id FROM '.CATEGORIES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON category_id=id - WHERE image_id='.$id.' - AND category_id NOT IN ('.$user['forbidden_categories'].') + WHERE image_id='.$id.'
+.'get_sql_condition_FandF(array('forbidden_categories' => 'category_id'), 'AND').'
LIMIT 1 ;'; if ( mysql_num_rows(pwg_query($query))<1 ) diff --git a/comments.php b/comments.php index 4d9ca26db..771d23ea7 100644 --- a/comments.php +++ b/comments.php @@ -216,13 +216,16 @@ $template->assign_block_vars( $query = ' SELECT id,name,uppercats,global_rank - FROM '.CATEGORIES_TABLE; -if ($user['forbidden_categories'] != '') -{ - $query.= ' - WHERE id NOT IN ('.$user['forbidden_categories'].')'; -} -$query.= ' + FROM '.CATEGORIES_TABLE.' +'.get_sql_condition_FandF + ( + array + ( + 'forbidden_categories' => 'id', + 'visible_categories' => 'id' + ), + 'WHERE' + ).' ;'; display_select_cat_wrapper($query, array(@$_GET['cat']), $blockname, true); @@ -308,13 +311,17 @@ SELECT COUNT(DISTINCT(id)) AND '.$page['cat_clause'].' AND '.$page['author_clause'].' AND '.$page['keyword_clause'].' - AND '.$page['status_clause']; -if ($user['forbidden_categories'] != '') -{ - $query.= ' - AND category_id NOT IN ('.$user['forbidden_categories'].')'; -} -$query.= ' + AND '.$page['status_clause'].' +'.get_sql_condition_FandF + ( + array + ( + 'forbidden_categories' => 'category_id', + 'visible_categories' => 'category_id', + 'visible_images' => 'ic.image_id' + ), + 'AND' + ).' ;'; list($counter) = mysql_fetch_row(pwg_query($query)); @@ -354,13 +361,17 @@ SELECT com.id AS comment_id AND '.$page['cat_clause'].' AND '.$page['author_clause'].' AND '.$page['keyword_clause'].' - AND '.$page['status_clause']; -if ($user['forbidden_categories'] != '') -{ - $query.= ' - AND category_id NOT IN ('.$user['forbidden_categories'].')'; -} -$query.= ' + AND '.$page['status_clause'].' +'.get_sql_condition_FandF + ( + array + ( + 'forbidden_categories' => 'category_id', + 'visible_categories' => 'category_id', + 'visible_images' => 'ic.image_id' + ), + 'AND' + ).' GROUP BY comment_id ORDER BY '.$page['sort_by'].' '.$page['sort_order']; if ('all' != $page['items_number']) diff --git a/include/category_cats.inc.php b/include/category_cats.inc.php index c84bdf6e9..67e666fb8 100644 --- a/include/category_cats.inc.php +++ b/include/category_cats.inc.php @@ -42,7 +42,16 @@ SELECT ON id = cat_id and user_id = '.$user['id'].' WHERE date_last > SUBDATE( CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY - );'; + ) +'.get_sql_condition_FandF + ( + array + ( + 'visible_categories' => 'id', + ), + 'AND' + ).' +;'; } else { @@ -54,14 +63,15 @@ SELECT FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' ON id = cat_id and user_id = '.$user['id'].' WHERE id_uppercat '. - (!isset($page['category']) ? 'is NULL' : '= '.$page['category']); - if ($page['filter_local_mode']) - { - $query.= ' - AND max_date_last > SUBDATE( - CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY)'; - } - $query.= ' + (!isset($page['category']) ? 'is NULL' : '= '.$page['category']).' +'.get_sql_condition_FandF + ( + array + ( + 'visible_categories' => 'id', + ), + 'AND' + ).' ORDER BY rank ;'; } @@ -85,21 +95,18 @@ while ($row = mysql_fetch_assoc($result)) SELECT image_id FROM '.CATEGORIES_TABLE.' AS c INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.category_id = c.id'; - if ($page['filter_local_mode'] or $user['filter_global_mode']) - { - $query.= ' - INNER JOIN '.IMAGES_TABLE.' AS i on ic.image_id = i.id '; - } $query.= ' WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\' - AND c.id NOT IN ('.$user['forbidden_categories'].')'; - if ($page['filter_local_mode'] or $user['filter_global_mode']) - { - $query.= ' - AND i.date_available > SUBDATE( - CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY)'; - } - $query.= ' +'.get_sql_condition_FandF + ( + array + ( + 'forbidden_categories' => 'c.id', + 'visible_categories' => 'c.id', + 'visible_images' => 'image_id' + ), + 'AND' + ).' ORDER BY RAND() LIMIT 0,1 ;'; @@ -116,14 +123,15 @@ SELECT representative_picture_id FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' ON id = cat_id and user_id = '.$user['id'].' WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\' - AND representative_picture_id IS NOT NULL'; - if ($page['filter_local_mode'] or $user['filter_global_mode']) - { - $query.= ' - AND max_date_last > SUBDATE( - CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY)'; - } - $query.= ' + AND representative_picture_id IS NOT NULL +'.get_sql_condition_FandF + ( + array + ( + 'visible_categories' => 'id', + ), + 'AND' + ).' ORDER BY RAND() LIMIT 0,1 ;'; @@ -161,6 +169,9 @@ SELECT id, path, tn_ext if (count($categories) > 0) { + // Update filtered data + update_cats_with_filtered_data($categories); + if ($conf['subcatify']) { $template->set_filenames( diff --git a/include/category_default.inc.php b/include/category_default.inc.php index 1fff71956..8422fcf13 100644 --- a/include/category_default.inc.php +++ b/include/category_default.inc.php @@ -2,7 +2,7 @@ // +-----------------------------------------------------------------------+ // | PhpWebGallery - a PHP based picture gallery | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | -// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | +// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net | // +-----------------------------------------------------------------------+ // | branch : BSF (Best So Far) // | file : $RCSfile$ @@ -46,14 +46,8 @@ if (count($selection) > 0) $query = ' SELECT * FROM '.IMAGES_TABLE.' - WHERE id IN ('.implode(',', $selection).')'; - if ($page['filter_local_mode'] or $user['filter_global_mode']) - { - $query.= ' - AND date_available > SUBDATE( - CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY)'; - } - $query.= ';'; + WHERE id IN ('.implode(',', $selection).') +;'; $result = pwg_query($query); while ($row = mysql_fetch_assoc($result)) { diff --git a/include/common.inc.php b/include/common.inc.php index c1ebc7f74..3fca4783d 100644 --- a/include/common.inc.php +++ b/include/common.inc.php @@ -112,6 +112,7 @@ $page = array(); $user = array(); $lang = array(); $header_msgs = array(); +$header_notes = array(); @include(PHPWG_ROOT_PATH .'include/mysql.inc.php'); if (!defined('PHPWG_INSTALLED')) @@ -228,6 +229,17 @@ if (count($header_msgs) > 0) } } +if (!defined('IN_ADMIN') or !IN_ADMIN) +{ + include(PHPWG_ROOT_PATH.'include/functions_filter.inc.php'); + include(PHPWG_ROOT_PATH.'include/filter.inc.php'); +} + +if (isset($conf['header_notes'])) +{ + $header_notes = array_merge($header_notes, $conf['header_notes']); +} + // default event handlers add_event_handler('render_comment_content', 'parse_comment_content'); trigger_action('init'); diff --git a/include/config_default.inc.php b/include/config_default.inc.php index 6e6b39cb5..453a9a02b 100644 --- a/include/config_default.inc.php +++ b/include/config_default.inc.php @@ -174,6 +174,10 @@ $conf['show_version'] = true; // page. $conf['links'] = array(); +// List of notes to display on all header page +// example $conf['header_notes'] = array('Test', 'Hello'); +$conf['header_notes'] = array(); + // show_thumbnail_caption : on thumbnails page, show thumbnail captions ? $conf['show_thumbnail_caption'] = true; @@ -543,7 +547,7 @@ $conf['nbm_treatment_timeout_default'] = 20; $conf['enable_plugins']=true; // +-----------------------------------------------------------------------+ -// | Set default for Web Service | +// | Set default for Web Service | // +-----------------------------------------------------------------------+ // Web services are accepted @@ -561,4 +565,17 @@ $conf['enable_plugins']=true; // 0 it's temporary closed (Useful for one access) $conf['ws_durations'] = array(3650,1825,730,365,182,91,30,15,10,7,5,1,0); +// +-----------------------------------------------------------------------+ +// | Filter | +// +-----------------------------------------------------------------------+ +// Pages where filter is enabled +// Other pages cancel current filter +$conf['filter_pages'] = array + ( + 'about.php', 'action.php', 'admin.php', 'comments.php', + 'index.php', 'picture.php', 'popuphelp.php', 'profile.php', + 'qsearch.php', 'random.php', 'register.php', 'search.php', + 'search_rules.php', 'tags.php', 'upload.php' + ); + ?> diff --git a/include/filter.inc.php b/include/filter.inc.php new file mode 100644 index 000000000..3a1279f94 --- /dev/null +++ b/include/filter.inc.php @@ -0,0 +1,117 @@ +<?php
+// +-----------------------------------------------------------------------+
+// | PhpWebGallery - a PHP based picture gallery |
+// | Copyright (C) 2006-2007 PhpWebGallery Team - http://phpwebgallery.net |
+// +-----------------------------------------------------------------------+
+// | branch : BSF (Best So Far)
+// | file : $Id: filter.inc.php 1651 2006-12-13 00:05:16Z rub $
+// | last update : $Date: 2006-12-13 01:05:16 +0100 (mer., 13 déc. 2006) $
+// | last modifier : $Author: rub $
+// | revision : $Revision: 1651 $
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify |
+// | it under the terms of the GNU General Public License as published by |
+// | the Free Software Foundation |
+// | |
+// | This program is distributed in the hope that it will be useful, but |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
+// | General Public License for more details. |
+// | |
+// | You should have received a copy of the GNU General Public License |
+// | along with this program; if not, write to the Free Software |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA. |
+// +-----------------------------------------------------------------------+
+
+// global variable for filter
+$filter = array();
+
+// $filter['enabled']: Filter is enabled
+// $filter['categories']: Computed data of filtered categories
+// $filter['visible_categories']: List of visible categories (count(visible) < count(forbidden) more often)
+// $filter['visible_images']: List of visible images
+
+
+$filter['enabled'] =
+ (in_array(basename($_SERVER['SCRIPT_FILENAME']), $conf['filter_pages'])) and
+ (
+ (isset($_GET['filter']) and ($_GET['filter'] == 'start')) or
+ pwg_get_session_var('filter_enabled', false)
+ );
+
+if (in_array(basename($_SERVER['SCRIPT_FILENAME']), $conf['filter_pages']))
+{
+ if (isset($_GET['filter']))
+ {
+ $filter['enabled'] = ($_GET['filter'] == 'start');
+ }
+ else
+ {
+ $filter['enabled'] = pwg_get_session_var('filter_enabled', false);
+ }
+}
+else
+{
+ $filter['enabled'] = false;
+}
+
+if ($filter['enabled'])
+{
+ if (
+ // New filter
+ !pwg_get_session_var('filter_enabled', false) or
+ // Cache data updated
+ $user['need_update_done'] or
+ // Date, period, user are changed
+ (pwg_get_session_var('filter_check_key', '') != get_filter_check_key())
+ )
+ {
+ // Need to compute dats
+ $filter['check_key'] = get_filter_check_key();
+ $filter['categories'] = get_computed_categories($user['id'], $user['forbidden_categories'], true, $user['recent_period']);
+ $filter['visible_categories'] = implode(',', array_keys($filter['categories']));
+
+ $query ='
+SELECT
+ distinct image_id
+FROM '.
+ IMAGE_CATEGORY_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON image_id = id
+WHERE ';
+ if (!empty($filter['visible_categories']))
+ {
+ $query.= '
+ category_id IN ('.$filter['visible_categories'].') and';
+ }
+ $query.= '
+ date_available > SUBDATE(
+ CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY)';
+
+ $filter['visible_images'] = implode(',', array_from_query($query, 'image_id'));
+ }
+ else
+ {
+ // Read only data
+ $filter['check_key'] = pwg_get_session_var('filter_check_key', '');
+ $filter['categories'] = unserialize(pwg_get_session_var('filter_categories', serialize(array())));
+ $filter['visible_categories'] = pwg_get_session_var('filter_visible_categories', '');
+ $filter['visible_images'] = pwg_get_session_var('filter_visible_images', '');
+ }
+
+ $header_notes[] = l10n_dec($lang['note_filter_day'], $lang['note_filter_days'], $user['recent_period']);
+}
+else
+{
+ $filter['check_key'] = '';
+ $filter['categories'] = array();
+ $filter['visible_categories'] = '';
+ $filter['visible_images'] = '';
+}
+
+pwg_set_session_var('filter_enabled', $filter['enabled']);
+pwg_set_session_var('filter_check_key', $filter['check_key']);
+pwg_set_session_var('filter_categories', serialize($filter['categories']));
+pwg_set_session_var('filter_visible_categories', $filter['visible_categories']);
+pwg_set_session_var('filter_visible_images', $filter['visible_images']);
+
+?>
diff --git a/include/functions_calendar.inc.php b/include/functions_calendar.inc.php index 3bc79cddc..3bb70ed35 100644 --- a/include/functions_calendar.inc.php +++ b/include/functions_calendar.inc.php @@ -29,7 +29,7 @@ define('CAL_VIEW_CALENDAR', 'calendar'); function initialize_calendar() { - global $page, $conf, $user, $template; + global $page, $conf, $user, $template, $filter; //------------------ initialize the condition on items to take into account --- $inner_sql = ' FROM ' . IMAGES_TABLE; @@ -58,7 +58,16 @@ WHERE category_id IN ('.implode(',',$sub_ids).')'; else { $inner_sql .= ' -WHERE category_id NOT IN ('.$user['forbidden_categories'].')'; + '.get_sql_condition_FandF + ( + array + ( + 'forbidden_categories' => 'category_id', + 'visible_categories' => 'category_id', + 'visible_images' => 'image_id' + ), + 'WHERE', true + ); } } else diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php index 4ae2b126c..bde0944e7 100644 --- a/include/functions_category.inc.php +++ b/include/functions_category.inc.php @@ -2,7 +2,7 @@ // +-----------------------------------------------------------------------+ // | PhpWebGallery - a PHP based picture gallery | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | -// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | +// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net | // +-----------------------------------------------------------------------+ // | branch : BSF (Best So Far) // | file : $Id$ @@ -44,6 +44,8 @@ function check_restrictions($category_id) { global $user; + // $filter['visible_categories'] and $filter['visible_images'] + // are not used because it's not necessary (filter <> restriction) if (in_array($category_id, explode(',', $user['forbidden_categories']))) { access_denied(); @@ -52,7 +54,7 @@ function check_restrictions($category_id) function get_categories_menu() { - global $page, $user; + global $page, $user, $filter; $query = ' SELECT '; @@ -65,28 +67,34 @@ SELECT '; // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE $query.= ' - FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' +FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' ON id = cat_id and user_id = '.$user['id']; - if ($page['filter_local_mode']) + + // Always expand when filter is activated + if (!$user['expand'] and !$filter['enabled']) { $query.= ' -where max_date_last > SUBDATE( - CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY)'; +WHERE +(id_uppercat is NULL'; + if (isset($page['category'])) + { + $query.= ' OR id_uppercat IN ('.$page['uppercats'].')'; + } + $query.= ')'; } else { - // Always expand when filter_local_mode is activated - if (!$user['expand'] and !$user['filter_global_mode']) - { - $query.= ' - WHERE (id_uppercat is NULL'; - if (isset($page['category'])) - { - $query.= ' OR id_uppercat IN ('.$page['uppercats'].')'; - } - $query.= ')'; - } + $query.= ' + '.get_sql_condition_FandF + ( + array + ( + 'visible_categories' => 'id', + ), + 'WHERE' + ); } + $query.= ' ;'; @@ -98,6 +106,9 @@ where max_date_last > SUBDATE( } usort($cats, 'global_rank_compare'); + // Update filtered data + update_cats_with_filtered_data($cats); + return get_html_menu_category($cats); } diff --git a/include/functions_filter.inc.php b/include/functions_filter.inc.php new file mode 100644 index 000000000..4bd5a6769 --- /dev/null +++ b/include/functions_filter.inc.php @@ -0,0 +1,66 @@ +<?php
+// +-----------------------------------------------------------------------+
+// | PhpWebGallery - a PHP based picture gallery |
+// | Copyright (C) 2006-2007 PhpWebGallery Team - http://phpwebgallery.net |
+// +-----------------------------------------------------------------------+
+// | branch : BSF (Best So Far)
+// | file : $Id: functions_filter.inc.php 1651 2006-12-13 00:05:16Z rub $
+// | last update : $Date: 2006-12-13 01:05:16 +0100 (mer., 13 déc. 2006) $
+// | last modifier : $Author: rub $
+// | revision : $Revision: 1651 $
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify |
+// | it under the terms of the GNU General Public License as published by |
+// | the Free Software Foundation |
+// | |
+// | This program is distributed in the hope that it will be useful, but |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
+// | General Public License for more details. |
+// | |
+// | You should have received a copy of the GNU General Public License |
+// | along with this program; if not, write to the Free Software |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA. |
+// +-----------------------------------------------------------------------+
+
+
+/**
+ * Get a check key for filtered data
+ * Check key are composed of elements witch force to compute data
+ *
+ * @param null
+ * @return strinf check_key
+ */
+function get_filter_check_key()
+{
+ global $user;
+
+ return $user['id'].$user['recent_period'].date('Ymd');
+}
+
+/**
+ * update data of categories with filtered values
+ *
+ * @param array list of categories
+ * @return null
+ */
+function update_cats_with_filtered_data(&$cats)
+{
+ global $filter;
+
+ if ($filter['enabled'])
+ {
+ $upd_fields = array('max_date_last', 'count_images', 'count_categories', 'nb_images');
+
+ foreach ($cats as $cat_id => $category)
+ {
+ foreach ($upd_fields as $upd_field)
+ {
+ $cats[$cat_id][$upd_field] = $filter['categories'][$category['id']][$upd_field];
+ }
+ }
+ }
+}
+
+?>
diff --git a/include/functions_html.inc.php b/include/functions_html.inc.php index 39f738f3f..8b544defa 100644 --- a/include/functions_html.inc.php +++ b/include/functions_html.inc.php @@ -288,11 +288,12 @@ function get_cat_display_name($cat_informations, { $output.= '<a class=""'; $output.= ' href="' - .make_index_url( + .duplicate_index_url( array( 'category'=>$id, 'cat_name'=>$name - ) + ), + array('start') ) .'">'; $output.= $name.'</a>'; diff --git a/include/functions_notification.inc.php b/include/functions_notification.inc.php index 8c88fd342..631922303 100644 --- a/include/functions_notification.inc.php +++ b/include/functions_notification.inc.php @@ -28,6 +28,31 @@ // +-----------------------------------------------------------------------+ // | functions | // +-----------------------------------------------------------------------+ +
+/*
+ * get standard sql where in order to
+ * restict an filter caregories and images
+ *
+ * IMAGE_CATEGORY_TABLE muste named ic in the query
+ *
+ * @param none
+ *
+ * @return string sql where
+ */
+function get_std_sql_where_restrict_filter($prefix_condition, $force_one_condition = false)
+{ + return get_sql_condition_FandF + ( + array + ( + 'forbidden_categories' => 'ic.category_id', + 'visible_categories' => 'ic.category_id', + 'visible_images' => 'ic.image_id' + ), + $prefix_condition, + $force_one_condition + ); +}
/* * Execute custom notification query @@ -43,7 +68,7 @@ function custom_notification_query($action, $type, $start, $end) { global $user; - +
switch($type) { case 'new_comments': @@ -53,7 +78,7 @@ function custom_notification_query($action, $type, $start, $end) WHERE c.image_id = ic.image_id AND c.validation_date > \''.$start.'\' AND c.validation_date <= \''.$end.'\' - AND category_id NOT IN ('.$user['forbidden_categories'].') + '.get_std_sql_where_restrict_filter('AND').' ;'; break; case 'unvalidated_comments': @@ -66,18 +91,18 @@ function custom_notification_query($action, $type, $start, $end) break; case 'new_elements': $query = ' - FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id + FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON image_id = id WHERE date_available > \''.$start.'\' AND date_available <= \''.$end.'\' - AND category_id NOT IN ('.$user['forbidden_categories'].') + '.get_std_sql_where_restrict_filter('AND').' ;'; break; case 'updated_categories': $query = ' - FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id + FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON image_id = id WHERE date_available > \''.$start.'\' AND date_available <= \''.$end.'\' - AND category_id NOT IN ('.$user['forbidden_categories'].') + '.get_std_sql_where_restrict_filter('AND').' ;'; break; case 'new_users': @@ -421,15 +446,15 @@ function news($start, $end, $exclude_img_cats=false, $add_url=false) */ function get_recent_post_dates($max_dates, $max_elements, $max_cats) { - global $conf, $user; + global $conf, $user;
- $where_sql = 'WHERE category_id NOT IN ('.$user['forbidden_categories'].')'; + $where_sql = get_std_sql_where_restrict_filter('WHERE', true); $query = ' SELECT date_available, COUNT(DISTINCT id) nb_elements, COUNT(DISTINCT category_id) nb_cats - FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id + FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id=image_id '.$where_sql.' GROUP BY date_available ORDER BY date_available DESC @@ -448,7 +473,7 @@ SELECT date_available, { // get some thumbnails ... $query = ' SELECT DISTINCT id, path, name, tn_ext - FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id + FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id=image_id '.$where_sql.' AND date_available="'.$dates[$i]['date_available'].'" AND tn_ext IS NOT NULL @@ -466,7 +491,7 @@ SELECT DISTINCT id, path, name, tn_ext {// get some categories ... $query = ' SELECT DISTINCT c.uppercats, COUNT(DISTINCT i.id) img_count - FROM '.IMAGES_TABLE.' i INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON i.id=image_id + FROM '.IMAGES_TABLE.' i INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON i.id=image_id INNER JOIN '.CATEGORIES_TABLE.' c ON c.id=category_id '.$where_sql.' AND date_available="'.$dates[$i]['date_available'].'" diff --git a/include/functions_search.inc.php b/include/functions_search.inc.php index 36dbb6210..14076ffb0 100644 --- a/include/functions_search.inc.php +++ b/include/functions_search.inc.php @@ -335,7 +335,7 @@ function get_qsearch_like_clause($q, $field) */ function get_quick_search_results($q) { - global $user, $page; + global $user, $page, $filter; $search_results = array(); // first search tag names corresponding to the query $q. we could also search @@ -384,7 +384,16 @@ FROM ( ) INNER JOIN '.CATEGORIES_TABLE.' c on c.id=ic.category_id -WHERE category_id NOT IN ('.$user['forbidden_categories'].') +'.get_sql_condition_FandF + ( + array + ( + 'forbidden_categories' => 'category_id', + 'visible_categories' => 'category_id', + 'visible_images' => 'ic.image_id' + ), + 'WHERE' + ).' GROUP BY i.id'; $query = 'SELECT id, MATCH(ft) AGAINST( "'.$q.'" IN BOOLEAN MODE) AS q FROM ('.$query.') AS Y @@ -427,8 +436,16 @@ SELECT DISTINCT(id) FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id WHERE id IN ('.implode(',', array_keys($by_tag_weights) ).') - AND category_id NOT IN ('.$user['forbidden_categories'].')'; - +'.get_sql_condition_FandF + ( + array + ( + 'forbidden_categories' => 'category_id', + 'visible_categories' => 'category_id', + 'visible_images' => 'ic.image_id' + ), + 'AND' + ); $allowed_image_ids = array_from_query( $query, 'id'); $by_tag_weights = array_intersect_key($by_tag_weights, array_flip($allowed_image_ids)); arsort($by_tag_weights, SORT_NUMERIC); diff --git a/include/functions_tag.inc.php b/include/functions_tag.inc.php index b330041ca..c01bb2fc7 100644 --- a/include/functions_tag.inc.php +++ b/include/functions_tag.inc.php @@ -37,7 +37,7 @@ * @param array forbidden categories * @return array */ -function get_available_tags($forbidden_categories = null) +function get_available_tags() { // we can find top fatter tags among reachable images $tags_query = ' @@ -45,13 +45,25 @@ SELECT tag_id, name, url_name, count(*) counter FROM '.IMAGE_TAG_TABLE.' INNER JOIN '.TAGS_TABLE.' ON tag_id = id'; - if (!is_null($forbidden_categories)) + $where_tag_img = + get_sql_condition_FandF + ( + array + ( + 'forbidden_categories' => 'category_id', + 'visible_categories' => 'category_id', + 'visible_images' => 'image_id' + ), + 'WHERE' + ); + + if (!is_null($where_tag_img)) { // first we need all reachable image ids $images_query = ' SELECT DISTINCT image_id FROM '.IMAGE_CATEGORY_TABLE.' - WHERE category_id NOT IN ('.implode(',', $forbidden_categories).') + '.$where_tag_img.' ;'; $image_ids = array_from_query($images_query, 'image_id'); if ( empty($image_ids) ) diff --git a/include/functions_url.inc.php b/include/functions_url.inc.php index 2b561f3d4..e50f3e2e8 100644 --- a/include/functions_url.inc.php +++ b/include/functions_url.inc.php @@ -264,6 +264,11 @@ function add_well_known_params_in_url($url, $params) } } + if (isset($params['flat_recent_cat']) and $params['flat_recent_cat'] > 0) + { + $url.= '/flat_recent_cat-'.$params['flat_recent_cat']; + } + if (isset($params['start']) and $params['start'] > 0) { $url.= '/start-'.$params['start']; diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php index d59a97e4d..dba5072fb 100644 --- a/include/functions_user.inc.php +++ b/include/functions_user.inc.php @@ -143,12 +143,11 @@ function setup_style($style) return new Template(PHPWG_ROOT_PATH.'template/'.$style); } -function build_user( $user_id, $use_cache, $filter_global_mode = false ) +function build_user( $user_id, $use_cache ) { global $conf; - $user['id'] = $user_id; - $user = array_merge( $user, getuserdata($user_id, $use_cache, $filter_global_mode) ); + $user = array_merge( $user, getuserdata($user_id, $use_cache) ); if ( $user['id'] == $conf['guest_id']) { $user['is_the_guest']=true; @@ -167,7 +166,6 @@ function build_user( $user_id, $use_cache, $filter_global_mode = false ) { $user['is_the_guest']=false; } - // calculation of the number of picture to display per page $user['nb_image_page'] = $user['nb_image_line'] * $user['nb_line_page']; @@ -198,7 +196,7 @@ function build_user( $user_id, $use_cache, $filter_global_mode = false ) * @param boolean use_cache * @param array */ -function getuserdata($user_id, $use_cache, $filter_global_mode = false ) +function getuserdata($user_id, $use_cache) { global $conf; @@ -267,21 +265,20 @@ SELECT ui.*, uc.* if ($use_cache) { - $userdata['filter_global_mode'] = $filter_global_mode; - if (!isset($userdata['need_update']) or !is_bool($userdata['need_update']) - or $userdata['need_update'] == true - or $filter_global_mode // not optimize condition RubTag - ) + or $userdata['need_update'] == true) { $userdata['forbidden_categories'] = calculate_permissions($userdata['id'], $userdata['status']); - update_user_cache_categories($userdata); + update_user_cache_categories($userdata['id'], $userdata['forbidden_categories']); // Set need update are done - $userdata['need_update'] = $userdata['filter_global_mode']; // for draft always update RubTag + $userdata['need_update'] = false; + + // Indicate update done + $userdata['need_update_done'] = true; $query = ' SELECT COUNT(DISTINCT(image_id)) as total @@ -306,8 +303,10 @@ INSERT INTO '.USER_CACHE_TABLE.' ;'; pwg_query($query); } - + else { + // Indicate update not done + $userdata['need_update_done'] = false; } } @@ -328,6 +327,8 @@ function check_user_favorites() return; } + // $filter['visible_categories'] and $filter['visible_images'] + // must be not used because filter <> restriction // retrieving images allowed : belonging to at least one authorized // category $query = ' @@ -335,7 +336,14 @@ SELECT DISTINCT f.image_id FROM '.FAVORITES_TABLE.' AS f INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON f.image_id = ic.image_id WHERE f.user_id = '.$user['id'].' - AND ic.category_id NOT IN ('.$user['forbidden_categories'].') +'.get_sql_condition_FandF + ( + array + ( + 'forbidden_categories' => 'ic.category_id', + ), + 'AND' + ).' ;'; $result = pwg_query($query); $authorizeds = array(); @@ -454,7 +462,7 @@ SELECT id } /** - * compute data of categories branches + * compute data of categories branches (one branch only) */ function compute_branch_cat_data(&$cats, &$list_cat_id, &$level, &$ref_level) { @@ -496,60 +504,82 @@ function compute_branch_cat_data(&$cats, &$list_cat_id, &$level, &$ref_level) } /** - * update data of user_cache_categories - * - * @param array userdata - * @return null + * compute data of categories branches */ -function update_user_cache_categories(&$userdata) +function compute_categories_data(&$cats) { - // delete user cache - $query = ' -DELETE FROM '.USER_CACHE_CATEGORIES_TABLE.' - WHERE user_id = '.$userdata['id'].' -;'; - pwg_query($query); + $ref_level = 0; + $level = 0; + $list_cat_id = array(); - /*$query = ' -SELECT id cat_id, date_last max_date_last, nb_images count_images, global_rank - FROM '.CATEGORIES_TABLE; - if ($userdata['forbidden_categories'] != '') + foreach ($cats as $id => $category) { - $query.= ' - WHERE id NOT IN ('.$userdata['forbidden_categories'].')'; + // Compute + $level = substr_count($category['global_rank'], '.') + 1; + if ($level > $ref_level) + { + array_push($list_cat_id, $id); + } + else + { + compute_branch_cat_data($cats, $list_cat_id, $level, $ref_level); + array_push($list_cat_id, $id); + } + $ref_level = $level; } - $query.= ';';*/ + $level = 1; + compute_branch_cat_data($cats, $list_cat_id, $level, $ref_level); +} +/** + * get computed array of categories + * + * @param int user_id + * @param list user_forbidden_categories + * @param bool filter_enabled + * @param int recent_period + * @return array + */ +function get_computed_categories($user_id, $user_forbidden_categories, $filter_enabled, $recent_period = 0) +{ $query = ' -SELECT c.id cat_id, date_last max_date_last, nb_images count_images, global_rank'; +SELECT + c.id cat_id, + date_last max_date_last, + nb_images count_images, + global_rank'; - if (!$userdata['filter_global_mode']) + if (!$filter_enabled) { $query.= ' - FROM '.CATEGORIES_TABLE.' as C'; +FROM '.CATEGORIES_TABLE.' as c'; } else { // Count by date_available to avoid count null - $query.= ', count(date_available) filtered_count_images, max(date_available) max_date_available - FROM '.CATEGORIES_TABLE.' as C - LEFT JOIN '.IMAGE_CATEGORY_TABLE.' AS ic - ON ic.category_id = c.id LEFT JOIN '.IMAGES_TABLE.' AS i - ON ic.image_id = i.id AND i.date_available > SUBDATE( - CURRENT_DATE,INTERVAL '.$userdata['recent_period'].' DAY)'; + $query.= ', + count(date_available) filtered_count_images, + max(date_available) max_date_available +FROM '.CATEGORIES_TABLE.' as c + LEFT JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.category_id = c.id + LEFT JOIN '.IMAGES_TABLE.' AS i + ON ic.image_id = i.id AND + i.date_available > SUBDATE(CURRENT_DATE,INTERVAL '.$recent_period.' DAY)'; } - if ($userdata['forbidden_categories'] != '') + if ($user_forbidden_categories != '') { $query.= ' - WHERE C.id NOT IN ('.$userdata['forbidden_categories'].')'; +WHERE + c.id NOT IN ('.$user_forbidden_categories.')'; } - if ($userdata['filter_global_mode']) + if ($filter_enabled) { $query.= ' - GROUP BY c.id'; +GROUP BY + c.id'; } $query.= ';'; @@ -558,10 +588,11 @@ SELECT c.id cat_id, date_last max_date_last, nb_images count_images, global_rank $cats = array(); while ($row = mysql_fetch_assoc($result)) { - $row['user_id'] = $userdata['id']; + $row['user_id'] = $user_id; $row['count_categories'] = 0; - if ($userdata['filter_global_mode']) + if ($filter_enabled) { + $row['nb_images'] = $row['filtered_count_images']; $row['count_images'] = $row['filtered_count_images']; $row['max_date_last'] = $row['max_date_available']; } @@ -569,50 +600,52 @@ SELECT c.id cat_id, date_last max_date_last, nb_images count_images, global_rank } usort($cats, 'global_rank_compare'); - $ref_level = 0; - $level = 0; - $list_cat_id = array(); - - foreach ($cats as $id => $category) - { - // Compute - $level = substr_count($category['global_rank'], '.') + 1; - if ($level > $ref_level) - { - array_push($list_cat_id, $id); - } - else - { - compute_branch_cat_data($cats, $list_cat_id, $level, $ref_level); - array_push($list_cat_id, $id); - } - $ref_level = $level; - } - - $level = 1; - compute_branch_cat_data($cats, $list_cat_id, $level, $ref_level); + compute_categories_data($cats); - if ($userdata['filter_global_mode']) + if ($filter_enabled) { - $forbidden_cats = array(); - $forbidden_cats = explode(',', $userdata['forbidden_categories']); $cat_tmp = $cats; $cats = array(); - foreach ($cat_tmp as $cat_id => $category) + foreach ($cat_tmp as $category) { - if (empty($category['max_date_last'])) - { - array_push($forbidden_cats, $category['cat_id']); - } - else + if (!empty($category['max_date_last'])) { - array_push($cats, $category); + // Re-init counters + $category['count_categories'] = 0; + $category['nb_images'] = $category['filtered_count_images']; + $category['count_images'] = $category['filtered_count_images']; + // Keep category + $cats[$category['cat_id']] = $category; + } } - $userdata['forbidden_categories'] = implode(',', array_unique($forbidden_cats)); + // Compute a second time + compute_categories_data($cats); } + return $cats; +} + +/** + * update data of user_cache_categories + * + * @param int user_id + * @param list user_forbidden_categories + * @param bool filter_enabled + * @return null + */ +function update_user_cache_categories($user_id, $user_forbidden_categories) +{ + // delete user cache + $query = ' +DELETE FROM '.USER_CACHE_CATEGORIES_TABLE.' + WHERE user_id = '.$user_id.' +;'; + pwg_query($query); + + $cats = get_computed_categories($user_id, $user_forbidden_categories, false); + include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); mass_inserts ( @@ -1014,4 +1047,82 @@ function get_email_address_as_display_text($email_address) } } +/* + * Compute sql where condition with restrict and filter data + * + * FandF: Forbidden and Filters + * + * @param $condition_fields array: + * keys are condition to aply and + * values are sql field to use + * array('forbidden_categories' => 'ic.category_id') + * $prefix_condition string: + * this value are concatenated if sql is not empty + * $force_one_condition: + * if there are not condition , use this condition "1 = 1" + * + * @return string sql where/conditions + */ +function get_sql_condition_FandF($condition_fields, $prefix_condition = null, $force_one_condition = false) +{ + global $user, $filter; + + $sql_list = array(); + + foreach ($condition_fields as $condition => $field_name) + { + switch($condition) + { + case 'forbidden_categories': + if (!empty($user['forbidden_categories'])) + { + $sql_list[] = $field_name.' NOT IN ('.$user['forbidden_categories'].')'; + } + break; + + case 'visible_categories': + if (!empty($filter['visible_categories'])) + { + $sql_list[] = $field_name.' IN ('.$filter['visible_categories'].')'; + } + break; + + case 'visible_images': + if (!empty($filter['visible_images'])) + { + $sql_list[] = $field_name.' IN ('.$filter['visible_images'].')'; + } + break; + + default: + die('Unknow condition'); + break; + + } + } + + if (count($sql_list) > 0) + { + $sql = '('.implode(' AND ', $sql_list).')'; + } + else + { + if ($force_one_condition) + { + $sql = '1 = 1'; + } + else + { + $sql = ''; + } + } + + if (isset($prefix_condition) and !empty($sql)) + { + $sql = $prefix_condition.' '.$sql; + } + + return $sql; +} + ?> diff --git a/include/menubar.inc.php b/include/menubar.inc.php index c149b3553..d5535ca12 100755 --- a/include/menubar.inc.php +++ b/include/menubar.inc.php @@ -63,6 +63,28 @@ foreach ($conf['links'] as $url => $label) ) ); } + +//------------------------------------------------------------------------ filter +if ($filter['enabled']) +{ + $template->assign_block_vars( + 'stop_filter', + array( + 'URL' => add_url_params(make_index_url(array()), array('filter' => 'stop')) + ) + ); +} +else +{ + $template->assign_block_vars( + 'start_filter', + array( + 'URL' => add_url_params(make_index_url(array()), array('filter' => 'start')) + ) + ); +} + + //------------------------------------------------------------------------ tags if ('tags' == $page['section']) { diff --git a/include/page_header.php b/include/page_header.php index a6d4619a3..db7fa3b9a 100644 --- a/include/page_header.php +++ b/include/page_header.php @@ -60,6 +60,18 @@ if (isset($header_infos)) { $template->assign_block_vars( 'header_meta', $header_infos); } + +// Header notes +if (count($header_notes) > 0) +{ + $template->assign_block_vars('header_notes', array()); + foreach ($header_notes as $header_note) + { + $template->assign_block_vars('header_notes.header_note', + array('HEADER_NOTE' => $header_note)); + } +} + // refresh if ( isset( $refresh ) and intval($refresh) >= 0 and isset( $url_link ) and isset( $redirect_msg ) ) diff --git a/include/section_init.inc.php b/include/section_init.inc.php index 416d98849..d5bbce645 100644 --- a/include/section_init.inc.php +++ b/include/section_init.inc.php @@ -267,6 +267,12 @@ while (isset($tokens[$i])) $page['start'] = $matches[1]; } + if (preg_match('/^flat_recent_cat-(\d+)/', $tokens[$i], $matches)) + { + // indicate a special list of images + $page['flat_recent_cat'] = $matches[1]; + } + if (preg_match('/^(posted|created)/', $tokens[$i] )) { $chronology_tokens = explode('-', $tokens[$i] ); @@ -325,59 +331,134 @@ if ('categories' == $page['section']) $page = array_merge( $page, array( - 'comment' => $result['comment'], - 'cat_dir' => $result['dir'], - 'cat_name' => $result['name'], - 'cat_site_id' => $result['site_id'], - 'cat_uploadable' => $result['uploadable'], - 'cat_commentable' => $result['commentable'], - 'cat_id_uppercat' => $result['id_uppercat'], - 'uppercats' => $result['uppercats'], - - 'title' => get_cat_display_name($result['name'], '', false), + 'comment' => $result['comment'], + 'cat_dir' => $result['dir'], + 'cat_name' => $result['name'], + 'cat_site_id' => $result['site_id'], + 'cat_uploadable' => $result['uploadable'], + 'cat_commentable' => $result['commentable'], + 'cat_id_uppercat' => $result['id_uppercat'], + 'uppercats' => $result['uppercats'], + 'title' => + get_cat_display_name($result['name'], '', false), + 'thumbnails_include' => + (($result['nb_images'] > 0) or (isset($page['flat_recent_cat']))) + ? 'include/category_default.inc.php' + : 'include/category_cats.inc.php' ) ); + } + else + { + $page['title'] = $lang['no_category']; + $page['thumbnails_include'] = + (isset($page['flat_recent_cat'])) + ? 'include/category_default.inc.php' + : 'include/category_cats.inc.php'; + } + + if (isset($page['flat_recent_cat'])) + { + $page['title'] = $lang['recent_pics_cat'].' : '.$page['title'] ; + } + + if + ( + (!isset($page['chronology_field'])) and + ( + (isset($page['category'])) or + (isset($page['flat_recent_cat'])) + ) + ) + { + if ( !empty($result['image_order']) and !isset($page['super_order_by']) ) + { + $conf[ 'order_by' ] = ' ORDER BY '.$result['image_order']; + } - if (!isset($page['chronology_field'])) + if (isset($page['flat_recent_cat'])) { - if ( !empty($result['image_order']) and !isset($page['super_order_by']) ) + // flat recent categories mode + $query = ' +SELECT + DISTINCT(ic.image_id) +FROM '.IMAGES_TABLE.' AS i + INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON i.id = ic.image_id + INNER JOIN '.CATEGORIES_TABLE.' AS c ON ic.category_id = c.id +WHERE + date_available > SUBDATE( + CURRENT_DATE,INTERVAL '.$page['flat_recent_cat'].' DAY)'. + (isset($page['category']) ? ' + AND uppercats REGEXP \'(^|,)'.$page['category'].'(,|$)\'' : '' ).' +'.get_sql_condition_FandF + ( + array + ( + 'forbidden_categories' => 'category_id', + 'visible_categories' => 'category_id', + 'visible_images' => 'image_id' + ), + 'AND' + ).' +;'; + + $where_sql = array_from_query($query, 'image_id'); + if (!empty($where_sql)) { - $conf[ 'order_by' ] = ' ORDER BY '.$result['image_order']; + $where_sql = 'image_id in ('.implode(',', $where_sql).')'; } + } + else + { + // Normal mode + $where_sql = 'category_id = '.$page['category']; + } + if (!empty($where_sql)) + { + // Main query $query = ' SELECT image_id FROM '.IMAGE_CATEGORY_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON id = image_id - WHERE category_id = '.$page['category'].' + WHERE + '.$where_sql.' +'.get_sql_condition_FandF + ( + array + ( + 'forbidden_categories' => 'category_id', + 'visible_categories' => 'category_id', + 'visible_images' => 'image_id' + ), + 'AND' + ).' '.$conf['order_by'].' ;'; - $page['items'] = array_from_query($query, 'image_id'); - $page['thumbnails_include'] = - $result['nb_images'] > 0 - ? 'include/category_default.inc.php' - : 'include/category_cats.inc.php'; - } //otherwise the calendar will requery all subitems - } - else - { - $page['title'] = $lang['no_category']; - $page['thumbnails_include'] = 'include/category_cats.inc.php'; - } + $page['items'] = array_from_query($query, 'image_id'); + } + else + { + $page['items'] = array(); + } + } //otherwise the calendar will requery all subitems } // special sections else { - if (!empty($user['forbidden_categories'])) - { - $forbidden = - ' category_id NOT IN ('.$user['forbidden_categories'].')'; - } - else - { - $forbidden = ' 1 = 1'; - } + $forbidden = + get_sql_condition_FandF + ( + array + ( + 'forbidden_categories' => 'category_id', + 'visible_categories' => 'category_id', + 'visible_images' => 'image_id' + ), + 'AND' + ); + // +-----------------------------------------------------------------------+ // | tags section | // +-----------------------------------------------------------------------+ @@ -400,7 +481,7 @@ else SELECT image_id FROM '.IMAGE_CATEGORY_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON image_id=id WHERE image_id IN ('.implode(',', $items).') - AND '.$forbidden. + '.$forbidden. $conf['order_by'].' ;'; $items = array_unique( @@ -434,7 +515,7 @@ SELECT DISTINCT(id) FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id WHERE id IN ('.implode(',', $search_result['items']).') - AND '.$forbidden.' + '.$forbidden.' '.$conf['order_by'].' ;'; $page['items'] = array_from_query($query, 'id'); @@ -464,6 +545,14 @@ SELECT image_id FROM '.FAVORITES_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON image_id = id WHERE user_id = '.$user['id'].' +'.get_sql_condition_FandF + ( + array + ( + 'visible_images' => 'image_id' + ), + 'AND' + ).' '.$conf['order_by'].' ;'; @@ -487,7 +576,7 @@ SELECT DISTINCT(id) INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id WHERE date_available > \''. date('Y-m-d', time() - 60*60*24*$user['recent_period']).'\' - AND '.$forbidden.' + '.$forbidden.' '.$conf['order_by'].' ;'; @@ -526,7 +615,7 @@ SELECT DISTINCT(id) FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id WHERE hit > 0 - AND '.$forbidden.' + '.$forbidden.' '.$conf['order_by'].' LIMIT 0, '.$conf['top_number'].' ;'; @@ -554,7 +643,7 @@ SELECT DISTINCT(id) FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id WHERE average_rate IS NOT NULL - AND '.$forbidden.' + '.$forbidden.' '.$conf['order_by'].' LIMIT 0, '.$conf['top_number'].' ;'; @@ -578,7 +667,7 @@ SELECT DISTINCT(id) FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id WHERE image_id IN ('.implode(',', $page['list']).') - AND '.$forbidden.' + '.$forbidden.' '.$conf['order_by'].' ;'; diff --git a/include/user.inc.php b/include/user.inc.php index 6f75ac962..b67d6e3e4 100644 --- a/include/user.inc.php +++ b/include/user.inc.php @@ -2,7 +2,7 @@ // +-----------------------------------------------------------------------+ // | PhpWebGallery - a PHP based picture gallery | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | -// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | +// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net | // +-----------------------------------------------------------------------+ // | branch : BSF (Best So Far) // | file : $RCSfile$ @@ -70,19 +70,8 @@ if ($conf['apache_authentication'] and isset($_SERVER['REMOTE_USER'])) } } -if (isset($_GET['filter_global_mode'])) -{ - $user['filter_global_mode'] = ($_GET['filter_global_mode'] == 'start'); - pwg_set_session_var('filter_global_mode', $user['filter_global_mode']); -} -else -{ - $user['filter_global_mode'] = pwg_get_session_var('filter_global_mode', false); -} - $user = build_user( $user['id'], - ( defined('IN_ADMIN') and IN_ADMIN ) ? false : true, // use cache ? - $user['filter_global_mode'] // filter_global_mode ? + ( defined('IN_ADMIN') and IN_ADMIN ) ? false : true // use cache ? ); ?>
\ No newline at end of file @@ -106,64 +106,22 @@ if (isset($page['cat_nb_images']) and $page['cat_nb_images'] > 0) $template_title.= ' ['.$page['cat_nb_images'].']'; } -if (isset($_GET['filter_local_mode'])) -{ - $page['filter_local_mode'] = ($_GET['filter_local_mode'] == 'start'); -} -else -{ - $page['filter_local_mode'] = pwg_get_session_var('filter_local_mode', false); -} - -$page['filter_local_mode'] = (($page['filter_local_mode']) and - ($page['section'] == 'categories') and - (!isset($page['chronology_field']))); -pwg_set_session_var('filter_local_mode', $page['filter_local_mode']); - -if ($page['filter_local_mode']) +if (isset($page['flat_recent_cat']) or isset($page['chronology_field'])) { $template->assign_block_vars( - 'stop_filter_local_mode', - array( - 'URL' => add_url_params(duplicate_index_url(array(), array('start')), array('filter_local_mode' => 'stop')) - ) - ); -} -else -{ - $template->assign_block_vars( - 'start_filter_local_mode', + 'mode_normal', array( - 'URL' => add_url_params(duplicate_index_url(array(), array('start')), array('filter_local_mode' => 'start')) + 'URL' => duplicate_index_url( array(), array('chronology_field', 'start', 'flat_recent_cat') ) ) ); } -if (isset($_GET['filter_global_mode'])) -{ - $user['filter_global_mode'] = ($_GET['filter_global_mode'] == 'start'); - pwg_set_session_var('filter_global_mode', $user['filter_global_mode']); -} -else -{ - $user['filter_global_mode'] = pwg_get_session_var('filter_global_mode', false); -} - -if ($user['filter_global_mode']) +if (!isset($page['flat_recent_cat'])) { $template->assign_block_vars( - 'stop_filter_global_mode', + 'flat_recent_cat', array( - 'URL' => add_url_params(duplicate_index_url(array(), array('start')), array('filter_global_mode' => 'stop')) - ) - ); -} -else -{ - $template->assign_block_vars( - 'start_filter_global_mode', - array( - 'URL' => add_url_params(duplicate_index_url(array(), array('start')), array('filter_global_mode' => 'start')) + 'URL' => duplicate_index_url(array('flat_recent_cat' => $user['recent_period']), array('start', 'chronology_field')) ) ); } @@ -179,7 +137,7 @@ if (!isset($page['chronology_field'])) $template->assign_block_vars( 'mode_created', array( - 'URL' => duplicate_index_url( $chronology_params, array('start') ) + 'URL' => duplicate_index_url( $chronology_params, array('start', 'flat_recent_cat') ) ) ); @@ -187,19 +145,12 @@ if (!isset($page['chronology_field'])) $template->assign_block_vars( 'mode_posted', array( - 'URL' => duplicate_index_url( $chronology_params, array('start') ) + 'URL' => duplicate_index_url( $chronology_params, array('start', 'flat_recent_cat') ) ) ); } else { - $template->assign_block_vars( - 'mode_normal', - array( - 'URL' => duplicate_index_url( array(), array('chronology_field','start') ) - ) - ); - if ($page['chronology_field'] == 'created') { $chronology_field = 'posted'; @@ -210,7 +161,7 @@ else } $url = duplicate_index_url( array('chronology_field'=>$chronology_field ), - array('chronology_date', 'start') + array('chronology_date', 'start', 'flat_recent_cat') ); $template->assign_block_vars( 'mode_'.$chronology_field, diff --git a/language/en_UK.iso-8859-1/common.lang.php b/language/en_UK.iso-8859-1/common.lang.php index 636d5a21b..dc16445c1 100644 --- a/language/en_UK.iso-8859-1/common.lang.php +++ b/language/en_UK.iso-8859-1/common.lang.php @@ -2,7 +2,7 @@ // +-----------------------------------------------------------------------+ // | PhpWebGallery - a PHP based picture gallery | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | -// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | +// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net | // +-----------------------------------------------------------------------+ // | branch : BSF (Best So Far) // | file : $RCSfile$ @@ -490,10 +490,9 @@ $lang['maxheight'] = 'Maximum height of the pictures'; $lang['maxheight_error'] = 'Maximum height must be a number superior to 50'; $lang['maxwidth'] = 'Maximum width of the pictures'; $lang['maxwidth_error'] = 'Maximum width must be a number superior to 50'; -$lang['start_filter_local_mode_hint'] = '[local] displays only recent elements'; -$lang['stop_filter_local_mode_hint'] = '[local] return to display all elements'; -$lang['start_filter_global_mode_hint'] = '[global] displays only recent elements'; -$lang['stop_filter_global_mode_hint'] = '[global] return to display all elements'; +$lang['flat_recent_cat_hint'] = 'display recent elements of categories and sub-categories'; +$lang['start_filter_hint'] = 'displays only recent elements'; +$lang['stop_filter_hint'] = 'return to display all elements'; $lang['mode_created_hint'] = 'displays a calendar by creation date'; $lang['mode_normal_hint'] = 'return to normal view mode'; $lang['mode_posted_hint'] = 'displays a calendar by date posted'; @@ -613,4 +612,6 @@ $lang['upload_username'] = 'Username'; $lang['useful when password forgotten'] = 'useful when password forgotten'; $lang['w_month'] = 'Month'; $lang['yes'] = 'Yes'; +$lang['note_filter_day'] = 'The whole of the elements are filtered in order to diplay the recent elements of less %s day.'; +$lang['note_filter_days'] = 'The whole of the elements are filtered in order to diplay the recent elements of less %s days.'; ?> diff --git a/language/fr_FR.iso-8859-1/common.lang.php b/language/fr_FR.iso-8859-1/common.lang.php index 9aa1fee9c..04a4081d9 100644 --- a/language/fr_FR.iso-8859-1/common.lang.php +++ b/language/fr_FR.iso-8859-1/common.lang.php @@ -2,7 +2,7 @@ // +-----------------------------------------------------------------------+ // | PhpWebGallery - a PHP based picture gallery | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | -// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | +// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net | // +-----------------------------------------------------------------------+ // | branch : BSF (Best So Far) // | file : $RCSfile$ @@ -490,10 +490,9 @@ $lang['maxheight'] = 'Hauteur maximum des images'; $lang['maxheight_error'] = 'La hauteur maximum des images doit être supérieure à 50'; $lang['maxwidth'] = 'Largeur maximum des images'; $lang['maxwidth_error'] = 'La largeur des images doit être supérieure à 50'; -$lang['start_filter_local_mode_hint'] = '[local] afficher que les éléments récents'; -$lang['stop_filter_local_mode_hint'] = '[local] retourner à l\'affichage de tous les éléments'; -$lang['start_filter_global_mode_hint'] = '[global] afficher que les éléments récents'; -$lang['stop_filter_global_mode_hint'] = '[global] retourner à l\'affichage de tous les éléments'; +$lang['flat_recent_cat_hint'] = 'affiche les éléments récents des catégories et des sous-catégories'; +$lang['start_filter_hint'] = 'afficher que les éléments récents'; +$lang['stop_filter_hint'] = 'retourner à l\'affichage de tous les éléments'; $lang['mode_created_hint'] = 'afficher un calendrier par date de création'; $lang['mode_normal_hint'] = 'retourner à la vue normale'; $lang['mode_posted_hint'] = 'afficher un calendrier par date d\'ajout'; @@ -614,4 +613,6 @@ $lang['upload_username'] = 'Nom d\'utilisateur'; $lang['useful when password forgotten'] = 'utile en cas d\'oubli de mot de passe'; $lang['w_month'] = 'Mois'; $lang['yes'] = 'Oui'; +$lang['note_filter_day'] = 'L\'ensemble des éléments est filtré pour n\'afficher que les éléments récents de moins de %d jour.'; +$lang['note_filter_days'] = 'L\'ensemble des éléments est filtré pour n\'afficher que les éléments récents de moins de %d jours.'; ?>
\ No newline at end of file diff --git a/picture.php b/picture.php index 4faf57f40..ab660da98 100644 --- a/picture.php +++ b/picture.php @@ -248,7 +248,15 @@ SELECT category_id,uppercats,commentable,global_rank FROM '.IMAGE_CATEGORY_TABLE.' INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id WHERE image_id = '.$page['image_id'].' - AND category_id NOT IN ('.$user['forbidden_categories'].') +'.get_sql_condition_FandF + ( + array + ( + 'forbidden_categories' => 'category_id', + 'visible_categories' => 'category_id' + ), + 'AND' + ).' ;'; $result = pwg_query($query); $related_categories = array(); diff --git a/random.php b/random.php index f3ebdc3dc..f73fa9642 100644 --- a/random.php +++ b/random.php @@ -45,11 +45,16 @@ $query = ' SELECT DISTINCT(id) FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id - '.( - $user['forbidden_categories'] != '' - ? 'WHERE category_id NOT IN ('.$user['forbidden_categories'].')' - : '' - ).' +'.get_sql_condition_FandF + ( + array + ( + 'forbidden_categories' => 'category_id', + 'visible_categories' => 'category_id', + 'visible_images' => 'id' + ), + 'WHERE' + ).' ORDER BY RAND(NOW()) LIMIT 0, '.$conf['top_number'].' ;'; diff --git a/search.php b/search.php index 1a482ec77..4bd64106a 100644 --- a/search.php +++ b/search.php @@ -187,11 +187,7 @@ $template->assign_vars( ) ); -$available_tags = get_available_tags( - isset($user['forbidden_categories']) - ? explode(',', $user['forbidden_categories']) - : null - ); +$available_tags = get_available_tags(); if (count($available_tags) > 0) { @@ -213,13 +209,16 @@ if (count($available_tags) > 0) //------------------------------------------------------------- categories form $query = ' SELECT name,id,date_last,nb_images,global_rank,uppercats - FROM '.CATEGORIES_TABLE; -if ($user['forbidden_categories'] != '') -{ - $query.= ' - WHERE id NOT IN ('.$user['forbidden_categories'].')'; -} -$query.= ' + FROM '.CATEGORIES_TABLE.' +'.get_sql_condition_FandF + ( + array + ( + 'forbidden_categories' => 'id', + 'visible_categories' => 'id' + ), + 'WHERE' + ).' ;'; $selecteds = array(); diff --git a/services/recent.php b/services/recent.php index 59b1ffd4a..808b5a165 100644 --- a/services/recent.php +++ b/services/recent.php @@ -1,7 +1,16 @@ <?php
-$where = ( $user['forbidden_categories'] == '') ? '' :
- 'ic.`category_id` NOT IN ('.$user['forbidden_categories'].')';
+$where =
+ get_sql_condition_FandF
+ (
+ array
+ (
+ 'forbidden_categories' => 'ic.category_id',
+ 'visible_categories' => 'ic.category_id',
+ 'visible_images' => 'i.id'
+ ),
+ ''
+ );
$list = implode(',', $final);
if ( $where !== '' and $list !== '' )
{
@@ -73,7 +73,7 @@ $template->assign_vars( // +-----------------------------------------------------------------------+ // find all tags available for the current user -$tags = get_available_tags(explode(',', $user['forbidden_categories'])); +$tags = get_available_tags(); // we want only the first most represented tags, so we sort them by counter // and take the first tags diff --git a/template/yoga/default-colors.css b/template/yoga/default-colors.css index ee8cdb6e6..cdcacb953 100644 --- a/template/yoga/default-colors.css +++ b/template/yoga/default-colors.css @@ -100,6 +100,20 @@ INPUT.rateButton, INPUT.rateButtonSelected, INPUT.rateButtonStarFull, INPUT.rate padding: 1px; } +/** + * Header notes box in public/administration + */ +.header_notes { + border: 1px solid #aaaaaa; /* border color and style */ + text-align: center; + background-image: url(icon/note.png); + background-repeat: no-repeat; + background-position: top left; + font-weight: bold; + margin: 14px; + padding: 5px 00px 0px 0px; +} + LEGEND { font-style: italic; } diff --git a/template/yoga/header.tpl b/template/yoga/header.tpl index 3e2b43634..5032a3f04 100644 --- a/template/yoga/header.tpl +++ b/template/yoga/header.tpl @@ -72,3 +72,10 @@ the "text/nonsense" prevents gecko based browsers to load it --> </div> <!-- END header_msgs --> <div id="theHeader">{PAGE_BANNER}</div> +<!-- BEGIN header_notes --> +<div class="header_notes"> + <!-- BEGIN header_note --> + <P>{header_notes.header_note.HEADER_NOTE}</p> + <!-- END header_note --> +</div> +<!-- END header_notes --> diff --git a/template/yoga/icon/flat_recent_cat.png b/template/yoga/icon/flat_recent_cat.png Binary files differnew file mode 100644 index 000000000..43584e825 --- /dev/null +++ b/template/yoga/icon/flat_recent_cat.png diff --git a/template/yoga/icon/normal_mode.png b/template/yoga/icon/normal_mode.png Binary files differindex 07318b568..92d27a234 100644 --- a/template/yoga/icon/normal_mode.png +++ b/template/yoga/icon/normal_mode.png diff --git a/template/yoga/icon/note.png b/template/yoga/icon/note.png Binary files differnew file mode 100644 index 000000000..df1e0a926 --- /dev/null +++ b/template/yoga/icon/note.png diff --git a/template/yoga/icon/start_filter_mode.png b/template/yoga/icon/start_filter.png Binary files differindex 3d81a4d2e..3d81a4d2e 100644 --- a/template/yoga/icon/start_filter_mode.png +++ b/template/yoga/icon/start_filter.png diff --git a/template/yoga/icon/stop_filter_mode.png b/template/yoga/icon/stop_filter.png Binary files differindex 1ff012e96..1ff012e96 100644 --- a/template/yoga/icon/stop_filter_mode.png +++ b/template/yoga/icon/stop_filter.png diff --git a/template/yoga/index.tpl b/template/yoga/index.tpl index 95c6e0051..b0c2e43dc 100644 --- a/template/yoga/index.tpl +++ b/template/yoga/index.tpl @@ -27,16 +27,14 @@ <li><a href="{search_rules.URL}" style="border:none;" onclick="popuphelp(this.href); return false;" title="{lang:Search rules}"><img src="{pwg_root}{themeconf:icon_dir}/search_rules.png" class="button" alt="(?)"></a></li> <!-- END search_rules --> - <!-- BEGIN start_filter_local_mode --> - <li><a href="{start_filter_local_mode.URL}" title="{lang:start_filter_local_mode_hint}"><img src="{pwg_root}{themeconf:icon_dir}/start_filter_mode.png" class="button" alt="{lang:start_filter_local_mode_hint}"></a></li> - <!-- END start_filter_local_mode --> - <!-- BEGIN stop_filter_local_mode --> - <li><a href="{stop_filter_local_mode.URL}" title="{lang:stop_filter_local_mode_hint}"><img src="{pwg_root}{themeconf:icon_dir}/stop_filter_mode.png" class="button" alt="{lang:stop_filter_local_mode_hint}"></a></li> - <!-- END stop_filter_local_mode --> - <!-- BEGIN mode_normal --> <li><a href="{mode_normal.URL}" title="{lang:mode_normal_hint}"><img src="{pwg_root}{themeconf:icon_dir}/normal_mode.png" class="button" alt="{lang:mode_normal_hint}"></a></li> <!-- END mode_normal --> + + <!-- BEGIN flat_recent_cat --> + <li><a href="{flat_recent_cat.URL}" title="{lang:flat_recent_cat_hint}"><img src="{pwg_root}{themeconf:icon_dir}/flat_recent_cat.png" class="button" alt="{lang:flat_recent_cat_hint}"></a></li> + <!-- END flat_recent_cat --> + <!-- BEGIN mode_posted --> <li><a href="{mode_posted.URL}" title="{lang:mode_posted_hint}" rel="nofollow"><img src="{pwg_root}{themeconf:icon_dir}/calendar.png" class="button" alt="{lang:mode_posted_hint}"></a></li> <!-- END mode_posted --> diff --git a/template/yoga/menubar.tpl b/template/yoga/menubar.tpl index eafec20a6..317a974d8 100644 --- a/template/yoga/menubar.tpl +++ b/template/yoga/menubar.tpl @@ -13,12 +13,12 @@ </dl> <!-- END links --> <dl id="mbCategories"> - <!-- BEGIN start_filter_global_mode --> - <a href="{start_filter_global_mode.URL}" title="{lang:start_filter_global_mode_hint}"><img src="{pwg_root}{themeconf:icon_dir}/start_filter_mode.png" class="buttonmenu" alt="{lang:start_filter_global_mode_hint}"></a> - <!-- END start_filter_global_mode --> - <!-- BEGIN stop_filter_global_mode --> - <a href="{stop_filter_global_mode.URL}" title="{lang:stop_filter_global_mode_hint}"><img src="{pwg_root}{themeconf:icon_dir}/stop_filter_mode.png" class="buttonmenu" alt="{lang:stop_filter_global_mode_hint}"></a> - <!-- END stop_filter_global_mode --> + <!-- BEGIN start_filter --> + <a href="{start_filter.URL}" title="{lang:start_filter_hint}"><img src="{pwg_root}{themeconf:icon_dir}/start_filter.png" class="buttonmenu" alt="{lang:start_filter_hint}"></a> + <!-- END start_filter --> + <!-- BEGIN stop_filter --> + <a href="{stop_filter.URL}" title="{lang:stop_filter_hint}"><img src="{pwg_root}{themeconf:icon_dir}/stop_filter.png" class="buttonmenu" alt="{lang:stop_filter_hint}"></a> + <!-- END stop_filter --> <dt><a href="{U_HOME}">{lang:Categories}</a></dt> <dd> {MENU_CATEGORIES_CONTENT} diff --git a/template/yoga/theme/clear/theme.css b/template/yoga/theme/clear/theme.css index d49ec0322..3a60fa8a5 100644 --- a/template/yoga/theme/clear/theme.css +++ b/template/yoga/theme/clear/theme.css @@ -15,7 +15,7 @@ H2, #menubar DT, #imageHeaderBar, #imageToolBar A:hover, .row1 { background-color: #d3d3d3; } -#menubar DL, #content, #imageToolBar { +#menubar DL, #content, #imageToolBar, .header_notes { background-color: #eeeeee; } diff --git a/template/yoga/theme/dark/theme.css b/template/yoga/theme/dark/theme.css index 7165bf6c3..5ca520099 100644 --- a/template/yoga/theme/dark/theme.css +++ b/template/yoga/theme/dark/theme.css @@ -26,7 +26,7 @@ H3, #the_page, #imageHeaderBar, #imageToolBar A:hover, .row1 { background-color: #3f3f3f; } -#menubar DL, #content, #imageToolBar { +#menubar DL, #content, #imageToolBar, .header_notes { background-color: #5f5f5f; } diff --git a/web_service.php b/web_service.php index 72cc345d4..f4568e2a1 100644 --- a/web_service.php +++ b/web_service.php @@ -170,7 +170,17 @@ $ret_ids = array(); $query = '
SELECT DISTINCT image_id
FROM '.IMAGE_CATEGORY_TABLE.'
-WHERE category_id NOT IN ('.$user['forbidden_categories'].')
+WHERE
+'.get_sql_condition_FandF
+ (
+ array
+ (
+ 'forbidden_categories' => 'category_id',
+ 'visible_categories' => 'category_id',
+ 'visible_images' => 'image_id'
+ ),
+ '', true
+ ).'
AND image_id IN ('.$list.')
;';
$result = pwg_query($query);
@@ -389,7 +399,16 @@ $query=' AND i.`height` > 0
AND i.`representative_ext` IS NULL
'.$cat_criterion.'
- AND c.`id` NOT IN ('.$user['forbidden_categories'].') ';
+ '.get_sql_condition_FandF
+ (
+ array
+ (
+ 'forbidden_categories' => 'c.id',
+ 'visible_categories' => 'c.id',
+ 'visible_images' => 'i.id'
+ ),
+ 'AND'
+ );
// AND c.`agreed_ws` = \'true\' (Obsolete specification replaced by force)
|