mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-03-28 17:42:57 +01:00
fixes #1968 new values for date_posted filter
* add 24h, 3m and yNNNN (year 2023 or 2022...) * remove 1y * provide labels from backend instead of managing it in javascript
This commit is contained in:
@@ -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']))
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
36
index.php
36
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);
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
?>
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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
|
||||
</div>
|
||||
|
||||
<div class="date_posted-option-container">
|
||||
{foreach from=$DATE_POSTED item=badge_number key=k}
|
||||
{foreach from=$DATE_POSTED item=date_posted key=k}
|
||||
<div class="date_posted-option">
|
||||
<input type="radio" id="date_posted-{$k}" value={$k} name="date_posted-period">
|
||||
<label for="date_posted-{$k}" id="{$k}">
|
||||
<span class="mcs-icon pwg-icon-checkmark checked-icon"></span>
|
||||
<span class="date-period">{'last year'|@translate}</span>
|
||||
<span class="date_posted-badge">{$badge_number}</span>
|
||||
<span class="date-period">{$date_posted.label}</span>
|
||||
<span class="date_posted-badge">{$date_posted.counter}</span>
|
||||
</label>
|
||||
</div>
|
||||
{/foreach}
|
||||
|
||||
2
ws.php
2
ws.php
@@ -1414,7 +1414,7 @@ enabled_high, registration_date, registration_date_string, registration_date_sin
|
||||
),
|
||||
'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',
|
||||
'info' => 'files posted within 24 hours, 7 days or 30 days or 3 months or 6 months or year NNNN. Value among 24h|7d|30d|3m|6m|yNNNN',
|
||||
),
|
||||
),
|
||||
'',
|
||||
|
||||
Reference in New Issue
Block a user