Skip to content

Commit

Permalink
There are no filter enabled if filter configuration is empty (no icon…
Browse files Browse the repository at this point in the history
…, no functions, ...)

New system for the filter page configuration 

View mode flat_recent_cat becomes flat_cat (recent period is removed because global filter is sufficient)

Recent period of global filter must be defined "after" start parameter (default value is $user['recent_period']).


git-svn-id: http://piwigo.org/svn/trunk@1722 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
rub committed Jan 15, 2007
1 parent 3cef1e6 commit 9362801
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 64 deletions.
5 changes: 4 additions & 1 deletion include/category_cats.inc.php
Expand Up @@ -174,7 +174,10 @@
if (count($categories) > 0)
{
// Update filtered data
update_cats_with_filtered_data($categories);
if (function_exists('update_cats_with_filtered_data'))
{
update_cats_with_filtered_data($categories);
}

if ($conf['subcatify'])
{
Expand Down
8 changes: 7 additions & 1 deletion include/common.inc.php
Expand Up @@ -231,11 +231,17 @@
}
}

if (!defined('IN_ADMIN') or !IN_ADMIN)
if (!empty($conf['filter_pages']) and get_filter_page_value('used'))
{
include(PHPWG_ROOT_PATH.'include/functions_filter.inc.php');
include(PHPWG_ROOT_PATH.'include/filter.inc.php');
}
else
{
// global variable for filter
$filter = array();
$filter['enabled'] = false;
}

if (isset($conf['header_notes']))
{
Expand Down
39 changes: 32 additions & 7 deletions include/config_default.inc.php
Expand Up @@ -568,15 +568,40 @@
// +-----------------------------------------------------------------------+
// | Filter |
// +-----------------------------------------------------------------------+
// Pages where filter is enabled
// Other pages cancel current filter
// Array of basename without file extention
// $conf['filter_pages'] contains configuration for each pages
// o If values are not defined for a specific page, default value are used
// o Array is composed by the basename of each page without extention
// o List of value names:
// - used: filter function are used
// (if false nothing is done [start, cancel, stop, ...]
// - cancel: cancel current started filter
// - add_notes: add notes about current started filter on the header
// o Empty configuration in order to disable completely filter functions
// No filter, No icon,...
// $conf['filter_pages'] = array();
$conf['filter_pages'] = array
(
'about', 'action', 'admin', 'comments',
'index', 'picture', 'popuphelp', 'profile',
'qsearch', 'random', 'register', 'search',
'search_rules', 'tags', 'upload'
// Default page
'default' => array(
'used' => true, 'cancel' => false, 'add_notes' => false),
// Real pages
'index' => array('add_notes' => true),
'tags' => array('add_notes' => true),
'search' => array('add_notes' => true),
'comments' => array('add_notes' => true),
'admin' => array('used' => false),
'feed' => array('used' => false),
'notification' => array('used' => false),
'nbm' => array('used' => false),
'popuphelp' => array('used' => false),
'profile' => array('used' => false),
'web_service' => array('used' => false),
'ws' => array('used' => false),
'identification' => array('cancel' => true),
'install' => array('cancel' => true),
'password' => array('cancel' => true),
'register' => array('cancel' => true),
'upgrade_feed' => array('cancel' => true),
);

?>
31 changes: 25 additions & 6 deletions include/filter.inc.php
Expand Up @@ -28,15 +28,20 @@
$filter = array();

// $filter['enabled']: Filter is enabled
// $filter['check_key']: Check key to valitade computed filter data
// $filter['recent_period']: Recent period used to computed filter data
// $filter['categories']: Computed data of filtered categories
// $filter['visible_categories']: List of visible categories (count(visible) < count(forbidden) more often)
// $filter['visible_categories']:
// List of visible categories (count(visible) < count(forbidden) more often)
// $filter['visible_images']: List of visible images

if (in_array(script_basename(), $conf['filter_pages']))
if (!get_filter_page_value('cancel'))
{
if (isset($_GET['filter']))
{
$filter['enabled'] = ($_GET['filter'] == 'start');
$filter['matches'] = array();
$filter['enabled'] =
preg_match('/^start-(\d+)/', $_GET['filter'], $filter['matches']) === 1;
}
else
{
Expand All @@ -50,6 +55,15 @@

if ($filter['enabled'])
{
if (isset($filter['matches']))
{
$filter['recent_period'] = $filter['matches'][1];
}
else
{
$filter['recent_period'] = pwg_get_session_var('filter_recent_period', $user['recent_period']);
}

if (
// New filter
!pwg_get_session_var('filter_enabled', false) or
Expand All @@ -61,7 +75,7 @@
{
// 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['categories'] = get_computed_categories($user['id'], $user['forbidden_categories'], true, $filter['recent_period']);

$filter['visible_categories'] = implode(',', array_keys($filter['categories']));
if (empty($filter['visible_categories']))
Expand All @@ -83,7 +97,7 @@
}
$query.= '
date_available > SUBDATE(
CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY)';
CURRENT_DATE,INTERVAL '.$filter['recent_period'].' DAY)';

$filter['visible_images'] = implode(',', array_from_query($query, 'image_id'));

Expand All @@ -96,6 +110,7 @@
// Save filter data on session
pwg_set_session_var('filter_enabled', $filter['enabled']);
pwg_set_session_var('filter_check_key', $filter['check_key']);
pwg_set_session_var('filter_recent_period', $filter['recent_period']);
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']);
Expand All @@ -110,14 +125,18 @@
$filter['visible_images'] = pwg_get_session_var('filter_visible_images', '');
}

$header_notes[] = l10n_dec('note_filter_day', 'note_filter_days', $user['recent_period']);
if (get_filter_page_value('add_notes'))
{
$header_notes[] = l10n_dec('note_filter_day', 'note_filter_days', $filter['recent_period']);
}
}
else
{
if (pwg_get_session_var('filter_enabled', false))
{
pwg_unset_session_var('filter_enabled');
pwg_unset_session_var('filter_check_key');
pwg_unset_session_var('filter_recent_period');
pwg_unset_session_var('filter_categories');
pwg_unset_session_var('filter_visible_categories');
pwg_unset_session_var('filter_visible_images');
Expand Down
28 changes: 28 additions & 0 deletions include/functions.inc.php
Expand Up @@ -1104,4 +1104,32 @@ function script_basename()
return basename(strtolower($file_name), '.php');
}

/**
* Return value for the current page define on $conf['filter_pages']
* Îf value is not defined, default value are returned
*
* @param value name
*
* @return filter page value
*/
function get_filter_page_value($value_name)
{
global $conf;

$page_name = script_basename();

if (isset($conf['filter_pages'][$page_name][$value_name]))
{
return $conf['filter_pages'][$page_name][$value_name];
}
else if (isset($conf['filter_pages']['default'][$value_name]))
{
return $conf['filter_pages']['default'][$value_name];
}
else
{
return null;
}
}

?>
5 changes: 4 additions & 1 deletion include/functions_category.inc.php
Expand Up @@ -107,7 +107,10 @@ function get_categories_menu()
usort($cats, 'global_rank_compare');

// Update filtered data
update_cats_with_filtered_data($cats);
if (function_exists('update_cats_with_filtered_data'))
{
update_cats_with_filtered_data($cats);
}

return get_html_menu_category($cats);
}
Expand Down
6 changes: 3 additions & 3 deletions include/functions_filter.inc.php
Expand Up @@ -34,9 +34,9 @@
*/
function get_filter_check_key()
{
global $user;
return $user['id'].$user['recent_period'].date('Ymd');
global $user, $filter;

return $user['id'].$filter['recent_period'].date('Ymd');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions include/functions_url.inc.php
Expand Up @@ -264,9 +264,9 @@ function add_well_known_params_in_url($url, $params)
}
}

if (isset($params['flat_recent_cat']) and $params['flat_recent_cat'] > 0)
if (isset($params['flat_cat']))
{
$url.= '/flat_recent_cat-'.$params['flat_recent_cat'];
$url.= '/flat_cat';
}

if (isset($params['start']) and $params['start'] > 0)
Expand Down
36 changes: 19 additions & 17 deletions include/menubar.inc.php
Expand Up @@ -65,26 +65,28 @@
}

//------------------------------------------------------------------------ filter
if ($filter['enabled'])
if (!empty($conf['filter_pages']) and get_filter_page_value('used'))
{
$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'))
)
);
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-'.$user['recent_period']))
)
);
}
}


//------------------------------------------------------------------------ tags
if ('tags' == $page['section'])
{
Expand Down
24 changes: 11 additions & 13 deletions include/section_init.inc.php
Expand Up @@ -278,11 +278,11 @@
$page['start'] = $matches[1];
}

if ('categories'==$page['section'] and
preg_match('/^flat_recent_cat-(\d+)/', $tokens[$i], $matches))
if ('categories' == $page['section'] and
'flat_cat' == $tokens[$i])
{
// indicate a special list of images
$page['flat_recent_cat'] = $matches[1];
$page['flat_cat'] = true;
}

if (preg_match('/^(posted|created)/', $tokens[$i] ))
Expand Down Expand Up @@ -364,7 +364,7 @@
'title' =>
get_cat_display_name($result['name'], '', false),
'thumbnails_include' =>
(($result['nb_images'] > 0) or (isset($page['flat_recent_cat'])))
(($result['nb_images'] > 0) or (isset($page['flat_cat'])))
? 'include/category_default.inc.php'
: 'include/category_cats.inc.php'
)
Expand All @@ -374,12 +374,12 @@
{
$page['title'] = $lang['no_category'];
$page['thumbnails_include'] =
(isset($page['flat_recent_cat']))
(isset($page['flat_cat']))
? 'include/category_default.inc.php'
: 'include/category_cats.inc.php';
}

if (isset($page['flat_recent_cat']))
if (isset($page['flat_cat']))
{
$page['title'] = $lang['recent_pics_cat'].' : '.$page['title'] ;
}
Expand All @@ -389,7 +389,7 @@
(!isset($page['chronology_field'])) and
(
(isset($page['category'])) or
(isset($page['flat_recent_cat']))
(isset($page['flat_cat']))
)
)
{
Expand All @@ -398,7 +398,7 @@
$conf[ 'order_by' ] = ' ORDER BY '.$result['image_order'];
}

if (isset($page['flat_recent_cat']))
if (isset($page['flat_cat']))
{
// flat recent categories mode
$query = '
Expand All @@ -408,10 +408,8 @@
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'].'(,|$)\'' : '' ).'
'.(isset($page['category']) ? '
uppercats REGEXP \'(^|,)'.$page['category'].'(,|$)\'' : '1=1' ).'
'.$forbidden.'
;';

Expand Down Expand Up @@ -712,7 +710,7 @@

// add meta robots noindex, nofollow to avoid unnecesary robot crawls
$page['meta_robots']=array();
if ( isset($page['chronology_field']) or isset($page['flat_recent_cat'])
if ( isset($page['chronology_field']) or isset($page['flat_cat'])
or 'list'==$page['section'] or 'recent_pics'==$page['section'] )
{
$page['meta_robots']=array('noindex'=>1, 'nofollow'=>1);
Expand Down

0 comments on commit 9362801

Please sign in to comment.