From 2d46924bf6a041bea5980d25513b5d9253aee957 Mon Sep 17 00:00:00 2001 From: plegall Date: Mon, 10 Jul 2023 15:17:46 +0200 Subject: [PATCH] issue #1941 search, implement filter by file type --- include/functions_search.inc.php | 10 ++++++++++ include/ws_functions/pwg.images.php | 13 +++++++++++++ ws.php | 3 +++ 3 files changed, 26 insertions(+) diff --git a/include/functions_search.inc.php b/include/functions_search.inc.php index a86429be3..0abd527b2 100644 --- a/include/functions_search.inc.php +++ b/include/functions_search.inc.php @@ -195,6 +195,16 @@ SELECT } } + if (!empty($search['fields']['filetypes'])) + { + $filetypes_clauses = array(); + foreach ($search['fields']['filetypes'] as $ext) + { + $filetypes_clauses[] = 'path LIKE \'%.'.$ext.'\''; + } + $clauses[] = implode(' OR ', $filetypes_clauses); + } + if (!empty($search['fields']['added_by'])) { $clauses[] = 'added_by IN ('.implode(',', $search['fields']['added_by']).')'; diff --git a/include/ws_functions/pwg.images.php b/include/ws_functions/pwg.images.php index 5b9e5b086..30e76095b 100644 --- a/include/ws_functions/pwg.images.php +++ b/include/ws_functions/pwg.images.php @@ -806,6 +806,19 @@ SELECT id ); } + if (isset($params['filetypes'])) + { + foreach ($params['filetypes'] as $ext) + { + if (!preg_match('/^[a-z0-9]+$/i', $ext)) + { + return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid parameter filetypes'); + } + } + + $search['fields']['filetypes'] = $params['filetypes']; + } + if (isset($params['added_by'])) { foreach ($params['added_by'] as $user_id) diff --git a/ws.php b/ws.php index e3c2116cb..7563269df 100644 --- a/ws.php +++ b/ws.php @@ -1410,6 +1410,9 @@ enabled_high, registration_date, registration_date_string, registration_date_sin 'flags' => WS_PARAM_OPTIONAL|WS_PARAM_FORCE_ARRAY, 'type' => WS_TYPE_ID, ), + 'filetypes' => array( + 'flags' => WS_PARAM_OPTIONAL|WS_PARAM_FORCE_ARRAY, + ), ), '', $ws_functions_root . 'pwg.images.php'