mirror of
https://github.com/Piwigo/Piwigo.git
synced 2025-04-27 19:59:56 +03:00
* First implementation of the new multi-criteria search. It replaces the old search.php form. * Displays live search criteria above search results. Each change reloads the list of results (displayed as thumbnails). * New API method pwg.images.filteredSearch.update called in AJAX to live change the filters. * New kind of filter: added_by
This commit is contained in:
parent
ebcdb34305
commit
60363ecd42
10 changed files with 1468 additions and 246 deletions
|
@ -688,6 +688,170 @@ SELECT *
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* API method
|
||||
* Returns a list of elements corresponding to a query search
|
||||
* @param mixed[] $params
|
||||
* @option string query
|
||||
* @option int per_page
|
||||
* @option int page
|
||||
* @option string order (optional)
|
||||
*/
|
||||
function ws_images_filteredSearch_update($params, $service)
|
||||
{
|
||||
// echo json_encode($params); exit();
|
||||
|
||||
// * check the search exists
|
||||
$query = '
|
||||
SELECT id
|
||||
FROM '.SEARCH_TABLE.'
|
||||
WHERE id = '.$params['search_id'].'
|
||||
;';
|
||||
|
||||
if (count(query2array($query)) == 0)
|
||||
{
|
||||
return new PwgError(WS_ERR_INVALID_PARAM, 'This search does not exist.');
|
||||
}
|
||||
|
||||
$search = array('mode' => 'AND');
|
||||
|
||||
// TODO we should check that this search is updated by the user who created the search.
|
||||
|
||||
// * check all parameters
|
||||
if (isset($params['allwords']))
|
||||
{
|
||||
$search['fields']['allwords'] = array();
|
||||
|
||||
if (!isset($params['allwords_mode']))
|
||||
{
|
||||
$params['allwords_mode'] = 'AND';
|
||||
}
|
||||
if (!preg_match('/^(OR|AND)$/', $params['allwords_mode']))
|
||||
{
|
||||
return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid parameter allwords_mode');
|
||||
}
|
||||
$search['fields']['allwords']['mode'] = $params['allwords_mode'];
|
||||
|
||||
$allwords_fields_available = array('name', 'comment', 'file', 'tags', 'cat-title', 'cat-desc');
|
||||
if (!isset($params['allwords_fields']))
|
||||
{
|
||||
$params['allwords_fields'] = $allwords_fields_available;
|
||||
}
|
||||
foreach ($params['allwords_fields'] as $field)
|
||||
{
|
||||
if (!in_array($field, $allwords_fields_available))
|
||||
{
|
||||
return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid parameter allwords_fields');
|
||||
}
|
||||
}
|
||||
$search['fields']['allwords']['fields'] = $params['allwords_fields'];
|
||||
|
||||
$search['fields']['allwords']['words'] = null;
|
||||
if (!preg_match('/^\s*$/', $params['allwords']))
|
||||
{
|
||||
$drop_char_match = array(
|
||||
'-','^','$',';','#','&','(',')','<','>','`','\'','"','|',',','@','_',
|
||||
'?','%','~','.','[',']','{','}',':','\\','/','=','\'','!','*'
|
||||
);
|
||||
$drop_char_replace = array(
|
||||
' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','','',' ',' ',' ',' ','',' ',
|
||||
' ',' ',' ',' ',' ',' ',' ',' ','' ,' ',' ',' ',' ',' '
|
||||
);
|
||||
|
||||
// Split words
|
||||
$search['fields']['allwords']['words'] = array_unique(
|
||||
preg_split(
|
||||
'/\s+/',
|
||||
str_replace(
|
||||
$drop_char_match,
|
||||
$drop_char_replace,
|
||||
$params['allwords']
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($params['tags']))
|
||||
{
|
||||
foreach ($params['tags'] as $tag_id)
|
||||
{
|
||||
if (!preg_match('/^\d+$/', $tag_id))
|
||||
{
|
||||
return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid parameter tags');
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($params['tags_mode']))
|
||||
{
|
||||
$params['tags_mode'] = 'AND';
|
||||
}
|
||||
if (!preg_match('/^(OR|AND)$/', $params['tags_mode']))
|
||||
{
|
||||
return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid parameter tags_mode');
|
||||
}
|
||||
|
||||
$search['fields']['tags'] = array(
|
||||
'words' => $params['tags'],
|
||||
'mode' => $params['tags_mode'],
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($params['categories']))
|
||||
{
|
||||
foreach ($params['categories'] as $cat_id)
|
||||
{
|
||||
if (!preg_match('/^\d+$/', $cat_id))
|
||||
{
|
||||
return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid parameter categories');
|
||||
}
|
||||
}
|
||||
|
||||
$search['fields']['cat'] = array(
|
||||
'words' => $params['categories'],
|
||||
'sub_inc' => $params['categories_withsubs'] ?? false,
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($params['authors']))
|
||||
{
|
||||
$authors = array();
|
||||
|
||||
foreach ($params['authors'] as $author)
|
||||
{
|
||||
$authors[] = strip_tags($author);
|
||||
}
|
||||
|
||||
$search['fields']['author'] = array(
|
||||
'words' => $authors,
|
||||
'mode' => 'OR',
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($params['added_by']))
|
||||
{
|
||||
foreach ($params['added_by'] as $user_id)
|
||||
{
|
||||
if (!preg_match('/^\d+$/', $user_id))
|
||||
{
|
||||
return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid parameter added_by');
|
||||
}
|
||||
}
|
||||
|
||||
$search['fields']['added_by'] = $params['added_by'];
|
||||
}
|
||||
|
||||
// register search rules in database, then they will be available on
|
||||
// thumbnails page and picture page.
|
||||
$query ='
|
||||
UPDATE '.SEARCH_TABLE.'
|
||||
SET rules = \''.pwg_db_real_escape_string(serialize($search)).'\'
|
||||
, last_seen = NOW()
|
||||
WHERE id = '.$params['search_id'].'
|
||||
;';
|
||||
pwg_query($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* API method
|
||||
* Sets the level of an image
|
||||
|
|
|
@ -1068,4 +1068,43 @@ SELECT
|
|||
'summary' => $search_summary
|
||||
);
|
||||
}
|
||||
|
||||
function ws_gallery_getSearch($param, &$service)
|
||||
{
|
||||
// return $param;
|
||||
if (is_null($param['search_id']))
|
||||
{
|
||||
// Créer une recherche
|
||||
return new PwgError(404, 'Search id is null');
|
||||
}
|
||||
include_once(PHPWG_ROOT_PATH.'include/functions_search.inc.php');
|
||||
|
||||
if (get_search_array($param['search_id']) == false)
|
||||
{
|
||||
return new PwgError(1404, 'Search associated to id '.$param['search_id'].' not found');
|
||||
}
|
||||
|
||||
return get_search_array($param['search_id']);
|
||||
}
|
||||
|
||||
function ws_gallery_updateSearch($param, &$service)
|
||||
{
|
||||
// return $param;
|
||||
if (is_null($param['search_id']))
|
||||
{
|
||||
// Créer une recherche
|
||||
return new PwgError(404, 'Search id is null');
|
||||
}
|
||||
include_once(PHPWG_ROOT_PATH.'include/functions_search.inc.php');
|
||||
|
||||
if (get_search_array($param['search_id']) == false)
|
||||
{
|
||||
return new PwgError(404, 'Search associated to id '.$param['search_id'].' not found');
|
||||
}
|
||||
|
||||
$tmp = get_search_array($param['search_id']);
|
||||
|
||||
// return 'search #'.$param['search_id'].' updated';
|
||||
return $param;
|
||||
}
|
||||
?>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue