Full-project rename. `git grep -i aksrt` is now empty apart from the
DBMigrator 3.3.0 changelog note that documents the rename itself.
Code identifiers
- PHP namespace AKSRT\ -> Jio\ (composer PSR-4 + 378 declarations)
- global constants AKSRT_* -> JIO_* (VERSION/DIR/URI, PAY_TYPE_*, CAPTCHA_*)
- procedural functions, hooks, options, meta keys, table names,
cookies, query vars, ajax actions and nonces: aksrt_ -> jio_
- text domain aksrt -> jio; Theme Name -> Jio
- JS globals: aksrtData/aksrtAdminData/... -> jioData/jioAdminData/...,
window.AKSRTCaptcha & friends -> window.JioCaptcha, Aksrt* -> Jio*
- Vue components Aks*.vue -> Jio*.vue (15 files renamed + imports)
- CSS classes/data-attrs/custom properties: aksrt- -> jio-
- REST namespace aksrt/v1 -> jio/v1 (incl. payment gateway callbacks)
Storage layer
- DB tables {prefix}aksrt_* -> {prefix}jio_*; SCHEMA_VERSION 3.2.0 -> 3.3.0
so dbDelta creates the new names on install
- widget id_base aksrt_widget_* -> jio_widget_*
- uninstall.php drop list rebuilt from the actual migrator tables
(dropped 3 stale entries, added the 17 missing ones)
Removed
- hardcoded https://api.aksrt.com/version.json default update endpoint;
get_endpoint() now reads the 「更新端点」 setting and do_check() no-ops
when it is empty
Files renamed: inc/helpers/aksrt-*.php -> jio-*.php (54),
assets/admin/src/components/form/Aks*.vue -> Jio*.vue (15).
Build artifacts regenerated: assets/css/build, assets/js/runtime,
assets/admin/build.
Verified: audit-psr4-paths errors=0, audit-admin-contracts errors=0
(warnings=56, unchanged baseline), 813/813 widget-system tests,
44/44 phpunit, php -l clean across all PHP.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
233 lines
8.4 KiB
PHP
233 lines
8.4 KiB
PHP
<?php
|
|
/**
|
|
* @package Jio
|
|
*/
|
|
|
|
namespace Jio\Settings;
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
class CreditsRuntime {
|
|
|
|
/**
|
|
* 积分配置(合并默认值)。
|
|
* @return array
|
|
*/
|
|
public static function get_credit_settings(): array {
|
|
$defaults = [
|
|
'enabled' => true,
|
|
'currency_name' => '',
|
|
|
|
'register_bonus' => 10,
|
|
|
|
'daily_signin' => [
|
|
'enabled' => true,
|
|
'base' => 1,
|
|
'streak' => [
|
|
3 => 2,
|
|
7 => 5,
|
|
30 => 20,
|
|
],
|
|
],
|
|
|
|
'comment_reward' => [
|
|
'enabled' => true,
|
|
'amount' => 1,
|
|
'daily_cap' => 5,
|
|
'min_length' => 10,
|
|
'on_approved' => true,
|
|
],
|
|
|
|
'referral_reward' => [
|
|
'enabled' => true,
|
|
'promoter_amount' => 5,
|
|
'referred_amount' => 2,
|
|
'require_verify' => true,
|
|
'ip_daily_cap' => 3,
|
|
'level_points' => 0,
|
|
],
|
|
|
|
'download_default_cost' => 0,
|
|
];
|
|
$saved = get_option('jio_credit_settings', []);
|
|
if (!is_array($saved)) {
|
|
$saved = [];
|
|
}
|
|
// Superseded top-level keys remain physically stored but are not exposed
|
|
// to runtime consumers or written back by current admin clients.
|
|
$saved = array_intersect_key($saved, $defaults);
|
|
return array_replace_recursive($defaults, $saved);
|
|
}
|
|
|
|
/**
|
|
* Normalized runtime settings for daily sign-in rewards.
|
|
*
|
|
* @return array{enabled:bool,base:int,streak:array<int,int>,currency_name:string}
|
|
*/
|
|
public static function get_signin_reward_settings(): array {
|
|
$config = self::get_credit_settings();
|
|
$signin = is_array($config['daily_signin'] ?? null) ? $config['daily_signin'] : [];
|
|
$streak = [];
|
|
|
|
foreach ((array) ($signin['streak'] ?? []) as $day => $bonus) {
|
|
$day = (int) $day;
|
|
$bonus = (int) $bonus;
|
|
if ($day <= 0 || $bonus < 0) {
|
|
continue;
|
|
}
|
|
$streak[$day] = $bonus;
|
|
}
|
|
|
|
ksort($streak, SORT_NUMERIC);
|
|
|
|
return [
|
|
'enabled' => !empty($config['enabled']) && !empty($signin['enabled']),
|
|
'base' => max(0, (int) ($signin['base'] ?? 0)),
|
|
'streak' => $streak,
|
|
'currency_name' => self::get_currency_name(),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Shared ref-code settings.
|
|
*
|
|
* @return array{code_length:int,window_days:int,attribution_model:string}
|
|
*/
|
|
public static function get_referral_settings(): array {
|
|
$all = Settings::get_all();
|
|
$attribution = sanitize_key((string) ($all['referral_attribution_model'] ?? 'first_touch'));
|
|
if (!in_array($attribution, ['first_touch', 'last_touch'], true)) {
|
|
$attribution = 'first_touch';
|
|
}
|
|
return [
|
|
'code_length' => max(4, min(12, (int) ($all['referral_code_length'] ?? 12))),
|
|
'window_days' => max(1, min(365, (int) ($all['referral_window_days'] ?? 30))),
|
|
'attribution_model' => $attribution,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array{enabled:bool,promoter_amount:int,referred_amount:int,require_verify:bool,ip_daily_cap:int,level_points:int}
|
|
*/
|
|
public static function get_referral_reward_settings(): array {
|
|
$config = self::get_credit_settings();
|
|
$reward = is_array($config['referral_reward'] ?? null) ? $config['referral_reward'] : [];
|
|
|
|
return [
|
|
'enabled' => !empty($config['enabled']) && !empty($reward['enabled']),
|
|
'promoter_amount' => max(0, (int) ($reward['promoter_amount'] ?? 0)),
|
|
'referred_amount' => max(0, (int) ($reward['referred_amount'] ?? 0)),
|
|
'require_verify' => !empty($reward['require_verify']),
|
|
'ip_daily_cap' => max(0, (int) ($reward['ip_daily_cap'] ?? 0)),
|
|
'level_points' => max(0, (int) ($reward['level_points'] ?? 0)),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array{enabled:bool,register_field:string,reject_invalid:bool,open_desc:string,required_desc:string}
|
|
*/
|
|
public static function get_referral_registration_settings(): array {
|
|
$all = Settings::get_all();
|
|
$mode = sanitize_key((string) ($all['invit_code_s'] ?? 'close'));
|
|
if (!in_array($mode, ['close', 'open', 'must'], true)) {
|
|
$mode = 'close';
|
|
}
|
|
$open_desc = trim((string) ($all['invit_code_open_desc'] ?? ''));
|
|
if ($open_desc === '') {
|
|
$open_desc = __('如您受到邀请,可填写推广码。部分推广码会有额外积分赠送', 'jio');
|
|
}
|
|
$required_desc = trim((string) ($all['invit_code_must_desc'] ?? ''));
|
|
if ($required_desc === '') {
|
|
$required_desc = __('<div>本站需使用推广码注册</div><div>获取推广码请与客服联系</div>', 'jio');
|
|
}
|
|
|
|
return [
|
|
'enabled' => $mode !== 'close',
|
|
'register_field' => $mode === 'must' ? 'required' : ($mode === 'open' ? 'optional' : 'hidden'),
|
|
'reject_invalid' => $mode !== 'close',
|
|
'open_desc' => $open_desc,
|
|
'required_desc' => $required_desc,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array{enabled:bool,register_field:string,open_desc:string,required_desc:string}
|
|
*/
|
|
public static function get_invite_code_registration_settings(): array {
|
|
$all = Settings::get_all();
|
|
$mode = sanitize_key((string) ($all['invite_code_s'] ?? 'close'));
|
|
if (!in_array($mode, ['close', 'open', 'must'], true)) {
|
|
$mode = 'close';
|
|
}
|
|
$open_desc = trim((string) ($all['invite_code_open_desc'] ?? ''));
|
|
if ($open_desc === '') {
|
|
$open_desc = __('请输入邀请码,注册成功后奖励将自动发放', 'jio');
|
|
}
|
|
$required_desc = trim((string) ($all['invite_code_must_desc'] ?? ''));
|
|
if ($required_desc === '') {
|
|
$required_desc = __('<div>本站需凭邀请码注册</div><div>获取邀请码请与客服联系</div>', 'jio');
|
|
}
|
|
|
|
return [
|
|
'enabled' => $mode !== 'close',
|
|
'register_field' => $mode === 'must' ? 'required' : ($mode === 'open' ? 'optional' : 'hidden'),
|
|
'open_desc' => $open_desc,
|
|
'required_desc' => $required_desc,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 积分功能是否启用。
|
|
* 仅看积分系统开关;不再与 cms_features.download_credit 联合(该开关表示积分购买模式,非按次扣费)。
|
|
*/
|
|
public static function credits_enabled(): bool {
|
|
$config = self::get_credit_settings();
|
|
return !empty($config['enabled']);
|
|
}
|
|
|
|
/**
|
|
* 自定义货币名称,为空时回退"积分"。
|
|
*/
|
|
public static function get_currency_name(): string {
|
|
$config = self::get_credit_settings();
|
|
$name = trim((string) ($config['currency_name'] ?? ''));
|
|
return $name !== '' ? $name : __('积分', 'jio');
|
|
}
|
|
|
|
/**
|
|
* Ref 积分奖励是否启用。
|
|
*/
|
|
public static function referral_reward_enabled(): bool {
|
|
return !empty(self::get_referral_reward_settings()['enabled']);
|
|
}
|
|
|
|
public static function referral_registration_enabled(): bool {
|
|
return !empty(self::get_referral_registration_settings()['enabled']);
|
|
}
|
|
|
|
public static function referral_register_field_mode(): string {
|
|
$registration = self::get_referral_registration_settings();
|
|
if (empty($registration['enabled'])) {
|
|
return 'hidden';
|
|
}
|
|
$mode = (string) ($registration['register_field'] ?? 'hidden');
|
|
return in_array($mode, ['hidden', 'optional', 'required'], true) ? $mode : 'hidden';
|
|
}
|
|
|
|
public static function referral_reject_invalid(): bool {
|
|
return !empty(self::get_referral_registration_settings()['reject_invalid']);
|
|
}
|
|
|
|
public static function referral_code_length(): int {
|
|
return (int) self::get_referral_settings()['code_length'];
|
|
}
|
|
|
|
/**
|
|
* 资源下载默认积分价(当资源未单独设价时回退使用)。
|
|
*/
|
|
public static function download_default_cost(): int {
|
|
$config = self::get_credit_settings();
|
|
return max(0, (int) ($config['download_default_cost'] ?? 0));
|
|
}
|
|
}
|