665 lines
38 KiB
PHP
665 lines
38 KiB
PHP
<?php
|
||
/**
|
||
* @package AKSRT
|
||
*/
|
||
|
||
namespace AKSRT\Settings;
|
||
|
||
defined('ABSPATH') || exit;
|
||
|
||
class PostDisplay {
|
||
|
||
public static function get_post_list_style_settings(): array {
|
||
$settings = Settings::get_all();
|
||
|
||
// post_card_style storage key mirrors Zibll list_type.
|
||
$list_type = sanitize_key((string) ($settings['post_card_style'] ?? 'thumb'));
|
||
$allowed_list_types = ['thumb', 'compact', 'large_thumb', 'multi_thumb', 'text', 'thumb_if_has', 'card', 'standard'];
|
||
|
||
if (!in_array($list_type, $allowed_list_types, true)) {
|
||
$list_type = 'thumb';
|
||
}
|
||
// Historical aliases → Zibll list_type tokens.
|
||
if ($list_type === 'standard') {
|
||
$list_type = 'thumb';
|
||
}
|
||
// Non-Zibll extras stay list-mode variants (never force card grid).
|
||
if (in_array($list_type, ['compact', 'large_thumb', 'multi_thumb'], true)) {
|
||
// Keep token for CSS hooks; render as list.
|
||
}
|
||
|
||
// Zibll: only list_type=card is card mode; thumb/text/thumb_if_has are list.
|
||
$render_mode_map = [
|
||
'thumb' => 'list',
|
||
'compact' => 'list',
|
||
'large_thumb' => 'list',
|
||
'multi_thumb' => 'list',
|
||
'text' => 'list',
|
||
'thumb_if_has' => 'list',
|
||
'card' => 'card',
|
||
];
|
||
|
||
$sticky_pages_raw = $settings['sticky_s'] ?? null;
|
||
if (is_array($sticky_pages_raw)) {
|
||
$allowed_pages = ['home', 'cat', 'tag'];
|
||
$sticky_pages = array_values(array_intersect(array_map('sanitize_key', $sticky_pages_raw), $allowed_pages));
|
||
} else {
|
||
$sticky_pages = ['home', 'cat'];
|
||
}
|
||
|
||
$badge_types_raw = $settings['list_badge_show'] ?? null;
|
||
if (is_array($badge_types_raw)) {
|
||
$allowed_types = ['pay', 'cat', 'tag'];
|
||
$badge_types = array_values(array_intersect(array_map('sanitize_key', $badge_types_raw), $allowed_types));
|
||
} else {
|
||
$badge_types = ['pay', 'cat', 'tag'];
|
||
}
|
||
|
||
$show_author = array_key_exists('post_list_author', $settings)
|
||
? !empty($settings['post_list_author'])
|
||
: (!isset($settings['post_show_author']) || !empty($settings['post_show_author']));
|
||
|
||
$show_date = array_key_exists('post_list_time', $settings)
|
||
? !empty($settings['post_list_time'])
|
||
: (!isset($settings['post_show_date']) || !empty($settings['post_show_date']));
|
||
|
||
$target_blank = array_key_exists('target_blank', $settings)
|
||
? !empty($settings['target_blank'])
|
||
: !empty($settings['post_target_blank']);
|
||
|
||
$ajax_trigger = '';
|
||
if (array_key_exists('ajax_trigger', $settings)) {
|
||
$ajax_trigger = sanitize_text_field((string) $settings['ajax_trigger']);
|
||
} elseif (array_key_exists('ajax_trigger_text', $settings)) {
|
||
$ajax_trigger = sanitize_text_field((string) $settings['ajax_trigger_text']);
|
||
}
|
||
|
||
$ajax_nomore = '';
|
||
if (array_key_exists('ajax_nomore', $settings)) {
|
||
$ajax_nomore = sanitize_text_field((string) $settings['ajax_nomore']);
|
||
} elseif (array_key_exists('ajax_nomore_text', $settings)) {
|
||
$ajax_nomore = sanitize_text_field((string) $settings['ajax_nomore_text']);
|
||
}
|
||
|
||
$list_style = sanitize_key((string) ($settings['list_list_style'] ?? ''));
|
||
if (!in_array($list_style, ['', 'style2'], true)) {
|
||
$list_style = '';
|
||
}
|
||
|
||
$card_variant = sanitize_key((string) ($settings['list_card_style'] ?? ''));
|
||
if (!in_array($card_variant, ['', 'style3'], true)) {
|
||
$card_variant = '';
|
||
}
|
||
|
||
$card_cat_ids = [];
|
||
if (is_array($settings['list_card_cat'] ?? null)) {
|
||
$card_cat_ids = array_values(array_filter(array_map('intval', $settings['list_card_cat'])));
|
||
}
|
||
|
||
return [
|
||
// Zibll list_type (storage: post_card_style).
|
||
'list_type' => $list_type,
|
||
// Base mode from list_type only (surface card overrides applied by resolver).
|
||
'render_mode' => $render_mode_map[$list_type] ?? 'list',
|
||
// List item subtype token for text/thumb_if_has class hooks (not card variant).
|
||
'list_type_token' => $list_type,
|
||
// List mode visual variant (Zibll list_list_option.style).
|
||
'list_style' => $list_style,
|
||
// Card mode visual variant (Zibll list_card_option.style).
|
||
'card_variant' => $card_variant,
|
||
// Back-compat aliases used by older callers (prefer list_type / card_variant).
|
||
'card_style' => $list_type,
|
||
'show_author' => $show_author,
|
||
'show_date' => $show_date,
|
||
'show_views' => !isset($settings['post_show_views']) || !empty($settings['post_show_views']),
|
||
'show_category' => !isset($settings['post_show_category']) || !empty($settings['post_show_category']),
|
||
'show_comments' => !isset($settings['post_meta_comments']) || !empty($settings['post_meta_comments']),
|
||
'show_likes' => !isset($settings['post_meta_likes']) || !empty($settings['post_meta_likes']),
|
||
'badge_types' => $badge_types,
|
||
'badge_show' => !empty($badge_types),
|
||
'sticky_pages' => $sticky_pages,
|
||
'sticky_enabled' => !empty($sticky_pages),
|
||
'target_blank' => $target_blank,
|
||
'heading_bold' => !empty($settings['item_heading_bold']),
|
||
'mobile_meta' => in_array(sanitize_key((string) ($settings['list_meta_show'] ?? 'like')), ['view', 'like', 'comm'], true) ? sanitize_key((string) ($settings['list_meta_show'] ?? 'like')) : 'like',
|
||
'list_show_type' => in_array(sanitize_key((string) ($settings['list_show_type'] ?? 'separate')), ['separate', 'no_margin'], true) ? sanitize_key((string) ($settings['list_show_type'] ?? 'separate')) : 'separate',
|
||
'excerpt_length' => max(20, min(500, (int) ($settings['post_excerpt_length'] ?? 120))),
|
||
'ias_max' => max(0, min(10, (int) ($settings['ias_max'] ?? 3))),
|
||
'paging_ajax' => self::is_list_paging_ajax($settings),
|
||
'paging_ajax_ias' => self::is_list_paging_ajax_ias($settings),
|
||
'ajax_trigger_text' => $ajax_trigger,
|
||
'ajax_nomore_text' => $ajax_nomore,
|
||
'list_orderby' => in_array(sanitize_key((string) ($settings['list_orderby'] ?? 'modified')), ['modified', 'date', 'default'], true) ? sanitize_key((string) ($settings['list_orderby'] ?? 'modified')) : 'modified',
|
||
'columns' => max(1, min(3, (int) ($settings['post_list_columns'] ?? 1))),
|
||
'per_page' => max(4, min(48, (int) ($settings['post_list_per_page'] ?? 12))),
|
||
'list_img_position' => in_array(sanitize_key((string) ($settings['list_list_img_position'] ?? 'left')), ['left', 'right'], true) ? sanitize_key((string) ($settings['list_list_img_position'] ?? 'left')) : 'left',
|
||
'list_scale' => max(50, min(200, (int) ($settings['list_list_scale'] ?? 70))),
|
||
'card_scale' => max(20, min(200, (int) ($settings['list_card_scale'] ?? 70))),
|
||
'card_home' => !empty($settings['list_card_home']),
|
||
'card_cat' => !empty($card_cat_ids),
|
||
'card_cat_ids' => $card_cat_ids,
|
||
'card_tag' => !empty($settings['list_card_tag']),
|
||
'card_author' => !empty($settings['list_card_author']),
|
||
];
|
||
}
|
||
|
||
public static function get_post_thumb_settings(): array {
|
||
$settings = Settings::get_all();
|
||
$priority_raw = (string) ($settings['thumb_priority'] ?? 'featured,attachment,resource,custom');
|
||
$priority = preg_split('/[\s,]+/', strtolower($priority_raw)) ?: [];
|
||
$priority = array_values(array_unique(array_filter(array_map('sanitize_key', $priority))));
|
||
$allowed_sources = ['featured', 'attachment', 'resource', 'custom', 'category_cover', 'post_first_img'];
|
||
$priority = array_values(array_filter($priority, static function (string $source) use ($allowed_sources): bool {
|
||
return in_array($source, $allowed_sources, true);
|
||
}));
|
||
|
||
if (empty($priority)) {
|
||
$priority = ['featured', 'attachment', 'resource', 'custom'];
|
||
}
|
||
|
||
$fallback = sanitize_key((string) ($settings['thumb_fallback'] ?? 'placeholder'));
|
||
if (!in_array($fallback, ['placeholder', 'hide', 'random'], true)) {
|
||
$fallback = 'placeholder';
|
||
}
|
||
|
||
$aspect_ratio = (string) ($settings['thumb_aspect_ratio'] ?? '16:9');
|
||
if (!in_array($aspect_ratio, ['16:9', '4:3', '1:1', 'auto'], true)) {
|
||
$aspect_ratio = '16:9';
|
||
}
|
||
|
||
return [
|
||
'priority' => $priority,
|
||
'fallback' => $fallback,
|
||
'spare_images' => is_array($settings['thumb_spare_images'] ?? null) ? $settings['thumb_spare_images'] : [],
|
||
'aspect_ratio' => $aspect_ratio,
|
||
'multi_enabled' => !empty($settings['thumb_multi_enabled']),
|
||
'multi_count' => max(2, min(6, (int) ($settings['thumb_multi_count'] ?? 3))),
|
||
'lazy' => !isset($settings['thumb_lazy']) || !empty($settings['thumb_lazy']),
|
||
'fit' => in_array(sanitize_key((string) ($settings['list_thumb_fit'] ?? 'cover')), ['cover', 'contain'], true) ? sanitize_key((string) ($settings['list_thumb_fit'] ?? 'cover')) : 'cover',
|
||
'slides_s' => !isset($settings['list_thumb_slides_s']) || !empty($settings['list_thumb_slides_s']),
|
||
'video_s' => !isset($settings['list_thumb_video_s']) || !empty($settings['list_thumb_video_s']),
|
||
'video_mute_s' => !isset($settings['list_thumb_video_mute_s']) || !empty($settings['list_thumb_video_mute_s']),
|
||
'postfirstimg_s' => !isset($settings['thumb_postfirstimg_s']) || !empty($settings['thumb_postfirstimg_s']),
|
||
'catimg_s' => !isset($settings['thumb_catimg_s']) || !empty($settings['thumb_catimg_s']),
|
||
'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',
|
||
'mult_thumb_cat_ids' => is_array($settings['mult_thumb_cat'] ?? null) ? array_map('intval', $settings['mult_thumb_cat']) : [],
|
||
];
|
||
}
|
||
|
||
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'] ?? '首页'));
|
||
// Zibll 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 = '赞赏';
|
||
}
|
||
$rewards_amounts = array_values(array_filter(array_map(static function ($value): float {
|
||
return round((float) $value, 2);
|
||
}, explode(',', (string) ($settings['post_rewards_amounts'] ?? '5,10,20,50,100'))), static fn(float $value): bool => $value > 0));
|
||
if ($rewards_amounts === []) {
|
||
$rewards_amounts = [5, 10, 20, 50, 100];
|
||
}
|
||
$rewards_min = max(0.01, round((float) ($settings['post_rewards_min'] ?? 1), 2));
|
||
$rewards_max = max($rewards_min, round((float) ($settings['post_rewards_max'] ?? 1000), 2));
|
||
$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: split Zibll display style (img/list/text) from query source (category/tag/random).
|
||
// Legacy post_related_type held either style (img|list|text) or source (category|tag|random).
|
||
$raw_related_type = sanitize_key((string) ($settings['post_related_type'] ?? ''));
|
||
$raw_related_style = sanitize_key((string) ($settings['post_related_style'] ?? ''));
|
||
$raw_related_source = sanitize_key((string) ($settings['post_related_source'] ?? ''));
|
||
|
||
$related_style = 'img';
|
||
if (in_array($raw_related_style, ['img', 'list', 'text'], true)) {
|
||
$related_style = $raw_related_style;
|
||
} elseif (in_array($raw_related_type, ['img', 'list', 'text'], true)) {
|
||
$related_style = $raw_related_type;
|
||
}
|
||
|
||
$related_source = 'category';
|
||
if (in_array($raw_related_source, ['category', 'tag', 'random'], true)) {
|
||
$related_source = $raw_related_source;
|
||
} elseif (in_array($raw_related_type, ['category', 'tag', 'random'], true)) {
|
||
$related_source = $raw_related_type;
|
||
}
|
||
|
||
$related_orderby = sanitize_key((string) ($settings['post_related_orderby'] ?? 'views'));
|
||
if (!in_array($related_orderby, ['rand', 'relevance', 'date', 'views', 'modified'], true)) {
|
||
$related_orderby = 'views';
|
||
}
|
||
|
||
return [
|
||
'toc_enabled' => !isset($settings['post_toc_enabled']) || !empty($settings['post_toc_enabled']),
|
||
'toc_depth' => max(1, min(6, (int) ($settings['post_toc_depth'] ?? 3))),
|
||
'article_nav_mobile_nav_s' => !isset($settings['article_nav_mobile_nav_s']) || !empty($settings['article_nav_mobile_nav_s']),
|
||
'mobile_nav_s' => !isset($settings['article_nav_mobile_nav_s']) || !empty($settings['article_nav_mobile_nav_s']),
|
||
'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 / author / time.
|
||
'prevnext' => $prevnext,
|
||
'prevnext_s' => $prevnext,
|
||
'authordesc' => $authordesc,
|
||
'authordesc_s' => $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_enabled']) || !empty($settings['post_related_enabled']),
|
||
'related_count' => max(1, min(20, (int) ($settings['post_related_count'] ?? 6))),
|
||
// Display style (Zibll img/list/text) + query source (category/tag/random).
|
||
'related_style' => $related_style,
|
||
'related_source' => $related_source,
|
||
// Legacy alias: older code treated related_type as source.
|
||
'related_type' => $related_source,
|
||
'related_orderby' => $related_orderby,
|
||
'related_title' => sanitize_text_field((string) ($settings['post_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 (Zibll 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 (Zibll 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))),
|
||
'word_count_enabled' => !isset($settings['post_word_count_enabled']) || !empty($settings['post_word_count_enabled']),
|
||
'reading_time_enabled' => !isset($settings['post_reading_time_enabled']) || !empty($settings['post_reading_time_enabled']),
|
||
'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();
|
||
|
||
$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' => max(0, (float) ($settings['post_article_pay_price_min'] ?? 0)),
|
||
'pay_price_max' => max(0, (float) ($settings['post_article_pay_price_max'] ?? 100)),
|
||
'pay_vip_price_s' => !isset($settings['post_article_pay_vip_price_s']) || !empty($settings['post_article_pay_vip_price_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' => [
|
||
'smilie' => !isset($settings['comment_smilie']) || !empty($settings['comment_smilie']),
|
||
'code' => !isset($settings['comment_code']) || !empty($settings['comment_code']),
|
||
'image' => !isset($settings['comment_img']) || !empty($settings['comment_img']),
|
||
'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 zibll-parity settings.
|
||
'close_comments' => !empty($settings['comment_close_comments']),
|
||
'hot_threshold' => max(1, min(999, (int) ($settings['comment_hot_threshold'] ?? 10))),
|
||
'quick_s' => !isset($settings['comment_quick_s']) || !empty($settings['comment_quick_s']),
|
||
'quick_phrases' => self::parse_comment_quick_phrases((string) ($settings['comment_quick_often'] ?? '')),
|
||
'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')),
|
||
];
|
||
}
|
||
|
||
/**
|
||
* @return array<int,string>
|
||
*/
|
||
private static function parse_comment_quick_phrases(string $raw): array {
|
||
if (trim($raw) === '') {
|
||
$raw = "不错,学习了\n感谢分享\n期待更新";
|
||
}
|
||
$lines = preg_split('/\r\n|\r|\n/', $raw) ?: [];
|
||
$out = [];
|
||
foreach ($lines as $line) {
|
||
$line = trim((string) $line);
|
||
if ($line !== '') {
|
||
$out[] = $line;
|
||
}
|
||
}
|
||
return array_values(array_unique($out));
|
||
}
|
||
|
||
private static function normalize_comment_city_type(string $type): string {
|
||
$type = sanitize_key($type);
|
||
// Map legacy zibll 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() && !$query->is_search()) {
|
||
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 {
|
||
if (is_admin() || !$query->is_main_query()) {
|
||
return;
|
||
}
|
||
if (!$query->is_archive() && !$query->is_search() && !$query->is_home()) {
|
||
return;
|
||
}
|
||
$s = Settings::get_all();
|
||
$per_page = max(4, min(48, (int) ($s['post_list_per_page'] ?? 12)));
|
||
if ($per_page !== 12) {
|
||
$query->set('posts_per_page', $per_page);
|
||
}
|
||
}
|
||
|
||
public static function get_archive_layout(): string {
|
||
$settings = self::get_post_list_style_settings();
|
||
return $settings['render_mode'];
|
||
}
|
||
|
||
public static function get_post_pagination_mode(): string {
|
||
$settings = Settings::get_all();
|
||
|
||
// Zibll: paging_ajax_s '1' = ajax append, '0' = numeric buttons.
|
||
if (array_key_exists('paging_ajax_s', $settings)) {
|
||
$ajax = self::is_list_paging_ajax($settings);
|
||
if (!$ajax) {
|
||
return 'numbered';
|
||
}
|
||
return self::is_list_paging_ajax_ias($settings) ? 'infinite' : 'load_more';
|
||
}
|
||
|
||
// Temporary bridge for installs still holding the previous schema key only.
|
||
$mode = (string) ($settings['post_pagination_mode'] ?? 'numbered');
|
||
if ($mode === 'numeric') {
|
||
$mode = 'numbered';
|
||
}
|
||
return in_array($mode, ['numbered', 'load_more', 'infinite'], true) ? $mode : 'numbered';
|
||
}
|
||
|
||
/**
|
||
* Whether list pagination uses AJAX append (Zibll paging_ajax_s).
|
||
*
|
||
* @param array<string,mixed>|null $settings
|
||
*/
|
||
public static function is_list_paging_ajax(?array $settings = null): bool {
|
||
$settings = $settings ?? Settings::get_all();
|
||
if (!array_key_exists('paging_ajax_s', $settings)) {
|
||
// Fallback from previous 3-mode key.
|
||
$mode = (string) ($settings['post_pagination_mode'] ?? 'numbered');
|
||
return in_array($mode, ['load_more', 'infinite', 'ajax'], true);
|
||
}
|
||
$raw = $settings['paging_ajax_s'];
|
||
if (is_bool($raw)) {
|
||
return $raw;
|
||
}
|
||
return (string) $raw === '1' || (string) $raw === 'true';
|
||
}
|
||
|
||
/**
|
||
* Whether AJAX list paging auto-loads on scroll (Zibll paging_ajax_ias_s).
|
||
*
|
||
* @param array<string,mixed>|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;
|
||
}
|
||
if (!array_key_exists('paging_ajax_ias_s', $settings)) {
|
||
$mode = (string) ($settings['post_pagination_mode'] ?? '');
|
||
return $mode === 'infinite';
|
||
}
|
||
return !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;
|
||
}
|
||
}
|