$list_type, 'list_orderby' => in_array($list_orderby, ['date', 'modified', 'default'], true) ? $list_orderby : 'modified', 'post_time_source' => $time_source === 'date' ? 'date' : 'modified', 'sticky_s' => $sticky_pages, 'target_blank' => !empty($settings['target_blank']), 'item_heading_bold' => !empty($settings['item_heading_bold']), 'post_list_author' => !array_key_exists('post_list_author', $settings) || !empty($settings['post_list_author']), 'post_list_time' => !array_key_exists('post_list_time', $settings) || !empty($settings['post_list_time']), 'paging_ajax_s' => (string) ($settings['paging_ajax_s'] ?? '1') === '1', 'paging_ajax_ias_s' => !array_key_exists('paging_ajax_ias_s', $settings) || !empty($settings['paging_ajax_ias_s']), 'ias_max' => max(0, min(10, (int) ($settings['ias_max'] ?? 3))), 'list_meta_show' => in_array($mobile_meta, ['view', 'like', 'comm'], true) ? $mobile_meta : 'like', 'list_badge_show' => $badge_types, 'list_show_type' => in_array($list_show_type, ['separate', 'no_margin'], true) ? $list_show_type : 'separate', 'list_card_home' => !empty($settings['list_card_home']), 'list_card_tag' => !empty($settings['list_card_tag']), 'list_card_author' => !empty($settings['list_card_author']), 'list_card_cat' => $card_cat_ids, 'list_list_option' => [ 'style' => $list_style, 'img_position' => $list_position, 'scale' => max(50, min(200, (int) ($list_option['scale'] ?? 70))), ], 'list_card_option' => [ 'style' => $card_style, 'scale' => max(20, min(200, (int) ($card_option['scale'] ?? 70))), ], 'mult_thumb_cat' => is_array($settings['mult_thumb_cat'] ?? null) ? array_values(array_filter(array_map('intval', $settings['mult_thumb_cat']))) : [], 'ajax_trigger' => wp_kses_post((string) ($settings['ajax_trigger'] ?? '加载更多')), 'ajax_nomore' => wp_kses_post((string) ($settings['ajax_nomore'] ?? '没有更多内容了')), ]; } public static function get_post_thumb_settings(): array { $settings = Settings::get_all(); $spare_settings = array_key_exists('spare_thumbnail', $settings) ? (array) $settings['spare_thumbnail'] : [['img' => get_template_directory_uri() . '/assets/img/thumbnail.svg']]; $spare = []; foreach ($spare_settings as $item) { $url = is_array($item) ? (string) ($item['img'] ?? '') : ''; if ($url !== '') { $spare[] = esc_url_raw($url); } } $fit = sanitize_key((string) ($settings['list_thumb_fit'] ?? '')); return [ 'list_thumb_slides_s' => !array_key_exists('list_thumb_slides_s', $settings) || !empty($settings['list_thumb_slides_s']), 'list_thumb_video_s' => !array_key_exists('list_thumb_video_s', $settings) || !empty($settings['list_thumb_video_s']), 'list_thumb_video_mute_s' => !array_key_exists('list_thumb_video_mute_s', $settings) || !empty($settings['list_thumb_video_mute_s']), 'thumb_postfirstimg_s' => !array_key_exists('thumb_postfirstimg_s', $settings) || !empty($settings['thumb_postfirstimg_s']), 'thumb_catimg_s' => !array_key_exists('thumb_catimg_s', $settings) || !empty($settings['thumb_catimg_s']), 'list_thumb_fit' => $fit === 'contain' ? 'contain' : '', 'thumb_postfirstimg_size' => in_array(sanitize_key((string) ($settings['thumb_postfirstimg_size'] ?? 'medium')), ['thumbnail', 'medium', 'large', 'full'], true) ? sanitize_key((string) ($settings['thumb_postfirstimg_size'] ?? 'medium')) : 'medium', 'spare_thumbnail' => $spare, ]; } public static function get_post_filter_settings(): array { $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' => 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 { $cfg = self::get_post_filter_settings(); foreach ($cfg['cat_custom_filter'] as $rule) { if (in_array($term_id, $rule['cats'], true)) { return $rule; } } return [ 'cats' => [], 'cat_s' => $cfg['cat_show_cat'], 'tag_s' => $cfg['cat_show_tag'], 'orderby_s' => $cfg['sort'], 'custom_filters' => [], ]; } public static function get_post_page_settings(): array { $settings = Settings::get_all(); // Canonical render keys (used by aksrt_single_*). Legacy *_s aliases kept for older callers. $breadcrumbs = !isset($settings['breadcrumbs_single_s']) || !empty($settings['breadcrumbs_single_s']); $breadcrumbs_home = sanitize_text_field((string) ($settings['breadcrumbs_home_text'] ?? '首页')); // legacy breadcrumbs_single_text: true → last crumb is "正文"; false → full title. $breadcrumbs_single_text = !isset($settings['breadcrumbs_single_text']) || !empty($settings['breadcrumbs_single_text']); $prevnext = !isset($settings['post_prevnext_s']) || !empty($settings['post_prevnext_s']); $authordesc = !isset($settings['post_authordesc_s']) || !empty($settings['post_authordesc_s']); $hide_time = !empty($settings['post_single_hide_time_s']); $share_enabled = !isset($settings['share_s']) || !empty($settings['share_s']); $rewards_enabled = !empty($settings['post_rewards_s']); $rewards_text = sanitize_text_field((string) ($settings['post_rewards_text'] ?? '')); if ($rewards_text === '') { $rewards_text = '赞赏'; } $reward_amount = static function ($value, string $default): \AKSRT\Ledger\AssetAmount { try { return \AKSRT\Ledger\AssetAmount::balance(is_string($value) ? trim($value) : ''); } catch (\InvalidArgumentException $e) { return \AKSRT\Ledger\AssetAmount::balance($default); } }; $rewards_amounts = []; foreach (explode(',', (string) ($settings['post_rewards_amounts'] ?? '5.00,10.00,20.00,50.00,100.00')) as $value) { try { $parsed = \AKSRT\Ledger\AssetAmount::balance(trim($value)); if ($parsed->minor() > 0) { $rewards_amounts[] = $parsed->decimal(); } } catch (\InvalidArgumentException $e) { continue; } } if ($rewards_amounts === []) { $rewards_amounts = ['5.00', '10.00', '20.00', '50.00', '100.00']; } $rewards_min_amount = $reward_amount($settings['post_rewards_min'] ?? '1.00', '1.00'); if ($rewards_min_amount->minor() <= 0) { $rewards_min_amount = \AKSRT\Ledger\AssetAmount::balance('0.01'); } $rewards_max_amount = $reward_amount($settings['post_rewards_max'] ?? '1000.00', '1000.00'); if ($rewards_max_amount->minor() < $rewards_min_amount->minor()) { $rewards_max_amount = $rewards_min_amount; } $rewards_min = $rewards_min_amount->decimal(); $rewards_max = $rewards_max_amount->decimal(); $author_card_limit = max(0, min(12, (int) ($settings['post_author_card_limit'] ?? 6))); $author_card_orderby = sanitize_key((string) ($settings['post_author_card_orderby'] ?? 'views')); if (!in_array($author_card_orderby, ['views', 'date', 'modified', 'comment_count'], true)) { $author_card_orderby = 'views'; } $author_card_style = sanitize_key((string) ($settings['post_author_card_style'] ?? 'card')); if (!in_array($author_card_style, ['card', 'list'], true)) { $author_card_style = 'card'; } $maxheight_enabled = !empty($settings['article_maxheight_kg']) || !empty($settings['post_article_maxheight_kg']) || !empty($settings['post_maxheight_kg']); $maxheight = max(0, (int) ($settings['article_maxheight'] ?? $settings['post_article_maxheight'] ?? $settings['post_maxheight'] ?? 1000)); if ($maxheight <= 0) { $maxheight = 1000; } $related_style = sanitize_key((string) ($settings['post_related_type'] ?? 'img')); if (!in_array($related_style, ['img', 'list', 'text'], true)) { $related_style = 'img'; } $related_orderby = sanitize_key((string) ($settings['post_related_orderby'] ?? 'views')); if (!in_array($related_orderby, ['modified', 'date', 'views', 'like', 'comment_count', 'favorite', 'rand'], true)) { $related_orderby = 'views'; } return [ 'reading_progress' => !isset($settings['post_reading_progress']) || !empty($settings['post_reading_progress']), // Canonical + legacy breadcrumbs. 'breadcrumbs' => $breadcrumbs, 'breadcrumbs_home' => $breadcrumbs_home, 'breadcrumbs_single_s' => $breadcrumbs, 'breadcrumbs_home_text' => $breadcrumbs_home, 'breadcrumbs_single_text' => $breadcrumbs_single_text, // Canonical + legacy prev/next / time; canonical author card flag. 'prevnext' => $prevnext, 'prevnext_s' => $prevnext, 'authordesc' => $authordesc, 'hide_time' => $hide_time, 'single_hide_time_s' => $hide_time, 'article_image_cover' => !isset($settings['post_article_image_cover']) || !empty($settings['post_article_image_cover']), 'article_image_cover_scale'=> max(10, min(100, (int) ($settings['post_article_image_cover_scale'] ?? 35))), 'article_slide_cover' => !isset($settings['post_article_slide_cover']) || !empty($settings['post_article_slide_cover']), 'article_video_cover' => !isset($settings['post_article_video_cover']) || !empty($settings['post_article_video_cover']), 'article_video_cover_scale'=> max(20, min(100, (int) ($settings['post_article_video_cover_scale'] ?? 56))), 'lightbox' => !isset($settings['post_lightbox']) || !empty($settings['post_lightbox']), 'lightbox_thumbs' => !isset($settings['post_lightbox_thumbs']) || !empty($settings['post_lightbox_thumbs']), 'lightbox_zoom' => !isset($settings['post_lightbox_zoom']) || !empty($settings['post_lightbox_zoom']), 'lightbox_full' => !isset($settings['post_lightbox_full']) || !empty($settings['post_lightbox_full']), 'lightbox_down' => !empty($settings['post_lightbox_down']), 'lightbox_play' => !empty($settings['post_lightbox_play']), 'related_enabled' => !isset($settings['post_related_s']) || !empty($settings['post_related_s']), 'related_count' => max(4, min(12, (int) ($settings['post_related_n'] ?? 6))), 'related_style' => $related_style, 'related_orderby' => $related_orderby, 'related_title' => sanitize_text_field((string) ($settings['related_title'] ?? '相关推荐')), 'like_enabled' => !isset($settings['post_like_enabled']) || !empty($settings['post_like_enabled']), 'favorite_enabled' => !isset($settings['post_favorite_enabled']) || !empty($settings['post_favorite_enabled']), // Canonical + legacy share. 'share_enabled' => $share_enabled, 'share_s' => $share_enabled, // Author card posts (legacy user_card_box defaults). 'author_card_limit' => $author_card_limit, 'author_card_orderby' => $author_card_orderby, 'author_card_style' => $author_card_style, // On-site wallet tipping. 'rewards_enabled' => $rewards_enabled, 'post_rewards_s' => $rewards_enabled, 'rewards_text' => $rewards_text, 'rewards_btn_text' => $rewards_text, 'rewards_amounts' => $rewards_amounts, 'rewards_custom' => !isset($settings['post_rewards_custom']) || !empty($settings['post_rewards_custom']), 'rewards_min' => $rewards_min, 'rewards_max' => $rewards_max, // Content max height (legacy article_maxheight_kg / article_maxheight). 'maxheight_enabled' => $maxheight_enabled, 'maxheight' => $maxheight, 'copyright_enabled' => !isset($settings['post_copyright_enabled']) || !empty($settings['post_copyright_enabled']), 'copyright_text' => (string) ($settings['post_copyright_text'] ?? ''), 'button_toptext' => sanitize_text_field((string) ($settings['post_button_toptext'] ?? '喜欢就支持一下吧')), 'front_content' => (string) ($settings['post_front_content'] ?? ''), 'after_content' => (string) ($settings['post_after_content'] ?? ''), 'yiyan_header' => !empty($settings['post_yiyan_header']), 'yiyan_footer' => !empty($settings['post_yiyan_footer']), 'yiyan_box' => !empty($settings['post_yiyan_box']), 'default_views_min' => max(0, min(9999, (int) ($settings['post_default_views_min'] ?? 20))), 'default_views_max' => max(1, min(9999, (int) ($settings['post_default_views_max'] ?? 50))), 'default_likes_min' => max(0, min(9999, (int) ($settings['post_default_likes_min'] ?? 5))), 'default_likes_max' => max(1, min(9999, (int) ($settings['post_default_likes_max'] ?? 15))), 'print_enabled' => !isset($settings['feature_print']) || !empty($settings['feature_print']), 'pdf_export_enabled' => !empty($settings['feature_pdf_export']), ]; } public static function get_share_settings(): array { $settings = Settings::get_all(); return [ 'enabled' => !isset($settings['share_s']) || !empty($settings['share_s']), 'wechat_appid' => sanitize_text_field((string) ($settings['wechat_share_appid'] ?? '')), 'wechat_timestamp' => sanitize_text_field((string) ($settings['wechat_share_timestamp'] ?? '')), 'wechat_nonce' => sanitize_text_field((string) ($settings['wechat_share_nonce'] ?? '')), 'wechat_signature' => sanitize_text_field((string) ($settings['wechat_share_signature'] ?? '')), 'poster_enabled' => !empty($settings['post_share_poster_s']), 'poster_qr_enabled' => !empty($settings['post_share_poster_qr_s']), 'poster_bg' => (string) ($settings['post_share_poster_bg'] ?? ''), 'social_items' => is_array($settings['social_share_items'] ?? null) ? $settings['social_share_items'] : [], 'copy_link_enabled' => !isset($settings['post_share_copylink_s']) || !empty($settings['post_share_copylink_s']), ]; } public static function get_submit_settings(): array { $settings = Settings::get_all(); $money_setting = static function ($value, string $default): string { if (!is_string($value)) { return $default; } try { return \AKSRT\Ledger\AssetAmount::balance($value)->decimal(); } catch (\InvalidArgumentException $e) { return $default; } }; $title_min = max(1, min(100, (int) ($settings['post_article_title_strlen_limit_min'] ?? 5))); $title_max = max(5, min(200, (int) ($settings['post_article_title_strlen_limit_max'] ?? 30))); if ($title_max < $title_min) { $title_max = $title_min; } $review_mode = sanitize_key((string) ($settings['front_submit_review_mode'] ?? 'pending')); if (!in_array($review_mode, ['pending', 'publish', 'draft'], true)) { $review_mode = 'pending'; } $editor_mode = sanitize_key((string) ($settings['front_submit_editor_mode'] ?? 'rich')); if (!in_array($editor_mode, ['rich', 'markdown', 'plain'], true)) { $editor_mode = 'rich'; } return [ 'enabled' => !isset($settings['front_submit_enabled']) || !empty($settings['front_submit_enabled']), 'btn_text' => sanitize_text_field((string) ($settings['post_article_btn_txte'] ?? '')) ?: __('发布文章', 'aksrt'), 'title_min' => $title_min, 'title_max' => $title_max, 'title_placeholder' => sanitize_text_field((string) ($settings['post_t_placeholder'] ?? '')) ?: __('请输入标题', 'aksrt'), 'content_placeholder' => sanitize_textarea_field((string) ($settings['post_c_placeholder'] ?? '')) ?: __('请输入内容', 'aksrt'), 'allowed_cat_ids' => is_array($settings['post_article_cat'] ?? null) ? array_values(array_filter(array_map('intval', $settings['post_article_cat']))) : [], 'default_user_id' => max(0, (int) ($settings['post_article_user'] ?? 0)), 'guest_enabled' => !empty($settings['front_submit_guest_enabled']), 'allow_title' => !isset($settings['front_submit_title']) || !empty($settings['front_submit_title']), 'allow_content' => !isset($settings['front_submit_content']) || !empty($settings['front_submit_content']), 'allow_excerpt' => !isset($settings['front_submit_excerpt']) || !empty($settings['front_submit_excerpt']), 'allow_cover' => !isset($settings['front_submit_cover']) || !empty($settings['front_submit_cover']), 'allow_category' => !isset($settings['front_submit_category']) || !empty($settings['front_submit_category']), 'allow_tags' => !isset($settings['front_submit_tags']) || !empty($settings['front_submit_tags']), 'tags_s' => !isset($settings['front_submit_tags']) || !empty($settings['front_submit_tags']), 'cover_required' => !empty($settings['front_submit_cover_required']), 'max_images' => max(0, min(50, (int) ($settings['front_submit_max_images'] ?? 5))), 'review_mode' => $review_mode, 'editor_mode' => $editor_mode, 'draft_save' => !isset($settings['front_submit_draft_save']) || !empty($settings['front_submit_draft_save']), 'leave_warning' => !isset($settings['front_submit_leave_warning']) || !empty($settings['front_submit_leave_warning']), 'pay_free_s' => !isset($settings['post_article_pay_free_s']) || !empty($settings['post_article_pay_free_s']), 'pay_price_min' => $money_setting($settings['post_article_pay_price_min'] ?? '0.00', '0.00'), 'pay_price_max' => $money_setting($settings['post_article_pay_price_max'] ?? '100.00', '100.00'), 'pay_vip_price_s' => !isset($settings['post_article_pay_vip_price_s']) || !empty($settings['post_article_pay_vip_price_s']), 'pay_vip_1_enabled' => !empty($settings['pay_user_vip_1_s']), 'pay_vip_2_enabled' => !empty($settings['pay_user_vip_2_s']), 'pay_vip_1_discount' => max(0, min(100, (int) ($settings['post_article_pay_vip_1_discount'] ?? 80))), 'pay_vip_2_discount' => max(0, min(100, (int) ($settings['post_article_pay_vip_2_discount'] ?? 50))), 'custom_filter_s' => !isset($settings['post_article_custom_filter_s']) || !empty($settings['post_article_custom_filter_s']), ]; } public static function get_comment_display_settings(): array { $settings = Settings::get_all(); $order = sanitize_key((string) ($settings['comment_order'] ?? 'desc')); if (!in_array($order, ['asc', 'desc'], true)) { $order = 'desc'; } $empty_text = trim((string) ($settings['comment_empty_text'] ?? '')); $submit_text = trim((string) ($settings['comment_submit_text'] ?? '')); $box_placeholder = trim((string) ($settings['comment_text'] ?? '')); $title = trim((string) ($settings['comment_title'] ?? '')); return [ 'order' => $order, 'pagination_mode' => self::get_comment_pagination_mode(), 'paging_ajax_ias' => !isset($settings['comment_paging_ajax_ias_s']) || !empty($settings['comment_paging_ajax_ias_s']), 'paging_ajax_ias_max'=> max(0, min(10, (int) ($settings['comment_paging_ajax_ias_max'] ?? 3))), 'per_page' => max(5, min(100, (int) ($settings['comment_per_page'] ?? 20))), 'nested_depth' => max(1, min(10, (int) ($settings['comment_nested_depth'] ?? 3))), 'require_login' => Settings::comment_requires_registration(), 'avatar_size' => max(24, min(96, (int) ($settings['comment_avatar_size'] ?? 48))), 'empty_text' => $empty_text !== '' ? $empty_text : __('暂无评论,来做第一个评论的人吧~', 'aksrt'), 'toolbar' => [ 'code' => !isset($settings['comment_code']) || !empty($settings['comment_code']), 'image' => !isset($settings['comment_img']) || !empty($settings['comment_img']), 'link' => !empty($settings['comment_link']), 'upload_img' => function_exists('aksrt_user_can') && aksrt_user_can('upload_comment_image', get_current_user_id()), ], 'like_enabled' => !isset($settings['comment_like_s']) || !empty($settings['comment_like_s']), 'author_tag' => !isset($settings['comment_author_tag']) || !empty($settings['comment_author_tag']), 'corderby' => !isset($settings['comment_corderby']) || !empty($settings['comment_corderby']), 'edit_window' => max(0, min(1440, (int) ($settings['comment_edit_window'] ?? 10))), 'submit_text' => $submit_text !== '' ? $submit_text : __('提交评论', 'aksrt'), 'box_placeholder' => $box_placeholder !== '' ? $box_placeholder : __('说点什么吧...', 'aksrt'), 'title' => $title !== '' ? $title : __('评论', 'aksrt'), // Extended legacy-parity settings. 'close_comments' => !empty($settings['comment_close_comments']), 'hot_threshold' => max(1, min(999, (int) ($settings['comment_hot_threshold'] ?? 10))), 'user_url' => !empty($settings['comment_user_url_s']), 'city_s' => !isset($settings['comment_city_s']) || !empty($settings['comment_city_s']), 'city_type' => self::normalize_comment_city_type((string) ($settings['comment_city_type'] ?? 'province_city')), ]; } private static function normalize_comment_city_type(string $type): string { $type = sanitize_key($type); // Map legacy legacy pro/city labels. if ($type === 'pro') { return 'province'; } if ($type === 'city') { return 'province_city'; } return in_array($type, ['province_city', 'province', 'country_province'], true) ? $type : 'province_city'; } public static function apply_list_orderby($query): void { if (is_admin() || !($query instanceof \WP_Query) || !$query->is_main_query()) { return; } if (!$query->is_home() && !$query->is_archive()) { return; } if ($query->get('orderby')) { return; } $orderby = sanitize_key((string) (self::get_post_list_style_settings()['list_orderby'] ?? 'modified')); if ($orderby === '' || $orderby === 'default') { return; } if (in_array($orderby, ['date', 'modified'], true)) { $query->set('orderby', $orderby); $query->set('order', 'DESC'); } } public static function apply_list_per_page($query): void { unset($query); } public static function get_archive_layout(): string { $settings = self::get_post_list_style_settings(); return ($settings['list_type'] ?? 'thumb') === 'card' ? 'card' : 'list'; } public static function get_post_pagination_mode(): string { $settings = Settings::get_all(); if (!self::is_list_paging_ajax($settings)) { return 'numbered'; } return self::is_list_paging_ajax_ias($settings) ? 'infinite' : 'load_more'; } /** * Whether list pagination uses AJAX append (legacy paging_ajax_s). * * @param array|null $settings */ public static function is_list_paging_ajax(?array $settings = null): bool { $settings = $settings ?? Settings::get_all(); $raw = $settings['paging_ajax_s'] ?? '1'; if (is_bool($raw)) { return $raw; } return (string) $raw === '1' || (string) $raw === 'true'; } /** * Whether AJAX list paging auto-loads on scroll (legacy paging_ajax_ias_s). * * @param array|null $settings */ public static function is_list_paging_ajax_ias(?array $settings = null): bool { $settings = $settings ?? Settings::get_all(); if (!self::is_list_paging_ajax($settings)) { return false; } return !array_key_exists('paging_ajax_ias_s', $settings) || !empty($settings['paging_ajax_ias_s']); } public static function get_comment_pagination_mode(): string { $mode = (string) Settings::get_value('comment_pagination_type', 'numbered'); if ($mode === 'page') { $mode = 'numbered'; } return in_array($mode, ['numbered', 'load_more', 'infinite'], true) ? $mode : 'numbered'; } private static function sanitize_custom_filter_defs($raw): array { if (!is_array($raw)) { return []; } $result = []; foreach ($raw as $item) { if (!is_array($item)) continue; $name = sanitize_text_field((string) ($item['name'] ?? '')); $key = sanitize_key((string) ($item['key'] ?? '')); if ($name === '' || $key === '') continue; $vals = []; foreach ((array) ($item['vals'] ?? []) as $val) { if (!is_array($val)) continue; $vkey = sanitize_key((string) ($val['key'] ?? '')); $vname = sanitize_text_field((string) ($val['name'] ?? '')); if ($vkey === '' || $vname === '') continue; $vals[] = ['key' => $vkey, 'name' => $vname]; } $result[] = ['name' => $name, 'key' => $key, 'vals' => $vals]; } return $result; } private static function sanitize_cat_custom_filter($raw): array { if (!is_array($raw)) { return []; } $result = []; foreach ($raw as $item) { 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']), 'tag_s' => !empty($item['tag_s']), 'orderby_s' => !isset($item['orderby_s']) || !empty($item['orderby_s']), 'custom_filters' => $filters, ]; } return $result; } }