From 2d2baa705209575e1baf645713cad59e978979a0 Mon Sep 17 00:00:00 2001 From: HWFord <54360213+HWFord@users.noreply.github.com> Date: Tue, 17 Sep 2024 16:50:38 +0200 Subject: [PATCH] fixes #2227 add creation date filter Same logic as date posted --- include/functions_search.inc.php | 82 +++++++ include/search_filters.inc.php | 106 +++++++++ include/ws_functions/pwg.images.php | 66 ++++++ themes/default/css/clear-search.css | 17 +- themes/default/css/dark-search.css | 11 +- themes/default/css/search.css | 64 ++++-- themes/default/js/mcs.js | 201 +++++++++++++++++- .../template/include/search_filters.inc.tpl | 107 +++++++++- ws.php | 8 + 9 files changed, 635 insertions(+), 27 deletions(-) diff --git a/include/functions_search.inc.php b/include/functions_search.inc.php index 011978913..8183b9e85 100644 --- a/include/functions_search.inc.php +++ b/include/functions_search.inc.php @@ -476,6 +476,88 @@ SELECT $image_ids_for_filter['date_posted'] = query2array($query, null, 'id'); } + // + // date_created + // + if (!empty($search['fields']['date_created']['preset'])) + { + + $has_filters_filled = true; + + $options = array( + '24h' => '24 HOUR', + '7d' => '7 DAY', + '30d' => '30 DAY', + '3m' => '3 MONTH', + '6m' => '6 MONTH', + ); + + if (isset($options[ $search['fields']['date_created']['preset'] ]) and 'custom' != $search['fields']['date_created']['preset']) + { + $date_created_clause = 'date_creation > SUBDATE(NOW(), INTERVAL '.$options[ $search['fields']['date_created']['preset'] ].')'; + } + elseif ('custom' == $search['fields']['date_created']['preset'] and isset($search['fields']['date_created']['custom'])) + { + $date_created_subclauses = array(); + $custom_dates = array_flip($search['fields']['date_created']['custom']); + + foreach (array_keys($custom_dates) as $custom_date) + { + // in real-life tests, we have determined "where year(date_creation) = 2024" was + // far less (4 times less) than "where date_creation between '2024-01-01 00:00:00' and '2024-12-31 23:59:59'" + // so let's find the begin/end for each custom date + // ... and also, no need to search for images of 2023-10-16 if 2023-10 is already requested + $begin = $end = null; + + $ymd = substr($custom_date, 0, 1); + if ('y' == $ymd) + { + $year = substr($custom_date, 1); + $begin = $year.'-01-01 00:00:00'; + $end = $year.'-12-31 23:59:59'; + } + elseif ('m' == $ymd) + { + list($year, $month) = explode('-', substr($custom_date, 1)); + + if (!isset($custom_dates['y'.$year])) + { + $begin = $year.'-'.$month.'-01 00:00:00'; + $end = $year.'-'.$month.'-'.cal_days_in_month(CAL_GREGORIAN, (int)$month, (int)$year).' 23:59:59'; + } + } + elseif ('d' == $ymd) + { + list($year, $month, $day) = explode('-', substr($custom_date, 1)); + + if (!isset($custom_dates['y'.$year]) and !isset($custom_dates['m'.$year.'-'.$month])) + { + $begin = $year.'-'.$month.'-'.$day.' 00:00:00'; + $end = $year.'-'.$month.'-'.$day.' 23:59:59'; + } + } + + if (!empty($begin)) + { + $date_created_subclauses[] = 'date_creation BETWEEN "'.$begin.'" AND "'.$end.'"'; + } + } + + $date_created_clause = '('.implode(' OR ', prepend_append_array_items($date_created_subclauses, '(', ')')).')'; + } + + $query = ' +SELECT + DISTINCT(id) + FROM '.IMAGES_TABLE.' AS i + INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id + WHERE '.$date_created_clause.' + '.$forbidden.' +;'; + + $image_ids_for_filter['date_created'] = query2array($query, null, 'id'); + } + // // ratios // diff --git a/include/search_filters.inc.php b/include/search_filters.inc.php index 5807eb993..19e13c670 100644 --- a/include/search_filters.inc.php +++ b/include/search_filters.inc.php @@ -222,6 +222,112 @@ SELECT $template->assign('DATE_POSTED', $counters); } + if (isset($my_search['fields']['date_created'])) + { + $filter_clause = get_clause_for_filter('date_created'); + $cache_key = $persistent_cache->make_key('filter_date_created'.$user['id'].$user['cache_update_time']); + $set_persistent_cache = !preg_match('/^image_id IN/', $filter_clause) and !$persistent_cache->get($cache_key, $date_created); + + if (!isset($date_created)) + { + $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]; + + $query = ' +SELECT + DISTINCT id, + date_creation as date + FROM '.IMAGES_TABLE.' AS i + JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.image_id = i.id + WHERE '.$filter_clause.' +;'; + + $list_of_dates = array(); + $pre_counters = array(); + + $result = pwg_query($query); + while ($row = pwg_db_fetch_assoc($result)) + { + if(!empty($row['date'])){ + foreach ($thresholds as $threshold => $date_limit) + { + if ($row['date'] > $date_limit) + { + @$pre_counters[$threshold]++; + } + } + + list($date_without_time) = explode(' ', $row['date']); + list($y, $m) = explode('-', $date_without_time); + + @$list_of_dates[$y]['months'][$y.'-'.$m]['days'][$date_without_time]['count']++; + @$list_of_dates[$y]['months'][$y.'-'.$m]['count']++; + @$list_of_dates[$y]['count']++; + } + } + + $date_created = array( + 'pre_counters' => $pre_counters, + 'list_of_dates' => $list_of_dates, + ); + + if ($set_persistent_cache) + { + // for this filter, we do not store in cache the $filter_rows : for a big gallery it may + // take more than 10MB. It is smarter to store in cache the result of the computation, + // which is just around 100 bytes. + $persistent_cache->set($cache_key, $date_created); + } + } + + $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'), + ); + + $counters = array(); + foreach (array_keys($label_for_threshold) as $threshold) + { + if (isset($date_created['pre_counters'][$threshold])) + { + $counters[$threshold] = array( + 'label' => $label_for_threshold[$threshold], + 'counter' => $date_created['pre_counters'][$threshold], + ); + } + } + + foreach (array_keys($date_created['list_of_dates']) as $y) + { + $date_created['list_of_dates'][$y]['label'] = l10n('year %d', $y); + + foreach (array_keys($date_created['list_of_dates'][$y]['months']) as $ym) + { + list(,$m) = explode('-', $ym); + $date_created['list_of_dates'][$y]['months'][$ym]['label'] = $lang['month'][(int)$m].' '.$y; + + foreach (array_keys($date_created['list_of_dates'][$y]['months'][$ym]['days']) as $ymd) + { + list(,,$d) = explode('-', $ymd); + $date_created['list_of_dates'][$y]['months'][$ym]['days'][$ymd]['label'] = format_date($ymd); + } + } + } + $template->assign('LIST_DATE_CREATED', $date_created['list_of_dates']); + $template->assign('DATE_CREATED', $counters); + } + + if (isset($my_search['fields']['added_by'])) { $filter_clause = get_clause_for_filter('added_by'); diff --git a/include/ws_functions/pwg.images.php b/include/ws_functions/pwg.images.php index d2ffb88de..0ba20fae6 100644 --- a/include/ws_functions/pwg.images.php +++ b/include/ws_functions/pwg.images.php @@ -925,6 +925,72 @@ function ws_images_filteredSearch_create($params, $service) } } + if (isset($params['date_created_preset'])) + { + if (!preg_match('/^(24h|7d|30d|3m|6m|custom|)$/', $params['date_created_preset'])) + { + return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid parameter date_created_preset'); + } + + @$search['fields']['date_created']['preset'] = $params['date_created_preset']; + + if ('custom' == $search['fields']['date_created']['preset'] and empty($params['date_created_custom'])) + { + return new PwgError(WS_ERR_INVALID_PARAM, 'date_created_custom is missing'); + } + } + + if (isset($params['date_created_custom'])) + { + if (!isset($search['fields']['date_created']['preset']) or $search['fields']['date_created']['preset'] != 'custom') + { + return new PwgError(WS_ERR_INVALID_PARAM, 'date_created_custom provided date_created_preset is not custom'); + } + + foreach ($params['date_created_custom'] as $date) + { + $correct_format = false; + + $ymd = substr($date, 0, 1); + if ('y' == $ymd) + { + if (preg_match('/^y(\d{4})$/', $date, $matches)) + { + $correct_format = true; + } + } + elseif ('m' == $ymd) + { + if (preg_match('/^m(\d{4}-\d{2})$/', $date, $matches)) + { + list($year, $month) = explode('-', $matches[1]); + if ($month >= 1 and $month <= 12) + { + $correct_format = true; + } + } + } + elseif ('d' == $ymd) + { + if (preg_match('/^d(\d{4}-\d{2}-\d{2})$/', $date, $matches)) + { + list($year, $month, $day) = explode('-', $matches[1]); + if ($month >= 1 and $month <= 12 and $day >= 1 and $day <= cal_days_in_month(CAL_GREGORIAN, (int)$month, (int)$year)) + { + $correct_format = true; + } + } + } + + if (!$correct_format) + { + return new PwgError(WS_ERR_INVALID_PARAM, 'date_created_custom, invalid option '.$date); + } + + @$search['fields']['date_created']['custom'][] = $date; + } + } + if (isset($params['ratios'])) { foreach ($params['ratios'] as $ext) diff --git a/themes/default/css/clear-search.css b/themes/default/css/clear-search.css index 79f590e4f..63eee4f3b 100644 --- a/themes/default/css/clear-search.css +++ b/themes/default/css/clear-search.css @@ -128,18 +128,28 @@ .custom_posted_date .date_posted-option:nth-child(even) .month_input i, .custom_posted_date .days_container .date_posted-option:nth-child(odd) label, .custom_posted_date .days_container .date_posted-option:nth-child(odd) i, +.preset_created_date .date_created-option:nth-child(odd) label, +.preset_created_date .date_created-option:nth-child(odd) i, +.custom_created_date .date_created-option:nth-child(odd) .year_input label, +.custom_created_date .date_created-option:nth-child(odd) .year_input i, +.custom_created_date .date_created-option:nth-child(even) .month_input label, +.custom_created_date .date_created-option:nth-child(even) .month_input i, +.custom_created_date .days_container .date_created-option:nth-child(odd) label, +.custom_created_date .days_container .date_created-option:nth-child(odd) i, .ratios-option:nth-child(odd), .ratings-option:nth-child(odd){ background: #f3f3f3; } -.date_posted-option label .checked-icon.grey-icon{ +.date_posted-option label .checked-icon.grey-icon, +.date_created-option label .checked-icon.grey-icon{ color:#777; } .filetypes-option label .checked-icon, .added_by-option label .checked-icon, .date_posted-option label .checked-icon, +.date_created-option label .checked-icon, .ratios-option label .checked-icon, .ratings-option label .checked-icon{ color: #ff7700; @@ -148,6 +158,7 @@ .filetypes-option label .ext-badge, .added_by-option label .added_by-badge, .date_posted-badge, +.date_created-badge, .ratios-option label .ratio-badge, .ratings-option label .ratings-badge { background: #ff7700; @@ -170,7 +181,9 @@ .ratios-option input:checked + label, .ratings-option input:checked + label, .preset_posted_date .date_posted-option input:checked + label, -.custom_posted_date .selected input:checked { +.custom_posted_date .selected input:checked, +.preset_created_date .date_created-option input:checked + label, +.custom_created_date .selected input:checked { background: #fff5e8; } diff --git a/themes/default/css/dark-search.css b/themes/default/css/dark-search.css index 84c6cfe86..e50f92234 100644 --- a/themes/default/css/dark-search.css +++ b/themes/default/css/dark-search.css @@ -112,9 +112,16 @@ .filetypes-option:nth-child(odd), .added_by-option:nth-child(odd), -.date_posted-option:nth-child(odd) label, +.preset_posted_date .date_posted-option:nth-child(odd) label, +.preset_posted_date .date_posted-option:nth-child(odd) i, +.custom_posted_date .date_posted-option:nth-child(odd) .year_input label, +.custom_posted_date .date_posted-option:nth-child(odd) .year_input i, +.custom_posted_date .date_posted-option:nth-child(even) .month_input label, +.custom_posted_date .date_posted-option:nth-child(even) .month_input i, +.custom_posted_date .days_container .date_posted-option:nth-child(odd) label, +.custom_posted_date .days_container .date_posted-option:nth-child(odd) i, .ratios-option:nth-child(odd), -.ratings-option:nth-child(odd) { +.ratings-option:nth-child(odd){ background: #444; } diff --git a/themes/default/css/search.css b/themes/default/css/search.css index fbbb86d25..025bc401c 100644 --- a/themes/default/css/search.css +++ b/themes/default/css/search.css @@ -234,6 +234,7 @@ .filter-filetypes-form .filter-actions, .filter-date_posted-form .filter-actions, +.filter-date_created-form .filter-actions, .filter-ratios-form .filter-actions, .filter-ratings-form .filter-actions{ gap: 5px; @@ -309,6 +310,7 @@ .filetypes-option-container, .added_by-option-container, .date_posted-option-container, +.date_created-option-container, .ratios-option-container .ratings-option-container { display: flex; @@ -319,7 +321,8 @@ } -.date_posted-option-container { +.date_posted-option-container, +.date_created-option-container { margin: 10px 0 10px 0; } @@ -331,6 +334,7 @@ .filetypes-option input, .added_by-option input, .date_posted-option input, +.date_created-option input, .ratios-option input, .ratings-option input { display: none; @@ -339,6 +343,7 @@ .filetypes-option label, .added_by-option label, .preset_posted_date .date_posted-option label, +.preset_created_date .date_created-option label, .ratios-option label, .ratings-option label{ display: flex; @@ -352,14 +357,16 @@ .added_by-option label .checked-icon, .ratios-option label .checked-icon, .ratings-option label .checked-icon, -.preset_posted_date .date_posted-option label .checked-icon{ +.preset_posted_date .date_posted-option label .checked-icon, +.preset_created_date .date_created-option label .checked-icon{ display: none; position: absolute; left: 3px; top: 4px; } -.custom_posted_date .date_posted-option label .checked-icon{ +.custom_posted_date .date_posted-option label .checked-icon, +.custom_created_date .date_created-option label .checked-icon{ display: none; position: absolute; right: 3px; @@ -374,6 +381,7 @@ .added_by-option label .added_by-name, .ratios-option label .ratio-name, .preset_posted_date .date_posted-option .date-period, +.preset_created_date .date_created-option .date-period, .ratings-option label .ratings-name { margin-left: 30px; } @@ -383,7 +391,8 @@ margin-right: 10px; } -.custom_posted_date .date_posted-option label .date-period{ +.custom_posted_date .date_posted-option label .date-period, +.custom_created_date .date_created-option label .date-period{ margin-right: 30px; } @@ -391,14 +400,16 @@ .added_by-option label .added_by-badge, .ratios-option label .ratio-badge, .ratings-option label .ratings-badge, -.preset_posted_date .date_posted-option label .date_posted-badge { +.preset_posted_date .date_posted-option label .date_posted-badge, +.preset_created_date .date_created-option label .date_created-badge { margin-left: auto; border-radius: 10px; padding: 0 5px; font-weight: 600; } -.custom_posted_date .date_posted-option label .date_posted-badge{ +.custom_posted_date .date_posted-option label .date_posted-badge, +.custom_created_date .date_created-option label .date_created-badge{ border-radius: 10px; padding: 0 5px; font-weight: 600; @@ -408,11 +419,13 @@ .added_by-option input:checked + label .checked-icon, .ratios-option input:checked + label .checked-icon, .ratings-option input:checked + label .checked-icon, -.preset_posted_date .date_posted-option input:checked + label .checked-icon{ +.preset_posted_date .date_posted-option input:checked + label .checked-icon, +.preset_created_date .date_created-option input:checked + label .checked-icon{ display: block; } .filter-date_posted-form, +.filter-date_created-form, .filter-album-form { width: 400px; } @@ -440,7 +453,8 @@ display:flex } -.date_posted-option label{ +.date_posted-option label, +.date_created-option label{ display: flex; flex-direction: row; align-items: baseline; @@ -449,35 +463,43 @@ margin-left:-1px; } -.custom_posted_date .date_posted-option label{ +.custom_posted_date .date_posted-option label, +.custom_created_date .date_created-option label{ width:100%; } -.date_posted-option .accordion-toggle{ +.date_posted-option .accordion-toggle, +.date_created-option .accordion-toggle{ padding:5px; rotate:90deg; } -.date_posted-option .accordion-toggle:hover{ +.date_posted-option .accordion-toggle:hover, +.date_created-option .accordion-toggle:hover{ color:#ff7700; cursor:pointer; } -.date_posted-option.month{ +.date_posted-option.month, +.date_created-option.month{ margin-left:15px; display:none; } -.date_posted-option.day{ + +.date_posted-option.day, +.date_created-option.day{ margin-left:30px; margin-right:10px; display:none; } -.date_posted-option .show-child .accordion-toggle::before { +.date_posted-option .show-child .accordion-toggle::before, +.date_created-option .show-child .accordion-toggle::before { transform: rotate(90deg); } -.custom_posted_date{ +.custom_posted_date, +.custom_created_date{ display:none; } @@ -485,21 +507,25 @@ display:block!important; } -.custom_posted_date_toggle{ +.custom_posted_date_toggle, +.custom_created_date_toggle{ cursor:pointer; } -.date_posted-option .custom_posted_date_toggle{ +.date_posted-option .custom_posted_date_toggle, +.date_created-option .custom_created_date_toggle{ padding: 5px 0; border-top: .3px solid #aaa; border-bottom: .3px solid #aaa; } -.custom_posted_date_toggle .gallery-icon-up-open:before{ +.custom_posted_date_toggle .gallery-icon-up-open:before, +.custom_created_date_toggle .gallery-icon-up-open:before{ rotate: -90deg; } -.custom_posted_date.custom_posted_date_toggle{ +.custom_posted_date.custom_posted_date_toggle, +.custom_created_date.custom_created_date_toggle{ position:absolute; } diff --git a/themes/default/js/mcs.js b/themes/default/js/mcs.js index 3a3a6d693..882b9f888 100644 --- a/themes/default/js/mcs.js +++ b/themes/default/js/mcs.js @@ -187,7 +187,7 @@ $(document).ready(function () { $(".custom_posted_date .date_posted-option input").change(function() { var parentOption = $(this).parent() - if(true == $(this).prop("checked")){ + if($(this).is(":checked")){ // Toggle tick icon on selected date in custom list $(this).siblings('label').find('.checked-icon').show(); @@ -276,6 +276,133 @@ $(document).ready(function () { empty_filters_list.push(PS_params.date_posted_custom); } + // Setup Date creation filter + + if (global_params.fields.date_created) { + $(".filter-date_created").css("display", "flex"); + $(".filter-manager-controller.date_created").prop("checked", true); + + if (global_params.fields.date_created.preset != null && global_params.fields.date_created.preset != "") { + // If filter is used and not empty check preset date option + $("#date_created-" + global_params.fields.date_created.preset).prop("checked", true); + date_created_str = $('.date_created-option label#'+ global_params.fields.date_created.preset +' .date-period').text(); + + // if option is custom check custom dates + if ('custom' == global_params.fields.date_created.preset && global_params.fields.date_created.custom != null) + { + date_created_str = ''; + var customArray = global_params.fields.date_created.custom + + $(customArray).each(function( index ) { + var customValue = this.substring(1, $(this).length); + + $("#date_created_"+customValue).prop("checked", true).addClass('selected'); + $("#date_created_"+customValue).siblings('label').find('.checked-icon').show(); + + date_created_str += $('.date_created-option label#'+ customValue +' .date-period').text() + + if($(global_params.fields.date_created.custom).length > 1 && index != $(customArray).length-1) + { + date_created_str += ', '; + } + }); + } + + // change badge label if filter not empty + $(".filter-date_created").addClass("filter-filled"); + $(".filter.filter-date_created .search-words").text(date_created_str); + } + + $(".filter-date_created .filter-actions .clear").on('click', function () { + updateFilters('date_created', 'add'); + $(".date_created-option input").prop('checked', false); + $(".date_created-option input").trigger('change'); + + // $('.date_created-option input').removeAttr('disabled'); + // $('.date_created-option input').removeClass('grey-icon'); + }); + + // Disable possiblity for user to select custom option, its gets selected programtically later on + $("#date_created_custom").attr('disabled', 'disabled'); + + // Handle toggle between preset and custom options + $(".custom_created_date_toggle").on("click", function (e) { + $('.custom_created_date').toggle() + $('.preset_created_date').toggle() + }); + + // Handle accoridan features in custom options + $(".custom_created_date .accordion-toggle").on("click", function (e) { + var clickedOption = $(this).parent(); + $(clickedOption).toggleClass('show-child'); + if('year' == $(this).data('type')) + { + $(clickedOption).parent().find('.date_created-option.month').toggle(); + } + else if('month' == $(this).data('type')) + { + $(clickedOption).parent().find('.date_created-option.day').toggle(); + } + }); + + // On custom date input select + $(".custom_created_date .date_created-option input").change(function() { + var parentOption = $(this).parent() + + if($(this).is(":checked")){ + // Toggle tick icon on selected date in custom list + $(this).siblings('label').find('.checked-icon').show(); + + // Add class selected to selected option, + // We want to find which are selected to handle the others + $(this).addClass('selected') + $(parentOption).addClass('selected') + $(parentOption).find('.mcs-icon').addClass('selected') + } + else + { + // Toggle tick icon on selected date in custom list + $(this).siblings('label').find('.checked-icon').hide(); + + // Add class selected to selected option, + // We want to find which are selected to handle the others + $(this).removeClass('selected') + $(parentOption).removeClass('selected') + $(parentOption).find('.mcs-icon').removeClass('selected') + } + // if this is selected then disable selecting children, and display grey tick + + // Used to select custom in preset list if dates are selected + if($('.custom_created_date input:checked').length > 0) + { + $("#date_created-custom").prop('checked', true); + $('.preset_created_date input').attr('disabled', 'disabled'); + } + else{ + $("#date_created-custom").prop('checked', false); + $('.preset_created_date input').removeAttr('disabled'); + } + + }); + + // Used to select custom in preset list if dates are selected + if($('.custom_created_date input:checked').length > 0) + { + $("#date_created-custom").prop('checked', true); + $('.preset_created_date input').attr('disabled', 'disabled'); + } + else{ + $("#date_created-custom").prop('checked', false); + $('.preset_created_date input').removeAttr('disabled'); + } + + PS_params.date_created_preset = global_params.fields.date_created.preset != '' ? global_params.fields.date_created.preset : ''; + PS_params.date_created_custom = global_params.fields.date_created.custom != '' ? global_params.fields.date_created.custom : ''; + + empty_filters_list.push(PS_params.date_created_preset); + empty_filters_list.push(PS_params.date_created_custom); + } + // Setup album filter if (global_params.fields.cat) { $(".filter-album").css("display", "flex"); @@ -620,7 +747,7 @@ $(document).ready(function () { exclude_params = ['search_id', 'allwords_mode', 'allwords_fields', 'tags_mode', 'categories_withsubs']; for (const key in PS_params) { if (!exclude_params.includes(key)) { - if("date_posted_custom" == key) + if("date_posted_custom" == key || "date_created_custom" == key) { PS_params[key] = []; } @@ -869,6 +996,58 @@ $(document).ready(function () { } }); + /** + * Filter Date created + */ + $(".filter-date_created").on("click", function (e) { + if ($(".filter-form").has(e.target).length != 0 || + $(e.target).hasClass("filter-form")) { + return; + } + $(".filter-date_created-form").toggle(0, function () { + if ($(this).is(':visible')) + { + $(".filter-date_created").addClass("show-filter-dropdown"); + } + else + { + $(".filter-date_created").removeClass("show-filter-dropdown"); + + var presetValue = $(".preset_created_date .date_created-option input:checked").val(); + + global_params.fields.date_created.preset = presetValue; + PS_params.date_created_preset = presetValue != null ? presetValue : ""; + + if ('custom' == presetValue) + { + var customDates = []; + + $(".custom_created_date .date_created-option input:checked").each(function(){ + customDates.push($(this).val()); + }); + + global_params.fields.date_created.custom = customDates; + PS_params.date_created_custom = customDates.length > 0 ? customDates : ""; + } + + } + }); + }); + + $(".filter-date_created .filter-validate").on("click", function () { + $(".filter-date_created").trigger("click"); + performSearch(PS_params, true); + }); + + $(".filter-date_created .filter-actions .delete").on("click", function () { + updateFilters('date_created', 'del'); + performSearch(PS_params, true); + if (!$(".filter-date_created").hasClass("filter-filled")) { + $(".filter-date_created").hide(); + $(".filter-manager-controller.date").prop("checked", false); + } + }); + /** * Filter Album */ @@ -1344,6 +1523,24 @@ function updateFilters(filterName, mode) { } break; + case 'date_created': + if (mode == 'add') { + global_params.fields['date_created'] = {}; + global_params.fields.date_created.preset = ''; + global_params.fields.date_created.custom = []; + + PS_params.date_created_preset = ''; + PS_params.date_created_custom = []; + + } else if (mode == 'del') { + delete global_params.fields.date_created.preset; + delete global_params.fields.date_created.custom; + + delete PS_params.date_created_preset; + delete PS_params.date_created_custom; + } + break; + case 'filesize': if (mode == 'add') { global_params.fields.filesize_min = ''; diff --git a/themes/default/template/include/search_filters.inc.tpl b/themes/default/template/include/search_filters.inc.tpl index 1b29810ea..759dd6315 100644 --- a/themes/default/template/include/search_filters.inc.tpl +++ b/themes/default/template/include/search_filters.inc.tpl @@ -114,6 +114,10 @@ const prefix_icon = 'gallery-icon-'; {'Post date'|@translate} +