212 lines
8.8 KiB
PHP
212 lines
8.8 KiB
PHP
<?php
|
||
defined('ABSPATH') || exit;
|
||
|
||
trait AKSRT_Settings_Auth_Reader {
|
||
|
||
/** 评论是否启用 */
|
||
public static function comment_enabled(): bool {
|
||
$s = self::get_all();
|
||
return !isset($s['comment_enabled']) || !empty($s['comment_enabled']);
|
||
}
|
||
|
||
/** 是否要求注册用户才能评论 */
|
||
public static function comment_requires_registration(): bool {
|
||
return !empty(self::get_value('comment_require_login', false)) && self::comment_enabled();
|
||
}
|
||
|
||
/** 是否允许注册 */
|
||
public static function registration_enabled(): bool {
|
||
return (bool) get_option('users_can_register');
|
||
}
|
||
|
||
/** 注册是否要求邮箱验证 */
|
||
public static function registration_requires_email_verification(): bool {
|
||
$s = self::get_all();
|
||
return self::registration_enabled() && !empty($s['registration_email_verification_enabled']);
|
||
}
|
||
|
||
/** 注册邮箱验证方式 */
|
||
public static function registration_verification_method(): string {
|
||
$s = self::get_all();
|
||
$method = $s['registration_email_verification_method'] ?? 'link';
|
||
return in_array($method, ['link', 'code'], true) ? $method : 'link';
|
||
}
|
||
|
||
/** 注册邮箱验证有效期(分钟) */
|
||
public static function registration_verification_ttl_minutes(): int {
|
||
$s = self::get_all();
|
||
$ttl = (int) ($s['registration_verification_ttl_minutes'] ?? 30);
|
||
return max(5, min(1440, $ttl));
|
||
}
|
||
|
||
/** 验证成功后自动登录 */
|
||
public static function registration_auto_login_after_verify(): bool {
|
||
$s = self::get_all();
|
||
return !isset($s['registration_auto_login_after_verify']) || !empty($s['registration_auto_login_after_verify']);
|
||
}
|
||
|
||
/** 注册邮箱验证功能首次启用时间戳(用于历史账号判定) */
|
||
public static function registration_verification_enabled_at(): int {
|
||
$s = self::get_all();
|
||
return (int) ($s['registration_verification_enabled_at'] ?? 0);
|
||
}
|
||
|
||
/** 主题内置默认图片 URL */
|
||
private static function default_asset_url(string $filename): string {
|
||
return get_template_directory_uri() . '/assets/img/' . $filename;
|
||
}
|
||
|
||
/** 获取Logo URL(留空时使用内置默认;zibll别名 logo_src 回退) */
|
||
public static function logo_url(): string {
|
||
$url = trim((string) self::get_value('site_logo', ''));
|
||
if ($url === '') {
|
||
$url = trim((string) get_option('logo_src', ''));
|
||
}
|
||
return $url !== '' ? $url : self::default_asset_url('default-logo.svg');
|
||
}
|
||
|
||
/** 获取暗色模式 Logo URL(留空时跟随浅色模式;zibll别名 logo_src_dark 回退) */
|
||
public static function logo_dark_url(): string {
|
||
$url = trim((string) self::get_value('site_logo_dark', ''));
|
||
if ($url === '') {
|
||
$url = trim((string) get_option('logo_src_dark', ''));
|
||
}
|
||
return $url !== '' ? $url : self::logo_url();
|
||
}
|
||
|
||
/** 获取站点品牌文字 */
|
||
public static function logo_text(): string {
|
||
$text = trim((string) self::get_value('logo_text', ''));
|
||
return $text !== '' ? $text : get_bloginfo('name');
|
||
}
|
||
|
||
// ---- 注册登录 auth 段 getter ----
|
||
|
||
/** 一键禁用登录注册总开关(默认 false;含社交登录,不影响后台) */
|
||
public static function close_sign(): bool {
|
||
return (bool) self::get_value('close_sign', false);
|
||
}
|
||
|
||
/** 是否关闭注册(受 close_sign 总开关影响;兼容 user_close_signup 别名) */
|
||
public static function close_signup(): bool {
|
||
if (self::close_sign()) return true;
|
||
return (bool) self::get_value('user_close_signup', false);
|
||
}
|
||
|
||
/** 是否关闭账密登录(仅允许社交登录) */
|
||
public static function close_signin(): bool {
|
||
if (self::close_sign()) return true;
|
||
return (bool) self::get_value('close_signin', false);
|
||
}
|
||
|
||
/** 是否关闭登录(受 close_sign 总开关影响;兼容 user_close_login 别名) */
|
||
public static function close_login(): bool {
|
||
if (self::close_sign()) return true;
|
||
return (bool) self::get_value('user_close_login', false);
|
||
}
|
||
|
||
/** 登录注册样式: 'modal' | 'page'(默认 page;modal 运行时未就绪时自动回退 page) */
|
||
public static function user_sign_type(): string {
|
||
$type = (string) self::get_value('user_sign_type', 'page');
|
||
if (!in_array($type, ['modal', 'page'], true)) $type = 'page';
|
||
return $type;
|
||
}
|
||
|
||
/** 应急登录 Key(空=禁用;管理员通过 ?aksrt_bypass=<key> 绕过 wp-login 替换) */
|
||
public static function admin_sign_key(): string {
|
||
return trim((string) self::get_value('admin_sign_key', ''));
|
||
}
|
||
|
||
/** 登录页 UI 配置数组 */
|
||
public static function sign_page_ui(): array {
|
||
return [
|
||
'background' => self::get_value('sign_page_background', []),
|
||
'theme_mode' => in_array((string) self::get_value('sign_theme_mode', 'default'), ['default', 'light', 'dark'], true)
|
||
? (string) self::get_value('sign_theme_mode', 'default') : 'default',
|
||
'show_header' => (bool) self::get_value('sign_show_header', true),
|
||
'card_position' => in_array((string) self::get_value('sign_card_position', 'center'), ['left', 'center', 'right'], true)
|
||
? (string) self::get_value('sign_card_position', 'center') : 'center',
|
||
'show_logo' => (bool) self::get_value('sign_show_logo', true),
|
||
'footer' => (string) self::get_value('sign_page_footer', ''),
|
||
];
|
||
}
|
||
|
||
/** 弹窗 UI 配置数组 */
|
||
public static function modal_ui(): array {
|
||
return [
|
||
'background' => self::get_value('sign_modal_background', []),
|
||
'show_logo' => (bool) self::get_value('sign_modal_show_logo', true),
|
||
];
|
||
}
|
||
|
||
/** 登录框日间 LOGO URL(空时回退全局 logo_url) */
|
||
public static function user_logo_url(): string {
|
||
$ids = self::get_value('user_logo', []);
|
||
if (is_array($ids) && !empty($ids)) {
|
||
$url = wp_get_attachment_url((int) $ids[0]);
|
||
if ($url) return $url;
|
||
}
|
||
return self::logo_url();
|
||
}
|
||
|
||
/** 登录框夜间 LOGO URL(空时回退全局 logo_dark_url) */
|
||
public static function user_logo_dark_url(): string {
|
||
$ids = self::get_value('user_logo_dark', []);
|
||
if (is_array($ids) && !empty($ids)) {
|
||
$url = wp_get_attachment_url((int) $ids[0]);
|
||
if ($url) return $url;
|
||
}
|
||
return self::logo_dark_url();
|
||
}
|
||
|
||
/** 是否允许手机号登录 */
|
||
public static function signin_phone_enabled(): bool {
|
||
return (bool) self::get_value('user_signin_phone_s', false);
|
||
}
|
||
|
||
/** 免密登录显示模式 */
|
||
public static function nopas_active_mode(): string {
|
||
$mode = (string) self::get_value('user_signin_nopas_active', 'nopas_first');
|
||
return in_array($mode, ['nopas_first', 'password_first', 'nopas_only'], true) ? $mode : 'nopas_first';
|
||
}
|
||
|
||
/** 绑定提醒类型(兼容旧 bool 值:true→'phone',false→'close') */
|
||
public static function bind_reminder_type(): string {
|
||
$val = self::get_value('bind_reminder', 'close');
|
||
if (is_bool($val)) return $val ? 'phone' : 'close';
|
||
$val = (string) $val;
|
||
return in_array($val, ['email', 'phone', 'email_phone', 'close'], true) ? $val : 'close';
|
||
}
|
||
|
||
/** 强制绑定类型(兼容旧 bool 值:true→'phone',false→'close') */
|
||
public static function mandatory_bind_type(): string {
|
||
$val = self::get_value('mandatory_bind', 'close');
|
||
if (is_bool($val)) return $val ? 'phone' : 'close';
|
||
$val = (string) $val;
|
||
return in_array($val, ['email', 'phone', 'email_phone', 'close'], true) ? $val : 'close';
|
||
}
|
||
|
||
/** 昵称黑名单关键词数组 */
|
||
public static function nickname_blacklist(): array {
|
||
$raw = (string) self::get_value('user_nickname_out', '');
|
||
if ($raw === '') return [];
|
||
// 支持逗号分隔和换行分隔
|
||
$items = preg_split('/[,,\r\n]+/', $raw);
|
||
return array_values(array_filter(array_map('trim', $items), 'strlen'));
|
||
}
|
||
|
||
/** 邮箱限制配置:['type' => 'black'|'white', 'domains' => [...]] */
|
||
public static function email_limit(): array {
|
||
$type = (string) self::get_value('user_email_limit_type', 'black');
|
||
if (!in_array($type, ['black', 'white'], true)) $type = 'black';
|
||
$raw = (string) self::get_value('user_email_out', '');
|
||
$domains = [];
|
||
if ($raw !== '') {
|
||
$items = preg_split('/[\r\n]+/', $raw);
|
||
$domains = array_values(array_filter(array_map('trim', $items), 'strlen'));
|
||
}
|
||
return ['type' => $type, 'domains' => $domains];
|
||
}
|
||
|
||
}
|