diff --git a/include/ws_functions/pwg.images.php b/include/ws_functions/pwg.images.php index 5323ff371..21dd061b0 100644 --- a/include/ws_functions/pwg.images.php +++ b/include/ws_functions/pwg.images.php @@ -834,7 +834,7 @@ SELECT id if (isset($params['date_posted'])) { - if (!preg_match('/^(7d|30d|6m|1y)$/', $params['date_posted'])) + if (!preg_match('/^(7d|30d|6m|1y|)$/', $params['date_posted'])) { return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid parameter date_posted'); } diff --git a/language/en_UK/common.lang.php b/language/en_UK/common.lang.php index 1be80ca5c..66791ca95 100644 --- a/language/en_UK/common.lang.php +++ b/language/en_UK/common.lang.php @@ -429,4 +429,9 @@ $lang['Clear'] = 'Clear'; $lang['Fill in the filters to start a search'] = 'Fill in the filters to start a search'; $lang['Pre-established filters are proposed, but you can add or remove them using the "Choose filters" button.'] = 'Pre-established filters are proposed, but you can add or remove them using the "Choose filters" button.'; $lang['Empty filters'] = 'Empty filters'; +$lang['last 7 days'] = 'Last 7 days'; +$lang['last 30 days'] = 'Last 30 days'; +$lang['last 6 months'] = 'Last 6 months'; +$lang['last year'] = 'Last year'; +$lang['Unknown time period'] = 'Unknown time period'; ?> diff --git a/language/fr_FR/common.lang.php b/language/fr_FR/common.lang.php index 0a98b632c..e7db8772f 100644 --- a/language/fr_FR/common.lang.php +++ b/language/fr_FR/common.lang.php @@ -434,3 +434,8 @@ $lang['Clear'] = 'Vider'; $lang['Fill in the filters to start a search'] = 'Complétez les filtres pour lancer une recherche'; $lang['Pre-established filters are proposed, but you can add or remove them using the "Choose filters" button.'] = 'Des filtres préétablis vous sont proposés, mais vous pouvez aussi en ajouter ou en retirer grâce au bouton "Choisir les filtres".'; $lang['Empty filters'] = 'Vider les filtres'; +$lang['last 7 days'] = '7 derniers jours'; +$lang['last 30 days'] = '30 derniers jours'; +$lang['last 6 months'] = '6 derniers mois'; +$lang['last year'] = 'Dernière année'; +$lang['Unknown time period'] = 'Période inconnue'; diff --git a/themes/default/js/mcs.js b/themes/default/js/mcs.js index 563d42b65..a43083eab 100644 --- a/themes/default/js/mcs.js +++ b/themes/default/js/mcs.js @@ -122,6 +122,43 @@ $(document).ready(function () { empty_filters_list.push(PS_params.tags); } + // Setup Date post filter + if (global_params.fields.hasOwnProperty('date_posted')) { + $(".filter-date_post").css("display", "flex"); + $(".filter-manager-controller.date_post").prop("checked", true); + if (global_params.fields.date_posted != null && global_params.fields.date_posted != "") { + $("#date_post-" + global_params.fields.date_posted).prop("checked", true); + + switch (global_params.fields.date_posted) { + case "7d": + date_posted_str = str_date_post_7d; + break; + case "30d": + date_posted_str = str_date_post_30d; + break; + case "6m": + date_posted_str = str_date_post_6m; + break; + case "1y": + date_posted_str = str_date_post_1y; + break; + + default: + date_posted_str = str_date_post_u; + break; + } + $(".filter-date_post").addClass("filter-filled"); + $(".filter.filter-date_post .search-words").text(date_posted_str); + } + $(".filter-date_post .filter-actions .clear").on('click', function () { + $(".date_post-option input").prop('checked', false); + }); + + PS_params.date_posted = global_params.fields.date_posted.length > 0 ? global_params.fields.date_posted : ''; + + empty_filters_list.push(PS_params.date_posted); + } + // Setup album filter if (global_params.fields.cat) { $(".filter-album").css("display", "flex"); @@ -421,28 +458,35 @@ $(document).ready(function () { }); /** - * Filter Date + * Filter Date posted */ - $(".filter-date").on("click", function (e) { + $(".filter-date_post").on("click", function (e) { if ($(".filter-form").has(e.target).length != 0 || $(e.target).hasClass("filter-form")) { return; } - $(".filter-date-form").toggle(0, function () { - + $(".filter-date_post-form").toggle(0, function () { if ($(this).is(':visible')) { - $(".filter-date").addClass("show-filter-dropdown"); + $(".filter-date_post").addClass("show-filter-dropdown"); } else { - $(".filter-date").removeClass("show-filter-dropdown"); - performSearch(PS_params, true); + $(".filter-date_post").removeClass("show-filter-dropdown"); + + global_params.fields.date_posted = $(".date_post-option input:checked").val(); + + PS_params.date_posted = $(".date_post-option input:checked").length > 0 ? $(".date_post-option input:checked").val() : ""; } }); }); - $(".filter-date .filter-actions .delete").on("click", function () { - updateFilters('date', 'del'); - performSearch(PS_params, $(".filter-date").hasClass("filter-filled")); - if (!$(".filter-date").hasClass("filter-filled")) { - $(".filter-date").hide(); + + $(".filter-date_post .filter-validate").on("click", function () { + $(".filter-date_post").trigger("click"); + performSearch(PS_params, true); + }); + $(".filter-date_post .filter-actions .delete").on("click", function () { + updateFilters('date_posted', 'del'); + performSearch(PS_params, $(".filter-date_post").hasClass("filter-filled")); + if (!$(".filter-date_post").hasClass("filter-filled")) { + $(".filter-date_post").hide(); $(".filter-manager-controller.date").prop("checked", false); } }); diff --git a/themes/default/template/index.tpl b/themes/default/template/index.tpl index 2fcf6bdee..51bc72d9e 100644 --- a/themes/default/template/index.tpl +++ b/themes/default/template/index.tpl @@ -25,6 +25,12 @@ 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}"; +str_date_post_30d = "{'last 30 days'|@translate|escape:javascript}"; +str_date_post_6m = "{'last 6 months'|@translate|escape:javascript}"; +str_date_post_1y = "{'last year'|@translate|escape:javascript}"; +str_date_post_u = "{'Unknown time period'|@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}"; @@ -212,6 +218,10 @@ str_empty_search_bot_alt = "{'Pre-established filters are proposed, but you can {'Tag'|@translate} +