refactor(autoload): migrate theme classes to Composer PSR-4

Move 288 types from global AKSRT_* + inc/classes manual requires into
namespace AKSRT\{Domain} under src/AKSRT/, wire composer.json psr-4,
and slim bootstrap to helpers/modules/hooks only. Split multi-class
widget/gateway files, update admin contract audit paths, and document
the layout in ADR/README.
This commit is contained in:
kate522 committed 2026-07-17 13:29:22 +08:00
1 parent 8f349b40fb
commit aaf458af1c
404 files changed
+13602 -7705

No files matched your search

+68 -68
View File
@@ -17,22 +17,22 @@ defined('ABSPATH') || exit;
// ============================================================
if (!defined('AKSRT_PAY_TYPE_NO')) {
define('AKSRT_PAY_TYPE_NO', AKSRT_Domain_Model::PAY_TYPE_NO);
define('AKSRT_PAY_TYPE_NO', \AKSRT\Core\DomainModel::PAY_TYPE_NO);
}
if (!defined('AKSRT_PAY_TYPE_READING')) {
define('AKSRT_PAY_TYPE_READING', AKSRT_Domain_Model::PAY_TYPE_READING);
define('AKSRT_PAY_TYPE_READING', \AKSRT\Core\DomainModel::PAY_TYPE_READING);
}
if (!defined('AKSRT_PAY_TYPE_DOWNLOAD')) {
define('AKSRT_PAY_TYPE_DOWNLOAD', AKSRT_Domain_Model::PAY_TYPE_DOWNLOAD);
define('AKSRT_PAY_TYPE_DOWNLOAD', \AKSRT\Core\DomainModel::PAY_TYPE_DOWNLOAD);
}
if (!defined('AKSRT_PAY_TYPE_GALLERY')) {
define('AKSRT_PAY_TYPE_GALLERY', AKSRT_Domain_Model::PAY_TYPE_GALLERY);
define('AKSRT_PAY_TYPE_GALLERY', \AKSRT\Core\DomainModel::PAY_TYPE_GALLERY);
}
if (!defined('AKSRT_PAY_TYPE_VIDEO')) {
define('AKSRT_PAY_TYPE_VIDEO', AKSRT_Domain_Model::PAY_TYPE_VIDEO);
define('AKSRT_PAY_TYPE_VIDEO', \AKSRT\Core\DomainModel::PAY_TYPE_VIDEO);
}
if (!defined('AKSRT_PAY_TYPE_VIP')) {
define('AKSRT_PAY_TYPE_VIP', AKSRT_Domain_Model::PAY_TYPE_VIP);
define('AKSRT_PAY_TYPE_VIP', \AKSRT\Core\DomainModel::PAY_TYPE_VIP);
}
/**
@@ -62,7 +62,7 @@ if (!function_exists('aksrt_is_vip_exempt')) {
}
function aksrt_get_pay_types(): array {
return AKSRT_Domain_Model::pay_type_labels();
return \AKSRT\Core\DomainModel::pay_type_labels();
return [
AKSRT_PAY_TYPE_NO => __('不付费', 'aksrt'),
@@ -85,14 +85,14 @@ if (!function_exists('aksrt_list_cash_payment_methods')) {
? ['balance', 'alipay', 'wechatpay', 'paypal', 'stripe']
: ['alipay', 'wechatpay', 'paypal', 'stripe'];
if (!class_exists('AKSRT_Payment_Gateway')) {
if (!class_exists('\AKSRT\Payment\Gateway')) {
return $logged_in
? [['id' => 'balance', 'name' => __('站内余额', 'aksrt')]]
: [['id' => 'alipay', 'name' => __('支付宝', 'aksrt')]];
}
$methods = [];
$gw = AKSRT_Payment_Gateway::get_instance();
$gw = \AKSRT\Payment\Gateway::get_instance();
foreach ($ids as $id) {
$g = $gw->get_gateway($id);
if (!$g) {
@@ -126,9 +126,9 @@ if (!function_exists('aksrt_get_pay_meta')) {
$p = get_post($post);
if (!($p instanceof WP_Post)) return aksrt_default_pay_meta();
$meta = get_post_meta($p->ID, AKSRT_Domain_Model::PAY_META_KEY, true);
$meta = get_post_meta($p->ID, \AKSRT\Core\DomainModel::PAY_META_KEY, true);
if (is_array($meta) && isset($meta['pay_type'])) {
return wp_parse_args(AKSRT_Domain_Model::sanitize_pay_meta($meta), aksrt_default_pay_meta());
return wp_parse_args(\AKSRT\Core\DomainModel::sanitize_pay_meta($meta), aksrt_default_pay_meta());
}
return aksrt_default_pay_meta();
@@ -137,7 +137,7 @@ if (!function_exists('aksrt_get_pay_meta')) {
if (!function_exists('aksrt_default_pay_meta')) {
function aksrt_default_pay_meta(): array {
return AKSRT_Domain_Model::default_pay_meta();
return \AKSRT\Core\DomainModel::default_pay_meta();
return [
'pay_type' => AKSRT_PAY_TYPE_NO,
@@ -190,10 +190,10 @@ if (!function_exists('aksrt_get_download_box_meta')) {
}
$pay_meta = aksrt_get_pay_meta($p);
$download_count = (int) get_post_meta($p->ID, AKSRT_Domain_Model::RESOURCE_DOWNLOAD_COUNT_KEY, true);
$view_count = (int) get_post_meta($p->ID, AKSRT_Domain_Model::POST_VIEW_COUNT_KEY, true);
$download_count = (int) get_post_meta($p->ID, \AKSRT\Core\DomainModel::RESOURCE_DOWNLOAD_COUNT_KEY, true);
$view_count = (int) get_post_meta($p->ID, \AKSRT\Core\DomainModel::POST_VIEW_COUNT_KEY, true);
$virtual_sales = max(0, (int) ($pay_meta['virtual_sales'] ?? 0));
$sales_volume = (int) get_post_meta($p->ID, AKSRT_Domain_Model::RESOURCE_SALES_VOLUME_KEY, true);
$sales_volume = (int) get_post_meta($p->ID, \AKSRT\Core\DomainModel::RESOURCE_SALES_VOLUME_KEY, true);
$show_sales = !isset($pay_meta['show_sales']) || !empty($pay_meta['show_sales']);
$pay_modo = (($pay_meta['pay_modo'] ?? '0') === 'points') ? 'points' : '0';
$pay_limit = (int) ($pay_meta['pay_limit'] ?? 0);
@@ -242,11 +242,11 @@ if (!function_exists('aksrt_get_download_box_meta')) {
if (!function_exists('aksrt_get_user_content_paid_order')) {
function aksrt_get_user_content_paid_order(int $post_id, int $user_id = 0): ?array {
$uid = $user_id > 0 ? $user_id : get_current_user_id();
if ($uid <= 0 || $post_id <= 0 || !class_exists('AKSRT_Order_Repository')) {
if ($uid <= 0 || $post_id <= 0 || !class_exists('\AKSRT\Payment\OrderRepository')) {
return null;
}
$orders = AKSRT_Order_Repository::get_instance()->get_user_orders($uid, [
'product_type' => AKSRT_Domain_Model::ORDER_PRODUCT_RESOURCE,
$orders = \AKSRT\Payment\OrderRepository::get_instance()->get_user_orders($uid, [
'product_type' => \AKSRT\Core\DomainModel::ORDER_PRODUCT_RESOURCE,
'status' => '',
'limit' => 20,
'offset' => 0,
@@ -256,7 +256,7 @@ if (!function_exists('aksrt_get_user_content_paid_order')) {
continue;
}
$status = (string) ($order['status'] ?? '');
if (AKSRT_Domain_Model::is_paid_order_status($status)) {
if (\AKSRT\Core\DomainModel::is_paid_order_status($status)) {
return $order;
}
}
@@ -272,7 +272,7 @@ if (!function_exists('aksrt_bump_content_sales_volume')) {
if ($post_id <= 0 || $delta === 0) {
return 0;
}
$key = AKSRT_Domain_Model::RESOURCE_SALES_VOLUME_KEY;
$key = \AKSRT\Core\DomainModel::RESOURCE_SALES_VOLUME_KEY;
$cur = (int) get_post_meta($post_id, $key, true);
$next = max(0, $cur + $delta);
update_post_meta($post_id, $key, $next);
@@ -298,8 +298,8 @@ if (!function_exists('aksrt_allow_guest_content_pay')) {
if ($pay_modo === 'points') {
return false; // points require login
}
$order = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_order_settings() : [];
$paid = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_paid_content_settings() : [];
$order = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_order_settings() : [];
$paid = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_paid_content_settings() : [];
$allow = !empty($order['no_logged_in']) || !empty($paid['no_logged_in']);
/**
* Filter guest content pay allow.
@@ -317,8 +317,8 @@ if (!function_exists('aksrt_allow_guest_content_pay')) {
if (!function_exists('aksrt_guest_pay_cookie_days')) {
function aksrt_guest_pay_cookie_days(int $post_id = 0): int {
$days = 15;
if (class_exists('AKSRT_Settings')) {
$order = AKSRT_Settings::get_order_settings();
if (class_exists('\AKSRT\Settings\Settings')) {
$order = \AKSRT\Settings\Settings::get_order_settings();
$days = max(1, min(31, (int) ($order['cookie_day'] ?? 15)));
}
/**
@@ -368,8 +368,8 @@ if (!function_exists('aksrt_content_order_cookie_token_key')) {
*/
if (!function_exists('aksrt_allow_guest_forum_pay')) {
function aksrt_allow_guest_forum_pay($post = null): bool {
$order = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_order_settings() : [];
$paid = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_paid_content_settings() : [];
$order = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_order_settings() : [];
$paid = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_paid_content_settings() : [];
$allow = !empty($order['no_logged_in']) || !empty($paid['no_logged_in']);
/**
* @param bool $allow
@@ -429,14 +429,14 @@ if (!function_exists('aksrt_get_guest_paid_order')) {
if ($product_id <= 0 || empty($_COOKIE['aksrt_pay_' . $product_id])) {
return null;
}
if (!class_exists('AKSRT_Order_Repository') || !class_exists('AKSRT_Domain_Model')) {
if (!class_exists('\AKSRT\Payment\OrderRepository') || !class_exists('\AKSRT\Core\DomainModel')) {
return null;
}
$order_number = sanitize_text_field((string) $_COOKIE['aksrt_pay_' . $product_id]);
if ($order_number === '') {
return null;
}
$order = AKSRT_Order_Repository::get_instance()->get($order_number);
$order = \AKSRT\Payment\OrderRepository::get_instance()->get($order_number);
if (!$order) {
return null;
}
@@ -453,7 +453,7 @@ if (!function_exists('aksrt_get_guest_paid_order')) {
return null;
}
$status = (string) ($order['status'] ?? '');
if (!AKSRT_Domain_Model::is_paid_order_status($status)) {
if (!\AKSRT\Core\DomainModel::is_paid_order_status($status)) {
return null;
}
@@ -484,8 +484,8 @@ if (!function_exists('aksrt_get_guest_paid_order')) {
*/
if (!function_exists('aksrt_get_guest_content_paid_order')) {
function aksrt_get_guest_content_paid_order(int $post_id): ?array {
$type = class_exists('AKSRT_Domain_Model')
? AKSRT_Domain_Model::ORDER_PRODUCT_RESOURCE
$type = class_exists('\AKSRT\Core\DomainModel')
? \AKSRT\Core\DomainModel::ORDER_PRODUCT_RESOURCE
: 'resource';
return aksrt_get_guest_paid_order($post_id, $type);
}
@@ -505,8 +505,8 @@ if (!function_exists('aksrt_guest_has_paid_access')) {
*/
if (!function_exists('aksrt_guest_has_plate_follow_access')) {
function aksrt_guest_has_plate_follow_access(int $plate_id): bool {
$type = class_exists('AKSRT_Domain_Model')
? AKSRT_Domain_Model::ORDER_PRODUCT_PLATE_FOLLOW
$type = class_exists('\AKSRT\Core\DomainModel')
? \AKSRT\Core\DomainModel::ORDER_PRODUCT_PLATE_FOLLOW
: 'plate_follow';
return null !== aksrt_get_guest_paid_order($plate_id, $type);
}
@@ -524,7 +524,7 @@ if (!function_exists('aksrt_guest_has_plate_follow_access')) {
*/
if (!function_exists('aksrt_get_user_pay_price')) {
function aksrt_get_user_pay_price($post = null, int $user_id = 0): array {
$meta = function_exists('aksrt_get_pay_meta') ? aksrt_get_pay_meta($post) : AKSRT_Domain_Model::default_pay_meta();
$meta = function_exists('aksrt_get_pay_meta') ? aksrt_get_pay_meta($post) : \AKSRT\Core\DomainModel::default_pay_meta();
$pay_modo = (($meta['pay_modo'] ?? '0') === 'points') ? 'points' : '0';
$pay_limit = (int) ($meta['pay_limit'] ?? 0);
if (!in_array($pay_limit, [0, 1, 2], true)) {
@@ -540,10 +540,10 @@ if (!function_exists('aksrt_get_user_pay_price')) {
$vip_level = max($vip_level, 2);
}
$currency = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_currency_name() : __('积分', 'aksrt');
$currency = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_currency_name() : __('积分', 'aksrt');
$cash_symbol = '¥';
if (class_exists('AKSRT_Settings')) {
$paid = AKSRT_Settings::get_paid_content_settings();
if (class_exists('\AKSRT\Settings\Settings')) {
$paid = \AKSRT\Settings\Settings::get_paid_content_settings();
$cash_symbol = (string) ($paid['display']['currency_symbol'] ?? '¥');
}
@@ -604,12 +604,12 @@ if (!function_exists('aksrt_is_content_coupon_allowed')) {
if (!empty($meta['coupon_s'])) {
return true;
}
if (class_exists('AKSRT_Settings') && method_exists('AKSRT_Settings', 'get_content_coupon_settings')) {
$cfg = AKSRT_Settings::get_content_coupon_settings();
if (class_exists('\AKSRT\Settings\Settings') && method_exists('\AKSRT\Settings\Settings', 'get_content_coupon_settings')) {
$cfg = \AKSRT\Settings\Settings::get_content_coupon_settings();
return !empty($cfg['enabled']);
}
if (class_exists('AKSRT_Settings') && method_exists('AKSRT_Settings', 'get_paid_content_settings')) {
$paid = AKSRT_Settings::get_paid_content_settings();
if (class_exists('\AKSRT\Settings\Settings') && method_exists('\AKSRT\Settings\Settings', 'get_paid_content_settings')) {
$paid = \AKSRT\Settings\Settings::get_paid_content_settings();
return !empty($paid['coupon_post_s']);
}
return false;
@@ -627,17 +627,17 @@ if (!function_exists('aksrt_get_post_rebate_discount')) {
if ($fixed <= 0) {
return 0.0;
}
if (!class_exists('AKSRT_Settings') || !method_exists('AKSRT_Settings', 'get_payment_affiliate_settings')) {
if (!class_exists('\AKSRT\Settings\Settings') || !method_exists('\AKSRT\Settings\Settings', 'get_payment_affiliate_settings')) {
return 0.0;
}
$aff = AKSRT_Settings::get_payment_affiliate_settings();
$aff = \AKSRT\Settings\Settings::get_payment_affiliate_settings();
if (empty($aff['enabled'])) {
return 0.0;
}
$uid = $user_id > 0 ? $user_id : (function_exists('get_current_user_id') ? (int) get_current_user_id() : 0);
$referrer_id = 0;
if (class_exists('AKSRT_Invite') && method_exists(AKSRT_Invite::get_instance(), 'get_referrer')) {
$referrer_id = (int) AKSRT_Invite::get_instance()->get_referrer($uid);
if (class_exists('\AKSRT\Credits\Invite') && method_exists(\AKSRT\Credits\Invite::get_instance(), 'get_referrer')) {
$referrer_id = (int) \AKSRT\Credits\Invite::get_instance()->get_referrer($uid);
}
if ($referrer_id <= 0) {
return 0.0;
@@ -673,10 +673,10 @@ if (!function_exists('aksrt_is_allow_points_deduction')) {
function aksrt_is_allow_points_deduction(string $context = 'content'): bool {
// Mirror zibll hard-off first.
$allowed = false;
if (class_exists('AKSRT_Settings') && method_exists('AKSRT_Settings', 'get_all')) {
$all = AKSRT_Settings::get_all();
if (class_exists('\AKSRT\Settings\Settings') && method_exists('\AKSRT\Settings\Settings', 'get_all')) {
$all = \AKSRT\Settings\Settings::get_all();
// Even if switch on, default remains false like zibll until product enables it.
if (!empty($all['points_deduction_s']) && class_exists('AKSRT_Settings') && method_exists('AKSRT_Settings', 'credits_enabled') && AKSRT_Settings::credits_enabled()) {
if (!empty($all['points_deduction_s']) && class_exists('\AKSRT\Settings\Settings') && method_exists('\AKSRT\Settings\Settings', 'credits_enabled') && \AKSRT\Settings\Settings::credits_enabled()) {
$allowed = false; // still disabled at runtime
}
}
@@ -744,9 +744,9 @@ if (!function_exists('aksrt_has_paid_access')) {
$p = get_post($post);
if (!($p instanceof WP_Post)) return true;
// 单一真相:付费访问由 AKSRT_Content_Visibility(基于订单 + VIP)裁决。
if (class_exists('AKSRT_Content_Visibility')) {
$state = AKSRT_Content_Visibility::get_post_access_state($p, $user_id);
// 单一真相:付费访问由 \AKSRT\Content\Visibility(基于订单 + VIP)裁决。
if (class_exists('\AKSRT\Content\Visibility')) {
$state = \AKSRT\Content\Visibility::get_post_access_state($p, $user_id);
return !empty($state['has_paid_access']);
}
@@ -769,8 +769,8 @@ if (!function_exists('aksrt_can_access_content')) {
$p = get_post($post);
if (!($p instanceof WP_Post)) return true;
if (class_exists('AKSRT_Content_Visibility')) {
return AKSRT_Content_Visibility::can_view_paid_content($p);
if (class_exists('\AKSRT\Content\Visibility')) {
return \AKSRT\Content\Visibility::can_view_paid_content($p);
}
$pay_type = aksrt_get_pay_meta($p)['pay_type'];
@@ -789,7 +789,7 @@ if (!function_exists('aksrt_can_download')) {
/**
* 下载授权门禁 —— 单一合同。
*
* 实际判定交给 AKSRT_Content_Visibility::can_download_resource()。
* 实际判定交给 \AKSRT\Content\Visibility::can_download_resource()。
* 不再使用 download_credit 做按次扣积分门禁。
*
* @param int|WP_Post|null $post
@@ -797,8 +797,8 @@ if (!function_exists('aksrt_can_download')) {
* @return true|WP_Error
*/
function aksrt_can_download($post = null, int $user_id = 0) {
if (class_exists('AKSRT_Content_Visibility')) {
return AKSRT_Content_Visibility::can_download_resource($post, $user_id);
if (class_exists('\AKSRT\Content\Visibility')) {
return \AKSRT\Content\Visibility::can_download_resource($post, $user_id);
}
$p = get_post($post);
@@ -811,8 +811,8 @@ if (!function_exists('aksrt_can_download')) {
return new WP_Error('aksrt_not_downloadable', __('该内容不是可下载资源。', 'aksrt'));
}
$paid_settings = class_exists('AKSRT_Settings')
? AKSRT_Settings::get_paid_content_settings()
$paid_settings = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::get_paid_content_settings()
: ['download_login' => true];
$uid = $user_id > 0 ? $user_id : get_current_user_id();
@@ -885,10 +885,10 @@ if (!function_exists('aksrt_get_single_download_page_url')) {
*/
if (!function_exists('aksrt_is_download_alone_page_enabled')) {
function aksrt_is_download_alone_page_enabled(): bool {
if (!class_exists('AKSRT_Settings')) {
if (!class_exists('\AKSRT\Settings\Settings')) {
return false;
}
$paid = AKSRT_Settings::get_paid_content_settings();
$paid = \AKSRT\Settings\Settings::get_paid_content_settings();
return !empty($paid['down_alone_page']) || !empty($paid['download']['alone_page']);
}
}
@@ -910,10 +910,10 @@ if (!function_exists('aksrt_get_pay_price_label')) {
? (int) ($priced['pay_limit'] ?? 0)
: (int) ($meta['pay_limit'] ?? 0);
$vip_level = is_array($priced) ? (int) ($priced['vip_level'] ?? 0) : 0;
$currency = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_currency_name() : __('积分', 'aksrt');
$currency = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_currency_name() : __('积分', 'aksrt');
$cash_symbol = '¥';
if (class_exists('AKSRT_Settings')) {
$paid = AKSRT_Settings::get_paid_content_settings();
if (class_exists('\AKSRT\Settings\Settings')) {
$paid = \AKSRT\Settings\Settings::get_paid_content_settings();
$cash_symbol = (string) ($paid['display']['currency_symbol'] ?? '¥');
}
@@ -1007,8 +1007,8 @@ if (!function_exists('aksrt_get_pay_type_badge')) {
if (!function_exists('aksrt_get_pay_service_html')) {
function aksrt_get_pay_service_html(string $class = 'resource-download-box__guarantee'): string {
$service = [];
if (class_exists('AKSRT_Settings')) {
$order = AKSRT_Settings::get_order_settings();
if (class_exists('\AKSRT\Settings\Settings')) {
$order = \AKSRT\Settings\Settings::get_order_settings();
$service = is_array($order['service'] ?? null) ? $order['service'] : [];
}
@@ -1141,10 +1141,10 @@ if (!function_exists('aksrt_get_paywall_html')) {
$pay_modo = is_array($priced) ? ((($priced['modo'] ?? '0') === 'points') ? 'points' : '0') : ((($meta['pay_modo'] ?? '0') === 'points') ? 'points' : '0');
$price = is_array($priced) ? (float) ($priced['amount'] ?? 0) : (float) ($meta['price'] ?? 0);
$vip_level = is_array($priced) ? (int) ($priced['vip_level'] ?? 0) : 0;
$currency = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_currency_name() : __('积分', 'aksrt');
$currency = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_currency_name() : __('积分', 'aksrt');
$cash_symbol = '¥';
if (class_exists('AKSRT_Settings')) {
$paid = AKSRT_Settings::get_paid_content_settings();
if (class_exists('\AKSRT\Settings\Settings')) {
$paid = \AKSRT\Settings\Settings::get_paid_content_settings();
$cash_symbol = (string) ($paid['display']['currency_symbol'] ?? '¥');
}
$price_text = $pay_modo === 'points'