From 2465654752f3a459c1430f8b4f68a8620f2b9beb Mon Sep 17 00:00:00 2001 From: Perrom <107625315+Perrom@users.noreply.github.com> Date: Fri, 8 Aug 2025 15:07:02 +0200 Subject: [PATCH] fixes #2362 add gallery filters options in admin (#2395) Add a config page in admin for the search filters in the gallery. Privacy and default filters can be selected. Needs a database update. --- admin/configuration.php | 45 ++++ admin/include/add_core_tabs.inc.php | 1 + admin/themes/clear/theme.css | 32 ++- .../default/template/configuration_search.tpl | 251 ++++++++++++++++++ admin/themes/default/theme.css | 52 +++- admin/themes/roma/theme.css | 36 ++- include/functions_search.inc.php | 50 +++- include/search_filters.inc.php | 157 +++++++++-- install/config.sql | 1 + install/db/178-database.php | 24 ++ search.php | 65 ++++- themes/default/js/mcs.js | 27 +- .../template/include/search_filters.inc.tpl | 34 +++ 13 files changed, 711 insertions(+), 64 deletions(-) create mode 100644 admin/themes/default/template/configuration_search.tpl create mode 100644 install/db/178-database.php diff --git a/admin/configuration.php b/admin/configuration.php index 0c3f00303..32ff2d9b6 100644 --- a/admin/configuration.php +++ b/admin/configuration.php @@ -112,6 +112,22 @@ $display_info_checkboxes = array( 'rating_score', ); +$filters_names_checkboxes = array( + 'words', + 'tags', + 'post_date', + 'creation_date', + 'album', + 'author', + 'added_by', + 'file_type', + 'ratio', + 'rating', + 'file_size', + 'height', + 'width' +); + // image order management $sort_fields = array( '' => '', @@ -277,6 +293,23 @@ if (isset($_POST['submit'])) $_POST['picture_informations'] = addslashes(serialize($_POST['picture_informations'])); break; } + case 'search' : + { + foreach( $filters_names_checkboxes as $checkbox) + { + if (empty($_POST['filters_views_box'][$checkbox])){ + $_POST['filters_views'][$checkbox]['access'] = 'nobody'; + $_POST['filters_views'][$checkbox]['default'] = false; + } + else{ + $_POST['filters_views'][$checkbox]['default'] = + empty($_POST['filters_views'][$checkbox]['default'])? false : true; + } + } + $_POST['filters_views']['last_filters_conf'] = + empty($_POST['filters_views']['last_filters_conf'])? false : true; + $_POST['filters_views'] = addslashes(serialize($_POST['filters_views'])); + } } // updating configuration if no error found @@ -660,6 +693,18 @@ switch ($page['section']) break; } + case 'search': + { + $filters_names = $filters_names_checkboxes; + $template->assign( + 'search', + array( + 'filters_views' => unserialize($conf['filters_views']), + 'filters_names' => $filters_names, + ), + ); + $template->assign('SHOW_FILTER_RATINGS', $conf['rate']); + } } $template->assign('isWebmaster', (is_webmaster()) ? 1 : 0); diff --git a/admin/include/add_core_tabs.inc.php b/admin/include/add_core_tabs.inc.php index 1f3e9b63f..7228657c3 100644 --- a/admin/include/add_core_tabs.inc.php +++ b/admin/include/add_core_tabs.inc.php @@ -81,6 +81,7 @@ function add_core_tabs($sheets, $tab_id) $sheets['watermark'] = array('caption' => ''.l10n('Watermark'), 'url' => $conf_link.'watermark'); $sheets['display'] = array('caption' => ''.l10n('Display'), 'url' => $conf_link.'display'); $sheets['comments'] = array('caption' => ''.l10n('Comments'), 'url' => $conf_link.'comments'); + $sheets['search'] = array('caption' => ''.l10n('Search'), 'url' => $conf_link.'search'); // $sheets['default'] = array('caption' => l10n('Guest Settings'), 'url' => $conf_link.'default'); break; diff --git a/admin/themes/clear/theme.css b/admin/themes/clear/theme.css index 4fd1c5ef5..ec311106f 100644 --- a/admin/themes/clear/theme.css +++ b/admin/themes/clear/theme.css @@ -629,7 +629,6 @@ table.dataTable thead th, table.dataTable.no-footer { background: #3C3C3C; } -.font-checkbox [class*=icon-check]:before { color:#444; } #watermarkPositionBox { border:2px solid #ccc; @@ -651,8 +650,10 @@ FORM#categoryOrdering p.albumActions .userSeparator {border: 1px solid #E1E1E1;} .afterUploadActions a.secondary_button {background-color: #ECECEC;} .afterUploadActions a.secondary_button:hover {background-color: #FFA646;} -.font-checkbox:hover {color: #FFA844;} +.font-checkbox:hover {color: #3C3C3C;} .font-checkbox.selected {color: #ffa646;} +.font-checkbox:hover .icon-check-empty, .font-checkbox:hover .icon-check {color: #FF7700;} +.font-checkbox .icon-check {color: #FFA646;} LEGEND {color: #3C3C3C;} a#showPermissions {color: #5B5B5B; border: 1px solid #D6D6D6; background-color: #FAFAFA;} @@ -920,4 +921,31 @@ li.plupload_delete a.remove-format:hover{color: #474747;} .RenameTagPopInContainer { background-color:#fff; +} + +/* Filters options */ +label:has(> .filters-icon-check:disabled), span:has(+ .filters-icon-check:disabled){ + color: #D5D5D5 !important; + cursor: not-allowed; +} + +.select-views{ + background-color: #f3f3f3; +} + +.filter-manager-options-container{ + color: #474747; +} + +.filter-manager-options-container:hover{ + background-color: #EDEDED; +} + +.filter-manager-options-container.selected-filter-container{ + background-color: #777777; + color: #FFFFFF; +} + +.filter-manager-options-container.selected-filter-container:hover{ + background-color: #5D5D5D; } \ No newline at end of file diff --git a/admin/themes/default/template/configuration_search.tpl b/admin/themes/default/template/configuration_search.tpl new file mode 100644 index 000000000..f5e542241 --- /dev/null +++ b/admin/themes/default/template/configuration_search.tpl @@ -0,0 +1,251 @@ +{combine_script id='common' load='footer' path='admin/themes/default/js/common.js'} + +{footer_script} + +filters_names = +[ + 'words', + 'tags', + 'post_date', + 'creation_date', + 'album', + 'author', + 'added_by', + 'file_type', + 'ratio', + 'rating', + 'file_size', + 'height', + 'width' +]; + +for(const filter_name of filters_names){ + if(!$("input#"+filter_name+"Filters").is(':checked')){ + $("#f"+filter_name+"Select, #"+filter_name+"Arrow").hide(); + $("#default_"+filter_name).parent().hide(); + } + + if($("#f"+filter_name+"Select").val()!="admins-only"){ + $("#"+filter_name+"AdminIcon").hide(); + } + + if($("#default_"+filter_name).is(':checked')){ + $("#default_"+filter_name).parent().addClass("selected-filter-container"); + } + + $("#"+filter_name+"Filters").on("click", function(){ + if($("input#"+filter_name+"Filters").is(':checked')){ + $("#f"+filter_name+"Select, #"+filter_name+"Arrow").show(); + $("#default_"+filter_name).parent().show(); + if($("#f"+filter_name+"Select").val()=="admins-only"){ + $("#"+filter_name+"AdminIcon").show(); + } + } + else{ + $("#f"+filter_name+"Select, #"+filter_name+"Arrow, #"+filter_name+"AdminIcon").hide(); + $("#default_"+filter_name).parent().hide(); + } + }) + + $("#f"+filter_name+"Select").on("click", function(){ + if($("#f"+filter_name+"Select").val()=="admins-only"){ + $("#"+filter_name+"AdminIcon").show(); + } + else{ + $("#"+filter_name+"AdminIcon").hide(); + } + }) + + $("#default_"+filter_name).on("click", function(){ + if($("#default_"+filter_name).is(':checked')){ + $("#default_"+filter_name).parent().addClass("selected-filter-container"); + } + else{ + $("#default_"+filter_name).parent().removeClass("selected-filter-container"); + } + }) +} + +{/footer_script} + +{combine_css path="themes/default/vendor/fontello/css/gallery-icon.css" order=-10} + +
+ +
+ +
+ {'Filters'|translate} +
    + {foreach from=$search.filters_names item=$filter_name} +
  • + +
    + +
    +
  • + {/foreach} +
+
+ +
+ {'Default filters'|translate} + +
+ + +
+ + + + + + + + + + + + + + + +
+ +
+ + + +
\ No newline at end of file diff --git a/admin/themes/default/theme.css b/admin/themes/default/theme.css index b04db974c..260bf8497 100644 --- a/admin/themes/default/theme.css +++ b/admin/themes/default/theme.css @@ -1920,6 +1920,7 @@ img.ui-datepicker-trigger { } .rotate-element{ + display: inline-block; transform: rotate(90deg); } @@ -6522,13 +6523,15 @@ table.qsearch_help_table td { .font-checkbox [class*=icon-check]:before { font-size:16px; line-height:16px; - margin-right:0; + margin-right:5px; margin-left:0; + font-size: 145%; } .font-checkbox .icon-check-empty { position:relative; left:-1px; } + .font-checkbox input[type=checkbox], .font-checkbox input[type=radio] { display:none; } @@ -8008,3 +8011,50 @@ color:#FF7B00; box-shadow: 0px 4px 4px 0px #00000040; font-size: 10px; } + +/* Filters options */ +.filters-grid{ + display: grid; + grid-template-columns: 200px 118px 25px; + margin-bottom: 0px !important; +} +.select-views{ + background-color: #f3f3f3; + font-size: 11px; + border: none; + height: 16px; + margin-top: 4.5px; + padding-left: 10px; +} +.select-views-arrow{ + display: flex; + position: absolute; + margin-left: 299.9px; + margin-top: 5px; + pointer-events: none; +} +.select-views-admin{ + margin-left: 3px; +} + +.last-filters{ + display: block; + margin-bottom: 15px; + font-weight: bold; +} + +.filter-manager-options-container{ + display: inline-block; + font-size: 11px; + font-weight: normal !important; + border: 1px solid #777; + border-radius: 20px; + padding: 4px 10px; + cursor: pointer; + margin-right: 7.5px; + margin-bottom: 7.5px; +} + +.mcs-icon-options::before{ + margin-right: 5px; +} \ No newline at end of file diff --git a/admin/themes/roma/theme.css b/admin/themes/roma/theme.css index b01548ad7..000eac0de 100644 --- a/admin/themes/roma/theme.css +++ b/admin/themes/roma/theme.css @@ -224,7 +224,7 @@ body .ui-resizable-autohide .ui-resizable-handle { display: none; } /* use 'body #ui-datepicker-div .ui-datepicker-buttonpane .ui-state-error:hover { background: #7e3030;} INPUT[type="text"].large { width: 317px; } -.buttonLike:disabled, input[type="button"]:disabled, input[type="submit"]:disabled, input[type="reset"]:disabled { +.buttonLike:disabled, .filters-icon-check:disabled, input[type="button"]:disabled, input[type="submit"]:disabled, input[type="reset"]:disabled { color:#555; border-color:#666; cursor:not-allowed; @@ -971,8 +971,6 @@ table.qsearch_help_table td { border-color: #444; } -.font-checkbox [class*=icon-check]:before { color:#aaa; } - #cboxLoadedContent { background-color:#333 !important; } #watermarkPositionBox { @@ -993,6 +991,8 @@ table.qsearch_help_table td { .font-checkbox {color: #898888;} .font-checkbox:hover {color: #ededed;} +.font-checkbox:hover .icon-check-empty, .font-checkbox:hover .icon-check {color: #FF7700;} +.font-checkbox .icon-check {color: #FFA646;} .with-border legend, .with-border strong {color: #c0c0c0;} .font-checkbox.selected {color: #ffa646;} @@ -2394,4 +2394,34 @@ ul.jqtree-tree li.jqtree-ghost span.jqtree-line { .RenameTagPopInContainer { background-color:#444; +} + +/* Filters options */ +.select-views{ + background-color: #444444; + color: #898888; + border: 1px solid #666; +} + +.filter-manager-options-container{ + background-color: #333; + color: #aaa; + border-color: #333; +} + +.filter-manager-options-container:hover{ + background-color: #5D5D5D; +} + +.filter-manager-options-container.selected-filter-container{ + background-color: #777777; + color: #ddd; +} + +.filter-manager-options-container.selected-filter-container:hover{ + background-color: #aaa; +} + +label:has(> .filters-icon-check:disabled){ + color:#555; } \ No newline at end of file diff --git a/include/functions_search.inc.php b/include/functions_search.inc.php index 288d1f517..a66f4cde5 100644 --- a/include/functions_search.inc.php +++ b/include/functions_search.inc.php @@ -119,10 +119,34 @@ function get_regular_search_results($search, $images_where='') $image_ids_for_filter = array(); + if (isset($conf['filters_views'])) + { + $display_filters = unserialize($conf['filters_views']); + } + else + { + $display_filters = unserialize('a:14:{s:5:"words";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:1;}s:4:"tags";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:9:"post_date";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:13:"creation_date";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:1;}s:5:"album";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:1;}s:6:"author";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:8:"added_by";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:9:"file_type";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:5:"ratio";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:6:"rating";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:9:"file_size";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:6:"height";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:5:"width";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:17:"last_filters_conf";b:1;}'); + } + + + foreach($display_filters as $filt_name => $filt_conf){ + if(isset($filt_conf['access'])) + { + if ($filt_conf['access'] == 'everybody' or ($filt_conf['access'] == 'admins-only' and is_admin()) or ($filt_conf['access'] == 'registered-users' and is_classic_user())) + { + $display_filters[$filt_name]['access'] = true; + } + else + { + $display_filters[$filt_name]['access'] = false; + } + } + } + // // allwords // - if (isset($search['fields']['allwords']) and !empty($search['fields']['allwords']['words']) and count($search['fields']['allwords']['fields']) > 0) + if (isset($search['fields']['allwords']) and !empty($search['fields']['allwords']['words']) and count($search['fields']['allwords']['fields']) > 0 and $display_filters['words']['access']) { $has_filters_filled = true; @@ -303,7 +327,7 @@ SELECT // // author // - if (isset($search['fields']['author']) and count($search['fields']['author']['words']) > 0) + if (isset($search['fields']['author']) and count($search['fields']['author']['words']) > 0 and $display_filters['author']['access']) { $has_filters_filled = true; @@ -327,7 +351,7 @@ SELECT // // filetypes // - if (!empty($search['fields']['filetypes'])) + if (!empty($search['fields']['filetypes']) and $display_filters['file_type']['access']) { $has_filters_filled = true; @@ -351,7 +375,7 @@ SELECT // // added_by // - if (!empty($search['fields']['added_by'])) + if (!empty($search['fields']['added_by']) and $display_filters['added_by']['access']) { $has_filters_filled = true; @@ -369,7 +393,7 @@ SELECT // // cat // - if (isset($search['fields']['cat']) and !empty($search['fields']['cat']['words'])) + if (isset($search['fields']['cat']) and !empty($search['fields']['cat']['words']) and $display_filters['album']['access']) { $has_filters_filled = true; @@ -403,7 +427,7 @@ SELECT // // date_posted // - if (!empty($search['fields']['date_posted']['preset'])) + if (!empty($search['fields']['date_posted']['preset']) and $display_filters['post_date']['access']) { $has_filters_filled = true; @@ -485,7 +509,7 @@ SELECT // // date_created // - if (!empty($search['fields']['date_created']['preset'])) + if (!empty($search['fields']['date_created']['preset']) and $display_filters['creation_date']['access']) { $has_filters_filled = true; @@ -567,7 +591,7 @@ SELECT // // ratios // - if (!empty($search['fields']['ratios'])) + if (!empty($search['fields']['ratios']) and $display_filters['ratio']['access']) { $has_filters_filled = true; @@ -598,7 +622,7 @@ SELECT // // ratings // - if ($conf['rate'] and !empty($search['fields']['ratings'])) + if ($conf['rate'] and !empty($search['fields']['ratings']) and $display_filters['rating']['access']) { $has_filters_filled = true; @@ -629,7 +653,7 @@ SELECT // // filesize // - if (!empty($search['fields']['filesize_min']) and !empty($search['fields']['filesize_max'])) + if (!empty($search['fields']['filesize_min']) and !empty($search['fields']['filesize_max']) and $display_filters['file_size']['access']) { $has_filters_filled = true; @@ -649,7 +673,7 @@ SELECT // // height // - if (!empty($search['fields']['height_min']) and !empty($search['fields']['height_max'])) + if (!empty($search['fields']['height_min']) and !empty($search['fields']['height_max']) and $display_filters['height']['access']) { $has_filters_filled = true; @@ -667,7 +691,7 @@ SELECT // // width // - if (!empty($search['fields']['width_min']) and !empty($search['fields']['width_max'])) + if (!empty($search['fields']['width_min']) and !empty($search['fields']['width_max']) and $display_filters['width']['access']) { $has_filters_filled = true; @@ -685,7 +709,7 @@ SELECT // // tags // - if (isset($search['fields']['tags']) and !empty($search['fields']['tags']['words'])) + if (isset($search['fields']['tags']) and !empty($search['fields']['tags']['words']) and $display_filters['tags']['access']) { $has_filters_filled = true; diff --git a/include/search_filters.inc.php b/include/search_filters.inc.php index 82e6591c2..adf8c3b65 100644 --- a/include/search_filters.inc.php +++ b/include/search_filters.inc.php @@ -6,11 +6,38 @@ // | file that was distributed with this source code. | // +-----------------------------------------------------------------------+ +if (isset($conf['filters_views'])) +{ + $filters_views = unserialize($conf['filters_views']); +} +else +{ + $filters_views = unserialize('a:14:{s:5:"words";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:1;}s:4:"tags";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:9:"post_date";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:13:"creation_date";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:1;}s:5:"album";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:1;}s:6:"author";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:8:"added_by";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:9:"file_type";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:5:"ratio";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:6:"rating";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:9:"file_size";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:6:"height";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:5:"width";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:17:"last_filters_conf";b:1;}'); +} + +$template->assign('display_filter', $filters_views); + // we add isset($page['search_details']) in this condition because it only // applies to regular search, not the legacy qsearch. As Piwigo 14 will still // be able to show an old quicksearch result, we must check this condtion too. if ('search' == $page['section'] and isset($page['search_details'])) { + $display_filters = $filters_views; + + foreach($filters_views as $filt_name => $filt_conf){ + if(isset($filt_conf['access'])) + { + if ($filt_conf['access'] == 'everybody' or ($filt_conf['access'] == 'admins-only' and is_admin()) or ($filt_conf['access'] == 'registered-users' and is_classic_user())) + { + $display_filters[$filt_name]['access'] = true; + } + else + { + $display_filters[$filt_name]['access'] = false; + } + } + } + include_once(PHPWG_ROOT_PATH.'include/functions_search.inc.php'); $my_search = get_search_array($page['search']); @@ -40,7 +67,12 @@ if ('search' == $page['section'] and isset($page['search_details'])) $search_items_clause = '1=1'; } - if (isset($my_search['fields']['tags'])) + if (isset($my_search['fields']['allwords']) and !($display_filters['words']['access'])) + { + unset($my_search['fields']['allwords']); + } + + if (isset($my_search['fields']['tags']) and $display_filters['tags']['access']) { $filter_tags = array(); @@ -77,7 +109,12 @@ if ('search' == $page['section'] and isset($page['search_details'])) $my_search['fields']['tags']['words'] = array_intersect($my_search['fields']['tags']['words'], $filter_tag_ids); } - if (isset($my_search['fields']['author'])) + else if (isset($my_search['fields']['tags']) and !($display_filters['tags']['access'])) + { + unset($my_search['fields']['tags']); + } + + if (isset($my_search['fields']['author']) and $display_filters['author']['access']) { $filter_clause = get_clause_for_filter('author'); @@ -118,7 +155,12 @@ SELECT $my_search['fields']['author']['words'] = array_intersect($my_search['fields']['author']['words'], $author_names); } - if (isset($my_search['fields']['date_posted'])) + else if (isset($my_search['fields']['author']) and !($display_filters['author']['access'])) + { + unset($my_search['fields']['author']); + } + + if (isset($my_search['fields']['date_posted']) and $display_filters['post_date']['access']) { $filter_clause = get_clause_for_filter('date_posted'); $cache_key = $persistent_cache->make_key('filter_date_posted'.$user['id'].$user['cache_update_time']); @@ -220,7 +262,12 @@ SELECT $template->assign('DATE_POSTED', $counters); } - if (isset($my_search['fields']['date_created'])) + else if (isset($my_search['fields']['date_posted']) and !($display_filters['post_date']['access'])) + { + unset($my_search['fields']['date_posted']); + } + + if (isset($my_search['fields']['date_created']) and $display_filters['creation_date']['access']) { $filter_clause = get_clause_for_filter('date_created'); $cache_key = $persistent_cache->make_key('filter_date_created'.$user['id'].$user['cache_update_time']); @@ -324,8 +371,12 @@ SELECT $template->assign('DATE_CREATED', $counters); } + else if (isset($my_search['fields']['date_created']) and !($display_filters['creation_date']['access'])) + { + unset($my_search['fields']['date_created']); + } - if (isset($my_search['fields']['added_by'])) + if (isset($my_search['fields']['added_by']) and $display_filters['added_by']['access']) { $filter_clause = get_clause_for_filter('added_by'); @@ -388,11 +439,18 @@ SELECT $my_search['fields']['added_by'] = array_intersect($my_search['fields']['added_by'], $user_ids); } - if (isset($my_search['fields']['cat']) and !empty($my_search['fields']['cat']['words'])) + else if (isset($my_search['fields']['added_by']) and !($display_filters['added_by']['access'])) { - $fullname_of = array(); + unset($my_search['fields']['added_by']); + } - $query = ' + if (isset($my_search['fields']['cat']) and $display_filters['album']['access']) + { + if (!empty($my_search['fields']['cat']['words'])) + { + $fullname_of = array(); + + $query = ' SELECT id, uppercats @@ -400,26 +458,32 @@ SELECT INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' ON id = cat_id AND user_id = '.$user['id'].' WHERE id IN ('.implode(',', $my_search['fields']['cat']['words']).') ;'; - $result = pwg_query($query); + $result = pwg_query($query); - while ($row = pwg_db_fetch_assoc($result)) - { - $cat_display_name = get_cat_display_name_cache( - $row['uppercats'], - 'admin.php?page=album-' // TODO not sure it's relevant to link to admin pages - ); - $row['fullname'] = strip_tags($cat_display_name); + while ($row = pwg_db_fetch_assoc($result)) + { + $cat_display_name = get_cat_display_name_cache( + $row['uppercats'], + 'admin.php?page=album-' // TODO not sure it's relevant to link to admin pages + ); + $row['fullname'] = strip_tags($cat_display_name); - $fullname_of[$row['id']] = $row['fullname']; + $fullname_of[$row['id']] = $row['fullname']; + } + + $template->assign('fullname_of', json_encode($fullname_of)); + + // in case the search has forbidden albums for current user, we need to filter the search rule + $my_search['fields']['cat']['words'] = array_intersect($my_search['fields']['cat']['words'], array_keys($fullname_of)); } - - $template->assign('fullname_of', json_encode($fullname_of)); - - // in case the search has forbidden albums for current user, we need to filter the search rule - $my_search['fields']['cat']['words'] = array_intersect($my_search['fields']['cat']['words'], array_keys($fullname_of)); } - if (isset($my_search['fields']['filetypes'])) + else if (isset($my_search['fields']['cat']) and !($display_filters['album']['access'])) + { + unset($my_search['fields']['cat']); + } + + if (isset($my_search['fields']['filetypes']) and $display_filters['file_type']['access']) { $filter_clause = get_clause_for_filter('filetypes'); @@ -469,12 +533,17 @@ SELECT } } + else if (isset($my_search['fields']['filetypes']) and !($display_filters['file_type']['access'])) + { + unset($my_search['fields']['filetypes']); + } + // For rating if ($conf['rate']) { $template->assign('SHOW_FILTER_RATINGS', true); - if (isset($my_search['fields']['ratings'])) + if (isset($my_search['fields']['ratings']) and $display_filters['rating']['access']) { $filter_clause = get_clause_for_filter('ratings'); @@ -529,14 +598,22 @@ SELECT } $template->assign('RATING', $ratings); } + else if (isset($my_search['fields']['ratings']) and !($display_filters['rating']['access'])) + { + unset($my_search['fields']['ratings']); + } } else { $template->assign('SHOW_FILTER_RATINGS', false); + if (isset($my_search['fields']['ratings'])) + { + unset($my_search['fields']['ratings']); + } } // For filesize - if (isset($my_search['fields']['filesize_min']) && isset($my_search['fields']['filesize_max'])) + if (isset($my_search['fields']['filesize_min']) && isset($my_search['fields']['filesize_max']) and $display_filters['file_size']['access']) { $filter_clause = get_clause_for_filter('filesize'); @@ -582,8 +659,14 @@ SELECT $template->assign('FILESIZE', $filesize ); } + + else if (isset($my_search['fields']['filesize_min']) && isset($my_search['fields']['filesize_max']) and !($display_filters['file_size']['access'])) + { + unset($my_search['fields']['filesize_min']); + unset($my_search['fields']['filesize_max']); + } - if (isset($my_search['fields']['ratios'])) + if (isset($my_search['fields']['ratios']) and $display_filters['ratio']['access']) { $filter_clause = get_clause_for_filter('ratios'); @@ -648,11 +731,15 @@ SELECT $persistent_cache->set($cache_key, $ratios); } } - $template->assign('RATIOS', $ratios); } - if (isset($my_search['fields']['height_min']) and isset($my_search['fields']['height_max'])) + else if (isset($my_search['fields']['ratios']) and !($display_filters['ratio']['access'])) + { + unset($my_search['fields']['ratios']); + } + + if (isset($my_search['fields']['height_min']) and isset($my_search['fields']['height_max']) and $display_filters['height']['access']) { $filter_clause = get_clause_for_filter('height'); @@ -699,7 +786,13 @@ SELECT $template->assign('HEIGHT', $height); } - if (isset($my_search['fields']['width_min']) and isset($my_search['fields']['width_max'])) + else if (isset($my_search['fields']['height_min']) && isset($my_search['fields']['height_max']) and !($display_filters['height']['access'])) + { + unset($my_search['fields']['height_min']); + unset($my_search['fields']['height_max']); + } + + if (isset($my_search['fields']['width_min']) and isset($my_search['fields']['width_max']) and $display_filters['width']['access']) { $filter_clause = get_clause_for_filter('width'); @@ -746,6 +839,12 @@ SELECT $template->assign('WIDTH', $width); } + else if (isset($my_search['fields']['width_min']) && isset($my_search['fields']['width_max']) and !($display_filters['width']['access'])) + { + unset($my_search['fields']['width_min']); + unset($my_search['fields']['width_max']); + } + $template->assign( array( 'GP' => json_encode($my_search), diff --git a/install/config.sql b/install/config.sql index 1dc6915ea..d2e9ede61 100644 --- a/install/config.sql +++ b/install/config.sql @@ -80,3 +80,4 @@ INSERT INTO piwigo_config (param,value) VALUES ('index_search_in_set_action','tr INSERT INTO piwigo_config (param,value) VALUES ('upload_detect_duplicate','true'); INSERT INTO piwigo_config (param,value) VALUES ('webmaster_id','1'); INSERT INTO piwigo_config (param,value) VALUES ('use_standard_pages','true'); +INSERT INTO piwigo_config (param,value,comment) VALUES ('filters_views','a:14:{s:5:"words";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:1;}s:4:"tags";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:9:"post_date";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:13:"creation_date";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:1;}s:5:"album";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:1;}s:6:"author";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:8:"added_by";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:9:"file_type";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:5:"ratio";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:6:"rating";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:9:"file_size";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:6:"height";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:5:"width";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:17:"last_filters_conf";b:1;}','Filters displays configuration'); diff --git a/install/db/178-database.php b/install/db/178-database.php new file mode 100644 index 000000000..9aa85dece --- /dev/null +++ b/install/db/178-database.php @@ -0,0 +1,24 @@ + diff --git a/search.php b/search.php index 0b81d86f7..c7391b3f7 100644 --- a/search.php +++ b/search.php @@ -28,9 +28,49 @@ $search = array( ); // list of filters in user preferences -// allwords, cat, tags, author, added_by, filetypes, date_posted -$default_fields = array('allwords', 'cat', 'tags', 'author'); -if (is_a_guest() or is_generic()) +// allwords, cat, tags, author, added_by, filetypes, date_posted, date_created, ratios, ratings (if rating is allowed in this Piwigo), height, width +//import the conf for the filters +if (isset($conf['filters_views'])) +{ + $filters_conf = unserialize($conf['filters_views']); +} +else +{ + $filters_conf = unserialize('a:14:{s:5:"words";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:1;}s:4:"tags";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:9:"post_date";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:13:"creation_date";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:1;}s:5:"album";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:1;}s:6:"author";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:8:"added_by";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:9:"file_type";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:5:"ratio";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:6:"rating";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:9:"file_size";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:6:"height";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:5:"width";a:2:{s:6:"access";s:9:"everybody";s:7:"default";b:0;}s:17:"last_filters_conf";b:1;}'); +} + +//change the name of the keys so that they can be used with this part of the program +$filters_conf = array_combine +( + array('allwords', + 'tags', + 'date_posted', + 'date_created', + 'cat', + 'author', + 'added_by', + 'filetypes', + 'ratios', + 'ratings', + 'filesize', + 'height', + 'width', + 'last_filters_conf' + ), + $filters_conf +); + +//get all default filters +$default_fields = array(); +foreach($filters_conf as $filt_name => $filt_conf){ + if(isset($filt_conf['default'])){ + if($filt_conf['default'] == true){ + $default_fields[] = $filt_name; + } + } +} + +if (is_a_guest() or is_generic() or $filters_conf['last_filters_conf']==false) { $fields = $default_fields; } @@ -131,7 +171,7 @@ SELECT } } -foreach (array('added_by', 'filetypes', 'date_posted') as $field) +foreach (array('added_by', 'filetypes', 'ratios', 'ratings') as $field) { if (in_array($field, $fields)) { @@ -139,6 +179,23 @@ foreach (array('added_by', 'filetypes', 'date_posted') as $field) } } +foreach (array('date_posted', 'date_created') as $field){ + if (in_array($field, $fields)) + { + $search['fields'][$field] = array( + 'preset' => '' + ); + } +} + +foreach (array('filesize_min', 'filesize_max', 'width_min', 'width_max', 'height_min', 'height_max') as $field) +{ + if (in_array($field, $fields)) + { + $search['fields'][$field] = ''; + } +} + list($search_uuid, $search_url) = save_search($search); redirect($search_url); ?> diff --git a/themes/default/js/mcs.js b/themes/default/js/mcs.js index ec20466ee..d1aa9f0cb 100644 --- a/themes/default/js/mcs.js +++ b/themes/default/js/mcs.js @@ -33,6 +33,8 @@ $(document).ready(function () { PS_params.search_id = search_id; empty_filters_list = []; + filters_to_remove = []; + // Setup word filter if (global_params.fields.allwords) { $(".filter-word").css("display", "flex"); @@ -76,6 +78,7 @@ $(document).ready(function () { empty_filters_list.push(PS_params.allwords); } + //Hide filter spinner $(".filter-spinner").hide(); @@ -87,7 +90,7 @@ $(document).ready(function () { items: global_params.fields.tags ? global_params.fields.tags.words : null, }); }); - + if (global_params.fields.tags) { $(".filter-tag").css("display", "flex"); $(".filter-manager-controller.tags").prop("checked", true); @@ -569,17 +572,13 @@ $(document).ready(function () { empty_filters_list.push(PS_params.ratings); } - else if (!show_filter_ratings) - { - updateFilters('ratings', 'add'); - } // Setup filesize filter if (global_params.fields.filesize_min != null && global_params.fields.filesize_max != null) { $(".filter-filesize").css("display", "flex"); $(".filter-manager-controller.filesize").prop("checked", true); - $(".filter.filter-filesize .slider-info").html(sprintf(sliders.filesizes.text,sliders.filesizes.selected.min,sliders.filesizes.selected.max,)); + $(".filter.filter-filesize .slider-info").html(sprintf(sliders.filesizes.text,sliders.filesizes.selected.min,sliders.filesizes.selected.max)); $('[data-slider=filesizes]').pwgDoubleSlider(sliders.filesizes); @@ -594,7 +593,7 @@ $(document).ready(function () { if( global_params.fields.filesize_min != null && global_params.fields.filesize_max > 0) { $(".filter-filesize").addClass("filter-filled"); - $(".filter.filter-filesize .search-words").html(sprintf(sliders.filesizes.text,sliders.filesizes.selected.min,sliders.filesizes.selected.max,)); + $(".filter.filter-filesize .search-words").html(sprintf(sliders.filesizes.text,sliders.filesizes.selected.min,sliders.filesizes.selected.max)); } else { @@ -622,13 +621,13 @@ $(document).ready(function () { if (global_params.fields.height_min != null && global_params.fields.height_max != null) { $(".filter-height").css("display", "flex"); $(".filter-manager-controller.height").prop("checked", true); - $(".filter.filter-height .slider-info").html(sprintf(sliders.heights.text,sliders.heights.selected.min,sliders.heights.selected.max,)); + $(".filter.filter-height .slider-info").html(sprintf(sliders.heights.text,sliders.heights.selected.min,sliders.heights.selected.max)); $('[data-slider=heights]').pwgDoubleSlider(sliders.heights); if( global_params.fields.height_min > 0 && global_params.fields.height_max > 0) { $(".filter-height").addClass("filter-filled"); - $(".filter.filter-height .search-words").html(sprintf(sliders.heights.text,sliders.heights.selected.min,sliders.heights.selected.max,)); + $(".filter.filter-height .search-words").html(sprintf(sliders.heights.text,sliders.heights.selected.min,sliders.heights.selected.max)); } else { @@ -656,13 +655,13 @@ $(document).ready(function () { if (global_params.fields.width_min != null && global_params.fields.width_max != null) { $(".filter-width").css("display", "flex"); $(".filter-manager-controller.width").prop("checked", true); - $(".filter.filter-width .slider-info").html(sprintf(sliders.widths.text,sliders.widths.selected.min,sliders.widths.selected.max,)); + $(".filter.filter-width .slider-info").html(sprintf(sliders.widths.text,sliders.widths.selected.min,sliders.widths.selected.max)); $('[data-slider=widths]').pwgDoubleSlider(sliders.widths); if( global_params.fields.width_min > 0 && global_params.fields.width_max > 0) { $(".filter-width").addClass("filter-filled"); - $(".filter.filter-width .search-words").html(sprintf(sliders.widths.text,sliders.widths.selected.min,sliders.widths.selected.max,)); + $(".filter.filter-width .search-words").html(sprintf(sliders.widths.text,sliders.widths.selected.min,sliders.widths.selected.max)); } else { @@ -686,6 +685,10 @@ $(document).ready(function () { empty_filters_list.push(PS_params.width_max); } + if(filters_to_remove.length > 0){ + filters_to_remove = []; + performSearch(PS_params, true); + } // Adapt no result message if ($(".filter-filled").length === 0) { @@ -693,7 +696,7 @@ $(document).ready(function () { $(".mcs-no-result .text .bot").html(str_empty_search_bot_alt); } - if (!empty_filters_list.every(param => param === "" || param === null)) { + if (!empty_filters_list.every(param => param === "" || param === null || (typeof param == 'undefined'))) { $(".clear-all").addClass("clickable"); $(".clear-all.clickable").on('click', function () { exclude_params = ['search_id', 'allwords_mode', 'allwords_fields', 'tags_mode', 'categories_withsubs']; diff --git a/themes/default/template/include/search_filters.inc.tpl b/themes/default/template/include/search_filters.inc.tpl index c1a5ff012..5eeb49575 100644 --- a/themes/default/template/include/search_filters.inc.tpl +++ b/themes/default/template/include/search_filters.inc.tpl @@ -23,6 +23,14 @@ fullname_of_cat = {$fullname_of}; search_id = '{$SEARCH_ID}'; {/if} +{if is_admin()} +user_rank = "admin"; +{elseif is_classic_user()} +user_rank = "user"; +{else} +user_rank = "none"; +{/if} + str_word_widget_label = "{'Search for words'|@translate|escape:javascript}"; str_tags_widget_label = "{'Tag'|@translate|escape:javascript}"; str_album_widget_label = "{'Album'|@translate|escape:javascript}"; @@ -101,60 +109,86 @@ const prefix_icon = 'gallery-icon-';
{'Choose filters'|@translate}
+ {if $display_filter.words.access == 'everybody' or ($display_filter.words.access == 'admins-only' and is_admin()) or ($display_filter.words.access == 'registered-users' and is_classic_user())} + {/if} + {if $display_filter.tags.access == 'everybody' or ($display_filter.tags.access == 'admins-only' and is_admin()) or ($display_filter.tags.access == 'registered-users' and is_classic_user())} + {/if} + {if $display_filter.post_date.access == 'everybody' or ($display_filter.post_date.access == 'admins-only' and is_admin()) or ($display_filter.post_date.access == 'registered-users' and is_classic_user())} + {/if} + {if $display_filter.creation_date.access == 'everybody' or ($display_filter.creation_date.access == 'admins-only' and is_admin()) or ($display_filter.creation_date.access == 'registered-users' and is_classic_user())} + {/if} + {if $display_filter.album.access == 'everybody' or ($display_filter.album.access == 'admins-only' and is_admin()) or ($display_filter.album.access == 'registered-users' and is_classic_user())} + {/if} + {if $display_filter.author.access == 'everybody' or ($display_filter.author.access == 'admins-only' and is_admin()) or ($display_filter.author.access == 'registered-users' and is_classic_user())} + {/if} + {if $display_filter.added_by.access == 'everybody' or ($display_filter.added_by.access == 'admins-only' and is_admin()) or ($display_filter.added_by.access == 'registered-users' and is_classic_user())} + {/if} + {if $display_filter.file_type.access == 'everybody' or ($display_filter.file_type.access == 'admins-only' and is_admin()) or ($display_filter.file_type.access == 'registered-users' and is_classic_user())} + {/if} + {if $display_filter.ratio.access == 'everybody' or ($display_filter.ratio.access == 'admins-only' and is_admin()) or ($display_filter.ratio.access == 'registered-users' and is_classic_user())} + {/if} {if $SHOW_FILTER_RATINGS and isset($SHOW_FILTER_RATINGS)} + {if $display_filter.rating.access == 'everybody' or ($display_filter.rating.access == 'admins-only' and is_admin()) or ($display_filter.rating.access == 'registered-users' and is_classic_user())} + {/if} {/if} + {if $display_filter.file_size.access == 'everybody' or ($display_filter.file_size.access == 'admins-only' and is_admin()) or ($display_filter.file_size.access == 'registered-users' and is_classic_user())} + {/if} + {if $display_filter.height.access == 'everybody' or ($display_filter.height.access == 'admins-only' and is_admin()) or ($display_filter.height.access == 'registered-users' and is_classic_user())} + {/if} + {if $display_filter.width.access == 'everybody' or ($display_filter.width.access == 'admins-only' and is_admin()) or ($display_filter.width.access == 'registered-users' and is_classic_user())} + {/if}