346 lines
18 KiB
PHP
346 lines
18 KiB
PHP
<?php
|
|
/**
|
|
* Settings forum/shop runtime helper.
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
class AKSRT_Settings_Forum_Shop {
|
|
|
|
/**
|
|
* 获取商城设置
|
|
*
|
|
* @return array
|
|
*/
|
|
public static function get_shop_settings(): array {
|
|
$s = AKSRT_Settings::get_all();
|
|
|
|
// -- basic / general --
|
|
$enabled = !empty($s['shop_s']);
|
|
$home_url = esc_url_raw((string) ($s['shop_home_url'] ?? ''));
|
|
|
|
// breadcrumbs
|
|
$breadcrumbs_s = !isset($s['shop_breadcrumbs_s']) || !empty($s['shop_breadcrumbs_s']);
|
|
$breadcrumbs_home = !isset($s['shop_breadcrumbs_home']) || !empty($s['shop_breadcrumbs_home']);
|
|
$breadcrumbs_shop_home = !isset($s['shop_breadcrumbs_shop_home']) || !empty($s['shop_breadcrumbs_shop_home']);
|
|
$breadcrumbs_shop_home_name = sanitize_text_field((string) ($s['shop_breadcrumbs_shop_home_name'] ?? '商城首页'));
|
|
|
|
// rewrite
|
|
$product_rewrite_slug = sanitize_key((string) ($s['shop_product_rewrite_slug'] ?? 'product'));
|
|
$cart_rewrite_slug = sanitize_key((string) ($s['shop_cart_rewrite_slug'] ?? 'cart'));
|
|
$rewrite_suffix_html = !empty($s['shop_rewrite_suffix_html_s']);
|
|
|
|
// -- list --
|
|
$list_orderby = sanitize_key((string) ($s['shop_list_orderby'] ?? 'date'));
|
|
if (!in_array($list_orderby, ['date', 'sales', 'price_asc', 'price_desc', 'comments'], true)) {
|
|
$list_orderby = 'date';
|
|
}
|
|
$list_count = max(4, min(100, (int) ($s['shop_list_count'] ?? 12)));
|
|
$list_paging = sanitize_key((string) ($s['shop_list_paging'] ?? 'number'));
|
|
if (!in_array($list_paging, ['number', 'ajax'], true)) {
|
|
$list_paging = 'number';
|
|
}
|
|
$list_ias_s = !empty($s['shop_list_ias_s']);
|
|
$list_ias_max = max(1, min(50, (int) ($s['shop_list_ias_max'] ?? 5)));
|
|
$list_style = sanitize_key((string) ($s['shop_list_style'] ?? 'default'));
|
|
if (!in_array($list_style, ['default', 'card-lg', 'card-sm'], true)) {
|
|
$list_style = 'default';
|
|
}
|
|
$sales_show = sanitize_key((string) ($s['shop_sales_show'] ?? 'show'));
|
|
if (!in_array($sales_show, ['show', 'hide', 'threshold'], true)) {
|
|
$sales_show = 'show';
|
|
}
|
|
$sales_show_min = max(0, min(99999, (int) ($s['shop_sales_show_min'] ?? 10)));
|
|
|
|
// -- contact --
|
|
$contact_msg_s = !isset($s['shop_contact_msg_s']) || !empty($s['shop_contact_msg_s']);
|
|
$contact_name = sanitize_text_field((string) ($s['shop_contact_name'] ?? '联系客服'));
|
|
$contact_note = sanitize_textarea_field((string) ($s['shop_contact_note'] ?? ''));
|
|
$contact_more = sanitize_textarea_field((string) ($s['shop_contact_more'] ?? ''));
|
|
|
|
// -- single --
|
|
$content_layout = sanitize_key((string) ($s['shop_content_layout'] ?? 'adapt'));
|
|
if (!in_array($content_layout, ['adapt', 'full', 'sidebar'], true)) {
|
|
$content_layout = 'adapt';
|
|
}
|
|
$content_show_bg = !empty($s['shop_content_show_bg']);
|
|
$single_tab = sanitize_textarea_field((string) ($s['shop_single_tab'] ?? ''));
|
|
$content_after = wp_kses_post((string) ($s['shop_content_after'] ?? ''));
|
|
$related_s = !isset($s['shop_single_related_s']) || !empty($s['shop_single_related_s']);
|
|
$related_opt = sanitize_textarea_field((string) ($s['shop_single_related_opt'] ?? ''));
|
|
$main_image_default = esc_url_raw((string) ($s['shop_main_image_default'] ?? ''));
|
|
|
|
// -- product defaults --
|
|
$limit_buy = max(-1, min(9999, (int) ($s['shop_limit_buy'] ?? -1)));
|
|
$guest_buy = !empty($s['shop_guest_buy']);
|
|
$email_fill = !empty($s['shop_email_fill']);
|
|
$rebate = !isset($s['shop_rebate']) || !empty($s['shop_rebate']);
|
|
$shipping_fee = sanitize_key((string) ($s['shop_shipping_fee'] ?? 'free'));
|
|
if (!in_array($shipping_fee, ['free', 'fixed', 'amount'], true)) {
|
|
$shipping_fee = 'free';
|
|
}
|
|
$after_sale = sanitize_key((string) ($s['shop_after_sale'] ?? 'refund_return'));
|
|
if (!in_array($after_sale, ['refund', 'refund_return', 'none'], true)) {
|
|
$after_sale = 'refund_return';
|
|
}
|
|
$service = sanitize_textarea_field((string) ($s['shop_service'] ?? ''));
|
|
$params_default = sanitize_textarea_field((string) ($s['shop_product_params_default'] ?? ''));
|
|
|
|
// -- shipping config --
|
|
$manual_address = !empty($s['shop_manual_address']);
|
|
$express_api_sdk = sanitize_key((string) ($s['shop_express_api_sdk'] ?? 'kuaidi100'));
|
|
if (!in_array($express_api_sdk, ['kuaidi100', 'aliyun', 'kdniao'], true)) {
|
|
$express_api_sdk = 'kuaidi100';
|
|
}
|
|
$express_query_interval = max(30, min(240, (int) ($s['shop_express_query_interval'] ?? 60)));
|
|
$express_kdniao_opt = sanitize_textarea_field((string) ($s['shop_express_kdniao_opt'] ?? ''));
|
|
$express_kuaidi100_opt = sanitize_textarea_field((string) ($s['shop_express_kuaidi100_opt'] ?? ''));
|
|
$express_aliyun_opt = sanitize_textarea_field((string) ($s['shop_express_aliyun_opt'] ?? ''));
|
|
$shipping_company = sanitize_textarea_field((string) ($s['shop_shipping_company'] ?? ''));
|
|
|
|
// -- timing --
|
|
$receipt_max_day = max(1, min(60, (int) ($s['shop_order_receipt_max_day'] ?? 15)));
|
|
$comment_max_day = max(1, min(60, (int) ($s['shop_comment_max_day'] ?? 7)));
|
|
$comment_placeholder = sanitize_text_field((string) ($s['shop_comment_placeholder'] ?? ''));
|
|
$comment_img_num = max(0, min(9, (int) ($s['shop_comment_img_num'] ?? 3)));
|
|
$after_sale_return_max_day = max(1, min(30, (int) ($s['shop_after_sale_return_express_max_day'] ?? 7)));
|
|
$after_sale_reason_refund = sanitize_textarea_field((string) ($s['shop_after_sale_reason_refund'] ?? ''));
|
|
$after_sale_reason_return = sanitize_textarea_field((string) ($s['shop_after_sale_reason_return'] ?? ''));
|
|
$author_show = !isset($s['shop_author_show']) || !empty($s['shop_author_show']);
|
|
|
|
return [
|
|
'enabled' => $enabled,
|
|
'home_url' => $home_url,
|
|
'breadcrumbs' => [
|
|
'enabled' => $breadcrumbs_s,
|
|
'home' => $breadcrumbs_home,
|
|
'shop_home' => $breadcrumbs_shop_home,
|
|
'shop_home_name' => $breadcrumbs_shop_home_name,
|
|
],
|
|
'rewrite' => [
|
|
'product_slug' => $product_rewrite_slug,
|
|
'cart_slug' => $cart_rewrite_slug,
|
|
'suffix_html' => $rewrite_suffix_html,
|
|
],
|
|
'list' => [
|
|
'orderby' => $list_orderby,
|
|
'count' => $list_count,
|
|
'paging' => $list_paging,
|
|
'ias_s' => $list_ias_s,
|
|
'ias_max' => $list_ias_max,
|
|
'style' => $list_style,
|
|
],
|
|
'sales' => [
|
|
'show' => $sales_show,
|
|
'show_min' => $sales_show_min,
|
|
],
|
|
'contact' => [
|
|
'msg_s' => $contact_msg_s,
|
|
'name' => $contact_name,
|
|
'note' => $contact_note,
|
|
'more' => $contact_more,
|
|
],
|
|
'single' => [
|
|
'content_layout' => $content_layout,
|
|
'content_show_bg' => $content_show_bg,
|
|
'tab' => $single_tab,
|
|
'content_after' => $content_after,
|
|
'related_s' => $related_s,
|
|
'related_opt' => $related_opt,
|
|
'main_image_default' => $main_image_default,
|
|
],
|
|
'product_defaults' => [
|
|
'limit_buy' => $limit_buy,
|
|
'guest_buy' => $guest_buy,
|
|
'email_fill' => $email_fill,
|
|
'rebate' => $rebate,
|
|
'shipping_fee' => $shipping_fee,
|
|
'after_sale' => $after_sale,
|
|
'service' => $service,
|
|
'params_default' => $params_default,
|
|
],
|
|
'shipping' => [
|
|
'manual_address' => $manual_address,
|
|
'express_api_sdk' => $express_api_sdk,
|
|
'express_query_interval' => $express_query_interval,
|
|
'express_kdniao_opt' => $express_kdniao_opt,
|
|
'express_kuaidi100_opt' => $express_kuaidi100_opt,
|
|
'express_aliyun_opt' => $express_aliyun_opt,
|
|
'shipping_company' => $shipping_company,
|
|
],
|
|
'timing' => [
|
|
'receipt_max_day' => $receipt_max_day,
|
|
'comment_max_day' => $comment_max_day,
|
|
'comment_placeholder' => $comment_placeholder,
|
|
'comment_img_num' => $comment_img_num,
|
|
'after_sale_return_max_day' => $after_sale_return_max_day,
|
|
'after_sale_reason_refund' => $after_sale_reason_refund,
|
|
'after_sale_reason_return' => $after_sale_reason_return,
|
|
],
|
|
'author_show' => $author_show,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 获取论坛设置
|
|
*
|
|
* 对标 zibll 论坛后台 12 section,提供一站式读取。
|
|
* 所有 key 与 schema_forum() 一一对应。
|
|
*/
|
|
public static function get_forum_settings(): array {
|
|
$s = AKSRT_Settings::get_all();
|
|
|
|
// helper: bool with default true
|
|
$bool = static fn(string $k, bool $d = false): bool =>
|
|
isset($s[$k]) ? !empty($s[$k]) : $d;
|
|
|
|
// helper: int
|
|
$int = static fn(string $k, int $d): int =>
|
|
(int) ($s[$k] ?? $d);
|
|
|
|
// helper: string
|
|
$str = static fn(string $k, string $d): string =>
|
|
sanitize_text_field((string) ($s[$k] ?? $d));
|
|
|
|
// helper: select with allowlist
|
|
$sel = static fn(string $k, string $d, array $allow): string =>
|
|
in_array($s[$k] ?? '', $allow, true) ? $s[$k] : $d;
|
|
|
|
return [
|
|
// ── basic ──
|
|
'enabled' => $bool('bbs_s', true),
|
|
'admin_users' => array_map('absint', (array) ($s['bbs_admin_users'] ?? [])),
|
|
|
|
// ── names ──
|
|
'names' => [
|
|
'forum' => $str('bbs_forum_display_name', '论坛'),
|
|
'plate' => $str('bbs_plate_display_name', '版块'),
|
|
'posts' => $str('bbs_posts_display_name', '帖子'),
|
|
'topic' => $str('bbs_topic_display_name', '话题'),
|
|
'tag' => $str('bbs_tag_display_name', '标签'),
|
|
'comment' => $str('bbs_comment_display_name', '回复'),
|
|
'question_badge' => $str('bbs_question_badge_name', '提问'),
|
|
'question_ok_badge' => $str('bbs_question_ok_badge_name', '已解决'),
|
|
'cat_moderator' => $str('bbs_cat_moderator_name', '分区版主'),
|
|
'plate_author' => $str('bbs_plate_author_name', '超级版主'),
|
|
'plate_moderator' => $str('bbs_plate_moderator_name', '版主'),
|
|
'plate_follow' => $str('bbs_plate_follow_name', '关注'),
|
|
],
|
|
|
|
// ── homepage ──
|
|
'homepage' => [
|
|
'tabs' => (array) ($s['bbs_home_tab'] ?? [
|
|
['type' => 'follow', 'label' => '关注'],
|
|
['type' => 'synthesis', 'label' => '综合'],
|
|
['type' => 'plate', 'label' => '版块'],
|
|
]),
|
|
'tab_active_index' => $int('bbs_home_tab_active_index', 1),
|
|
'quick_posts' => $bool('bbs_home_tab_quick_posts_s', true),
|
|
'tab_swiper' => $bool('bbs_home_tab_swiper', true),
|
|
],
|
|
|
|
// ── board_page ──
|
|
'board_page' => [
|
|
'top_info' => $bool('bbs_plate_top_info_s', true),
|
|
'tabs' => (array) ($s['bbs_plate_tab'] ?? [
|
|
['label' => '全部', 'sort' => 'date'],
|
|
['label' => '推荐', 'sort' => 'featured'],
|
|
['label' => '最新回复', 'sort' => 'last_reply'],
|
|
['label' => '热门', 'sort' => 'hot'],
|
|
['label' => '精华', 'sort' => 'essence'],
|
|
]),
|
|
'tab_active_index' => $int('bbs_plate_tab_active_index', 0),
|
|
'tab_swiper' => $bool('bbs_plate_tab_swiper', true),
|
|
],
|
|
|
|
// ── post_page ──
|
|
'post_page' => [
|
|
'breadcrumbs' => $bool('bbs_breadcrumbs_s', true),
|
|
'breadcrumbs_home' => $bool('bbs_breadcrumbs_home', true),
|
|
'breadcrumbs_bbs_home' => $bool('bbs_breadcrumbs_bbs_home', true),
|
|
'breadcrumbs_bbs_home_name' => $str('bbs_breadcrumbs_bbs_home_name', '论坛'),
|
|
'breadcrumbs_plate_cat' => $bool('bbs_breadcrumbs_plate_cat', true),
|
|
'score_extra_max' => $int('bbs_score_extra_max', 5),
|
|
'score_deduct_max' => $int('bbs_score_deduct_max', 3),
|
|
'maxheight_enabled' => $bool('bbs_posts_maxheight_s'),
|
|
'maxheight' => $int('bbs_posts_maxheight', 800),
|
|
'cover_ratio' => $sel('bbs_posts_cover_ratio', '16:9', ['16:9', '4:3', '1:1', '3:4']),
|
|
'cover_video_mute' => $bool('bbs_posts_cover_video_mute', true),
|
|
],
|
|
|
|
// ── reply ──
|
|
'reply' => [
|
|
'paginate_type' => $sel('bbs_reply_paginate_type', 'ajax', ['ajax', 'page']),
|
|
'paginate_ias' => $bool('bbs_reply_paginate_ias_s'),
|
|
'paginate_ias_max' => $int('bbs_reply_paginate_ias_max', 3),
|
|
'smilie' => $bool('bbs_comment_smilie', true),
|
|
'code' => $bool('bbs_comment_code', true),
|
|
'img' => $bool('bbs_comment_img', true),
|
|
'upload_img' => $bool('bbs_comment_upload_img'),
|
|
'quick_reply' => $bool('bbs_comment_quick_s', true),
|
|
'quick_phrases' => $str('bbs_comment_quick_often', "不错,学习了\n感谢分享\n期待更新"),
|
|
'placeholder' => $str('bbs_comment_placeholder', '写下你的回复…'),
|
|
'hot_threshold' => $int('bbs_comment_hot_threshold', 10),
|
|
],
|
|
|
|
// ── permissions ──
|
|
'permissions' => [
|
|
'post_add_limit' => $int('bbs_posts_add_limit_opt_max', 10),
|
|
'plate_add_limit' => $int('bbs_plate_add_limit_opt_max', 3),
|
|
'show_new_plate' => $bool('bbs_show_new_plate'),
|
|
'show_new_topic' => $bool('bbs_show_new_topic', true),
|
|
'show_apply_moderator' => $bool('bbs_show_apply_moderator', true),
|
|
'paid_content' => $bool('bbs_post_pay_hide_type_s'),
|
|
'vip_price' => $bool('bbs_post_pay_vip_price_s'),
|
|
'vip_1_discount' => $int('bbs_post_pay_vip_1_discount', 80),
|
|
'vip_2_discount' => $int('bbs_post_pay_vip_2_discount', 50),
|
|
'pay_price_limit' => $int('bbs_post_pay_price_limit', 1000),
|
|
'plate_follow_pay' => $bool('bbs_plate_follow_pay_s'),
|
|
'plate_follow_price' => $int('bbs_plate_follow_pay_price', 10),
|
|
'plate_follow_pay_type' => $sel('bbs_plate_follow_pay_type', 'money', ['money', 'points']),
|
|
],
|
|
|
|
// ── other ──
|
|
'other' => [
|
|
'vote_number_type' => $sel('bbs_vote_number_type', 'percent', ['percent', 'number']),
|
|
'vote_max' => $int('bbs_vote_max', 8),
|
|
'apply_moderator_desc' => $str('bbs_apply_moderator_desc', '欢迎有热情的用户申请成为版主,协助管理社区秩序。'),
|
|
'term_thumb' => esc_url_raw((string) ($s['bbs_term_thumb'] ?? '')),
|
|
'hide_pay_in_list' => $bool('bbs_post_lists_hide_pay_s'),
|
|
'title_strlen_limit' => $int('bbs_post_title_strlen_limit', 30),
|
|
't_placeholder' => $str('bbs_t_placeholder', '请输入标题'),
|
|
'c_placeholder' => $str('bbs_c_placeholder', '请输入内容'),
|
|
'html_suffix' => $bool('bbs_rewrite_suffix_html_s'),
|
|
'plate_slug' => $str('bbs_plate_rewrite_slug', 'board'),
|
|
'posts_slug' => $str('bbs_posts_rewrite_slug', 'topic'),
|
|
'edit_slug' => $str('bbs_posts_edit_rewrite_slug', 'topic-edit'),
|
|
'gutenberg' => $bool('bbs_posts_show_in_rest_s'),
|
|
],
|
|
|
|
// ── upload ──
|
|
'upload' => [
|
|
'img_size' => $int('bbs_upload_img_size', 2048),
|
|
'img_multiple' => $int('bbs_image_upload_multiple', 9),
|
|
'video_size' => $int('bbs_upload_video_size', 20480),
|
|
'file_size' => $int('bbs_upload_file_size', 10240),
|
|
'file_mimes' => $str('bbs_upload_file_mimes', 'jpg,jpeg,png,gif,mp4,zip,rar,pdf'),
|
|
],
|
|
|
|
// ── credits ──
|
|
'credits' => [
|
|
'post_new' => $int('bbs_credits_post_new', 5),
|
|
'plate_new' => $int('bbs_credits_plate_new', 10),
|
|
'comment_new' => $int('bbs_credits_comment_new', 2),
|
|
'comment_like' => $int('bbs_credits_comment_like', 1),
|
|
'score_extra' => $int('bbs_credits_score_extra', 3),
|
|
'essence' => $int('bbs_credits_essence', 10),
|
|
'posts_hot' => $int('bbs_credits_posts_hot', 5),
|
|
'adopted' => $int('bbs_credits_adopted', 20),
|
|
'daily_max' => $int('bbs_credits_daily_max', 50),
|
|
],
|
|
];
|
|
}
|
|
}
|