fix(admin): replicate reference advanced-filter settings page 1:1
- Rewrite post_list/filter schema (PHP + JS) with the reference theme's
field set, order, defaults and dependencies; topics fields excluded
(no topics taxonomy), AKSRT private filter_* toggles dropped
- Support dynamic checkbox options in AksField (options as formData key)
so cat_custom_filter.custom_filters lists the custom_filter dimensions
- Map PostDisplay filter settings to the new keys without legacy fallback;
cat_custom_filter now carries lists/dropdown fieldsets and array filters
- Wire the archive chain to reference semantics: cat_custom_filter
overrides per-category filter projects, custom_filter_show gates the
default display, dimension chip groups render on category/tag archives
- Filter archive queries (main query + AJAX endpoint) by _aksrt_cf_{key}
meta with exact-quoted LIKE matching
- Add advanced-filter settings reference contract test
This commit is contained in:
@@ -108,6 +108,7 @@ class GlobalController extends ControllerBase {
|
||||
'term_id' => ['type' => 'integer', 'default' => 0, 'sanitize_callback' => 'absint'],
|
||||
'filter_cat' => ['type' => 'string', 'default' => '', 'sanitize_callback' => 'sanitize_text_field'],
|
||||
'filter_tag' => ['type' => 'string', 'default' => '', 'sanitize_callback' => 'sanitize_text_field'],
|
||||
'custom_filter' => ['type' => 'string', 'default' => '', 'sanitize_callback' => 'sanitize_text_field'],
|
||||
'sort' => ['type' => 'string', 'default' => 'date', 'sanitize_callback' => 'sanitize_key'],
|
||||
'page' => ['type' => 'integer', 'default' => 1, 'sanitize_callback' => 'absint'],
|
||||
],
|
||||
@@ -209,6 +210,44 @@ class GlobalController extends ControllerBase {
|
||||
if ($tax_query !== []) {
|
||||
$args['tax_query'] = $tax_query;
|
||||
}
|
||||
|
||||
// 自定义高级筛选维度(custom_filter=JSON {dim_key:value};参考主题 meta_query LIKE 语义)。
|
||||
$custom_raw = (string) $request->get_param('custom_filter');
|
||||
$custom = $custom_raw !== '' ? json_decode($custom_raw, true) : [];
|
||||
if (is_array($custom) && $custom !== []) {
|
||||
$filter_cfg = \AKSRT\Settings\Settings::get_post_filter_settings();
|
||||
$allowed = [];
|
||||
foreach ($filter_cfg['custom_filter'] as $dimension) {
|
||||
$dim_key = sanitize_key((string) ($dimension['key'] ?? ''));
|
||||
if ($dim_key === '') {
|
||||
continue;
|
||||
}
|
||||
$vals = [];
|
||||
foreach ((array) ($dimension['vals'] ?? []) as $val) {
|
||||
$vkey = sanitize_key((string) ($val['key'] ?? ''));
|
||||
if ($vkey !== '') {
|
||||
$vals[] = $vkey;
|
||||
}
|
||||
}
|
||||
$allowed[$dim_key] = $vals;
|
||||
}
|
||||
$meta_query = [];
|
||||
foreach ($custom as $dim_key => $dim_value) {
|
||||
$dim_key = sanitize_key((string) $dim_key);
|
||||
$dim_value = sanitize_key((string) $dim_value);
|
||||
if ($dim_key === '' || $dim_value === '' || !isset($allowed[$dim_key]) || !in_array($dim_value, $allowed[$dim_key], true)) {
|
||||
continue;
|
||||
}
|
||||
$meta_query[] = [
|
||||
'key' => '_aksrt_cf_' . $dim_key,
|
||||
'value' => '"' . $dim_value . '"',
|
||||
'compare' => 'LIKE',
|
||||
];
|
||||
}
|
||||
if ($meta_query !== []) {
|
||||
$args['meta_query'] = $meta_query;
|
||||
}
|
||||
}
|
||||
if (function_exists('aksrt_homepage_apply_named_sort_args')) {
|
||||
$args = aksrt_homepage_apply_named_sort_args($args, $sort);
|
||||
}
|
||||
|
||||
@@ -129,43 +129,49 @@ class SchemaPostList {
|
||||
'filter' => [
|
||||
'key' => 'filter',
|
||||
'title' => '高级筛选',
|
||||
'version' => '1.0.0',
|
||||
'version' => '2.0.0',
|
||||
'option_key' => 'aksrt_settings',
|
||||
'groups' => [
|
||||
['key' => 'basic', 'title' => '筛选基础', 'fields' => [
|
||||
['key' => 'filter_enabled', 'label' => '启用筛选栏', 'type' => 'switch', 'default' => false],
|
||||
['key' => 'custom_filter_show', 'label' => '筛选显示页面', 'type' => 'checkbox', 'default' => ['cat', 'tag'], 'options' => [
|
||||
['label' => '分类页', 'value' => 'cat'],
|
||||
['label' => '标签页', 'value' => 'tag'],
|
||||
], 'help' => '选择在哪些页面显示筛选栏'],
|
||||
['key' => 'filter_categories', 'label' => '分类筛选', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'filter_tags', 'label' => '标签筛选', 'type' => 'switch', 'default' => false],
|
||||
['key' => 'filter_sort', 'label' => '排序选项', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'filter_ajax_enabled', 'label' => 'AJAX 无刷新筛选', 'type' => 'switch', 'default' => true, 'help' => '启用后分类/标签/排序切换将通过 AJAX 加载,无需刷新页面'],
|
||||
]],
|
||||
['key' => 'ajax_dimensions', 'title' => 'AJAX 筛选维度', 'fields' => [
|
||||
['key' => 'filter_cat_show_cat', 'label' => '分类页:显示分类筛选', 'type' => 'switch', 'default' => true, 'dependsOn' => ['key' => 'filter_enabled', 'value' => true]],
|
||||
['key' => 'filter_cat_show_tag', 'label' => '分类页:显示标签筛选', 'type' => 'switch', 'default' => false, 'dependsOn' => ['key' => 'filter_enabled', 'value' => true]],
|
||||
['key' => 'filter_tag_show_cat', 'label' => '标签页:显示分类筛选', 'type' => 'switch', 'default' => true, 'dependsOn' => ['key' => 'filter_enabled', 'value' => true]],
|
||||
['key' => 'filter_tag_show_tag', 'label' => '标签页:显示标签筛选', 'type' => 'switch', 'default' => false, 'dependsOn' => ['key' => 'filter_enabled', 'value' => true]],
|
||||
]],
|
||||
['key' => 'custom_filter', 'title' => '自定义筛选维度', 'fields' => [
|
||||
['key' => 'custom_filter', 'label' => '筛选维度定义', 'type' => 'repeater', 'default' => [], 'dependsOn' => ['key' => 'filter_enabled', 'value' => true], 'help' => '每项定义一个筛选维度(如"类型""地区""年份"),及其可选值列表', 'fields' => [
|
||||
['key' => 'name', 'label' => '维度名称', 'type' => 'input', 'default' => ''],
|
||||
['key' => 'key', 'label' => '维度标识', 'type' => 'input', 'default' => ''],
|
||||
['key' => 'vals', 'label' => '可选值', 'type' => 'repeater', 'default' => [], 'fields' => [
|
||||
['key' => 'key', 'label' => '标识', 'type' => 'input', 'default' => ''],
|
||||
['key' => 'name', 'label' => '显示名', 'type' => 'input', 'default' => ''],
|
||||
['key' => 'advanced_filter', 'title' => '高级筛选', 'fields' => [
|
||||
['key' => 'custom_filter_show', 'label' => '高级筛选默认显示', 'type' => 'checkbox', 'default' => [], 'options' => [
|
||||
['label' => '分类页面显示', 'value' => 'cat'],
|
||||
['label' => '标签页面显示', 'value' => 'tag'],
|
||||
], 'description' => '勾选后将会在对应页面默认显示全部筛选,您可以在下方为单独的分类添加自定义筛选'],
|
||||
['key' => 'custom_filter', 'label' => '自定义高级筛选明细', 'type' => 'repeater', 'default' => [], 'addText' => '添加筛选类别', 'description' => '添加筛选类型及明细', 'fields' => [
|
||||
['key' => 'name', 'label' => '类型名称', 'type' => 'input', 'default' => ''],
|
||||
['key' => 'key', 'label' => '类型key', 'type' => 'input', 'default' => '', 'description' => '必填,只能使用英文加下划线,不能有空格!尽量复杂一点,且配置唯一前缀,以避免与其他mate_key重复,例如(axb_type,axb_year)'],
|
||||
['key' => 'vals', 'label' => '可选择的值', 'type' => 'repeater', 'default' => [], 'addText' => '添加值', 'fields' => [
|
||||
['key' => 'key', 'label' => '值', 'type' => 'input', 'default' => ''],
|
||||
['key' => 'name', 'label' => '显示名称', 'type' => 'input', 'default' => ''],
|
||||
]],
|
||||
]],
|
||||
]],
|
||||
['key' => 'cat_custom_filter', 'title' => '按分类绑定筛选', 'fields' => [
|
||||
['key' => 'cat_custom_filter', 'label' => '分类筛选绑定', 'type' => 'repeater', 'default' => [], 'dependsOn' => ['key' => 'filter_enabled', 'value' => true], 'help' => '为指定分类绑定不同的筛选维度组合', 'fields' => [
|
||||
['key' => 'cats', 'label' => '绑定分类', 'type' => 'taxonomy_select', 'taxonomy' => 'category', 'multiple' => true, 'default' => []],
|
||||
['key' => 'cat_s', 'label' => '显示分类筛选', 'type' => 'switch', 'default' => false],
|
||||
['key' => 'tag_s', 'label' => '显示标签筛选', 'type' => 'switch', 'default' => false],
|
||||
['key' => 'orderby_s', 'label' => '显示排序按钮', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'custom_filters', 'label' => '启用的自定义维度', 'type' => 'input', 'default' => '', 'help' => '逗号分隔维度标识,留空使用全部'],
|
||||
['key' => 'cat_custom_filter', 'label' => '自定义分类的高级筛选', 'type' => 'repeater', 'default' => [], 'addText' => '添加自定义分类筛选', 'description' => '在此处为不同的分类添加不同的筛选项目,实现更加精细化的筛选。同时你也可以在页面显示/分类页面设置分类的默认筛选方式', 'fields' => [
|
||||
['key' => 'cats', 'label' => '绑定分类', 'type' => 'taxonomy_select', 'taxonomy' => 'category', 'multiple' => true, 'default' => [], 'description' => '支持添加多个分类'],
|
||||
['key' => 'cat_s', 'label' => '分类筛选', 'type' => 'switch', 'default' => false, 'description' => '在所选分类页显示的分类筛选列表'],
|
||||
['key' => 'cat_lists', 'label' => ' ', 'type' => 'fieldset', 'default' => ['lists' => [], 'dropdown' => false], 'dependsOn' => ['key' => 'cat_s', 'value' => true], 'fields' => [
|
||||
['key' => 'lists', 'label' => '按钮列表', 'type' => 'async_select', 'source' => 'categories', 'multiple' => true, 'sortable' => true, 'default' => [], 'description' => '选择并排序需要显示的按钮,建议选择同级内容,会自动获取二级三级内容。所选按钮内没有文章则不会显示'],
|
||||
['key' => 'dropdown', 'label' => '下拉列表', 'type' => 'switch', 'default' => false, 'description' => '用下拉框显示更多内容'],
|
||||
]],
|
||||
['key' => 'tag_s', 'label' => '标签筛选', 'type' => 'switch', 'default' => false, 'description' => '在所选分类页显示的标签筛选列表'],
|
||||
['key' => 'tag_lists', 'label' => ' ', 'type' => 'fieldset', 'default' => ['lists' => [], 'dropdown' => false], 'dependsOn' => ['key' => 'tag_s', 'value' => true], 'fields' => [
|
||||
['key' => 'lists', 'label' => '按钮列表', 'type' => 'async_select', 'source' => 'tags', 'multiple' => true, 'sortable' => true, 'default' => [], 'description' => '选择并排序需要显示的按钮'],
|
||||
['key' => 'dropdown', 'label' => '下拉列表', 'type' => 'switch', 'default' => false, 'description' => '用下拉框显示更多内容'],
|
||||
]],
|
||||
['key' => 'orderby_s', 'label' => '排序方式', 'type' => 'switch', 'default' => true, 'description' => '在所选分类页显示排序方式按钮'],
|
||||
['key' => 'orderby_lists', 'label' => ' ', 'type' => 'fieldset', 'default' => ['lists' => ['modified', 'views', 'like', 'comment_count'], 'dropdown' => false], 'dependsOn' => ['key' => 'orderby_s', 'value' => true], 'fields' => [
|
||||
['key' => 'lists', 'label' => '显示排序方式', 'type' => 'select', 'multiple' => true, 'sortable' => true, 'default' => ['modified', 'views', 'like', 'comment_count'], 'options' => [
|
||||
['label' => '更新', 'value' => 'modified'],
|
||||
['label' => '发布', 'value' => 'date'],
|
||||
['label' => '浏览', 'value' => 'views'],
|
||||
['label' => '点赞', 'value' => 'like'],
|
||||
['label' => '评论', 'value' => 'comment_count'],
|
||||
['label' => '收藏', 'value' => 'favorite'],
|
||||
['label' => '随机', 'value' => 'rand'],
|
||||
], 'description' => '选择需要的排序方式按钮'],
|
||||
['key' => 'dropdown', 'label' => '更多排序方式', 'type' => 'switch', 'default' => false, 'description' => '用下拉框显示全部排序方式'],
|
||||
]],
|
||||
// custom_filters 的 options 为运行时动态来源(custom_filter 维度定义),前端按 formData 解析。
|
||||
['key' => 'custom_filters', 'label' => '自定义高级筛选', 'type' => 'checkbox', 'default' => [], 'options' => [], 'description' => '在所选分类页显示的自定义高级筛选项目。如果此处没有选项,或者您修改了上方的文章高级筛选明细,请先保存主题配置并刷新页面后再设置此处'],
|
||||
]],
|
||||
]],
|
||||
],
|
||||
|
||||
+65
-8
@@ -104,21 +104,54 @@ class TermMeta {
|
||||
$description = (string) $term->description;
|
||||
}
|
||||
|
||||
// 高级筛选(参考主题 zib-category.php 语义):cat 页按 cat_custom_filter 全量覆盖
|
||||
// 筛选项目,未匹配或 tag 页回退默认配置,custom_filter_show 决定自定义筛选显示。
|
||||
$page = $taxonomy === 'post_tag' ? 'tag' : 'cat';
|
||||
$custom_filter = class_exists('\AKSRT\Settings\Settings')
|
||||
? \AKSRT\Settings\Settings::get_archive_custom_filter_config((int) $term->term_id, $page)
|
||||
: ['custom_enabled' => false, 'custom_filters' => 'all', 'overrides' => []];
|
||||
$overrides = is_array($custom_filter['overrides'] ?? null) ? $custom_filter['overrides'] : [];
|
||||
|
||||
$ajax_category_enabled = !empty($global['ajax_category_enabled']);
|
||||
$ajax_category = is_array($global['ajax_category'] ?? null) ? $global['ajax_category'] : [];
|
||||
$ajax_tag_enabled = !empty($global['ajax_tag_enabled']);
|
||||
$ajax_tag = is_array($global['ajax_tag'] ?? null) ? $global['ajax_tag'] : [];
|
||||
$orderby_enabled = !empty($global['orderby_enabled']);
|
||||
$orderby_option = is_array($global['orderby_option'] ?? null) ? $global['orderby_option'] : [];
|
||||
if (array_key_exists('cat_s', $overrides)) {
|
||||
$ajax_category_enabled = !empty($overrides['cat_s']);
|
||||
$ajax_category = is_array($overrides['cat_lists'] ?? null) ? $overrides['cat_lists'] : $ajax_category;
|
||||
}
|
||||
if (array_key_exists('tag_s', $overrides)) {
|
||||
$ajax_tag_enabled = !empty($overrides['tag_s']);
|
||||
$ajax_tag = is_array($overrides['tag_lists'] ?? null) ? $overrides['tag_lists'] : $ajax_tag;
|
||||
}
|
||||
if (array_key_exists('orderby_s', $overrides)) {
|
||||
$orderby_enabled = !empty($overrides['orderby_s']);
|
||||
$orderby_option = is_array($overrides['orderby_lists'] ?? null) ? $overrides['orderby_lists'] : $orderby_option;
|
||||
}
|
||||
$orderby = sanitize_key((string) ($orderby_option['lists'][0] ?? $global['orderby'] ?? 'date'));
|
||||
|
||||
$filter_all = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_post_filter_settings() : [];
|
||||
|
||||
return [
|
||||
'taxonomy' => $taxonomy,
|
||||
'header_style' => $header_style,
|
||||
'show_sidebar' => $sidebar_enabled,
|
||||
'show_cover' => $header_style === 'cover' && !empty($global['cover_enabled']) && $cover_url !== '',
|
||||
'show_desc' => $taxonomy === 'post_tag' ? $description !== '' : (!empty($global['desc_enabled']) && $description !== ''),
|
||||
'filter_bar' => !empty($global['filter_bar']),
|
||||
'filter_bar' => !empty($global['filter_bar']) || $ajax_category_enabled || $ajax_tag_enabled || $orderby_enabled || !empty($custom_filter['custom_enabled']),
|
||||
'post_count' => !empty($global['post_count']),
|
||||
'orderby_enabled' => !empty($global['orderby_enabled']),
|
||||
'orderby' => sanitize_key((string) ($global['orderby'] ?? 'date')),
|
||||
'orderby_option'=> is_array($global['orderby_option'] ?? null) ? $global['orderby_option'] : [],
|
||||
'ajax_category_enabled' => !empty($global['ajax_category_enabled']),
|
||||
'ajax_tag_enabled' => !empty($global['ajax_tag_enabled']),
|
||||
'ajax_category' => is_array($global['ajax_category'] ?? null) ? $global['ajax_category'] : [],
|
||||
'ajax_tag' => is_array($global['ajax_tag'] ?? null) ? $global['ajax_tag'] : [],
|
||||
'orderby_enabled' => $orderby_enabled,
|
||||
'orderby' => $orderby,
|
||||
'orderby_option'=> $orderby_option,
|
||||
'ajax_category_enabled' => $ajax_category_enabled,
|
||||
'ajax_tag_enabled' => $ajax_tag_enabled,
|
||||
'ajax_category' => $ajax_category,
|
||||
'ajax_tag' => $ajax_tag,
|
||||
'custom_filter_enabled' => !empty($custom_filter['custom_enabled']),
|
||||
'custom_filter_keys' => $custom_filter['custom_filters'] ?? 'all',
|
||||
'custom_dimensions' => is_array($filter_all['custom_filter'] ?? null) ? $filter_all['custom_filter'] : [],
|
||||
'per_page' => max(4, min(48, (int) ($global['per_page'] ?? 12))),
|
||||
'cover_url' => $cover_url,
|
||||
'description' => $description,
|
||||
@@ -178,6 +211,30 @@ class TermMeta {
|
||||
$query->set('tax_query', $tax_query);
|
||||
}
|
||||
|
||||
// 自定义高级筛选维度 meta 过滤(参考主题 zib_sift_posts_per_page:meta_query LIKE;
|
||||
// meta 值为序列化数组,用带引号精确匹配避免前缀误命中)。
|
||||
if (!empty($settings['custom_filter_enabled'])) {
|
||||
$keys = $settings['custom_filter_keys'];
|
||||
$meta_query = is_array($query->get('meta_query')) ? $query->get('meta_query') : [];
|
||||
foreach ((array) ($settings['custom_dimensions'] ?? []) as $dimension) {
|
||||
$dim_key = sanitize_key((string) ($dimension['key'] ?? ''));
|
||||
if ($dim_key === '' || empty($_GET[$dim_key])) {
|
||||
continue;
|
||||
}
|
||||
if ($keys !== 'all' && !in_array($dim_key, (array) $keys, true)) {
|
||||
continue;
|
||||
}
|
||||
$meta_query[] = [
|
||||
'key' => '_aksrt_cf_' . $dim_key,
|
||||
'value' => '"' . sanitize_key(wp_unslash((string) $_GET[$dim_key])) . '"',
|
||||
'compare' => 'LIKE',
|
||||
];
|
||||
}
|
||||
if ($meta_query !== []) {
|
||||
$query->set('meta_query', $meta_query);
|
||||
}
|
||||
}
|
||||
|
||||
$orderby = isset($_GET['orderby']) ? sanitize_key(wp_unslash((string) $_GET['orderby'])) : 'date';
|
||||
$allowed = class_exists('\AKSRT\Settings\Settings')
|
||||
? \AKSRT\Settings\Settings::homepage_allowed_sorts()
|
||||
|
||||
@@ -231,10 +231,9 @@ trait DisplayPageGroups {
|
||||
'list' => $list,
|
||||
'thumb' => $thumb,
|
||||
'filter' => [
|
||||
'filter_enabled' => $filter['enabled'],
|
||||
'filter_categories' => $filter['categories'],
|
||||
'filter_tags' => $filter['tags'],
|
||||
'filter_sort' => $filter['sort'],
|
||||
'custom_filter_show' => $filter['custom_filter_show'],
|
||||
'custom_filter' => $filter['custom_filter'],
|
||||
'cat_custom_filter' => $filter['cat_custom_filter'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -104,34 +104,46 @@ class PostDisplay {
|
||||
$settings = Settings::get_all();
|
||||
|
||||
return [
|
||||
'enabled' => !empty($settings['filter_enabled']),
|
||||
'categories' => !isset($settings['filter_categories']) || !empty($settings['filter_categories']),
|
||||
'tags' => !empty($settings['filter_tags']),
|
||||
'sort' => !isset($settings['filter_sort']) || !empty($settings['filter_sort']),
|
||||
'ajax_enabled' => !empty($settings['filter_ajax_enabled']),
|
||||
'cat_show_cat' => !isset($settings['filter_cat_show_cat']) || !empty($settings['filter_cat_show_cat']),
|
||||
'cat_show_tag' => !empty($settings['filter_cat_show_tag']),
|
||||
'tag_show_cat' => !isset($settings['filter_tag_show_cat']) || !empty($settings['filter_tag_show_cat']),
|
||||
'tag_show_tag' => !empty($settings['filter_tag_show_tag']),
|
||||
'custom_filter_show' => is_array($settings['custom_filter_show'] ?? null) ? array_map('sanitize_key', $settings['custom_filter_show']) : ['cat', 'tag'],
|
||||
'custom_filter_show' => is_array($settings['custom_filter_show'] ?? null) ? array_values(array_intersect(array_map('sanitize_key', $settings['custom_filter_show']), ['cat', 'tag'])) : [],
|
||||
'custom_filter' => self::sanitize_custom_filter_defs($settings['custom_filter'] ?? []),
|
||||
'cat_custom_filter' => self::sanitize_cat_custom_filter($settings['cat_custom_filter'] ?? []),
|
||||
];
|
||||
}
|
||||
|
||||
public static function get_filter_config_for_category(int $term_id): array {
|
||||
/**
|
||||
* 归档页高级筛选配置(参考主题 zib-category.php:zib_get_ajax_option_menu 语义)。
|
||||
*
|
||||
* cat 页优先匹配 cat_custom_filter(绑定 cats 含当前 term 时全量覆盖筛选项目);
|
||||
* 未匹配或 tag 页回退默认配置:custom_filter_show 决定是否显示自定义筛选('all')。
|
||||
*
|
||||
* @return array{custom_enabled:bool,custom_filters:mixed,overrides:array<string,mixed>}
|
||||
*/
|
||||
public static function get_archive_custom_filter_config(int $term_id, string $page): array {
|
||||
$cfg = self::get_post_filter_settings();
|
||||
foreach ($cfg['cat_custom_filter'] as $rule) {
|
||||
if (in_array($term_id, $rule['cats'], true)) {
|
||||
return $rule;
|
||||
|
||||
if ($page === 'cat') {
|
||||
foreach ($cfg['cat_custom_filter'] as $rule) {
|
||||
if (in_array($term_id, $rule['cats'], true)) {
|
||||
return [
|
||||
'custom_enabled' => $rule['custom_filters'] !== [],
|
||||
'custom_filters' => $rule['custom_filters'],
|
||||
'overrides' => [
|
||||
'cat_s' => $rule['cat_s'],
|
||||
'cat_lists' => $rule['cat_lists'],
|
||||
'tag_s' => $rule['tag_s'],
|
||||
'tag_lists' => $rule['tag_lists'],
|
||||
'orderby_s' => $rule['orderby_s'],
|
||||
'orderby_lists' => $rule['orderby_lists'],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'cats' => [],
|
||||
'cat_s' => $cfg['cat_show_cat'],
|
||||
'tag_s' => $cfg['cat_show_tag'],
|
||||
'orderby_s' => $cfg['sort'],
|
||||
'custom_filters' => [],
|
||||
'custom_enabled' => in_array($page, $cfg['custom_filter_show'], true),
|
||||
'custom_filters' => 'all',
|
||||
'overrides' => [],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -506,16 +518,49 @@ class PostDisplay {
|
||||
if (!is_array($item)) continue;
|
||||
$cats = is_array($item['cats'] ?? null) ? array_values(array_filter(array_map('absint', $item['cats']), static fn($id) => $id > 0)) : [];
|
||||
if (empty($cats)) continue;
|
||||
$filters_raw = trim((string) ($item['custom_filters'] ?? ''));
|
||||
$filters = $filters_raw === '' ? [] : array_values(array_filter(array_map('sanitize_key', preg_split('/[,,\s]+/', $filters_raw) ?: [])));
|
||||
$result[] = [
|
||||
'cats' => $cats,
|
||||
'cat_s' => !isset($item['cat_s']) || !empty($item['cat_s']),
|
||||
'cat_s' => !empty($item['cat_s']),
|
||||
'cat_lists' => self::sanitize_filter_option_lists($item['cat_lists'] ?? []),
|
||||
'tag_s' => !empty($item['tag_s']),
|
||||
'orderby_s' => !isset($item['orderby_s']) || !empty($item['orderby_s']),
|
||||
'custom_filters' => $filters,
|
||||
'tag_lists' => self::sanitize_filter_option_lists($item['tag_lists'] ?? []),
|
||||
'orderby_s' => !empty($item['orderby_s']),
|
||||
'orderby_lists' => self::sanitize_filter_orderby_lists($item['orderby_lists'] ?? []),
|
||||
'custom_filters' => is_array($item['custom_filters'] ?? null)
|
||||
? array_values(array_unique(array_filter(array_map('sanitize_key', $item['custom_filters']))))
|
||||
: [],
|
||||
];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 归档筛选按钮列表 fieldset(lists + dropdown,参考主题 CFS_Module::ajax_but)。
|
||||
*/
|
||||
private static function sanitize_filter_option_lists($raw): array {
|
||||
$option = is_array($raw) ? $raw : [];
|
||||
$lists = is_array($option['lists'] ?? null) ? array_values(array_filter(array_map('absint', $option['lists']), static fn($id) => $id > 0)) : [];
|
||||
return [
|
||||
'lists' => $lists,
|
||||
'dropdown' => !empty($option['dropdown']),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 排序方式 fieldset(lists + dropdown,参考主题 CFS_Module::orderby)。
|
||||
*/
|
||||
private static function sanitize_filter_orderby_lists($raw): array {
|
||||
$option = is_array($raw) ? $raw : [];
|
||||
$allowed = Settings::homepage_allowed_sorts();
|
||||
$lists = is_array($option['lists'] ?? null)
|
||||
? array_values(array_intersect(array_map('sanitize_key', $option['lists']), $allowed))
|
||||
: [];
|
||||
if ($lists === []) {
|
||||
$lists = ['modified', 'views', 'like', 'comment_count'];
|
||||
}
|
||||
return [
|
||||
'lists' => $lists,
|
||||
'dropdown' => !empty($option['dropdown']),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -666,9 +666,9 @@ class Settings {
|
||||
|
||||
|
||||
/**
|
||||
* Post-list filter toolbar settings.
|
||||
* Post-list advanced filter settings (reference parity).
|
||||
*
|
||||
* @return array{enabled:bool,categories:bool,tags:bool,sort:bool}
|
||||
* @return array{custom_filter_show:array,custom_filter:array,cat_custom_filter:array}
|
||||
*/
|
||||
public static function get_post_filter_settings(): array {
|
||||
return PostDisplay::get_post_filter_settings();
|
||||
@@ -677,14 +677,14 @@ class Settings {
|
||||
|
||||
|
||||
/**
|
||||
* Get custom filter definitions for a specific category.
|
||||
* Finds the matching cat_custom_filter binding, falls back to global custom_filter.
|
||||
* Archive custom filter config (cat_custom_filter override + custom_filter_show gate).
|
||||
*
|
||||
* @param int $cat_id Category term ID.
|
||||
* @return array{dimensions: array, show_cat: bool, show_tag: bool, show_orderby: bool}
|
||||
* @param int $term_id Category term ID.
|
||||
* @param string $page cat|tag.
|
||||
* @return array{custom_enabled:bool,custom_filters:mixed,overrides:array<string,mixed>}
|
||||
*/
|
||||
public static function get_filter_config_for_category(int $cat_id): array {
|
||||
return PostDisplay::get_filter_config_for_category($cat_id);
|
||||
public static function get_archive_custom_filter_config(int $term_id, string $page): array {
|
||||
return PostDisplay::get_archive_custom_filter_config($term_id, $page);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user