diff --git a/index.php b/index.php index 968c7adc0..fc1a41be5 100644 --- a/index.php +++ b/index.php @@ -433,7 +433,27 @@ SELECT { $filter_clause = get_clause_for_filter('filetypes'); - $query = ' + // get all file extensions for this user in the gallery, whatever the current filters + $cache_key = $persistent_cache->make_key('file_exts'.$user['id'].$user['cache_update_time']); + if (!$persistent_cache->get($cache_key, $all_exts)) + { + $query = ' +SELECT + SUBSTRING_INDEX(path, ".", -1) AS ext, + COUNT(DISTINCT(id)) AS counter + FROM '.IMAGES_TABLE.' AS i + JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.image_id = i.id + WHERE 1=1'.$page['search_details']['forbidden'].' + GROUP BY ext + ORDER BY counter DESC +;'; + $all_exts = query2array($query, 'ext', 'counter'); + $persistent_cache->set($cache_key, $all_exts); + } + + if (preg_match('/^image_id IN/', $filter_clause)) + { + $query = ' SELECT SUBSTRING_INDEX(path, ".", -1) AS ext, COUNT(DISTINCT(id)) AS counter @@ -443,7 +463,20 @@ SELECT GROUP BY ext ORDER BY counter DESC ;'; - $template->assign('FILETYPES', query2array($query, 'ext', 'counter')); + $filtered_exts = query2array($query, 'ext', 'counter'); + + $exts = array(); + foreach ($all_exts as $ext => $counter) + { + $exts[$ext] = $filtered_exts[$ext] ?? 0; + } + + $template->assign('FILETYPES', $exts); + } + else + { + $template->assign('FILETYPES', $all_exts); + } } // For rating diff --git a/themes/default/css/clear-search.css b/themes/default/css/clear-search.css index 904597a2d..ebcd178e1 100644 --- a/themes/default/css/clear-search.css +++ b/themes/default/css/clear-search.css @@ -136,11 +136,13 @@ } .ratios-option.disabled label .ratio-badge, +.filetypes-option.disabled label .ext-badge, .ratings-option.disabled label .ratings-badge{ background-color: #888; } .ratios-option.disabled label .ratio-name, +.filetypes-option.disabled label .ext-name, .ratings-option.disabled label .ratings-name{ color:#888 } diff --git a/themes/default/css/dark-search.css b/themes/default/css/dark-search.css index a1c38efee..9df2b56c5 100644 --- a/themes/default/css/dark-search.css +++ b/themes/default/css/dark-search.css @@ -136,11 +136,13 @@ } .ratios-option.disabled label .ratio-badge, +.filetypes-option.disabled label .ext-badge, .ratings-option.disabled label .ratings-badge{ background-color: #888; } .ratios-option.disabled label .ratio-name, +.filetypes-option.disabled label .ext-name, .ratings-option.disabled label .ratings-name{ color:#888 } diff --git a/themes/default/template/include/search_filters.inc.tpl b/themes/default/template/include/search_filters.inc.tpl index 1b58febf1..a6cc40d30 100644 --- a/themes/default/template/include/search_filters.inc.tpl +++ b/themes/default/template/include/search_filters.inc.tpl @@ -401,12 +401,12 @@ const prefix_icon = 'gallery-icon-';
{foreach from=$FILETYPES item=filetypes key=k} -
- +
+
{/foreach}