diff --git a/include/functions_search.inc.php b/include/functions_search.inc.php index 7e8ec5960..5718d6c65 100644 --- a/include/functions_search.inc.php +++ b/include/functions_search.inc.php @@ -268,12 +268,23 @@ SELECT if (!empty($search['fields']['date_posted'])) { $options = array( + '24h' => '24 HOUR', '7d' => '7 DAY', '30d' => '30 DAY', + '3m' => '3 MONTH', '6m' => '6 MONTH', '1y' => '1 YEAR', ); - $clauses[] = 'date_available > SUBDATE(NOW(), INTERVAL '.$options[ $search['fields']['date_posted'] ].')'; + + if (isset($options[ $search['fields']['date_posted'] ])) + { + $clauses[] = 'date_available > SUBDATE(NOW(), INTERVAL '.$options[ $search['fields']['date_posted'] ].')'; + } + elseif (preg_match('/^y(\d+)$/', $search['fields']['date_posted'], $matches)) + { + // that is for y2023 = all photos posted in 2022 + $clauses[] = 'YEAR(date_available) = '.$matches[1]; + } } if (!empty($search['fields']['filetypes'])) diff --git a/include/ws_functions/pwg.images.php b/include/ws_functions/pwg.images.php index cac9d82f8..c90764196 100644 --- a/include/ws_functions/pwg.images.php +++ b/include/ws_functions/pwg.images.php @@ -838,7 +838,7 @@ function ws_images_filteredSearch_update($params, $service) if (isset($params['date_posted'])) { - if (!preg_match('/^(7d|30d|6m|1y|)$/', $params['date_posted'])) + if (!preg_match('/^(24h|7d|30d|3m|6m|y\d+|)$/', $params['date_posted'])) { return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid parameter date_posted'); } diff --git a/index.php b/index.php index ce131886f..4371a494b 100644 --- a/index.php +++ b/index.php @@ -235,8 +235,10 @@ SELECT { $query = ' SELECT + SUBDATE(NOW(), INTERVAL 24 HOUR) AS 24h, SUBDATE(NOW(), INTERVAL 7 DAY) AS 7d, SUBDATE(NOW(), INTERVAL 30 DAY) AS 30d, + SUBDATE(NOW(), INTERVAL 3 MONTH) AS 3m, SUBDATE(NOW(), INTERVAL 6 MONTH) AS 6m ;'; $thresholds = query2array($query)[0]; @@ -255,12 +257,13 @@ SELECT ), ' WHERE ' ).' - AND date_available > SUBDATE(NOW(), INTERVAL 1 YEAR) ;'; $dates = query2array($query); $pre_counters = array_fill_keys(array_keys($thresholds), array()); foreach ($dates as $date_row) { + $year = date('Y', strtotime($date_row['date_available'])); + @$pre_counters['y'.$year][ $date_row['image_id'] ] = 1; foreach ($thresholds as $threshold => $date_limit) { if ($date_row['date_available'] > $date_limit) @@ -268,16 +271,39 @@ SELECT @$pre_counters[$threshold][ $date_row['image_id'] ] = 1; } } - @$pre_counters['1y'][ $date_row['image_id'] ] = 1; } + $label_for_threshold = array( + '24h' => l10n('last 24 hours'), + '7d' => l10n('last 7 days'), + '30d' => l10n('last 30 days'), + '3m' => l10n('last 3 months'), + '6m' => l10n('last 6 months'), + ); + // pre_counters need to be deduplicated because a photo can be in several albums - $counters = array_fill_keys(array_keys($thresholds), 0); + $counters = array_fill_keys(array_keys($thresholds), array('label'=>'default label', 'counter'=>0)); foreach (array_keys($thresholds) as $threshold) { - $counters[$threshold] = count(array_keys($pre_counters[$threshold])); + $counters[$threshold] = array( + 'label' => $label_for_threshold[$threshold], + 'counter' => count(array_keys($pre_counters[$threshold])) + ); + } + + $pre_counters_keys = array_keys($pre_counters); + rsort($pre_counters_keys); // we want y2023 to come before y2022 in the list + + foreach ($pre_counters_keys as $key) + { + if (preg_match('/^y(\d+)$/', $key, $matches)) + { + $counters[$key] = array( + 'label' => l10n('year %d', $matches[1]), + 'counter' => count(array_keys($pre_counters[$key])) + ); + } } - $counters['1y'] = count(array_keys($pre_counters['1y'])); $template->assign('DATE_POSTED', $counters); } diff --git a/language/en_UK/common.lang.php b/language/en_UK/common.lang.php index 365158963..e4958b449 100644 --- a/language/en_UK/common.lang.php +++ b/language/en_UK/common.lang.php @@ -441,4 +441,7 @@ $lang['Tags listed here match your search by word. Click on one to browse by tag $lang['Albums listed here match your search by word. Click on one to browse by album.'] = 'Albums listed here match your search by word. Click on one to browse by album.'; $lang['%d visits'] = '%d visits'; $lang['rating score %s'] = 'rating score %s'; +$lang['year %d'] = 'year %d'; +$lang['last 3 months'] = 'Last 3 months'; +$lang['last 24 hours'] = 'last 24 hours'; ?> diff --git a/language/fr_FR/common.lang.php b/language/fr_FR/common.lang.php index e513d60b3..2d79a6933 100644 --- a/language/fr_FR/common.lang.php +++ b/language/fr_FR/common.lang.php @@ -446,3 +446,6 @@ $lang['Tags listed here match your search by word. Click on one to browse by tag $lang['Albums listed here match your search by word. Click on one to browse by album.'] = 'Les albums ci-dessous correspondent à votre recherche par mot. Cliquez sur l\'un d\'eux pour basculer en navigation par album.'; $lang['%d visits'] = '%d visites'; $lang['rating score %s'] = 'score %s'; +$lang['year %d'] = 'année %d'; +$lang['last 3 months'] = '3 derniers mois'; +$lang['last 24 hours'] = '24 dernières heures'; diff --git a/themes/default/js/mcs.js b/themes/default/js/mcs.js index 0458c63bb..73f0f9469 100644 --- a/themes/default/js/mcs.js +++ b/themes/default/js/mcs.js @@ -131,15 +131,11 @@ $(document).ready(function () { if (global_params.fields.date_posted != null && global_params.fields.date_posted != "") { $("#date_posted-" + global_params.fields.date_posted).prop("checked", true); - date_posted_str = str_date_post[global_params.fields.date_posted]; + date_posted_str = $('.date_posted-option label#'+global_params.fields.date_posted+' .date-period').text(); $(".filter-date_posted").addClass("filter-filled"); $(".filter.filter-date_posted .search-words").text(date_posted_str); } - $(".date_posted-option label").each(function () { - $(this).find('.date-period').html(str_date_post[$(this).attr('id')]) - }); - $(".filter-date_posted .filter-actions .clear").on('click', function () { $(".date_posted-option input").prop('checked', false); }); diff --git a/themes/default/template/include/search_filters.inc.tpl b/themes/default/template/include/search_filters.inc.tpl index 200ba2d30..9871692d7 100644 --- a/themes/default/template/include/search_filters.inc.tpl +++ b/themes/default/template/include/search_filters.inc.tpl @@ -18,13 +18,6 @@ str_author_widget_label = "{'Author'|@translate|escape:javascript}"; str_added_by_widget_label = "{'Added by'|@translate|escape:javascript}"; str_filetypes_widget_label = "{'File type'|@translate|escape:javascript}"; -str_date_post = { - '7d': "{'last 7 days'|@translate|escape:javascript}", - '30d': "{'last 30 days'|@translate|escape:javascript}", - '6m': "{'last 6 months'|@translate|escape:javascript}", - '1y': "{'last year'|@translate|escape:javascript}", -} - str_empty_search_top_alt = "{'Fill in the filters to start a search'|@translate|escape:javascript}"; str_empty_search_bot_alt = "{'Pre-established filters are proposed, but you can add or remove them using the "Choose filters" button.'|@translate|escape:javascript}"; @@ -183,13 +176,13 @@ str_empty_search_bot_alt = "{'Pre-established filters are proposed, but you can