refactor: flatten src/AKSRT → src (drop theme-identifier dir)

Move all domain folders from src/AKSRT/{Domain} to src/{Domain}; remap
Composer PSR-4 "AKSRT\\": "src/"; update audit script + README + ADR
paths; remove dead tools/build-psr4-map.php (scanned deleted inc/classes).
This commit is contained in:
2026-08-02 22:06:06 +08:00
parent 56f1a8175f
commit 8c5b1555c9
285 changed files with 26 additions and 3600 deletions
+621
View File
@@ -0,0 +1,621 @@
<?php
/**
* @package AKSRT
*/
namespace AKSRT\Settings;
defined('ABSPATH') || exit;
class Integration {
/** 私信邮件接收组限制 (all/vip/vip2/admin) */
public static function get_email_private_receive_limit(): string {
$limit = (string) Settings::get_value('email_private_receive_limit', 'all');
$valid = ['all', 'vip', 'vip2', 'admin'];
return in_array($limit, $valid, true) ? $limit : 'all';
}
/** 获取OAuth配置 */
public static function get_oauth(): array {
return get_option('aksrt_oauth', []);
}
/** 检查OAuth平台是否已配置 */
public static function oauth_configured(string $provider): bool {
$oauth = self::get_oauth();
return !empty($oauth[$provider]['client_id']) && !empty($oauth[$provider]['client_secret']);
}
/** OAuth 代理登录模式: 'off' | 'server' | 'client' (schema 存 'close'→映射为 'off') */
public static function oauth_proxy_mode(): string {
$settings = Settings::get_all();
$mode = sanitize_key((string) ($settings['oauth_proxy_mode'] ?? ''));
if ($mode === '') {
$oauth = self::get_oauth();
$mode = $oauth['proxy']['mode'] ?? (!empty($settings['oauth_agent']) ? 'client' : 'off');
}
if ($mode === 'close') {
$mode = 'off';
}
return in_array($mode, ['off', 'server', 'client'], true) ? $mode : 'off';
}
/** OAuth 代理登录 HMAC 密钥 */
public static function oauth_proxy_secret(): string {
$settings = Settings::get_all();
if (!empty($settings['oauth_proxy_secret'])) {
return (string) $settings['oauth_proxy_secret'];
}
$oauth = self::get_oauth();
return (string) ($oauth['proxy']['secret'] ?? '');
}
/** OAuth 代理登录服务端地址(客户端模式使用) */
public static function oauth_proxy_server_url(): string {
$settings = Settings::get_all();
if (!empty($settings['oauth_proxy_server_url'])) {
return esc_url_raw((string) $settings['oauth_proxy_server_url']);
}
$oauth = self::get_oauth();
return esc_url_raw((string) ($oauth['proxy']['server_url'] ?? ''));
}
/** OAuth 代理登录允许的平台列表(服务端模式使用) */
public static function oauth_proxy_allowed_providers(): array {
$settings = Settings::get_all();
$valid = ['github', 'gitee', 'qq', 'google', 'weibo', 'weixin', 'baidu', 'alipay'];
if (isset($settings['oauth_proxy_server_providers']) && is_array($settings['oauth_proxy_server_providers'])) {
return array_values(array_intersect($settings['oauth_proxy_server_providers'], $valid));
}
$oauth = self::get_oauth();
$allowed = $oauth['proxy']['allowed_providers'] ?? ['github', 'gitee', 'qq', 'google'];
return array_values(array_intersect($allowed, $valid));
}
/** OAuth 代理登录启用的平台列表(客户端模式使用) */
public static function oauth_proxy_client_providers(): array {
$settings = Settings::get_all();
$valid = ['github', 'gitee', 'qq', 'google', 'weibo', 'weixin', 'baidu', 'alipay'];
if (isset($settings['oauth_proxy_client_providers']) && is_array($settings['oauth_proxy_client_providers'])) {
return array_values(array_intersect($settings['oauth_proxy_client_providers'], $valid));
}
$oauth = self::get_oauth();
$enabled = $oauth['proxy']['client_providers'] ?? ['github', 'gitee', 'qq', 'google'];
return array_values(array_intersect($enabled, $valid));
}
/**
* 获取微信公众号登录完整配置
*
* @return array{gzh_type:string,token:string,token_nocheck:bool,encoding_aes_key:string,appid:string,appsecret:string,code_qrcode:string,code_keyword:string,code_reply:string,code_subscribe_reply:string,subscribe_msg:string,new_subscribe_msg:string,scan_msg:string,auto_reply_text:string,auto_reply_search:string,auto_reply_image:string,auto_reply_voice:string,auto_reply_default:string,gzh_menu:string,priority:bool,auto:bool,auto_expires:int}
*/
public static function get_weixingzh_settings(): array {
$settings = Settings::get_all();
$gzh_type = sanitize_key((string) ($settings['weixingzh_gzh_type'] ?? 'service'));
if (!in_array($gzh_type, ['service', 'subscribe'], true)) {
$gzh_type = 'service';
}
$auto_expires = max(0, min(86400, (int) ($settings['weixingzh_auto_expires'] ?? 3600)));
return [
'gzh_type' => $gzh_type,
'token' => (string) ($settings['weixingzh_token'] ?? ''),
'token_nocheck' => !empty($settings['weixingzh_token_nocheck']),
'encoding_aes_key' => (string) ($settings['weixingzh_encoding_aes_key'] ?? ''),
'appid' => (string) ($settings['weixingzh_appid'] ?? ''),
'appsecret' => (string) ($settings['weixingzh_appsecret'] ?? ''),
'code_qrcode' => (string) ($settings['weixingzh_code_qrcode'] ?? ''),
'code_keyword' => (string) ($settings['weixingzh_code_keyword'] ?? '登录'),
'code_reply' => (string) ($settings['weixingzh_code_reply'] ?? ''),
'code_subscribe_reply' => (string) ($settings['weixingzh_code_subscribe_reply'] ?? ''),
'subscribe_msg' => (string) ($settings['weixingzh_subscribe_msg'] ?? ''),
'new_subscribe_msg' => (string) ($settings['weixingzh_new_subscribe_msg'] ?? ''),
'scan_msg' => (string) ($settings['weixingzh_scan_msg'] ?? ''),
'auto_reply_text' => (string) ($settings['weixingzh_auto_reply_text'] ?? ''),
'auto_reply_search' => (string) ($settings['weixingzh_auto_reply_search'] ?? ''),
'auto_reply_image' => (string) ($settings['weixingzh_auto_reply_image'] ?? ''),
'auto_reply_voice' => (string) ($settings['weixingzh_auto_reply_voice'] ?? ''),
'auto_reply_default' => (string) ($settings['weixingzh_auto_reply_default'] ?? ''),
'gzh_menu' => (string) ($settings['weixingzh_gzh_menu'] ?? ''),
'priority' => !empty($settings['weixingzh_priority']),
'auto' => !empty($settings['weixingzh_auto']),
'auto_expires' => $auto_expires,
];
}
/**
* 获取 OAuth 代理登录完整配置(aksrt_settings 优先,BC fallback aksrt_oauth)
*
* @return array{mode:string,secret:string,server_url:string,server_providers:array,client_providers:array,gzh_type:string}
*/
public static function get_oauth_proxy_settings(): array {
$settings = Settings::get_all();
$oauth = self::get_oauth();
$mode = sanitize_key((string) ($settings['oauth_proxy_mode'] ?? ''));
if ($mode === '') {
$mode = $oauth['proxy']['mode'] ?? (!empty($settings['oauth_agent']) ? 'client' : 'close');
}
if (!in_array($mode, ['close', 'server', 'client'], true)) {
$mode = 'close';
}
$secret = (string) ($settings['oauth_proxy_secret'] ?? ($oauth['proxy']['secret'] ?? ''));
$server_url = esc_url_raw((string) ($settings['oauth_proxy_server_url'] ?? ($oauth['proxy']['server_url'] ?? '')));
$valid_providers = ['github', 'gitee', 'qq', 'google', 'weibo', 'weixin', 'baidu', 'alipay'];
$server_providers = array_values(array_intersect(
(array) ($settings['oauth_proxy_server_providers'] ?? ($oauth['proxy']['allowed_providers'] ?? ['github', 'gitee', 'qq', 'google'])),
$valid_providers
));
$client_providers = array_values(array_intersect(
(array) ($settings['oauth_proxy_client_providers'] ?? ($oauth['proxy']['client_providers'] ?? ['github', 'gitee', 'qq', 'google'])),
$valid_providers
));
$gzh_type = sanitize_key((string) ($settings['oauth_proxy_gzh_type'] ?? 'service'));
if (!in_array($gzh_type, ['service', 'subscribe'], true)) {
$gzh_type = 'service';
}
return [
'mode' => $mode,
'secret' => $secret,
'server_url' => $server_url,
'server_providers' => $server_providers,
'client_providers' => $client_providers,
'gzh_type' => $gzh_type,
];
}
/**
* 获取底部Tab完整配置
* @return array {enabled, scroll_hide, scroll_down_hide, items}
*/
public static function get_footer_tabbar_settings(): array {
$defaults = [
'enabled' => true,
'scroll_hide' => false,
'scroll_down_hide' => true,
'max_items' => 5,
'icon_size' => 22,
'text_size' => 10,
'show_text' => true,
'active_color' => '#f04494',
'bg_color' => '',
'border' => true,
'shadow' => true,
'animation' => true,
'double_click_home' => true,
'badge_dot' => false,
'footer_tabbar_single' => 'default',
'items' => [
[
'id' => 'tab_home',
'type' => 'home',
'icon' => 'fas fa-home',
'text' => __('首页', 'aksrt'),
'link' => '',
'badge' => '',
'badge_mode' => 'static',
'category_id' => 0,
'new_window' => false,
'enabled' => true,
'sort_order' => 0,
'ontop' => true,
],
[
'id' => 'tab_category',
'type' => 'category',
'icon' => 'fas fa-th-large',
'text' => __('分类', 'aksrt'),
'link' => '',
'badge' => '',
'badge_mode' => 'static',
'category_id' => 0,
'new_window' => false,
'enabled' => true,
'sort_order' => 1,
],
[
'id' => 'tab_search',
'type' => 'search',
'icon' => 'fas fa-search',
'text' => __('搜索', 'aksrt'),
'link' => '',
'badge' => '',
'badge_mode' => 'dynamic',
'category_id' => 0,
'search_default_type' => 'post',
'new_window' => false,
'enabled' => true,
'sort_order' => 2,
],
[
'id' => 'tab_auth',
'type' => 'auth',
'icon' => 'fas fa-user',
'text' => __('我的', 'aksrt'),
'link' => '',
'badge' => '',
'badge_mode' => 'dynamic',
'category_id' => 0,
'search_default_type' => 'post',
'new_window' => false,
'enabled' => true,
'sort_order' => 3,
],
],
];
$saved = get_option('aksrt_footer_tabbar', []);
if (!is_array($saved)) {
$saved = [];
}
return array_merge($defaults, $saved);
}
/**
* 获取底部Tab项(仅返回启用的,按排序)
* @return array
*/
public static function get_footer_tabbar_items(): array {
$settings = self::get_footer_tabbar_settings();
if (empty($settings['enabled'])) {
return [];
}
$items = array_filter($settings['items'], fn($item) => !empty($item['enabled']));
usort($items, fn($a, $b) => ($a['sort_order'] ?? 0) <=> ($b['sort_order'] ?? 0));
return array_values($items);
}
/**
* 获取文章页专属Tab模式
* @return string 'default' | 'extend'
*/
public static function get_footer_tabbar_single(): string {
$settings = self::get_footer_tabbar_settings();
$mode = (string) ($settings['footer_tabbar_single'] ?? 'default');
$valid = ['default', 'extend'];
return in_array($mode, $valid, true) ? $mode : 'default';
}
/**
* 获取通知系统设置
* @return array {read_retention_days, unread_retention_days, max_per_user}
*/
public static function get_notification_settings(): array {
$defaults = [
'enabled_types' => [
'comment_reply' => true,
'comment_approved' => true,
'download_ready' => true,
'credits_added' => true,
'credits_deducted' => true,
'verify_email' => true,
'pending_comments' => true,
'upload_moderation' => true,
],
'user_badge_enabled' => true,
'badge_include_stateful' => true,
'read_retention_days' => 30,
'unread_retention_days' => 180,
'max_per_user' => 200,
];
$saved = get_option('aksrt_notification_settings', []);
if (!is_array($saved)) {
$saved = [];
}
$merged = array_merge($defaults, $saved);
$merged['read_retention_days'] = max(1, min(365, (int) $merged['read_retention_days']));
$merged['unread_retention_days'] = max(7, min(3650, (int) $merged['unread_retention_days']));
$merged['max_per_user'] = max(20, min(5000, (int) $merged['max_per_user']));
return $merged;
}
/** 单项通知是否启用 */
public static function notification_enabled(string $type): bool {
$settings = self::get_notification_settings();
$enabled = is_array($settings['enabled_types'] ?? null) ? $settings['enabled_types'] : [];
return !isset($enabled[$type]) || !empty($enabled[$type]);
}
/** user 徽标是否启用 */
public static function notification_user_badge_enabled(): bool {
$settings = self::get_notification_settings();
return !isset($settings['user_badge_enabled']) || !empty($settings['user_badge_enabled']);
}
/** user 徽标是否包含即时提醒 */
public static function notification_badge_include_stateful(): bool {
$settings = self::get_notification_settings();
return !empty($settings['badge_include_stateful']);
}
/** 站内通知总开关 */
public static function message_enabled(): bool {
return !empty(Settings::get_value('message_s', true));
}
/** 通知基础设置(basic group) */
public static function notification_settings(): array {
$settings = Settings::get_all();
$slug = sanitize_key((string) ($settings['msg_center_rewrite_slug'] ?? 'message'));
if ($slug === '') {
$slug = 'message';
}
$paginate = sanitize_key((string) ($settings['message_paginate_type'] ?? 'ajax_lists'));
if (!in_array($paginate, ['ajax_lists', 'default'], true)) {
$paginate = 'ajax_lists';
}
$icon_show = $settings['message_icon_show'] ?? ['nav_menu'];
if (!is_array($icon_show)) {
$icon_show = ['nav_menu'];
}
$allowed_positions = ['nav_menu', 'avatar', 'mobile_bar'];
$icon_show = array_values(array_intersect($icon_show, $allowed_positions));
return [
'enabled' => !empty($settings['message_s']),
'slug' => $slug,
'icon_show' => $icon_show,
'paginate_type' => $paginate,
'user_set' => !empty($settings['message_user_set']),
];
}
/** 已关闭的通知推送类型列表 */
public static function notification_closed_types(): array {
$types = Settings::get_value('message_close_msg_type', []);
if (!is_array($types)) {
return [];
}
$allowed = ['posts', 'comment', 'favorite', 'like', 'hot', 'followed', 'system', 'pay', 'withdraw_reply', 'medal', 'auth_apply_reply'];
return array_values(array_intersect($types, $allowed));
}
/** 自动清理已读消息配置 */
public static function auto_clear_settings(): array {
$settings = Settings::get_all();
$types = $settings['message_auto_clear_types'] ?? ['posts', 'comment', 'favorite', 'like', 'hot', 'followed', 'system'];
if (!is_array($types)) {
$types = [];
}
$allowed = ['posts', 'comment', 'favorite', 'like', 'hot', 'followed', 'system', 'pay', 'withdraw_reply', 'medal', 'auth_apply_reply', 'download', 'credits', 'private', 'report'];
return [
'enabled' => !empty($settings['message_auto_clear_s']),
'days' => max(1, min(3650, (int) ($settings['message_auto_clear_time'] ?? 365))),
'types' => array_values(array_intersect($types, $allowed)),
];
}
/** 私信功能配置 */
public static function private_message_settings(): array {
$settings = Settings::get_all();
$quick_often = (string) ($settings['private_quick_often'] ?? "你好,请问有什么可以帮你的?\n感谢你的反馈\n已处理,请查收");
$quick_lines = array_filter(array_map('trim', preg_split('/\r\n|\r|\n/', $quick_often)));
return [
'enabled' => !array_key_exists('private_s', $settings) || !empty($settings['private_s']),
'smilie' => !empty($settings['private_smilie_s']),
'code' => !empty($settings['private_code_s']),
'image' => !empty($settings['private_image_s']),
'upload_img' => !empty($settings['private_upload_img']),
'quick_reply' => !empty($settings['private_quick_s']),
'quick_often' => array_values($quick_lines),
'submit_text' => sanitize_text_field((string) ($settings['private_submit_text'] ?? '发送')),
'placeholder' => sanitize_text_field((string) ($settings['private_placeholder'] ?? '请输入消息...')),
];
}
/**
* 获取右侧浮动按钮完整配置
* @return array {enabled, style, position, scroll_hide, scroll_down_hide, filter_blur, items}
*/
public static function get_floating_buttons_settings(): array {
$defaults = [
'enabled' => true,
'style' => 'round',
'position' => 'bottom',
'scroll_hide' => false,
'scroll_down_hide' => true,
'max' => 5,
'size' => 44,
'spacing' => 10,
'shadow' => true,
'animation' => true,
'opacity' => 100,
'active_color' => '',
'bg_color' => '',
'pc_show' => true,
'm_show' => true,
'filter_blur' => ['mobile'],
'items' => [
[
'id' => 'btn_wechat',
'type' => 'service_wechat',
'icon' => 'fab fa-weixin',
'icon_dark' => '',
'icon_light' => '',
'text' => __('微信', 'aksrt'),
'desc' => '',
'action_mode'=> 'qrcode',
'qq' => '',
'qrcode_img' => '',
'wechat_img' => '',
'link' => '',
'add_items' => [],
'hover' => '',
'qr_size' => 120,
'hover_width' => 200,
'pc_s' => true,
'm_s' => true,
'color' => '',
'bg' => '',
'enabled' => true,
'sort_order' => 0,
],
[
'id' => 'btn_theme',
'type' => 'theme_mode',
'icon' => 'fas fa-sun',
'icon_dark' => '',
'icon_light' => '',
'text' => __('主题', 'aksrt'),
'desc' => __('切换主题', 'aksrt'),
'action_mode'=> 'link',
'qq' => '',
'qrcode_img' => '',
'wechat_img' => '',
'link' => '',
'add_items' => [],
'hover' => '',
'qr_size' => 120,
'hover_width' => 200,
'pc_s' => true,
'm_s' => false,
'color' => '',
'bg' => '',
'enabled' => true,
'sort_order' => 1,
],
[
'id' => 'btn_top',
'type' => 'back_top',
'icon' => 'fas fa-chevron-up',
'icon_dark' => '',
'icon_light' => '',
'text' => __('顶部', 'aksrt'),
'desc' => __('返回顶部', 'aksrt'),
'action_mode'=> 'link',
'qq' => '',
'qrcode_img' => '',
'wechat_img' => '',
'link' => '',
'add_items' => [],
'hover' => '',
'qr_size' => 120,
'hover_width' => 200,
'pc_s' => true,
'm_s' => true,
'color' => '',
'bg' => '',
'enabled' => true,
'sort_order' => 2,
],
],
];
$saved = get_option('aksrt_floating_buttons', []);
if (!is_array($saved)) {
$saved = [];
}
return array_merge($defaults, $saved);
}
/**
* 获取右侧浮动按钮项(仅返回启用的,按排序)
* @return array
*/
public static function get_floating_buttons_items(): array {
$settings = self::get_floating_buttons_settings();
if (empty($settings['enabled'])) {
return [];
}
$items = array_filter($settings['items'], fn($item) => !empty($item['enabled']));
usort($items, fn($a, $b) => ($a['sort_order'] ?? 0) <=> ($b['sort_order'] ?? 0));
return array_values($items);
}
/**
* 获取微信通知设置
*
* @return array{enabled:bool,app_id:string,app_secret:string,template_id:string}
*/
public static function get_wechat_settings(): array {
$stored = get_option('aksrt_wechat_settings', []);
if (!is_array($stored)) {
$stored = [];
}
return [
'enabled' => !empty($stored['enabled']),
'app_id' => sanitize_text_field((string) ($stored['app_id'] ?? '')),
'app_secret' => (string) ($stored['app_secret'] ?? ''),
'template_id' => sanitize_text_field((string) ($stored['template_id'] ?? '')),
];
}
/**
* 更新微信通知设置
*
* @param array $settings 合并后的完整微信配置
*/
public static function update_wechat_settings(array $settings): void {
$allowed = ['enabled', 'app_id', 'app_secret', 'template_id'];
$clean = [];
foreach ($allowed as $key) {
if (array_key_exists($key, $settings)) {
$clean[$key] = $settings[$key];
}
}
update_option('aksrt_wechat_settings', $clean);
}
/**
* 获取文档模式设置
*/
public static function get_docs_mode_settings(): array {
$all = Settings::get_all();
$template = in_array($all['docs_mode_default_template'] ?? '', ['documentnav', 'special'], true)
? $all['docs_mode_default_template']
: 'documentnav';
$order = in_array($all['docs_mode_default_order'] ?? '', ['menu_order', 'date', 'title'], true)
? $all['docs_mode_default_order']
: 'menu_order';
$style = in_array($all['docs_mode_style'] ?? '', ['default', 'simple', 'card'], true)
? $all['docs_mode_style']
: 'default';
$raw_cats = $all['docs_mode_cats'] ?? [];
if (!is_array($raw_cats)) {
$raw_cats = array_filter(array_map('trim', explode(',', (string) $raw_cats)));
}
$cats = array_values(array_filter(array_map('absint', $raw_cats)));
return [
'enabled' => !empty($all['docs_mode_enabled']),
'default_template' => $template,
'toc_enabled' => !isset($all['docs_mode_toc_enabled']) || !empty($all['docs_mode_toc_enabled']),
'chapter_nav_enabled' => !isset($all['docs_mode_chapter_nav_enabled']) || !empty($all['docs_mode_chapter_nav_enabled']),
'default_order' => $order,
'cats' => $cats,
'exclude' => !isset($all['docs_mode_exclude']) || !empty($all['docs_mode_exclude']),
'toc_depth' => max(1, min(6, (int) ($all['docs_mode_toc_depth'] ?? 3))),
'chapter_title' => sanitize_text_field((string) ($all['docs_mode_chapter_title'] ?? '')),
'style' => $style,
'icon' => !isset($all['docs_mode_icon']) || !empty($all['docs_mode_icon']),
'count' => !isset($all['docs_mode_count']) || !empty($all['docs_mode_count']),
'docs_mode_enabled' => !empty($all['docs_mode_enabled']),
'docs_mode_default_template' => $template,
'docs_mode_toc_enabled' => !isset($all['docs_mode_toc_enabled']) || !empty($all['docs_mode_toc_enabled']),
'docs_mode_chapter_nav_enabled' => !isset($all['docs_mode_chapter_nav_enabled']) || !empty($all['docs_mode_chapter_nav_enabled']),
'docs_mode_default_order' => $order,
'docs_mode_cats' => $cats,
'docs_mode_exclude' => !isset($all['docs_mode_exclude']) || !empty($all['docs_mode_exclude']),
'docs_mode_toc_depth' => max(1, min(6, (int) ($all['docs_mode_toc_depth'] ?? 3))),
'docs_mode_chapter_title' => sanitize_text_field((string) ($all['docs_mode_chapter_title'] ?? '')),
'docs_mode_style' => $style,
'docs_mode_icon' => !isset($all['docs_mode_icon']) || !empty($all['docs_mode_icon']),
'docs_mode_count' => !isset($all['docs_mode_count']) || !empty($all['docs_mode_count']),
];
}
}