mirror of
https://github.com/Piwigo/Piwigo.git
synced 2025-04-27 11:49:56 +03:00
fixes #2096 keep list of search filters in memory
This commit is contained in:
parent
411ae43c19
commit
e59b5282d5
2 changed files with 64 additions and 26 deletions
|
@ -1767,6 +1767,11 @@ function save_search($rules, $forked_from=null)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!is_a_guest() and !is_generic())
|
||||||
|
{
|
||||||
|
userprefs_update_param('gallery_search_filters', array_keys($rules['fields'] ?? array()));
|
||||||
|
}
|
||||||
|
|
||||||
$url = make_index_url(
|
$url = make_index_url(
|
||||||
array(
|
array(
|
||||||
'section' => 'search',
|
'section' => 'search',
|
||||||
|
|
85
search.php
85
search.php
|
@ -22,12 +22,38 @@ trigger_notify('loc_begin_search');
|
||||||
// | Create a default search |
|
// | Create a default search |
|
||||||
// +-----------------------------------------------------------------------+
|
// +-----------------------------------------------------------------------+
|
||||||
|
|
||||||
|
$search = array(
|
||||||
|
'mode' => 'AND',
|
||||||
|
'fields' => array()
|
||||||
|
);
|
||||||
|
|
||||||
|
// list of filters in user preferences
|
||||||
|
// allwords, cat, tags, author, added_by, filetypes, date_posted
|
||||||
|
$default_fields = array('allwords', 'cat', 'tags', 'author');
|
||||||
|
if (is_a_guest() or is_generic())
|
||||||
|
{
|
||||||
|
$fields = $default_fields;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$fields = userprefs_get_param('gallery_search_filters', $default_fields);
|
||||||
|
}
|
||||||
|
|
||||||
$words = array();
|
$words = array();
|
||||||
if (!empty($_GET['q']))
|
if (!empty($_GET['q']))
|
||||||
{
|
{
|
||||||
$words = split_allwords($_GET['q']);
|
$words = split_allwords($_GET['q']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (count($words) > 0 or in_array('allwords', $fields))
|
||||||
|
{
|
||||||
|
$search['fields']['allwords'] = array(
|
||||||
|
'words' => $words,
|
||||||
|
'mode' => 'AND',
|
||||||
|
'fields' => array('file', 'name', 'comment', 'tags', 'author', 'cat-title', 'cat-desc'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$cat_ids = array();
|
$cat_ids = array();
|
||||||
if (isset($_GET['cat_id']))
|
if (isset($_GET['cat_id']))
|
||||||
{
|
{
|
||||||
|
@ -35,20 +61,13 @@ if (isset($_GET['cat_id']))
|
||||||
$cat_ids = array($_GET['cat_id']);
|
$cat_ids = array($_GET['cat_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$search = array(
|
if (count($cat_ids) > 0 or in_array('cat', $fields))
|
||||||
'mode' => 'AND',
|
{
|
||||||
'fields' => array(
|
$search['fields']['cat'] = array(
|
||||||
'allwords' => array(
|
'words' => $cat_ids,
|
||||||
'words' => $words,
|
'sub_inc' => true,
|
||||||
'mode' => 'AND',
|
);
|
||||||
'fields' => array('file', 'name', 'comment', 'tags', 'author', 'cat-title', 'cat-desc'),
|
}
|
||||||
),
|
|
||||||
'cat' => array(
|
|
||||||
'words' => $cat_ids,
|
|
||||||
'sub_inc' => true,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (count(get_available_tags()) > 0)
|
if (count(get_available_tags()) > 0)
|
||||||
{
|
{
|
||||||
|
@ -59,14 +78,19 @@ if (count(get_available_tags()) > 0)
|
||||||
$tag_ids = explode(',', $_GET['tag_id']);
|
$tag_ids = explode(',', $_GET['tag_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$search['fields']['tags'] = array(
|
if (count($tag_ids) > 0 or in_array('tags', $fields))
|
||||||
'words' => $tag_ids,
|
{
|
||||||
'mode' => 'AND',
|
$search['fields']['tags'] = array(
|
||||||
);
|
'words' => $tag_ids,
|
||||||
|
'mode' => 'AND',
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// does this Piwigo has authors for current user?
|
if (in_array('author', $fields))
|
||||||
$query = '
|
{
|
||||||
|
// does this Piwigo has authors for current user?
|
||||||
|
$query = '
|
||||||
SELECT
|
SELECT
|
||||||
id
|
id
|
||||||
FROM '.IMAGES_TABLE.' AS i
|
FROM '.IMAGES_TABLE.' AS i
|
||||||
|
@ -82,14 +106,23 @@ SELECT
|
||||||
AND author IS NOT NULL
|
AND author IS NOT NULL
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
;';
|
;';
|
||||||
$first_author = query2array($query);
|
$first_author = query2array($query);
|
||||||
|
|
||||||
if (count($first_author) > 0)
|
if (count($first_author) > 0)
|
||||||
|
{
|
||||||
|
$search['fields']['author'] = array(
|
||||||
|
'words' => array(),
|
||||||
|
'mode' => 'OR',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (array('added_by', 'filetypes', 'date_posted') as $field)
|
||||||
{
|
{
|
||||||
$search['fields']['author'] = array(
|
if (in_array($field, $fields))
|
||||||
'words' => array(),
|
{
|
||||||
'mode' => 'OR',
|
$search['fields'][$field] = array();
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
list($search_uuid, $search_url) = save_search($search);
|
list($search_uuid, $search_url) = save_search($search);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue