From 87c4fad23e2e6e8756478155a08c1089cb22db02 Mon Sep 17 00:00:00 2001 From: plegall Date: Mon, 24 Jul 2023 16:49:53 +0200 Subject: [PATCH] issue #1946 implement backend for search by date_posted --- include/functions_search.inc.php | 11 +++++++++++ include/ws_functions/pwg.images.php | 10 ++++++++++ ws.php | 4 ++++ 3 files changed, 25 insertions(+) diff --git a/include/functions_search.inc.php b/include/functions_search.inc.php index 0abd527b2..4f816e515 100644 --- a/include/functions_search.inc.php +++ b/include/functions_search.inc.php @@ -195,6 +195,17 @@ SELECT } } + if (!empty($search['fields']['date_posted'])) + { + $options = array( + '7d' => '7 DAY', + '30d' => '30 DAY', + '6m' => '6 MONTH', + '1y' => '1 YEAR', + ); + $clauses[] = 'date_available > SUBDATE(NOW(), INTERVAL '.$options[ $search['fields']['date_posted'] ].')'; + } + if (!empty($search['fields']['filetypes'])) { $filetypes_clauses = array(); diff --git a/include/ws_functions/pwg.images.php b/include/ws_functions/pwg.images.php index 30e76095b..5323ff371 100644 --- a/include/ws_functions/pwg.images.php +++ b/include/ws_functions/pwg.images.php @@ -832,6 +832,16 @@ SELECT id $search['fields']['added_by'] = $params['added_by']; } + if (isset($params['date_posted'])) + { + if (!preg_match('/^(7d|30d|6m|1y)$/', $params['date_posted'])) + { + return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid parameter date_posted'); + } + + $search['fields']['date_posted'] = $params['date_posted']; + } + // register search rules in database, then they will be available on // thumbnails page and picture page. $query =' diff --git a/ws.php b/ws.php index 7563269df..39379db77 100644 --- a/ws.php +++ b/ws.php @@ -1413,6 +1413,10 @@ enabled_high, registration_date, registration_date_string, registration_date_sin 'filetypes' => array( 'flags' => WS_PARAM_OPTIONAL|WS_PARAM_FORCE_ARRAY, ), + 'date_posted' => array( + 'flags' => WS_PARAM_OPTIONAL, + 'info' => 'files posted within 7 days (7d) or 30 days (30d) or 6 months (6m) or 1 year (1y). Value among 7d|30d|6m|1y', + ), ), '', $ws_functions_root . 'pwg.images.php'