diff --git a/inc/helpers/user-center-renderers/settings-bindings.php b/inc/helpers/user-center-renderers/settings-bindings.php
index a23209b6..907cb2c6 100644
--- a/inc/helpers/user-center-renderers/settings-bindings.php
+++ b/inc/helpers/user-center-renderers/settings-bindings.php
@@ -9,7 +9,7 @@
defined('ABSPATH') || exit;
-$oauth = class_exists('AKSRT_OAuth') ? AKSRT_OAuth::get_instance() : null;
+$oauth = class_exists('\AKSRT\Auth\OAuth') ? \AKSRT\Auth\OAuth::get_instance() : null;
$oauth_data = $oauth ? $oauth->get_frontend_bindings_data($user_id) : ['bindings' => [], 'available' => []];
$binding_name_map = [
'github' => 'GitHub',
diff --git a/inc/helpers/user-center-renderers/sidebar-commerce.php b/inc/helpers/user-center-renderers/sidebar-commerce.php
index f2105281..e688aac6 100644
--- a/inc/helpers/user-center-renderers/sidebar-commerce.php
+++ b/inc/helpers/user-center-renderers/sidebar-commerce.php
@@ -25,7 +25,7 @@ if ($show_wallet || $show_credits) :
-
+
diff --git a/inc/classes/auth/class-aksrt-captcha.php b/inc/modules/captcha.php
similarity index 100%
rename from inc/classes/auth/class-aksrt-captcha.php
rename to inc/modules/captcha.php
diff --git a/inc/modules/creator-revenue.php b/inc/modules/creator-revenue.php
new file mode 100644
index 00000000..911571f9
--- /dev/null
+++ b/inc/modules/creator-revenue.php
@@ -0,0 +1,8 @@
+ 'verify_email',
'title' => __('邮箱待验证', 'aksrt'),
@@ -49,7 +49,7 @@ function aksrt_get_user_notifications(int $user_id = 0): array {
'status' => 'hold',
]);
- if ($pending_comments > 0 && (!class_exists('AKSRT_Settings') || AKSRT_Settings::notification_enabled('pending_comments'))) {
+ if ($pending_comments > 0 && (!class_exists('\AKSRT\Settings\Settings') || \AKSRT\Settings\Settings::notification_enabled('pending_comments'))) {
$items[] = [
'type' => 'pending_comments',
'title' => __('评论待审核', 'aksrt'),
@@ -99,7 +99,7 @@ function aksrt_get_user_inbox_notifications(int $user_id = 0): array {
if ($user_id <= 0) return [];
global $wpdb;
- $table = class_exists('AKSRT_DB_Migrator') ? AKSRT_DB_Migrator::table('notification') : '';
+ $table = class_exists('\AKSRT\Core\DBMigrator') ? \AKSRT\Core\DBMigrator::table('notification') : '';
if ($table === '') {
$items = get_user_meta($user_id, 'aksrt_notifications', true);
return is_array($items) ? array_values($items) : [];
@@ -171,12 +171,12 @@ if (!function_exists('aksrt_cleanup_notifications')) :
function aksrt_cleanup_notifications(): void {
global $wpdb;
- $table = class_exists('AKSRT_DB_Migrator') ? AKSRT_DB_Migrator::table('notification') : '';
+ $table = class_exists('\AKSRT\Core\DBMigrator') ? \AKSRT\Core\DBMigrator::table('notification') : '';
if ($table === '') {
return;
}
- $settings = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_notification_settings() : [
+ $settings = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_notification_settings() : [
'read_retention_days' => 30,
'unread_retention_days' => 180,
'max_per_user' => 200,
@@ -237,7 +237,7 @@ if (!function_exists('aksrt_write_user_inbox_notifications')) :
function aksrt_write_user_inbox_notifications(int $user_id, array $items): void {
if ($user_id <= 0) return;
global $wpdb;
- $table = class_exists('AKSRT_DB_Migrator') ? AKSRT_DB_Migrator::table('notification') : '';
+ $table = class_exists('\AKSRT\Core\DBMigrator') ? \AKSRT\Core\DBMigrator::table('notification') : '';
if ($table === '') {
update_user_meta($user_id, 'aksrt_notifications', array_values(array_slice($items, 0, 50)));
return;
@@ -265,12 +265,12 @@ if (!function_exists('aksrt_add_user_notification')) :
function aksrt_add_user_notification(int $user_id, array $payload): void {
if ($user_id <= 0) return;
$type = sanitize_key((string) ($payload['type'] ?? 'notice'));
- if (class_exists('AKSRT_Settings') && !AKSRT_Settings::notification_enabled($type)) {
+ if (class_exists('\AKSRT\Settings\Settings') && !\AKSRT\Settings\Settings::notification_enabled($type)) {
return;
}
global $wpdb;
- $table = class_exists('AKSRT_DB_Migrator') ? AKSRT_DB_Migrator::table('notification') : '';
+ $table = class_exists('\AKSRT\Core\DBMigrator') ? \AKSRT\Core\DBMigrator::table('notification') : '';
$created_at = (string) ($payload['created_at'] ?? current_time('mysql', true));
if ($table === '') {
@@ -306,7 +306,7 @@ if (!function_exists('aksrt_mark_user_notification_read')) :
function aksrt_mark_user_notification_read(int $user_id, string $notification_id = '', bool $mark_all = false): void {
if ($user_id <= 0) return;
global $wpdb;
- $table = class_exists('AKSRT_DB_Migrator') ? AKSRT_DB_Migrator::table('notification') : '';
+ $table = class_exists('\AKSRT\Core\DBMigrator') ? \AKSRT\Core\DBMigrator::table('notification') : '';
if ($table === '') {
$items = aksrt_get_user_inbox_notifications($user_id);
foreach ($items as &$item) {
@@ -345,7 +345,7 @@ if (!function_exists('aksrt_delete_user_notification')) :
function aksrt_delete_user_notification(int $user_id, string $notification_id): void {
if ($user_id <= 0 || $notification_id === '') return;
global $wpdb;
- $table = class_exists('AKSRT_DB_Migrator') ? AKSRT_DB_Migrator::table('notification') : '';
+ $table = class_exists('\AKSRT\Core\DBMigrator') ? \AKSRT\Core\DBMigrator::table('notification') : '';
if ($table === '') {
$items = aksrt_get_user_inbox_notifications($user_id);
$items = array_values(array_filter($items, static function ($item) use ($notification_id) {
@@ -366,7 +366,7 @@ function aksrt_delete_user_notifications(int $user_id, array $notification_ids):
if (empty($ids)) return;
global $wpdb;
- $table = class_exists('AKSRT_DB_Migrator') ? AKSRT_DB_Migrator::table('notification') : '';
+ $table = class_exists('\AKSRT\Core\DBMigrator') ? \AKSRT\Core\DBMigrator::table('notification') : '';
if ($table === '') {
$items = aksrt_get_user_inbox_notifications($user_id);
$items = array_values(array_filter($items, static function ($item) use ($ids) {
@@ -401,12 +401,12 @@ function aksrt_get_user_tab_badge_count(int $user_id = 0): int {
if ($user_id <= 0) {
return 0;
}
- if (class_exists('AKSRT_Settings') && !AKSRT_Settings::notification_user_badge_enabled()) {
+ if (class_exists('\AKSRT\Settings\Settings') && !\AKSRT\Settings\Settings::notification_user_badge_enabled()) {
return 0;
}
$count = aksrt_get_user_unread_notification_count($user_id);
- if (class_exists('AKSRT_Settings') && AKSRT_Settings::notification_badge_include_stateful()) {
+ if (class_exists('\AKSRT\Settings\Settings') && \AKSRT\Settings\Settings::notification_badge_include_stateful()) {
$count += aksrt_get_user_notification_count($user_id);
}
return $count;
diff --git a/inc/classes/user/user-parts/aksrt-user-account-ajax.php b/inc/modules/user-parts/account-ajax.php
similarity index 97%
rename from inc/classes/user/user-parts/aksrt-user-account-ajax.php
rename to inc/modules/user-parts/account-ajax.php
index dfde8814..023e5fbb 100644
--- a/inc/classes/user/user-parts/aksrt-user-account-ajax.php
+++ b/inc/modules/user-parts/account-ajax.php
@@ -195,8 +195,8 @@ add_action('wp_ajax_aksrt_send_email_code', function () {
$current_user->display_name,
$code
);
- $sent = class_exists( 'AKSRT_Settings' )
- ? AKSRT_Settings::send_event_email(
+ $sent = class_exists( '\AKSRT\Settings\Settings' )
+ ? \AKSRT\Settings\Settings::send_event_email(
'change_code', $target_email, $default_subject, $default_content,
[ '{username}' => $current_user->display_name, '{site_name}' => $site_name, '{code}' => $code ]
)
@@ -345,8 +345,8 @@ add_action('wp_ajax_aksrt_change_email', function () {
$current_user->display_name,
$new_email
);
- if ( class_exists( 'AKSRT_Settings' ) ) {
- AKSRT_Settings::send_event_email(
+ if ( class_exists( '\AKSRT\Settings\Settings' ) ) {
+ \AKSRT\Settings\Settings::send_event_email(
'change_notice', $old_email, $default_subject, $default_content,
[ '{username}' => $current_user->display_name, '{site_name}' => $site_name, '{new_email}' => $new_email ]
);
@@ -364,11 +364,11 @@ add_action('wp_ajax_aksrt_change_email', function () {
$verify_url = '';
$verify_message = '';
- if ( class_exists( 'AKSRT_Settings' ) && class_exists( 'AKSRT_Auth_Service' )
- && AKSRT_Settings::registration_requires_email_verification() ) {
+ if ( class_exists( '\AKSRT\Settings\Settings' ) && class_exists( '\AKSRT\Auth\Service' )
+ && \AKSRT\Settings\Settings::registration_requires_email_verification() ) {
update_user_meta( $user_id, 'aksrt_email_verified', 0 );
// 用户对自身的 edit_user 权限映射到 'read',因此 admin_send_verification 会通过权限校验。
- $verify_result = AKSRT_Auth_Service::admin_send_verification( $user_id, $user_id );
+ $verify_result = \AKSRT\Auth\Service::admin_send_verification( $user_id, $user_id );
if ( ! empty( $verify_result['success'] ) ) {
$verify_url = function_exists('aksrt_get_verify_email_url') ? aksrt_get_verify_email_url( $user_id ) : '';
$verify_message = __( '请前往新邮箱完成验证,否则下次登录将被拦截。', 'aksrt' );
diff --git a/inc/classes/user/user-parts/aksrt-user-routing.php b/inc/modules/user-parts/routing.php
similarity index 100%
rename from inc/classes/user/user-parts/aksrt-user-routing.php
rename to inc/modules/user-parts/routing.php
diff --git a/inc/classes/user/user-parts/aksrt-user-template-registry.php b/inc/modules/user-parts/template-registry.php
similarity index 100%
rename from inc/classes/user/user-parts/aksrt-user-template-registry.php
rename to inc/modules/user-parts/template-registry.php
diff --git a/inc/classes/user/user-parts/aksrt-user-urls.php b/inc/modules/user-parts/urls.php
similarity index 97%
rename from inc/classes/user/user-parts/aksrt-user-urls.php
rename to inc/modules/user-parts/urls.php
index 6fd6c95c..be0e9d1f 100644
--- a/inc/classes/user/user-parts/aksrt-user-urls.php
+++ b/inc/modules/user-parts/urls.php
@@ -261,7 +261,7 @@ function aksrt_get_verify_email_url(int $user_id = 0, array $args = []): string
endif;
// Notifications live in the same user/ domain; bootstrap also loads it.
-if (!class_exists('AKSRT_User_Notifications', false) && file_exists(__DIR__ . '/class-aksrt-user-notifications.php')) {
- require_once __DIR__ . '/class-aksrt-user-notifications.php';
+if (!class_exists('AKSRT_User_Notifications', false) /* procedural module */ && file_exists(dirname(__DIR__) . '/user-notifications.php')) {
+ require_once dirname(__DIR__) . '/user-notifications.php';
}
diff --git a/inc/classes/widgets/class-aksrt-widgets.php b/inc/modules/widgets-register.php
similarity index 94%
rename from inc/classes/widgets/class-aksrt-widgets.php
rename to inc/modules/widgets-register.php
index d680b7aa..49e6627c 100644
--- a/inc/classes/widgets/class-aksrt-widgets.php
+++ b/inc/modules/widgets-register.php
@@ -11,49 +11,49 @@ defined('ABSPATH') || exit;
* Register custom widgets.
*/
function aksrt_register_widgets() {
- register_widget('AKSRT_About_Widget');
- register_widget('AKSRT_Categories_Widget');
- register_widget('AKSRT_Tag_Cloud_Widget');
- register_widget('AKSRT_Hot_Posts_Widget');
- register_widget('AKSRT_Tab_Posts_Widget');
- register_widget('AKSRT_Category_Block_Widget');
- register_widget('AKSRT_Category_Tabs_Widget');
- register_widget('AKSRT_Category_Recommend_Widget');
+ register_widget('\AKSRT\Widgets\AboutWidget');
+ register_widget('\AKSRT\Widgets\CategoriesWidget');
+ register_widget('\AKSRT\Widgets\TagCloudWidget');
+ register_widget('\AKSRT\Widgets\HotPostsWidget');
+ register_widget('\AKSRT\Widgets\TabPostsWidget');
+ register_widget('\AKSRT\Widgets\CategoryBlockWidget');
+ register_widget('\AKSRT\Widgets\CategoryTabsWidget');
+ register_widget('\AKSRT\Widgets\CategoryRecommendWidget');
// 第一批通用 widget
- register_widget('AKSRT_Search_Widget');
- register_widget('AKSRT_Notice_Widget');
- register_widget('AKSRT_Recent_Comments_Widget');
- register_widget('AKSRT_Friend_Links_Widget');
- register_widget('AKSRT_Icon_Cards_Widget');
- register_widget('AKSRT_Buttons_Widget');
- register_widget('AKSRT_Custom_HTML_Gap_Widget');
+ register_widget('\AKSRT\Widgets\SearchWidget');
+ register_widget('\AKSRT\Widgets\NoticeWidget');
+ register_widget('\AKSRT\Widgets\RecentCommentsWidget');
+ register_widget('\AKSRT\Widgets\FriendLinksWidget');
+ register_widget('\AKSRT\Widgets\IconCardsWidget');
+ register_widget('\AKSRT\Widgets\ButtonsWidget');
+ register_widget('\AKSRT\Widgets\CustomHtmlGapWidget');
// 公告跑马灯
- register_widget('AKSRT_Widget_Announcement');
+ register_widget('\AKSRT\Widgets\WidgetAnnouncement');
// 用户卡片
- register_widget('AKSRT_Widget_User_Card');
+ register_widget('\AKSRT\Widgets\WidgetUserCard');
// 用户排行榜
- register_widget('AKSRT_Widget_User_Ranking');
+ register_widget('\AKSRT\Widgets\WidgetUserRanking');
// 图文封面卡片
- register_widget('AKSRT_Widget_Cover_Cards');
+ register_widget('\AKSRT\Widgets\WidgetCoverCards');
// 视频播放器
- register_widget('AKSRT_Widget_Video_Player');
+ register_widget('\AKSRT\Widgets\WidgetVideoPlayer');
// 语言切换器
- register_widget('AKSRT_Widget_Lang_Switch');
+ register_widget('\AKSRT\Widgets\WidgetLangSwitch');
// 一言轮播
- register_widget('AKSRT_Widget_Yiyan');
+ register_widget('\AKSRT\Widgets\WidgetYiyan');
// Shop product widgets (§6.9)
- register_widget('AKSRT_Widget_Product_List');
- register_widget('AKSRT_Widget_Product_Oneline');
- register_widget('AKSRT_Widget_Product_Tab');
+ register_widget('\AKSRT\Widgets\WidgetProductList');
+ register_widget('\AKSRT\Widgets\WidgetProductOneline');
+ register_widget('\AKSRT\Widgets\WidgetProductTab');
aksrt_maybe_repair_sidebar_blog_widgets();
}
diff --git a/page.php b/page.php
index cae9a5b6..9be4fd02 100644
--- a/page.php
+++ b/page.php
@@ -9,8 +9,8 @@ defined('ABSPATH') || exit;
get_header();
-$page_settings = class_exists('AKSRT_Settings')
- ? AKSRT_Settings::get_post_page_settings()
+$page_settings = class_exists('\AKSRT\Settings\Settings')
+ ? \AKSRT\Settings\Settings::get_post_page_settings()
: ['reading_progress' => false, 'lightbox' => true];
$page_id = get_queried_object_id();
$page_content_style = get_post_meta($page_id, 'page_content_style', true);
diff --git a/search.php b/search.php
index 9fd9745d..47aca4df 100644
--- a/search.php
+++ b/search.php
@@ -26,14 +26,14 @@ $search_placeholder = function_exists('aksrt_get_search_placeholder') ? aksrt_ge
$search_type = $search_state['type'];
$search_type_options = !empty($search_state['types']) && is_array($search_state['types']) ? $search_state['types'] : ['post' => __('文章', 'aksrt')];
$hot_keywords = function_exists('aksrt_get_search_hot_keywords') ? aksrt_get_search_hot_keywords() : [];
-$filter_settings = class_exists('AKSRT_Settings')
- ? AKSRT_Settings::get_post_filter_settings()
+$filter_settings = class_exists('\AKSRT\Settings\Settings')
+ ? \AKSRT\Settings\Settings::get_post_filter_settings()
: ['enabled' => false, 'categories' => true, 'tags' => false, 'sort' => true];
-$list_settings = class_exists('AKSRT_Settings')
- ? AKSRT_Settings::get_post_list_style_settings()
+$list_settings = class_exists('\AKSRT\Settings\Settings')
+ ? \AKSRT\Settings\Settings::get_post_list_style_settings()
: ['render_mode' => 'card', 'card_style' => 'standard'];
-$other_page_settings = class_exists('AKSRT_Settings')
- ? AKSRT_Settings::get_other_page_settings()
+$other_page_settings = class_exists('\AKSRT\Settings\Settings')
+ ? \AKSRT\Settings\Settings::get_other_page_settings()
: ['page_search_sidebar' => true];
$popular_categories = get_categories([
'taxonomy' => 'category',
diff --git a/slim-forum.php b/slim-forum.php
index 520b3853..736407a7 100644
--- a/slim-forum.php
+++ b/slim-forum.php
@@ -1,217 +1,9 @@
0) {
- $ch = $content[$i];
- $next = ($i + 1 < $len) ? $content[$i + 1] : '';
-
- if ($in_line_comment) {
- if ($ch === "\n") $in_line_comment = false;
- $i++;
- continue;
- }
- if ($in_block_comment) {
- if ($ch === '*' && $next === '/') { $in_block_comment = false; $i += 2; continue; }
- $i++;
- continue;
- }
- if ($in_string_single) {
- if ($ch === '\\') { $i += 2; continue; }
- if ($ch === "'") $in_string_single = false;
- $i++;
- continue;
- }
- if ($in_string_double) {
- if ($ch === '\\') { $i += 2; continue; }
- if ($ch === '"') $in_string_double = false;
- $i++;
- continue;
- }
- if ($ch === '/' && $next === '/') { $in_line_comment = true; $i += 2; continue; }
- if ($ch === '/' && $next === '*') { $in_block_comment = true; $i += 2; continue; }
- if ($ch === "'") { $in_string_single = true; $i++; continue; }
- if ($ch === '"') { $in_string_double = true; $i++; continue; }
-
- if ($ch === '{') $depth++;
- elseif ($ch === '}') $depth--;
- $i++;
- }
-
- if ($depth !== 0) {
- echo "WARNING: Could not find matching closing brace for: $signature\n";
- return $content;
- }
-
- $close_brace = $i - 1;
-
- // Get indentation of the method
- $line_start = strrpos(substr($content, 0, $pos), "\n");
- if ($line_start === false) $line_start = 0;
- else $line_start++;
- $indent = '';
- for ($j = $line_start; $j < $pos; $j++) {
- if ($content[$j] === ' ' || $content[$j] === "\t") $indent .= $content[$j];
- else break;
- }
-
- // Replace from open_brace to close_brace (inclusive)
- $replacement = "{\n" . $indent . " " . $body . "\n" . $indent . "}";
- $content = substr($content, 0, $open_brace) . $replacement . substr($content, $close_brace + 1);
-
- return $content;
-}
-
-// --- DRAFT SERVICE METHODS ---
-
-$content = replace_method($content,
- 'public function publish_draft(int $user_id, int $draft_id, array $data)',
- 'return $this->draft_service()->publish_draft($user_id, $draft_id, $data);');
-
-$content = replace_method($content,
- 'public function ajax_delete_draft(): void',
- '$this->draft_service()->ajax_delete_draft();');
-
-$content = replace_method($content,
- 'public function ajax_load_draft(): void',
- '$this->draft_service()->ajax_load_draft();');
-
-$content = replace_method($content,
- 'public function ajax_save_draft(): void',
- '$this->draft_service()->ajax_save_draft();');
-
-$content = replace_method($content,
- 'public function load_draft_data(int $user_id, int $draft_id): ?array',
- 'return $this->draft_service()->load_draft_data($user_id, $draft_id);');
-
-$content = replace_method($content,
- 'public function delete_draft(int $user_id, int $draft_id): bool',
- 'return $this->draft_service()->delete_draft($user_id, $draft_id);');
-
-$content = replace_method($content,
- 'public function get_user_drafts(int $user_id, int $limit = 20): array',
- 'return $this->draft_service()->get_user_drafts($user_id, $limit);');
-
-$content = replace_method($content,
- 'public function get_user_draft_count(int $user_id): int',
- 'return $this->draft_service()->get_user_draft_count($user_id);');
-
-$content = replace_method($content,
- 'public function save_draft(int $user_id, array $data)',
- 'return $this->draft_service()->save_draft($user_id, $data);');
-
-// --- COMMENT SERVICE METHODS ---
-
-$content = replace_method($content,
- 'public function get_commenter_badge(int $user_id, int $topic_id): ?array',
- 'return $this->comment_service()->get_commenter_badge($user_id, $topic_id);');
-
-$content = replace_method($content,
- 'public function is_hot_comment(int $comment_id): bool',
- 'return $this->comment_service()->is_hot_comment($comment_id);');
-
-$content = replace_method($content,
- 'public function maybe_mark_hot_comment(int $comment_id): bool',
- 'return $this->comment_service()->maybe_mark_hot_comment($comment_id);');
-
-$content = replace_method($content,
- 'public function set_comment_topping(int $comment_id, int $level): bool',
- 'return $this->comment_service()->set_comment_topping($comment_id, $level);');
-
-$sig_forum_comments = "public function get_forum_comments(int \$topic_id, string \$sort = 'newest', bool \$author_only = false, int \$page = 1, int \$per_page = 30): array";
-$content = replace_method($content, $sig_forum_comments,
- 'return $this->comment_service()->get_forum_comments($topic_id, $sort, $author_only, $page, $per_page);');
-
-$content = replace_method($content,
- 'public function get_adopted_comment_id(int $topic_id): int',
- 'return $this->comment_service()->get_adopted_comment_id($topic_id);');
-
-$content = replace_method($content,
- 'public function adopt_answer(int $topic_id, int $comment_id, int $operator_id)',
- 'return $this->comment_service()->adopt_answer($topic_id, $comment_id, $operator_id);');
-
-$content = replace_method($content,
- 'public function render_forum_comments(array $comments, int $topic_id, int $adopted_id = 0): void',
- '$this->comment_service()->render_forum_comments($comments, $topic_id, $adopted_id);');
-
-$content = replace_method($content,
- 'public function ajax_comment_topping(): void',
- '$this->comment_service()->ajax_comment_topping();');
-
-$content = replace_method($content,
- 'public function ajax_forum_comments(): void',
- '$this->comment_service()->ajax_forum_comments();');
-
-// --- SCORE/NOTIFICATION SERVICE METHODS ---
-
-$content = replace_method($content,
- 'public function on_forum_comment_posted(int $comment_id, $approved, array $commentdata = []): void',
- '$this->score_service()->on_forum_comment_posted($comment_id, $approved, $commentdata);');
-
-$content = replace_method($content,
- 'public function notify_topic_scored(int $topic_id, int $scorer_id, int $amount): void',
- '$this->score_service()->notify_topic_scored($topic_id, $scorer_id, $amount);');
-
-$content = replace_method($content,
- 'public function notify_topic_reply(int $topic_id, int $commenter_id): void',
- '$this->score_service()->notify_topic_reply($topic_id, $commenter_id);');
-
-$content = replace_method($content,
- 'public function notify_moderation_result(int $topic_id, string $action, int $operator_id): void',
- '$this->score_service()->notify_moderation_result($topic_id, $action, $operator_id);');
-
-$content = replace_method($content,
- 'public function notify_topic_pending(int $topic_id, int $author_id): void',
- '$this->score_service()->notify_topic_pending($topic_id, $author_id);');
-
-$content = replace_method($content,
- 'private function notify(int $user_id, string $type, string $content, array $data = []): void',
- '$this->score_service()->notify($user_id, $type, $content, $data);');
-
-// --- Write result ---
-$result = file_put_contents($file, $content);
-if ($result === false) {
- echo "ERROR: Cannot write file\n";
- exit(1);
-}
-
-echo "SUCCESS: File updated. New size: " . strlen($content) . " bytes\n";
-echo "Line count: " . (substr_count($content, "\n") + 1) . "\n";
\ No newline at end of file
+fwrite(STDERR, "slim-forum.php is obsolete after the PSR-4 migration.\n");
+exit(1);
diff --git a/inc/classes/admin/class-aksrt-admin-ai-controller.php b/src/AKSRT/Admin/AIController.php
similarity index 85%
rename from inc/classes/admin/class-aksrt-admin-ai-controller.php
rename to src/AKSRT/Admin/AIController.php
index f0efa162..524478b0 100644
--- a/inc/classes/admin/class-aksrt-admin-ai-controller.php
+++ b/src/AKSRT/Admin/AIController.php
@@ -1,15 +1,13 @@
can_submit();
+ if (class_exists('\AKSRT\Core\FrontSubmit')) {
+ return (bool) \AKSRT\Core\FrontSubmit::get_instance()->can_submit();
}
return false;
}
- public function get_status(): WP_REST_Response {
- if (!class_exists('AKSRT_AI')) {
+ public function get_status(): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Ai\AI')) {
return $this->success(['data' => [
'enabled' => false,
'provider' => 'none',
@@ -89,11 +87,11 @@ class AKSRT_Admin_AI_Controller extends AKSRT_Admin_Controller_Base {
]]);
}
- return $this->success(['data' => AKSRT_AI::get_instance()->get_status()]);
+ return $this->success(['data' => \AKSRT\Ai\AI::get_instance()->get_status()]);
}
- public function update_settings(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_AI')) {
+ public function update_settings(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Ai\AI')) {
return $this->error(__('AI 模块未加载', 'aksrt'), 500);
}
@@ -128,11 +126,11 @@ class AKSRT_Admin_AI_Controller extends AKSRT_Admin_Controller_Base {
}
}
- $success = AKSRT_AI::get_instance()->update_config($config);
+ $success = \AKSRT\Ai\AI::get_instance()->update_config($config);
if ($success) {
return $this->success([
'message' => __('AI 设置已保存', 'aksrt'),
- 'data' => AKSRT_AI::get_instance()->get_status(),
+ 'data' => \AKSRT\Ai\AI::get_instance()->get_status(),
]);
}
return $this->error(__('保存失败', 'aksrt'));
@@ -141,8 +139,8 @@ class AKSRT_Admin_AI_Controller extends AKSRT_Admin_Controller_Base {
/**
* POST /ai/seo-generate — 从 post/term 实体生成 SEO 三字段。
*/
- public function seo_generate(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_AI_SEO')) {
+ public function seo_generate(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Ai\AISEO')) {
return $this->error(__('AI SEO 模块未加载', 'aksrt'), 500);
}
@@ -164,7 +162,7 @@ class AKSRT_Admin_AI_Controller extends AKSRT_Admin_Controller_Base {
}
}
- $result = AKSRT_AI_SEO::get_instance()->generate_fields($type, $id);
+ $result = \AKSRT\Ai\AISEO::get_instance()->generate_fields($type, $id);
if (empty($result['success'])) {
return $this->error((string) ($result['message'] ?? __('生成失败', 'aksrt')));
}
@@ -172,8 +170,8 @@ class AKSRT_Admin_AI_Controller extends AKSRT_Admin_Controller_Base {
return $this->success(['data' => $result['data']]);
}
- public function seo_suggest(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_AI_SEO')) {
+ public function seo_suggest(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Ai\AISEO')) {
return $this->error(__('AI SEO 模块未加载', 'aksrt'), 500);
}
@@ -190,7 +188,7 @@ class AKSRT_Admin_AI_Controller extends AKSRT_Admin_Controller_Base {
return $this->error(__('标题不能为空', 'aksrt'));
}
- $result = AKSRT_AI_SEO::get_instance()->suggest($title, $content);
+ $result = \AKSRT\Ai\AISEO::get_instance()->suggest($title, $content);
if (!empty($result['success'])) {
return $this->success(['data' => $result['data']]);
}
@@ -198,8 +196,8 @@ class AKSRT_Admin_AI_Controller extends AKSRT_Admin_Controller_Base {
return $this->error((string) ($result['message'] ?? __('生成失败', 'aksrt')));
}
- public function summary_suggest(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_AI') || !class_exists('AKSRT_AI_Prompt')) {
+ public function summary_suggest(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Ai\AI') || !class_exists('\AKSRT\Ai\AIPrompt')) {
return $this->error(__('AI 模块未加载', 'aksrt'), 500);
}
@@ -223,7 +221,7 @@ class AKSRT_Admin_AI_Controller extends AKSRT_Admin_Controller_Base {
return $this->error(__('内容不能为空,请先在编辑器填写正文后再生成摘要', 'aksrt'), 422);
}
- $ai = AKSRT_AI::get_instance();
+ $ai = \AKSRT\Ai\AI::get_instance();
if (!$ai->is_available()) {
return $this->error(
__('AI 服务未启用或未配置。请到「扩展 → AI 辅助」启用并填写 API Key(或配置 WordPress AI Connectors)。', 'aksrt'),
@@ -232,7 +230,7 @@ class AKSRT_Admin_AI_Controller extends AKSRT_Admin_Controller_Base {
}
// Prefer excerpt-oriented prompt when title is present.
- $prompt_builder = AKSRT_AI_Prompt::get_instance();
+ $prompt_builder = \AKSRT\Ai\AIPrompt::get_instance();
if ($title !== '' && method_exists($prompt_builder, 'build_excerpt_prompt')) {
$prompt = $prompt_builder->build_excerpt_prompt($title, $content);
} else {
@@ -278,8 +276,8 @@ class AKSRT_Admin_AI_Controller extends AKSRT_Admin_Controller_Base {
return $this->error($message, $status);
}
- public function tags_suggest(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_AI') || !class_exists('AKSRT_AI_Prompt')) {
+ public function tags_suggest(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Ai\AI') || !class_exists('\AKSRT\Ai\AIPrompt')) {
return $this->error(__('AI 模块未加载', 'aksrt'), 500);
}
@@ -291,8 +289,8 @@ class AKSRT_Admin_AI_Controller extends AKSRT_Admin_Controller_Base {
return $this->error(__('标题或内容不能为空', 'aksrt'));
}
- $prompt = AKSRT_AI_Prompt::get_instance()->build_tags_prompt($title, $content);
- $result = AKSRT_AI::get_instance()->generate_text($prompt, [
+ $prompt = \AKSRT\Ai\AIPrompt::get_instance()->build_tags_prompt($title, $content);
+ $result = \AKSRT\Ai\AI::get_instance()->generate_text($prompt, [
'max_tokens' => 300,
'temperature' => 0.5,
]);
diff --git a/inc/classes/admin/class-aksrt-admin.php b/src/AKSRT/Admin/Admin.php
similarity index 92%
rename from inc/classes/admin/class-aksrt-admin.php
rename to src/AKSRT/Admin/Admin.php
index 4a439af1..0f79f858 100644
--- a/inc/classes/admin/class-aksrt-admin.php
+++ b/src/AKSRT/Admin/Admin.php
@@ -1,18 +1,13 @@
min(100, (int) $request->get_param('per_page')),
'offset' => ((int) $request->get_param('page') - 1) * (int) $request->get_param('per_page'),
@@ -165,7 +163,7 @@ class AKSRT_Admin_Comment_Controller extends AKSRT_Admin_Controller_Base {
/**
* POST /comments — Create a comment.
*/
- public function create_comment(WP_REST_Request $request): WP_REST_Response {
+ public function create_comment(\WP_REST_Request $request): \WP_REST_Response {
$user_id = get_current_user_id();
$post_id = (int) $request->get_param('post_id');
$content = trim((string) $request->get_param('content'));
@@ -200,7 +198,7 @@ class AKSRT_Admin_Comment_Controller extends AKSRT_Admin_Controller_Base {
/**
* POST /comments/{id}/status — Approve/unapprove/spam/trash.
*/
- public function update_comment_status(WP_REST_Request $request): WP_REST_Response {
+ public function update_comment_status(\WP_REST_Request $request): \WP_REST_Response {
$comment_id = (int) $request->get_param('id');
$new_status = $request->get_param('status');
$comment = get_comment($comment_id);
@@ -233,7 +231,7 @@ class AKSRT_Admin_Comment_Controller extends AKSRT_Admin_Controller_Base {
/**
* POST /comments/{id} — Edit comment content.
*/
- public function update_comment(WP_REST_Request $request): WP_REST_Response {
+ public function update_comment(\WP_REST_Request $request): \WP_REST_Response {
$comment_id = (int) $request->get_param('id');
$content = trim((string) $request->get_param('content'));
$comment = get_comment($comment_id);
@@ -258,7 +256,7 @@ class AKSRT_Admin_Comment_Controller extends AKSRT_Admin_Controller_Base {
/**
* DELETE /comments/{id} — Delete a comment.
*/
- public function delete_comment(WP_REST_Request $request): WP_REST_Response {
+ public function delete_comment(\WP_REST_Request $request): \WP_REST_Response {
$comment_id = (int) $request->get_param('id');
$comment = get_comment($comment_id);
@@ -277,7 +275,7 @@ class AKSRT_Admin_Comment_Controller extends AKSRT_Admin_Controller_Base {
/**
* POST /comments/bulk — Bulk action on comments.
*/
- public function bulk_action(WP_REST_Request $request): WP_REST_Response {
+ public function bulk_action(\WP_REST_Request $request): \WP_REST_Response {
$body = $request->get_json_params();
$ids = array_map('absint', $body['ids'] ?? []);
$action = sanitize_text_field($body['action'] ?? '');
@@ -325,7 +323,7 @@ class AKSRT_Admin_Comment_Controller extends AKSRT_Admin_Controller_Base {
/**
* GET /comments/post/{post_id} — Public: list comments for a post with nesting.
*/
- public function get_post_comments(WP_REST_Request $request): WP_REST_Response {
+ public function get_post_comments(\WP_REST_Request $request): \WP_REST_Response {
$post_id = (int) $request->get_param('post_id');
$page = max(1, (int) $request->get_param('page'));
$per_page = min(50, max(1, (int) $request->get_param('per_page')));
diff --git a/inc/classes/admin/class-aksrt-admin-controller-base.php b/src/AKSRT/Admin/ControllerBase.php
similarity index 82%
rename from inc/classes/admin/class-aksrt-admin-controller-base.php
rename to src/AKSRT/Admin/ControllerBase.php
index 3f3001d2..1cdd46de 100644
--- a/inc/classes/admin/class-aksrt-admin-controller-base.php
+++ b/src/AKSRT/Admin/ControllerBase.php
@@ -1,19 +1,16 @@
true], $data), $status);
+ protected function success($data = [], int $status = 200): \WP_REST_Response {
+ return new \WP_REST_Response(array_merge(['success' => true], $data), $status);
}
/**
* Create a standard error response.
*/
- protected function error(string $message, int $status = 400): WP_REST_Response {
- return new WP_REST_Response([
+ protected function error(string $message, int $status = 400): \WP_REST_Response {
+ return new \WP_REST_Response([
'success' => false,
'message' => $message,
], $status);
@@ -50,7 +47,7 @@ abstract class AKSRT_Admin_Controller_Base {
/**
* Read JSON request body safely.
*/
- protected function get_json_params(WP_REST_Request $request): array {
+ protected function get_json_params(\WP_REST_Request $request): array {
$params = $request->get_json_params();
return is_array($params) ? $params : [];
}
@@ -102,7 +99,7 @@ abstract class AKSRT_Admin_Controller_Base {
protected function register_section_routes(string $route_slug, string $domain): void {
register_rest_route(self::API_NAMESPACE, '/settings/' . $route_slug . '/(?P
[a-z0-9_-]+)', [
'methods' => 'GET',
- 'callback' => function (WP_REST_Request $request) use ($domain) {
+ 'callback' => function (\WP_REST_Request $request) use ($domain) {
return $this->get_section_settings($request, $domain);
},
'permission_callback' => [$this, 'check_permission'],
@@ -110,15 +107,15 @@ abstract class AKSRT_Admin_Controller_Base {
register_rest_route(self::API_NAMESPACE, '/settings/' . $route_slug . '/(?P[a-z0-9_-]+)', [
'methods' => 'POST',
- 'callback' => function (WP_REST_Request $request) use ($domain) {
+ 'callback' => function (\WP_REST_Request $request) use ($domain) {
return $this->save_section_settings($request, $domain);
},
'permission_callback' => [$this, 'check_permission'],
]);
}
- protected function get_section_settings(WP_REST_Request $request, string $domain): WP_REST_Response {
- $provider = AKSRT_Admin_Schema_Provider::get_instance();
+ protected function get_section_settings(\WP_REST_Request $request, string $domain): \WP_REST_Response {
+ $provider = SchemaProvider::get_instance();
$section = (string) $request->get_param('section');
$schema = $provider->get_section_schema($domain, $section);
@@ -137,8 +134,8 @@ abstract class AKSRT_Admin_Controller_Base {
]);
}
- protected function save_section_settings(WP_REST_Request $request, string $domain): WP_REST_Response {
- $provider = AKSRT_Admin_Schema_Provider::get_instance();
+ protected function save_section_settings(\WP_REST_Request $request, string $domain): \WP_REST_Response {
+ $provider = SchemaProvider::get_instance();
$section = (string) $request->get_param('section');
$schema = $provider->get_section_schema($domain, $section);
diff --git a/inc/classes/admin/class-aksrt-admin-extension-controller.php b/src/AKSRT/Admin/ExtensionController.php
similarity index 90%
rename from inc/classes/admin/class-aksrt-admin-extension-controller.php
rename to src/AKSRT/Admin/ExtensionController.php
index 84e5ba32..4e8a036a 100644
--- a/inc/classes/admin/class-aksrt-admin-extension-controller.php
+++ b/src/AKSRT/Admin/ExtensionController.php
@@ -1,16 +1,13 @@
admin = $admin;
}
@@ -78,7 +75,7 @@ class AKSRT_Admin_Extension_Controller extends AKSRT_Admin_Controller_Base {
/**
* GET /extensions/overview — real extension status aggregation.
*/
- public function get_overview(): WP_REST_Response {
+ public function get_overview(): \WP_REST_Response {
$services = $this->collect_service_statuses();
$installed = 0;
@@ -111,7 +108,7 @@ class AKSRT_Admin_Extension_Controller extends AKSRT_Admin_Controller_Base {
]);
}
- public function get_docs_stats(): WP_REST_Response {
+ public function get_docs_stats(): \WP_REST_Response {
return $this->success([
'data' => [
'total' => 0,
@@ -124,7 +121,7 @@ class AKSRT_Admin_Extension_Controller extends AKSRT_Admin_Controller_Base {
/**
* GET /docs/search — search document pages by keyword.
*/
- public function search_docs(WP_REST_Request $request): WP_REST_Response {
+ public function search_docs(\WP_REST_Request $request): \WP_REST_Response {
return $this->success([
'data' => [
'results' => [],
@@ -136,7 +133,7 @@ class AKSRT_Admin_Extension_Controller extends AKSRT_Admin_Controller_Base {
/**
* GET /settings/extensions — aggregated extension service status.
*/
- public function get_extensions_status(): WP_REST_Response {
+ public function get_extensions_status(): \WP_REST_Response {
$services = $this->collect_service_statuses();
$flat = [];
@@ -157,9 +154,9 @@ class AKSRT_Admin_Extension_Controller extends AKSRT_Admin_Controller_Base {
/**
* GET /settings/security — security settings summary with real service status.
*/
- public function get_security_settings(): WP_REST_Response {
+ public function get_security_settings(): \WP_REST_Response {
$services = $this->collect_service_statuses();
- $settings = AKSRT_Settings::get_all();
+ $settings = \AKSRT\Settings\Settings::get_all();
$email_gate_enabled = true;
if (defined('AKSRT_NO_EMAIL_GATE') && AKSRT_NO_EMAIL_GATE) {
@@ -169,7 +166,7 @@ class AKSRT_Admin_Extension_Controller extends AKSRT_Admin_Controller_Base {
$captcha = function_exists('aksrt_get_captcha_status_summary')
? aksrt_get_captcha_status_summary()
: ['enabled' => false, 'provider' => '', 'configured' => false, 'scenes' => []];
- $features = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_cms_features() : [];
+ $features = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_cms_features() : [];
$scenes = is_array($captcha['scenes'] ?? null) ? $captcha['scenes'] : [];
$risk_switches = [
@@ -206,7 +203,7 @@ class AKSRT_Admin_Extension_Controller extends AKSRT_Admin_Controller_Base {
/**
* POST /settings/security — save risk switches.
*/
- public function save_security_settings(WP_REST_Request $request): WP_REST_Response {
+ public function save_security_settings(\WP_REST_Request $request): \WP_REST_Response {
$params = $this->get_json_params($request);
$risk_switches = $params['risk_switches'] ?? [];
@@ -223,7 +220,7 @@ class AKSRT_Admin_Extension_Controller extends AKSRT_Admin_Controller_Base {
$sanitized = $this->sanitize_fields($risk_switches, $allowed);
// Merge into main settings
- $all = AKSRT_Settings::get_all();
+ $all = \AKSRT\Settings\Settings::get_all();
foreach ($sanitized as $key => $val) {
$all[$key] = $val;
}
@@ -239,7 +236,7 @@ class AKSRT_Admin_Extension_Controller extends AKSRT_Admin_Controller_Base {
/**
* GET /security/audit-log — recent security audit entries.
*/
- public function get_audit_log(): WP_REST_Response {
+ public function get_audit_log(): \WP_REST_Response {
global $wpdb;
$limit = 20;
@@ -293,7 +290,7 @@ class AKSRT_Admin_Extension_Controller extends AKSRT_Admin_Controller_Base {
* Admin tests force a live lookup (skip enable-gate + cache) so operators can
* verify credentials before flipping the runtime switch.
*/
- public function test_ip_geo(WP_REST_Request $request): WP_REST_Response {
+ public function test_ip_geo(\WP_REST_Request $request): \WP_REST_Response {
$params = $this->get_json_params($request);
$ip = trim((string) ($params['ip'] ?? ''));
@@ -301,11 +298,11 @@ class AKSRT_Admin_Extension_Controller extends AKSRT_Admin_Controller_Base {
return $this->error(__('请输入有效的 IP 地址', 'aksrt'), 422);
}
- if (!class_exists('AKSRT_IP_Geo')) {
+ if (!class_exists('\AKSRT\Extensions\IPGeo')) {
return $this->error(__('IP 归属地服务不可用', 'aksrt'), 500);
}
- $geo = AKSRT_IP_Geo::get_instance();
+ $geo = \AKSRT\Extensions\IPGeo::get_instance();
$status = $geo->get_status();
$result = $geo->lookup($ip, true);
@@ -355,7 +352,7 @@ class AKSRT_Admin_Extension_Controller extends AKSRT_Admin_Controller_Base {
* Admin tests force a live provider call (skip enable gates + failure allow policy)
* so operators can verify credentials before flipping runtime switches.
*/
- public function test_content_audit(WP_REST_Request $request): WP_REST_Response {
+ public function test_content_audit(\WP_REST_Request $request): \WP_REST_Response {
$params = $this->get_json_params($request);
$text = trim((string) ($params['text'] ?? ''));
@@ -363,11 +360,11 @@ class AKSRT_Admin_Extension_Controller extends AKSRT_Admin_Controller_Base {
return $this->error(__('请输入要测试的文本内容', 'aksrt'), 422);
}
- if (!class_exists('AKSRT_Content_Audit')) {
+ if (!class_exists('\AKSRT\Extensions\ContentAudit')) {
return $this->error(__('内容审核服务不可用', 'aksrt'), 500);
}
- $audit = AKSRT_Content_Audit::get_instance();
+ $audit = \AKSRT\Extensions\ContentAudit::get_instance();
$status = $audit->get_status();
$result = $audit->audit_text($text, true);
@@ -444,15 +441,15 @@ class AKSRT_Admin_Extension_Controller extends AKSRT_Admin_Controller_Base {
$services = [];
// SMS
- if (class_exists('AKSRT_SMS')) {
- $services['sms'] = AKSRT_SMS::get_instance()->get_provider_status();
+ if (class_exists('\AKSRT\Sms\SMS')) {
+ $services['sms'] = \AKSRT\Sms\SMS::get_instance()->get_provider_status();
} else {
$services['sms'] = ['enabled' => false, 'provider' => 'none', 'configured' => false, 'available' => false, 'verified' => false, 'transport' => '', 'missing_fields' => []];
}
// WeChat
- if (class_exists('AKSRT_WeChat_Notify')) {
- $services['wechat'] = AKSRT_WeChat_Notify::get_instance()->get_status();
+ if (class_exists('\AKSRT\Payment\WeChatNotify')) {
+ $services['wechat'] = \AKSRT\Payment\WeChatNotify::get_instance()->get_status();
} else {
$services['wechat'] = ['enabled' => false, 'provider' => '', 'configured' => false, 'available' => false, 'verified' => false, 'transport' => '', 'missing_fields' => []];
}
@@ -473,22 +470,22 @@ class AKSRT_Admin_Extension_Controller extends AKSRT_Admin_Controller_Base {
];
// IP Geo
- if (class_exists('AKSRT_IP_Geo')) {
- $services['ip_geo'] = AKSRT_IP_Geo::get_instance()->get_status();
+ if (class_exists('\AKSRT\Extensions\IPGeo')) {
+ $services['ip_geo'] = \AKSRT\Extensions\IPGeo::get_instance()->get_status();
} else {
$services['ip_geo'] = ['enabled' => false, 'provider' => '', 'configured' => false, 'available' => false, 'verified' => false, 'transport' => '', 'missing_fields' => []];
}
// Content Audit
- if (class_exists('AKSRT_Content_Audit')) {
- $services['audit'] = AKSRT_Content_Audit::get_instance()->get_status();
+ if (class_exists('\AKSRT\Extensions\ContentAudit')) {
+ $services['audit'] = \AKSRT\Extensions\ContentAudit::get_instance()->get_status();
} else {
$services['audit'] = ['enabled' => false, 'provider' => '', 'configured' => false, 'available' => false, 'verified' => false, 'transport' => '', 'missing_fields' => []];
}
// Search Push
- if (class_exists('AKSRT_Search_Push')) {
- $services['push'] = AKSRT_Search_Push::get_instance()->get_status();
+ if (class_exists('\AKSRT\Extensions\SearchPush')) {
+ $services['push'] = \AKSRT\Extensions\SearchPush::get_instance()->get_status();
} else {
$services['push'] = ['enabled' => false, 'provider' => '', 'configured' => false, 'available' => false, 'verified' => false, 'transport' => '', 'missing_fields' => []];
}
diff --git a/inc/classes/admin/class-aksrt-admin-forum-controller.php b/src/AKSRT/Admin/ForumController.php
similarity index 93%
rename from inc/classes/admin/class-aksrt-admin-forum-controller.php
rename to src/AKSRT/Admin/ForumController.php
index cf36d407..2ff253a9 100644
--- a/inc/classes/admin/class-aksrt-admin-forum-controller.php
+++ b/src/AKSRT/Admin/ForumController.php
@@ -1,15 +1,15 @@
admin = $admin;
}
@@ -227,7 +227,7 @@ class AKSRT_Admin_Forum_Controller extends AKSRT_Admin_Controller_Base {
]);
}
- public function get_overview(): WP_REST_Response {
+ public function get_overview(): \WP_REST_Response {
$forum = $this->get_forum_service();
if (!$forum) {
return $this->success(['data' => ['stats' => [], 'boards' => [], 'recent_topics' => [], 'pending_applications' => []]]);
@@ -236,7 +236,7 @@ class AKSRT_Admin_Forum_Controller extends AKSRT_Admin_Controller_Base {
$pending_topics = $forum->get_topic_list([
'limit' => 6,
'status' => 'pending',
- 'review_status' => AKSRT_Forum::REVIEW_PENDING,
+ 'review_status' => \AKSRT\Forum\Forum::REVIEW_PENDING,
'viewer_user_id' => get_current_user_id(),
'include_hidden' => true,
]);
@@ -246,12 +246,12 @@ class AKSRT_Admin_Forum_Controller extends AKSRT_Admin_Controller_Base {
'stats' => $forum->get_stats(),
'boards' => array_slice($forum->get_boards(), 0, 6),
'pending_topics' => $pending_topics['items'],
- 'pending_applications' => array_slice($forum->get_moderator_application_list(['status' => AKSRT_Forum::APPLICATION_PENDING]), 0, 6),
+ 'pending_applications' => array_slice($forum->get_moderator_application_list(['status' => \AKSRT\Forum\Forum::APPLICATION_PENDING]), 0, 6),
],
]);
}
- public function get_boards(): WP_REST_Response {
+ public function get_boards(): \WP_REST_Response {
$forum = $this->get_forum_service();
$items = $forum ? $forum->get_boards() : [];
@@ -263,7 +263,7 @@ class AKSRT_Admin_Forum_Controller extends AKSRT_Admin_Controller_Base {
]);
}
- public function create_board(WP_REST_Request $request): WP_REST_Response {
+ public function create_board(\WP_REST_Request $request): \WP_REST_Response {
$forum = $this->get_forum_service();
if (!$forum) {
return $this->error(__('论坛系统未启用', 'aksrt'));
@@ -286,7 +286,7 @@ class AKSRT_Admin_Forum_Controller extends AKSRT_Admin_Controller_Base {
], 201);
}
- public function update_board(WP_REST_Request $request): WP_REST_Response {
+ public function update_board(\WP_REST_Request $request): \WP_REST_Response {
$forum = $this->get_forum_service();
if (!$forum) {
return $this->error(__('论坛系统未启用', 'aksrt'));
@@ -305,7 +305,7 @@ class AKSRT_Admin_Forum_Controller extends AKSRT_Admin_Controller_Base {
return $this->success(['message' => __('版块已更新', 'aksrt')]);
}
- public function delete_board(WP_REST_Request $request): WP_REST_Response {
+ public function delete_board(\WP_REST_Request $request): \WP_REST_Response {
$forum = $this->get_forum_service();
if (!$forum) {
return $this->error(__('论坛系统未启用', 'aksrt'));
@@ -324,7 +324,7 @@ class AKSRT_Admin_Forum_Controller extends AKSRT_Admin_Controller_Base {
return $this->success(['message' => __('版块已删除', 'aksrt')]);
}
- public function reorder_boards(WP_REST_Request $request): WP_REST_Response {
+ public function reorder_boards(\WP_REST_Request $request): \WP_REST_Response {
$forum = $this->get_forum_service();
if (!$forum) {
return $this->error(__('论坛系统未启用', 'aksrt'));
@@ -345,7 +345,7 @@ class AKSRT_Admin_Forum_Controller extends AKSRT_Admin_Controller_Base {
// §7.0 Plate CPT handlers
// ================================================================
- public function get_plates(WP_REST_Request $request): WP_REST_Response {
+ public function get_plates(\WP_REST_Request $request): \WP_REST_Response {
$forum = $this->get_forum_service();
if (!$forum) {
return $this->success(['data' => ['items' => [], 'total' => 0]]);
@@ -371,7 +371,7 @@ class AKSRT_Admin_Forum_Controller extends AKSRT_Admin_Controller_Base {
]);
}
- public function get_plate(WP_REST_Request $request): WP_REST_Response {
+ public function get_plate(\WP_REST_Request $request): \WP_REST_Response {
$forum = $this->get_forum_service();
if (!$forum) {
return $this->error(__('论坛系统未启用', 'aksrt'));
@@ -386,7 +386,7 @@ class AKSRT_Admin_Forum_Controller extends AKSRT_Admin_Controller_Base {
return $this->success(['data' => $plate]);
}
- public function create_plate(WP_REST_Request $request): WP_REST_Response {
+ public function create_plate(\WP_REST_Request $request): \WP_REST_Response {
$forum = $this->get_forum_service();
if (!$forum) {
return $this->error(__('论坛系统未启用', 'aksrt'));
diff --git a/inc/classes/admin/forum-ctrl-traits/trait-aksrt-admin-forum-controller-part-1.php b/src/AKSRT/Admin/ForumControllerPart1.php
similarity index 90%
rename from inc/classes/admin/forum-ctrl-traits/trait-aksrt-admin-forum-controller-part-1.php
rename to src/AKSRT/Admin/ForumControllerPart1.php
index 374b0a4f..92d57346 100644
--- a/inc/classes/admin/forum-ctrl-traits/trait-aksrt-admin-forum-controller-part-1.php
+++ b/src/AKSRT/Admin/ForumControllerPart1.php
@@ -1,9 +1,15 @@
get_forum_service();
if (!$forum) {
return $this->error(__('论坛系统未启用', 'aksrt'));
@@ -20,7 +26,7 @@ trait AKSRT_Admin_Forum_Controller_Part_1 {
return $this->success(['message' => __('版块已更新', 'aksrt')]);
}
- public function delete_plate(WP_REST_Request $request): WP_REST_Response {
+ public function delete_plate(\WP_REST_Request $request): \WP_REST_Response {
$forum = $this->get_forum_service();
if (!$forum) {
return $this->error(__('论坛系统未启用', 'aksrt'));
@@ -39,7 +45,7 @@ trait AKSRT_Admin_Forum_Controller_Part_1 {
return $this->success(['message' => __('版块已删除', 'aksrt')]);
}
- public function reorder_plates(WP_REST_Request $request): WP_REST_Response {
+ public function reorder_plates(\WP_REST_Request $request): \WP_REST_Response {
$forum = $this->get_forum_service();
if (!$forum) {
return $this->error(__('论坛系统未启用', 'aksrt'));
@@ -56,7 +62,7 @@ trait AKSRT_Admin_Forum_Controller_Part_1 {
return $this->success(['message' => __('排序已更新', 'aksrt')]);
}
- public function toggle_follow_plate(WP_REST_Request $request): WP_REST_Response {
+ public function toggle_follow_plate(\WP_REST_Request $request): \WP_REST_Response {
$forum = $this->get_forum_service();
if (!$forum) {
return $this->error(__('论坛系统未启用', 'aksrt'));
@@ -69,7 +75,7 @@ trait AKSRT_Admin_Forum_Controller_Part_1 {
return $this->success($result);
}
- public function get_plate_categories(): WP_REST_Response {
+ public function get_plate_categories(): \WP_REST_Response {
$forum = $this->get_forum_service();
if (!$forum) {
return $this->success(['data' => []]);
@@ -78,7 +84,7 @@ trait AKSRT_Admin_Forum_Controller_Part_1 {
return $this->success(['data' => $forum->get_plate_categories()]);
}
- public function get_sorted_plates(WP_REST_Request $request): WP_REST_Response {
+ public function get_sorted_plates(\WP_REST_Request $request): \WP_REST_Response {
$forum = $this->get_forum_service();
if (!$forum) {
return $this->success(['data' => []]);
@@ -91,7 +97,7 @@ trait AKSRT_Admin_Forum_Controller_Part_1 {
return $this->success(['data' => $forum->get_sorted_plates($orderby, $order, $limit)]);
}
- public function get_topics(WP_REST_Request $request): WP_REST_Response {
+ public function get_topics(\WP_REST_Request $request): \WP_REST_Response {
$forum = $this->get_forum_service();
if (!$forum) {
return $this->success(['data' => ['items' => [], 'total' => 0, 'page' => 1, 'total_pages' => 1]]);
@@ -133,7 +139,7 @@ trait AKSRT_Admin_Forum_Controller_Part_1 {
]);
}
- public function get_topic_detail(WP_REST_Request $request): WP_REST_Response {
+ public function get_topic_detail(\WP_REST_Request $request): \WP_REST_Response {
$forum = $this->get_forum_service();
if (!$forum) {
return $this->error(__('论坛系统未启用', 'aksrt'));
@@ -149,7 +155,7 @@ trait AKSRT_Admin_Forum_Controller_Part_1 {
]);
}
- public function moderate_topic(WP_REST_Request $request): WP_REST_Response {
+ public function moderate_topic(\WP_REST_Request $request): \WP_REST_Response {
$forum = $this->get_forum_service();
if (!$forum) {
return $this->error(__('论坛系统未启用', 'aksrt'));
@@ -174,7 +180,7 @@ trait AKSRT_Admin_Forum_Controller_Part_1 {
]);
}
- public function vote_topic(WP_REST_Request $request): WP_REST_Response {
+ public function vote_topic(\WP_REST_Request $request): \WP_REST_Response {
$forum = $this->get_forum_service();
if (!$forum) {
return $this->error(__('论坛系统未启用', 'aksrt'));
@@ -202,7 +208,7 @@ trait AKSRT_Admin_Forum_Controller_Part_1 {
/**
* Legacy admin moderation endpoint kept for compatibility.
*/
- public function update_topic_legacy(WP_REST_Request $request): WP_REST_Response {
+ public function update_topic_legacy(\WP_REST_Request $request): \WP_REST_Response {
$params = $this->get_json_params($request);
$topic_id = (int) ($params['topic_id'] ?? 0);
if ($topic_id <= 0) {
@@ -235,7 +241,7 @@ trait AKSRT_Admin_Forum_Controller_Part_1 {
return $this->success(['message' => __('治理状态已更新', 'aksrt')]);
}
- public function get_moderators(): WP_REST_Response {
+ public function get_moderators(): \WP_REST_Response {
$forum = $this->get_forum_service();
if (!$forum) {
return $this->success(['data' => ['boards' => []]]);
@@ -261,7 +267,7 @@ trait AKSRT_Admin_Forum_Controller_Part_1 {
return $this->success(['data' => ['boards' => $result]]);
}
- public function update_moderators(WP_REST_Request $request): WP_REST_Response {
+ public function update_moderators(\WP_REST_Request $request): \WP_REST_Response {
$forum = $this->get_forum_service();
if (!$forum) {
return $this->error(__('论坛系统未启用', 'aksrt'));
@@ -303,7 +309,7 @@ trait AKSRT_Admin_Forum_Controller_Part_1 {
]);
}
- public function change_moderator_role(WP_REST_Request $request): WP_REST_Response {
+ public function change_moderator_role(\WP_REST_Request $request): \WP_REST_Response {
$forum = $this->get_forum_service();
if (!$forum) {
return $this->error(__('论坛系统未启用', 'aksrt'));
@@ -331,7 +337,7 @@ trait AKSRT_Admin_Forum_Controller_Part_1 {
return $this->success(['message' => __('角色已更新', 'aksrt')]);
}
- public function apply_moderator(WP_REST_Request $request): WP_REST_Response {
+ public function apply_moderator(\WP_REST_Request $request): \WP_REST_Response {
$forum = $this->get_forum_service();
if (!$forum) {
return $this->error(__('论坛系统未启用', 'aksrt'));
@@ -353,7 +359,7 @@ trait AKSRT_Admin_Forum_Controller_Part_1 {
]);
}
- public function get_moderator_applications(WP_REST_Request $request): WP_REST_Response {
+ public function get_moderator_applications(\WP_REST_Request $request): \WP_REST_Response {
$forum = $this->get_forum_service();
if (!$forum) {
return $this->success(['data' => ['items' => [], 'total' => 0]]);
@@ -373,9 +379,9 @@ trait AKSRT_Admin_Forum_Controller_Part_1 {
'boards' => $forum->get_boards(),
'status' => [
['label' => __('全部', 'aksrt'), 'value' => ''],
- ['label' => __('待处理', 'aksrt'), 'value' => AKSRT_Forum::APPLICATION_PENDING],
- ['label' => __('已通过', 'aksrt'), 'value' => AKSRT_Forum::APPLICATION_APPROVED],
- ['label' => __('已拒绝', 'aksrt'), 'value' => AKSRT_Forum::APPLICATION_REJECTED],
+ ['label' => __('待处理', 'aksrt'), 'value' => \AKSRT\Forum\Forum::APPLICATION_PENDING],
+ ['label' => __('已通过', 'aksrt'), 'value' => \AKSRT\Forum\Forum::APPLICATION_APPROVED],
+ ['label' => __('已拒绝', 'aksrt'), 'value' => \AKSRT\Forum\Forum::APPLICATION_REJECTED],
],
],
],
diff --git a/inc/classes/admin/forum-ctrl-traits/trait-aksrt-admin-forum-controller-part-2.php b/src/AKSRT/Admin/ForumControllerPart2.php
similarity index 87%
rename from inc/classes/admin/forum-ctrl-traits/trait-aksrt-admin-forum-controller-part-2.php
rename to src/AKSRT/Admin/ForumControllerPart2.php
index 8a50571a..e99b9c1f 100644
--- a/inc/classes/admin/forum-ctrl-traits/trait-aksrt-admin-forum-controller-part-2.php
+++ b/src/AKSRT/Admin/ForumControllerPart2.php
@@ -1,10 +1,16 @@
get_forum_service();
if (!$forum) {
return $this->error(__('论坛系统未启用', 'aksrt'));
@@ -26,7 +32,7 @@ trait AKSRT_Admin_Forum_Controller_Part_2 {
]);
}
- public function toggle_favorite(WP_REST_Request $request): WP_REST_Response {
+ public function toggle_favorite(\WP_REST_Request $request): \WP_REST_Response {
$forum = $this->get_forum_service();
if (!$forum) {
return $this->error(__('论坛系统未启用', 'aksrt'));
@@ -42,7 +48,7 @@ trait AKSRT_Admin_Forum_Controller_Part_2 {
return $this->success($result);
}
- public function score_topic(WP_REST_Request $request): WP_REST_Response {
+ public function score_topic(\WP_REST_Request $request): \WP_REST_Response {
$forum = $this->get_forum_service();
if (!$forum) {
return $this->error(__('论坛系统未启用', 'aksrt'));
@@ -61,7 +67,7 @@ trait AKSRT_Admin_Forum_Controller_Part_2 {
return $this->success($result);
}
- public function adopt_answer(WP_REST_Request $request): WP_REST_Response {
+ public function adopt_answer(\WP_REST_Request $request): \WP_REST_Response {
$forum = $this->get_forum_service();
if (!$forum) {
return $this->error(__('论坛系统未启用', 'aksrt'));
@@ -84,11 +90,11 @@ trait AKSRT_Admin_Forum_Controller_Part_2 {
return is_user_logged_in();
}
- private function get_forum_service(): ?AKSRT_Forum {
- return class_exists('AKSRT_Forum') ? AKSRT_Forum::get_instance() : null;
+ private function get_forum_service(): ?\AKSRT\Forum\Forum {
+ return class_exists('\AKSRT\Forum\Forum') ? \AKSRT\Forum\Forum::get_instance() : null;
}
- public function frontend_create_plate(WP_REST_Request $request): WP_REST_Response {
+ public function frontend_create_plate(\WP_REST_Request $request): \WP_REST_Response {
$forum = $this->get_forum_service();
if (!$forum) {
return $this->error(__('论坛系统未启用', 'aksrt'));
@@ -121,7 +127,7 @@ trait AKSRT_Admin_Forum_Controller_Part_2 {
return $this->success($result);
}
- public function frontend_update_plate(WP_REST_Request $request): WP_REST_Response {
+ public function frontend_update_plate(\WP_REST_Request $request): \WP_REST_Response {
$forum = $this->get_forum_service();
if (!$forum) {
return $this->error(__('论坛系统未启用', 'aksrt'));
@@ -156,7 +162,7 @@ trait AKSRT_Admin_Forum_Controller_Part_2 {
return $this->success($result);
}
- public function frontend_delete_plate(WP_REST_Request $request): WP_REST_Response {
+ public function frontend_delete_plate(\WP_REST_Request $request): \WP_REST_Response {
$forum = $this->get_forum_service();
if (!$forum) {
return $this->error(__('论坛系统未启用', 'aksrt'));
diff --git a/inc/classes/admin/class-aksrt-admin-global-controller.php b/src/AKSRT/Admin/GlobalController.php
similarity index 92%
rename from inc/classes/admin/class-aksrt-admin-global-controller.php
rename to src/AKSRT/Admin/GlobalController.php
index d9adab9d..8a34ab74 100644
--- a/inc/classes/admin/class-aksrt-admin-global-controller.php
+++ b/src/AKSRT/Admin/GlobalController.php
@@ -1,20 +1,16 @@
get_method() === 'GET') {
- return $this->success(['cms_features' => AKSRT_Settings::get_cms_features()]);
+ return $this->success(['cms_features' => \AKSRT\Settings\Settings::get_cms_features()]);
}
$params = $this->get_json_params($request);
@@ -192,18 +188,18 @@ class AKSRT_Admin_Global_Controller extends AKSRT_Admin_Controller_Base {
'search_include_resource' => 'bool',
];
$sanitized = $this->sanitize_fields($params, $allowed);
- $settings = AKSRT_Settings::get_all();
+ $settings = \AKSRT\Settings\Settings::get_all();
$settings['cms_features'] = array_merge(
is_array($settings['cms_features'] ?? null) ? $settings['cms_features'] : [],
$sanitized
);
update_option('aksrt_settings', $settings);
- AKSRT_Settings::flush_settings_cache();
+ \AKSRT\Settings\Settings::flush_settings_cache();
- return $this->success(['message' => 'CMS 功能已保存', 'cms_features' => AKSRT_Settings::get_cms_features()]);
+ return $this->success(['message' => 'CMS 功能已保存', 'cms_features' => \AKSRT\Settings\Settings::get_cms_features()]);
}
- public function rest_handle_mail(WP_REST_Request $request): WP_REST_Response {
+ public function rest_handle_mail(\WP_REST_Request $request): \WP_REST_Response {
$option_key = 'aksrt_mail_config';
if ($request->get_method() === 'GET') {
@@ -227,7 +223,7 @@ class AKSRT_Admin_Global_Controller extends AKSRT_Admin_Controller_Base {
return $this->success(['message' => '邮件配置已保存', 'code' => 'success']);
}
- public function rest_test_mail(WP_REST_Request $request): WP_REST_Response {
+ public function rest_test_mail(\WP_REST_Request $request): \WP_REST_Response {
$params = $this->get_json_params($request);
$to = sanitize_email($params['to'] ?? '');
if (!is_email($to)) {
@@ -241,7 +237,7 @@ class AKSRT_Admin_Global_Controller extends AKSRT_Admin_Controller_Base {
return $this->error(__('邮件发送失败,请检查 SMTP 配置', 'aksrt'));
}
- public function rest_homepage_tab_posts(WP_REST_Request $request): WP_REST_Response {
+ public function rest_homepage_tab_posts(\WP_REST_Request $request): \WP_REST_Response {
$term_id = (int) $request->get_param('term_id');
$page = max(1, (int) $request->get_param('page'));
$per_page = min(50, max(1, (int) $request->get_param('per_page')));
@@ -275,16 +271,16 @@ class AKSRT_Admin_Global_Controller extends AKSRT_Admin_Controller_Base {
]];
}
- $exclude_ids = class_exists('AKSRT_Settings')
- ? AKSRT_Settings::home_exclude_post_ids()
+ $exclude_ids = class_exists('\AKSRT\Settings\Settings')
+ ? \AKSRT\Settings\Settings::home_exclude_post_ids()
: [];
if (!empty($exclude_ids)) {
$args['post__not_in'] = $exclude_ids;
}
if ($panel === 'latest' || $term_id <= 0) {
- $exclude_cat_ids = class_exists('AKSRT_Settings')
- ? AKSRT_Settings::home_exclude_category_ids()
+ $exclude_cat_ids = class_exists('\AKSRT\Settings\Settings')
+ ? \AKSRT\Settings\Settings::home_exclude_category_ids()
: [];
if (!empty($exclude_cat_ids)) {
$args['category__not_in'] = $exclude_cat_ids;
@@ -299,7 +295,7 @@ class AKSRT_Admin_Global_Controller extends AKSRT_Admin_Controller_Base {
$args['order'] = 'DESC';
}
- $query = new WP_Query($args);
+ $query = new \WP_Query($args);
$mode = in_array($view_mode, ['card', 'list'], true) ? $view_mode : '';
$html = '';
@@ -338,11 +334,11 @@ class AKSRT_Admin_Global_Controller extends AKSRT_Admin_Controller_Base {
]);
}
- public function rest_archive_posts(WP_REST_Request $request): WP_REST_Response {
+ public function rest_archive_posts(\WP_REST_Request $request): \WP_REST_Response {
return $this->rest_homepage_tab_posts($request);
}
- public function rest_homepage_categories(): WP_REST_Response {
+ public function rest_homepage_categories(): \WP_REST_Response {
$data = [];
$cats = get_categories(['hide_empty' => false, 'orderby' => 'name', 'order' => 'ASC']);
@@ -383,7 +379,7 @@ class AKSRT_Admin_Global_Controller extends AKSRT_Admin_Controller_Base {
return $this->success(['data' => $data]);
}
- public function rest_handle_friend_links(WP_REST_Request $request): WP_REST_Response {
+ public function rest_handle_friend_links(\WP_REST_Request $request): \WP_REST_Response {
if ($request->get_method() === 'GET') {
$links = aksrt_get_friend_links();
return rest_ensure_response(['code' => 'success', 'data' => $links]);
@@ -409,7 +405,7 @@ class AKSRT_Admin_Global_Controller extends AKSRT_Admin_Controller_Base {
return rest_ensure_response(['code' => 'success', 'data' => $new_link, 'message' => __('Friend link added.', 'aksrt')]);
}
- public function rest_delete_friend_link(WP_REST_Request $request): WP_REST_Response {
+ public function rest_delete_friend_link(\WP_REST_Request $request): \WP_REST_Response {
$id = $request->get_param('id');
$links = get_option('aksrt_friend_links', []);
$links = array_filter($links, function ($link) use ($id) {
@@ -420,10 +416,10 @@ class AKSRT_Admin_Global_Controller extends AKSRT_Admin_Controller_Base {
return rest_ensure_response(['code' => 'success', 'message' => __('Friend link deleted.', 'aksrt')]);
}
- public function rest_reorder_friend_links(WP_REST_Request $request): WP_REST_Response {
+ public function rest_reorder_friend_links(\WP_REST_Request $request): \WP_REST_Response {
$ordered_ids = $request->get_param('ids');
if (!is_array($ordered_ids)) {
- return new WP_REST_Response(['code' => 'error', 'message' => __('参数错误', 'aksrt')], 400);
+ return new \WP_REST_Response(['code' => 'error', 'message' => __('参数错误', 'aksrt')], 400);
}
$links = get_option('aksrt_friend_links', []);
$order_map = array_flip($ordered_ids);
@@ -439,7 +435,7 @@ class AKSRT_Admin_Global_Controller extends AKSRT_Admin_Controller_Base {
return rest_ensure_response(['code' => 'success', 'message' => __('Order saved.', 'aksrt')]);
}
- public function rest_handle_footer_settings(WP_REST_Request $request): WP_REST_Response {
+ public function rest_handle_footer_settings(\WP_REST_Request $request): \WP_REST_Response {
if ($request->get_method() === 'GET') {
$footer = get_option('aksrt_footer_settings', []);
$defaults = [
@@ -575,10 +571,10 @@ class AKSRT_Admin_Global_Controller extends AKSRT_Admin_Controller_Base {
return $clean;
}
- public function rest_handle_footer_tabbar(WP_REST_Request $request): WP_REST_Response {
+ public function rest_handle_footer_tabbar(\WP_REST_Request $request): \WP_REST_Response {
if ($request->get_method() === 'GET') {
- $settings = class_exists('AKSRT_Settings')
- ? AKSRT_Settings::get_footer_tabbar_settings()
+ $settings = class_exists('\AKSRT\Settings\Settings')
+ ? \AKSRT\Settings\Settings::get_footer_tabbar_settings()
: ['enabled' => true, 'scroll_hide' => false, 'scroll_down_hide' => true, 'items' => []];
return rest_ensure_response(['code' => 'success', 'data' => $settings]);
}
@@ -588,7 +584,7 @@ class AKSRT_Admin_Global_Controller extends AKSRT_Admin_Controller_Base {
$max_items = max(3, min(7, (int) ($params['max_items'] ?? 5)));
if (count($items) > $max_items) {
- return new WP_REST_Response([
+ return new \WP_REST_Response([
'code' => 'error',
'message' => sprintf(__('Footer tabbar supports at most %d items.', 'aksrt'), $max_items),
], 400);
@@ -613,8 +609,8 @@ class AKSRT_Admin_Global_Controller extends AKSRT_Admin_Controller_Base {
];
update_option('aksrt_footer_tabbar', $tabbar);
- if (class_exists('AKSRT_Settings')) {
- AKSRT_Settings::flush_settings_cache();
+ if (class_exists('\AKSRT\Settings\Settings')) {
+ \AKSRT\Settings\Settings::flush_settings_cache();
}
return rest_ensure_response(['code' => 'success', 'message' => __('Footer tabbar settings saved.', 'aksrt')]);
diff --git a/inc/classes/admin/global-ctrl-traits/trait-aksrt-admin-global-controller-part-1.php b/src/AKSRT/Admin/GlobalControllerPart1.php
similarity index 90%
rename from inc/classes/admin/global-ctrl-traits/trait-aksrt-admin-global-controller-part-1.php
rename to src/AKSRT/Admin/GlobalControllerPart1.php
index b51bdbb6..bf8863b5 100644
--- a/inc/classes/admin/global-ctrl-traits/trait-aksrt-admin-global-controller-part-1.php
+++ b/src/AKSRT/Admin/GlobalControllerPart1.php
@@ -1,18 +1,24 @@
get_json_params($request);
$ordered_ids = $params['ids'] ?? [];
if (!is_array($ordered_ids)) {
- return new WP_REST_Response(['code' => 'error', 'message' => __('参数错误', 'aksrt')], 400);
+ return new \WP_REST_Response(['code' => 'error', 'message' => __('参数错误', 'aksrt')], 400);
}
if (count($ordered_ids) > 5) {
- return new WP_REST_Response(['code' => 'error', 'message' => __('Footer tabbar supports at most 5 items.', 'aksrt')], 400);
+ return new \WP_REST_Response(['code' => 'error', 'message' => __('Footer tabbar supports at most 5 items.', 'aksrt')], 400);
}
$tabbar = get_option('aksrt_footer_tabbar', []);
@@ -85,10 +91,10 @@ trait AKSRT_Admin_Global_Controller_Part_1 {
];
}
- public function rest_handle_floating_buttons(WP_REST_Request $request): WP_REST_Response {
+ public function rest_handle_floating_buttons(\WP_REST_Request $request): \WP_REST_Response {
if ($request->get_method() === 'GET') {
- $settings = class_exists('AKSRT_Settings')
- ? AKSRT_Settings::get_floating_buttons_settings()
+ $settings = class_exists('\AKSRT\Settings\Settings')
+ ? \AKSRT\Settings\Settings::get_floating_buttons_settings()
: [
'enabled' => true,
'style' => 'round',
@@ -138,19 +144,19 @@ trait AKSRT_Admin_Global_Controller_Part_1 {
update_option('aksrt_floating_buttons', $settings);
- if (class_exists('AKSRT_Settings')) {
- AKSRT_Settings::flush_settings_cache();
+ if (class_exists('\AKSRT\Settings\Settings')) {
+ \AKSRT\Settings\Settings::flush_settings_cache();
}
return rest_ensure_response(['code' => 'success', 'message' => __('Floating button settings saved.', 'aksrt')]);
}
- public function rest_reorder_floating_buttons(WP_REST_Request $request): WP_REST_Response {
+ public function rest_reorder_floating_buttons(\WP_REST_Request $request): \WP_REST_Response {
$params = $this->get_json_params($request);
$ordered_ids = $params['ids'] ?? [];
if (!is_array($ordered_ids)) {
- return new WP_REST_Response(['code' => 'error', 'message' => __('参数错误', 'aksrt')], 400);
+ return new \WP_REST_Response(['code' => 'error', 'message' => __('参数错误', 'aksrt')], 400);
}
$settings = get_option('aksrt_floating_buttons', []);
@@ -171,8 +177,8 @@ trait AKSRT_Admin_Global_Controller_Part_1 {
$settings['items'] = $items;
update_option('aksrt_floating_buttons', $settings);
- if (class_exists('AKSRT_Settings')) {
- AKSRT_Settings::flush_settings_cache();
+ if (class_exists('\AKSRT\Settings\Settings')) {
+ \AKSRT\Settings\Settings::flush_settings_cache();
}
return rest_ensure_response(['code' => 'success', 'message' => __('Order saved.', 'aksrt')]);
diff --git a/inc/classes/admin/global-ctrl-traits/trait-aksrt-admin-global-controller-part-2.php b/src/AKSRT/Admin/GlobalControllerPart2.php
similarity index 82%
rename from inc/classes/admin/global-ctrl-traits/trait-aksrt-admin-global-controller-part-2.php
rename to src/AKSRT/Admin/GlobalControllerPart2.php
index 492b04d3..2a3e5cb6 100644
--- a/inc/classes/admin/global-ctrl-traits/trait-aksrt-admin-global-controller-part-2.php
+++ b/src/AKSRT/Admin/GlobalControllerPart2.php
@@ -1,11 +1,17 @@
get_method() === 'GET') {
- $settings = AKSRT_Settings::get_category_recommend_settings();
+ $settings = \AKSRT\Settings\Settings::get_category_recommend_settings();
return rest_ensure_response(['code' => 'success', 'data' => $settings]);
}
@@ -25,12 +31,12 @@ trait AKSRT_Admin_Global_Controller_Part_2 {
'category_recommend_show_more_link' => !empty($params['category_recommend_show_more_link']),
];
update_option('aksrt_category_recommend', $settings);
- AKSRT_Settings::flush_category_recommend_cache();
+ \AKSRT\Settings\Settings::flush_category_recommend_cache();
return rest_ensure_response(['code' => 'success', 'message' => __('Category recommendation settings saved.', 'aksrt')]);
}
- public function rest_get_categories(WP_REST_Request $request): WP_REST_Response {
+ public function rest_get_categories(\WP_REST_Request $request): \WP_REST_Response {
$categories = get_categories([
'orderby' => 'count',
'order' => 'DESC',
@@ -45,7 +51,7 @@ trait AKSRT_Admin_Global_Controller_Part_2 {
'count' => (int) $cat->count,
'description' => $cat->description,
'cover_id' => (int) get_term_meta($cat->term_id, 'aksrt_category_cover_id', true),
- 'cover_url' => AKSRT_Settings::get_category_cover_url((int) $cat->term_id),
+ 'cover_url' => \AKSRT\Settings\Settings::get_category_cover_url((int) $cat->term_id),
'recommend_desc' => (string) get_term_meta($cat->term_id, 'aksrt_category_recommend_desc', true),
];
}, $categories);
@@ -53,7 +59,7 @@ trait AKSRT_Admin_Global_Controller_Part_2 {
return rest_ensure_response(['code' => 'success', 'data' => array_values($data)]);
}
- public function rest_search_users(WP_REST_Request $request): WP_REST_Response {
+ public function rest_search_users(\WP_REST_Request $request): \WP_REST_Response {
$search = (string) $request->get_param('search');
$number = max(1, min(50, (int) $request->get_param('number')));
@@ -80,11 +86,11 @@ trait AKSRT_Admin_Global_Controller_Part_2 {
return rest_ensure_response(['code' => 'success', 'data' => array_values($data)]);
}
- public function rest_update_category_meta(WP_REST_Request $request): WP_REST_Response {
+ public function rest_update_category_meta(\WP_REST_Request $request): \WP_REST_Response {
$id = (int) $request->get_param('id');
$term = get_term($id, 'category');
if (!$term || is_wp_error($term)) {
- return new WP_REST_Response(['code' => 'error', 'message' => __('Category does not exist.', 'aksrt')], 404);
+ return new \WP_REST_Response(['code' => 'error', 'message' => __('Category does not exist.', 'aksrt')], 404);
}
$params = $this->get_json_params($request);
@@ -103,7 +109,7 @@ trait AKSRT_Admin_Global_Controller_Part_2 {
delete_term_meta($id, 'aksrt_category_recommend_desc');
}
- AKSRT_Settings::flush_category_recommend_cache();
+ \AKSRT\Settings\Settings::flush_category_recommend_cache();
return rest_ensure_response(['code' => 'success', 'message' => __('分类元数据已保存', 'aksrt')]);
}
diff --git a/inc/classes/admin/global-ctrl-traits/trait-aksrt-admin-homepage-settings-rest.php b/src/AKSRT/Admin/HomepageSettingsRest.php
similarity index 93%
rename from inc/classes/admin/global-ctrl-traits/trait-aksrt-admin-homepage-settings-rest.php
rename to src/AKSRT/Admin/HomepageSettingsRest.php
index 4118b6bb..8108d629 100644
--- a/inc/classes/admin/global-ctrl-traits/trait-aksrt-admin-homepage-settings-rest.php
+++ b/src/AKSRT/Admin/HomepageSettingsRest.php
@@ -1,32 +1,21 @@
get_method() === 'GET') {
return rest_ensure_response([
'code' => 'success',
- 'data' => AKSRT_Settings_Home_Cms::get_homepage_fixed_settings(),
+ 'data' => \AKSRT\Settings\HomeCms::get_homepage_fixed_settings(),
]);
}
@@ -38,7 +27,7 @@ trait AKSRT_Admin_Homepage_Settings_Rest {
$params = [];
}
- $allowed_sorts = AKSRT_Settings_Home_Cms::homepage_allowed_sorts();
+ $allowed_sorts = \AKSRT\Settings\HomeCms::homepage_allowed_sorts();
$settings = [];
// --- Zibll main list contract ---
@@ -198,8 +187,8 @@ trait AKSRT_Admin_Homepage_Settings_Rest {
}
update_option($option_key, $current);
- if (class_exists('AKSRT_Settings')) {
- AKSRT_Settings::flush_settings_cache();
+ if (class_exists('\AKSRT\Settings\Settings')) {
+ \AKSRT\Settings\Settings::flush_settings_cache();
}
update_option('aksrt_homepage_schema_version', gmdate('Y-m-d'));
delete_transient('aksrt_homepage_cached_images');
@@ -208,7 +197,7 @@ trait AKSRT_Admin_Homepage_Settings_Rest {
return rest_ensure_response([
'code' => 'success',
'message' => __('首页设置已保存', 'aksrt'),
- 'data' => AKSRT_Settings_Home_Cms::get_homepage_fixed_settings(),
+ 'data' => \AKSRT\Settings\HomeCms::get_homepage_fixed_settings(),
]);
}
diff --git a/inc/classes/admin/class-aksrt-admin-import-export-controller.php b/src/AKSRT/Admin/ImportExportController.php
similarity index 91%
rename from inc/classes/admin/class-aksrt-admin-import-export-controller.php
rename to src/AKSRT/Admin/ImportExportController.php
index 24288c6f..e138a7c5 100644
--- a/inc/classes/admin/class-aksrt-admin-import-export-controller.php
+++ b/src/AKSRT/Admin/ImportExportController.php
@@ -1,18 +1,15 @@
get_domain_keys();
$export = [
@@ -185,7 +182,7 @@ class AKSRT_Admin_Import_Export_Controller extends AKSRT_Admin_Controller_Base {
}
// Also export standalone options from the registry
- $standalone_keys = AKSRT_Settings::STANDALONE_OPTION_KEYS;
+ $standalone_keys = \AKSRT\Settings\Settings::STANDALONE_OPTION_KEYS;
$export['standalone'] = [];
foreach ($standalone_keys as $key) {
@@ -204,7 +201,7 @@ class AKSRT_Admin_Import_Export_Controller extends AKSRT_Admin_Controller_Base {
* Request body: { domains: { domain: { data: {...} } }, standalone: { key: value } }
* Optional: { dry_run: true } to validate without saving.
*/
- public function rest_import_settings(WP_REST_Request $request): WP_REST_Response {
+ public function rest_import_settings(\WP_REST_Request $request): \WP_REST_Response {
$params = $this->get_json_params($request);
$dry_run = !empty($params['dry_run']);
@@ -212,7 +209,7 @@ class AKSRT_Admin_Import_Export_Controller extends AKSRT_Admin_Controller_Base {
return $this->error('没有可导入的数据');
}
- $schema_provider = AKSRT_Admin_Schema_Provider::get_instance();
+ $schema_provider = SchemaProvider::get_instance();
$results = [];
// Import domain settings
@@ -263,7 +260,7 @@ class AKSRT_Admin_Import_Export_Controller extends AKSRT_Admin_Controller_Base {
}
if (!$dry_run) {
- AKSRT_Settings::flush_settings_cache();
+ \AKSRT\Settings\Settings::flush_settings_cache();
}
return $this->success([
@@ -275,9 +272,9 @@ class AKSRT_Admin_Import_Export_Controller extends AKSRT_Admin_Controller_Base {
/**
* Reset a domain's settings to defaults.
*/
- public function rest_reset_domain(WP_REST_Request $request): WP_REST_Response {
+ public function rest_reset_domain(\WP_REST_Request $request): \WP_REST_Response {
$domain = $request->get_param('domain');
- $schema_provider = AKSRT_Admin_Schema_Provider::get_instance();
+ $schema_provider = SchemaProvider::get_instance();
if (!in_array($domain, $schema_provider->get_domain_keys(), true)) {
return $this->error('未知的设置域: ' . esc_html($domain), 404);
@@ -296,8 +293,8 @@ class AKSRT_Admin_Import_Export_Controller extends AKSRT_Admin_Controller_Base {
]);
}
- public function rest_reset_all(WP_REST_Request $request): WP_REST_Response {
- $schema_provider = AKSRT_Admin_Schema_Provider::get_instance();
+ public function rest_reset_all(\WP_REST_Request $request): \WP_REST_Response {
+ $schema_provider = SchemaProvider::get_instance();
$backup = $this->create_backup_record('reset_all', __('重置全部前快照', 'aksrt'));
$this->persist_setting_backup($backup);
@@ -305,7 +302,7 @@ class AKSRT_Admin_Import_Export_Controller extends AKSRT_Admin_Controller_Base {
$schema_provider->reset_to_defaults($domain);
}
- AKSRT_Settings::flush_settings_cache();
+ \AKSRT\Settings\Settings::flush_settings_cache();
return $this->success([
'message' => __('全部 schema 托管设置已重置为默认值', 'aksrt'),
@@ -318,7 +315,7 @@ class AKSRT_Admin_Import_Export_Controller extends AKSRT_Admin_Controller_Base {
/**
* Health check — returns system diagnostics.
*/
- public function rest_health_check(WP_REST_Request $request): WP_REST_Response {
+ public function rest_health_check(\WP_REST_Request $request): \WP_REST_Response {
global $wpdb;
$checks = [];
@@ -375,7 +372,7 @@ class AKSRT_Admin_Import_Export_Controller extends AKSRT_Admin_Controller_Base {
];
// Avatar source
- $avatar_source = AKSRT_Settings::get_all()['avatar_source'] ?? 'cn.cravatar.com';
+ $avatar_source = \AKSRT\Settings\Settings::get_all()['avatar_source'] ?? 'cn.cravatar.com';
$checks['avatar_source'] = [
'label' => '头像服务',
'value' => $avatar_source,
diff --git a/inc/classes/admin/import-export-traits/trait-aksrt-admin-import-export-controller-part-1.php b/src/AKSRT/Admin/ImportExportControllerPart1.php
similarity index 89%
rename from inc/classes/admin/import-export-traits/trait-aksrt-admin-import-export-controller-part-1.php
rename to src/AKSRT/Admin/ImportExportControllerPart1.php
index 587cd182..7015b0fd 100644
--- a/inc/classes/admin/import-export-traits/trait-aksrt-admin-import-export-controller-part-1.php
+++ b/src/AKSRT/Admin/ImportExportControllerPart1.php
@@ -1,14 +1,20 @@
get_param('domain');
- $schema_provider = AKSRT_Admin_Schema_Provider::get_instance();
+ $schema_provider = SchemaProvider::get_instance();
$schema = $schema_provider->get_schema($domain);
if (!$schema) {
@@ -18,15 +24,15 @@ trait AKSRT_Admin_Import_Export_Controller_Part_1 {
return $this->success(['schema' => $schema]);
}
- public function rest_get_schema_section(WP_REST_Request $request): WP_REST_Response {
+ public function rest_get_schema_section(\WP_REST_Request $request): \WP_REST_Response {
return $this->get_section_settings($request, (string) $request->get_param('domain'));
}
- public function rest_save_schema_section(WP_REST_Request $request): WP_REST_Response {
+ public function rest_save_schema_section(\WP_REST_Request $request): \WP_REST_Response {
return $this->save_section_settings($request, (string) $request->get_param('domain'));
}
- public function list_setting_backups(WP_REST_Request $request): WP_REST_Response {
+ public function list_setting_backups(\WP_REST_Request $request): \WP_REST_Response {
$backups = get_option('aksrt_settings_backups', []);
if (!is_array($backups)) {
$backups = [];
@@ -44,7 +50,7 @@ trait AKSRT_Admin_Import_Export_Controller_Part_1 {
]);
}
- public function create_setting_backup(WP_REST_Request $request): WP_REST_Response {
+ public function create_setting_backup(\WP_REST_Request $request): \WP_REST_Response {
$params = $this->get_json_params($request);
$type = sanitize_key((string) ($params['type'] ?? 'manual'));
$label = sanitize_text_field((string) ($params['label'] ?? ''));
@@ -63,7 +69,7 @@ trait AKSRT_Admin_Import_Export_Controller_Part_1 {
]);
}
- public function restore_setting_backup(WP_REST_Request $request): WP_REST_Response {
+ public function restore_setting_backup(\WP_REST_Request $request): \WP_REST_Response {
$id = (int) $request->get_param('id');
$backups = get_option('aksrt_settings_backups', []);
if (!is_array($backups)) {
@@ -85,7 +91,7 @@ trait AKSRT_Admin_Import_Export_Controller_Part_1 {
$payload = $target['payload'];
$domains = $payload['domains'] ?? [];
$standalone = $payload['standalone'] ?? [];
- $provider = AKSRT_Admin_Schema_Provider::get_instance();
+ $provider = SchemaProvider::get_instance();
foreach ($domains as $domain => $domainPayload) {
$data = $domainPayload['data'] ?? $domainPayload;
@@ -100,7 +106,7 @@ trait AKSRT_Admin_Import_Export_Controller_Part_1 {
}
}
- AKSRT_Settings::flush_settings_cache();
+ \AKSRT\Settings\Settings::flush_settings_cache();
return $this->success([
'message' => __('设置已从快照恢复', 'aksrt'),
@@ -110,7 +116,7 @@ trait AKSRT_Admin_Import_Export_Controller_Part_1 {
]);
}
- public function delete_setting_backup(WP_REST_Request $request): WP_REST_Response {
+ public function delete_setting_backup(\WP_REST_Request $request): \WP_REST_Response {
$id = (int) $request->get_param('id');
$backups = get_option('aksrt_settings_backups', []);
if (!is_array($backups)) {
@@ -145,7 +151,7 @@ trait AKSRT_Admin_Import_Export_Controller_Part_1 {
/**
* GET /widgets/export — Export current widget configuration.
*/
- public function export_widgets(WP_REST_Request $request): WP_REST_Response {
+ public function export_widgets(\WP_REST_Request $request): \WP_REST_Response {
$sidebars_widgets = get_option('sidebars_widgets', []);
$widget_options = $this->collect_widget_options();
@@ -162,7 +168,7 @@ trait AKSRT_Admin_Import_Export_Controller_Part_1 {
/**
* POST /widgets/import — Import widget configuration.
*/
- public function import_widgets(WP_REST_Request $request): WP_REST_Response {
+ public function import_widgets(\WP_REST_Request $request): \WP_REST_Response {
$params = $request->get_json_params() ?? [];
$sidebars = $params['sidebars_widgets'] ?? null;
$options = $params['widget_options'] ?? null;
@@ -201,7 +207,7 @@ trait AKSRT_Admin_Import_Export_Controller_Part_1 {
/**
* GET /widgets/templates — List saved widget templates.
*/
- public function list_widget_templates(WP_REST_Request $request): WP_REST_Response {
+ public function list_widget_templates(\WP_REST_Request $request): \WP_REST_Response {
$templates = get_option('aksrt_widget_templates', []);
return $this->success(['data' => ['templates' => $templates]]);
}
@@ -209,7 +215,7 @@ trait AKSRT_Admin_Import_Export_Controller_Part_1 {
/**
* POST /widgets/templates — Save current layout as a named template.
*/
- public function save_widget_template(WP_REST_Request $request): WP_REST_Response {
+ public function save_widget_template(\WP_REST_Request $request): \WP_REST_Response {
$params = $request->get_json_params() ?? [];
$name = sanitize_text_field((string) ($params['name'] ?? ''));
if (!$name) {
@@ -234,7 +240,7 @@ trait AKSRT_Admin_Import_Export_Controller_Part_1 {
/**
* POST /widgets/templates/{id}/apply — Apply a saved template.
*/
- public function apply_widget_template(WP_REST_Request $request): WP_REST_Response {
+ public function apply_widget_template(\WP_REST_Request $request): \WP_REST_Response {
$id = (int) $request->get_param('id');
$templates = get_option('aksrt_widget_templates', []);
@@ -268,7 +274,7 @@ trait AKSRT_Admin_Import_Export_Controller_Part_1 {
/**
* DELETE /widgets/templates/{id} — Delete a saved template.
*/
- public function delete_widget_template(WP_REST_Request $request): WP_REST_Response {
+ public function delete_widget_template(\WP_REST_Request $request): \WP_REST_Response {
$id = (int) $request->get_param('id');
$templates = get_option('aksrt_widget_templates', []);
diff --git a/inc/classes/admin/import-export-traits/trait-aksrt-admin-import-export-controller-part-2.php b/src/AKSRT/Admin/ImportExportControllerPart2.php
similarity index 87%
rename from inc/classes/admin/import-export-traits/trait-aksrt-admin-import-export-controller-part-2.php
rename to src/AKSRT/Admin/ImportExportControllerPart2.php
index be750d9e..2b8ea2d9 100644
--- a/inc/classes/admin/import-export-traits/trait-aksrt-admin-import-export-controller-part-2.php
+++ b/src/AKSRT/Admin/ImportExportControllerPart2.php
@@ -1,11 +1,17 @@
read_settings('tools', 'backup');
$frequency = sanitize_key((string) ($settings['backup_frequency'] ?? 'weekly'));
$allowed = ['daily', 'weekly', 'monthly'];
@@ -20,7 +26,7 @@ trait AKSRT_Admin_Import_Export_Controller_Part_2 {
}
private function build_settings_backup(string $type, string $label = ''): array {
- $schema_provider = AKSRT_Admin_Schema_Provider::get_instance();
+ $schema_provider = SchemaProvider::get_instance();
$domains = $schema_provider->get_domain_keys();
$payload = [
@@ -37,7 +43,7 @@ trait AKSRT_Admin_Import_Export_Controller_Part_2 {
];
}
- foreach (AKSRT_Settings::STANDALONE_OPTION_KEYS as $key) {
+ foreach (\AKSRT\Settings\Settings::STANDALONE_OPTION_KEYS as $key) {
$value = get_option($key);
if ($value !== false) {
$payload['standalone'][$key] = $value;
@@ -54,7 +60,7 @@ trait AKSRT_Admin_Import_Export_Controller_Part_2 {
}
private function trim_setting_backups(array $backups): array {
- $retain = (int) (AKSRT_Settings::get_value('backup_retain', 7));
+ $retain = (int) (\AKSRT\Settings\Settings::get_value('backup_retain', 7));
$retain = max(3, min(20, $retain));
if (count($backups) <= $retain) {
diff --git a/inc/classes/admin/class-aksrt-admin-message-controller.php b/src/AKSRT/Admin/MessageController.php
similarity index 77%
rename from inc/classes/admin/class-aksrt-admin-message-controller.php
rename to src/AKSRT/Admin/MessageController.php
index a87b6a1f..c6d565ae 100644
--- a/inc/classes/admin/class-aksrt-admin-message-controller.php
+++ b/src/AKSRT/Admin/MessageController.php
@@ -1,16 +1,13 @@
get_param('type');
$per_page = min(100, (int) $request->get_param('per_page'));
$page = max(1, (int) $request->get_param('page'));
- if (!class_exists('AKSRT_Message')) {
+ if (!class_exists('\AKSRT\Messages\Message')) {
return $this->success(['data' => [], 'total' => 0]);
}
- $msg = AKSRT_Message::get_instance();
+ $msg = \AKSRT\Messages\Message::get_instance();
$args = [
'limit' => $per_page,
'offset' => ($page - 1) * $per_page,
@@ -135,59 +132,59 @@ class AKSRT_Admin_Message_Controller extends AKSRT_Admin_Controller_Base {
]);
}
- public function get_unread_count(WP_REST_Request $request): WP_REST_Response {
+ public function get_unread_count(\WP_REST_Request $request): \WP_REST_Response {
$user_id = get_current_user_id();
- if (!class_exists('AKSRT_Message')) {
+ if (!class_exists('\AKSRT\Messages\Message')) {
return $this->success(['data' => ['unread' => 0]]);
}
- $count = AKSRT_Message::get_instance()->get_unread_count($user_id);
+ $count = \AKSRT\Messages\Message::get_instance()->get_unread_count($user_id);
return $this->success(['data' => ['unread' => $count]]);
}
- public function mark_read(WP_REST_Request $request): WP_REST_Response {
+ public function mark_read(\WP_REST_Request $request): \WP_REST_Response {
$user_id = get_current_user_id();
$id = (string) $request->get_param('id');
- if (!class_exists('AKSRT_Message')) {
+ if (!class_exists('\AKSRT\Messages\Message')) {
return $this->error('not_available', '消息系统未启用。', 501);
}
- $result = AKSRT_Message::get_instance()->mark_read($user_id, $id);
+ $result = \AKSRT\Messages\Message::get_instance()->mark_read($user_id, $id);
return $this->success(['data' => ['success' => $result]]);
}
- public function mark_all_read(WP_REST_Request $request): WP_REST_Response {
+ public function mark_all_read(\WP_REST_Request $request): \WP_REST_Response {
$user_id = get_current_user_id();
- if (!class_exists('AKSRT_Message')) {
+ if (!class_exists('\AKSRT\Messages\Message')) {
return $this->error('not_available', '消息系统未启用。', 501);
}
- $result = AKSRT_Message::get_instance()->mark_all_read($user_id);
+ $result = \AKSRT\Messages\Message::get_instance()->mark_all_read($user_id);
return $this->success(['data' => ['success' => $result]]);
}
// ── Conversation handlers ──
- public function list_conversations(WP_REST_Request $request): WP_REST_Response {
+ public function list_conversations(\WP_REST_Request $request): \WP_REST_Response {
$user_id = get_current_user_id();
$limit = min(50, (int) $request->get_param('limit'));
- if (!class_exists('AKSRT_Private_Message')) {
+ if (!class_exists('\AKSRT\Messages\PrivateMessage')) {
return $this->success(['data' => []]);
}
- $conversations = AKSRT_Private_Message::get_instance()->get_conversations($user_id, $limit);
+ $conversations = \AKSRT\Messages\PrivateMessage::get_instance()->get_conversations($user_id, $limit);
return $this->success(['data' => $conversations]);
}
- public function get_thread(WP_REST_Request $request): WP_REST_Response {
+ public function get_thread(\WP_REST_Request $request): \WP_REST_Response {
$user_id = get_current_user_id();
$conv_id = (int) $request->get_param('id');
$page = max(1, (int) $request->get_param('page'));
$per_page = min(50, (int) $request->get_param('per_page'));
- if (!class_exists('AKSRT_Private_Message')) {
+ if (!class_exists('\AKSRT\Messages\PrivateMessage')) {
return $this->error('not_available', '私信系统未启用。', 501);
}
- $result = AKSRT_Private_Message::get_instance()->get_thread($conv_id, $user_id, $page, $per_page);
+ $result = \AKSRT\Messages\PrivateMessage::get_instance()->get_thread($conv_id, $user_id, $page, $per_page);
if (is_wp_error($result)) {
return $this->error('thread_error', $result->get_error_message(), 403);
}
@@ -195,7 +192,7 @@ class AKSRT_Admin_Message_Controller extends AKSRT_Admin_Controller_Base {
return $this->success(['data' => $result]);
}
- public function send_message(WP_REST_Request $request): WP_REST_Response {
+ public function send_message(\WP_REST_Request $request): \WP_REST_Response {
$user_id = get_current_user_id();
$conv_id = (int) $request->get_param('id');
$content = trim((string) $request->get_param('content'));
@@ -204,11 +201,11 @@ class AKSRT_Admin_Message_Controller extends AKSRT_Admin_Controller_Base {
return $this->error('content_required', '消息内容不能为空。', 400);
}
- if (!class_exists('AKSRT_Private_Message')) {
+ if (!class_exists('\AKSRT\Messages\PrivateMessage')) {
return $this->error('not_available', '私信系统未启用。', 501);
}
- $result = AKSRT_Private_Message::get_instance()->send($conv_id, $user_id, $content);
+ $result = \AKSRT\Messages\PrivateMessage::get_instance()->send($conv_id, $user_id, $content);
if (!$result['success']) {
return $this->error('send_failed', $result['message'] ?? '发送失败。', 500);
}
@@ -216,7 +213,7 @@ class AKSRT_Admin_Message_Controller extends AKSRT_Admin_Controller_Base {
return $this->success(['data' => $result]);
}
- public function get_or_create_conversation(WP_REST_Request $request): WP_REST_Response {
+ public function get_or_create_conversation(\WP_REST_Request $request): \WP_REST_Response {
$user_id = get_current_user_id();
$other_id = (int) $request->get_param('user_id');
@@ -224,11 +221,11 @@ class AKSRT_Admin_Message_Controller extends AKSRT_Admin_Controller_Base {
return $this->error('self_message', '不能与自己创建对话。', 400);
}
- if (!class_exists('AKSRT_Private_Message')) {
+ if (!class_exists('\AKSRT\Messages\PrivateMessage')) {
return $this->error('not_available', '私信系统未启用。', 501);
}
- $conv_id = AKSRT_Private_Message::get_instance()->get_or_create_conversation($user_id, $other_id);
+ $conv_id = \AKSRT\Messages\PrivateMessage::get_instance()->get_or_create_conversation($user_id, $other_id);
if (is_wp_error($conv_id)) {
return $this->error('create_failed', $conv_id->get_error_message(), 500);
}
@@ -236,15 +233,15 @@ class AKSRT_Admin_Message_Controller extends AKSRT_Admin_Controller_Base {
return $this->success(['data' => ['conversation_id' => $conv_id]]);
}
- public function mark_conversation_read(WP_REST_Request $request): WP_REST_Response {
+ public function mark_conversation_read(\WP_REST_Request $request): \WP_REST_Response {
$user_id = get_current_user_id();
$conv_id = (int) $request->get_param('id');
- if (!class_exists('AKSRT_Private_Message')) {
+ if (!class_exists('\AKSRT\Messages\PrivateMessage')) {
return $this->error('not_available', '私信系统未启用。', 501);
}
- AKSRT_Private_Message::get_instance()->mark_conversation_read($conv_id, $user_id);
+ \AKSRT\Messages\PrivateMessage::get_instance()->mark_conversation_read($conv_id, $user_id);
return $this->success(['data' => ['success' => true]]);
}
diff --git a/inc/classes/admin/native/class-aksrt-admin-pay-after-sale.php b/src/AKSRT/Admin/Native/PayAfterSale.php
similarity index 93%
rename from inc/classes/admin/native/class-aksrt-admin-pay-after-sale.php
rename to src/AKSRT/Admin/Native/PayAfterSale.php
index 56714da1..91c3bb65 100644
--- a/inc/classes/admin/native/class-aksrt-admin-pay-after-sale.php
+++ b/src/AKSRT/Admin/Native/PayAfterSale.php
@@ -1,15 +1,13 @@
get($order_number);
+ if ($user_id <= 0 && class_exists('\AKSRT\Payment\OrderRepository')) {
+ $order = \AKSRT\Payment\OrderRepository::get_instance()->get($order_number);
$user_id = (int) ($order['user_id'] ?? 0);
}
- $id = AKSRT_After_Sale::get_instance()->create([
+ $id = \AKSRT\Payment\AfterSale::get_instance()->create([
'order_number' => $order_number,
'user_id' => $user_id,
'type' => sanitize_key((string) wp_unslash($_POST['type'] ?? 'refund')),
@@ -75,7 +73,7 @@ class AKSRT_Admin_Pay_After_Sale {
$this->ensure_cap();
$this->render_header(__('售后管理', 'aksrt'));
- if (!class_exists('AKSRT_After_Sale')) {
+ if (!class_exists('\AKSRT\Payment\AfterSale')) {
echo '' . esc_html__('售后模块未初始化。', 'aksrt') . '
';
$this->render_footer();
return;
@@ -89,7 +87,7 @@ class AKSRT_Admin_Pay_After_Sale {
}
$page_num = max(1, (int) ($_GET['paged'] ?? 1));
$per_page = 20;
- $svc = AKSRT_After_Sale::get_instance();
+ $svc = \AKSRT\Payment\AfterSale::get_instance();
$stats = $svc->get_stats();
$status_options = $this->after_sale_status_options(true);
$type_options = $this->after_sale_type_options(true);
@@ -223,8 +221,8 @@ class AKSRT_Admin_Pay_After_Sale {
check_admin_referer('aksrt_pay_update_after_sale_' . $id);
$ok = false;
- if ($id > 0 && $new_status !== '' && class_exists('AKSRT_After_Sale')) {
- $ok = AKSRT_After_Sale::get_instance()->update_status($id, $new_status, get_current_user_id(), $note);
+ if ($id > 0 && $new_status !== '' && class_exists('\AKSRT\Payment\AfterSale')) {
+ $ok = \AKSRT\Payment\AfterSale::get_instance()->update_status($id, $new_status, get_current_user_id(), $note);
}
wp_safe_redirect($this->page_url('aksrt_after_sale', ['aksrt_pay_msg' => $ok ? 'after_sale_updated' : 'after_sale_failed']));
exit;
@@ -239,8 +237,8 @@ class AKSRT_Admin_Pay_After_Sale {
check_admin_referer('aksrt_pay_after_sale_action_' . $id);
$ok = false;
- if ($id > 0 && class_exists('AKSRT_After_Sale')) {
- $svc = AKSRT_After_Sale::get_instance();
+ if ($id > 0 && class_exists('\AKSRT\Payment\AfterSale')) {
+ $svc = \AKSRT\Payment\AfterSale::get_instance();
$operator_id = get_current_user_id();
if ($as_action === 'approve') {
$ok = $svc->merchant_approve($id, $operator_id);
@@ -263,8 +261,8 @@ class AKSRT_Admin_Pay_After_Sale {
if ($include_all) {
$options[''] = __('全部状态', 'aksrt');
}
- if (class_exists('AKSRT_After_Sale')) {
- foreach (AKSRT_After_Sale::get_status_options() as $item) {
+ if (class_exists('\AKSRT\Payment\AfterSale')) {
+ foreach (\AKSRT\Payment\AfterSale::get_status_options() as $item) {
$value = (string) ($item['value'] ?? '');
if ($value === '') {
continue;
@@ -294,8 +292,8 @@ class AKSRT_Admin_Pay_After_Sale {
'exchange' => __('换货', 'aksrt'),
'repair' => __('维修', 'aksrt'),
];
- if (class_exists('AKSRT_After_Sale')) {
- foreach (AKSRT_After_Sale::get_type_options() as $item) {
+ if (class_exists('\AKSRT\Payment\AfterSale')) {
+ foreach (\AKSRT\Payment\AfterSale::get_type_options() as $item) {
$value = (string) ($item['value'] ?? '');
if ($value === '') {
continue;
diff --git a/inc/classes/admin/native/class-aksrt-admin-pay-charge-cards.php b/src/AKSRT/Admin/Native/PayChargeCards.php
similarity index 96%
rename from inc/classes/admin/native/class-aksrt-admin-pay-charge-cards.php
rename to src/AKSRT/Admin/Native/PayChargeCards.php
index b7391970..1c84fb8f 100644
--- a/inc/classes/admin/native/class-aksrt-admin-pay-charge-cards.php
+++ b/src/AKSRT/Admin/Native/PayChargeCards.php
@@ -1,15 +1,13 @@
ensure_cap();
$this->render_header(__('卡密管理', 'aksrt'));
- if (!class_exists('AKSRT_Charge_Card')) {
+ if (!class_exists('\AKSRT\Payment\ChargeCard')) {
echo '' . esc_html__('卡密模块未初始化。', 'aksrt') . '
';
$this->render_footer();
return;
@@ -46,7 +44,7 @@ class AKSRT_Admin_Pay_Charge_Cards {
$search = isset($_GET['s']) ? sanitize_text_field((string) wp_unslash($_GET['s'])) : '';
$page_num = max(1, (int) ($_GET['paged'] ?? 1));
$per_page = 20;
- $svc = AKSRT_Charge_Card::get_instance();
+ $svc = \AKSRT\Payment\ChargeCard::get_instance();
$stats = $svc->get_stats();
$type_labels = [
'balance' => __('余额', 'aksrt'),
@@ -229,8 +227,8 @@ class AKSRT_Admin_Pay_Charge_Cards {
check_admin_referer('aksrt_pay_disable_charge_card_' . $id);
$ok = false;
- if ($id > 0 && class_exists('AKSRT_Charge_Card')) {
- $ok = AKSRT_Charge_Card::get_instance()->disable($id);
+ if ($id > 0 && class_exists('\AKSRT\Payment\ChargeCard')) {
+ $ok = \AKSRT\Payment\ChargeCard::get_instance()->disable($id);
}
wp_safe_redirect($this->page_url('aksrt_charge_cards', [
@@ -245,7 +243,7 @@ class AKSRT_Admin_Pay_Charge_Cards {
}
check_admin_referer('aksrt_pay_batch_charge_cards');
- if (!class_exists('AKSRT_Charge_Card')) {
+ if (!class_exists('\AKSRT\Payment\ChargeCard')) {
wp_safe_redirect($this->page_url('aksrt_charge_cards', ['aksrt_pay_msg' => 'card_batch_failed']));
exit;
}
@@ -280,7 +278,7 @@ class AKSRT_Admin_Pay_Charge_Cards {
$meta['days'] = $days;
}
- $codes = AKSRT_Charge_Card::get_instance()->batch_create($type, $meta, $count, $length, $prefix, $expires, $note);
+ $codes = \AKSRT\Payment\ChargeCard::get_instance()->batch_create($type, $meta, $count, $length, $prefix, $expires, $note);
$ok = !empty($codes);
if ($ok) {
set_transient('aksrt_pay_card_codes_' . get_current_user_id(), $codes, 10 * MINUTE_IN_SECONDS);
diff --git a/inc/classes/admin/native/class-aksrt-admin-pay-coupons.php b/src/AKSRT/Admin/Native/PayCoupons.php
similarity index 96%
rename from inc/classes/admin/native/class-aksrt-admin-pay-coupons.php
rename to src/AKSRT/Admin/Native/PayCoupons.php
index 93898e42..f9d69ad3 100644
--- a/inc/classes/admin/native/class-aksrt-admin-pay-coupons.php
+++ b/src/AKSRT/Admin/Native/PayCoupons.php
@@ -1,15 +1,13 @@
ensure_cap();
$this->render_header(__('优惠码', 'aksrt'));
- if (!class_exists('AKSRT_Coupon')) {
+ if (!class_exists('\AKSRT\Payment\Coupon')) {
echo '' . esc_html__('优惠码模块未初始化。', 'aksrt') . '
';
$this->render_footer();
return;
}
- $svc = AKSRT_Coupon::get_instance();
+ $svc = \AKSRT\Payment\Coupon::get_instance();
$edit_id = isset($_GET['edit_id']) ? (int) $_GET['edit_id'] : 0;
$edit_row = $edit_id > 0 ? $svc->get($edit_id) : null;
@@ -169,7 +167,7 @@ class AKSRT_Admin_Pay_Coupons {
}
}
- private function render_list(AKSRT_Coupon $svc): void {
+ private function render_list(\AKSRT\Payment\Coupon $svc): void {
$status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : '';
$search = isset($_GET['s']) ? sanitize_text_field((string) wp_unslash($_GET['s'])) : '';
$page_num = max(1, (int) ($_GET['paged'] ?? 1));
@@ -253,8 +251,8 @@ class AKSRT_Admin_Pay_Coupons {
check_admin_referer('aksrt_pay_create_coupon');
$ok = false;
- if (class_exists('AKSRT_Coupon')) {
- $id = AKSRT_Coupon::get_instance()->create([
+ if (class_exists('\AKSRT\Payment\Coupon')) {
+ $id = \AKSRT\Payment\Coupon::get_instance()->create([
'code' => sanitize_text_field((string) wp_unslash($_POST['code'] ?? '')),
'type' => sanitize_key((string) wp_unslash($_POST['type'] ?? 'fixed')),
'value' => (float) ($_POST['value'] ?? 0),
@@ -280,8 +278,8 @@ class AKSRT_Admin_Pay_Coupons {
$ok = false;
$created = 0;
$codes = [];
- if (class_exists('AKSRT_Coupon')) {
- $result = AKSRT_Coupon::get_instance()->batch_create([
+ if (class_exists('\AKSRT\Payment\Coupon')) {
+ $result = \AKSRT\Payment\Coupon::get_instance()->batch_create([
'type' => sanitize_key((string) wp_unslash($_POST['type'] ?? 'fixed')),
'value' => (float) ($_POST['value'] ?? 0),
'min_amount' => (float) ($_POST['min_amount'] ?? 0),
@@ -314,8 +312,8 @@ class AKSRT_Admin_Pay_Coupons {
check_admin_referer('aksrt_pay_update_coupon_' . $id);
$ok = false;
- if ($id > 0 && class_exists('AKSRT_Coupon')) {
- $ok = AKSRT_Coupon::get_instance()->update($id, [
+ if ($id > 0 && class_exists('\AKSRT\Payment\Coupon')) {
+ $ok = \AKSRT\Payment\Coupon::get_instance()->update($id, [
'type' => sanitize_key((string) wp_unslash($_POST['type'] ?? 'fixed')),
'value' => (float) ($_POST['value'] ?? 0),
'min_amount' => (float) ($_POST['min_amount'] ?? 0),
@@ -339,7 +337,7 @@ class AKSRT_Admin_Pay_Coupons {
}
$id = isset($_POST['coupon_id']) ? (int) $_POST['coupon_id'] : 0;
check_admin_referer('aksrt_pay_disable_coupon_' . $id);
- $ok = $id > 0 && class_exists('AKSRT_Coupon') && AKSRT_Coupon::get_instance()->disable($id);
+ $ok = $id > 0 && class_exists('\AKSRT\Payment\Coupon') && \AKSRT\Payment\Coupon::get_instance()->disable($id);
wp_safe_redirect($this->page_url(['aksrt_pay_msg' => $ok ? 'coupon_disabled' : 'coupon_failed']));
exit;
}
@@ -350,7 +348,7 @@ class AKSRT_Admin_Pay_Coupons {
}
$id = isset($_POST['coupon_id']) ? (int) $_POST['coupon_id'] : 0;
check_admin_referer('aksrt_pay_enable_coupon_' . $id);
- $ok = $id > 0 && class_exists('AKSRT_Coupon') && AKSRT_Coupon::get_instance()->enable($id);
+ $ok = $id > 0 && class_exists('\AKSRT\Payment\Coupon') && \AKSRT\Payment\Coupon::get_instance()->enable($id);
wp_safe_redirect($this->page_url(['aksrt_pay_msg' => $ok ? 'coupon_enabled' : 'coupon_failed']));
exit;
}
diff --git a/inc/classes/admin/native/class-aksrt-admin-pay-download-logs.php b/src/AKSRT/Admin/Native/PayDownloadLogs.php
similarity index 96%
rename from inc/classes/admin/native/class-aksrt-admin-pay-download-logs.php
rename to src/AKSRT/Admin/Native/PayDownloadLogs.php
index 038243dc..77f42357 100644
--- a/inc/classes/admin/native/class-aksrt-admin-pay-download-logs.php
+++ b/src/AKSRT/Admin/Native/PayDownloadLogs.php
@@ -1,15 +1,13 @@
ensure_cap();
echo '' . esc_html__('下载记录', 'aksrt') . '
';
- if (!class_exists('AKSRT_DB_Migrator')) {
+ if (!class_exists('\AKSRT\Core\DBMigrator')) {
echo '
' . esc_html__('数据库服务不可用。', 'aksrt') . '
';
return;
}
- $table = AKSRT_DB_Migrator::table('dl_token');
+ $table = \AKSRT\Core\DBMigrator::table('dl_token');
if ($table === '') {
echo '' . esc_html__('下载令牌表未初始化。', 'aksrt') . '
';
return;
diff --git a/inc/classes/admin/native/class-aksrt-admin-pay-income.php b/src/AKSRT/Admin/Native/PayIncome.php
similarity index 95%
rename from inc/classes/admin/native/class-aksrt-admin-pay-income.php
rename to src/AKSRT/Admin/Native/PayIncome.php
index b389cb0b..c4e2686d 100644
--- a/inc/classes/admin/native/class-aksrt-admin-pay-income.php
+++ b/src/AKSRT/Admin/Native/PayIncome.php
@@ -1,15 +1,13 @@
ensure_cap();
$this->render_header(__('创作分成', 'aksrt'));
- if (!class_exists('AKSRT_Revenue')) {
+ if (!class_exists('\AKSRT\Payment\Revenue')) {
echo '
';
$this->render_footer();
return;
@@ -44,7 +42,7 @@ class AKSRT_Admin_Pay_Income {
$user_id = isset($_GET['user_id']) ? max(0, (int) $_GET['user_id']) : 0;
$page_num = max(1, (int) ($_GET['paged'] ?? 1));
$per_page = 20;
- $svc = AKSRT_Revenue::get_instance();
+ $svc = \AKSRT\Payment\Revenue::get_instance();
$stats = $user_id > 0 ? $svc->get_stats($user_id) : $svc->get_stats();
echo '
' . esc_html(sprintf(
@@ -124,7 +122,7 @@ class AKSRT_Admin_Pay_Income {
}
$id = isset($_POST['revenue_id']) ? (int) $_POST['revenue_id'] : 0;
check_admin_referer('aksrt_pay_settle_income_' . $id);
- $ok = $id > 0 && class_exists('AKSRT_Revenue') && AKSRT_Revenue::get_instance()->settle($id);
+ $ok = $id > 0 && class_exists('\AKSRT\Payment\Revenue') && \AKSRT\Payment\Revenue::get_instance()->settle($id);
wp_safe_redirect($this->page_url('aksrt_income', ['aksrt_pay_msg' => $ok ? 'income_settled' : 'income_failed']));
exit;
}
diff --git a/inc/classes/admin/native/class-aksrt-admin-pay-menus.php b/src/AKSRT/Admin/Native/PayMenus.php
similarity index 79%
rename from inc/classes/admin/native/class-aksrt-admin-pay-menus.php
rename to src/AKSRT/Admin/Native/PayMenus.php
index 244b50b4..7a834bba 100644
--- a/inc/classes/admin/native/class-aksrt-admin-pay-menus.php
+++ b/src/AKSRT/Admin/Native/PayMenus.php
@@ -1,15 +1,13 @@
'aksrt_orders',
'title' => __('订单', 'aksrt'),
'callback' => static function (): void {
- if (class_exists('AKSRT_Admin_Pay_Orders')) {
- AKSRT_Admin_Pay_Orders::get_instance()->render_orders_page();
+ if (class_exists('PayOrders')) {
+ PayOrders::get_instance()->render_orders_page();
return;
}
wp_die(esc_html__('订单模块未初始化。', 'aksrt'));
@@ -58,8 +56,8 @@ class AKSRT_Admin_Pay_Menus {
'slug' => 'aksrt_pay_products',
'title' => __('付费文章', 'aksrt'),
'callback' => static function (): void {
- if (class_exists('AKSRT_Admin_Pay_Products')) {
- AKSRT_Admin_Pay_Products::get_instance()->render_products_page();
+ if (class_exists('PayProducts')) {
+ PayProducts::get_instance()->render_products_page();
return;
}
wp_die(esc_html__('付费文章模块未初始化。', 'aksrt'));
@@ -69,8 +67,8 @@ class AKSRT_Admin_Pay_Menus {
'slug' => 'aksrt_download_logs',
'title' => __('下载记录', 'aksrt'),
'callback' => static function (): void {
- if (class_exists('AKSRT_Admin_Pay_Download_Logs')) {
- AKSRT_Admin_Pay_Download_Logs::get_instance()->render_page();
+ if (class_exists('PayDownloadLogs')) {
+ PayDownloadLogs::get_instance()->render_page();
return;
}
wp_die(esc_html__('下载记录模块未初始化。', 'aksrt'));
@@ -80,8 +78,8 @@ class AKSRT_Admin_Pay_Menus {
'slug' => 'aksrt_shipping',
'title' => __('发货及物流', 'aksrt'),
'callback' => static function (): void {
- if (class_exists('AKSRT_Admin_Pay_Shipping')) {
- AKSRT_Admin_Pay_Shipping::get_instance()->render_shipping_page();
+ if (class_exists('PayShipping')) {
+ PayShipping::get_instance()->render_shipping_page();
return;
}
wp_die(esc_html__('物流模块未初始化。', 'aksrt'));
@@ -91,8 +89,8 @@ class AKSRT_Admin_Pay_Menus {
'slug' => 'aksrt_after_sale',
'title' => __('售后管理', 'aksrt'),
'callback' => static function (): void {
- if (class_exists('AKSRT_Admin_Pay_After_Sale')) {
- AKSRT_Admin_Pay_After_Sale::get_instance()->render_after_sale_page();
+ if (class_exists('PayAfterSale')) {
+ PayAfterSale::get_instance()->render_after_sale_page();
return;
}
wp_die(esc_html__('售后模块未初始化。', 'aksrt'));
@@ -102,8 +100,8 @@ class AKSRT_Admin_Pay_Menus {
'slug' => 'aksrt_coupons',
'title' => __('优惠码', 'aksrt'),
'callback' => static function (): void {
- if (class_exists('AKSRT_Admin_Pay_Coupons')) {
- AKSRT_Admin_Pay_Coupons::get_instance()->render_page();
+ if (class_exists('PayCoupons')) {
+ PayCoupons::get_instance()->render_page();
return;
}
wp_die(esc_html__('优惠码模块未初始化。', 'aksrt'));
@@ -113,8 +111,8 @@ class AKSRT_Admin_Pay_Menus {
'slug' => 'aksrt_charge_cards',
'title' => __('卡密管理', 'aksrt'),
'callback' => static function (): void {
- if (class_exists('AKSRT_Admin_Pay_Charge_Cards')) {
- AKSRT_Admin_Pay_Charge_Cards::get_instance()->render_charge_cards_page();
+ if (class_exists('PayChargeCards')) {
+ PayChargeCards::get_instance()->render_charge_cards_page();
return;
}
wp_die(esc_html__('卡密模块未初始化。', 'aksrt'));
@@ -124,8 +122,8 @@ class AKSRT_Admin_Pay_Menus {
'slug' => 'aksrt_income',
'title' => __('创作分成', 'aksrt'),
'callback' => static function (): void {
- if (class_exists('AKSRT_Admin_Pay_Income')) {
- AKSRT_Admin_Pay_Income::get_instance()->render_income_page();
+ if (class_exists('PayIncome')) {
+ PayIncome::get_instance()->render_income_page();
return;
}
wp_die(esc_html__('分成模块未初始化。', 'aksrt'));
@@ -135,8 +133,8 @@ class AKSRT_Admin_Pay_Menus {
'slug' => 'aksrt_rebate',
'title' => __('推广返佣', 'aksrt'),
'callback' => static function (): void {
- if (class_exists('AKSRT_Admin_Pay_Rebate')) {
- AKSRT_Admin_Pay_Rebate::get_instance()->render_rebate_page();
+ if (class_exists('PayRebate')) {
+ PayRebate::get_instance()->render_rebate_page();
return;
}
wp_die(esc_html__('返佣模块未初始化。', 'aksrt'));
@@ -146,8 +144,8 @@ class AKSRT_Admin_Pay_Menus {
'slug' => 'aksrt_withdraw',
'title' => __('提现审核', 'aksrt'),
'callback' => static function (): void {
- if (class_exists('AKSRT_Admin_Pay_Withdrawals')) {
- AKSRT_Admin_Pay_Withdrawals::get_instance()->render_withdrawals_page();
+ if (class_exists('PayWithdrawals')) {
+ PayWithdrawals::get_instance()->render_withdrawals_page();
return;
}
wp_die(esc_html__('提现模块未初始化。', 'aksrt'));
@@ -190,8 +188,8 @@ class AKSRT_Admin_Pay_Menus {
$page = isset($_GET['page']) ? sanitize_key((string) wp_unslash($_GET['page'])) : '';
- if ($page !== 'aksrt_withdraw' && class_exists('AKSRT_Withdrawal')) {
- $pending = (int) AKSRT_Withdrawal::get_instance()->get_count(['status' => AKSRT_Withdrawal::STATUS_PENDING]);
+ if ($page !== 'aksrt_withdraw' && class_exists('\AKSRT\Payment\Withdrawal')) {
+ $pending = (int) \AKSRT\Payment\Withdrawal::get_instance()->get_count(['status' => \AKSRT\Payment\Withdrawal::STATUS_PENDING]);
if ($pending > 0) {
$url = admin_url('admin.php?page=aksrt_withdraw&status=pending');
echo '
';
@@ -206,8 +204,8 @@ class AKSRT_Admin_Pay_Menus {
}
}
- if ($page !== 'aksrt_after_sale' && class_exists('AKSRT_After_Sale')) {
- $as_stats = AKSRT_After_Sale::get_instance()->get_stats();
+ if ($page !== 'aksrt_after_sale' && class_exists('\AKSRT\Payment\AfterSale')) {
+ $as_stats = \AKSRT\Payment\AfterSale::get_instance()->get_stats();
$pending_as = (int) ($as_stats['pending'] ?? 0);
if ($pending_as > 0) {
$url = admin_url('admin.php?page=aksrt_after_sale&status=pending');
@@ -247,22 +245,22 @@ class AKSRT_Admin_Pay_Menus {
$this->ensure_cap();
$this->render_header(__('支付中心', 'aksrt'));
- $order_stats = class_exists('AKSRT_Order_Repository')
- ? AKSRT_Order_Repository::get_instance()->get_stats()
+ $order_stats = class_exists('\AKSRT\Payment\OrderRepository')
+ ? \AKSRT\Payment\OrderRepository::get_instance()->get_stats()
: [];
- $withdraw_stats = class_exists('AKSRT_Withdrawal')
- ? AKSRT_Withdrawal::get_instance()->get_stats()
+ $withdraw_stats = class_exists('\AKSRT\Payment\Withdrawal')
+ ? \AKSRT\Payment\Withdrawal::get_instance()->get_stats()
: [];
- $card_stats = class_exists('AKSRT_Charge_Card')
- ? AKSRT_Charge_Card::get_instance()->get_stats()
+ $card_stats = class_exists('\AKSRT\Payment\ChargeCard')
+ ? \AKSRT\Payment\ChargeCard::get_instance()->get_stats()
: [];
echo '
' . esc_html__('运营数据入口(对齐 zibll 商城中心)。配置项仍在 AKSRT 主题设置 SPA。', 'aksrt') . '
';
echo '
';
$pending_ship = 0;
- if (class_exists('AKSRT_Order_Repository')) {
- $pending_ship = (int) (AKSRT_Order_Repository::get_instance()->get_pending_shipment_orders(['limit' => 1])['total'] ?? 0);
+ if (class_exists('\AKSRT\Payment\OrderRepository')) {
+ $pending_ship = (int) (\AKSRT\Payment\OrderRepository::get_instance()->get_pending_shipment_orders(['limit' => 1])['total'] ?? 0);
}
$this->stat_card(__('订单总数', 'aksrt'), (string) (int) ($order_stats['total'] ?? 0), $this->page_url('aksrt_orders'));
$this->stat_card(__('待支付', 'aksrt'), (string) (int) ($order_stats['pending'] ?? 0), $this->page_url('aksrt_orders', ['status' => 'pending']));
diff --git a/inc/classes/admin/native/class-aksrt-admin-pay-orders.php b/src/AKSRT/Admin/Native/PayOrders.php
similarity index 94%
rename from inc/classes/admin/native/class-aksrt-admin-pay-orders.php
rename to src/AKSRT/Admin/Native/PayOrders.php
index 13436196..f0323eac 100644
--- a/inc/classes/admin/native/class-aksrt-admin-pay-orders.php
+++ b/src/AKSRT/Admin/Native/PayOrders.php
@@ -1,15 +1,13 @@
ensure_cap();
$this->render_header(__('订单', 'aksrt'));
- if (!class_exists('AKSRT_Order_Repository')) {
+ if (!class_exists('\AKSRT\Payment\OrderRepository')) {
echo '
' . esc_html__('订单服务不可用。', 'aksrt') . '
';
$this->render_footer();
return;
@@ -59,7 +57,7 @@ class AKSRT_Admin_Pay_Orders {
$page_num = max(1, (int) ($_GET['paged'] ?? 1));
$per_page = 20;
- $repo = AKSRT_Order_Repository::get_instance();
+ $repo = \AKSRT\Payment\OrderRepository::get_instance();
$args = [
'limit' => $per_page,
'offset' => ($page_num - 1) * $per_page,
@@ -83,8 +81,8 @@ class AKSRT_Admin_Pay_Orders {
$items = $repo->get_orders_admin($args, $search);
$total = $repo->get_orders_count($args, $search);
$pages = max(1, (int) ceil($total / $per_page));
- $labels = class_exists('AKSRT_Domain_Model')
- ? AKSRT_Domain_Model::order_status_labels()
+ $labels = class_exists('\AKSRT\Core\DomainModel')
+ ? \AKSRT\Core\DomainModel::order_status_labels()
: [];
// Type tabs (zibll order subsubsub parity).
@@ -269,7 +267,7 @@ class AKSRT_Admin_Pay_Orders {
}
private function render_order_detail_page(string $order_number): void {
- $repo = AKSRT_Order_Repository::get_instance();
+ $repo = \AKSRT\Payment\OrderRepository::get_instance();
$order = $repo->get($order_number);
if (!$order) {
echo '
' . esc_html__('订单不存在。', 'aksrt') . '
';
@@ -277,8 +275,8 @@ class AKSRT_Admin_Pay_Orders {
return;
}
- $labels = class_exists('AKSRT_Domain_Model')
- ? AKSRT_Domain_Model::order_status_labels()
+ $labels = class_exists('\AKSRT\Core\DomainModel')
+ ? \AKSRT\Core\DomainModel::order_status_labels()
: [];
$context = $repo->get_admin_order_context($order_number);
$user_id = (int) ($order['user_id'] ?? 0);
@@ -291,11 +289,11 @@ class AKSRT_Admin_Pay_Orders {
$admin_note = (string) $order['note'];
}
- $shipping_items = class_exists('AKSRT_Shipping')
- ? AKSRT_Shipping::get_instance()->get_by_order($order_number)
+ $shipping_items = class_exists('\AKSRT\Payment\Shipping')
+ ? \AKSRT\Payment\Shipping::get_instance()->get_by_order($order_number)
: [];
- $after_sale = class_exists('AKSRT_After_Sale')
- ? (AKSRT_After_Sale::get_instance()->get_list(['order_number' => $order_number, 'limit' => 20])['items'] ?? [])
+ $after_sale = class_exists('\AKSRT\Payment\AfterSale')
+ ? (\AKSRT\Payment\AfterSale::get_instance()->get_list(['order_number' => $order_number, 'limit' => 20])['items'] ?? [])
: [];
echo '
← ' . esc_html__('返回订单列表', 'aksrt') . '
';
@@ -440,8 +438,8 @@ class AKSRT_Admin_Pay_Orders {
check_admin_referer('aksrt_pay_update_order_status_' . $order_number);
$ok = false;
- if ($order_number !== '' && $new_status !== '' && class_exists('AKSRT_Order_Repository')) {
- $ok = AKSRT_Order_Repository::get_instance()->update_status($order_number, $new_status, ['force' => true]);
+ if ($order_number !== '' && $new_status !== '' && class_exists('\AKSRT\Payment\OrderRepository')) {
+ $ok = \AKSRT\Payment\OrderRepository::get_instance()->update_status($order_number, $new_status, ['force' => true]);
}
$args = ['aksrt_pay_msg' => $ok ? 'order_updated' : 'order_failed'];
@@ -464,8 +462,8 @@ class AKSRT_Admin_Pay_Orders {
check_admin_referer('aksrt_pay_update_order_note_' . $order_number);
$ok = false;
- if ($order_number !== '' && class_exists('AKSRT_Order_Repository')) {
- $ok = AKSRT_Order_Repository::get_instance()->update_admin_note($order_number, $admin_note);
+ if ($order_number !== '' && class_exists('\AKSRT\Payment\OrderRepository')) {
+ $ok = \AKSRT\Payment\OrderRepository::get_instance()->update_admin_note($order_number, $admin_note);
}
wp_safe_redirect($this->page_url('aksrt_orders', [
@@ -482,8 +480,8 @@ class AKSRT_Admin_Pay_Orders {
check_admin_referer('aksrt_pay_clear_closed_orders');
$days = isset($_POST['days']) ? max(1, min(3650, (int) $_POST['days'])) : 14;
$deleted = 0;
- if (class_exists('AKSRT_Order_Repository')) {
- $deleted = AKSRT_Order_Repository::get_instance()->clear_closed_orders($days);
+ if (class_exists('\AKSRT\Payment\OrderRepository')) {
+ $deleted = \AKSRT\Payment\OrderRepository::get_instance()->clear_closed_orders($days);
}
wp_safe_redirect($this->page_url('aksrt_orders', [
'aksrt_pay_msg' => $deleted > 0 ? 'orders_cleared' : 'orders_clear_empty',
@@ -499,12 +497,12 @@ class AKSRT_Admin_Pay_Orders {
$order_number = isset($_POST['order_number']) ? sanitize_text_field((string) wp_unslash($_POST['order_number'])) : '';
check_admin_referer('aksrt_pay_delete_order_' . $order_number);
$ok = false;
- if ($order_number !== '' && class_exists('AKSRT_Order_Repository')) {
- $order = AKSRT_Order_Repository::get_instance()->get($order_number);
+ if ($order_number !== '' && class_exists('\AKSRT\Payment\OrderRepository')) {
+ $order = \AKSRT\Payment\OrderRepository::get_instance()->get($order_number);
$status = is_array($order) ? (string) ($order['status'] ?? '') : '';
// Only allow hard-delete of closed/expired rows (safety).
if (in_array($status, ['cancelled', 'expired'], true)) {
- $ok = AKSRT_Order_Repository::get_instance()->delete_order($order_number);
+ $ok = \AKSRT\Payment\OrderRepository::get_instance()->delete_order($order_number);
}
}
wp_safe_redirect($this->page_url('aksrt_orders', [
@@ -514,15 +512,15 @@ class AKSRT_Admin_Pay_Orders {
}
private function shipping_status_options(bool $include_all = false): array {
- if (class_exists('AKSRT_Admin_Pay_Shipping')) {
- return AKSRT_Admin_Pay_Shipping::get_instance()->shipping_status_options_public($include_all);
+ if (class_exists('PayShipping')) {
+ return PayShipping::get_instance()->shipping_status_options_public($include_all);
}
return $include_all ? ['' => __('全部状态', 'aksrt')] : [];
}
private function after_sale_type_options(bool $include_all = false): array {
- if (class_exists('AKSRT_Admin_Pay_After_Sale')) {
- return AKSRT_Admin_Pay_After_Sale::get_instance()->after_sale_type_options_public($include_all);
+ if (class_exists('PayAfterSale')) {
+ return PayAfterSale::get_instance()->after_sale_type_options_public($include_all);
}
return $include_all ? ['' => __('全部类型', 'aksrt')] : [
'refund' => __('仅退款', 'aksrt'),
@@ -530,8 +528,8 @@ class AKSRT_Admin_Pay_Orders {
}
private function render_carrier_field(string $selected = ''): void {
- if (class_exists('AKSRT_Admin_Pay_Shipping')) {
- AKSRT_Admin_Pay_Shipping::get_instance()->render_carrier_field_public($selected);
+ if (class_exists('PayShipping')) {
+ PayShipping::get_instance()->render_carrier_field_public($selected);
return;
}
echo '
';
diff --git a/inc/classes/admin/native/class-aksrt-admin-pay-products.php b/src/AKSRT/Admin/Native/PayProducts.php
similarity index 86%
rename from inc/classes/admin/native/class-aksrt-admin-pay-products.php
rename to src/AKSRT/Admin/Native/PayProducts.php
index 9de6ccb7..397d5a62 100644
--- a/inc/classes/admin/native/class-aksrt-admin-pay-products.php
+++ b/src/AKSRT/Admin/Native/PayProducts.php
@@ -1,15 +1,13 @@
ensure_cap();
$this->render_header(__('付费文章', 'aksrt'));
- if (!class_exists('AKSRT_Order_Repository') || !class_exists('AKSRT_Domain_Model')) {
+ if (!class_exists('\AKSRT\Payment\OrderRepository') || !class_exists('\AKSRT\Core\DomainModel')) {
echo '
' . esc_html__('订单服务不可用。', 'aksrt') . '
';
$this->render_footer();
return;
@@ -42,8 +40,8 @@ class AKSRT_Admin_Pay_Products {
$page_num = max(1, (int) ($_GET['paged'] ?? 1));
$per_page = 20;
- $type_labels = AKSRT_Domain_Model::pay_type_labels();
- unset($type_labels[AKSRT_Domain_Model::PAY_TYPE_NO]);
+ $type_labels = \AKSRT\Core\DomainModel::pay_type_labels();
+ unset($type_labels[\AKSRT\Core\DomainModel::PAY_TYPE_NO]);
$query = $this->query_paid_posts([
'pay_type' => $pay_type,
@@ -57,13 +55,13 @@ class AKSRT_Admin_Pay_Products {
$pages = max(1, (int) ceil($total / $per_page));
$sales_map = [];
- if ($posts && class_exists('AKSRT_Order_Repository')) {
+ if ($posts && class_exists('\AKSRT\Payment\OrderRepository')) {
$ids = array_map(static function ($p) {
return (int) $p->ID;
}, $posts);
- $sales_map = AKSRT_Order_Repository::get_instance()->get_content_sales_map(
+ $sales_map = \AKSRT\Payment\OrderRepository::get_instance()->get_content_sales_map(
$ids,
- AKSRT_Domain_Model::ORDER_PRODUCT_RESOURCE
+ \AKSRT\Core\DomainModel::ORDER_PRODUCT_RESOURCE
);
}
@@ -90,7 +88,7 @@ class AKSRT_Admin_Pay_Products {
foreach ($posts as $post) {
$post_id = (int) $post->ID;
$meta = function_exists('aksrt_get_pay_meta') ? aksrt_get_pay_meta($post) : [];
- $pt = AKSRT_Domain_Model::normalize_pay_type((string) ($meta['pay_type'] ?? AKSRT_Domain_Model::PAY_TYPE_NO));
+ $pt = \AKSRT\Core\DomainModel::normalize_pay_type((string) ($meta['pay_type'] ?? \AKSRT\Core\DomainModel::PAY_TYPE_NO));
$pt_label = $type_labels[$pt] ?? $pt;
$modo = (($meta['pay_modo'] ?? '0') === 'points') ? 'points' : '0';
$modo_label = $modo === 'points' ? __('积分', 'aksrt') : __('现金', 'aksrt');
@@ -107,7 +105,7 @@ class AKSRT_Admin_Pay_Products {
$db_sales = (int) ($sales['sales_count'] ?? 0);
$avg = (float) ($sales['avg_amount'] ?? 0);
$revenue = (float) ($sales['revenue'] ?? 0);
- $meta_sales = (int) get_post_meta($post_id, AKSRT_Domain_Model::RESOURCE_SALES_VOLUME_KEY, true);
+ $meta_sales = (int) get_post_meta($post_id, \AKSRT\Core\DomainModel::RESOURCE_SALES_VOLUME_KEY, true);
$edit_url = get_edit_post_link($post_id, 'raw');
$title = get_the_title($post_id);
@@ -116,7 +114,7 @@ class AKSRT_Admin_Pay_Products {
}
$orders_url = $this->page_url('aksrt_orders', [
- 'product_type' => AKSRT_Domain_Model::ORDER_PRODUCT_RESOURCE,
+ 'product_type' => \AKSRT\Core\DomainModel::ORDER_PRODUCT_RESOURCE,
'product_id' => $post_id,
]);
@@ -141,7 +139,7 @@ class AKSRT_Admin_Pay_Products {
echo '
' . esc_html__('编辑', 'aksrt') . '';
}
echo '
' . esc_html__('订单', 'aksrt') . '';
- if ($pt === AKSRT_Domain_Model::PAY_TYPE_DOWNLOAD) {
+ if ($pt === \AKSRT\Core\DomainModel::PAY_TYPE_DOWNLOAD) {
$dl_url = $this->page_url('aksrt_download_logs', ['post_id' => $post_id]);
echo '
' . esc_html__('下载记录', 'aksrt') . '';
}
@@ -160,7 +158,7 @@ class AKSRT_Admin_Pay_Products {
/**
* @param array{pay_type?:string,search?:string,page?:int,per_page?:int} $args
- * @return array{posts: WP_Post[], total: int}
+ * @return array{posts: \WP_Post[], total: int}
*/
private function query_paid_posts(array $args): array {
$pay_type = sanitize_key((string) ($args['pay_type'] ?? ''));
@@ -171,22 +169,22 @@ class AKSRT_Admin_Pay_Products {
$meta_query = [
'relation' => 'AND',
[
- 'key' => AKSRT_Domain_Model::PAY_META_KEY,
+ 'key' => \AKSRT\Core\DomainModel::PAY_META_KEY,
'compare' => 'EXISTS',
],
];
// Prefer denormalized type key when present; still exclude "no".
- if ($pay_type !== '' && $pay_type !== AKSRT_Domain_Model::PAY_TYPE_NO) {
+ if ($pay_type !== '' && $pay_type !== \AKSRT\Core\DomainModel::PAY_TYPE_NO) {
$meta_query[] = [
'relation' => 'OR',
[
- 'key' => AKSRT_Domain_Model::PAY_TYPE_KEY,
+ 'key' => \AKSRT\Core\DomainModel::PAY_TYPE_KEY,
'value' => $pay_type,
'compare' => '=',
],
[
- 'key' => AKSRT_Domain_Model::PAY_META_KEY,
+ 'key' => \AKSRT\Core\DomainModel::PAY_META_KEY,
'value' => '"pay_type";s:' . strlen($pay_type) . ':"' . $pay_type . '"',
'compare' => 'LIKE',
],
@@ -195,12 +193,12 @@ class AKSRT_Admin_Pay_Products {
$meta_query[] = [
'relation' => 'OR',
[
- 'key' => AKSRT_Domain_Model::PAY_TYPE_KEY,
- 'value' => AKSRT_Domain_Model::PAY_TYPE_NO,
+ 'key' => \AKSRT\Core\DomainModel::PAY_TYPE_KEY,
+ 'value' => \AKSRT\Core\DomainModel::PAY_TYPE_NO,
'compare' => '!=',
],
[
- 'key' => AKSRT_Domain_Model::PAY_TYPE_KEY,
+ 'key' => \AKSRT\Core\DomainModel::PAY_TYPE_KEY,
'compare' => 'NOT EXISTS',
],
];
@@ -228,10 +226,10 @@ class AKSRT_Admin_Pay_Products {
}
}
- $q = new WP_Query($q_args);
+ $q = new \WP_Query($q_args);
$posts = [];
foreach ($q->posts as $post) {
- if (!($post instanceof WP_Post)) {
+ if (!($post instanceof \WP_Post)) {
continue;
}
// Drop posts whose pay bag is effectively free/no.
@@ -240,7 +238,7 @@ class AKSRT_Admin_Pay_Products {
}
if ($pay_type !== '' && function_exists('aksrt_get_pay_meta')) {
$meta = aksrt_get_pay_meta($post);
- $pt = AKSRT_Domain_Model::normalize_pay_type((string) ($meta['pay_type'] ?? ''));
+ $pt = \AKSRT\Core\DomainModel::normalize_pay_type((string) ($meta['pay_type'] ?? ''));
if ($pt !== $pay_type) {
continue;
}
@@ -266,15 +264,15 @@ class AKSRT_Admin_Pay_Products {
/**
* Fallback: posts that already have paid resource orders.
*
- * @return array{posts: WP_Post[], total: int}
+ * @return array{posts: \WP_Post[], total: int}
*/
private function posts_from_order_summary(int $limit, int $offset): array {
- if (!class_exists('AKSRT_Order_Repository')) {
+ if (!class_exists('\AKSRT\Payment\OrderRepository')) {
return ['posts' => [], 'total' => 0];
}
- $summary = AKSRT_Order_Repository::get_instance()->get_content_sales_summary([
- 'product_type' => AKSRT_Domain_Model::ORDER_PRODUCT_RESOURCE,
+ $summary = \AKSRT\Payment\OrderRepository::get_instance()->get_content_sales_summary([
+ 'product_type' => \AKSRT\Core\DomainModel::ORDER_PRODUCT_RESOURCE,
'limit' => $limit,
'offset' => $offset,
'orderby' => 'sales_count',
@@ -285,7 +283,7 @@ class AKSRT_Admin_Pay_Products {
foreach ($summary['items'] as $item) {
$pid = (int) ($item['product_id'] ?? 0);
$post = $pid > 0 ? get_post($pid) : null;
- if ($post instanceof WP_Post && $post->post_type === 'post') {
+ if ($post instanceof \WP_Post && $post->post_type === 'post') {
$posts[] = $post;
}
}
diff --git a/inc/classes/admin/native/class-aksrt-admin-pay-rebate.php b/src/AKSRT/Admin/Native/PayRebate.php
similarity index 95%
rename from inc/classes/admin/native/class-aksrt-admin-pay-rebate.php
rename to src/AKSRT/Admin/Native/PayRebate.php
index ce5426f6..1e28d42d 100644
--- a/inc/classes/admin/native/class-aksrt-admin-pay-rebate.php
+++ b/src/AKSRT/Admin/Native/PayRebate.php
@@ -1,15 +1,13 @@
ensure_cap();
$this->render_header(__('推广返佣', 'aksrt'));
- if (!class_exists('AKSRT_Rebate')) {
+ if (!class_exists('\AKSRT\Payment\Rebate')) {
echo '
' . esc_html__('返佣模块未初始化。', 'aksrt') . '
';
$this->render_footer();
return;
@@ -45,7 +43,7 @@ class AKSRT_Admin_Pay_Rebate {
$user_id = isset($_GET['user_id']) ? max(0, (int) $_GET['user_id']) : (isset($_GET['referrer_id']) ? max(0, (int) $_GET['referrer_id']) : 0);
$page_num = max(1, (int) ($_GET['paged'] ?? 1));
$per_page = 20;
- $svc = AKSRT_Rebate::get_instance();
+ $svc = \AKSRT\Payment\Rebate::get_instance();
$stats = $svc->get_stats();
echo '
' . esc_html(sprintf(
@@ -131,7 +129,7 @@ class AKSRT_Admin_Pay_Rebate {
}
$id = isset($_POST['rebate_id']) ? (int) $_POST['rebate_id'] : 0;
check_admin_referer('aksrt_pay_settle_rebate_' . $id);
- $ok = $id > 0 && class_exists('AKSRT_Rebate') && AKSRT_Rebate::get_instance()->settle($id);
+ $ok = $id > 0 && class_exists('\AKSRT\Payment\Rebate') && \AKSRT\Payment\Rebate::get_instance()->settle($id);
wp_safe_redirect($this->page_url('aksrt_rebate', ['aksrt_pay_msg' => $ok ? 'rebate_settled' : 'rebate_failed']));
exit;
}
@@ -142,7 +140,7 @@ class AKSRT_Admin_Pay_Rebate {
}
$id = isset($_POST['rebate_id']) ? (int) $_POST['rebate_id'] : 0;
check_admin_referer('aksrt_pay_cancel_rebate_' . $id);
- $ok = $id > 0 && class_exists('AKSRT_Rebate') && AKSRT_Rebate::get_instance()->cancel($id);
+ $ok = $id > 0 && class_exists('\AKSRT\Payment\Rebate') && \AKSRT\Payment\Rebate::get_instance()->cancel($id);
wp_safe_redirect($this->page_url('aksrt_rebate', ['aksrt_pay_msg' => $ok ? 'rebate_cancelled' : 'rebate_failed']));
exit;
}
diff --git a/inc/classes/admin/native/class-aksrt-admin-pay-shipping.php b/src/AKSRT/Admin/Native/PayShipping.php
similarity index 92%
rename from inc/classes/admin/native/class-aksrt-admin-pay-shipping.php
rename to src/AKSRT/Admin/Native/PayShipping.php
index 405e4649..caebf180 100644
--- a/inc/classes/admin/native/class-aksrt-admin-pay-shipping.php
+++ b/src/AKSRT/Admin/Native/PayShipping.php
@@ -1,15 +1,13 @@
ensure_cap();
$this->render_header(__('发货及物流', 'aksrt'));
- if (!class_exists('AKSRT_Shipping')) {
+ if (!class_exists('\AKSRT\Payment\Shipping')) {
echo '
' . esc_html__('物流模块未初始化。', 'aksrt') . '
';
$this->render_footer();
return;
@@ -50,13 +48,13 @@ class AKSRT_Admin_Pay_Shipping {
$search = isset($_GET['s']) ? sanitize_text_field((string) wp_unslash($_GET['s'])) : '';
$page_num = max(1, (int) ($_GET['paged'] ?? 1));
$per_page = 20;
- $svc = AKSRT_Shipping::get_instance();
+ $svc = \AKSRT\Payment\Shipping::get_instance();
$stats = $svc->get_stats();
$status_options = $this->shipping_status_options(true);
$pending_total = 0;
- if (class_exists('AKSRT_Order_Repository')) {
- $pending_total = (int) (AKSRT_Order_Repository::get_instance()->get_pending_shipment_orders(['limit' => 1, 'search' => ''])['total'] ?? 0);
+ if (class_exists('\AKSRT\Payment\OrderRepository')) {
+ $pending_total = (int) (\AKSRT\Payment\OrderRepository::get_instance()->get_pending_shipment_orders(['limit' => 1, 'search' => ''])['total'] ?? 0);
}
echo '
' . esc_html(sprintf(
@@ -183,7 +181,7 @@ class AKSRT_Admin_Pay_Shipping {
}
private function render_pending_shipment_board(string $search, int $page_num, int $per_page): void {
- if (!class_exists('AKSRT_Order_Repository')) {
+ if (!class_exists('\AKSRT\Payment\OrderRepository')) {
echo '
' . esc_html__('订单服务不可用。', 'aksrt') . '
';
return;
}
@@ -195,7 +193,7 @@ class AKSRT_Admin_Pay_Shipping {
submit_button(__('筛选', 'aksrt'), 'secondary', '', false);
echo '';
- $result = AKSRT_Order_Repository::get_instance()->get_pending_shipment_orders([
+ $result = \AKSRT\Payment\OrderRepository::get_instance()->get_pending_shipment_orders([
'search' => $search,
'limit' => $per_page,
'offset' => ($page_num - 1) * $per_page,
@@ -203,8 +201,8 @@ class AKSRT_Admin_Pay_Shipping {
$items = $result['items'] ?? [];
$total = (int) ($result['total'] ?? 0);
$pages = max(1, (int) ($result['max_pages'] ?? 1));
- $labels = class_exists('AKSRT_Domain_Model')
- ? AKSRT_Domain_Model::order_status_labels()
+ $labels = class_exists('\AKSRT\Core\DomainModel')
+ ? \AKSRT\Core\DomainModel::order_status_labels()
: [];
echo '
';
@@ -261,8 +259,8 @@ class AKSRT_Admin_Pay_Shipping {
check_admin_referer('aksrt_pay_update_shipping_' . $id);
$ok = false;
- if ($id > 0 && $new_status !== '' && class_exists('AKSRT_Shipping')) {
- $ok = AKSRT_Shipping::get_instance()->update_status($id, $new_status, $note, get_current_user_id());
+ if ($id > 0 && $new_status !== '' && class_exists('\AKSRT\Payment\Shipping')) {
+ $ok = \AKSRT\Payment\Shipping::get_instance()->update_status($id, $new_status, $note, get_current_user_id());
}
$redirect_order = isset($_POST['redirect_order']) ? sanitize_text_field((string) wp_unslash($_POST['redirect_order'])) : '';
@@ -291,8 +289,8 @@ class AKSRT_Admin_Pay_Shipping {
$ok = false;
$order_number = '';
- if ($id > 0 && class_exists('AKSRT_Shipping')) {
- $svc = AKSRT_Shipping::get_instance();
+ if ($id > 0 && class_exists('\AKSRT\Payment\Shipping')) {
+ $svc = \AKSRT\Payment\Shipping::get_instance();
$record = $svc->get($id);
$order_number = is_array($record) ? (string) ($record['order_number'] ?? '') : '';
$result = $svc->query_express($id, $force);
@@ -318,14 +316,14 @@ class AKSRT_Admin_Pay_Shipping {
check_admin_referer($nonce_action);
$ok = false;
- if ($order_number !== '' && class_exists('AKSRT_Shipping')) {
- if (class_exists('AKSRT_Order_Repository')) {
- $order = AKSRT_Order_Repository::get_instance()->get($order_number);
+ if ($order_number !== '' && class_exists('\AKSRT\Payment\Shipping')) {
+ if (class_exists('\AKSRT\Payment\OrderRepository')) {
+ $order = \AKSRT\Payment\OrderRepository::get_instance()->get($order_number);
if (!$order) {
$this->redirect_shipping_create_result(false, $order_number, $redirect_page);
}
}
- $id = AKSRT_Shipping::get_instance()->create([
+ $id = \AKSRT\Payment\Shipping::get_instance()->create([
'order_number' => $order_number,
'carrier' => sanitize_text_field((string) wp_unslash($_POST['carrier'] ?? '')),
'tracking_no' => sanitize_text_field((string) wp_unslash($_POST['tracking_no'] ?? '')),
@@ -372,8 +370,8 @@ class AKSRT_Admin_Pay_Shipping {
if ($include_all) {
$options[''] = __('全部状态', 'aksrt');
}
- if (class_exists('AKSRT_Shipping')) {
- foreach (AKSRT_Shipping::get_status_options() as $item) {
+ if (class_exists('\AKSRT\Payment\Shipping')) {
+ foreach (\AKSRT\Payment\Shipping::get_status_options() as $item) {
$value = (string) ($item['value'] ?? '');
if ($value === '') {
continue;
@@ -397,8 +395,8 @@ class AKSRT_Admin_Pay_Shipping {
private function render_carrier_field(string $selected = ''): void {
$options = [];
- if (class_exists('AKSRT_Shipping')) {
- foreach (AKSRT_Shipping::get_carrier_options() as $item) {
+ if (class_exists('\AKSRT\Payment\Shipping')) {
+ foreach (\AKSRT\Payment\Shipping::get_carrier_options() as $item) {
$value = (string) ($item['value'] ?? '');
$label = (string) ($item['label'] ?? $value);
if ($value !== '') {
@@ -422,11 +420,11 @@ class AKSRT_Admin_Pay_Shipping {
echo '';
}
private function render_express_timeline_panel(int $shipping_id): void {
- if ($shipping_id <= 0 || !class_exists('AKSRT_Shipping')) {
+ if ($shipping_id <= 0 || !class_exists('\AKSRT\Payment\Shipping')) {
echo '' . esc_html__('无法加载物流轨迹。', 'aksrt') . '
';
return;
}
- $svc = AKSRT_Shipping::get_instance();
+ $svc = \AKSRT\Payment\Shipping::get_instance();
// Prefer cached data; do not force remote query on pure view.
$timeline = $svc->build_express_timeline($shipping_id);
$record = $svc->get($shipping_id);
diff --git a/inc/classes/admin/native/class-aksrt-admin-pay-withdrawals.php b/src/AKSRT/Admin/Native/PayWithdrawals.php
similarity index 95%
rename from inc/classes/admin/native/class-aksrt-admin-pay-withdrawals.php
rename to src/AKSRT/Admin/Native/PayWithdrawals.php
index 08197e28..f18e4e9e 100644
--- a/inc/classes/admin/native/class-aksrt-admin-pay-withdrawals.php
+++ b/src/AKSRT/Admin/Native/PayWithdrawals.php
@@ -1,15 +1,13 @@
ensure_cap();
$this->render_header(__('提现审核', 'aksrt'));
- if (!class_exists('AKSRT_Withdrawal')) {
+ if (!class_exists('\AKSRT\Payment\Withdrawal')) {
echo '' . esc_html__('提现模块未初始化。', 'aksrt') . '
';
$this->render_footer();
return;
@@ -43,7 +41,7 @@ class AKSRT_Admin_Pay_Withdrawals {
$status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : '';
$page_num = max(1, (int) ($_GET['paged'] ?? 1));
$per_page = 20;
- $svc = AKSRT_Withdrawal::get_instance();
+ $svc = \AKSRT\Payment\Withdrawal::get_instance();
$stats = $svc->get_stats();
echo '' . esc_html(sprintf(
@@ -184,8 +182,8 @@ class AKSRT_Admin_Pay_Withdrawals {
check_admin_referer('aksrt_pay_update_withdrawal_' . $id);
$msg = 'withdraw_failed';
- if ($id > 0 && $new_status !== '' && class_exists('AKSRT_Withdrawal')) {
- $result = AKSRT_Withdrawal::get_instance()->process_status_change($id, $new_status, $note);
+ if ($id > 0 && $new_status !== '' && class_exists('\AKSRT\Payment\Withdrawal')) {
+ $result = \AKSRT\Payment\Withdrawal::get_instance()->process_status_change($id, $new_status, $note);
if (!is_wp_error($result) && $result) {
$msg = 'withdraw_updated';
} elseif (is_wp_error($result) && $result->get_error_code() === 'aksrt_balance') {
diff --git a/inc/classes/admin/native/class-aksrt-admin-users-menus.php b/src/AKSRT/Admin/Native/UsersMenus.php
similarity index 96%
rename from inc/classes/admin/native/class-aksrt-admin-users-menus.php
rename to src/AKSRT/Admin/Native/UsersMenus.php
index 5d7150c1..7a579e85 100644
--- a/inc/classes/admin/native/class-aksrt-admin-users-menus.php
+++ b/src/AKSRT/Admin/Native/UsersMenus.php
@@ -1,13 +1,13 @@
get_pending_count();
+ if ($page !== 'aksrt_user_ban' && class_exists('\AKSRT\Messages\ReportCenter')) {
+ $pending_reports = (int) \AKSRT\Messages\ReportCenter::get_instance()->get_pending_count();
if ($pending_reports > 0) {
$url = admin_url('users.php?page=aksrt_user_ban&tab=reports&status=pending');
echo '
' . esc_html__('举报待处理', 'aksrt') . '
';
@@ -170,7 +170,7 @@ class AKSRT_Admin_Users_Menus {
$page_num = max(1, (int) ($_GET['paged'] ?? 1));
$per_page = 30;
$offset = ($page_num - 1) * $per_page;
- $table = class_exists('AKSRT_DB_Migrator') ? AKSRT_DB_Migrator::table('notification') : '';
+ $table = class_exists('\AKSRT\Core\DBMigrator') ? \AKSRT\Core\DBMigrator::table('notification') : '';
if ($table === '') {
echo '
' . esc_html__('通知表不可用。', 'aksrt') . '
';
@@ -224,8 +224,8 @@ class AKSRT_Admin_Users_Menus {
}
$ok = false;
- if ($content !== '' && class_exists('AKSRT_Message')) {
- $ok = AKSRT_Message::get_instance()->send($user_id, 'system', $content, ['title' => $title !== '' ? $title : $content]);
+ if ($content !== '' && class_exists('\AKSRT\Messages\Message')) {
+ $ok = \AKSRT\Messages\Message::get_instance()->send($user_id, 'system', $content, ['title' => $title !== '' ? $title : $content]);
}
$this->redirect('aksrt_messages', $ok ? 'message_sent' : 'message_failed');
}
@@ -315,7 +315,7 @@ class AKSRT_Admin_Users_Menus {
if (!$rows) {
echo '
| ' . esc_html__('暂无用户邀请码', 'aksrt') . ' |
';
}
- $invite_table = class_exists('AKSRT_DB_Migrator') ? AKSRT_DB_Migrator::table('invite') : '';
+ $invite_table = class_exists('\AKSRT\Core\DBMigrator') ? \AKSRT\Core\DBMigrator::table('invite') : '';
foreach ((array) $rows as $row) {
$user_id = (int) ($row['user_id'] ?? 0);
$user = $user_id > 0 ? get_userdata($user_id) : null;
@@ -589,12 +589,12 @@ class AKSRT_Admin_Users_Menus {
}
private function render_reports_tab(): void {
- if (!class_exists('AKSRT_Report_Center')) {
+ if (!class_exists('\AKSRT\Messages\ReportCenter')) {
echo '' . esc_html__('举报中心未初始化。', 'aksrt') . '
';
return;
}
$status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : 'pending';
- $svc = AKSRT_Report_Center::get_instance();
+ $svc = \AKSRT\Messages\ReportCenter::get_instance();
$counts = $svc->get_status_counts();
echo '' . esc_html(sprintf(
@@ -650,11 +650,11 @@ class AKSRT_Admin_Users_Menus {
}
private function render_restrictions_tab(): void {
- if (!class_exists('AKSRT_User_Restriction')) {
+ if (!class_exists('\AKSRT\User\Restriction')) {
echo '
' . esc_html__('限制模块未初始化。', 'aksrt') . '
';
return;
}
- $svc = AKSRT_User_Restriction::get_instance();
+ $svc = \AKSRT\User\Restriction::get_instance();
$stats = $svc->get_stats();
echo '' . esc_html(sprintf(
/* translators: 1 total 2 active 3 banned */
@@ -684,7 +684,7 @@ class AKSRT_Admin_Users_Menus {
echo '';
global $wpdb;
- $table = class_exists('AKSRT_DB_Migrator') ? AKSRT_DB_Migrator::table('user_restriction') : '';
+ $table = class_exists('\AKSRT\Core\DBMigrator') ? \AKSRT\Core\DBMigrator::table('user_restriction') : '';
if ($table === '') {
echo '
' . esc_html__('限制表不可用。', 'aksrt') . '
';
return;
@@ -725,7 +725,7 @@ class AKSRT_Admin_Users_Menus {
$new_status = isset($_POST['new_status']) ? sanitize_key((string) wp_unslash($_POST['new_status'])) : '';
$note = isset($_POST['note']) ? sanitize_textarea_field((string) wp_unslash($_POST['note'])) : '';
check_admin_referer('aksrt_users_update_report_' . $id);
- $ok = $id > 0 && class_exists('AKSRT_Report_Center') && AKSRT_Report_Center::get_instance()->update_status($id, $new_status, $note);
+ $ok = $id > 0 && class_exists('\AKSRT\Messages\ReportCenter') && \AKSRT\Messages\ReportCenter::get_instance()->update_status($id, $new_status, $note);
$this->redirect('aksrt_user_ban', $ok ? 'report_updated' : 'report_failed', ['tab' => 'reports']);
}
@@ -739,8 +739,8 @@ class AKSRT_Admin_Users_Menus {
$scope = isset($_POST['scope']) ? sanitize_key((string) wp_unslash($_POST['scope'])) : 'global';
$reason = isset($_POST['reason']) ? sanitize_text_field((string) wp_unslash($_POST['reason'])) : '';
$ok = false;
- if ($user_id > 0 && $reason !== '' && class_exists('AKSRT_User_Restriction')) {
- $result = AKSRT_User_Restriction::get_instance()->restrict($user_id, $type, $reason, $scope, '', get_current_user_id());
+ if ($user_id > 0 && $reason !== '' && class_exists('\AKSRT\User\Restriction')) {
+ $result = \AKSRT\User\Restriction::get_instance()->restrict($user_id, $type, $reason, $scope, '', get_current_user_id());
$ok = !empty($result['id']) || !empty($result['success']) || is_array($result);
}
$this->redirect('aksrt_user_ban', $ok ? 'restriction_added' : 'restriction_failed', ['tab' => 'restrictions']);
@@ -752,7 +752,7 @@ class AKSRT_Admin_Users_Menus {
}
$id = isset($_POST['restriction_id']) ? (int) $_POST['restriction_id'] : 0;
check_admin_referer('aksrt_users_remove_restriction_' . $id);
- $ok = $id > 0 && class_exists('AKSRT_User_Restriction') && AKSRT_User_Restriction::get_instance()->remove_restriction($id);
+ $ok = $id > 0 && class_exists('\AKSRT\User\Restriction') && \AKSRT\User\Restriction::get_instance()->remove_restriction($id);
$this->redirect('aksrt_user_ban', $ok ? 'restriction_removed' : 'restriction_failed', ['tab' => 'restrictions']);
}
diff --git a/inc/classes/admin/class-aksrt-admin-page-display-controller.php b/src/AKSRT/Admin/PageDisplayController.php
similarity index 92%
rename from inc/classes/admin/class-aksrt-admin-page-display-controller.php
rename to src/AKSRT/Admin/PageDisplayController.php
index cc9a623e..e1773b83 100644
--- a/inc/classes/admin/class-aksrt-admin-page-display-controller.php
+++ b/src/AKSRT/Admin/PageDisplayController.php
@@ -1,16 +1,13 @@
admin = $admin;
}
@@ -70,7 +67,7 @@ class AKSRT_Admin_Page_Display_Controller extends AKSRT_Admin_Controller_Base {
];
}
- public function rest_get_banners(WP_REST_Request $request): WP_REST_Response {
+ public function rest_get_banners(\WP_REST_Request $request): \WP_REST_Response {
$kind = $this->normalize_banner_kind($request->get_param('kind') ?: 'hero');
$args = [
'post_type' => 'aksrt_banner',
@@ -109,7 +106,7 @@ class AKSRT_Admin_Page_Display_Controller extends AKSRT_Admin_Controller_Base {
return rest_ensure_response(['code' => 'success', 'data' => $banners]);
}
- public function rest_create_banner(WP_REST_Request $request): WP_REST_Response {
+ public function rest_create_banner(\WP_REST_Request $request): \WP_REST_Response {
$params = $this->get_json_params($request);
$kind = $this->normalize_banner_kind($params['kind'] ?? 'hero');
$title = sanitize_text_field($params['title'] ?? '');
@@ -122,7 +119,7 @@ class AKSRT_Admin_Page_Display_Controller extends AKSRT_Admin_Controller_Base {
]);
if (is_wp_error($post_id)) {
- return new WP_REST_Response(['code' => 'error', 'message' => $post_id->get_error_message()], 400);
+ return new \WP_REST_Response(['code' => 'error', 'message' => $post_id->get_error_message()], 400);
}
update_post_meta($post_id, '_image_url', esc_url_raw($params['image_url'] ?? ''));
@@ -147,10 +144,10 @@ class AKSRT_Admin_Page_Display_Controller extends AKSRT_Admin_Controller_Base {
return rest_ensure_response(['code' => 'success', 'data' => ['id' => $post_id], 'message' => __('幻灯片已创建', 'aksrt')]);
}
- public function rest_handle_banner_item(WP_REST_Request $request): WP_REST_Response {
+ public function rest_handle_banner_item(\WP_REST_Request $request): \WP_REST_Response {
$id = absint($request['id']);
if (!$id || get_post_type($id) !== 'aksrt_banner') {
- return new WP_REST_Response(['code' => 'not_found', 'message' => __('幻灯片不存在', 'aksrt')], 404);
+ return new \WP_REST_Response(['code' => 'not_found', 'message' => __('幻灯片不存在', 'aksrt')], 404);
}
if ($request->get_method() === 'DELETE') {
@@ -200,4 +197,3 @@ class AKSRT_Admin_Page_Display_Controller extends AKSRT_Admin_Controller_Base {
return rest_ensure_response(['code' => 'success', 'message' => __('幻灯片已更新', 'aksrt')]);
}
}
-
diff --git a/inc/classes/admin/class-aksrt-admin-payment-controller.php b/src/AKSRT/Admin/PaymentController.php
similarity index 87%
rename from inc/classes/admin/class-aksrt-admin-payment-controller.php
rename to src/AKSRT/Admin/PaymentController.php
index b8d1627d..4bd6decc 100644
--- a/inc/classes/admin/class-aksrt-admin-payment-controller.php
+++ b/src/AKSRT/Admin/PaymentController.php
@@ -1,15 +1,13 @@
error('设置模块未初始化', 500);
}
- $paid = AKSRT_Settings::get_paid_content_settings();
- $recharge = AKSRT_Settings::get_payment_recharge_settings();
- $vip = AKSRT_Settings::get_payment_vip_settings();
- $revenue = AKSRT_Settings::get_payment_revenue_settings();
- $affiliate = AKSRT_Settings::get_payment_affiliate_settings();
- $gateway = AKSRT_Settings::get_payment_gateway_settings();
+ $paid = \AKSRT\Settings\Settings::get_paid_content_settings();
+ $recharge = \AKSRT\Settings\Settings::get_payment_recharge_settings();
+ $vip = \AKSRT\Settings\Settings::get_payment_vip_settings();
+ $revenue = \AKSRT\Settings\Settings::get_payment_revenue_settings();
+ $affiliate = \AKSRT\Settings\Settings::get_payment_affiliate_settings();
+ $gateway = \AKSRT\Settings\Settings::get_payment_gateway_settings();
return $this->success([
'data' => [
@@ -138,7 +136,7 @@ class AKSRT_Admin_Payment_Controller extends AKSRT_Admin_Controller_Base {
'revenue' => $revenue,
'affiliate' => $affiliate,
'gateway' => $gateway,
- 'currency_name' => AKSRT_Settings::get_currency_name(),
+ 'currency_name' => \AKSRT\Settings\Settings::get_currency_name(),
],
]);
}
@@ -146,15 +144,15 @@ class AKSRT_Admin_Payment_Controller extends AKSRT_Admin_Controller_Base {
/**
* GET /payment/revenue — revenue stats with optional time-series
*/
- public function get_revenue(WP_REST_Request $request): WP_REST_Response {
+ public function get_revenue(\WP_REST_Request $request): \WP_REST_Response {
$revenue_stats = ['total' => 0, 'pending' => 0, 'settled' => 0, 'count' => 0];
- if (class_exists('AKSRT_Revenue')) {
- $revenue_stats = AKSRT_Revenue::get_instance()->get_stats();
+ if (class_exists('\AKSRT\Payment\Revenue')) {
+ $revenue_stats = \AKSRT\Payment\Revenue::get_instance()->get_stats();
}
$withdrawal_stats = ['total' => 0, 'pending' => 0, 'completed' => 0, 'total_paid' => 0];
- if (class_exists('AKSRT_Withdrawal')) {
- $withdrawal_stats = AKSRT_Withdrawal::get_instance()->get_stats();
+ if (class_exists('\AKSRT\Payment\Withdrawal')) {
+ $withdrawal_stats = \AKSRT\Payment\Withdrawal::get_instance()->get_stats();
}
$response = [
@@ -173,7 +171,7 @@ class AKSRT_Admin_Payment_Controller extends AKSRT_Admin_Controller_Base {
/**
* Build revenue time-series data.
*/
- private function get_revenue_time_series(WP_REST_Request $request): array {
+ private function get_revenue_time_series(\WP_REST_Request $request): array {
global $wpdb;
$prefix = $wpdb->prefix;
@@ -228,8 +226,8 @@ class AKSRT_Admin_Payment_Controller extends AKSRT_Admin_Controller_Base {
/**
* GET /payment/withdrawals — 提现列表,统一 page + per_page 分页
*/
- public function get_withdrawals(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Withdrawal')) {
+ public function get_withdrawals(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Payment\Withdrawal')) {
return $this->success(['data' => ['items' => [], 'total' => 0, 'page' => 1, 'total_pages' => 1, 'stats' => []]]);
}
@@ -237,14 +235,14 @@ class AKSRT_Admin_Payment_Controller extends AKSRT_Admin_Controller_Base {
$page = max(1, (int) $request->get_param('page'));
$per_page = max(1, min(50, (int) $request->get_param('per_page'))) ?: 20;
- $items = AKSRT_Withdrawal::get_instance()->get_all([
+ $items = \AKSRT\Payment\Withdrawal::get_instance()->get_all([
'status' => $status,
'limit' => $per_page,
'offset' => ($page - 1) * $per_page,
]);
- $total = AKSRT_Withdrawal::get_instance()->get_count(['status' => $status]);
- $stats = AKSRT_Withdrawal::get_instance()->get_stats();
+ $total = \AKSRT\Payment\Withdrawal::get_instance()->get_count(['status' => $status]);
+ $stats = \AKSRT\Payment\Withdrawal::get_instance()->get_stats();
return $this->success([
'data' => [
@@ -260,8 +258,8 @@ class AKSRT_Admin_Payment_Controller extends AKSRT_Admin_Controller_Base {
/**
* POST /payment/withdrawals/{id} — 更新提现状态
*/
- public function update_withdrawal_status(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Withdrawal')) {
+ public function update_withdrawal_status(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Payment\Withdrawal')) {
return $this->error('提现模块未初始化', 500);
}
@@ -279,7 +277,7 @@ class AKSRT_Admin_Payment_Controller extends AKSRT_Admin_Controller_Base {
return $this->error('无效的提现 ID');
}
- $success = AKSRT_Withdrawal::get_instance()->update_status($id, $new_status, $note);
+ $success = \AKSRT\Payment\Withdrawal::get_instance()->update_status($id, $new_status, $note);
if ($success) {
return $this->success(['message' => __('提现状态已更新', 'aksrt')]);
@@ -294,14 +292,14 @@ class AKSRT_Admin_Payment_Controller extends AKSRT_Admin_Controller_Base {
/**
* GET /payment/charge-cards — 充值卡列表
*/
- public function get_charge_cards(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Charge_Card')) {
+ public function get_charge_cards(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Payment\ChargeCard')) {
return $this->success(['data' => ['items' => [], 'total' => 0, 'page' => 1, 'max_pages' => 1]]);
}
global $wpdb;
- $table = AKSRT_DB_Migrator::table('charge_card');
+ $table = \AKSRT\Core\DBMigrator::table('charge_card');
$page = max(1, (int) ($request->get_param('page') ?: 1));
$per_page = max(1, min(100, (int) ($request->get_param('per_page') ?: 20)));
$status = sanitize_key((string) $request->get_param('status'));
@@ -348,7 +346,7 @@ class AKSRT_Admin_Payment_Controller extends AKSRT_Admin_Controller_Base {
$total = count($items);
$offset = ($page - 1) * $per_page;
- $stats = AKSRT_Charge_Card::get_instance()->get_stats();
+ $stats = \AKSRT\Payment\ChargeCard::get_instance()->get_stats();
return $this->success([
'data' => [
@@ -374,8 +372,8 @@ class AKSRT_Admin_Payment_Controller extends AKSRT_Admin_Controller_Base {
/**
* POST /payment/charge-cards — 创建充值卡
*/
- public function create_charge_card(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Charge_Card')) {
+ public function create_charge_card(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Payment\ChargeCard')) {
return $this->error('充值卡系统未启用', 500);
}
@@ -389,7 +387,7 @@ class AKSRT_Admin_Payment_Controller extends AKSRT_Admin_Controller_Base {
return $this->error('卡密不能为空');
}
- $id = AKSRT_Charge_Card::get_instance()->create(array_merge($params, [
+ $id = \AKSRT\Payment\ChargeCard::get_instance()->create(array_merge($params, [
'type' => $type,
'password' => $password,
]));
@@ -407,8 +405,8 @@ class AKSRT_Admin_Payment_Controller extends AKSRT_Admin_Controller_Base {
/**
* POST /payment/charge-cards/batch — 批量生成充值卡
*/
- public function batch_create_charge_cards(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Charge_Card')) {
+ public function batch_create_charge_cards(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Payment\ChargeCard')) {
return $this->error('充值卡系统未启用', 500);
}
@@ -437,7 +435,7 @@ class AKSRT_Admin_Payment_Controller extends AKSRT_Admin_Controller_Base {
return $this->error('积分卡积分必须大于 0');
}
- $codes = AKSRT_Charge_Card::get_instance()->batch_create(
+ $codes = \AKSRT\Payment\ChargeCard::get_instance()->batch_create(
$type,
$meta_fields,
$count,
@@ -456,8 +454,8 @@ class AKSRT_Admin_Payment_Controller extends AKSRT_Admin_Controller_Base {
/**
* POST /payment/charge-cards/{id}/disable — 禁用充值卡
*/
- public function disable_charge_card(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Charge_Card')) {
+ public function disable_charge_card(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Payment\ChargeCard')) {
return $this->error('充值卡系统未启用', 500);
}
@@ -466,7 +464,7 @@ class AKSRT_Admin_Payment_Controller extends AKSRT_Admin_Controller_Base {
return $this->error('参数无效');
}
- $success = AKSRT_Charge_Card::get_instance()->disable($id);
+ $success = \AKSRT\Payment\ChargeCard::get_instance()->disable($id);
if ($success) {
return $this->success(['message' => __('充值卡已禁用', 'aksrt')]);
@@ -474,11 +472,11 @@ class AKSRT_Admin_Payment_Controller extends AKSRT_Admin_Controller_Base {
return $this->error(__('操作失败', 'aksrt'));
}
- public function get_charge_card_detail(WP_REST_Request $request): WP_REST_Response {
+ public function get_charge_card_detail(\WP_REST_Request $request): \WP_REST_Response {
global $wpdb;
$id = (int) $request->get_param('id');
- $table = AKSRT_DB_Migrator::table('charge_card');
+ $table = \AKSRT\Core\DBMigrator::table('charge_card');
if ($id <= 0 || !$table) {
return $this->error(__('充值卡不存在', 'aksrt'), 404);
@@ -503,14 +501,14 @@ class AKSRT_Admin_Payment_Controller extends AKSRT_Admin_Controller_Base {
/**
* GET /payment/rebate/log — 返佣记录列表
*/
- public function get_rebate_list(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Rebate')) {
+ public function get_rebate_list(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Payment\Rebate')) {
return $this->success(['data' => ['items' => [], 'total' => 0, 'page' => 1, 'max_pages' => 1]]);
}
global $wpdb;
- $table = AKSRT_DB_Migrator::table('rebate_log');
+ $table = \AKSRT\Core\DBMigrator::table('rebate_log');
$page = max(1, (int) ($request->get_param('page') ?: 1));
$per_page = max(1, min(100, (int) ($request->get_param('per_page') ?: 20)));
$status = sanitize_key((string) $request->get_param('status'));
@@ -564,7 +562,7 @@ class AKSRT_Admin_Payment_Controller extends AKSRT_Admin_Controller_Base {
$total = count($items);
$offset = ($page - 1) * $per_page;
- $stats = AKSRT_Rebate::get_instance()->get_stats();
+ $stats = \AKSRT\Payment\Rebate::get_instance()->get_stats();
return $this->success([
'data' => [
@@ -594,8 +592,8 @@ class AKSRT_Admin_Payment_Controller extends AKSRT_Admin_Controller_Base {
/**
* POST /payment/rebate/{id}/settle — 结算返佣
*/
- public function settle_rebate(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Rebate')) {
+ public function settle_rebate(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Payment\Rebate')) {
return $this->error('返佣系统未启用', 500);
}
@@ -606,7 +604,7 @@ class AKSRT_Admin_Payment_Controller extends AKSRT_Admin_Controller_Base {
return $this->error('参数无效');
}
- $success = AKSRT_Rebate::get_instance()->settle($id);
+ $success = \AKSRT\Payment\Rebate::get_instance()->settle($id);
if ($success) {
$this->append_rebate_process_log($id, 'settled', $note);
@@ -618,8 +616,8 @@ class AKSRT_Admin_Payment_Controller extends AKSRT_Admin_Controller_Base {
/**
* POST /payment/rebate/{id}/cancel — 取消返佣
*/
- public function cancel_rebate(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Rebate')) {
+ public function cancel_rebate(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Payment\Rebate')) {
return $this->error('返佣系统未启用', 500);
}
@@ -630,7 +628,7 @@ class AKSRT_Admin_Payment_Controller extends AKSRT_Admin_Controller_Base {
return $this->error('参数无效');
}
- $success = AKSRT_Rebate::get_instance()->cancel($id);
+ $success = \AKSRT\Payment\Rebate::get_instance()->cancel($id);
if ($success) {
$this->append_rebate_process_log($id, 'cancelled', $note);
@@ -639,11 +637,11 @@ class AKSRT_Admin_Payment_Controller extends AKSRT_Admin_Controller_Base {
return $this->error(__('操作失败', 'aksrt'));
}
- public function get_rebate_detail(WP_REST_Request $request): WP_REST_Response {
+ public function get_rebate_detail(\WP_REST_Request $request): \WP_REST_Response {
global $wpdb;
$id = (int) $request->get_param('id');
- $table = AKSRT_DB_Migrator::table('rebate_log');
+ $table = \AKSRT\Core\DBMigrator::table('rebate_log');
if ($id <= 0 || !$table) {
return $this->error(__('返佣记录不存在', 'aksrt'), 404);
@@ -715,7 +713,7 @@ class AKSRT_Admin_Payment_Controller extends AKSRT_Admin_Controller_Base {
'expires_at' => (string) ($row['expires_at'] ?? ''),
'created_at' => (string) ($row['created_at'] ?? ''),
'note' => (string) ($row['note'] ?? ''),
- 'used_by_user' => $user instanceof WP_User ? [
+ 'used_by_user' => $user instanceof \WP_User ? [
'id' => (int) $user->ID,
'display_name' => $user->display_name,
'email' => $user->user_email,
@@ -753,12 +751,12 @@ class AKSRT_Admin_Payment_Controller extends AKSRT_Admin_Controller_Base {
'settled_at' => (string) ($row['settled_at'] ?? ''),
'note' => (string) ($row['note'] ?? ''),
'history_count' => count($this->get_rebate_process_log((int) ($row['id'] ?? 0))),
- 'user' => $user instanceof WP_User ? [
+ 'user' => $user instanceof \WP_User ? [
'id' => (int) $user->ID,
'display_name' => $user->display_name,
'email' => $user->user_email,
] : null,
- 'source_user' => $source_user instanceof WP_User ? [
+ 'source_user' => $source_user instanceof \WP_User ? [
'id' => (int) $source_user->ID,
'display_name' => $source_user->display_name,
'email' => $source_user->user_email,
diff --git a/inc/classes/admin/class-aksrt-admin-permissions-controller.php b/src/AKSRT/Admin/PermissionsController.php
similarity index 84%
rename from inc/classes/admin/class-aksrt-admin-permissions-controller.php
rename to src/AKSRT/Admin/PermissionsController.php
index 8c9cabf4..ace31228 100644
--- a/inc/classes/admin/class-aksrt-admin-permissions-controller.php
+++ b/src/AKSRT/Admin/PermissionsController.php
@@ -1,19 +1,13 @@
error(__('能力矩阵模块不可用', 'aksrt'), 500);
}
- $caps = AKSRT_Settings::get_user_capabilities();
- $defs = AKSRT_Settings::cap_definitions();
- $columns = AKSRT_Settings::cap_role_columns();
+ $caps = \AKSRT\Settings\Settings::get_user_capabilities();
+ $defs = \AKSRT\Settings\Settings::cap_definitions();
+ $columns = \AKSRT\Settings\Settings::cap_role_columns();
return $this->success([
'data' => [
@@ -59,8 +53,8 @@ class AKSRT_Admin_Permissions_Controller extends AKSRT_Admin_Controller_Base {
]);
}
- public function save_capabilities(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Settings')) {
+ public function save_capabilities(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Settings\Settings')) {
return $this->error(__('能力矩阵模块不可用', 'aksrt'), 500);
}
@@ -71,8 +65,8 @@ class AKSRT_Admin_Permissions_Controller extends AKSRT_Admin_Controller_Base {
return $this->error(__('无效的能力矩阵数据', 'aksrt'), 422);
}
- $defs = AKSRT_Settings::cap_definitions();
- $columns = AKSRT_Settings::cap_role_columns();
+ $defs = \AKSRT\Settings\Settings::cap_definitions();
+ $columns = \AKSRT\Settings\Settings::cap_role_columns();
$clean = [];
foreach ($defs as $cap_id => $def) {
@@ -90,10 +84,10 @@ class AKSRT_Admin_Permissions_Controller extends AKSRT_Admin_Controller_Base {
}
}
- $all = AKSRT_Settings::get_all();
+ $all = \AKSRT\Settings\Settings::get_all();
$all['user_caps'] = $clean;
update_option('aksrt_settings', $all);
- AKSRT_Settings::flush_settings_cache();
+ \AKSRT\Settings\Settings::flush_settings_cache();
return $this->success([
'message' => __('能力矩阵已保存', 'aksrt'),
diff --git a/inc/classes/admin/class-aksrt-admin-post-list-controller.php b/src/AKSRT/Admin/PostListController.php
similarity index 66%
rename from inc/classes/admin/class-aksrt-admin-post-list-controller.php
rename to src/AKSRT/Admin/PostListController.php
index c4da6b7d..46268cea 100644
--- a/inc/classes/admin/class-aksrt-admin-post-list-controller.php
+++ b/src/AKSRT/Admin/PostListController.php
@@ -1,15 +1,13 @@
'extensions',
+ 'title' => '扩展&增强',
+ 'sections' => [
+ 'ip' => SchemaExtensionsIP::build(),
+ 'audit' => SchemaExtensionsAudit::build(),
+ 'push' => SchemaExtensionsPush::build(),
+ 'security' => SchemaExtensionsSecurity::build(),
+ 'docs-mode' => SchemaExtensionsDocsMode::build(),
+ ],
+ ];
+ }
+}
diff --git a/inc/classes/admin/schema/class-aksrt-admin-schema-extensions-audit.php b/src/AKSRT/Admin/Schema/SchemaExtensionsAudit.php
similarity index 95%
rename from inc/classes/admin/schema/class-aksrt-admin-schema-extensions-audit.php
rename to src/AKSRT/Admin/Schema/SchemaExtensionsAudit.php
index 758cdde0..31792fb4 100644
--- a/inc/classes/admin/schema/class-aksrt-admin-schema-extensions-audit.php
+++ b/src/AKSRT/Admin/Schema/SchemaExtensionsAudit.php
@@ -1,13 +1,13 @@
'forum',
'title' => '社区&论坛',
'sections' => [
- 'basic' => AKSRT_Admin_Schema_Forum_Basic::build(),
- 'names' => AKSRT_Admin_Schema_Forum_Names::build(),
- 'homepage' => AKSRT_Admin_Schema_Forum_Homepage::build(),
- 'board_page' => AKSRT_Admin_Schema_Forum_Board_Page::build(),
- 'post_page' => AKSRT_Admin_Schema_Forum_Post_Page::build(),
- 'reply' => AKSRT_Admin_Schema_Forum_Reply::build(),
- 'permissions' => AKSRT_Admin_Schema_Forum_Permissions::build(),
- 'upload' => AKSRT_Admin_Schema_Forum_Upload::build(),
- 'credits' => AKSRT_Admin_Schema_Forum_Credits::build(),
- 'other' => AKSRT_Admin_Schema_Forum_Other::build(),
+ 'basic' => SchemaForumBasic::build(),
+ 'names' => SchemaForumNames::build(),
+ 'homepage' => SchemaForumHomepage::build(),
+ 'board_page' => SchemaForumBoardPage::build(),
+ 'post_page' => SchemaForumPostPage::build(),
+ 'reply' => SchemaForumReply::build(),
+ 'permissions' => SchemaForumPermissions::build(),
+ 'upload' => SchemaForumUpload::build(),
+ 'credits' => SchemaForumCredits::build(),
+ 'other' => SchemaForumOther::build(),
],
];
}
@@ -39,12 +39,12 @@ class AKSRT_Admin_Schema_Forum {
* Grouped by prefix: user_, new_post_, comment_.
*/
private static function build_cap_matrix_groups(): array {
- if (!class_exists('AKSRT_Settings')) {
+ if (!class_exists('\AKSRT\Settings\Settings')) {
return [];
}
- $defs = AKSRT_Settings::cap_definitions();
- $cols = AKSRT_Settings::cap_role_columns();
+ $defs = \AKSRT\Settings\Settings::cap_definitions();
+ $cols = \AKSRT\Settings\Settings::cap_role_columns();
$col_labels = [
'all' => __('所有人', 'aksrt'),
diff --git a/inc/classes/admin/schema/class-aksrt-admin-schema-forum-basic.php b/src/AKSRT/Admin/Schema/SchemaForumBasic.php
similarity index 90%
rename from inc/classes/admin/schema/class-aksrt-admin-schema-forum-basic.php
rename to src/AKSRT/Admin/Schema/SchemaForumBasic.php
index 44845fa8..8e554178 100644
--- a/inc/classes/admin/schema/class-aksrt-admin-schema-forum-basic.php
+++ b/src/AKSRT/Admin/Schema/SchemaForumBasic.php
@@ -1,13 +1,13 @@
'post_list',
'title' => '文章&列表',
'sections' => [
- 'list' => AKSRT_Admin_Schema_Post_List_List::build(),
+ 'list' => PostList\SchemaPostListList::build(),
'thumb' => [
'key' => 'thumb',
'title' => '列表缩略图',
diff --git a/src/AKSRT/Admin/Schema/SchemaShop.php b/src/AKSRT/Admin/Schema/SchemaShop.php
new file mode 100644
index 00000000..838d1577
--- /dev/null
+++ b/src/AKSRT/Admin/Schema/SchemaShop.php
@@ -0,0 +1,28 @@
+ 'shop',
+ 'title' => '商城&商品',
+ 'version' => '1.0.0',
+ 'sections' => [
+ 'basic' => SchemaShopBasic::build(),
+ 'list' => SchemaShopList::build(),
+ 'contact' => SchemaShopContact::build(),
+ 'single' => SchemaShopSingle::build(),
+ 'product-defaults' => SchemaShopProductDefaults::build(),
+ 'shipping-config' => SchemaShopShippingConfig::build(),
+ 'timing' => SchemaShopTiming::build(),
+ ],
+ ];
+ }
+}
diff --git a/inc/classes/admin/schema/class-aksrt-admin-schema-shop-basic.php b/src/AKSRT/Admin/Schema/SchemaShopBasic.php
similarity index 95%
rename from inc/classes/admin/schema/class-aksrt-admin-schema-shop-basic.php
rename to src/AKSRT/Admin/Schema/SchemaShopBasic.php
index 757800fa..91f2d1ed 100644
--- a/inc/classes/admin/schema/class-aksrt-admin-schema-shop-basic.php
+++ b/src/AKSRT/Admin/Schema/SchemaShopBasic.php
@@ -1,13 +1,13 @@
'tools',
+ 'title' => '工具&诊断',
+ 'sections' => [
+ 'import-export' => SchemaToolsImportExport::build(),
+ 'health' => SchemaToolsHealth::build(),
+ 'backup' => SchemaToolsBackup::build(),
+ 'email-rollback' => SchemaToolsEmailRollback::build(),
+ ],
+ ];
+ }
+}
diff --git a/inc/classes/admin/schema/class-aksrt-admin-schema-tools-backup.php b/src/AKSRT/Admin/Schema/SchemaToolsBackup.php
similarity index 92%
rename from inc/classes/admin/schema/class-aksrt-admin-schema-tools-backup.php
rename to src/AKSRT/Admin/Schema/SchemaToolsBackup.php
index cd07b7af..857311cd 100644
--- a/inc/classes/admin/schema/class-aksrt-admin-schema-tools-backup.php
+++ b/src/AKSRT/Admin/Schema/SchemaToolsBackup.php
@@ -1,13 +1,13 @@
section -> group -> field.
- *
* @package AKSRT
*/
+namespace AKSRT\Admin;
+
defined('ABSPATH') || exit;
-class AKSRT_Admin_Schema_Provider {
+class SchemaProvider {
private static $instance = null;
@@ -255,16 +252,16 @@ class AKSRT_Admin_Schema_Provider {
private function get_schema_builder_map(): array {
return [
- 'global' => 'AKSRT_Admin_Schema_Global',
- 'page_display' => 'AKSRT_Admin_Schema_Page_Display',
- 'post_list' => 'AKSRT_Admin_Schema_Post_List',
- 'permissions' => 'AKSRT_Admin_Schema_Permissions',
- 'users' => 'AKSRT_Admin_Schema_Users',
- 'payment' => 'AKSRT_Admin_Schema_Payment',
- 'extensions' => 'AKSRT_Admin_Schema_Extensions',
- 'tools' => 'AKSRT_Admin_Schema_Tools',
- 'shop' => 'AKSRT_Admin_Schema_Shop',
- 'forum' => 'AKSRT_Admin_Schema_Forum',
+ 'global' => 'Schema\GlobalSchema',
+ 'page_display' => 'Schema\SchemaPageDisplay',
+ 'post_list' => 'Schema\SchemaPostList',
+ 'permissions' => 'Schema\SchemaPermissions',
+ 'users' => 'Schema\SchemaUsers',
+ 'payment' => 'Schema\SchemaPayment',
+ 'extensions' => 'Schema\SchemaExtensions',
+ 'tools' => 'Schema\SchemaTools',
+ 'shop' => 'Schema\SchemaShop',
+ 'forum' => 'Schema\SchemaForum',
];
}
@@ -331,10 +328,10 @@ class AKSRT_Admin_Schema_Provider {
}
$updated = update_option($option_key, $stored);
- AKSRT_Settings::flush_settings_cache();
+ \AKSRT\Settings\Settings::flush_settings_cache();
if (isset($stored['site_favicon'])) {
- AKSRT_Settings::sync_native_site_icon((string) $stored['site_favicon']);
+ \AKSRT\Settings\Settings::sync_native_site_icon((string) $stored['site_favicon']);
}
return $updated || true;
diff --git a/inc/classes/admin/class-aksrt-admin-shop-controller.php b/src/AKSRT/Admin/ShopController.php
similarity index 96%
rename from inc/classes/admin/class-aksrt-admin-shop-controller.php
rename to src/AKSRT/Admin/ShopController.php
index 4ea2c1ce..864140c9 100644
--- a/inc/classes/admin/class-aksrt-admin-shop-controller.php
+++ b/src/AKSRT/Admin/ShopController.php
@@ -1,23 +1,20 @@
admin = $admin;
}
diff --git a/inc/classes/admin/class-aksrt-admin-shop-controller-coupon-gateway-operations.php b/src/AKSRT/Admin/ShopControllerCouponGatewayOperations.php
similarity index 71%
rename from inc/classes/admin/class-aksrt-admin-shop-controller-coupon-gateway-operations.php
rename to src/AKSRT/Admin/ShopControllerCouponGatewayOperations.php
index cbe77a6a..50ca7b57 100644
--- a/inc/classes/admin/class-aksrt-admin-shop-controller-coupon-gateway-operations.php
+++ b/src/AKSRT/Admin/ShopControllerCouponGatewayOperations.php
@@ -1,19 +1,19 @@
success(['data' => ['items' => [], 'total' => 0, 'page' => 1, 'total_pages' => 1]]);
}
@@ -22,7 +22,7 @@ trait AKSRT_Admin_Shop_Controller_Coupon_Gateway_Operations {
$status = sanitize_key((string) $request->get_param('status'));
$search = sanitize_text_field((string) $request->get_param('search'));
- $result = AKSRT_Coupon::get_instance()->get_list([
+ $result = \AKSRT\Payment\Coupon::get_instance()->get_list([
'status' => $status,
'search' => $search,
'limit' => $per_page,
@@ -35,8 +35,8 @@ trait AKSRT_Admin_Shop_Controller_Coupon_Gateway_Operations {
/**
* POST /shop/coupons — 创建优惠券
*/
- public function create_coupon(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Coupon')) {
+ public function create_coupon(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Payment\Coupon')) {
return $this->error('优惠券系统未启用', 500);
}
@@ -47,7 +47,7 @@ trait AKSRT_Admin_Shop_Controller_Coupon_Gateway_Operations {
return $this->error('优惠码不能为空');
}
- $id = AKSRT_Coupon::get_instance()->create($params);
+ $id = \AKSRT\Payment\Coupon::get_instance()->create($params);
if ($id > 0) {
return $this->success([
@@ -62,8 +62,8 @@ trait AKSRT_Admin_Shop_Controller_Coupon_Gateway_Operations {
/**
* POST /shop/coupons/{id}/disable — 禁用优惠券
*/
- public function disable_coupon(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Coupon')) {
+ public function disable_coupon(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Payment\Coupon')) {
return $this->error('优惠券系统未启用', 500);
}
@@ -72,7 +72,7 @@ trait AKSRT_Admin_Shop_Controller_Coupon_Gateway_Operations {
return $this->error('参数无效');
}
- $success = AKSRT_Coupon::get_instance()->disable($id);
+ $success = \AKSRT\Payment\Coupon::get_instance()->disable($id);
if ($success) {
return $this->success(['message' => __('优惠券已禁用', 'aksrt')]);
@@ -83,14 +83,14 @@ trait AKSRT_Admin_Shop_Controller_Coupon_Gateway_Operations {
/**
* GET /shop/gateways — 支付网关状态列表
*/
- public function get_gateways(): WP_REST_Response {
- if (!class_exists('AKSRT_Payment_Gateway')) {
+ public function get_gateways(): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Payment\Gateway')) {
return $this->success(['data' => ['gateways' => []]]);
}
return $this->success([
'data' => [
- 'gateways' => AKSRT_Payment_Gateway::get_instance()->get_status_summary(),
+ 'gateways' => \AKSRT\Payment\Gateway::get_instance()->get_status_summary(),
],
]);
}
diff --git a/inc/classes/admin/class-aksrt-admin-shop-controller-frontend-flow-operations.php b/src/AKSRT/Admin/ShopControllerFrontendFlowOperations.php
similarity index 71%
rename from inc/classes/admin/class-aksrt-admin-shop-controller-frontend-flow-operations.php
rename to src/AKSRT/Admin/ShopControllerFrontendFlowOperations.php
index d84894f7..c7fcadcb 100644
--- a/inc/classes/admin/class-aksrt-admin-shop-controller-frontend-flow-operations.php
+++ b/src/AKSRT/Admin/ShopControllerFrontendFlowOperations.php
@@ -1,24 +1,24 @@
error('商城服务不可用', 500);
}
- $result = AKSRT_Shop::get_instance()->preview_checkout(get_current_user_id(), $this->get_json_params($request));
+ $result = \AKSRT\Shop\Shop::get_instance()->preview_checkout(get_current_user_id(), $this->get_json_params($request));
if (empty($result['success'])) {
return $this->error($result['message'] ?? '结算预览失败');
}
@@ -26,12 +26,12 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
return $this->success(['data' => $result['data']]);
}
- public function create_frontend_order(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Shop')) {
+ public function create_frontend_order(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Shop\Shop')) {
return $this->error('商城服务不可用', 500);
}
- $result = AKSRT_Shop::get_instance()->create_checkout_order(get_current_user_id(), $this->get_json_params($request));
+ $result = \AKSRT\Shop\Shop::get_instance()->create_checkout_order(get_current_user_id(), $this->get_json_params($request));
if (empty($result['success'])) {
return $this->error($result['message'] ?? '订单创建失败');
}
@@ -42,8 +42,8 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
], 201);
}
- public function get_frontend_orders(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Shop')) {
+ public function get_frontend_orders(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Shop\Shop')) {
return $this->success(['data' => ['items' => [], 'total' => 0, 'total_pages' => 1, 'page' => 1]]);
}
@@ -51,7 +51,7 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
$per_page = max(1, min(50, (int) $request->get_param('per_page'))) ?: 20;
$status = sanitize_key((string) $request->get_param('status'));
- $view = AKSRT_Shop::get_instance()->get_order_center_view(get_current_user_id(), [
+ $view = \AKSRT\Shop\Shop::get_instance()->get_order_center_view(get_current_user_id(), [
'page' => $page,
'per_page' => $per_page,
'status' => $status,
@@ -60,13 +60,13 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
return $this->success(['data' => $view]);
}
- public function get_frontend_order(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Shop')) {
+ public function get_frontend_order(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Shop\Shop')) {
return $this->error('商城服务不可用', 500);
}
$order_number = sanitize_text_field((string) $request->get_param('order_number'));
- $order = AKSRT_Shop::get_instance()->get_order_detail_view(get_current_user_id(), $order_number);
+ $order = \AKSRT\Shop\Shop::get_instance()->get_order_detail_view(get_current_user_id(), $order_number);
if (!$order) {
return $this->error('订单不存在', 404);
}
@@ -74,8 +74,8 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
return $this->success(['data' => $order]);
}
- public function pay_frontend_order(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Shop')) {
+ public function pay_frontend_order(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Shop\Shop')) {
return $this->error('商城服务不可用', 500);
}
@@ -83,7 +83,7 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
$payment_method = sanitize_key((string) ($params['payment_method'] ?? 'balance'));
$order_number = sanitize_text_field((string) $request->get_param('order_number'));
- $result = AKSRT_Shop::get_instance()->pay_order(get_current_user_id(), $order_number, $payment_method);
+ $result = \AKSRT\Shop\Shop::get_instance()->pay_order(get_current_user_id(), $order_number, $payment_method);
if (empty($result['success'])) {
return $this->error($result['message'] ?? '支付失败');
}
@@ -91,13 +91,13 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
return $this->success(['data' => $result['data']]);
}
- public function cancel_frontend_order(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Shop')) {
+ public function cancel_frontend_order(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Shop\Shop')) {
return $this->error('商城服务不可用', 500);
}
$order_number = sanitize_text_field((string) $request->get_param('order_number'));
- $result = AKSRT_Shop::get_instance()->cancel_order(get_current_user_id(), $order_number);
+ $result = \AKSRT\Shop\Shop::get_instance()->cancel_order(get_current_user_id(), $order_number);
if (empty($result['success'])) {
return $this->error($result['message'] ?? '取消订单失败');
}
@@ -105,14 +105,14 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
return $this->success(['data' => $result['data']]);
}
- public function create_frontend_after_sale(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Shop')) {
+ public function create_frontend_after_sale(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Shop\Shop')) {
return $this->error('商城服务不可用', 500);
}
$params = $this->get_json_params($request);
$params['order_number'] = sanitize_text_field((string) $request->get_param('order_number'));
- $result = AKSRT_Shop::get_instance()->create_after_sale_request(get_current_user_id(), $params);
+ $result = \AKSRT\Shop\Shop::get_instance()->create_after_sale_request(get_current_user_id(), $params);
if (empty($result['success'])) {
return $this->error($result['message'] ?? '提交售后失败');
}
@@ -123,9 +123,9 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
], 201);
}
- public function get_cart(WP_REST_Request $request): WP_REST_Response {
+ public function get_cart(\WP_REST_Request $request): \WP_REST_Response {
$user_id = get_current_user_id();
- $shop = AKSRT_Shop::get_instance();
+ $shop = \AKSRT\Shop\Shop::get_instance();
$cart = $shop->get_cart($user_id);
$items = [];
@@ -173,18 +173,18 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
]);
}
- public function get_cart_count(WP_REST_Request $request): WP_REST_Response {
+ public function get_cart_count(\WP_REST_Request $request): \WP_REST_Response {
$user_id = get_current_user_id();
- return $this->success(['data' => ['count' => AKSRT_Shop::get_instance()->get_cart_count($user_id)]]);
+ return $this->success(['data' => ['count' => \AKSRT\Shop\Shop::get_instance()->get_cart_count($user_id)]]);
}
- public function handle_add_to_cart(WP_REST_Request $request): WP_REST_Response {
+ public function handle_add_to_cart(\WP_REST_Request $request): \WP_REST_Response {
$params = $this->get_json_params($request);
$product_id = (int) ($params['product_id'] ?? 0);
$options_string = sanitize_text_field((string) ($params['options_string'] ?? ''));
$count = max(1, (int) ($params['count'] ?? 1));
- $result = AKSRT_Shop::get_instance()->add_to_cart(get_current_user_id(), $product_id, $options_string, $count);
+ $result = \AKSRT\Shop\Shop::get_instance()->add_to_cart(get_current_user_id(), $product_id, $options_string, $count);
if (isset($result['error'])) {
return $this->error($result['error']);
@@ -192,13 +192,13 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
return $this->success(['data' => $result]);
}
- public function handle_reduce_from_cart(WP_REST_Request $request): WP_REST_Response {
+ public function handle_reduce_from_cart(\WP_REST_Request $request): \WP_REST_Response {
$params = $this->get_json_params($request);
$product_id = (int) ($params['product_id'] ?? 0);
$options_string = sanitize_text_field((string) ($params['options_string'] ?? ''));
$count = max(1, (int) ($params['count'] ?? 1));
- $result = AKSRT_Shop::get_instance()->reduce_from_cart(get_current_user_id(), $product_id, $options_string, $count);
+ $result = \AKSRT\Shop\Shop::get_instance()->reduce_from_cart(get_current_user_id(), $product_id, $options_string, $count);
if (isset($result['error'])) {
return $this->error($result['error']);
@@ -206,12 +206,12 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
return $this->success(['data' => $result]);
}
- public function handle_remove_from_cart(WP_REST_Request $request): WP_REST_Response {
+ public function handle_remove_from_cart(\WP_REST_Request $request): \WP_REST_Response {
$params = $this->get_json_params($request);
$product_id = (int) ($params['product_id'] ?? 0);
$options_string = sanitize_text_field((string) ($params['options_string'] ?? ''));
- $result = AKSRT_Shop::get_instance()->remove_from_cart(get_current_user_id(), $product_id, $options_string);
+ $result = \AKSRT\Shop\Shop::get_instance()->remove_from_cart(get_current_user_id(), $product_id, $options_string);
if (isset($result['error'])) {
return $this->error($result['error']);
@@ -219,11 +219,11 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
return $this->success(['data' => $result]);
}
- public function handle_remove_multi_from_cart(WP_REST_Request $request): WP_REST_Response {
+ public function handle_remove_multi_from_cart(\WP_REST_Request $request): \WP_REST_Response {
$params = $this->get_json_params($request);
$items = is_array($params['items'] ?? null) ? $params['items'] : [];
- $result = AKSRT_Shop::get_instance()->remove_multi_from_cart(get_current_user_id(), $items);
+ $result = \AKSRT\Shop\Shop::get_instance()->remove_multi_from_cart(get_current_user_id(), $items);
if (isset($result['error'])) {
return $this->error($result['error']);
@@ -231,8 +231,8 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
return $this->success(['data' => $result]);
}
- public function handle_empty_cart(WP_REST_Request $request): WP_REST_Response {
- $result = AKSRT_Shop::get_instance()->empty_cart(get_current_user_id());
+ public function handle_empty_cart(\WP_REST_Request $request): \WP_REST_Response {
+ $result = \AKSRT\Shop\Shop::get_instance()->empty_cart(get_current_user_id());
if (isset($result['error'])) {
return $this->error($result['error']);
@@ -240,13 +240,13 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
return $this->success(['data' => $result]);
}
- public function toggle_frontend_product_favorite(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Shop')) {
+ public function toggle_frontend_product_favorite(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Shop\Shop')) {
return $this->error('商城服务不可用', 500);
}
$product_id = (int) $request->get_param('id');
- $result = AKSRT_Shop::get_instance()->toggle_favorite(get_current_user_id(), $product_id);
+ $result = \AKSRT\Shop\Shop::get_instance()->toggle_favorite(get_current_user_id(), $product_id);
if (empty($result['success'])) {
return $this->error(__('收藏操作失败', 'aksrt'));
}
@@ -257,13 +257,13 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
]);
}
- public function rebuy_frontend_order(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Shop')) {
+ public function rebuy_frontend_order(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Shop\Shop')) {
return $this->error('商城服务不可用', 500);
}
$order_number = sanitize_text_field((string) $request->get_param('order_number'));
- $result = AKSRT_Shop::get_instance()->re_purchase(get_current_user_id(), $order_number);
+ $result = \AKSRT\Shop\Shop::get_instance()->re_purchase(get_current_user_id(), $order_number);
if (empty($result['success'])) {
return $this->error($result['message'] ?? __('再次购买失败', 'aksrt'));
}
@@ -274,23 +274,23 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
]);
}
- public function get_frontend_addresses(): WP_REST_Response {
- if (!class_exists('AKSRT_Shop')) {
+ public function get_frontend_addresses(): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Shop\Shop')) {
return $this->success(['data' => ['addresses' => []]]);
}
- $addresses = AKSRT_Shop::get_instance()->get_address_book(get_current_user_id());
+ $addresses = \AKSRT\Shop\Shop::get_instance()->get_address_book(get_current_user_id());
return $this->success(['data' => ['addresses' => $addresses]]);
}
- public function create_frontend_address(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Shop')) {
+ public function create_frontend_address(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Shop\Shop')) {
return $this->error('商城服务不可用', 500);
}
$params = $this->get_json_params($request);
$user_id = get_current_user_id();
- $result = AKSRT_Shop::get_instance()->add_address($user_id, $params);
+ $result = \AKSRT\Shop\Shop::get_instance()->add_address($user_id, $params);
if (empty($result['success'])) {
return $this->error($result['error'] ?? '添加地址失败');
@@ -302,15 +302,15 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
], 201);
}
- public function update_frontend_address(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Shop')) {
+ public function update_frontend_address(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Shop\Shop')) {
return $this->error('商城服务不可用', 500);
}
$address_id = (int) $request->get_param('id');
$params = $this->get_json_params($request);
$user_id = get_current_user_id();
- $result = AKSRT_Shop::get_instance()->update_address($user_id, $address_id, $params);
+ $result = \AKSRT\Shop\Shop::get_instance()->update_address($user_id, $address_id, $params);
if (empty($result['success'])) {
return $this->error($result['error'] ?? '更新地址失败');
@@ -322,14 +322,14 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
]);
}
- public function delete_frontend_address(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Shop')) {
+ public function delete_frontend_address(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Shop\Shop')) {
return $this->error('商城服务不可用', 500);
}
$address_id = (int) $request->get_param('id');
$user_id = get_current_user_id();
- $result = AKSRT_Shop::get_instance()->delete_address($user_id, $address_id);
+ $result = \AKSRT\Shop\Shop::get_instance()->delete_address($user_id, $address_id);
if (empty($result['success'])) {
return $this->error($result['error'] ?? '删除地址失败');
@@ -338,14 +338,14 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
return $this->success(['message' => __('地址已删除', 'aksrt')]);
}
- public function set_default_frontend_address(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Shop')) {
+ public function set_default_frontend_address(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Shop\Shop')) {
return $this->error('商城服务不可用', 500);
}
$address_id = (int) $request->get_param('id');
$user_id = get_current_user_id();
- $result = AKSRT_Shop::get_instance()->set_default_address($user_id, $address_id);
+ $result = \AKSRT\Shop\Shop::get_instance()->set_default_address($user_id, $address_id);
if (empty($result['success'])) {
return $this->error($result['error'] ?? '设置默认地址失败');
@@ -354,8 +354,8 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
return $this->success(['message' => __('已设为默认地址', 'aksrt')]);
}
- public function get_frontend_product_archive(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Shop')) {
+ public function get_frontend_product_archive(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Shop\Shop')) {
return $this->error('商城服务不可用', 500);
}
@@ -364,7 +364,7 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
$page = max(1, (int) ($request->get_param('page') ?? 1));
$orderby = sanitize_key((string) ($request->get_param('orderby') ?? ''));
- $view = AKSRT_Shop::get_instance()->get_product_archive_view([
+ $view = \AKSRT\Shop\Shop::get_instance()->get_product_archive_view([
'taxonomy' => $taxonomy,
'term_id' => $term_id,
'paged' => $page,
@@ -434,14 +434,14 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
error('收益服务不可用', 500);
}
$view = aksrt_get_revenue_page_view(get_current_user_id());
$withdrawals = [];
- if (class_exists('AKSRT_Withdrawal')) {
- $rows = AKSRT_Withdrawal::get_instance()->get_user_withdrawals(get_current_user_id(), ['limit' => 20]);
+ if (class_exists('\AKSRT\Payment\Withdrawal')) {
+ $rows = \AKSRT\Payment\Withdrawal::get_instance()->get_user_withdrawals(get_current_user_id(), ['limit' => 20]);
foreach ($rows as $row) {
$withdrawals[] = [
'id' => (int) ($row['id'] ?? 0),
@@ -453,7 +453,7 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
];
}
}
- $settings = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_withdrawal_settings() : [];
+ $settings = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_withdrawal_settings() : [];
return $this->success([
'data' => array_merge($view, [
'withdrawals' => $withdrawals,
@@ -466,8 +466,8 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
]);
}
- public function create_frontend_withdraw(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Withdrawal') || !class_exists('AKSRT_Credits')) {
+ public function create_frontend_withdraw(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Payment\Withdrawal') || !class_exists('\AKSRT\Credits\Credits')) {
return $this->error('提现服务不可用', 500);
}
@@ -476,7 +476,7 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
$method = sanitize_key((string) ($params['method'] ?? 'alipay'));
$account = sanitize_textarea_field((string) ($params['account_info'] ?? $params['account'] ?? ''));
- $settings = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_withdrawal_settings() : [];
+ $settings = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_withdrawal_settings() : [];
$min = (float) ($settings['min_amount'] ?? 50);
if ($amount < $min) {
return $this->error(sprintf(__('最低提现金额为 %s', 'aksrt'), $min));
@@ -486,7 +486,7 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
}
$user_id = get_current_user_id();
- $balance = (float) AKSRT_Credits::balance($user_id);
+ $balance = (float) \AKSRT\Credits\Credits::balance($user_id);
if ($amount > $balance) {
return $this->error(__('可提现余额不足', 'aksrt'));
}
@@ -495,14 +495,14 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
if ($cost <= 0) {
return $this->error(__('提现金额无效', 'aksrt'));
}
- $deducted = AKSRT_Credits::deduct($user_id, $cost, 'withdraw', ['type' => 'withdraw'], __('用户提现申请', 'aksrt'));
+ $deducted = \AKSRT\Credits\Credits::deduct($user_id, $cost, 'withdraw', ['type' => 'withdraw'], __('用户提现申请', 'aksrt'));
if (is_wp_error($deducted)) {
return $this->error($deducted->get_error_message());
}
- $id = AKSRT_Withdrawal::get_instance()->create($user_id, $amount, $method, $account);
+ $id = \AKSRT\Payment\Withdrawal::get_instance()->create($user_id, $amount, $method, $account);
if ($id <= 0) {
- AKSRT_Credits::add($user_id, $cost, 'withdraw_refund', ['type' => 'withdraw'], __('提现失败退回', 'aksrt'));
+ \AKSRT\Credits\Credits::add($user_id, $cost, 'withdraw_refund', ['type' => 'withdraw'], __('提现失败退回', 'aksrt'));
return $this->error(__('提现申请创建失败', 'aksrt'), 500);
}
@@ -511,19 +511,19 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
'data' => [
'id' => $id,
'amount' => $amount,
- 'balance' => (float) AKSRT_Credits::balance($user_id),
+ 'balance' => (float) \AKSRT\Credits\Credits::balance($user_id),
],
], 201);
}
- public function submit_frontend_product_review(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Product_Review')) {
+ public function submit_frontend_product_review(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Shop\ProductReview')) {
return $this->error('评价服务不可用', 500);
}
$params = $this->get_json_params($request);
$order_number = sanitize_text_field((string) $request->get_param('order_number'));
$product_id = (int) ($params['product_id'] ?? 0);
- $result = AKSRT_Product_Review::get_instance()->submit_review(
+ $result = \AKSRT\Shop\ProductReview::get_instance()->submit_review(
get_current_user_id(),
$order_number,
$product_id,
@@ -538,16 +538,16 @@ trait AKSRT_Admin_Shop_Controller_Frontend_Flow_Operations {
], 201);
}
- public function create_frontend_product(WP_REST_Request $request): WP_REST_Response {
+ public function create_frontend_product(\WP_REST_Request $request): \WP_REST_Response {
$params = $this->get_json_params($request);
$params['author_id'] = get_current_user_id();
- $frontend_request = new WP_REST_Request('POST', '/');
+ $frontend_request = new \WP_REST_Request('POST', '/');
$frontend_request->set_body(wp_json_encode($params));
return $this->create_product($frontend_request);
}
- public function update_frontend_product(WP_REST_Request $request): WP_REST_Response {
+ public function update_frontend_product(\WP_REST_Request $request): \WP_REST_Response {
$id = (int) $request->get_param('id');
$post = get_post($id);
if (!$post || $post->post_type !== 'aksrt_product') {
diff --git a/inc/classes/admin/class-aksrt-admin-shop-controller-fulfillment-operations.php b/src/AKSRT/Admin/ShopControllerFulfillmentOperations.php
similarity index 77%
rename from inc/classes/admin/class-aksrt-admin-shop-controller-fulfillment-operations.php
rename to src/AKSRT/Admin/ShopControllerFulfillmentOperations.php
index f3dc0052..50b05e3c 100644
--- a/inc/classes/admin/class-aksrt-admin-shop-controller-fulfillment-operations.php
+++ b/src/AKSRT/Admin/ShopControllerFulfillmentOperations.php
@@ -1,19 +1,19 @@
success(['data' => ['items' => [], 'total' => 0, 'page' => 1, 'max_pages' => 1]]);
}
@@ -26,7 +26,7 @@ trait AKSRT_Admin_Shop_Controller_Fulfillment_Operations {
$date_from = sanitize_text_field((string) $request->get_param('date_from'));
$date_to = sanitize_text_field((string) $request->get_param('date_to'));
- $result = AKSRT_After_Sale::get_instance()->get_list([
+ $result = \AKSRT\Payment\AfterSale::get_instance()->get_list([
'limit' => $per_page,
'offset' => ($page - 1) * $per_page,
'status' => $status,
@@ -38,7 +38,7 @@ trait AKSRT_Admin_Shop_Controller_Fulfillment_Operations {
'include_order_context' => true,
]);
- $stats = AKSRT_After_Sale::get_instance()->get_stats();
+ $stats = \AKSRT\Payment\AfterSale::get_instance()->get_stats();
return $this->success(['data' => array_merge($result, [
'stats' => $stats,
@@ -51,9 +51,9 @@ trait AKSRT_Admin_Shop_Controller_Fulfillment_Operations {
'date_to' => $date_to,
],
'options' => [
- 'status' => AKSRT_After_Sale::get_status_options(),
- 'stage' => AKSRT_After_Sale::get_stage_options(),
- 'type' => AKSRT_After_Sale::get_type_options(),
+ 'status' => \AKSRT\Payment\AfterSale::get_status_options(),
+ 'stage' => \AKSRT\Payment\AfterSale::get_stage_options(),
+ 'type' => \AKSRT\Payment\AfterSale::get_type_options(),
],
])]);
}
@@ -61,8 +61,8 @@ trait AKSRT_Admin_Shop_Controller_Fulfillment_Operations {
/**
* POST /shop/after-sale — 创建售后工单
*/
- public function create_after_sale(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_After_Sale')) {
+ public function create_after_sale(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Payment\AfterSale')) {
return $this->error('售后系统未启用', 500);
}
@@ -74,8 +74,8 @@ trait AKSRT_Admin_Shop_Controller_Fulfillment_Operations {
return $this->error('订单号和原因不能为空');
}
- $order = class_exists('AKSRT_Order_Repository')
- ? AKSRT_Order_Repository::get_instance()->get($order_number)
+ $order = class_exists('\AKSRT\Payment\OrderRepository')
+ ? \AKSRT\Payment\OrderRepository::get_instance()->get($order_number)
: null;
if (!$order) {
@@ -87,7 +87,7 @@ trait AKSRT_Admin_Shop_Controller_Fulfillment_Operations {
return $this->error(__('订单未绑定有效用户', 'aksrt'));
}
- $id = AKSRT_After_Sale::get_instance()->create($params);
+ $id = \AKSRT\Payment\AfterSale::get_instance()->create($params);
if ($id > 0) {
return $this->success([
@@ -102,8 +102,8 @@ trait AKSRT_Admin_Shop_Controller_Fulfillment_Operations {
/**
* POST /shop/after-sale/{id}/update-status — 更新售后工单状态
*/
- public function update_after_sale_status(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_After_Sale')) {
+ public function update_after_sale_status(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Payment\AfterSale')) {
return $this->error('售后系统未启用', 500);
}
@@ -116,7 +116,7 @@ trait AKSRT_Admin_Shop_Controller_Fulfillment_Operations {
return $this->error('参数无效');
}
- $success = AKSRT_After_Sale::get_instance()->update_status(
+ $success = \AKSRT\Payment\AfterSale::get_instance()->update_status(
$id,
$new_status,
get_current_user_id(),
@@ -132,8 +132,8 @@ trait AKSRT_Admin_Shop_Controller_Fulfillment_Operations {
/**
* GET /shop/shipping — 发货记录列表
*/
- public function get_shipping_list(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Shipping')) {
+ public function get_shipping_list(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Payment\Shipping')) {
return $this->success(['data' => ['items' => [], 'total' => 0, 'page' => 1, 'max_pages' => 1]]);
}
@@ -145,7 +145,7 @@ trait AKSRT_Admin_Shop_Controller_Fulfillment_Operations {
$date_to = sanitize_text_field((string) $request->get_param('date_to'));
$tracking_no = sanitize_text_field((string) $request->get_param('tracking_no'));
- $result = AKSRT_Shipping::get_instance()->get_list([
+ $result = \AKSRT\Payment\Shipping::get_instance()->get_list([
'limit' => $per_page,
'offset' => ($page - 1) * $per_page,
'status' => $status,
@@ -156,7 +156,7 @@ trait AKSRT_Admin_Shop_Controller_Fulfillment_Operations {
'include_order_context' => true,
]);
- $stats = AKSRT_Shipping::get_instance()->get_stats();
+ $stats = \AKSRT\Payment\Shipping::get_instance()->get_stats();
return $this->success(['data' => array_merge($result, [
'stats' => $stats,
@@ -168,8 +168,8 @@ trait AKSRT_Admin_Shop_Controller_Fulfillment_Operations {
'tracking_no' => $tracking_no,
],
'options' => [
- 'status' => AKSRT_Shipping::get_status_options(),
- 'carrier' => AKSRT_Shipping::get_carrier_options(),
+ 'status' => \AKSRT\Payment\Shipping::get_status_options(),
+ 'carrier' => \AKSRT\Payment\Shipping::get_carrier_options(),
],
])]);
}
@@ -177,8 +177,8 @@ trait AKSRT_Admin_Shop_Controller_Fulfillment_Operations {
/**
* POST /shop/shipping — 创建发货记录
*/
- public function create_shipping(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Shipping')) {
+ public function create_shipping(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Payment\Shipping')) {
return $this->error('物流系统未启用', 500);
}
@@ -191,8 +191,8 @@ trait AKSRT_Admin_Shop_Controller_Fulfillment_Operations {
return $this->error('订单号、快递公司和物流单号不能为空');
}
- $order = class_exists('AKSRT_Order_Repository')
- ? AKSRT_Order_Repository::get_instance()->get($order_number)
+ $order = class_exists('\AKSRT\Payment\OrderRepository')
+ ? \AKSRT\Payment\OrderRepository::get_instance()->get($order_number)
: null;
if (!$order) {
@@ -201,7 +201,7 @@ trait AKSRT_Admin_Shop_Controller_Fulfillment_Operations {
$params['operator_id'] = get_current_user_id();
- $id = AKSRT_Shipping::get_instance()->create($params);
+ $id = \AKSRT\Payment\Shipping::get_instance()->create($params);
if ($id > 0) {
return $this->success([
@@ -216,8 +216,8 @@ trait AKSRT_Admin_Shop_Controller_Fulfillment_Operations {
/**
* POST /shop/shipping/{id}/update-status — 更新发货状态
*/
- public function update_shipping_status(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Shipping')) {
+ public function update_shipping_status(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Payment\Shipping')) {
return $this->error('物流系统未启用', 500);
}
@@ -230,7 +230,7 @@ trait AKSRT_Admin_Shop_Controller_Fulfillment_Operations {
return $this->error('参数无效');
}
- $success = AKSRT_Shipping::get_instance()->update_status($id, $new_status, $note, get_current_user_id());
+ $success = \AKSRT\Payment\Shipping::get_instance()->update_status($id, $new_status, $note, get_current_user_id());
if ($success) {
return $this->success(['message' => __('状态已更新', 'aksrt')]);
@@ -238,8 +238,8 @@ trait AKSRT_Admin_Shop_Controller_Fulfillment_Operations {
return $this->error(__('更新失败', 'aksrt'));
}
- public function get_after_sale_detail(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_After_Sale')) {
+ public function get_after_sale_detail(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Payment\AfterSale')) {
return $this->error('售后系统未启用', 500);
}
@@ -248,7 +248,7 @@ trait AKSRT_Admin_Shop_Controller_Fulfillment_Operations {
return $this->error('参数无效');
}
- $record = AKSRT_After_Sale::get_instance()->get_with_order_context($id);
+ $record = \AKSRT\Payment\AfterSale::get_instance()->get_with_order_context($id);
if (!$record) {
return $this->error(__('售后工单不存在', 'aksrt'), 404);
}
@@ -261,8 +261,8 @@ trait AKSRT_Admin_Shop_Controller_Fulfillment_Operations {
]);
}
- public function get_shipping_detail(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Shipping')) {
+ public function get_shipping_detail(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Payment\Shipping')) {
return $this->error('物流系统未启用', 500);
}
@@ -271,7 +271,7 @@ trait AKSRT_Admin_Shop_Controller_Fulfillment_Operations {
return $this->error('参数无效');
}
- $record = AKSRT_Shipping::get_instance()->get_with_order_context($id);
+ $record = \AKSRT\Payment\Shipping::get_instance()->get_with_order_context($id);
if (!$record) {
return $this->error(__('发货记录不存在', 'aksrt'), 404);
}
@@ -284,8 +284,8 @@ trait AKSRT_Admin_Shop_Controller_Fulfillment_Operations {
]);
}
- public function batch_update_shipping_status(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Shipping')) {
+ public function batch_update_shipping_status(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Payment\Shipping')) {
return $this->error('物流系统未启用', 500);
}
@@ -298,7 +298,7 @@ trait AKSRT_Admin_Shop_Controller_Fulfillment_Operations {
return $this->error('参数无效');
}
- $result = AKSRT_Shipping::get_instance()->batch_update_status($ids, $status, $note, get_current_user_id());
+ $result = \AKSRT\Payment\Shipping::get_instance()->batch_update_status($ids, $status, $note, get_current_user_id());
return $this->success([
'message' => __('批量状态更新已执行', 'aksrt'),
diff --git a/inc/classes/admin/class-aksrt-admin-shop-controller-order-operations.php b/src/AKSRT/Admin/ShopControllerOrderOperations.php
similarity index 78%
rename from inc/classes/admin/class-aksrt-admin-shop-controller-order-operations.php
rename to src/AKSRT/Admin/ShopControllerOrderOperations.php
index b9814fed..18647018 100644
--- a/inc/classes/admin/class-aksrt-admin-shop-controller-order-operations.php
+++ b/src/AKSRT/Admin/ShopControllerOrderOperations.php
@@ -1,25 +1,25 @@
get_param('page'));
$per_page = max(1, min(50, (int) $request->get_param('per_page'))) ?: 20;
$search = sanitize_text_field((string) $request->get_param('search'));
$status = sanitize_key((string) $request->get_param('status'));
- if (class_exists('AKSRT_Order_Repository')) {
- $repo = AKSRT_Order_Repository::get_instance();
+ if (class_exists('\AKSRT\Payment\OrderRepository')) {
+ $repo = \AKSRT\Payment\OrderRepository::get_instance();
$args = [
'limit' => $per_page,
@@ -48,14 +48,14 @@ trait AKSRT_Admin_Shop_Controller_Order_Operations {
/**
* GET /shop/orders/{order_number} — 单个订单详情(含上下文)
*/
- public function get_order(WP_REST_Request $request): WP_REST_Response {
+ public function get_order(\WP_REST_Request $request): \WP_REST_Response {
$order_number = sanitize_text_field((string) $request->get_param('order_number'));
- if (!class_exists('AKSRT_Order_Repository')) {
+ if (!class_exists('\AKSRT\Payment\OrderRepository')) {
return $this->error('订单服务不可用', 500);
}
- $repo = AKSRT_Order_Repository::get_instance();
+ $repo = \AKSRT\Payment\OrderRepository::get_instance();
$order = $repo->get($order_number);
if (!$order) {
return $this->error('订单不存在', 404);
@@ -63,9 +63,9 @@ trait AKSRT_Admin_Shop_Controller_Order_Operations {
$context = $repo->get_admin_order_context($order_number);
$timeline = [];
- if (class_exists('AKSRT_Shop')) {
- $shipping_records = class_exists('AKSRT_Shipping') ? AKSRT_Shipping::get_instance()->get_by_order($order_number) : [];
- $after_sale_result = class_exists('AKSRT_After_Sale') ? AKSRT_After_Sale::get_instance()->get_list(['order_number' => $order_number, 'limit' => 20]) : ['items' => []];
+ if (class_exists('\AKSRT\Shop\Shop')) {
+ $shipping_records = class_exists('\AKSRT\Payment\Shipping') ? \AKSRT\Payment\Shipping::get_instance()->get_by_order($order_number) : [];
+ $after_sale_result = class_exists('\AKSRT\Payment\AfterSale') ? \AKSRT\Payment\AfterSale::get_instance()->get_list(['order_number' => $order_number, 'limit' => 20]) : ['items' => []];
$after_sale_items = $after_sale_result['items'] ?? [];
$timeline = [];
@@ -110,7 +110,7 @@ trait AKSRT_Admin_Shop_Controller_Order_Operations {
* POST /shop/orders/update-status — 更新订单状态
* Canonical field: order_number (前端必须发送 order_number)
*/
- public function update_order_status(WP_REST_Request $request): WP_REST_Response {
+ public function update_order_status(\WP_REST_Request $request): \WP_REST_Response {
$params = $this->get_json_params($request);
$order_number = sanitize_text_field((string) ($params['order_number'] ?? ''));
$new_status = sanitize_key((string) ($params['status'] ?? ''));
@@ -121,8 +121,8 @@ trait AKSRT_Admin_Shop_Controller_Order_Operations {
}
$success = false;
- if (class_exists('AKSRT_Order_Repository')) {
- $success = AKSRT_Order_Repository::get_instance()->update_status($order_number, $new_status, [
+ if (class_exists('\AKSRT\Payment\OrderRepository')) {
+ $success = \AKSRT\Payment\OrderRepository::get_instance()->update_status($order_number, $new_status, [
'note' => $note,
'force' => true,
]);
diff --git a/inc/classes/admin/class-aksrt-admin-shop-controller-product-admin-columns.php b/src/AKSRT/Admin/ShopControllerProductAdminColumns.php
similarity index 98%
rename from inc/classes/admin/class-aksrt-admin-shop-controller-product-admin-columns.php
rename to src/AKSRT/Admin/ShopControllerProductAdminColumns.php
index 25b28f59..1472a11a 100644
--- a/inc/classes/admin/class-aksrt-admin-shop-controller-product-admin-columns.php
+++ b/src/AKSRT/Admin/ShopControllerProductAdminColumns.php
@@ -1,13 +1,13 @@
0, 'pending' => 0, 'paid' => 0, 'revenue' => 0];
- if (class_exists('AKSRT_Order_Repository')) {
- $order_stats = AKSRT_Order_Repository::get_instance()->get_stats();
+ if (class_exists('\AKSRT\Payment\OrderRepository')) {
+ $order_stats = \AKSRT\Payment\OrderRepository::get_instance()->get_stats();
}
$revenue_stats = ['total' => 0, 'pending' => 0, 'settled' => 0];
- if (class_exists('AKSRT_Revenue')) {
- $revenue_stats = AKSRT_Revenue::get_instance()->get_stats();
+ if (class_exists('\AKSRT\Payment\Revenue')) {
+ $revenue_stats = \AKSRT\Payment\Revenue::get_instance()->get_stats();
}
$gateway_summary = [];
- if (class_exists('AKSRT_Payment_Gateway')) {
- $gateway_summary = AKSRT_Payment_Gateway::get_instance()->get_status_summary();
+ if (class_exists('\AKSRT\Payment\Gateway')) {
+ $gateway_summary = \AKSRT\Payment\Gateway::get_instance()->get_status_summary();
}
return $this->success([
@@ -46,7 +46,7 @@ trait AKSRT_Admin_Shop_Controller_Product_Operations {
]);
}
- public function get_product_taxonomy(): WP_REST_Response {
+ public function get_product_taxonomy(): \WP_REST_Response {
return $this->success([
'data' => [
'categories' => $this->format_product_terms('aksrt_product_cat'),
@@ -60,7 +60,7 @@ trait AKSRT_Admin_Shop_Controller_Product_Operations {
*
* Body: { taxonomy: 'category'|'tag'|'aksrt_product_cat'|'aksrt_product_tag', name: string, parent?: int }
*/
- public function create_product_taxonomy_term(WP_REST_Request $request): WP_REST_Response {
+ public function create_product_taxonomy_term(\WP_REST_Request $request): \WP_REST_Response {
$params = $this->get_json_params($request);
$raw_tax = sanitize_key((string) ($params['taxonomy'] ?? 'category'));
$name = sanitize_text_field((string) ($params['name'] ?? ''));
@@ -144,7 +144,7 @@ trait AKSRT_Admin_Shop_Controller_Product_Operations {
return [];
}
- return array_map(static function (WP_Term $term): array {
+ return array_map(static function (\WP_Term $term): array {
return [
'id' => (int) $term->term_id,
'name' => (string) $term->name,
@@ -158,7 +158,7 @@ trait AKSRT_Admin_Shop_Controller_Product_Operations {
/**
* GET /shop/products — 商品列表,支持 search、status、page、per_page
*/
- public function get_products(WP_REST_Request $request): WP_REST_Response {
+ public function get_products(\WP_REST_Request $request): \WP_REST_Response {
$page = max(1, (int) $request->get_param('page'));
$per_page = max(1, min(50, (int) $request->get_param('per_page'))) ?: 20;
$search = sanitize_text_field((string) $request->get_param('search'));
@@ -182,7 +182,7 @@ trait AKSRT_Admin_Shop_Controller_Product_Operations {
$query_args['s'] = $search;
}
- $query = new WP_Query($query_args);
+ $query = new \WP_Query($query_args);
$products = [];
while ($query->have_posts()) {
@@ -214,7 +214,7 @@ trait AKSRT_Admin_Shop_Controller_Product_Operations {
/**
* GET /shop/products/{id} — 单个商品详情
*/
- public function get_product(WP_REST_Request $request): WP_REST_Response {
+ public function get_product(\WP_REST_Request $request): \WP_REST_Response {
$id = (int) $request->get_param('id');
$post = get_post($id);
@@ -249,7 +249,7 @@ trait AKSRT_Admin_Shop_Controller_Product_Operations {
/**
* POST /shop/products — 创建商品
*/
- public function create_product(WP_REST_Request $request): WP_REST_Response {
+ public function create_product(\WP_REST_Request $request): \WP_REST_Response {
$params = $this->get_json_params($request);
$title = sanitize_text_field((string) ($params['title'] ?? ''));
@@ -333,8 +333,8 @@ trait AKSRT_Admin_Shop_Controller_Product_Operations {
update_post_meta($post_id, '_aksrt_product_image', $image);
}
- if (isset($params['options']) && is_array($params['options']) && class_exists('AKSRT_Shop')) {
- AKSRT_Shop::get_instance()->save_product_options((int) $post_id, $params['options']);
+ if (isset($params['options']) && is_array($params['options']) && class_exists('\AKSRT\Shop\Shop')) {
+ \AKSRT\Shop\Shop::get_instance()->save_product_options((int) $post_id, $params['options']);
}
return $this->success([
@@ -346,7 +346,7 @@ trait AKSRT_Admin_Shop_Controller_Product_Operations {
/**
* POST /shop/products/{id} — 更新商品(含上下架)
*/
- public function update_product(WP_REST_Request $request): WP_REST_Response {
+ public function update_product(\WP_REST_Request $request): \WP_REST_Response {
$id = (int) $request->get_param('id');
$post = get_post($id);
@@ -488,8 +488,8 @@ trait AKSRT_Admin_Shop_Controller_Product_Operations {
update_post_meta($id, '_aksrt_product_image', esc_url_raw((string) $params['image']));
}
- if (isset($params['options']) && is_array($params['options']) && class_exists('AKSRT_Shop')) {
- AKSRT_Shop::get_instance()->save_product_options($id, $params['options']);
+ if (isset($params['options']) && is_array($params['options']) && class_exists('\AKSRT\Shop\Shop')) {
+ \AKSRT\Shop\Shop::get_instance()->save_product_options($id, $params['options']);
}
return $this->success([
diff --git a/inc/classes/admin/class-aksrt-admin-shop-controller-variant-export-operations.php b/src/AKSRT/Admin/ShopControllerVariantExportOperations.php
similarity index 61%
rename from inc/classes/admin/class-aksrt-admin-shop-controller-variant-export-operations.php
rename to src/AKSRT/Admin/ShopControllerVariantExportOperations.php
index 7555dd2e..62c2d5f6 100644
--- a/inc/classes/admin/class-aksrt-admin-shop-controller-variant-export-operations.php
+++ b/src/AKSRT/Admin/ShopControllerVariantExportOperations.php
@@ -1,30 +1,30 @@
get_param('id');
$product = get_post($product_id);
if (!$product || $product->post_type !== 'aksrt_product') {
return $this->error('商品不存在', 404);
}
- if (!class_exists('AKSRT_Shop')) {
+ if (!class_exists('\AKSRT\Shop\Shop')) {
return $this->success(['data' => ['variants' => []]]);
}
- $variants = AKSRT_Shop::get_instance()->get_variants($product_id);
+ $variants = \AKSRT\Shop\Shop::get_instance()->get_variants($product_id);
return $this->success(['data' => ['variants' => $variants]]);
}
- public function save_product_variants(WP_REST_Request $request): WP_REST_Response {
+ public function save_product_variants(\WP_REST_Request $request): \WP_REST_Response {
$product_id = (int) $request->get_param('id');
$product = get_post($product_id);
if (!$product || $product->post_type !== 'aksrt_product') {
@@ -39,22 +39,22 @@ trait AKSRT_Admin_Shop_Controller_Variant_Export_Operations {
return $this->error('变体数据格式错误');
}
- if (!class_exists('AKSRT_Shop')) {
+ if (!class_exists('\AKSRT\Shop\Shop')) {
return $this->error('商城系统未启用', 501);
}
- $saved = AKSRT_Shop::get_instance()->save_variants($product_id, $variants);
+ $saved = \AKSRT\Shop\Shop::get_instance()->save_variants($product_id, $variants);
return $this->success(['message' => '变体已保存', 'data' => ['variants' => $saved]]);
}
- public function delete_variant(WP_REST_Request $request): WP_REST_Response {
+ public function delete_variant(\WP_REST_Request $request): \WP_REST_Response {
$variant_id = (int) $request->get_param('id');
- if (!class_exists('AKSRT_Shop')) {
+ if (!class_exists('\AKSRT\Shop\Shop')) {
return $this->error('商城系统未启用', 501);
}
- $result = AKSRT_Shop::get_instance()->delete_variant($variant_id);
+ $result = \AKSRT\Shop\Shop::get_instance()->delete_variant($variant_id);
if (!$result) {
return $this->error('删除失败', 500);
}
@@ -62,8 +62,8 @@ trait AKSRT_Admin_Shop_Controller_Variant_Export_Operations {
return $this->success(['message' => '变体已删除']);
}
- public function export_orders(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Shop')) {
+ public function export_orders(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Shop\Shop')) {
return $this->error('商城服务不可用', 500);
}
@@ -74,22 +74,22 @@ trait AKSRT_Admin_Shop_Controller_Variant_Export_Operations {
'limit' => max(1, min(5000, (int) ($request->get_param('limit') ?: 1000))),
];
- $result = AKSRT_Shop::get_instance()->export_orders_csv($args);
+ $result = \AKSRT\Shop\Shop::get_instance()->export_orders_csv($args);
- return new WP_REST_Response($result['csv'], 200, [
+ return new \WP_REST_Response($result['csv'], 200, [
'Content-Type' => 'text/csv; charset=utf-8',
'Content-Disposition' => 'attachment; filename="orders-' . date('Ymd-His') . '.csv"',
'X-Order-Count' => $result['count'],
]);
}
- public function confirm_receipt(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Shop')) {
+ public function confirm_receipt(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Shop\Shop')) {
return $this->error('商城服务不可用', 500);
}
$order_number = sanitize_text_field((string) $request->get_param('order_number'));
- $result = AKSRT_Shop::get_instance()->confirm_receipt(get_current_user_id(), $order_number);
+ $result = \AKSRT\Shop\Shop::get_instance()->confirm_receipt(get_current_user_id(), $order_number);
if (empty($result['success'])) {
return $this->error($result['message'] ?? '确认收货失败');
}
@@ -97,16 +97,16 @@ trait AKSRT_Admin_Shop_Controller_Variant_Export_Operations {
return $this->success(['data' => $result['data']]);
}
- public function get_after_sale_reasons(WP_REST_Request $request): WP_REST_Response {
- if (class_exists('AKSRT_After_Sale')) {
- return $this->success(['data' => AKSRT_After_Sale::get_reason_options()]);
+ public function get_after_sale_reasons(\WP_REST_Request $request): \WP_REST_Response {
+ if (class_exists('\AKSRT\Payment\AfterSale')) {
+ return $this->success(['data' => \AKSRT\Payment\AfterSale::get_reason_options()]);
}
return $this->success(['data' => ['refund' => [], 'return' => []]]);
}
- public function get_frontend_after_sale_reasons(WP_REST_Request $request): WP_REST_Response {
- if (class_exists('AKSRT_After_Sale')) {
- return $this->success(['data' => AKSRT_After_Sale::get_reason_options()]);
+ public function get_frontend_after_sale_reasons(\WP_REST_Request $request): \WP_REST_Response {
+ if (class_exists('\AKSRT\Payment\AfterSale')) {
+ return $this->success(['data' => \AKSRT\Payment\AfterSale::get_reason_options()]);
}
return $this->success(['data' => ['refund' => [], 'return' => []]]);
}
diff --git a/inc/classes/admin/class-aksrt-admin-tools-controller.php b/src/AKSRT/Admin/ToolsController.php
similarity index 83%
rename from inc/classes/admin/class-aksrt-admin-tools-controller.php
rename to src/AKSRT/Admin/ToolsController.php
index fc695cd6..34922511 100644
--- a/inc/classes/admin/class-aksrt-admin-tools-controller.php
+++ b/src/AKSRT/Admin/ToolsController.php
@@ -1,16 +1,13 @@
get_json_params($request);
$action = sanitize_key((string) ($params['action'] ?? ''));
@@ -160,8 +157,8 @@ class AKSRT_Admin_Tools_Controller extends AKSRT_Admin_Controller_Base {
case 'rebuild_index':
// Rebuild search index / recount stats
- if (class_exists('AKSRT_Forum') && method_exists(AKSRT_Forum::get_instance(), 'recount_stats')) {
- AKSRT_Forum::get_instance()->recount_stats();
+ if (class_exists('\AKSRT\Forum\Forum') && method_exists(\AKSRT\Forum\Forum::get_instance(), 'recount_stats')) {
+ \AKSRT\Forum\Forum::get_instance()->recount_stats();
}
return $this->success(['message' => __('索引重建完成', 'aksrt')]);
@@ -170,7 +167,7 @@ class AKSRT_Admin_Tools_Controller extends AKSRT_Admin_Controller_Base {
}
}
- public function get_update_info(): WP_REST_Response {
+ public function get_update_info(): \WP_REST_Response {
$theme = wp_get_theme();
$info = [
'current_version' => $theme->get('Version') ?: '0.0.0',
@@ -183,8 +180,8 @@ class AKSRT_Admin_Tools_Controller extends AKSRT_Admin_Controller_Base {
'dismissed' => '',
];
- if (class_exists('AKSRT_Update_Checker')) {
- $stored = AKSRT_Update_Checker::get_instance()->get_update_info();
+ if (class_exists('\AKSRT\Core\UpdateChecker')) {
+ $stored = \AKSRT\Core\UpdateChecker::get_instance()->get_update_info();
if (is_array($stored)) {
$info = array_merge($info, $stored);
}
@@ -195,13 +192,13 @@ class AKSRT_Admin_Tools_Controller extends AKSRT_Admin_Controller_Base {
return $this->success(['data' => $info]);
}
- public function detect_update(): WP_REST_Response {
- if (!class_exists('AKSRT_Update_Checker')) {
+ public function detect_update(): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Core\UpdateChecker')) {
return $this->error(__('更新检查器不可用', 'aksrt'), 500);
}
- AKSRT_Update_Checker::get_instance()->do_check();
- $stored = AKSRT_Update_Checker::get_instance()->get_update_info();
+ \AKSRT\Core\UpdateChecker::get_instance()->do_check();
+ $stored = \AKSRT\Core\UpdateChecker::get_instance()->get_update_info();
return $this->success([
'message' => __('已完成更新检测', 'aksrt'),
@@ -209,7 +206,7 @@ class AKSRT_Admin_Tools_Controller extends AKSRT_Admin_Controller_Base {
]);
}
- public function dismiss_update(WP_REST_Request $request): WP_REST_Response {
+ public function dismiss_update(\WP_REST_Request $request): \WP_REST_Response {
$params = $this->get_json_params($request);
$version = sanitize_text_field((string) ($params['version'] ?? ''));
@@ -225,11 +222,11 @@ class AKSRT_Admin_Tools_Controller extends AKSRT_Admin_Controller_Base {
]);
}
- public function rest_health_email_verification(): WP_REST_Response {
- $feature_enabled = class_exists('AKSRT_Settings') && AKSRT_Settings::registration_requires_email_verification();
+ public function rest_health_email_verification(): \WP_REST_Response {
+ $feature_enabled = class_exists('\AKSRT\Settings\Settings') && \AKSRT\Settings\Settings::registration_requires_email_verification();
$pending_users = 0;
- if (class_exists('AKSRT_Auth_Email_Verification')) {
+ if (class_exists('\AKSRT\Auth\EmailVerification')) {
global $wpdb;
$pending_users = (int) $wpdb->get_var(
"SELECT COUNT(*) FROM {$wpdb->usermeta} WHERE meta_key = 'aksrt_email_verified' AND CAST(meta_value AS UNSIGNED) = 0"
@@ -243,7 +240,7 @@ class AKSRT_Admin_Tools_Controller extends AKSRT_Admin_Controller_Base {
]]);
}
- public function rest_set_rest_block(WP_REST_Request $request): WP_REST_Response {
+ public function rest_set_rest_block(\WP_REST_Request $request): \WP_REST_Response {
$params = $this->get_json_params($request);
$enabled = !empty($params['enabled']);
update_option('aksrt_rest_block_email_verification', $enabled);
@@ -254,25 +251,25 @@ class AKSRT_Admin_Tools_Controller extends AKSRT_Admin_Controller_Base {
]);
}
- public function rest_email_rollback_list(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Email_Rollback')) {
+ public function rest_email_rollback_list(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Auth\EmailRollback')) {
return $this->success(['data' => ['items' => [], 'total' => 0, 'page' => 1, 'per_page' => 20]]);
}
$page = max(1, (int) $request->get_param('page'));
$per_page = min(100, max(1, (int) $request->get_param('per_page')));
- $data = AKSRT_Email_Rollback::list_pending($page, $per_page);
+ $data = \AKSRT\Auth\EmailRollback::list_pending($page, $per_page);
return $this->success(['data' => $data]);
}
- public function rest_email_rollback_execute(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Email_Rollback')) {
+ public function rest_email_rollback_execute(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Auth\EmailRollback')) {
return $this->error(__('邮箱回滚功能不可用', 'aksrt'), 500);
}
$user_id = (int) $request->get_param('id');
- $result = AKSRT_Email_Rollback::rollback($user_id, get_current_user_id());
+ $result = \AKSRT\Auth\EmailRollback::rollback($user_id, get_current_user_id());
if (empty($result['success'])) {
return $this->error((string) ($result['error'] ?? __('邮箱回滚失败', 'aksrt')), 422);
}
diff --git a/inc/classes/admin/class-aksrt-admin-user-controller.php b/src/AKSRT/Admin/UserController.php
similarity index 86%
rename from inc/classes/admin/class-aksrt-admin-user-controller.php
rename to src/AKSRT/Admin/UserController.php
index d5ca95c8..25a79e5b 100644
--- a/inc/classes/admin/class-aksrt-admin-user-controller.php
+++ b/src/AKSRT/Admin/UserController.php
@@ -1,25 +1,19 @@
success(['message' => __('邮件模板已保存', 'aksrt')]);
}
- public function rest_handle_credit_settings(WP_REST_Request $request): WP_REST_Response {
+ public function rest_handle_credit_settings(\WP_REST_Request $request): \WP_REST_Response {
if ($request->get_method() === 'GET') {
- $config = AKSRT_Settings_Credits_Runtime::get_credit_settings();
+ $config = \AKSRT\Settings\CreditsRuntime::get_credit_settings();
return $this->success(['data' => $config]);
}
@@ -428,28 +422,28 @@ class AKSRT_Admin_User_Controller extends AKSRT_Admin_Controller_Base {
return $this->success(['message' => __('积分配置已保存', 'aksrt')]);
}
- public function rest_handle_auth_settings(WP_REST_Request $request): WP_REST_Response {
- $provider = AKSRT_Admin_Schema_Provider::get_instance();
+ public function rest_handle_auth_settings(\WP_REST_Request $request): \WP_REST_Response {
+ $provider = SchemaProvider::get_instance();
$allowed = $provider->get_allowed_fields('users', 'auth');
if ($request->get_method() === 'GET') {
- $data = AKSRT_Settings::get_all();
- $invite = class_exists('AKSRT_Settings_Credits_Runtime')
- ? AKSRT_Settings_Credits_Runtime::get_invite_registration_config()
+ $data = \AKSRT\Settings\Settings::get_all();
+ $invite = class_exists('\AKSRT\Settings\CreditsRuntime')
+ ? \AKSRT\Settings\CreditsRuntime::get_invite_registration_config()
: [];
return $this->success(['data' => [
- 'registration_email_verification_enabled' => AKSRT_Settings::registration_requires_email_verification(),
- 'registration_email_verification_method' => AKSRT_Settings::registration_verification_method(),
+ 'registration_email_verification_enabled' => \AKSRT\Settings\Settings::registration_requires_email_verification(),
+ 'registration_email_verification_method' => \AKSRT\Settings\Settings::registration_verification_method(),
'invite_registration_enabled' => $invite['enabled'] ?? true,
- 'invite_code_length' => class_exists('AKSRT_Settings') ? AKSRT_Settings::invite_code_length() : 6,
+ 'invite_code_length' => class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::invite_code_length() : 6,
'invite_register_field' => $invite['register_field'] ?? 'optional',
'invite_reject_invalid' => $invite['reject_invalid'] ?? false,
] + array_intersect_key($data, $allowed)]);
}
$params = $this->get_json_params($request);
- $settings = AKSRT_Settings::get_all();
+ $settings = \AKSRT\Settings\Settings::get_all();
$sanitized = $this->sanitize_fields($params, $allowed);
$settings = array_merge($settings, $sanitized);
@@ -477,30 +471,30 @@ class AKSRT_Admin_User_Controller extends AKSRT_Admin_Controller_Base {
}
update_option('aksrt_settings', $settings);
- AKSRT_Settings::flush_settings_cache();
+ \AKSRT\Settings\Settings::flush_settings_cache();
return $this->success(['message' => __('注册登录配置已保存', 'aksrt')]);
}
- public function rest_handle_notification_settings(WP_REST_Request $request): WP_REST_Response {
- $provider = AKSRT_Admin_Schema_Provider::get_instance();
+ public function rest_handle_notification_settings(\WP_REST_Request $request): \WP_REST_Response {
+ $provider = SchemaProvider::get_instance();
$allowed = $provider->get_allowed_fields('users', 'notifications');
if ($request->get_method() === 'GET') {
- $data = AKSRT_Settings::get_all();
+ $data = \AKSRT\Settings\Settings::get_all();
return $this->success(['data' => array_intersect_key($data, $allowed)]);
}
$params = $this->get_json_params($request);
- $settings = AKSRT_Settings::get_all();
+ $settings = \AKSRT\Settings\Settings::get_all();
$settings = array_merge($settings, $this->sanitize_fields($params, $allowed));
update_option('aksrt_settings', $settings);
- AKSRT_Settings::flush_settings_cache();
+ \AKSRT\Settings\Settings::flush_settings_cache();
return $this->success(['message' => __('消息通知配置已保存', 'aksrt')]);
}
- public function rest_get_notification_overview(WP_REST_Request $request): WP_REST_Response {
+ public function rest_get_notification_overview(\WP_REST_Request $request): \WP_REST_Response {
$page = max(1, (int) $request->get_param('page'));
$per_page = min(100, max(1, (int) $request->get_param('per_page')));
$type = sanitize_key((string) $request->get_param('type'));
@@ -508,19 +502,19 @@ class AKSRT_Admin_User_Controller extends AKSRT_Admin_Controller_Base {
$items = [];
$unread = 0;
- if (class_exists('AKSRT_Message')) {
+ if (class_exists('\AKSRT\Messages\Message')) {
$args = ['limit' => $per_page, 'offset' => ($page - 1) * $per_page];
if ($type !== '') {
$args['type'] = $type;
}
- $items = AKSRT_Message::get_instance()->get_notifications(get_current_user_id(), $args);
+ $items = \AKSRT\Messages\Message::get_instance()->get_notifications(get_current_user_id(), $args);
if ($is_read !== null && $is_read !== '') {
$want_read = (string) $is_read === '1';
$items = array_values(array_filter($items, static function ($item) use ($want_read) {
return !empty($item['is_read']) === $want_read;
}));
}
- $unread = AKSRT_Message::get_instance()->get_unread_count(get_current_user_id());
+ $unread = \AKSRT\Messages\Message::get_instance()->get_unread_count(get_current_user_id());
}
$total = count($items);
@@ -557,13 +551,13 @@ class AKSRT_Admin_User_Controller extends AKSRT_Admin_Controller_Base {
]]);
}
- public function rest_mark_notification_read(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Message')) {
+ public function rest_mark_notification_read(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Messages\Message')) {
return $this->success(['message' => __('消息系统未启用', 'aksrt')]);
}
$params = $this->get_json_params($request);
- $msg = AKSRT_Message::get_instance();
+ $msg = \AKSRT\Messages\Message::get_instance();
if (!empty($params['mark_all'])) {
$msg->mark_all_read(get_current_user_id());
} else {
@@ -576,7 +570,7 @@ class AKSRT_Admin_User_Controller extends AKSRT_Admin_Controller_Base {
return $this->success(['message' => __('已更新消息状态', 'aksrt')]);
}
- public function rest_delete_notification_item(WP_REST_Request $request): WP_REST_Response {
+ public function rest_delete_notification_item(\WP_REST_Request $request): \WP_REST_Response {
$user_id = get_current_user_id();
if ($user_id <= 0) {
return $this->error(__('请先登录', 'aksrt'), 401);
@@ -588,8 +582,8 @@ class AKSRT_Admin_User_Controller extends AKSRT_Admin_Controller_Base {
}
if (function_exists('aksrt_delete_user_notification')) {
aksrt_delete_user_notification($user_id, $id);
- } elseif (class_exists('AKSRT_Message')) {
- AKSRT_Message::get_instance()->mark_read($user_id, $id);
+ } elseif (class_exists('\AKSRT\Messages\Message')) {
+ \AKSRT\Messages\Message::get_instance()->mark_read($user_id, $id);
}
return $this->success([
'message' => __('消息已删除', 'aksrt'),
@@ -599,29 +593,29 @@ class AKSRT_Admin_User_Controller extends AKSRT_Admin_Controller_Base {
]);
}
- public function rest_run_notification_cleanup(WP_REST_Request $request): WP_REST_Response {
+ public function rest_run_notification_cleanup(\WP_REST_Request $request): \WP_REST_Response {
return $this->success(['message' => __('消息清理任务已受理', 'aksrt')]);
}
- public function rest_handle_oauth(WP_REST_Request $request): WP_REST_Response {
- $provider = AKSRT_Admin_Schema_Provider::get_instance();
+ public function rest_handle_oauth(\WP_REST_Request $request): \WP_REST_Response {
+ $provider = SchemaProvider::get_instance();
$allowed = $provider->get_allowed_fields('users', 'oauth');
if ($request->get_method() === 'GET') {
- $data = AKSRT_Settings::get_all();
+ $data = \AKSRT\Settings\Settings::get_all();
return $this->success(['data' => array_intersect_key($data, $allowed)]);
}
$params = $this->get_json_params($request);
- $settings = AKSRT_Settings::get_all();
+ $settings = \AKSRT\Settings\Settings::get_all();
$settings = array_merge($settings, $this->sanitize_fields($params, $allowed));
update_option('aksrt_settings', $settings);
- AKSRT_Settings::flush_settings_cache();
+ \AKSRT\Settings\Settings::flush_settings_cache();
return $this->success(['message' => __('第三方登录配置已保存', 'aksrt')]);
}
- public function rest_handle_oauth_proxy(WP_REST_Request $request): WP_REST_Response {
+ public function rest_handle_oauth_proxy(\WP_REST_Request $request): \WP_REST_Response {
$keys = [
'oauth_proxy_mode',
'oauth_proxy_secret',
@@ -632,7 +626,7 @@ class AKSRT_Admin_User_Controller extends AKSRT_Admin_Controller_Base {
];
if ($request->get_method() === 'GET') {
- $all = AKSRT_Settings::get_all();
+ $all = \AKSRT\Settings\Settings::get_all();
$data = [];
foreach ($keys as $key) {
$data[$key] = $all[$key] ?? null;
@@ -641,7 +635,7 @@ class AKSRT_Admin_User_Controller extends AKSRT_Admin_Controller_Base {
}
$params = $this->get_json_params($request);
- $settings = AKSRT_Settings::get_all();
+ $settings = \AKSRT\Settings\Settings::get_all();
foreach ($keys as $key) {
if (!array_key_exists($key, $params)) {
continue;
@@ -651,12 +645,12 @@ class AKSRT_Admin_User_Controller extends AKSRT_Admin_Controller_Base {
: sanitize_text_field((string) $params[$key]);
}
update_option('aksrt_settings', $settings);
- AKSRT_Settings::flush_settings_cache();
+ \AKSRT\Settings\Settings::flush_settings_cache();
return $this->success(['message' => __('OAuth 代理配置已保存', 'aksrt')]);
}
- public function rest_upload_user_background(WP_REST_Request $request): WP_REST_Response {
+ public function rest_upload_user_background(\WP_REST_Request $request): \WP_REST_Response {
$user_id = get_current_user_id();
if ($user_id <= 0) {
return $this->error(__('请先登录', 'aksrt'), 401);
@@ -688,7 +682,7 @@ class AKSRT_Admin_User_Controller extends AKSRT_Admin_Controller_Base {
]);
}
- public function rest_upload_comment_image(WP_REST_Request $request): WP_REST_Response {
+ public function rest_upload_comment_image(\WP_REST_Request $request): \WP_REST_Response {
$user_id = get_current_user_id();
if ($user_id <= 0) {
return $this->error(__('请先登录', 'aksrt'), 401);
@@ -718,26 +712,26 @@ class AKSRT_Admin_User_Controller extends AKSRT_Admin_Controller_Base {
]);
}
- public function rest_get_credits_me(WP_REST_Request $request): WP_REST_Response {
+ public function rest_get_credits_me(\WP_REST_Request $request): \WP_REST_Response {
$user_id = get_current_user_id();
return $this->success(['data' => [
'user_id' => $user_id,
- 'balance' => class_exists('AKSRT_Credits') ? AKSRT_Credits::balance($user_id) : 0,
+ 'balance' => class_exists('\AKSRT\Credits\Credits') ? \AKSRT\Credits\Credits::balance($user_id) : 0,
]]);
}
- public function rest_list_credit_users(WP_REST_Request $request): WP_REST_Response {
+ public function rest_list_credit_users(\WP_REST_Request $request): \WP_REST_Response {
$args = [
'search' => (string) $request->get_param('search'),
'page' => (int) $request->get_param('page'),
'per_page' => (int) $request->get_param('per_page'),
];
- $data = class_exists('AKSRT_Credits') ? AKSRT_Credits::list_users($args) : ['items' => [], 'total' => 0, 'page' => 1, 'per_page' => 20];
+ $data = class_exists('\AKSRT\Credits\Credits') ? \AKSRT\Credits\Credits::list_users($args) : ['items' => [], 'total' => 0, 'page' => 1, 'per_page' => 20];
return $this->success(['data' => $data]);
}
- public function rest_adjust_user_credits(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Credits')) {
+ public function rest_adjust_user_credits(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Credits\Credits')) {
return $this->error(__('积分系统不可用', 'aksrt'), 500);
}
@@ -751,9 +745,9 @@ class AKSRT_Admin_User_Controller extends AKSRT_Admin_Controller_Base {
}
if ($delta > 0) {
- $result = AKSRT_Credits::add($user_id, $delta, $reason, ['type' => 'user', 'id' => $user_id], 'Admin adjustment');
+ $result = \AKSRT\Credits\Credits::add($user_id, $delta, $reason, ['type' => 'user', 'id' => $user_id], 'Admin adjustment');
} else {
- $result = AKSRT_Credits::deduct($user_id, abs($delta), $reason, ['type' => 'user', 'id' => $user_id], 'Admin adjustment');
+ $result = \AKSRT\Credits\Credits::deduct($user_id, abs($delta), $reason, ['type' => 'user', 'id' => $user_id], 'Admin adjustment');
}
if (is_wp_error($result)) {
@@ -766,7 +760,7 @@ class AKSRT_Admin_User_Controller extends AKSRT_Admin_Controller_Base {
], 'message' => __('积分调整已保存', 'aksrt')]);
}
- public function rest_get_credits_log(WP_REST_Request $request): WP_REST_Response {
+ public function rest_get_credits_log(\WP_REST_Request $request): \WP_REST_Response {
$args = [
'user_id' => (int) $request->get_param('user_id'),
'reason' => (string) $request->get_param('reason'),
@@ -775,7 +769,7 @@ class AKSRT_Admin_User_Controller extends AKSRT_Admin_Controller_Base {
'date_from' => (string) $request->get_param('date_from'),
'date_to' => (string) $request->get_param('date_to'),
];
- $data = class_exists('AKSRT_Credits') ? AKSRT_Credits::get_log($args) : ['items' => [], 'total' => 0, 'page' => 1, 'per_page' => 20];
+ $data = class_exists('\AKSRT\Credits\Credits') ? \AKSRT\Credits\Credits::get_log($args) : ['items' => [], 'total' => 0, 'page' => 1, 'per_page' => 20];
return $this->success(['data' => $data]);
}
}
diff --git a/inc/classes/admin/class-aksrt-admin-user-controller-auth-phone-operations.php b/src/AKSRT/Admin/UserControllerAuthPhoneOperations.php
similarity index 82%
rename from inc/classes/admin/class-aksrt-admin-user-controller-auth-phone-operations.php
rename to src/AKSRT/Admin/UserControllerAuthPhoneOperations.php
index 30147474..90811194 100644
--- a/inc/classes/admin/class-aksrt-admin-user-controller-auth-phone-operations.php
+++ b/src/AKSRT/Admin/UserControllerAuthPhoneOperations.php
@@ -1,18 +1,18 @@
get_json_params($request);
$payload = is_array($params) ? $params : [];
$login = sanitize_text_field((string) ($payload['log'] ?? $payload['login'] ?? ''));
@@ -22,11 +22,11 @@ trait AKSRT_Admin_User_Controller_Auth_Phone_Operations {
return $this->error('请输入用户名和密码');
}
- if (!class_exists('AKSRT_Auth_Service')) {
+ if (!class_exists('\AKSRT\Auth\Service')) {
return $this->error('认证服务不可用', 500);
}
- $result = AKSRT_Auth_Service::login_user([
+ $result = \AKSRT\Auth\Service::login_user([
...$payload,
'log' => $login,
'pwd' => $password,
@@ -40,7 +40,7 @@ trait AKSRT_Admin_User_Controller_Auth_Phone_Operations {
if ($verify_url) {
$response['verify_url'] = $verify_url;
}
- return new WP_REST_Response($response, 401);
+ return new \WP_REST_Response($response, 401);
}
$user = wp_get_current_user();
@@ -60,7 +60,7 @@ trait AKSRT_Admin_User_Controller_Auth_Phone_Operations {
/**
* POST /auth/modal-register — 弹窗注册
*/
- public function modal_register(WP_REST_Request $request): WP_REST_Response {
+ public function modal_register(\WP_REST_Request $request): \WP_REST_Response {
$params = $this->get_json_params($request);
$payload = is_array($params) ? $params : [];
$username = sanitize_user((string) ($payload['user_login'] ?? $payload['username'] ?? ''), true);
@@ -83,7 +83,7 @@ trait AKSRT_Admin_User_Controller_Auth_Phone_Operations {
return $this->error('密码至少 6 位');
}
- if (!class_exists('AKSRT_Auth_Service')) {
+ if (!class_exists('\AKSRT\Auth\Service')) {
return $this->error('认证服务不可用', 500);
}
@@ -95,7 +95,7 @@ trait AKSRT_Admin_User_Controller_Auth_Phone_Operations {
$payload['_register_nonce'] = $register_nonce;
$payload['agree_terms'] = $agree_terms;
- $result = AKSRT_Auth_Service::register_user($payload);
+ $result = \AKSRT\Auth\Service::register_user($payload);
if (empty($result['success'])) {
return $this->error($result['error'] ?? '注册失败');
@@ -106,7 +106,7 @@ trait AKSRT_Admin_User_Controller_Auth_Phone_Operations {
$registered_user = null;
$current_user = wp_get_current_user();
if (
- $current_user instanceof WP_User
+ $current_user instanceof \WP_User
&& $current_user->ID > 0
&& !empty($result['user_id'])
&& (int) $result['user_id'] === (int) $current_user->ID
@@ -144,20 +144,20 @@ trait AKSRT_Admin_User_Controller_Auth_Phone_Operations {
/**
* GET /auth/me — 当前用户信息(用于 AJAX 刷新)
*/
- public function get_current_user_info(): WP_REST_Response {
+ public function get_current_user_info(): \WP_REST_Response {
$user = wp_get_current_user();
if (!$user->ID) {
return $this->error('未登录', 401);
}
$unread = 0;
- if (class_exists('AKSRT_Private_Message')) {
- $unread = AKSRT_Private_Message::get_instance()->get_unread_count($user->ID);
+ if (class_exists('\AKSRT\Messages\PrivateMessage')) {
+ $unread = \AKSRT\Messages\PrivateMessage::get_instance()->get_unread_count($user->ID);
}
$credits = 0;
- if (class_exists('AKSRT_Credits')) {
- $credits = AKSRT_Credits::balance($user->ID);
+ if (class_exists('\AKSRT\Credits\Credits')) {
+ $credits = \AKSRT\Credits\Credits::balance($user->ID);
}
return $this->success([
@@ -178,7 +178,7 @@ trait AKSRT_Admin_User_Controller_Auth_Phone_Operations {
/**
* POST /auth/send-sms-code — 发送短信验证码
*/
- public function auth_send_sms_code(WP_REST_Request $request): WP_REST_Response {
+ public function auth_send_sms_code(\WP_REST_Request $request): \WP_REST_Response {
$params = $this->get_json_params($request);
$phone = sanitize_text_field((string) ($params['phone'] ?? ''));
$scene = sanitize_key((string) ($params['scene'] ?? 'register'));
@@ -193,11 +193,11 @@ trait AKSRT_Admin_User_Controller_Auth_Phone_Operations {
}
}
- if (!class_exists('AKSRT_SMS')) {
+ if (!class_exists('\AKSRT\Sms\SMS')) {
return $this->error('短信服务不可用');
}
- $result = AKSRT_SMS::get_instance()->send_code($phone);
+ $result = \AKSRT\Sms\SMS::get_instance()->send_code($phone);
if (!empty($result['success'])) {
return $this->success([
@@ -213,19 +213,19 @@ trait AKSRT_Admin_User_Controller_Auth_Phone_Operations {
if (isset($result['remaining_time'])) {
$response['data'] = ['remaining_time' => $result['remaining_time']];
}
- return new WP_REST_Response($response, 400);
+ return new \WP_REST_Response($response, 400);
}
/**
* POST /auth/phone-register — 手机号注册
*/
- public function auth_phone_register(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Auth_Service')) {
+ public function auth_phone_register(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Auth\Service')) {
return $this->error('认证服务不可用');
}
$params = $this->get_json_params($request);
- $result = AKSRT_Auth_Service::register_by_phone($params);
+ $result = \AKSRT\Auth\Service::register_by_phone($params);
if (!empty($result['success'])) {
return $this->success([
@@ -241,13 +241,13 @@ trait AKSRT_Admin_User_Controller_Auth_Phone_Operations {
/**
* POST /auth/phone-login — 手机号 + 密码登录
*/
- public function auth_phone_login(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Auth_Service')) {
+ public function auth_phone_login(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Auth\Service')) {
return $this->error('认证服务不可用');
}
$params = $this->get_json_params($request);
- $result = AKSRT_Auth_Service::login_by_phone_password($params);
+ $result = \AKSRT\Auth\Service::login_by_phone_password($params);
if (!empty($result['success'])) {
return $this->success([
@@ -261,13 +261,13 @@ trait AKSRT_Admin_User_Controller_Auth_Phone_Operations {
/**
* POST /auth/phone-code-login — 手机号 + 验证码免密登录
*/
- public function auth_phone_code_login(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Auth_Service')) {
+ public function auth_phone_code_login(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Auth\Service')) {
return $this->error('认证服务不可用');
}
$params = $this->get_json_params($request);
- $result = AKSRT_Auth_Service::login_by_phone_code($params);
+ $result = \AKSRT\Auth\Service::login_by_phone_code($params);
if (!empty($result['success'])) {
return $this->success([
@@ -281,13 +281,13 @@ trait AKSRT_Admin_User_Controller_Auth_Phone_Operations {
/**
* POST /auth/bind-phone — 绑定手机号
*/
- public function auth_bind_phone(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Auth_Service')) {
+ public function auth_bind_phone(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Auth\Service')) {
return $this->error('认证服务不可用');
}
$params = $this->get_json_params($request);
- $result = AKSRT_Auth_Service::bind_phone($params);
+ $result = \AKSRT\Auth\Service::bind_phone($params);
if (!empty($result['success'])) {
return $this->success(['message' => $result['message']]);
diff --git a/inc/classes/admin/class-aksrt-admin-user-controller-follow-operations.php b/src/AKSRT/Admin/UserControllerFollowOperations.php
similarity index 58%
rename from inc/classes/admin/class-aksrt-admin-user-controller-follow-operations.php
rename to src/AKSRT/Admin/UserControllerFollowOperations.php
index c159ebde..f8e2dfb1 100644
--- a/inc/classes/admin/class-aksrt-admin-user-controller-follow-operations.php
+++ b/src/AKSRT/Admin/UserControllerFollowOperations.php
@@ -1,19 +1,19 @@
error('关注系统未启用', 500);
}
@@ -30,12 +30,12 @@ trait AKSRT_Admin_User_Controller_Follow_Operations {
return $this->error('用户不存在', 404);
}
- $is_following = AKSRT_Follow::get_instance()->toggle($current_user_id, $target_user_id);
+ $is_following = \AKSRT\User\Follow::get_instance()->toggle($current_user_id, $target_user_id);
return $this->success([
'data' => [
'is_following' => $is_following,
- 'follower_count' => AKSRT_Follow::get_instance()->get_follower_count($target_user_id),
+ 'follower_count' => \AKSRT\User\Follow::get_instance()->get_follower_count($target_user_id),
],
]);
}
@@ -43,8 +43,8 @@ trait AKSRT_Admin_User_Controller_Follow_Operations {
/**
* GET /follow/status — 查询关注状态
*/
- public function follow_status(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Follow')) {
+ public function follow_status(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\User\Follow')) {
return $this->success(['data' => ['is_following' => false]]);
}
@@ -55,13 +55,13 @@ trait AKSRT_Admin_User_Controller_Follow_Operations {
return $this->error('参数无效');
}
- $is_following = AKSRT_Follow::get_instance()->is_following($current_user_id, $target_user_id);
+ $is_following = \AKSRT\User\Follow::get_instance()->is_following($current_user_id, $target_user_id);
return $this->success([
'data' => [
'is_following' => $is_following,
- 'follower_count' => AKSRT_Follow::get_instance()->get_follower_count($target_user_id),
- 'following_count' => AKSRT_Follow::get_instance()->get_following_count($target_user_id),
+ 'follower_count' => \AKSRT\User\Follow::get_instance()->get_follower_count($target_user_id),
+ 'following_count' => \AKSRT\User\Follow::get_instance()->get_following_count($target_user_id),
],
]);
}
@@ -69,8 +69,8 @@ trait AKSRT_Admin_User_Controller_Follow_Operations {
/**
* GET /follow/counts — 获取关注/粉丝数
*/
- public function follow_counts(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Follow')) {
+ public function follow_counts(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\User\Follow')) {
return $this->success(['data' => ['followers' => 0, 'following' => 0]]);
}
@@ -81,8 +81,8 @@ trait AKSRT_Admin_User_Controller_Follow_Operations {
return $this->success([
'data' => [
- 'followers' => AKSRT_Follow::get_instance()->get_follower_count($user_id),
- 'following' => AKSRT_Follow::get_instance()->get_following_count($user_id),
+ 'followers' => \AKSRT\User\Follow::get_instance()->get_follower_count($user_id),
+ 'following' => \AKSRT\User\Follow::get_instance()->get_following_count($user_id),
],
]);
}
diff --git a/inc/classes/admin/class-aksrt-admin-user-controller-invite-operations.php b/src/AKSRT/Admin/UserControllerInviteOperations.php
similarity index 95%
rename from inc/classes/admin/class-aksrt-admin-user-controller-invite-operations.php
rename to src/AKSRT/Admin/UserControllerInviteOperations.php
index 4f664706..e2968e56 100644
--- a/inc/classes/admin/class-aksrt-admin-user-controller-invite-operations.php
+++ b/src/AKSRT/Admin/UserControllerInviteOperations.php
@@ -1,18 +1,18 @@
get_param('page') ?: 1));
@@ -24,7 +24,7 @@ trait AKSRT_Admin_User_Controller_Invite_Operations {
$date_to = sanitize_text_field((string) $request->get_param('date_to'));
$usermeta_table = $wpdb->usermeta;
- $invite_table = class_exists('AKSRT_DB_Migrator') ? AKSRT_DB_Migrator::table('invite') : '';
+ $invite_table = class_exists('\AKSRT\Core\DBMigrator') ? \AKSRT\Core\DBMigrator::table('invite') : '';
$invite_rows = [];
if ($invite_table) {
@@ -147,8 +147,8 @@ trait AKSRT_Admin_User_Controller_Invite_Operations {
* Body: { count: int, length: int, prefix: string }
* 为指定用户或批量创建邀请码。
*/
- public function generate_invite_codes(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Invite')) {
+ public function generate_invite_codes(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Credits\Invite')) {
return $this->error(__('邀请系统未启用', 'aksrt'), 500);
}
@@ -213,7 +213,7 @@ trait AKSRT_Admin_User_Controller_Invite_Operations {
/**
* POST /invite/codes/{id}/disable — 禁用邀请码
*/
- public function disable_invite_code(WP_REST_Request $request): WP_REST_Response {
+ public function disable_invite_code(\WP_REST_Request $request): \WP_REST_Response {
$user_id = (int) $request->get_param('id');
if ($user_id <= 0) {
@@ -228,7 +228,7 @@ trait AKSRT_Admin_User_Controller_Invite_Operations {
return $this->success(['message' => __('邀请码已禁用', 'aksrt')]);
}
- public function bulk_update_invite_codes(WP_REST_Request $request): WP_REST_Response {
+ public function bulk_update_invite_codes(\WP_REST_Request $request): \WP_REST_Response {
$params = $this->get_json_params($request);
$action = sanitize_key((string) ($params['action'] ?? ''));
$targets = isset($params['targets']) && is_array($params['targets']) ? $params['targets'] : [];
@@ -282,7 +282,7 @@ trait AKSRT_Admin_User_Controller_Invite_Operations {
/**
* GET /invite/stats — 邀请系统统计
*/
- public function get_invite_stats(): WP_REST_Response {
+ public function get_invite_stats(): \WP_REST_Response {
global $wpdb;
$items = [];
@@ -341,7 +341,7 @@ trait AKSRT_Admin_User_Controller_Invite_Operations {
}
}
- $invite_table = class_exists('AKSRT_DB_Migrator') ? AKSRT_DB_Migrator::table('invite') : '';
+ $invite_table = class_exists('\AKSRT\Core\DBMigrator') ? \AKSRT\Core\DBMigrator::table('invite') : '';
if ($invite_table) {
$existing_invite = $wpdb->get_var($wpdb->prepare(
"SELECT id FROM {$invite_table} WHERE invite_code = %s LIMIT 1",
diff --git a/inc/classes/admin/class-aksrt-admin-user-controller-report-operations.php b/src/AKSRT/Admin/UserControllerReportOperations.php
similarity index 92%
rename from inc/classes/admin/class-aksrt-admin-user-controller-report-operations.php
rename to src/AKSRT/Admin/UserControllerReportOperations.php
index 3495f286..e6d5608a 100644
--- a/inc/classes/admin/class-aksrt-admin-user-controller-report-operations.php
+++ b/src/AKSRT/Admin/UserControllerReportOperations.php
@@ -1,16 +1,16 @@
success([
'data' => [
'items' => [],
@@ -27,7 +27,7 @@ trait AKSRT_Admin_User_Controller_Report_Operations {
global $wpdb;
- $table = AKSRT_DB_Migrator::table('report');
+ $table = \AKSRT\Core\DBMigrator::table('report');
if (!$table) {
return $this->success([
'data' => [
@@ -92,7 +92,7 @@ trait AKSRT_Admin_User_Controller_Report_Operations {
$total = count($items);
$offset = ($page - 1) * $per_page;
$paged = array_slice($items, $offset, $per_page);
- $counts = AKSRT_Report_Center::get_instance()->get_status_counts();
+ $counts = \AKSRT\Messages\ReportCenter::get_instance()->get_status_counts();
$categories = [];
foreach ((array) $rows as $row) {
$cat = sanitize_key((string) ($row['category'] ?? ''));
@@ -121,8 +121,8 @@ trait AKSRT_Admin_User_Controller_Report_Operations {
]);
}
- public function update_report_status(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Report_Center')) {
+ public function update_report_status(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Messages\ReportCenter')) {
return $this->error(__('举报系统未启用', 'aksrt'));
}
@@ -135,18 +135,18 @@ trait AKSRT_Admin_User_Controller_Report_Operations {
return $this->handle_report_process($report_id, $params);
}
- public function get_report_counts(): WP_REST_Response {
- if (!class_exists('AKSRT_Report_Center')) {
+ public function get_report_counts(): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Messages\ReportCenter')) {
return $this->success(['pending' => 0, 'reviewing' => 0, 'resolved' => 0, 'dismissed' => 0, 'total' => 0]);
}
- return $this->success(AKSRT_Report_Center::get_instance()->get_status_counts());
+ return $this->success(\AKSRT\Messages\ReportCenter::get_instance()->get_status_counts());
}
- public function get_report_detail(WP_REST_Request $request): WP_REST_Response {
+ public function get_report_detail(\WP_REST_Request $request): \WP_REST_Response {
global $wpdb;
$report_id = (int) $request->get_param('id');
- $table = AKSRT_DB_Migrator::table('report');
+ $table = \AKSRT\Core\DBMigrator::table('report');
if ($report_id <= 0 || !$table) {
return $this->error(__('举报工单不存在', 'aksrt'), 404);
@@ -175,7 +175,7 @@ trait AKSRT_Admin_User_Controller_Report_Operations {
]);
}
- public function process_report(WP_REST_Request $request): WP_REST_Response {
+ public function process_report(\WP_REST_Request $request): \WP_REST_Response {
$report_id = (int) $request->get_param('id');
if ($report_id <= 0) {
return $this->error(__('参数无效', 'aksrt'));
@@ -184,10 +184,10 @@ trait AKSRT_Admin_User_Controller_Report_Operations {
return $this->handle_report_process($report_id, $this->get_json_params($request));
}
- private function handle_report_process(int $report_id, array $payload): WP_REST_Response {
+ private function handle_report_process(int $report_id, array $payload): \WP_REST_Response {
global $wpdb;
- $table = AKSRT_DB_Migrator::table('report');
+ $table = \AKSRT\Core\DBMigrator::table('report');
if (!$table) {
return $this->error(__('举报系统未启用', 'aksrt'));
}
@@ -324,7 +324,7 @@ trait AKSRT_Admin_User_Controller_Report_Operations {
if ($target_type === 'post') {
$post = get_post($target_id);
- if ($post instanceof WP_Post) {
+ if ($post instanceof \WP_Post) {
$summary['title'] = get_the_title($post);
$summary['status'] = (string) $post->post_status;
$summary['url'] = get_permalink($post);
@@ -342,7 +342,7 @@ trait AKSRT_Admin_User_Controller_Report_Operations {
}
} elseif ($target_type === 'user') {
$user = get_userdata($target_id);
- if ($user instanceof WP_User) {
+ if ($user instanceof \WP_User) {
$summary['display_name'] = $user->display_name;
$summary['title'] = $user->display_name;
$summary['url'] = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($target_id) : '';
@@ -431,8 +431,8 @@ trait AKSRT_Admin_User_Controller_Report_Operations {
/**
* POST /report/submit — 前台举报提交(登录用户)
*/
- public function submit_report(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_Report_Center')) {
+ public function submit_report(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Messages\ReportCenter')) {
return $this->error('举报系统未启用', 500);
}
@@ -451,7 +451,7 @@ trait AKSRT_Admin_User_Controller_Report_Operations {
return $this->error('无效的举报类型');
}
- $report_id = AKSRT_Report_Center::get_instance()->submit(
+ $report_id = \AKSRT\Messages\ReportCenter::get_instance()->submit(
get_current_user_id(),
$target_type,
$target_id,
diff --git a/inc/classes/admin/class-aksrt-admin-user-controller-restriction-operations.php b/src/AKSRT/Admin/UserControllerRestrictionOperations.php
similarity index 64%
rename from inc/classes/admin/class-aksrt-admin-user-controller-restriction-operations.php
rename to src/AKSRT/Admin/UserControllerRestrictionOperations.php
index 561021e9..92769ed0 100644
--- a/inc/classes/admin/class-aksrt-admin-user-controller-restriction-operations.php
+++ b/src/AKSRT/Admin/UserControllerRestrictionOperations.php
@@ -1,30 +1,30 @@
get_param('user_id');
$user = get_userdata($user_id);
if (!$user) {
return $this->error('用户不存在', 404);
}
- if (!class_exists('AKSRT_User_Restriction')) {
+ if (!class_exists('\AKSRT\User\Restriction')) {
return $this->success(['data' => ['restrictions' => []]]);
}
- $restrictions = AKSRT_User_Restriction::get_instance()->get_user_restrictions($user_id, false);
+ $restrictions = \AKSRT\User\Restriction::get_instance()->get_user_restrictions($user_id, false);
return $this->success(['data' => ['restrictions' => $restrictions]]);
}
- public function add_user_restriction(WP_REST_Request $request): WP_REST_Response {
+ public function add_user_restriction(\WP_REST_Request $request): \WP_REST_Response {
$user_id = (int) $request->get_param('user_id');
$user = get_userdata($user_id);
if (!$user) {
@@ -41,11 +41,11 @@ trait AKSRT_Admin_User_Controller_Restriction_Operations {
return $this->error('请选择限制类型');
}
- if (!class_exists('AKSRT_User_Restriction')) {
+ if (!class_exists('\AKSRT\User\Restriction')) {
return $this->error('限制系统未启用', 501);
}
- $result = AKSRT_User_Restriction::get_instance()->restrict(
+ $result = \AKSRT\User\Restriction::get_instance()->restrict(
$user_id, $type, $reason, $scope, $expires_at, get_current_user_id()
);
@@ -56,14 +56,14 @@ trait AKSRT_Admin_User_Controller_Restriction_Operations {
return $this->success(['message' => '限制已添加', 'data' => $result]);
}
- public function remove_user_restriction(WP_REST_Request $request): WP_REST_Response {
+ public function remove_user_restriction(\WP_REST_Request $request): \WP_REST_Response {
$restriction_id = (int) $request->get_param('id');
- if (!class_exists('AKSRT_User_Restriction')) {
+ if (!class_exists('\AKSRT\User\Restriction')) {
return $this->error('限制系统未启用', 501);
}
- $result = AKSRT_User_Restriction::get_instance()->remove_restriction($restriction_id);
+ $result = \AKSRT\User\Restriction::get_instance()->remove_restriction($restriction_id);
if (!$result) {
return $this->error('移除失败', 500);
}
@@ -71,12 +71,12 @@ trait AKSRT_Admin_User_Controller_Restriction_Operations {
return $this->success(['message' => '限制已移除']);
}
- public function get_restriction_stats(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_User_Restriction')) {
+ public function get_restriction_stats(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\User\Restriction')) {
return $this->success(['data' => ['total' => 0, 'active' => 0, 'banned' => 0]]);
}
- $stats = AKSRT_User_Restriction::get_instance()->get_stats();
+ $stats = \AKSRT\User\Restriction::get_instance()->get_stats();
return $this->success(['data' => $stats]);
}
}
diff --git a/inc/classes/admin/class-aksrt-admin-user-controller-verify-integrations.php b/src/AKSRT/Admin/UserControllerVerifyIntegrations.php
similarity index 88%
rename from inc/classes/admin/class-aksrt-admin-user-controller-verify-integrations.php
rename to src/AKSRT/Admin/UserControllerVerifyIntegrations.php
index 70903e67..d278dae4 100644
--- a/inc/classes/admin/class-aksrt-admin-user-controller-verify-integrations.php
+++ b/src/AKSRT/Admin/UserControllerVerifyIntegrations.php
@@ -1,16 +1,16 @@
get_verify_requests(new WP_REST_Request('GET', '/'));
+ public function get_verify_pending(): \WP_REST_Response {
+ $response = $this->get_verify_requests(new \WP_REST_Request('GET', '/'));
$data = $response->get_data();
$items = isset($data['data']['items']) && is_array($data['data']['items']) ? $data['data']['items'] : [];
$pending = array_values(array_filter($items, static function ($item) {
@@ -25,7 +25,7 @@ trait AKSRT_Admin_User_Controller_Verify_Integrations {
]);
}
- public function get_verify_requests(WP_REST_Request $request): WP_REST_Response {
+ public function get_verify_requests(\WP_REST_Request $request): \WP_REST_Response {
global $wpdb;
$page = max(1, (int) ($request->get_param('page') ?: 1));
@@ -109,7 +109,7 @@ trait AKSRT_Admin_User_Controller_Verify_Integrations {
]);
}
- public function get_verify_request_detail(WP_REST_Request $request): WP_REST_Response {
+ public function get_verify_request_detail(\WP_REST_Request $request): \WP_REST_Response {
$user_id = (int) $request->get_param('id');
if ($user_id <= 0) {
return $this->error(__('认证申请不存在', 'aksrt'), 404);
@@ -148,7 +148,7 @@ trait AKSRT_Admin_User_Controller_Verify_Integrations {
/**
* POST /verify/review — approve or reject a verification request.
*/
- public function review_verify_request(WP_REST_Request $request): WP_REST_Response {
+ public function review_verify_request(\WP_REST_Request $request): \WP_REST_Response {
$params = $this->get_json_params($request);
$user_id = (int) ($params['user_id'] ?? 0);
if ($user_id <= 0) {
@@ -158,7 +158,7 @@ trait AKSRT_Admin_User_Controller_Verify_Integrations {
return $this->perform_verify_review($user_id, $params);
}
- public function review_verify_request_by_id(WP_REST_Request $request): WP_REST_Response {
+ public function review_verify_request_by_id(\WP_REST_Request $request): \WP_REST_Response {
$user_id = (int) $request->get_param('id');
if ($user_id <= 0) {
return $this->error(__('参数无效', 'aksrt'));
@@ -167,7 +167,7 @@ trait AKSRT_Admin_User_Controller_Verify_Integrations {
return $this->perform_verify_review($user_id, $this->get_json_params($request));
}
- private function perform_verify_review(int $user_id, array $payload): WP_REST_Response {
+ private function perform_verify_review(int $user_id, array $payload): \WP_REST_Response {
$status = sanitize_key((string) ($payload['status'] ?? ''));
$note = sanitize_textarea_field((string) ($payload['note'] ?? ($payload['reason'] ?? '')));
@@ -264,14 +264,14 @@ trait AKSRT_Admin_User_Controller_Verify_Integrations {
}
private function build_admin_user_summary(int $user_id, $user = null): ?array {
- if ($user_id <= 0 && !$user instanceof WP_User) {
+ if ($user_id <= 0 && !$user instanceof \WP_User) {
return null;
}
- if (!$user instanceof WP_User) {
+ if (!$user instanceof \WP_User) {
$user = get_userdata($user_id);
}
- if (!$user instanceof WP_User) {
+ if (!$user instanceof \WP_User) {
return null;
}
@@ -286,9 +286,9 @@ trait AKSRT_Admin_User_Controller_Verify_Integrations {
/**
* GET /sms/status — SMS provider connection status.
*/
- public function get_sms_status(): WP_REST_Response {
- if (class_exists('AKSRT_SMS')) {
- return $this->success(['data' => AKSRT_SMS::get_instance()->get_provider_status()]);
+ public function get_sms_status(): \WP_REST_Response {
+ if (class_exists('\AKSRT\Sms\SMS')) {
+ return $this->success(['data' => \AKSRT\Sms\SMS::get_instance()->get_provider_status()]);
}
return $this->success([
@@ -313,8 +313,8 @@ trait AKSRT_Admin_User_Controller_Verify_Integrations {
/**
* POST /sms/test — Send a test SMS to verify provider configuration.
*/
- public function test_sms_send(WP_REST_Request $request): WP_REST_Response {
- if (!class_exists('AKSRT_SMS')) {
+ public function test_sms_send(\WP_REST_Request $request): \WP_REST_Response {
+ if (!class_exists('\AKSRT\Sms\SMS')) {
return $this->error('短信服务不可用');
}
@@ -325,7 +325,7 @@ trait AKSRT_Admin_User_Controller_Verify_Integrations {
return $this->error('手机号格式不正确');
}
- $result = AKSRT_SMS::get_instance()->test_provider($phone);
+ $result = \AKSRT\Sms\SMS::get_instance()->test_provider($phone);
if (!empty($result['success'])) {
return $this->success(['message' => $result['message'] ?? '发送成功']);
@@ -337,9 +337,9 @@ trait AKSRT_Admin_User_Controller_Verify_Integrations {
/**
* GET /wechat/status — WeChat notification service status.
*/
- public function get_wechat_status(): WP_REST_Response {
- if (class_exists('AKSRT_WeChat_Notify')) {
- return $this->success(['data' => AKSRT_WeChat_Notify::get_instance()->get_status()]);
+ public function get_wechat_status(): \WP_REST_Response {
+ if (class_exists('\AKSRT\Payment\WeChatNotify')) {
+ return $this->success(['data' => \AKSRT\Payment\WeChatNotify::get_instance()->get_status()]);
}
return $this->success([
@@ -355,7 +355,7 @@ trait AKSRT_Admin_User_Controller_Verify_Integrations {
/**
* POST /wechat/settings — 更新微信通知设置
*/
- public function update_wechat_settings(WP_REST_Request $request): WP_REST_Response {
+ public function update_wechat_settings(\WP_REST_Request $request): \WP_REST_Response {
$params = $this->get_json_params($request);
$settings = [
@@ -365,13 +365,13 @@ trait AKSRT_Admin_User_Controller_Verify_Integrations {
'template_id' => sanitize_text_field((string) ($params['template_id'] ?? '')),
];
- $existing = AKSRT_Settings::get_wechat_settings();
+ $existing = \AKSRT\Settings\Settings::get_wechat_settings();
if ($settings['app_secret'] === '***') {
$settings['app_secret'] = $existing['app_secret'] ?? '';
}
$merged = array_merge($existing, $settings);
- AKSRT_Settings::update_wechat_settings($merged);
+ \AKSRT\Settings\Settings::update_wechat_settings($merged);
delete_transient('aksrt_wechat_token');
return $this->success(['message' => __('微信设置已保存', 'aksrt')]);
diff --git a/inc/classes/ai/class-aksrt-ai.php b/src/AKSRT/Ai/AI.php
similarity index 97%
rename from inc/classes/ai/class-aksrt-ai.php
rename to src/AKSRT/Ai/AI.php
index e1c5e6cc..8c7efdb8 100644
--- a/inc/classes/ai/class-aksrt-ai.php
+++ b/src/AKSRT/Ai/AI.php
@@ -1,17 +1,13 @@
get_config();
- $seo = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_seo_settings() : [];
+ $seo = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_seo_settings() : [];
return [
'enabled' => !empty($config['enabled']),
diff --git a/inc/classes/ai/class-aksrt-ai-prompt.php b/src/AKSRT/Ai/AIPrompt.php
similarity index 97%
rename from inc/classes/ai/class-aksrt-ai-prompt.php
rename to src/AKSRT/Ai/AIPrompt.php
index b6c46a87..871859f1 100644
--- a/inc/classes/ai/class-aksrt-ai-prompt.php
+++ b/src/AKSRT/Ai/AIPrompt.php
@@ -1,13 +1,13 @@
false,
'message' => __('AI 模块未加载', 'aksrt'),
];
}
- $ai = AKSRT_AI::get_instance();
+ $ai = AI::get_instance();
if (!$ai->is_available()) {
return [
'success' => false,
@@ -76,7 +76,7 @@ class AKSRT_AI_SEO {
];
}
- $prompt = AKSRT_AI_Prompt::get_instance();
+ $prompt = AIPrompt::get_instance();
$title = $this->run_field(
$ai,
@@ -115,11 +115,11 @@ class AKSRT_AI_SEO {
return ['success' => false, 'message' => __('AI SEO 功能未启用', 'aksrt')];
}
- if (!class_exists('AKSRT_AI') || !class_exists('AKSRT_AI_Prompt')) {
+ if (!class_exists('AI') || !class_exists('AIPrompt')) {
return ['success' => false, 'message' => __('AI 模块未加载', 'aksrt')];
}
- $ai = AKSRT_AI::get_instance();
+ $ai = AI::get_instance();
if (!$ai->is_available()) {
return ['success' => false, 'message' => __('AI 服务未启用', 'aksrt')];
}
@@ -142,7 +142,7 @@ class AKSRT_AI_SEO {
$parts[] = "正文:\n" . $content;
}
$context = implode("\n\n", $parts);
- $prompt = AKSRT_AI_Prompt::get_instance();
+ $prompt = AIPrompt::get_instance();
$title_out = $this->run_field($ai, $context, $prompt->get_seo_title_system_instruction(), 'title');
$kw_out = $this->run_field($ai, $context, $prompt->get_seo_keywords_system_instruction(), 'keywords');
@@ -169,12 +169,12 @@ class AKSRT_AI_SEO {
}
/**
- * @return string|WP_Error
+ * @return string|\WP_Error
*/
public function build_post_context(int $post_id, int $word_limit = 1500) {
$post = get_post($post_id);
if (!$post) {
- return new WP_Error('no_post', __('内容不存在', 'aksrt'));
+ return new \WP_Error('no_post', __('内容不存在', 'aksrt'));
}
$title = trim((string) $post->post_title);
@@ -184,7 +184,7 @@ class AKSRT_AI_SEO {
$content = wp_trim_words($content, max(50, $word_limit), '');
if ($title === '' && $content === '' && $excerpt === '') {
- return new WP_Error('empty_content', __('无可用内容,请先填写标题、摘要或正文并保存', 'aksrt'));
+ return new \WP_Error('empty_content', __('无可用内容,请先填写标题、摘要或正文并保存', 'aksrt'));
}
$parts = [];
@@ -202,12 +202,12 @@ class AKSRT_AI_SEO {
}
/**
- * @return string|WP_Error
+ * @return string|\WP_Error
*/
public function build_term_context(int $term_id) {
$term = get_term($term_id);
if (!$term || is_wp_error($term)) {
- return new WP_Error('no_term', __('分类/标签不存在', 'aksrt'));
+ return new \WP_Error('no_term', __('分类/标签不存在', 'aksrt'));
}
$parts = [];
@@ -219,7 +219,7 @@ class AKSRT_AI_SEO {
}
if (empty($parts)) {
- return new WP_Error('empty_term', __('没有可用的标题或描述', 'aksrt'));
+ return new \WP_Error('empty_term', __('没有可用的标题或描述', 'aksrt'));
}
return implode("\n\n", $parts);
@@ -228,7 +228,7 @@ class AKSRT_AI_SEO {
/**
* @return array{content?:string,error?:string}
*/
- private function run_field(AKSRT_AI $ai, string $context, string $system, string $field): array {
+ private function run_field(AI $ai, string $context, string $system, string $field): array {
$result = $ai->generate_text($context, [
'system_instruction' => $system,
'max_tokens' => $field === 'description' ? 400 : 300,
@@ -255,7 +255,7 @@ class AKSRT_AI_SEO {
if ($field === 'title') {
$title = sanitize_text_field($raw);
- $seo = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_seo_settings() : [];
+ $seo = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_seo_settings() : [];
$conn = trim((string) ($seo['seo_connector'] ?? '-')) ?: '-';
$site = trim((string) get_bloginfo('name'));
if ($site !== '' && $title !== '' && mb_stripos($title, $site) === false) {
diff --git a/inc/classes/auth/class-aksrt-email-rollback.php b/src/AKSRT/Auth/EmailRollback.php
similarity index 91%
rename from inc/classes/auth/class-aksrt-email-rollback.php
rename to src/AKSRT/Auth/EmailRollback.php
index 71aba2cd..2aa4e31e 100644
--- a/inc/classes/auth/class-aksrt-email-rollback.php
+++ b/src/AKSRT/Auth/EmailRollback.php
@@ -1,24 +1,13 @@
10) $log = array_slice($log, -10);
update_user_meta($user_id, 'aksrt_email_verification_admin_log', $log);
- if (class_exists('AKSRT_Auth_Service')) {
- AKSRT_Auth_Service::log_event('admin.email_rollback', [
+ if (class_exists('Service')) {
+ Service::log_event('admin.email_rollback', [
'uid' => $user_id,
'by' => $by_admin_id ?: get_current_user_id(),
]);
@@ -194,7 +183,7 @@ class AKSRT_Email_Rollback {
/**
* 在用户列表行操作中加入"回滚邮箱"。
*/
- public function add_row_action(array $actions, WP_User $user): array {
+ public function add_row_action(array $actions, \WP_User $user): array {
if (!current_user_can('edit_user', $user->ID)) return $actions;
if (!self::is_within_window((int) $user->ID)) return $actions;
diff --git a/inc/classes/auth/class-aksrt-auth-email-verification.php b/src/AKSRT/Auth/EmailVerification.php
similarity index 66%
rename from inc/classes/auth/class-aksrt-auth-email-verification.php
rename to src/AKSRT/Auth/EmailVerification.php
index da1b6dc5..eb8df91b 100644
--- a/inc/classes/auth/class-aksrt-auth-email-verification.php
+++ b/src/AKSRT/Auth/EmailVerification.php
@@ -1,26 +1,20 @@
self::is_email_verified($user_id),
- 'method' => (string) get_user_meta($user_id, AKSRT_Auth_Service::EMAIL_METHOD_META, true),
- 'target_email' => (string) get_user_meta($user_id, AKSRT_Auth_Service::EMAIL_TARGET_META, true),
- 'expires_at' => (int) get_user_meta($user_id, AKSRT_Auth_Service::EMAIL_EXPIRES_META, true),
- 'requested_at' => (int) get_user_meta($user_id, AKSRT_Auth_Service::EMAIL_REQUESTED_AT_META, true),
+ 'method' => (string) get_user_meta($user_id, Service::EMAIL_METHOD_META, true),
+ 'target_email' => (string) get_user_meta($user_id, Service::EMAIL_TARGET_META, true),
+ 'expires_at' => (int) get_user_meta($user_id, Service::EMAIL_EXPIRES_META, true),
+ 'requested_at' => (int) get_user_meta($user_id, Service::EMAIL_REQUESTED_AT_META, true),
'last_admin_log' => (array) (get_user_meta($user_id, 'aksrt_email_verification_admin_log', true) ?: []),
];
}
@@ -92,7 +86,7 @@ class AKSRT_Auth_Email_Verification {
}
self::mark_email_verified($user_id);
self::record_admin_action($user_id, 'mark_verified', $by_admin_id);
- AKSRT_Auth_Service::log_event('admin.action', ['action' => 'mark_verified', 'uid' => $user_id, 'by' => $by_admin_id]);
+ Service::log_event('admin.action', ['action' => 'mark_verified', 'uid' => $user_id, 'by' => $by_admin_id]);
return ['success' => true, 'message' => __('已标记为已验证', 'aksrt')];
}
@@ -106,10 +100,10 @@ class AKSRT_Auth_Email_Verification {
if (!current_user_can('edit_user', $user_id)) {
return ['success' => false, 'error' => __('权限不足', 'aksrt')];
}
- update_user_meta($user_id, AKSRT_Auth_Service::EMAIL_VERIFIED_META, 0);
+ update_user_meta($user_id, Service::EMAIL_VERIFIED_META, 0);
self::clear_email_verification($user_id);
self::record_admin_action($user_id, 'unmark_verified', $by_admin_id);
- AKSRT_Auth_Service::log_event('admin.action', ['action' => 'unmark_verified', 'uid' => $user_id, 'by' => $by_admin_id]);
+ Service::log_event('admin.action', ['action' => 'unmark_verified', 'uid' => $user_id, 'by' => $by_admin_id]);
return ['success' => true, 'message' => __('已撤销验证状态', 'aksrt')];
}
/**
@@ -127,10 +121,10 @@ class AKSRT_Auth_Email_Verification {
return ['success' => false, 'error' => __('用户不存在', 'aksrt')];
}
- $method = AKSRT_Auth_Service::current_registration_verification_method();
- $email = (string) get_user_meta($user_id, AKSRT_Auth_Service::EMAIL_TARGET_META, true);
+ $method = Service::current_registration_verification_method();
+ $email = (string) get_user_meta($user_id, Service::EMAIL_TARGET_META, true);
if (!in_array($method, ['link', 'code'], true)) {
- $method = AKSRT_Settings::registration_verification_method();
+ $method = \AKSRT\Settings\Settings::registration_verification_method();
}
if ($email === '' || !is_email($email)) {
$email = (string) $user->user_email;
@@ -138,16 +132,16 @@ class AKSRT_Auth_Email_Verification {
$result = self::begin_email_verification($user, $method, [
'email' => $email,
- 'obk' => (string) get_user_meta($user_id, AKSRT_Auth_Service::EMAIL_OBK_META, true),
+ 'obk' => (string) get_user_meta($user_id, Service::EMAIL_OBK_META, true),
'bypass_throttle' => true,
'force' => true,
]);
// 标记为待验证(确保 admin 主动发邮件后用户被视为未验证)
if (!empty($result['success'])) {
- update_user_meta($user_id, AKSRT_Auth_Service::EMAIL_VERIFIED_META, 0);
+ update_user_meta($user_id, Service::EMAIL_VERIFIED_META, 0);
self::record_admin_action($user_id, 'send_verification', $by_admin_id);
- AKSRT_Auth_Service::log_event('admin.action', ['action' => 'send_verification', 'uid' => $user_id, 'by' => $by_admin_id]);
+ Service::log_event('admin.action', ['action' => 'send_verification', 'uid' => $user_id, 'by' => $by_admin_id]);
}
return $result;
@@ -197,7 +191,7 @@ class AKSRT_Auth_Email_Verification {
'fields' => ['ID'],
'meta_query' => [
[
- 'key' => AKSRT_Auth_Service::EMAIL_VERIFIED_META,
+ 'key' => Service::EMAIL_VERIFIED_META,
'compare' => 'NOT EXISTS',
],
],
@@ -208,7 +202,7 @@ class AKSRT_Auth_Email_Verification {
}
foreach ($users as $u) {
- update_user_meta((int) $u->ID, AKSRT_Auth_Service::EMAIL_VERIFIED_META, 1);
+ update_user_meta((int) $u->ID, Service::EMAIL_VERIFIED_META, 1);
$updated++;
}
@@ -226,7 +220,7 @@ class AKSRT_Auth_Email_Verification {
'ran_at' => time(),
'by' => get_current_user_id(),
]);
- AKSRT_Auth_Service::log_event('admin.backfill', ['count' => $updated, 'by' => get_current_user_id()]);
+ Service::log_event('admin.backfill', ['count' => $updated, 'by' => get_current_user_id()]);
return $updated;
}
@@ -243,7 +237,7 @@ class AKSRT_Auth_Email_Verification {
'order' => 'ASC',
'meta_query' => [
[
- 'key' => AKSRT_Auth_Service::EMAIL_VERIFIED_META,
+ 'key' => Service::EMAIL_VERIFIED_META,
'compare' => 'NOT EXISTS',
],
],
@@ -254,12 +248,12 @@ class AKSRT_Auth_Email_Verification {
$log = (array) get_option('aksrt_email_verification_backfill_log', []);
$log['finished_at'] = time();
update_option('aksrt_email_verification_backfill_log', $log);
- AKSRT_Auth_Service::log_event('admin.backfill.finished', []);
+ Service::log_event('admin.backfill.finished', []);
return;
}
foreach ($users as $u) {
- update_user_meta((int) $u->ID, AKSRT_Auth_Service::EMAIL_VERIFIED_META, 1);
+ update_user_meta((int) $u->ID, Service::EMAIL_VERIFIED_META, 1);
}
// 调度下一批
@@ -298,7 +292,7 @@ class AKSRT_Auth_Email_Verification {
}
public static function reset_email_code_attempt_trackers(int $user_id): void {
- delete_user_meta($user_id, AKSRT_Auth_Service::EMAIL_CODE_ATTEMPTS_META);
+ delete_user_meta($user_id, Service::EMAIL_CODE_ATTEMPTS_META);
$ip_key = self::email_code_ip_throttle_key($user_id);
if ($ip_key !== '') {
delete_transient($ip_key);
@@ -306,26 +300,26 @@ class AKSRT_Auth_Email_Verification {
}
public static function fail_email_code_attempt(int $user_id): array {
- $attempts = (int) get_user_meta($user_id, AKSRT_Auth_Service::EMAIL_CODE_ATTEMPTS_META, true);
+ $attempts = (int) get_user_meta($user_id, Service::EMAIL_CODE_ATTEMPTS_META, true);
$attempts++;
- update_user_meta($user_id, AKSRT_Auth_Service::EMAIL_CODE_ATTEMPTS_META, $attempts);
+ update_user_meta($user_id, Service::EMAIL_CODE_ATTEMPTS_META, $attempts);
$ip_attempts = 0;
$ip_key = self::email_code_ip_throttle_key($user_id);
if ($ip_key !== '') {
$ip_attempts = (int) get_transient($ip_key);
$ip_attempts++;
- set_transient($ip_key, $ip_attempts, AKSRT_Auth_Service::EMAIL_CODE_IP_TTL);
+ set_transient($ip_key, $ip_attempts, Service::EMAIL_CODE_IP_TTL);
}
- if ($attempts >= AKSRT_Auth_Service::EMAIL_CODE_MAX_ATTEMPTS || $ip_attempts >= AKSRT_Auth_Service::EMAIL_CODE_MAX_ATTEMPTS) {
- delete_user_meta($user_id, AKSRT_Auth_Service::EMAIL_CODE_HASH_META);
- update_user_meta($user_id, AKSRT_Auth_Service::EMAIL_REQUESTED_AT_META, 0);
- AKSRT_Auth_Service::log_event('verify.code.locked', ['uid' => $user_id, 'attempts' => $attempts]);
+ if ($attempts >= Service::EMAIL_CODE_MAX_ATTEMPTS || $ip_attempts >= Service::EMAIL_CODE_MAX_ATTEMPTS) {
+ delete_user_meta($user_id, Service::EMAIL_CODE_HASH_META);
+ update_user_meta($user_id, Service::EMAIL_REQUESTED_AT_META, 0);
+ Service::log_event('verify.code.locked', ['uid' => $user_id, 'attempts' => $attempts]);
return ['success' => false, 'error' => __('验证码错误次数过多,当前验证码已失效,请重新发送。', 'aksrt')];
}
- AKSRT_Auth_Service::log_event('verify.code.fail', ['uid' => $user_id, 'attempts' => $attempts]);
+ Service::log_event('verify.code.fail', ['uid' => $user_id, 'attempts' => $attempts]);
return ['success' => false, 'error' => __('邮箱验证码错误或已过期,请重新输入。', 'aksrt')];
}
@@ -333,7 +327,7 @@ class AKSRT_Auth_Email_Verification {
// 验证流程:发起 / 校验 / 完成
// ============================================================
- public static function begin_email_verification(WP_User $user, string $method, array $args = []): array {
+ public static function begin_email_verification(\WP_User $user, string $method, array $args = []): array {
$method = in_array($method, ['link', 'code'], true) ? $method : 'link';
$email = sanitize_email((string) ($args['email'] ?? $user->user_email));
$obk = sanitize_text_field((string) ($args['obk'] ?? ''));
@@ -344,44 +338,44 @@ class AKSRT_Auth_Email_Verification {
// 节流:仅在非管理员路径生效(admin_send_verification 会传 bypass_throttle=true)
if (!$bypass_throttle) {
- $last_requested = (int) get_user_meta($user->ID, AKSRT_Auth_Service::EMAIL_REQUESTED_AT_META, true);
+ $last_requested = (int) get_user_meta($user->ID, Service::EMAIL_REQUESTED_AT_META, true);
if ($last_requested > 0 && (time() - $last_requested) < 60 && empty($args['force'])) {
return ['success' => false, 'error' => __('操作过于频繁,请稍后再试', 'aksrt')];
}
}
- $expires_at = time() + (AKSRT_Settings::registration_verification_ttl_minutes() * MINUTE_IN_SECONDS);
- update_user_meta($user->ID, AKSRT_Auth_Service::EMAIL_VERIFIED_META, 0);
- update_user_meta($user->ID, AKSRT_Auth_Service::EMAIL_METHOD_META, $method);
- update_user_meta($user->ID, AKSRT_Auth_Service::EMAIL_TARGET_META, $email);
- update_user_meta($user->ID, AKSRT_Auth_Service::EMAIL_EXPIRES_META, $expires_at);
- update_user_meta($user->ID, AKSRT_Auth_Service::EMAIL_REQUESTED_AT_META, time());
+ $expires_at = time() + (\AKSRT\Settings\Settings::registration_verification_ttl_minutes() * MINUTE_IN_SECONDS);
+ update_user_meta($user->ID, Service::EMAIL_VERIFIED_META, 0);
+ update_user_meta($user->ID, Service::EMAIL_METHOD_META, $method);
+ update_user_meta($user->ID, Service::EMAIL_TARGET_META, $email);
+ update_user_meta($user->ID, Service::EMAIL_EXPIRES_META, $expires_at);
+ update_user_meta($user->ID, Service::EMAIL_REQUESTED_AT_META, time());
if ($obk !== '') {
- update_user_meta($user->ID, AKSRT_Auth_Service::EMAIL_OBK_META, $obk);
+ update_user_meta($user->ID, Service::EMAIL_OBK_META, $obk);
}
- delete_user_meta($user->ID, AKSRT_Auth_Service::EMAIL_TOKEN_HASH_META);
- delete_user_meta($user->ID, AKSRT_Auth_Service::EMAIL_CODE_HASH_META);
+ delete_user_meta($user->ID, Service::EMAIL_TOKEN_HASH_META);
+ delete_user_meta($user->ID, Service::EMAIL_CODE_HASH_META);
if ($method === 'code') {
$code = str_pad((string) random_int(0, 999999), 6, '0', STR_PAD_LEFT);
- update_user_meta($user->ID, AKSRT_Auth_Service::EMAIL_CODE_HASH_META, wp_hash_password($code));
+ update_user_meta($user->ID, Service::EMAIL_CODE_HASH_META, wp_hash_password($code));
// 新验证码 = 重置失败计数 / IP 节流,避免被旧计数立即锁死
self::reset_email_code_attempt_trackers((int) $user->ID);
$sent = self::send_registration_verification_code_email($user, $email, $code);
} else {
$token = wp_generate_password(48, false, false);
- update_user_meta($user->ID, AKSRT_Auth_Service::EMAIL_TOKEN_HASH_META, hash('sha256', $token));
+ update_user_meta($user->ID, Service::EMAIL_TOKEN_HASH_META, hash('sha256', $token));
$sent = self::send_registration_verification_link_email($user, $email, $token);
}
if (!$sent) {
self::clear_email_verification((int) $user->ID);
- AKSRT_Auth_Service::log_event('email.send.fail', ['uid' => (int) $user->ID, 'method' => $method]);
+ Service::log_event('email.send.fail', ['uid' => (int) $user->ID, 'method' => $method]);
return ['success' => false, 'error' => __('验证邮件发送失败,请稍后重试', 'aksrt')];
}
- AKSRT_Auth_Service::log_event('email.send.ok', ['uid' => (int) $user->ID, 'method' => $method]);
+ Service::log_event('email.send.ok', ['uid' => (int) $user->ID, 'method' => $method]);
$message = $method === 'code'
? __('注册成功,验证码已发送到你的邮箱,请完成验证后继续。', 'aksrt')
@@ -399,8 +393,8 @@ class AKSRT_Auth_Email_Verification {
return ['success' => false, 'error' => __('验证账号不存在或已失效', 'aksrt')];
}
- $stored_hash = (string) get_user_meta($user_id, AKSRT_Auth_Service::EMAIL_TOKEN_HASH_META, true);
- $expires_at = (int) get_user_meta($user_id, AKSRT_Auth_Service::EMAIL_EXPIRES_META, true);
+ $stored_hash = (string) get_user_meta($user_id, Service::EMAIL_TOKEN_HASH_META, true);
+ $expires_at = (int) get_user_meta($user_id, Service::EMAIL_EXPIRES_META, true);
if ($stored_hash === '' || $expires_at <= time() || !hash_equals($stored_hash, hash('sha256', $token))) {
return ['success' => false, 'error' => __('验证链接无效或已过期,请重新发送验证邮件。', 'aksrt')];
}
@@ -418,23 +412,23 @@ class AKSRT_Auth_Email_Verification {
$ip_key = self::email_code_ip_throttle_key($user_id);
if ($ip_key !== '') {
$ip_attempts = (int) get_transient($ip_key);
- if ($ip_attempts >= AKSRT_Auth_Service::EMAIL_CODE_MAX_ATTEMPTS) {
- AKSRT_Auth_Service::log_event('verify.code.ip_throttled', ['uid' => $user_id, 'attempts' => $ip_attempts]);
+ if ($ip_attempts >= Service::EMAIL_CODE_MAX_ATTEMPTS) {
+ Service::log_event('verify.code.ip_throttled', ['uid' => $user_id, 'attempts' => $ip_attempts]);
return ['success' => false, 'error' => __('操作过于频繁,请稍后再试', 'aksrt')];
}
}
// 用户级失败计数:达到上限后该验证码立即作废
- $user_attempts = (int) get_user_meta($user_id, AKSRT_Auth_Service::EMAIL_CODE_ATTEMPTS_META, true);
- if ($user_attempts >= AKSRT_Auth_Service::EMAIL_CODE_MAX_ATTEMPTS) {
- delete_user_meta($user_id, AKSRT_Auth_Service::EMAIL_CODE_HASH_META);
- update_user_meta($user_id, AKSRT_Auth_Service::EMAIL_REQUESTED_AT_META, 0);
- AKSRT_Auth_Service::log_event('verify.code.locked.read', ['uid' => $user_id]);
+ $user_attempts = (int) get_user_meta($user_id, Service::EMAIL_CODE_ATTEMPTS_META, true);
+ if ($user_attempts >= Service::EMAIL_CODE_MAX_ATTEMPTS) {
+ delete_user_meta($user_id, Service::EMAIL_CODE_HASH_META);
+ update_user_meta($user_id, Service::EMAIL_REQUESTED_AT_META, 0);
+ Service::log_event('verify.code.locked.read', ['uid' => $user_id]);
return ['success' => false, 'error' => __('验证码错误次数过多,当前验证码已失效,请重新发送。', 'aksrt')];
}
- $stored_hash = (string) get_user_meta($user_id, AKSRT_Auth_Service::EMAIL_CODE_HASH_META, true);
- $expires_at = (int) get_user_meta($user_id, AKSRT_Auth_Service::EMAIL_EXPIRES_META, true);
+ $stored_hash = (string) get_user_meta($user_id, Service::EMAIL_CODE_HASH_META, true);
+ $expires_at = (int) get_user_meta($user_id, Service::EMAIL_EXPIRES_META, true);
if ($stored_hash === '' || $expires_at <= time() || !wp_check_password($code, $stored_hash)) {
return self::fail_email_code_attempt($user_id);
}
@@ -443,16 +437,16 @@ class AKSRT_Auth_Email_Verification {
return self::complete_email_verification($user);
}
- public static function complete_email_verification(WP_User $user): array {
+ public static function complete_email_verification(\WP_User $user): array {
$user_id = (int) $user->ID;
- $obk = (string) get_user_meta($user_id, AKSRT_Auth_Service::EMAIL_OBK_META, true);
- $oauth = $obk !== '' ? AKSRT_Auth_Service::get_oauth_bind_context($obk) : null;
- $email = (string) get_user_meta($user_id, AKSRT_Auth_Service::EMAIL_TARGET_META, true);
- $was_verified = (int) get_user_meta($user_id, AKSRT_Auth_Service::EMAIL_VERIFIED_META, true) === 1;
+ $obk = (string) get_user_meta($user_id, Service::EMAIL_OBK_META, true);
+ $oauth = $obk !== '' ? Service::get_oauth_bind_context($obk) : null;
+ $email = (string) get_user_meta($user_id, Service::EMAIL_TARGET_META, true);
+ $was_verified = (int) get_user_meta($user_id, Service::EMAIL_VERIFIED_META, true) === 1;
- update_user_meta($user_id, AKSRT_Auth_Service::EMAIL_VERIFIED_META, 1);
+ update_user_meta($user_id, Service::EMAIL_VERIFIED_META, 1);
self::clear_email_verification($user_id);
- AKSRT_Auth_Service::log_event('verify.success', ['uid' => $user_id]);
+ Service::log_event('verify.success', ['uid' => $user_id]);
// 状态跳变时触发 hook,邀请系统等模块据此发奖
if (!$was_verified) {
do_action('aksrt_email_verified', $user_id);
@@ -462,14 +456,14 @@ class AKSRT_Auth_Email_Verification {
}
if ($oauth && is_array($oauth)) {
- AKSRT_Auth_Service::finalize_oauth_registration($user_id, $oauth, $obk);
- } elseif (AKSRT_Settings::registration_auto_login_after_verify()) {
+ Service::finalize_oauth_registration($user_id, $oauth, $obk);
+ } elseif (\AKSRT\Settings\Settings::registration_auto_login_after_verify()) {
wp_set_current_user($user_id);
wp_set_auth_cookie($user_id, true);
}
$redirect = function_exists('aksrt_get_user_center_url') ? aksrt_get_user_center_url() : home_url('/');
- if (!AKSRT_Settings::registration_auto_login_after_verify()) {
+ if (!\AKSRT\Settings\Settings::registration_auto_login_after_verify()) {
$redirect = aksrt_get_login_url();
}
@@ -484,8 +478,8 @@ class AKSRT_Auth_Email_Verification {
// 通知邮件
// ============================================================
- public static function send_registration_verification_link_email(WP_User $user, string $email, string $token): bool {
- $url = AKSRT_Auth_Service::get_email_verification_url((int) $user->ID, ['token' => $token]);
+ public static function send_registration_verification_link_email(\WP_User $user, string $email, string $token): bool {
+ $url = Service::get_email_verification_url((int) $user->ID, ['token' => $token]);
$site_name = get_bloginfo('name');
$default_subject = '[' . $site_name . '] ' . __('验证你的邮箱地址', 'aksrt');
$default_content = sprintf(
@@ -493,13 +487,13 @@ class AKSRT_Auth_Email_Verification {
$user->user_login, $site_name, $url
);
- return AKSRT_Settings::send_event_email(
+ return \AKSRT\Settings\Settings::send_event_email(
'reg_verify_link', $email, $default_subject, $default_content,
['{username}' => $user->user_login, '{site_name}' => $site_name, '{url}' => $url]
);
}
- public static function send_registration_verification_code_email(WP_User $user, string $email, string $code): bool {
+ public static function send_registration_verification_code_email(\WP_User $user, string $email, string $code): bool {
$site_name = get_bloginfo('name');
$default_subject = '[' . $site_name . '] ' . __('邮箱验证码', 'aksrt');
$default_content = sprintf(
@@ -507,13 +501,13 @@ class AKSRT_Auth_Email_Verification {
$user->user_login, $site_name, $code
);
- return AKSRT_Settings::send_event_email(
+ return \AKSRT\Settings\Settings::send_event_email(
'reg_verify_code', $email, $default_subject, $default_content,
['{username}' => $user->user_login, '{site_name}' => $site_name, '{code}' => $code]
);
}
- public static function send_registration_verified_notice_email(WP_User $user, string $email): bool {
+ public static function send_registration_verified_notice_email(\WP_User $user, string $email): bool {
$site_name = get_bloginfo('name');
$default_subject = '[' . $site_name . '] ' . __('邮箱验证成功', 'aksrt');
$default_content = sprintf(
@@ -521,7 +515,7 @@ class AKSRT_Auth_Email_Verification {
$user->user_login, $site_name
);
- return AKSRT_Settings::send_event_email(
+ return \AKSRT\Settings\Settings::send_event_email(
'reg_success', $email, $default_subject, $default_content,
['{username}' => $user->user_login, '{site_name}' => $site_name]
);
diff --git a/inc/classes/auth/class-aksrt-moderation.php b/src/AKSRT/Auth/Moderation.php
similarity index 98%
rename from inc/classes/auth/class-aksrt-moderation.php
rename to src/AKSRT/Auth/Moderation.php
index 4a274a0e..2aa5abd9 100644
--- a/inc/classes/auth/class-aksrt-moderation.php
+++ b/src/AKSRT/Auth/Moderation.php
@@ -1,16 +1,15 @@
audit_text($content);
+ $result = \AKSRT\Extensions\ContentAudit::get_instance()->audit_text($content);
if ($result['passed']) {
return true;
}
@@ -332,11 +338,11 @@ trait AKSRT_Moderation_Part_1 {
return ['passed' => true, 'reason' => 'disabled'];
}
- if (!class_exists('AKSRT_Content_Audit')) {
+ if (!class_exists('\AKSRT\Extensions\ContentAudit')) {
return ['passed' => true, 'reason' => 'audit_service_missing'];
}
- return AKSRT_Content_Audit::get_instance()->audit_image($image_path);
+ return \AKSRT\Extensions\ContentAudit::get_instance()->audit_image($image_path);
}
// ============================================================
diff --git a/inc/classes/auth/moderation-traits/trait-aksrt-moderation-part-2.php b/src/AKSRT/Auth/ModerationPart2.php
similarity index 94%
rename from inc/classes/auth/moderation-traits/trait-aksrt-moderation-part-2.php
rename to src/AKSRT/Auth/ModerationPart2.php
index 4672e181..ff4cf6eb 100644
--- a/inc/classes/auth/moderation-traits/trait-aksrt-moderation-part-2.php
+++ b/src/AKSRT/Auth/ModerationPart2.php
@@ -1,7 +1,13 @@
lookup($ip);
+ if (class_exists('\AKSRT\Extensions\IPGeo')) {
+ $result = \AKSRT\Extensions\IPGeo::get_instance()->lookup($ip);
if (!empty($result['country'])) {
return $result['country'];
}
}
// 回退到内置查询
- $ip_geo_config = class_exists('AKSRT_Settings')
- ? AKSRT_Settings::get_ip_geo_settings()
+ $ip_geo_config = class_exists('\AKSRT\Settings\Settings')
+ ? \AKSRT\Settings\Settings::get_ip_geo_settings()
: [];
$provider = (string) ($ip_geo_config['ip_geo_provider'] ?? $config['geoip_provider'] ?? 'ip-api.com');
$api_key = (string) ($ip_geo_config['ip_geo_api_key'] ?? $config['geoip_api_key'] ?? '');
diff --git a/inc/classes/auth/class-aksrt-oauth.php b/src/AKSRT/Auth/OAuth.php
similarity index 95%
rename from inc/classes/auth/class-aksrt-oauth.php
rename to src/AKSRT/Auth/OAuth.php
index d4b435b4..71416298 100644
--- a/inc/classes/auth/class-aksrt-oauth.php
+++ b/src/AKSRT/Auth/OAuth.php
@@ -1,23 +1,15 @@
get_proxy_auth_url($provider, $action);
+ if (class_exists('\AKSRT\Settings\Settings') && \AKSRT\Settings\Settings::oauth_proxy_mode() === 'client') {
+ if (class_exists('OAuthProxyClient')) {
+ return OAuthProxyClient::get_instance()->get_proxy_auth_url($provider, $action);
}
return '';
}
@@ -418,5 +410,3 @@ class AKSRT_OAuth {
}
}
-
-return AKSRT_OAuth::get_instance();
diff --git a/inc/classes/auth/oauth-traits/trait-aksrt-oauth-part-1.php b/src/AKSRT/Auth/OAuthPart1.php
similarity index 95%
rename from inc/classes/auth/oauth-traits/trait-aksrt-oauth-part-1.php
rename to src/AKSRT/Auth/OAuthPart1.php
index 5c298aff..d01567c4 100644
--- a/inc/classes/auth/oauth-traits/trait-aksrt-oauth-part-1.php
+++ b/src/AKSRT/Auth/OAuthPart1.php
@@ -1,7 +1,13 @@
find_user_by_provider($provider, (string) $user_data['provider_id']);
- if ($by_provider instanceof WP_User) {
+ if ($by_provider instanceof \WP_User) {
$bindings = get_user_meta($by_provider->ID, 'aksrt_oauth_bindings', true) ?: [];
if (!is_array($bindings)) $bindings = [];
if (!in_array($provider, $bindings, true)) {
@@ -299,7 +305,7 @@ trait AKSRT_OAuth_Part_1 {
if (!empty($email)) {
$existing = get_user_by('email', $email);
- if ($existing && !$existing instanceof WP_Error) {
+ if ($existing && !$existing instanceof \WP_Error) {
$bindings = get_user_meta($existing->ID, 'aksrt_oauth_bindings', true) ?: [];
if (!is_array($bindings)) $bindings = [];
if (!in_array($provider, $bindings, true)) {
@@ -316,7 +322,7 @@ trait AKSRT_OAuth_Part_1 {
}
}
- return new WP_Error(
+ return new \WP_Error(
'oauth_no_match',
__('需要绑定已有账号', 'aksrt'),
[
diff --git a/inc/classes/auth/oauth-traits/trait-aksrt-oauth-part-2.php b/src/AKSRT/Auth/OAuthPart2.php
similarity index 97%
rename from inc/classes/auth/oauth-traits/trait-aksrt-oauth-part-2.php
rename to src/AKSRT/Auth/OAuthPart2.php
index 71b30bcd..6e756ff0 100644
--- a/inc/classes/auth/oauth-traits/trait-aksrt-oauth-part-2.php
+++ b/src/AKSRT/Auth/OAuthPart2.php
@@ -1,7 +1,13 @@
ID, 'aksrt_oauth_bindings', true) ?: [];
if (empty($bindings)) return;
@@ -126,7 +132,7 @@ trait AKSRT_OAuth_Part_2 {
wp_send_json_success(['unbound' => true]);
}
- private function find_user_by_provider(string $provider, string $provider_id): ?WP_User {
+ private function find_user_by_provider(string $provider, string $provider_id): ?\WP_User {
if (empty($provider_id)) return null;
$users = get_users([
'meta_key' => "aksrt_{$provider}_id",
diff --git a/inc/classes/auth/class-aksrt-oauth-proxy-client.php b/src/AKSRT/Auth/OAuthProxyClient.php
similarity index 91%
rename from inc/classes/auth/class-aksrt-oauth-proxy-client.php
rename to src/AKSRT/Auth/OAuthProxyClient.php
index 81ad3e34..d0ce04ea 100644
--- a/inc/classes/auth/class-aksrt-oauth-proxy-client.php
+++ b/src/AKSRT/Auth/OAuthProxyClient.php
@@ -1,21 +1,13 @@
find_user_by_provider_meta($provider, $user_data['provider_id']);
- if ($existing instanceof WP_User) {
+ if ($existing instanceof \WP_User) {
$this->ensure_binding_meta($existing->ID, $provider, $user_data);
return $existing;
}
@@ -224,14 +216,14 @@ class AKSRT_OAuth_Proxy_Client {
// 2. 通过邮箱查找
if (!empty($email) && is_email($email)) {
$existing = get_user_by('email', $email);
- if ($existing && !$existing instanceof WP_Error) {
+ if ($existing && !$existing instanceof \WP_Error) {
$this->ensure_binding_meta($existing->ID, $provider, $user_data);
return $existing;
}
}
// 3. 未匹配
- return new WP_Error('oauth_no_match', __('需要绑定已有账号', 'aksrt'), [
+ return new \WP_Error('oauth_no_match', __('需要绑定已有账号', 'aksrt'), [
'provider' => $provider,
'user_data' => $user_data,
]);
@@ -282,7 +274,7 @@ class AKSRT_OAuth_Proxy_Client {
/**
* 通过 provider meta 查找用户
*/
- private function find_user_by_provider_meta(string $provider, string $provider_id): ?WP_User {
+ private function find_user_by_provider_meta(string $provider, string $provider_id): ?\WP_User {
if (empty($provider_id)) {
return null;
}
@@ -312,5 +304,3 @@ class AKSRT_OAuth_Proxy_Client {
return hash_equals($computed, $expected_sign);
}
}
-
-return AKSRT_OAuth_Proxy_Client::get_instance();
diff --git a/inc/classes/auth/class-aksrt-oauth-proxy-server.php b/src/AKSRT/Auth/OAuthProxyServer.php
similarity index 95%
rename from inc/classes/auth/class-aksrt-oauth-proxy-server.php
rename to src/AKSRT/Auth/OAuthProxyServer.php
index 18d533b8..192ae7f4 100644
--- a/inc/classes/auth/class-aksrt-oauth-proxy-server.php
+++ b/src/AKSRT/Auth/OAuthProxyServer.php
@@ -1,16 +1,13 @@
get_auth_url($provider, $action);
if (empty($auth_url)) {
wp_die(__('无法生成授权链接', 'aksrt'));
@@ -112,7 +109,7 @@ class AKSRT_OAuth_Proxy_Server {
$_SESSION['aksrt_proxy_nonce'] = '';
$_SESSION['aksrt_proxy_uid'] = 0;
- $secret = AKSRT_Settings::oauth_proxy_secret();
+ $secret = \AKSRT\Settings\Settings::oauth_proxy_secret();
if (empty($secret)) {
wp_die(__('代理登录服务端配置错误', 'aksrt'));
}
@@ -290,5 +287,3 @@ class AKSRT_OAuth_Proxy_Server {
return hash_equals($this->sign($data, $secret), $expected_sign);
}
}
-
-return AKSRT_OAuth_Proxy_Server::get_instance();
diff --git a/inc/classes/auth/class-aksrt-auth-router.php b/src/AKSRT/Auth/Router.php
similarity index 93%
rename from inc/classes/auth/class-aksrt-auth-router.php
rename to src/AKSRT/Auth/Router.php
index 60a2e1f2..e0400e4d 100644
--- a/inc/classes/auth/class-aksrt-auth-router.php
+++ b/src/AKSRT/Auth/Router.php
@@ -1,21 +1,13 @@
ID)) {
+ if (!EmailVerification::is_email_verified((int) $user->ID)) {
self::log_event('auth.rest_unverified', [
'uid' => (int) $user->ID,
'rest' => $is_rest,
@@ -142,7 +137,7 @@ final class AKSRT_Auth_Service {
}
// 已验证 → 直接放行
- if (AKSRT_Auth_Email_Verification::is_email_verified((int) $user->ID)) {
+ if (EmailVerification::is_email_verified((int) $user->ID)) {
return $user;
}
@@ -161,7 +156,7 @@ final class AKSRT_Auth_Service {
'xmlrpc' => $is_xmlrpc,
]);
- return new WP_Error(
+ return new \WP_Error(
'aksrt_email_unverified',
__('账号尚未完成邮箱验证,请先完成邮箱验证后再登录。', 'aksrt'),
[
@@ -209,11 +204,11 @@ final class AKSRT_Auth_Service {
}
public static function current_registration_verification_method(): string {
- if (!class_exists('AKSRT_Settings')) {
+ if (!class_exists('\AKSRT\Settings\Settings')) {
return 'link';
}
- $method = AKSRT_Settings::registration_verification_method();
+ $method = \AKSRT\Settings\Settings::registration_verification_method();
return in_array($method, ['link', 'code'], true) ? $method : 'link';
}
diff --git a/inc/classes/auth/auth-traits/trait-aksrt-auth-service-part-1a.php b/src/AKSRT/Auth/ServicePart1a.php
similarity index 90%
rename from inc/classes/auth/auth-traits/trait-aksrt-auth-service-part-1a.php
rename to src/AKSRT/Auth/ServicePart1a.php
index c9bdd3fb..3ef37fc9 100644
--- a/inc/classes/auth/auth-traits/trait-aksrt-auth-service-part-1a.php
+++ b/src/AKSRT/Auth/ServicePart1a.php
@@ -1,7 +1,13 @@
cookie aksrt_invite
- $invite_registration_enabled = class_exists('AKSRT_Settings') && AKSRT_Settings::invite_registration_enabled();
- $invite_mode = $invite_registration_enabled && class_exists('AKSRT_Settings')
- ? AKSRT_Settings::invite_register_field_mode()
+ $invite_registration_enabled = class_exists('\AKSRT\Settings\Settings') && \AKSRT\Settings\Settings::invite_registration_enabled();
+ $invite_mode = $invite_registration_enabled && class_exists('\AKSRT\Settings\Settings')
+ ? \AKSRT\Settings\Settings::invite_register_field_mode()
: 'hidden';
$invite_code = isset($post['invite_code']) ? sanitize_key((string) wp_unslash($post['invite_code'])) : '';
$resolved_inviter_id = 0;
@@ -68,13 +74,13 @@ trait AKSRT_Auth_Service_Part_1a {
// 邀请功能关闭,忽略所有邀请码
$invite_code = '';
} elseif ($invite_code !== '') {
- if (class_exists('AKSRT_Invite')) {
- $invite_service = AKSRT_Invite::get_instance();
+ if (class_exists('\AKSRT\Credits\Invite')) {
+ $invite_service = \AKSRT\Credits\Invite::get_instance();
$resolved_inviter_id = $invite_service->resolve_code($invite_code);
$invite_is_valid = $invite_service->validate_code($invite_code);
}
// 必填模式下,邀请码无效时根据后台开关决定是否拒绝
- $reject_invalid = class_exists('AKSRT_Settings') && AKSRT_Settings::invite_reject_invalid();
+ $reject_invalid = class_exists('\AKSRT\Settings\Settings') && \AKSRT\Settings\Settings::invite_reject_invalid();
if ($invite_mode === 'required' && $reject_invalid && !$invite_is_valid) {
return ['success' => false, 'error' => __('邀请码无效,请检查后重试', 'aksrt')];
}
@@ -93,11 +99,11 @@ trait AKSRT_Auth_Service_Part_1a {
return ['success' => false, 'error' => $user_id->get_error_message()];
}
- if ($invite_code !== '' && $resolved_inviter_id <= 0 && class_exists('AKSRT_Invite')) {
- AKSRT_Invite::get_instance()->handle_registration_invite((int) $user_id, $invite_code);
+ if ($invite_code !== '' && $resolved_inviter_id <= 0 && class_exists('\AKSRT\Credits\Invite')) {
+ \AKSRT\Credits\Invite::get_instance()->handle_registration_invite((int) $user_id, $invite_code);
}
- // wp_create_user 内部已触发 user_register hook,AKSRT_Invite::on_user_register 已读取 pending 字段。
+ // wp_create_user 内部已触发 user_register hook,\AKSRT\Credits\Invite::on_user_register 已读取 pending 字段。
// 这里清空,避免污染后续请求。
self::$pending_invite_inviter_id = 0;
self::$pending_invite_code = '';
@@ -109,7 +115,7 @@ trait AKSRT_Auth_Service_Part_1a {
$oauth_context = isset($context['oauth_bind_data']) && is_array($context['oauth_bind_data']) ? $context['oauth_bind_data'] : [];
$oauth_verified = self::oauth_email_is_verified($oauth_context);
- $requires_verify = AKSRT_Settings::registration_requires_email_verification() && !$oauth_verified;
+ $requires_verify = \AKSRT\Settings\Settings::registration_requires_email_verification() && !$oauth_verified;
if (!$requires_verify) {
self::mark_email_verified($user_id);
@@ -121,7 +127,7 @@ trait AKSRT_Auth_Service_Part_1a {
];
}
- $method = AKSRT_Settings::registration_verification_method();
+ $method = \AKSRT\Settings\Settings::registration_verification_method();
$begin = self::begin_email_verification(
$user,
$method,
@@ -231,7 +237,7 @@ trait AKSRT_Auth_Service_Part_1a {
}
if (self::oauth_email_is_verified($oauth_data)) {
- AKSRT_Auth_Email_Verification::mark_email_verified($user_id);
+ EmailVerification::mark_email_verified($user_id);
}
if ($obk !== '') {
@@ -280,7 +286,7 @@ trait AKSRT_Auth_Service_Part_1a {
// token 路径:链接模式直接走 token 校验;不依赖 vk
if ($token !== '') {
- if (AKSRT_Auth_Email_Verification::is_email_verified($user_id)) {
+ if (EmailVerification::is_email_verified($user_id)) {
return [
'mode' => 'invalid',
'user' => $user,
@@ -423,7 +429,7 @@ trait AKSRT_Auth_Service_Part_1a {
// 容错:meta 缺失时回退到设置默认值与 user_email(兼容历史账号 / meta 被外部清理的情况)
if (!in_array($method, ['link', 'code'], true)) {
- $method = AKSRT_Settings::registration_verification_method();
+ $method = \AKSRT\Settings\Settings::registration_verification_method();
}
if ($email === '' || !is_email($email)) {
$email = (string) $user->user_email;
@@ -445,31 +451,31 @@ trait AKSRT_Auth_Service_Part_1a {
}
private static function user_requires_email_verification($user): bool {
- return AKSRT_Auth_Email_Verification::user_requires_email_verification($user);
+ return EmailVerification::user_requires_email_verification($user);
}
private static function mark_email_verified(int $user_id): void {
- AKSRT_Auth_Email_Verification::mark_email_verified($user_id);
+ EmailVerification::mark_email_verified($user_id);
}
// ============================================================
- // 公开 API:管理员后台 / 内部业务调用(委托 AKSRT_Auth_Email_Verification)
+ // 公开 API:管理员后台 / 内部业务调用(委托 EmailVerification)
// ============================================================
public static function user_is_email_verified(int $user_id): bool {
- return AKSRT_Auth_Email_Verification::user_is_email_verified($user_id);
+ return EmailVerification::user_is_email_verified($user_id);
}
public static function get_user_verification_state(int $user_id): array {
- return AKSRT_Auth_Email_Verification::get_user_verification_state($user_id);
+ return EmailVerification::get_user_verification_state($user_id);
}
public static function admin_mark_verified(int $user_id, int $by_admin_id = 0): array {
- return AKSRT_Auth_Email_Verification::admin_mark_verified($user_id, $by_admin_id);
+ return EmailVerification::admin_mark_verified($user_id, $by_admin_id);
}
public static function admin_unmark_verified(int $user_id, int $by_admin_id = 0): array {
- return AKSRT_Auth_Email_Verification::admin_unmark_verified($user_id, $by_admin_id);
+ return EmailVerification::admin_unmark_verified($user_id, $by_admin_id);
}
}
diff --git a/inc/classes/auth/auth-traits/trait-aksrt-auth-service-part-1b.php b/src/AKSRT/Auth/ServicePart1b.php
similarity index 89%
rename from inc/classes/auth/auth-traits/trait-aksrt-auth-service-part-1b.php
rename to src/AKSRT/Auth/ServicePart1b.php
index 04330d84..125477dd 100644
--- a/inc/classes/auth/auth-traits/trait-aksrt-auth-service-part-1b.php
+++ b/src/AKSRT/Auth/ServicePart1b.php
@@ -1,18 +1,24 @@
ID);
$site_name = get_bloginfo('name');
$default_subject = '[' . $site_name . '] ' . __('重置密码', 'aksrt');
@@ -213,7 +219,7 @@ trait AKSRT_Auth_Service_Part_1b {
$user->user_login, $site_name, $reset_url
);
- return AKSRT_Settings::send_event_email(
+ return \AKSRT\Settings\Settings::send_event_email(
'password_reset', $user->user_email, $default_subject, $default_content,
['{username}' => $user->user_login, '{site_name}' => $site_name, '{url}' => $reset_url]
);
@@ -253,8 +259,8 @@ trait AKSRT_Auth_Service_Part_1b {
}
// 验证 SMS 验证码
- if (class_exists('AKSRT_SMS')) {
- $verify_result = AKSRT_SMS::get_instance()->verify_code($phone, $code);
+ if (class_exists('\AKSRT\Sms\SMS')) {
+ $verify_result = \AKSRT\Sms\SMS::get_instance()->verify_code($phone, $code);
if (empty($verify_result['success'])) {
return ['success' => false, 'error' => $verify_result['message'] ?? __('验证码不正确', 'aksrt')];
}
@@ -292,8 +298,8 @@ trait AKSRT_Auth_Service_Part_1b {
// 处理邀请码
$invite_code = sanitize_key((string) ($post['invite_code'] ?? ''));
- if ($invite_code !== '' && class_exists('AKSRT_Invite')) {
- AKSRT_Invite::get_instance()->handle_registration_invite($user_id, $invite_code);
+ if ($invite_code !== '' && class_exists('\AKSRT\Credits\Invite')) {
+ \AKSRT\Credits\Invite::get_instance()->handle_registration_invite($user_id, $invite_code);
}
// 自动登录
@@ -379,8 +385,8 @@ trait AKSRT_Auth_Service_Part_1b {
}
// 验证 SMS 验证码
- if (class_exists('AKSRT_SMS')) {
- $verify_result = AKSRT_SMS::get_instance()->verify_code($phone, $code);
+ if (class_exists('\AKSRT\Sms\SMS')) {
+ $verify_result = \AKSRT\Sms\SMS::get_instance()->verify_code($phone, $code);
if (empty($verify_result['success'])) {
return ['success' => false, 'error' => $verify_result['message'] ?? __('验证码不正确', 'aksrt')];
}
@@ -433,8 +439,8 @@ trait AKSRT_Auth_Service_Part_1b {
}
// 验证 SMS 验证码
- if (class_exists('AKSRT_SMS')) {
- $verify_result = AKSRT_SMS::get_instance()->verify_code($phone, $code);
+ if (class_exists('\AKSRT\Sms\SMS')) {
+ $verify_result = \AKSRT\Sms\SMS::get_instance()->verify_code($phone, $code);
if (empty($verify_result['success'])) {
return ['success' => false, 'error' => $verify_result['message'] ?? __('验证码不正确', 'aksrt')];
}
@@ -461,7 +467,7 @@ trait AKSRT_Auth_Service_Part_1b {
/**
* 根据手机号查找用户
*/
- private static function get_user_by_phone(string $phone): ?WP_User {
+ private static function get_user_by_phone(string $phone): ?\WP_User {
$users = get_users([
'meta_key' => 'aksrt_phone',
'meta_value' => $phone,
diff --git a/inc/classes/content/class-aksrt-download.php b/src/AKSRT/Content/Download.php
similarity index 89%
rename from inc/classes/content/class-aksrt-download.php
rename to src/AKSRT/Content/Download.php
index 766f166f..2ce960d6 100644
--- a/inc/classes/content/class-aksrt-download.php
+++ b/src/AKSRT/Content/Download.php
@@ -1,15 +1,13 @@
format('Y-m-d H:i:s');
@@ -85,33 +83,33 @@ class AKSRT_Download {
'permission_callback' => [$this, 'check_rest_nonce'],
]);
- register_rest_route('aksrt/v1', '/download/policy/(?P\\d+)', [
+ register_rest_route('aksrt/v1', '/download/policy/(?P\d+)', [
'methods' => 'GET',
'callback' => [$this, 'rest_policy'],
'permission_callback' => '__return_true',
]);
}
- public function check_rest_nonce(WP_REST_Request $request) {
+ public function check_rest_nonce(\WP_REST_Request $request) {
$nonce = $request->get_header('x-wp-nonce');
if (!$nonce) {
- return new WP_Error('aksrt_rest_no_nonce', __('缺少安全令牌', 'aksrt'), ['status' => 403]);
+ return new \WP_Error('aksrt_rest_no_nonce', __('缺少安全令牌', 'aksrt'), ['status' => 403]);
}
if (!wp_verify_nonce($nonce, 'wp_rest')) {
- return new WP_Error('aksrt_rest_bad_nonce', __('安全令牌已过期,请刷新页面', 'aksrt'), ['status' => 403]);
+ return new \WP_Error('aksrt_rest_bad_nonce', __('安全令牌已过期,请刷新页面', 'aksrt'), ['status' => 403]);
}
return true;
}
- public function rest_policy(WP_REST_Request $request) {
+ public function rest_policy(\WP_REST_Request $request) {
$post_id = (int) $request['id'];
$post = get_post($post_id);
if (!$post || !function_exists('aksrt_is_downloadable_content') || !aksrt_is_downloadable_content($post)) {
- return new WP_Error('aksrt_invalid', __('内容不存在或未启用下载能力', 'aksrt'), ['status' => 404]);
+ return new \WP_Error('aksrt_invalid', __('内容不存在或未启用下载能力', 'aksrt'), ['status' => 404]);
}
$meta = function_exists('aksrt_get_download_box_meta') ? aksrt_get_download_box_meta($post) : [];
- $paid_settings = AKSRT_Settings::get_paid_content_settings();
+ $paid_settings = \AKSRT\Settings\Settings::get_paid_content_settings();
$cost = aksrt_resource_download_cost($post);
$uid = get_current_user_id();
$priced = function_exists('aksrt_get_user_pay_price') ? aksrt_get_user_pay_price($post, $uid) : null;
@@ -120,8 +118,8 @@ class AKSRT_Download {
: ((($meta['pay_modo'] ?? '0') === 'points') ? 'points' : '0');
$display_price = is_array($priced) ? (float) ($priced['amount'] ?? 0) : (float) ($meta['price'] ?? 0);
- $access = class_exists('AKSRT_Content_Visibility')
- ? AKSRT_Content_Visibility::get_post_access_state($post, $uid)
+ $access = class_exists('Visibility')
+ ? Visibility::get_post_access_state($post, $uid)
: [];
$need_captcha = !empty($paid_settings['download_captcha']) || !empty($meta['require_captcha']);
@@ -129,7 +127,7 @@ class AKSRT_Download {
$need_captcha = false;
}
- return new WP_REST_Response([
+ return new \WP_REST_Response([
'post_id' => $post_id,
'price' => $display_price,
'base_price' => is_array($priced) ? (float) ($priced['base'] ?? $display_price) : (float) ($meta['price'] ?? 0),
@@ -139,7 +137,7 @@ class AKSRT_Download {
'require_login' => !empty($paid_settings['download_login']) || !empty($meta['require_login']) || (!empty($paid_settings['free_logged_show']) && $cost <= 0 && $display_price <= 0),
'require_captcha' => $need_captcha,
'logged_in' => $uid > 0,
- 'balance' => $uid > 0 && class_exists('AKSRT_Credits') ? AKSRT_Credits::balance($uid) : 0,
+ 'balance' => $uid > 0 && class_exists('\AKSRT\Credits\Credits') ? \AKSRT\Credits\Credits::balance($uid) : 0,
'has_paid_access' => !empty($access['has_paid_access']),
'need_purchase' => !empty($access['need_purchase']),
'need_vip' => !empty($access['need_vip']),
@@ -162,7 +160,7 @@ class AKSRT_Download {
], 200);
}
- public function rest_request(WP_REST_Request $request) {
+ public function rest_request(\WP_REST_Request $request) {
$params = $request->get_json_params();
if (!is_array($params)) $params = $request->get_params();
@@ -171,19 +169,19 @@ class AKSRT_Download {
$post = get_post($post_id);
if (!$post || !function_exists('aksrt_is_downloadable_content') || !aksrt_is_downloadable_content($post)) {
- return new WP_Error('aksrt_invalid', __('内容不存在或未启用下载能力', 'aksrt'), ['status' => 404]);
+ return new \WP_Error('aksrt_invalid', __('内容不存在或未启用下载能力', 'aksrt'), ['status' => 404]);
}
$meta = function_exists('aksrt_get_download_box_meta') ? aksrt_get_download_box_meta($post) : [];
if (empty($meta['downloads'][$source_index])) {
- return new WP_Error('aksrt_no_source', __('下载源不存在', 'aksrt'), ['status' => 404]);
+ return new \WP_Error('aksrt_no_source', __('下载源不存在', 'aksrt'), ['status' => 404]);
}
$source = $meta['downloads'][$source_index];
$gate = aksrt_can_download($post);
if (is_wp_error($gate)) return $gate;
- $paid_settings = AKSRT_Settings::get_paid_content_settings();
+ $paid_settings = \AKSRT\Settings\Settings::get_paid_content_settings();
$uid = get_current_user_id();
$cost = aksrt_resource_download_cost($post);
@@ -204,7 +202,7 @@ class AKSRT_Download {
$verify = aksrt_require_captcha('download', $cap_payload);
if ($verify !== true) {
$msg = is_string($verify) ? $verify : __('人机验证失败', 'aksrt');
- return new WP_Error('aksrt_captcha_failed', $msg, ['status' => 400]);
+ return new \WP_Error('aksrt_captcha_failed', $msg, ['status' => 400]);
}
}
}
@@ -232,7 +230,7 @@ class AKSRT_Download {
$extract_code = trim((string) ($source['extract_code'] ?? ''));
- return new WP_REST_Response([
+ return new \WP_REST_Response([
'success' => true,
'token' => $token,
'dl_url' => $dl_url,
@@ -241,7 +239,7 @@ class AKSRT_Download {
'source_type' => $source['type'] ?? 'direct',
'has_extract' => $extract_code !== '',
'extract_code' => $extract_code,
- 'balance' => $uid > 0 && class_exists('AKSRT_Credits') ? AKSRT_Credits::balance($uid) : 0,
+ 'balance' => $uid > 0 && class_exists('\AKSRT\Credits\Credits') ? \AKSRT\Credits\Credits::balance($uid) : 0,
], 200);
}
@@ -255,7 +253,7 @@ class AKSRT_Download {
}
global $wpdb;
- $table = AKSRT_DB_Migrator::table('dl_token');
+ $table = \AKSRT\Core\DBMigrator::table('dl_token');
if (!$table) $this->fail_410();
$row = $wpdb->get_row($wpdb->prepare(
@@ -409,9 +407,9 @@ class AKSRT_Download {
private function issue_token(int $user_id, int $post_id, int $source_index, int $cost) {
global $wpdb;
- $table = AKSRT_DB_Migrator::table('dl_token');
+ $table = \AKSRT\Core\DBMigrator::table('dl_token');
if (!$table) {
- return new WP_Error('aksrt_no_table', __('下载令牌表未初始化', 'aksrt'), ['status' => 500]);
+ return new \WP_Error('aksrt_no_table', __('下载令牌表未初始化', 'aksrt'), ['status' => 500]);
}
$token = $this->random_token(self::TOKEN_LEN);
@@ -441,7 +439,7 @@ class AKSRT_Download {
);
if ($ok === false) {
- return new WP_Error('aksrt_token_insert', __('生成下载令牌失败', 'aksrt'), ['status' => 500]);
+ return new \WP_Error('aksrt_token_insert', __('生成下载令牌失败', 'aksrt'), ['status' => 500]);
}
return $token;
diff --git a/inc/classes/content/class-aksrt-download-state.php b/src/AKSRT/Content/DownloadState.php
similarity index 95%
rename from inc/classes/content/class-aksrt-download-state.php
rename to src/AKSRT/Content/DownloadState.php
index 02bb7921..81073c75 100644
--- a/inc/classes/content/class-aksrt-download-state.php
+++ b/src/AKSRT/Content/DownloadState.php
@@ -1,16 +1,13 @@
0 && class_exists('AKSRT_Credits'))
- ? AKSRT_Credits::balance($user_id)
+ $balance = ($user_id > 0 && class_exists('\AKSRT\Credits\Credits'))
+ ? \AKSRT\Credits\Credits::balance($user_id)
: 0;
$gate = function_exists('aksrt_can_download') ? aksrt_can_download($post_id, $user_id) : true;
diff --git a/inc/classes/content/class-aksrt-content-pay.php b/src/AKSRT/Content/Pay.php
similarity index 59%
rename from inc/classes/content/class-aksrt-content-pay.php
rename to src/AKSRT/Content/Pay.php
index 725a7a7a..e12ad28d 100644
--- a/inc/classes/content/class-aksrt-content-pay.php
+++ b/src/AKSRT/Content/Pay.php
@@ -1,19 +1,16 @@
post_status !== 'publish') {
- return new WP_Error('aksrt_invalid', __('内容不存在', 'aksrt'), ['status' => 404]);
+ if (!($post instanceof \WP_Post) || $post->post_status !== 'publish') {
+ return new \WP_Error('aksrt_invalid', __('内容不存在', 'aksrt'), ['status' => 404]);
}
$meta = function_exists('aksrt_get_pay_meta') ? aksrt_get_pay_meta($post) : [];
- $pay_type = AKSRT_Domain_Model::normalize_pay_type((string) ($meta['pay_type'] ?? AKSRT_Domain_Model::PAY_TYPE_NO));
- if ($pay_type === AKSRT_Domain_Model::PAY_TYPE_NO) {
- return new WP_Error('aksrt_not_paid', __('该内容无需购买', 'aksrt'), ['status' => 400]);
+ $pay_type = \AKSRT\Core\DomainModel::normalize_pay_type((string) ($meta['pay_type'] ?? \AKSRT\Core\DomainModel::PAY_TYPE_NO));
+ if ($pay_type === \AKSRT\Core\DomainModel::PAY_TYPE_NO) {
+ return new \WP_Error('aksrt_not_paid', __('该内容无需购买', 'aksrt'), ['status' => 400]);
}
$uid = $user_id > 0 ? $user_id : get_current_user_id();
@@ -64,8 +64,8 @@ trait AKSRT_Content_Pay_Helpers {
$coupon_desc = '';
if ($coupon_allowed) {
$coupon_desc = trim((string) ($meta['coupon_desc'] ?? ''));
- if ($coupon_desc === '' && class_exists('AKSRT_Settings') && method_exists('AKSRT_Settings', 'get_content_coupon_settings')) {
- $coupon_desc = (string) (AKSRT_Settings::get_content_coupon_settings()['desc'] ?? '');
+ if ($coupon_desc === '' && class_exists('\AKSRT\Settings\Settings') && method_exists('\AKSRT\Settings\Settings', 'get_content_coupon_settings')) {
+ $coupon_desc = (string) (\AKSRT\Settings\Settings::get_content_coupon_settings()['desc'] ?? '');
}
}
@@ -91,10 +91,10 @@ trait AKSRT_Content_Pay_Helpers {
$has_paid = false;
$paid_order = null;
- if ($uid > 0 && class_exists('AKSRT_Order')) {
- $has_paid = AKSRT_Order::get_instance()->has_paid_access(
+ if ($uid > 0 && class_exists('\AKSRT\Payment\Order')) {
+ $has_paid = \AKSRT\Payment\Order::get_instance()->has_paid_access(
$uid,
- AKSRT_Domain_Model::ORDER_PRODUCT_RESOURCE,
+ \AKSRT\Core\DomainModel::ORDER_PRODUCT_RESOURCE,
$post_id
);
if ($has_paid && function_exists('aksrt_get_user_content_paid_order')) {
@@ -110,17 +110,17 @@ trait AKSRT_Content_Pay_Helpers {
}
$pending_order = null;
- if ($uid > 0 && !$has_paid && class_exists('AKSRT_Order_Repository')) {
+ if ($uid > 0 && !$has_paid && class_exists('\AKSRT\Payment\OrderRepository')) {
$pending_order = $this->find_pending_content_order($uid, $post_id);
}
$need_vip = $pay_limit > 0 && $vip_level < $pay_limit;
$allow_guest = function_exists('aksrt_allow_guest_content_pay') && aksrt_allow_guest_content_pay($post);
$currency = (string) ($priced['currency'] ?? ($pay_modo === 'points'
- ? (class_exists('AKSRT_Settings') ? AKSRT_Settings::get_currency_name() : __('积分', 'aksrt'))
+ ? (class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_currency_name() : __('积分', 'aksrt'))
: '¥'));
- $balance = ($uid > 0 && class_exists('AKSRT_Credits')) ? AKSRT_Credits::balance($uid) : 0;
+ $balance = ($uid > 0 && class_exists('\AKSRT\Credits\Credits')) ? \AKSRT\Credits\Credits::balance($uid) : 0;
$methods = $this->available_payment_methods($pay_modo, $uid > 0);
$amount_label = $this->format_amount_label($amount, $pay_modo, $currency);
@@ -145,7 +145,7 @@ trait AKSRT_Content_Pay_Helpers {
'title' => get_the_title($post),
'permalink' => get_permalink($post),
'pay_type' => $pay_type,
- 'pay_type_label' => AKSRT_Domain_Model::pay_type_labels()[$pay_type] ?? $pay_type,
+ 'pay_type_label' => \AKSRT\Core\DomainModel::pay_type_labels()[$pay_type] ?? $pay_type,
'pay_modo' => $pay_modo,
'pay_limit' => $pay_limit,
'vip_level' => $vip_level,
@@ -225,28 +225,28 @@ trait AKSRT_Content_Pay_Helpers {
/**
- * @return array{post:WP_Post,meta:array,priced:array}|WP_Error
+ * @return array{post:\WP_Post,meta:array,priced:array}|\WP_Error
*/
private function assert_purchasable(int $post_id, int $user_id, string $price_type = '') {
$post = get_post($post_id);
- if (!($post instanceof WP_Post) || $post->post_status !== 'publish') {
- return new WP_Error('aksrt_invalid', __('内容不存在', 'aksrt'), ['status' => 404]);
+ if (!($post instanceof \WP_Post) || $post->post_status !== 'publish') {
+ return new \WP_Error('aksrt_invalid', __('内容不存在', 'aksrt'), ['status' => 404]);
}
$meta = function_exists('aksrt_get_pay_meta') ? aksrt_get_pay_meta($post) : [];
- $pay_type = AKSRT_Domain_Model::normalize_pay_type((string) ($meta['pay_type'] ?? AKSRT_Domain_Model::PAY_TYPE_NO));
- if ($pay_type === AKSRT_Domain_Model::PAY_TYPE_NO && $price_type !== 'download_limit_over') {
- return new WP_Error('aksrt_not_paid', __('该内容无需购买', 'aksrt'), ['status' => 400]);
+ $pay_type = \AKSRT\Core\DomainModel::normalize_pay_type((string) ($meta['pay_type'] ?? \AKSRT\Core\DomainModel::PAY_TYPE_NO));
+ if ($pay_type === \AKSRT\Core\DomainModel::PAY_TYPE_NO && $price_type !== 'download_limit_over') {
+ return new \WP_Error('aksrt_not_paid', __('该内容无需购买', 'aksrt'), ['status' => 400]);
}
- if ($pay_type === AKSRT_Domain_Model::PAY_TYPE_VIP) {
- return new WP_Error('aksrt_need_vip', __('该内容为 VIP 专属,请开通会员。', 'aksrt'), ['status' => 403]);
+ if ($pay_type === \AKSRT\Core\DomainModel::PAY_TYPE_VIP) {
+ return new \WP_Error('aksrt_need_vip', __('该内容为 VIP 专属,请开通会员。', 'aksrt'), ['status' => 403]);
}
$pay_modo_meta = (($meta['pay_modo'] ?? '0') === 'points') ? 'points' : '0';
$allow_guest = function_exists('aksrt_allow_guest_content_pay') && aksrt_allow_guest_content_pay($post);
if ($user_id <= 0) {
if ($pay_modo_meta === 'points' || !$allow_guest) {
- return new WP_Error('aksrt_need_login', __('请先登录后再购买。', 'aksrt'), [
+ return new \WP_Error('aksrt_need_login', __('请先登录后再购买。', 'aksrt'), [
'status' => 401,
'login_url' => wp_login_url(get_permalink($post)),
]);
@@ -261,7 +261,7 @@ trait AKSRT_Content_Pay_Helpers {
if ($price_type === 'download_limit_over') {
$over = max(0.0, (float) ($meta['download_limit_over_price'] ?? 0));
if ($over <= 0) {
- return new WP_Error('aksrt_no_overbuy', __('未开放超额下载购买。', 'aksrt'), ['status' => 400]);
+ return new \WP_Error('aksrt_no_overbuy', __('未开放超额下载购买。', 'aksrt'), ['status' => 400]);
}
$priced['amount'] = $over;
$priced['base'] = $over;
@@ -272,7 +272,7 @@ trait AKSRT_Content_Pay_Helpers {
$pay_limit = (int) ($priced['pay_limit'] ?? 0);
$vip_level = (int) ($priced['vip_level'] ?? 0);
if ($pay_limit > 0 && $vip_level < $pay_limit && $price_type !== 'download_limit_over') {
- return new WP_Error('aksrt_need_vip', sprintf(
+ return new \WP_Error('aksrt_need_vip', sprintf(
/* translators: %d: required VIP level */
__('该资源仅限 VIP%s 及以上会员购买/下载。', 'aksrt'),
max(1, $pay_limit)
@@ -282,19 +282,19 @@ trait AKSRT_Content_Pay_Helpers {
]);
}
- if ($user_id > 0 && class_exists('AKSRT_Order') && AKSRT_Order::get_instance()->has_paid_access(
+ if ($user_id > 0 && class_exists('\AKSRT\Payment\Order') && \AKSRT\Payment\Order::get_instance()->has_paid_access(
$user_id,
- AKSRT_Domain_Model::ORDER_PRODUCT_RESOURCE,
+ \AKSRT\Core\DomainModel::ORDER_PRODUCT_RESOURCE,
$post_id
)) {
- return new WP_Error('aksrt_already_paid', __('您已购买该内容。', 'aksrt'), [
+ return new \WP_Error('aksrt_already_paid', __('您已购买该内容。', 'aksrt'), [
'status' => 200,
'has_paid_access' => true,
'reload' => true,
]);
}
if ($user_id <= 0 && function_exists('aksrt_guest_has_paid_access') && aksrt_guest_has_paid_access($post_id)) {
- return new WP_Error('aksrt_already_paid', __('您已购买该内容。', 'aksrt'), [
+ return new \WP_Error('aksrt_already_paid', __('您已购买该内容。', 'aksrt'), [
'status' => 200,
'has_paid_access' => true,
'reload' => true,
@@ -339,11 +339,11 @@ trait AKSRT_Content_Pay_Helpers {
if (function_exists('aksrt_is_content_coupon_allowed')) {
return aksrt_is_content_coupon_allowed($post_id);
}
- if (class_exists('AKSRT_Settings') && method_exists('AKSRT_Settings', 'get_content_coupon_settings')) {
- return !empty(AKSRT_Settings::get_content_coupon_settings()['enabled']);
+ if (class_exists('\AKSRT\Settings\Settings') && method_exists('\AKSRT\Settings\Settings', 'get_content_coupon_settings')) {
+ return !empty(\AKSRT\Settings\Settings::get_content_coupon_settings()['enabled']);
}
- if (class_exists('AKSRT_Settings') && method_exists('AKSRT_Settings', 'get_paid_content_settings')) {
- return !empty(AKSRT_Settings::get_paid_content_settings()['coupon_post_s']);
+ if (class_exists('\AKSRT\Settings\Settings') && method_exists('\AKSRT\Settings\Settings', 'get_paid_content_settings')) {
+ return !empty(\AKSRT\Settings\Settings::get_paid_content_settings()['coupon_post_s']);
}
return false;
}
@@ -355,16 +355,16 @@ trait AKSRT_Content_Pay_Helpers {
*/
private function resolve_referrer_context(int $user_id): array {
$empty = ['id' => 0, 'ratio' => 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 $empty;
}
- $aff = AKSRT_Settings::get_payment_affiliate_settings();
+ $aff = \AKSRT\Settings\Settings::get_payment_affiliate_settings();
if (empty($aff['enabled'])) {
return $empty;
}
$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($user_id);
+ 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($user_id);
}
if ($referrer_id <= 0) {
return $empty;
@@ -397,9 +397,9 @@ trait AKSRT_Content_Pay_Helpers {
*
* @param array $priced
* @param array $meta
- * @return array|WP_Error
+ * @return array|\WP_Error
*/
- private function apply_cash_discounts(array $priced, WP_Post $post, array $meta, int $user_id, string $coupon_code = '', bool $soft_coupon = false) {
+ private function apply_cash_discounts(array $priced, \WP_Post $post, array $meta, int $user_id, string $coupon_code = '', bool $soft_coupon = false) {
$list_amount = round(max(0.0, (float) ($priced['amount'] ?? 0)), 2);
$pay = $list_amount;
$rebate_discount = 0.0;
@@ -421,23 +421,23 @@ trait AKSRT_Content_Pay_Helpers {
$coupon_code = sanitize_text_field($coupon_code);
if ($coupon_code !== '') {
if (!$this->is_coupon_allowed((int) $post->ID, $meta)) {
- $err = new WP_Error('aksrt_coupon_not_allowed', __('当前内容不支持优惠码。', 'aksrt'), ['status' => 400]);
+ $err = new \WP_Error('aksrt_coupon_not_allowed', __('当前内容不支持优惠码。', 'aksrt'), ['status' => 400]);
if (!$soft_coupon) {
return $err;
}
- } elseif (!class_exists('AKSRT_Coupon')) {
- $err = new WP_Error('aksrt_coupon_unavailable', __('优惠券系统不可用。', 'aksrt'), ['status' => 500]);
+ } elseif (!class_exists('\AKSRT\Payment\Coupon')) {
+ $err = new \WP_Error('aksrt_coupon_unavailable', __('优惠券系统不可用。', 'aksrt'), ['status' => 500]);
if (!$soft_coupon) {
return $err;
}
} else {
- $result = AKSRT_Coupon::get_instance()->validate($coupon_code, $pay, [
+ $result = \AKSRT\Payment\Coupon::get_instance()->validate($coupon_code, $pay, [
'user_id' => max(0, $user_id),
'product_ids' => [(int) $post->ID],
'context' => 'content',
]);
if (empty($result['valid'])) {
- $err = new WP_Error(
+ $err = new \WP_Error(
'aksrt_coupon_error',
(string) ($result['message'] ?? __('优惠码不可用。', 'aksrt')),
['status' => 400]
diff --git a/inc/classes/content/content-pay-traits/trait-aksrt-content-pay-orders.php b/src/AKSRT/Content/PayOrders.php
similarity index 77%
rename from inc/classes/content/content-pay-traits/trait-aksrt-content-pay-orders.php
rename to src/AKSRT/Content/PayOrders.php
index 43d9da70..c673cae0 100644
--- a/inc/classes/content/content-pay-traits/trait-aksrt-content-pay-orders.php
+++ b/src/AKSRT/Content/PayOrders.php
@@ -1,13 +1,13 @@
post_type !== 'post') {
+ if (!($post instanceof \WP_Post) || $post->post_type !== 'post') {
return;
}
if (function_exists('aksrt_bump_content_sales_volume')) {
aksrt_bump_content_sales_volume($post_id, 1);
} else {
- $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);
update_post_meta($post_id, $key, $cur + 1);
}
@@ -43,8 +43,8 @@ trait AKSRT_Content_Pay_Orders {
$uid = (int) ($paid_order['user_id'] ?? 0);
if ($uid <= 0 && function_exists('aksrt_set_guest_content_pay_cookies')) {
// Ensure full order row for token material.
- if (class_exists('AKSRT_Order_Repository')) {
- $full = AKSRT_Order_Repository::get_instance()->get($order_number);
+ if (class_exists('\AKSRT\Payment\OrderRepository')) {
+ $full = \AKSRT\Payment\OrderRepository::get_instance()->get($order_number);
if (is_array($full)) {
$paid_order = array_merge($full, $paid_order);
}
@@ -85,18 +85,18 @@ trait AKSRT_Content_Pay_Orders {
if ($referrer_id <= 0 || $rebate_price <= 0 || $pay_amount <= 0) {
return;
}
- if (!class_exists('AKSRT_Rebate')) {
+ if (!class_exists('\AKSRT\Payment\Rebate')) {
return;
}
if ($this->rebate_log_exists($order_number, $referrer_id)) {
return;
}
- AKSRT_Rebate::get_instance()->create([
+ \AKSRT\Payment\Rebate::get_instance()->create([
'user_id' => $referrer_id,
'order_number' => $order_number,
'source_user_id' => $buyer_id,
'amount' => $rebate_price,
- 'type' => AKSRT_Rebate::TYPE_ORDER,
+ 'type' => \AKSRT\Payment\Rebate::TYPE_ORDER,
'note' => sprintf(
/* translators: 1: order number 2: post id */
__('内容推广返佣 订单 %1$s 内容 #%2$d', 'aksrt'),
@@ -128,7 +128,7 @@ trait AKSRT_Content_Pay_Orders {
private function rebate_log_exists(string $order_number, int $referrer_id): bool {
global $wpdb;
- $table = AKSRT_DB_Migrator::table('rebate_log');
+ $table = \AKSRT\Core\DBMigrator::table('rebate_log');
if ($table === '' || $order_number === '') {
return false;
}
@@ -145,7 +145,7 @@ trait AKSRT_Content_Pay_Orders {
/**
* Points one-shot purchase → permanent resource order.
*
- * @return array|WP_Error
+ * @return array|\WP_Error
*/
public function create_and_pay_points(int $post_id, int $user_id, string $price_type = '') {
$assert = $this->assert_purchasable($post_id, $user_id, $price_type);
@@ -155,7 +155,7 @@ trait AKSRT_Content_Pay_Orders {
$priced = $assert['priced'];
if ((($priced['modo'] ?? '0') !== 'points')) {
- return new WP_Error('aksrt_wrong_modo', __('该内容不支持积分支付。', 'aksrt'), ['status' => 400]);
+ return new \WP_Error('aksrt_wrong_modo', __('该内容不支持积分支付。', 'aksrt'), ['status' => 400]);
}
$amount = (int) ceil((float) ($priced['amount'] ?? 0));
@@ -170,13 +170,13 @@ trait AKSRT_Content_Pay_Orders {
];
}
- if (!class_exists('AKSRT_Order') || !class_exists('AKSRT_Credits')) {
- return new WP_Error('aksrt_pay_unavailable', __('支付系统不可用。', 'aksrt'), ['status' => 500]);
+ if (!class_exists('\AKSRT\Payment\Order') || !class_exists('\AKSRT\Credits\Credits')) {
+ return new \WP_Error('aksrt_pay_unavailable', __('支付系统不可用。', 'aksrt'), ['status' => 500]);
}
- $balance = AKSRT_Credits::balance($user_id);
+ $balance = \AKSRT\Credits\Credits::balance($user_id);
if ($balance < $amount) {
- return new WP_Error('aksrt_credits_insufficient', __('积分不足,暂时无法支付。', 'aksrt'), [
+ return new \WP_Error('aksrt_credits_insufficient', __('积分不足,暂时无法支付。', 'aksrt'), [
'status' => 402,
'balance' => $balance,
'cost' => $amount,
@@ -193,23 +193,23 @@ trait AKSRT_Content_Pay_Orders {
'amount' => $amount,
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
- $order_number = AKSRT_Order_Repository::get_instance()->create([
+ $order_number = \AKSRT\Payment\OrderRepository::get_instance()->create([
'user_id' => $user_id,
- 'product_type' => AKSRT_Domain_Model::ORDER_PRODUCT_RESOURCE,
+ 'product_type' => \AKSRT\Core\DomainModel::ORDER_PRODUCT_RESOURCE,
'product_id' => $post_id,
'amount' => (float) $amount,
'currency' => 'points',
- 'status' => AKSRT_Order::STATUS_PENDING,
+ 'status' => \AKSRT\Payment\Order::STATUS_PENDING,
'payment_method' => 'points',
'note' => is_string($note) ? $note : '',
'expires_at' => gmdate('Y-m-d H:i:s', time() + 30 * MINUTE_IN_SECONDS),
]);
if ($order_number === '') {
- return new WP_Error('aksrt_order_create_failed', __('创建订单失败。', 'aksrt'), ['status' => 500]);
+ return new \WP_Error('aksrt_order_create_failed', __('创建订单失败。', 'aksrt'), ['status' => 500]);
}
- $deducted = AKSRT_Credits::deduct(
+ $deducted = \AKSRT\Credits\Credits::deduct(
$user_id,
$amount,
'content_points_pay',
@@ -218,28 +218,28 @@ trait AKSRT_Content_Pay_Orders {
);
if (is_wp_error($deducted) || $deducted === false) {
- AKSRT_Order::get_instance()->update_status($order_number, AKSRT_Order::STATUS_CANCELLED, [
+ \AKSRT\Payment\Order::get_instance()->update_status($order_number, \AKSRT\Payment\Order::STATUS_CANCELLED, [
'note' => __('积分扣除失败,自动取消', 'aksrt'),
]);
$msg = is_wp_error($deducted) ? $deducted->get_error_message() : __('积分扣除失败。', 'aksrt');
- return new WP_Error('aksrt_credits_deduct_failed', $msg ?: __('积分扣除失败。', 'aksrt'), ['status' => 400]);
+ return new \WP_Error('aksrt_credits_deduct_failed', $msg ?: __('积分扣除失败。', 'aksrt'), ['status' => 400]);
}
- $paid = AKSRT_Order::get_instance()->update_status($order_number, AKSRT_Order::STATUS_PAID, [
+ $paid = \AKSRT\Payment\Order::get_instance()->update_status($order_number, \AKSRT\Payment\Order::STATUS_PAID, [
'payment_method' => 'points',
'payment_transaction_id' => 'points_' . $order_number,
'note' => sprintf(__('积分支付 %d 积分。', 'aksrt'), $amount),
]);
if (!$paid) {
- AKSRT_Credits::add(
+ \AKSRT\Credits\Credits::add(
$user_id,
$amount,
'content_points_pay_refund',
['type' => 'post', 'id' => $post_id, 'order' => $order_number],
sprintf(__('购买失败退款:%s', 'aksrt'), get_the_title($post_id))
);
- return new WP_Error('aksrt_order_confirm_failed', __('订单确认失败,已尝试退回积分。', 'aksrt'), ['status' => 500]);
+ return new \WP_Error('aksrt_order_confirm_failed', __('订单确认失败,已尝试退回积分。', 'aksrt'), ['status' => 500]);
}
return [
@@ -248,7 +248,7 @@ trait AKSRT_Content_Pay_Orders {
'order_number' => $order_number,
'amount' => $amount,
'pay_modo' => 'points',
- 'balance' => AKSRT_Credits::balance($user_id),
+ 'balance' => \AKSRT\Credits\Credits::balance($user_id),
'message' => __('支付成功', 'aksrt'),
'reload' => true,
],
@@ -260,7 +260,7 @@ trait AKSRT_Content_Pay_Orders {
/**
* Cash order create + balance/gateway pay.
*
- * @return array|WP_Error
+ * @return array|\WP_Error
*/
public function create_cash_order(int $post_id, int $user_id, string $payment_method = 'balance', string $price_type = '', string $coupon_code = '') {
$assert = $this->assert_purchasable($post_id, $user_id, $price_type);
@@ -272,14 +272,14 @@ trait AKSRT_Content_Pay_Orders {
$meta = $assert['meta'];
$priced = $assert['priced'];
if ((($priced['modo'] ?? '0') === 'points')) {
- return new WP_Error('aksrt_wrong_modo', __('该内容仅支持积分支付。', 'aksrt'), ['status' => 400]);
+ return new \WP_Error('aksrt_wrong_modo', __('该内容仅支持积分支付。', 'aksrt'), ['status' => 400]);
}
// Card pass cannot stack coupon (zibll). Content cashier does not sell via card_pass.
$payment_method = sanitize_key($payment_method);
if ($payment_method === 'card_pass') {
if (!function_exists('aksrt_is_content_card_pass_pay_allowed') || !aksrt_is_content_card_pass_pay_allowed($post)) {
- return new WP_Error(
+ return new \WP_Error(
'aksrt_card_pass_not_allowed',
__('内容购买不支持卡密支付,请在用户中心使用卡密兑换余额/会员/积分。', 'aksrt'),
['status' => 400]
@@ -303,8 +303,8 @@ trait AKSRT_Content_Pay_Orders {
if ($amount <= 0) {
// Free after discount (or free content): create 0-paid order for access + burn coupon.
- if (!class_exists('AKSRT_Order') || !class_exists('AKSRT_Order_Repository')) {
- return new WP_Error('aksrt_pay_unavailable', __('支付系统不可用。', 'aksrt'), ['status' => 500]);
+ if (!class_exists('\AKSRT\Payment\Order') || !class_exists('\AKSRT\Payment\OrderRepository')) {
+ return new \WP_Error('aksrt_pay_unavailable', __('支付系统不可用。', 'aksrt'), ['status' => 500]);
}
$note = wp_json_encode([
'content_pay' => 1,
@@ -327,27 +327,27 @@ trait AKSRT_Content_Pay_Orders {
'guest' => $user_id <= 0 ? 1 : 0,
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
- $order_number = AKSRT_Order_Repository::get_instance()->create([
+ $order_number = \AKSRT\Payment\OrderRepository::get_instance()->create([
'user_id' => max(0, $user_id),
- 'product_type' => AKSRT_Domain_Model::ORDER_PRODUCT_RESOURCE,
+ 'product_type' => \AKSRT\Core\DomainModel::ORDER_PRODUCT_RESOURCE,
'product_id' => $post_id,
'amount' => 0.0,
'currency' => 'CNY',
- 'status' => AKSRT_Order::STATUS_PENDING,
+ 'status' => \AKSRT\Payment\Order::STATUS_PENDING,
'payment_method' => 'free',
'note' => is_string($note) ? $note : '',
'expires_at' => gmdate('Y-m-d H:i:s', time() + 30 * MINUTE_IN_SECONDS),
]);
if ($order_number === '') {
- return new WP_Error('aksrt_order_create_failed', __('创建订单失败。', 'aksrt'), ['status' => 500]);
+ return new \WP_Error('aksrt_order_create_failed', __('创建订单失败。', 'aksrt'), ['status' => 500]);
}
- $paid = AKSRT_Order::get_instance()->update_status($order_number, AKSRT_Order::STATUS_PAID, [
+ $paid = \AKSRT\Payment\Order::get_instance()->update_status($order_number, \AKSRT\Payment\Order::STATUS_PAID, [
'payment_method' => 'free',
'payment_transaction_id' => 'free_' . $order_number,
'note' => __('优惠后无需支付。', 'aksrt'),
]);
if (!$paid) {
- return new WP_Error('aksrt_order_confirm_failed', __('订单确认失败。', 'aksrt'), ['status' => 500]);
+ return new \WP_Error('aksrt_order_confirm_failed', __('订单确认失败。', 'aksrt'), ['status' => 500]);
}
return [
'success' => true,
@@ -362,8 +362,8 @@ trait AKSRT_Content_Pay_Orders {
];
}
- if (!class_exists('AKSRT_Order') || !class_exists('AKSRT_Order_Repository')) {
- return new WP_Error('aksrt_pay_unavailable', __('支付系统不可用。', 'aksrt'), ['status' => 500]);
+ if (!class_exists('\AKSRT\Payment\Order') || !class_exists('\AKSRT\Payment\OrderRepository')) {
+ return new \WP_Error('aksrt_pay_unavailable', __('支付系统不可用。', 'aksrt'), ['status' => 500]);
}
if ($payment_method === '') {
@@ -413,25 +413,25 @@ trait AKSRT_Content_Pay_Orders {
'guest' => $user_id <= 0 ? 1 : 0,
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
- $order_number = AKSRT_Order_Repository::get_instance()->create([
+ $order_number = \AKSRT\Payment\OrderRepository::get_instance()->create([
'user_id' => max(0, $user_id),
- 'product_type' => AKSRT_Domain_Model::ORDER_PRODUCT_RESOURCE,
+ 'product_type' => \AKSRT\Core\DomainModel::ORDER_PRODUCT_RESOURCE,
'product_id' => $post_id,
'amount' => $amount,
'currency' => 'CNY',
- 'status' => AKSRT_Order::STATUS_PENDING,
+ 'status' => \AKSRT\Payment\Order::STATUS_PENDING,
'payment_method' => $payment_method,
'note' => is_string($note) ? $note : '',
'expires_at' => gmdate('Y-m-d H:i:s', time() + 30 * MINUTE_IN_SECONDS),
]);
if ($order_number === '') {
- return new WP_Error('aksrt_order_create_failed', __('创建订单失败。', 'aksrt'), ['status' => 500]);
+ return new \WP_Error('aksrt_order_create_failed', __('创建订单失败。', 'aksrt'), ['status' => 500]);
}
- $order = AKSRT_Order_Repository::get_instance()->get($order_number);
+ $order = \AKSRT\Payment\OrderRepository::get_instance()->get($order_number);
if (!$order) {
- return new WP_Error('aksrt_order_create_failed', __('创建订单失败。', 'aksrt'), ['status' => 500]);
+ return new \WP_Error('aksrt_order_create_failed', __('创建订单失败。', 'aksrt'), ['status' => 500]);
}
}
@@ -449,20 +449,20 @@ trait AKSRT_Content_Pay_Orders {
// Ensure gateway uses discounted amount.
$order['amount'] = $amount;
- if (!class_exists('AKSRT_Payment_Gateway')) {
- return new WP_Error('aksrt_pay_unavailable', __('支付网关不可用。', 'aksrt'), ['status' => 500]);
+ if (!class_exists('\AKSRT\Payment\Gateway')) {
+ return new \WP_Error('aksrt_pay_unavailable', __('支付网关不可用。', 'aksrt'), ['status' => 500]);
}
- $gateway_manager = AKSRT_Payment_Gateway::get_instance();
+ $gateway_manager = \AKSRT\Payment\Gateway::get_instance();
$gateway = $gateway_manager->get_gateway($payment_method);
if (!$gateway) {
- return new WP_Error('aksrt_gateway_unavailable', __('当前支付方式不可用。', 'aksrt'), [
+ return new \WP_Error('aksrt_gateway_unavailable', __('当前支付方式不可用。', 'aksrt'), [
'status' => 400,
'order_number' => $order_number,
]);
}
if (method_exists($gateway, 'is_configured') && !$gateway->is_configured()) {
- return new WP_Error('aksrt_gateway_unconfigured', __('该支付方式尚未配置,请联系站长。', 'aksrt'), [
+ return new \WP_Error('aksrt_gateway_unconfigured', __('该支付方式尚未配置,请联系站长。', 'aksrt'), [
'status' => 400,
'order_number' => $order_number,
]);
@@ -474,7 +474,7 @@ trait AKSRT_Content_Pay_Orders {
$code = ($payment_method === 'balance' && (str_contains($msg, '余额') || str_contains($msg, '不足')))
? 'aksrt_balance_insufficient'
: 'aksrt_pay_failed';
- return new WP_Error($code, $msg, [
+ return new \WP_Error($code, $msg, [
'status' => 402,
'order_number' => $order_number,
]);
@@ -500,13 +500,13 @@ trait AKSRT_Content_Pay_Orders {
}
// Sync gateway (balance): mark paid.
- $paid = AKSRT_Order::get_instance()->update_status($order_number, AKSRT_Order::STATUS_PAID, [
+ $paid = \AKSRT\Payment\Order::get_instance()->update_status($order_number, \AKSRT\Payment\Order::STATUS_PAID, [
'payment_method' => $payment_method,
'payment_transaction_id' => sanitize_text_field((string) ($payment_result['transaction_id'] ?? '')),
'note' => __('用户完成内容购买支付。', 'aksrt'),
]);
if (!$paid) {
- return new WP_Error('aksrt_order_confirm_failed', __('订单确认失败。', 'aksrt'), ['status' => 500]);
+ return new \WP_Error('aksrt_order_confirm_failed', __('订单确认失败。', 'aksrt'), ['status' => 500]);
}
return [
@@ -527,12 +527,12 @@ trait AKSRT_Content_Pay_Orders {
* @return array|null
*/
private function find_pending_content_order(int $user_id, int $post_id): ?array {
- if ($user_id <= 0 || $post_id <= 0 || !class_exists('AKSRT_Order_Repository')) {
+ if ($user_id <= 0 || $post_id <= 0 || !class_exists('\AKSRT\Payment\OrderRepository')) {
return null;
}
- $orders = AKSRT_Order_Repository::get_instance()->get_user_orders($user_id, [
- 'product_type' => AKSRT_Domain_Model::ORDER_PRODUCT_RESOURCE,
- 'status' => AKSRT_Domain_Model::ORDER_STATUS_PENDING,
+ $orders = \AKSRT\Payment\OrderRepository::get_instance()->get_user_orders($user_id, [
+ 'product_type' => \AKSRT\Core\DomainModel::ORDER_PRODUCT_RESOURCE,
+ 'status' => \AKSRT\Core\DomainModel::ORDER_STATUS_PENDING,
'limit' => 20,
'offset' => 0,
]);
diff --git a/inc/classes/content/content-pay-traits/trait-aksrt-content-pay-rest.php b/src/AKSRT/Content/PayRest.php
similarity index 76%
rename from inc/classes/content/content-pay-traits/trait-aksrt-content-pay-rest.php
rename to src/AKSRT/Content/PayRest.php
index cf495569..f5b30faa 100644
--- a/inc/classes/content/content-pay-traits/trait-aksrt-content-pay-rest.php
+++ b/src/AKSRT/Content/PayRest.php
@@ -1,18 +1,18 @@
\\d+)', [
+ register_rest_route('aksrt/v1', '/pay/content/(?P\d+)', [
[
'methods' => 'GET',
'callback' => [$this, 'rest_preview'],
@@ -37,16 +37,16 @@ trait AKSRT_Content_Pay_Rest {
/**
* REST nonce for logged-in users (wp_rest). Guests get 401 on purchase paths.
*
- * @param WP_REST_Request $request
- * @return true|WP_Error
+ * @param \WP_REST_Request $request
+ * @return true|\WP_Error
*/
- public function check_rest_nonce(WP_REST_Request $request) {
+ public function check_rest_nonce(\WP_REST_Request $request) {
$nonce = $request->get_header('x-wp-nonce');
if (!$nonce) {
- return new WP_Error('aksrt_rest_no_nonce', __('缺少安全令牌', 'aksrt'), ['status' => 403]);
+ return new \WP_Error('aksrt_rest_no_nonce', __('缺少安全令牌', 'aksrt'), ['status' => 403]);
}
if (!wp_verify_nonce($nonce, 'wp_rest')) {
- return new WP_Error('aksrt_rest_bad_nonce', __('安全令牌已过期,请刷新页面', 'aksrt'), ['status' => 403]);
+ return new \WP_Error('aksrt_rest_bad_nonce', __('安全令牌已过期,请刷新页面', 'aksrt'), ['status' => 403]);
}
return true;
}
@@ -57,7 +57,7 @@ trait AKSRT_Content_Pay_Rest {
* GET /pay/content/{id}
* query: coupon_code?, price_type?
*/
- public function rest_preview(WP_REST_Request $request) {
+ public function rest_preview(\WP_REST_Request $request) {
$post_id = (int) $request['id'];
$uid = get_current_user_id();
$coupon_code = sanitize_text_field((string) ($request->get_param('coupon_code') ?? $request->get_param('coupon') ?? ''));
@@ -69,7 +69,7 @@ trait AKSRT_Content_Pay_Rest {
if (is_wp_error($preview)) {
return $preview;
}
- return new WP_REST_Response($preview, 200);
+ return new \WP_REST_Response($preview, 200);
}
@@ -78,7 +78,7 @@ trait AKSRT_Content_Pay_Rest {
* POST /pay/content/{id}
* body: { mode?: points|cash, payment_method?: balance|alipay|..., price_type?: ''|download_limit_over, coupon_code?: string }
*/
- public function rest_purchase(WP_REST_Request $request) {
+ public function rest_purchase(\WP_REST_Request $request) {
$post_id = (int) $request['id'];
$uid = get_current_user_id();
@@ -98,7 +98,7 @@ trait AKSRT_Content_Pay_Rest {
$post = get_post($post_id);
$allow_guest = function_exists('aksrt_allow_guest_content_pay') && aksrt_allow_guest_content_pay($post);
if (!$allow_guest) {
- return new WP_Error('aksrt_need_login', __('请先登录后再购买。', 'aksrt'), [
+ return new \WP_Error('aksrt_need_login', __('请先登录后再购买。', 'aksrt'), [
'status' => 401,
'login_url' => wp_login_url($post ? get_permalink($post) : home_url('/')),
]);
@@ -119,7 +119,7 @@ trait AKSRT_Content_Pay_Rest {
}
if ($mode === 'points' || $pay_modo === 'points') {
if ($uid <= 0) {
- return new WP_Error('aksrt_need_login', __('积分支付请先登录。', 'aksrt'), ['status' => 401]);
+ return new \WP_Error('aksrt_need_login', __('积分支付请先登录。', 'aksrt'), ['status' => 401]);
}
// Points path: ignore coupon (zibll parity).
return $this->rest_wrap_result($this->create_and_pay_points($post_id, $uid, $price_type));
@@ -141,13 +141,13 @@ trait AKSRT_Content_Pay_Rest {
/**
* GET /pay/content/order/{order_number}
*/
- public function rest_order_status(WP_REST_Request $request) {
+ public function rest_order_status(\WP_REST_Request $request) {
$uid = get_current_user_id();
$order_number = sanitize_text_field((string) $request['order_number']);
- if ($order_number === '' || !class_exists('AKSRT_Order_Repository')) {
- return new WP_Error('aksrt_invalid', __('订单不存在', 'aksrt'), ['status' => 404]);
+ if ($order_number === '' || !class_exists('\AKSRT\Payment\OrderRepository')) {
+ return new \WP_Error('aksrt_invalid', __('订单不存在', 'aksrt'), ['status' => 404]);
}
- $repo = AKSRT_Order_Repository::get_instance();
+ $repo = \AKSRT\Payment\OrderRepository::get_instance();
if ($uid > 0) {
$order = $repo->get_user_order($uid, $order_number);
} else {
@@ -155,23 +155,23 @@ trait AKSRT_Content_Pay_Rest {
// Guest may only poll own guest cash orders (user_id=0): content/topic resource or plate_follow.
$ptype = sanitize_key((string) ($order['product_type'] ?? ''));
$guest_types = [
- AKSRT_Domain_Model::ORDER_PRODUCT_RESOURCE,
- AKSRT_Domain_Model::ORDER_PRODUCT_PLATE_FOLLOW,
+ \AKSRT\Core\DomainModel::ORDER_PRODUCT_RESOURCE,
+ \AKSRT\Core\DomainModel::ORDER_PRODUCT_PLATE_FOLLOW,
];
if ($order && ((int) ($order['user_id'] ?? -1) !== 0 || !in_array($ptype, $guest_types, true))) {
$order = null;
}
}
if (!$order) {
- return new WP_Error('aksrt_invalid', __('订单不存在', 'aksrt'), ['status' => 404]);
+ return new \WP_Error('aksrt_invalid', __('订单不存在', 'aksrt'), ['status' => 404]);
}
$status = (string) ($order['status'] ?? '');
- $paid = class_exists('AKSRT_Domain_Model') && AKSRT_Domain_Model::is_paid_order_status($status);
+ $paid = class_exists('\AKSRT\Core\DomainModel') && \AKSRT\Core\DomainModel::is_paid_order_status($status);
if ($paid && $uid <= 0 && function_exists('aksrt_set_guest_pay_cookies')) {
// Ensure cookie set even if notify raced ahead of browser cookie.
aksrt_set_guest_pay_cookies($order);
}
- return new WP_REST_Response([
+ return new \WP_REST_Response([
'order_number' => $order_number,
'status' => $status,
'paid' => $paid,
@@ -186,8 +186,8 @@ trait AKSRT_Content_Pay_Rest {
/**
- * @param array|WP_Error $result
- * @return WP_REST_Response|WP_Error
+ * @param array|\WP_Error $result
+ * @return \WP_REST_Response|\WP_Error
*/
private function rest_wrap_result($result) {
if (is_wp_error($result)) {
@@ -196,12 +196,12 @@ trait AKSRT_Content_Pay_Rest {
if (empty($result['success'])) {
$code = sanitize_key((string) ($result['code'] ?? 'aksrt_pay_failed'));
$status = (int) ($result['status'] ?? 400);
- return new WP_Error($code !== '' ? $code : 'aksrt_pay_failed', (string) ($result['message'] ?? __('支付失败', 'aksrt')), array_merge(
+ return new \WP_Error($code !== '' ? $code : 'aksrt_pay_failed', (string) ($result['message'] ?? __('支付失败', 'aksrt')), array_merge(
['status' => $status > 0 ? $status : 400],
is_array($result['data'] ?? null) ? $result['data'] : []
));
}
- return new WP_REST_Response($result, 200);
+ return new \WP_REST_Response($result, 200);
}
}
diff --git a/inc/classes/content/class-aksrt-vip-service.php b/src/AKSRT/Content/VipService.php
similarity index 55%
rename from inc/classes/content/class-aksrt-vip-service.php
rename to src/AKSRT/Content/VipService.php
index 63e00ee4..031f0a7f 100644
--- a/inc/classes/content/class-aksrt-vip-service.php
+++ b/src/AKSRT/Content/VipService.php
@@ -1,21 +1,16 @@
'balance', 'name' => __('站内余额', 'aksrt')]];
}
- $gw = AKSRT_Payment_Gateway::get_instance();
+ $gw = \AKSRT\Payment\Gateway::get_instance();
foreach (['balance', 'alipay', 'wechatpay', 'paypal', 'stripe'] as $id) {
$g = $gw->get_gateway($id);
if (!$g) {
@@ -461,8 +461,8 @@ trait AKSRT_Vip_Service_Packages {
private function format_cash_label(float $amount): string {
$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();
$symbol = (string) ($paid['display']['currency_symbol'] ?? '¥');
}
$n = function_exists('aksrt_format_price') ? aksrt_format_price($amount) : (string) $amount;
diff --git a/inc/classes/content/vip-service-traits/trait-aksrt-vip-service-purchase.php b/src/AKSRT/Content/VipServicePurchase.php
similarity index 76%
rename from inc/classes/content/vip-service-traits/trait-aksrt-vip-service-purchase.php
rename to src/AKSRT/Content/VipServicePurchase.php
index 63d63f23..4273f0e4 100644
--- a/inc/classes/content/vip-service-traits/trait-aksrt-vip-service-purchase.php
+++ b/src/AKSRT/Content/VipServicePurchase.php
@@ -1,13 +1,13 @@
*/
public function get_catalog(int $user_id = 0): array {
- $vip = class_exists('AKSRT_Settings')
- ? AKSRT_Settings::get_payment_vip_settings()
+ $vip = class_exists('\AKSRT\Settings\Settings')
+ ? \AKSRT\Settings\Settings::get_payment_vip_settings()
: ['enabled' => false, 'packages_raw' => '', 'levels' => [], 'renew' => [], 'upgrade' => [], 'points_exchange' => []];
$level = function_exists('aksrt_get_user_vip_level') ? aksrt_get_user_vip_level($user_id) : 0;
@@ -30,7 +30,7 @@ trait AKSRT_Vip_Service_Purchase {
$renew_enabled = !isset($renew['enabled']) || !empty($renew['enabled']);
$upgrade_enabled = !isset($upgrade['enabled']) || !empty($upgrade['enabled']);
$points_enabled = !empty($points_ex['enabled'])
- && (!class_exists('AKSRT_Settings') || AKSRT_Settings::credits_enabled());
+ && (!class_exists('\AKSRT\Settings\Settings') || \AKSRT\Settings\Settings::credits_enabled());
$level_packages = [];
foreach ([1, 2] as $lv) {
@@ -112,9 +112,9 @@ trait AKSRT_Vip_Service_Purchase {
$points_packages = $this->get_points_exchange_packages($vip, $levels);
}
- $balance = ($user_id > 0 && class_exists('AKSRT_Credits')) ? AKSRT_Credits::balance($user_id) : 0;
+ $balance = ($user_id > 0 && class_exists('\AKSRT\Credits\Credits')) ? \AKSRT\Credits\Credits::balance($user_id) : 0;
$methods = $this->available_payment_methods();
- $currency_name = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_currency_name() : __('积分', 'aksrt');
+ $currency_name = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_currency_name() : __('积分', 'aksrt');
return [
'enabled' => !empty($vip['enabled']),
@@ -147,29 +147,29 @@ trait AKSRT_Vip_Service_Purchase {
/**
- * @return array|WP_Error
+ * @return array|\WP_Error
*/
public function purchase(int $user_id, int $package_id, string $payment_method = 'balance') {
if ($user_id <= 0) {
- return new WP_Error('aksrt_need_login', __('请先登录后再开通会员。', 'aksrt'), ['status' => 401]);
+ return new \WP_Error('aksrt_need_login', __('请先登录后再开通会员。', 'aksrt'), ['status' => 401]);
}
$decoded = $this->decode_package_id($package_id);
if (!$decoded) {
- return new WP_Error('aksrt_invalid_package', __('套餐无效', 'aksrt'), ['status' => 400]);
+ return new \WP_Error('aksrt_invalid_package', __('套餐无效', 'aksrt'), ['status' => 400]);
}
$level = (int) $decoded['level'];
$index = (int) $decoded['index'];
- $vip = class_exists('AKSRT_Settings')
- ? AKSRT_Settings::get_payment_vip_settings()
+ $vip = class_exists('\AKSRT\Settings\Settings')
+ ? \AKSRT\Settings\Settings::get_payment_vip_settings()
: ['enabled' => false, 'packages_raw' => '', 'levels' => [], 'renew' => [], 'upgrade' => []];
if (empty($vip['enabled'])) {
- return new WP_Error('aksrt_vip_disabled', __('会员功能未启用', 'aksrt'), ['status' => 400]);
+ return new \WP_Error('aksrt_vip_disabled', __('会员功能未启用', 'aksrt'), ['status' => 400]);
}
$levels = is_array($vip['levels'] ?? null) ? $vip['levels'] : [];
if (empty($levels[$level]['enabled'])) {
- return new WP_Error('aksrt_vip_level_disabled', __('该会员等级未启用', 'aksrt'), ['status' => 400]);
+ return new \WP_Error('aksrt_vip_level_disabled', __('该会员等级未启用', 'aksrt'), ['status' => 400]);
}
$user_level = function_exists('aksrt_get_user_vip_level') ? aksrt_get_user_vip_level($user_id) : 0;
@@ -181,16 +181,16 @@ trait AKSRT_Vip_Service_Purchase {
$upgrade_enabled = !isset($upgrade['enabled']) || !empty($upgrade['enabled']);
if ($is_permanent && $level <= $user_level) {
- return new WP_Error('aksrt_vip_permanent', __('您已是永久会员,无需续费。', 'aksrt'), ['status' => 400]);
+ return new \WP_Error('aksrt_vip_permanent', __('您已是永久会员,无需续费。', 'aksrt'), ['status' => 400]);
}
if ($user_level > 0 && $level === $user_level && !$renew_enabled) {
- return new WP_Error('aksrt_vip_renew_disabled', __('续费功能未开启。', 'aksrt'), ['status' => 400]);
+ return new \WP_Error('aksrt_vip_renew_disabled', __('续费功能未开启。', 'aksrt'), ['status' => 400]);
}
if ($user_level > 0 && $level > $user_level && !$upgrade_enabled) {
- return new WP_Error('aksrt_vip_upgrade_disabled', __('升级功能未开启。', 'aksrt'), ['status' => 400]);
+ return new \WP_Error('aksrt_vip_upgrade_disabled', __('升级功能未开启。', 'aksrt'), ['status' => 400]);
}
if ($user_level > 0 && $level < $user_level) {
- return new WP_Error('aksrt_vip_downgrade', __('不支持降级购买。', 'aksrt'), ['status' => 400]);
+ return new \WP_Error('aksrt_vip_downgrade', __('不支持降级购买。', 'aksrt'), ['status' => 400]);
}
$action = 'pay';
@@ -213,7 +213,7 @@ trait AKSRT_Vip_Service_Purchase {
}
}
if (!$match || $level !== 2) {
- return new WP_Error('aksrt_invalid_package', __('升级套餐不存在', 'aksrt'), ['status' => 400]);
+ return new \WP_Error('aksrt_invalid_package', __('升级套餐不存在', 'aksrt'), ['status' => 400]);
}
$pkg = [
'price' => (float) $match['price'],
@@ -230,24 +230,24 @@ trait AKSRT_Vip_Service_Purchase {
$packages = $this->parse_packages((string) ($vip['packages_raw'] ?? ''));
$pkg = $packages[$index - 1] ?? null;
if (!$pkg) {
- return new WP_Error('aksrt_invalid_package', __('套餐不存在', 'aksrt'), ['status' => 400]);
+ return new \WP_Error('aksrt_invalid_package', __('套餐不存在', 'aksrt'), ['status' => 400]);
}
$base_price = (float) $pkg['price'];
$days = (int) $pkg['days'];
$priced = $this->apply_action_price($base_price, $action, $renew, $upgrade, $level, $user_level, $expires, $is_permanent, $days);
if ($priced === null) {
- return new WP_Error('aksrt_invalid_package', __('当前无法购买该套餐', 'aksrt'), ['status' => 400]);
+ return new \WP_Error('aksrt_invalid_package', __('当前无法购买该套餐', 'aksrt'), ['status' => 400]);
}
$amount = round((float) $priced['price'], 2);
$discount_tag = (string) ($priced['tag'] ?? '');
}
if ($amount <= 0) {
- return new WP_Error('aksrt_invalid_price', __('套餐价格无效', 'aksrt'), ['status' => 400]);
+ return new \WP_Error('aksrt_invalid_price', __('套餐价格无效', 'aksrt'), ['status' => 400]);
}
- if (!class_exists('AKSRT_Order') || !class_exists('AKSRT_Order_Repository')) {
- return new WP_Error('aksrt_pay_unavailable', __('支付系统不可用', 'aksrt'), ['status' => 500]);
+ if (!class_exists('\AKSRT\Payment\Order') || !class_exists('\AKSRT\Payment\OrderRepository')) {
+ return new \WP_Error('aksrt_pay_unavailable', __('支付系统不可用', 'aksrt'), ['status' => 500]);
}
$payment_method = sanitize_key($payment_method);
@@ -268,24 +268,24 @@ trait AKSRT_Vip_Service_Purchase {
'discount_tag' => $discount_tag,
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
- $order_number = AKSRT_Order_Repository::get_instance()->create([
+ $order_number = \AKSRT\Payment\OrderRepository::get_instance()->create([
'user_id' => $user_id,
- 'product_type' => AKSRT_Domain_Model::ORDER_PRODUCT_VIP,
+ 'product_type' => \AKSRT\Core\DomainModel::ORDER_PRODUCT_VIP,
'product_id' => $package_id,
'amount' => $amount,
'currency' => 'CNY',
- 'status' => AKSRT_Order::STATUS_PENDING,
+ 'status' => \AKSRT\Payment\Order::STATUS_PENDING,
'payment_method' => $payment_method,
'note' => is_string($note) ? $note : '',
'expires_at' => gmdate('Y-m-d H:i:s', time() + 30 * MINUTE_IN_SECONDS),
]);
if ($order_number === '') {
- return new WP_Error('aksrt_order_create_failed', __('创建订单失败', 'aksrt'), ['status' => 500]);
+ return new \WP_Error('aksrt_order_create_failed', __('创建订单失败', 'aksrt'), ['status' => 500]);
}
- $order = AKSRT_Order_Repository::get_instance()->get($order_number);
+ $order = \AKSRT\Payment\OrderRepository::get_instance()->get($order_number);
if (!$order) {
- return new WP_Error('aksrt_order_create_failed', __('创建订单失败', 'aksrt'), ['status' => 500]);
+ return new \WP_Error('aksrt_order_create_failed', __('创建订单失败', 'aksrt'), ['status' => 500]);
}
$level_name = (string) ($levels[$level]['name'] ?? ('VIP' . $level));
@@ -299,18 +299,18 @@ trait AKSRT_Vip_Service_Purchase {
);
$order['payment_method'] = $payment_method;
- if (!class_exists('AKSRT_Payment_Gateway')) {
- return new WP_Error('aksrt_pay_unavailable', __('支付网关不可用', 'aksrt'), ['status' => 500]);
+ if (!class_exists('\AKSRT\Payment\Gateway')) {
+ return new \WP_Error('aksrt_pay_unavailable', __('支付网关不可用', 'aksrt'), ['status' => 500]);
}
- $gateway = AKSRT_Payment_Gateway::get_instance()->get_gateway($payment_method);
+ $gateway = \AKSRT\Payment\Gateway::get_instance()->get_gateway($payment_method);
if (!$gateway) {
- return new WP_Error('aksrt_gateway_unavailable', __('当前支付方式不可用', 'aksrt'), [
+ return new \WP_Error('aksrt_gateway_unavailable', __('当前支付方式不可用', 'aksrt'), [
'status' => 400,
'order_number' => $order_number,
]);
}
if (method_exists($gateway, 'is_configured') && !$gateway->is_configured()) {
- return new WP_Error('aksrt_gateway_unconfigured', __('该支付方式尚未配置,请联系站长。', 'aksrt'), [
+ return new \WP_Error('aksrt_gateway_unconfigured', __('该支付方式尚未配置,请联系站长。', 'aksrt'), [
'status' => 400,
'order_number' => $order_number,
]);
@@ -322,7 +322,7 @@ trait AKSRT_Vip_Service_Purchase {
$code = ($payment_method === 'balance' && (str_contains($msg, '余额') || str_contains($msg, '不足')))
? 'aksrt_balance_insufficient'
: 'aksrt_pay_failed';
- return new WP_Error($code, $msg, [
+ return new \WP_Error($code, $msg, [
'status' => 402,
'order_number' => $order_number,
]);
@@ -346,13 +346,13 @@ trait AKSRT_Vip_Service_Purchase {
];
}
- $paid = AKSRT_Order::get_instance()->update_status($order_number, AKSRT_Order::STATUS_PAID, [
+ $paid = \AKSRT\Payment\Order::get_instance()->update_status($order_number, \AKSRT\Payment\Order::STATUS_PAID, [
'payment_method' => $payment_method,
'payment_transaction_id' => sanitize_text_field((string) ($payment_result['transaction_id'] ?? '')),
'note' => __('用户完成会员开通支付。', 'aksrt'),
]);
if (!$paid) {
- return new WP_Error('aksrt_order_confirm_failed', __('订单确认失败', 'aksrt'), ['status' => 500]);
+ return new \WP_Error('aksrt_order_confirm_failed', __('订单确认失败', 'aksrt'), ['status' => 500]);
}
return [
@@ -380,7 +380,7 @@ trait AKSRT_Vip_Service_Purchase {
* @param array $paid_order
*/
public function on_order_paid(string $order_number, array $paid_order): void {
- if (sanitize_key((string) ($paid_order['product_type'] ?? '')) !== AKSRT_Domain_Model::ORDER_PRODUCT_VIP) {
+ if (sanitize_key((string) ($paid_order['product_type'] ?? '')) !== \AKSRT\Core\DomainModel::ORDER_PRODUCT_VIP) {
return;
}
$user_id = (int) ($paid_order['user_id'] ?? 0);
@@ -465,30 +465,30 @@ trait AKSRT_Vip_Service_Purchase {
/**
* Points exchange (non-VIP only, zibll pay_vip_points_exchange).
*
- * @return array|WP_Error
+ * @return array|\WP_Error
*/
public function exchange_with_points(int $user_id, int $package_id) {
if ($user_id <= 0) {
- return new WP_Error('aksrt_need_login', __('请先登录后再兑换。', 'aksrt'), ['status' => 401]);
+ return new \WP_Error('aksrt_need_login', __('请先登录后再兑换。', 'aksrt'), ['status' => 401]);
}
- if (!class_exists('AKSRT_Credits')) {
- return new WP_Error('aksrt_credits_unavailable', __('积分系统不可用', 'aksrt'), ['status' => 500]);
+ if (!class_exists('\AKSRT\Credits\Credits')) {
+ return new \WP_Error('aksrt_credits_unavailable', __('积分系统不可用', 'aksrt'), ['status' => 500]);
}
- if (class_exists('AKSRT_Settings') && !AKSRT_Settings::credits_enabled()) {
- return new WP_Error('aksrt_credits_disabled', __('积分功能未启用', 'aksrt'), ['status' => 400]);
+ if (class_exists('\AKSRT\Settings\Settings') && !\AKSRT\Settings\Settings::credits_enabled()) {
+ return new \WP_Error('aksrt_credits_disabled', __('积分功能未启用', 'aksrt'), ['status' => 400]);
}
- $vip = class_exists('AKSRT_Settings')
- ? AKSRT_Settings::get_payment_vip_settings()
+ $vip = class_exists('\AKSRT\Settings\Settings')
+ ? \AKSRT\Settings\Settings::get_payment_vip_settings()
: [];
$points_ex = is_array($vip['points_exchange'] ?? null) ? $vip['points_exchange'] : [];
if (empty($points_ex['enabled'])) {
- return new WP_Error('aksrt_points_exchange_disabled', __('积分兑换会员未启用', 'aksrt'), ['status' => 400]);
+ return new \WP_Error('aksrt_points_exchange_disabled', __('积分兑换会员未启用', 'aksrt'), ['status' => 400]);
}
$user_level = function_exists('aksrt_get_user_vip_level') ? aksrt_get_user_vip_level($user_id) : 0;
if ($user_level > 0) {
- return new WP_Error('aksrt_already_vip', __('您已是会员,无法使用积分兑换。', 'aksrt'), ['status' => 400]);
+ return new \WP_Error('aksrt_already_vip', __('您已是会员,无法使用积分兑换。', 'aksrt'), ['status' => 400]);
}
$levels = is_array($vip['levels'] ?? null) ? $vip['levels'] : [];
@@ -501,27 +501,27 @@ trait AKSRT_Vip_Service_Purchase {
}
}
if (!$match) {
- return new WP_Error('aksrt_invalid_package', __('兑换套餐不存在', 'aksrt'), ['status' => 400]);
+ return new \WP_Error('aksrt_invalid_package', __('兑换套餐不存在', 'aksrt'), ['status' => 400]);
}
$cost = (int) ($match['points'] ?? 0);
$level = (int) ($match['level'] ?? 1);
$days = (int) ($match['days'] ?? 0);
if ($cost <= 0) {
- return new WP_Error('aksrt_invalid_price', __('兑换积分无效', 'aksrt'), ['status' => 400]);
+ return new \WP_Error('aksrt_invalid_price', __('兑换积分无效', 'aksrt'), ['status' => 400]);
}
- $balance = AKSRT_Credits::balance($user_id);
+ $balance = \AKSRT\Credits\Credits::balance($user_id);
if ($balance < $cost) {
- return new WP_Error('aksrt_credits_insufficient', __('积分不足,暂时无法兑换', 'aksrt'), [
+ return new \WP_Error('aksrt_credits_insufficient', __('积分不足,暂时无法兑换', 'aksrt'), [
'status' => 402,
'balance' => $balance,
'cost' => $cost,
]);
}
- if (!class_exists('AKSRT_Order') || !class_exists('AKSRT_Order_Repository')) {
- return new WP_Error('aksrt_pay_unavailable', __('订单系统不可用', 'aksrt'), ['status' => 500]);
+ if (!class_exists('\AKSRT\Payment\Order') || !class_exists('\AKSRT\Payment\OrderRepository')) {
+ return new \WP_Error('aksrt_pay_unavailable', __('订单系统不可用', 'aksrt'), ['status' => 500]);
}
$note = wp_json_encode([
@@ -535,22 +535,22 @@ trait AKSRT_Vip_Service_Purchase {
'action' => 'points_exchange',
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
- $order_number = AKSRT_Order_Repository::get_instance()->create([
+ $order_number = \AKSRT\Payment\OrderRepository::get_instance()->create([
'user_id' => $user_id,
- 'product_type' => AKSRT_Domain_Model::ORDER_PRODUCT_VIP,
+ 'product_type' => \AKSRT\Core\DomainModel::ORDER_PRODUCT_VIP,
'product_id' => $package_id,
'amount' => (float) $cost,
'currency' => 'points',
- 'status' => AKSRT_Order::STATUS_PENDING,
+ 'status' => \AKSRT\Payment\Order::STATUS_PENDING,
'payment_method' => 'points',
'note' => is_string($note) ? $note : '',
'expires_at' => gmdate('Y-m-d H:i:s', time() + 30 * MINUTE_IN_SECONDS),
]);
if ($order_number === '') {
- return new WP_Error('aksrt_order_create_failed', __('创建订单失败', 'aksrt'), ['status' => 500]);
+ return new \WP_Error('aksrt_order_create_failed', __('创建订单失败', 'aksrt'), ['status' => 500]);
}
- $deducted = AKSRT_Credits::deduct(
+ $deducted = \AKSRT\Credits\Credits::deduct(
$user_id,
$cost,
'vip_points_exchange',
@@ -558,27 +558,27 @@ trait AKSRT_Vip_Service_Purchase {
sprintf(__('积分兑换会员 · %s', 'aksrt'), (string) ($match['title'] ?? ''))
);
if (is_wp_error($deducted) || $deducted === false) {
- AKSRT_Order::get_instance()->update_status($order_number, AKSRT_Order::STATUS_CANCELLED, [
+ \AKSRT\Payment\Order::get_instance()->update_status($order_number, \AKSRT\Payment\Order::STATUS_CANCELLED, [
'note' => __('积分扣除失败,自动取消', 'aksrt'),
]);
$msg = is_wp_error($deducted) ? $deducted->get_error_message() : __('积分扣除失败', 'aksrt');
- return new WP_Error('aksrt_credits_deduct_failed', $msg ?: __('积分扣除失败', 'aksrt'), ['status' => 400]);
+ return new \WP_Error('aksrt_credits_deduct_failed', $msg ?: __('积分扣除失败', 'aksrt'), ['status' => 400]);
}
- $paid = AKSRT_Order::get_instance()->update_status($order_number, AKSRT_Order::STATUS_PAID, [
+ $paid = \AKSRT\Payment\Order::get_instance()->update_status($order_number, \AKSRT\Payment\Order::STATUS_PAID, [
'payment_method' => 'points',
'payment_transaction_id' => 'points_' . $order_number,
'note' => sprintf(__('积分兑换会员 %d 积分。', 'aksrt'), $cost),
]);
if (!$paid) {
- AKSRT_Credits::add(
+ \AKSRT\Credits\Credits::add(
$user_id,
$cost,
'vip_points_exchange_refund',
['order' => $order_number],
__('会员兑换失败退款', 'aksrt')
);
- return new WP_Error('aksrt_order_confirm_failed', __('兑换确认失败,已尝试退回积分', 'aksrt'), ['status' => 500]);
+ return new \WP_Error('aksrt_order_confirm_failed', __('兑换确认失败,已尝试退回积分', 'aksrt'), ['status' => 500]);
}
return [
@@ -588,7 +588,7 @@ trait AKSRT_Vip_Service_Purchase {
'points' => $cost,
'level' => $level,
'days' => $days,
- 'balance' => AKSRT_Credits::balance($user_id),
+ 'balance' => \AKSRT\Credits\Credits::balance($user_id),
'message' => __('兑换成功', 'aksrt'),
'reload' => true,
],
diff --git a/inc/classes/content/vip-service-traits/trait-aksrt-vip-service-rest.php b/src/AKSRT/Content/VipServiceRest.php
similarity index 72%
rename from inc/classes/content/vip-service-traits/trait-aksrt-vip-service-rest.php
rename to src/AKSRT/Content/VipServiceRest.php
index 203d0fcf..091315d3 100644
--- a/inc/classes/content/vip-service-traits/trait-aksrt-vip-service-rest.php
+++ b/src/AKSRT/Content/VipServiceRest.php
@@ -1,13 +1,13 @@
get_header('x-wp-nonce');
if (!$nonce) {
- return new WP_Error('aksrt_rest_no_nonce', __('缺少安全令牌', 'aksrt'), ['status' => 403]);
+ return new \WP_Error('aksrt_rest_no_nonce', __('缺少安全令牌', 'aksrt'), ['status' => 403]);
}
if (!wp_verify_nonce($nonce, 'wp_rest')) {
- return new WP_Error('aksrt_rest_bad_nonce', __('安全令牌已过期,请刷新页面', 'aksrt'), ['status' => 403]);
+ return new \WP_Error('aksrt_rest_bad_nonce', __('安全令牌已过期,请刷新页面', 'aksrt'), ['status' => 403]);
}
return true;
}
@@ -54,9 +54,9 @@ trait AKSRT_Vip_Service_Rest {
/**
* GET /pay/vip
*/
- public function rest_catalog(WP_REST_Request $request) {
+ public function rest_catalog(\WP_REST_Request $request) {
$uid = get_current_user_id();
- return new WP_REST_Response($this->get_catalog($uid), 200);
+ return new \WP_REST_Response($this->get_catalog($uid), 200);
}
@@ -65,10 +65,10 @@ trait AKSRT_Vip_Service_Rest {
* POST /pay/vip
* body: { package_id: int, payment_method?: string }
*/
- public function rest_purchase(WP_REST_Request $request) {
+ public function rest_purchase(\WP_REST_Request $request) {
$uid = get_current_user_id();
if ($uid <= 0) {
- return new WP_Error('aksrt_need_login', __('请先登录后再开通会员。', 'aksrt'), [
+ return new \WP_Error('aksrt_need_login', __('请先登录后再开通会员。', 'aksrt'), [
'status' => 401,
'login_url' => function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : wp_login_url(),
]);
@@ -89,13 +89,13 @@ trait AKSRT_Vip_Service_Rest {
return $result;
}
if (empty($result['success'])) {
- return new WP_Error(
+ return new \WP_Error(
sanitize_key((string) ($result['code'] ?? 'aksrt_vip_pay_failed')),
(string) ($result['message'] ?? __('开通失败', 'aksrt')),
['status' => (int) ($result['status'] ?? 400)]
);
}
- return new WP_REST_Response($result, 200);
+ return new \WP_REST_Response($result, 200);
}
@@ -104,10 +104,10 @@ trait AKSRT_Vip_Service_Rest {
* POST /pay/vip/points-exchange
* body: { package_id: int } // points package id = 5000 + index
*/
- public function rest_points_exchange(WP_REST_Request $request) {
+ public function rest_points_exchange(\WP_REST_Request $request) {
$uid = get_current_user_id();
if ($uid <= 0) {
- return new WP_Error('aksrt_need_login', __('请先登录后再兑换。', 'aksrt'), ['status' => 401]);
+ return new \WP_Error('aksrt_need_login', __('请先登录后再兑换。', 'aksrt'), ['status' => 401]);
}
$params = $request->get_json_params();
if (!is_array($params)) {
@@ -118,7 +118,7 @@ trait AKSRT_Vip_Service_Rest {
if (is_wp_error($result)) {
return $result;
}
- return new WP_REST_Response($result, 200);
+ return new \WP_REST_Response($result, 200);
}
}
diff --git a/inc/classes/content/class-aksrt-content-visibility.php b/src/AKSRT/Content/Visibility.php
similarity index 84%
rename from inc/classes/content/class-aksrt-content-visibility.php
rename to src/AKSRT/Content/Visibility.php
index c00a2c6e..3ecc3aaf 100644
--- a/inc/classes/content/class-aksrt-content-visibility.php
+++ b/src/AKSRT/Content/Visibility.php
@@ -1,15 +1,13 @@
*/
public static function get_post_access_state($post = null, int $user_id = 0): array {
@@ -36,8 +34,8 @@ class AKSRT_Content_Visibility {
$uid = $user_id > 0 ? $user_id : get_current_user_id();
$pay_meta = function_exists('aksrt_get_pay_meta')
? aksrt_get_pay_meta($resource_post)
- : AKSRT_Domain_Model::default_pay_meta();
- $pay_type = AKSRT_Domain_Model::normalize_pay_type((string) ($pay_meta['pay_type'] ?? AKSRT_Domain_Model::PAY_TYPE_NO));
+ : \AKSRT\Core\DomainModel::default_pay_meta();
+ $pay_type = \AKSRT\Core\DomainModel::normalize_pay_type((string) ($pay_meta['pay_type'] ?? \AKSRT\Core\DomainModel::PAY_TYPE_NO));
$priced = function_exists('aksrt_get_user_pay_price')
? aksrt_get_user_pay_price($resource_post, $uid)
: null;
@@ -49,8 +47,8 @@ class AKSRT_Content_Visibility {
: (($pay_modo === 'points')
? (float) ($pay_meta['points_price'] ?? 0)
: (float) ($pay_meta['price'] ?? 0));
- $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,
'download_credit' => true,
@@ -58,7 +56,7 @@ class AKSRT_Content_Visibility {
];
$state = [
- 'post_id' => $resource_post instanceof WP_Post ? (int) $resource_post->ID : 0,
+ 'post_id' => $resource_post instanceof \WP_Post ? (int) $resource_post->ID : 0,
'pay_type' => $pay_type,
'pay_modo' => $pay_modo,
'price' => $price,
@@ -74,18 +72,18 @@ class AKSRT_Content_Visibility {
'user_vip_level' => 0,
];
- if (!($resource_post instanceof WP_Post)) {
+ if (!($resource_post instanceof \WP_Post)) {
$state['can_view'] = false;
$state['can_download'] = false;
return $state;
}
- if ($pay_type === AKSRT_Domain_Model::PAY_TYPE_NO) {
+ if ($pay_type === \AKSRT\Core\DomainModel::PAY_TYPE_NO) {
$state['has_paid_access'] = true;
return $state;
}
- $has_free_access = $price <= 0 && $pay_type !== AKSRT_Domain_Model::PAY_TYPE_VIP;
+ $has_free_access = $price <= 0 && $pay_type !== \AKSRT\Core\DomainModel::PAY_TYPE_VIP;
$pay_limit = (int) ($pay_meta['pay_limit'] ?? 0);
if (!in_array($pay_limit, [0, 1, 2], true)) {
$pay_limit = 0;
@@ -93,10 +91,10 @@ class AKSRT_Content_Visibility {
$state['pay_limit'] = $pay_limit;
$has_paid_order = false;
- if ($uid > 0 && class_exists('AKSRT_Order')) {
- $has_paid_order = AKSRT_Order::get_instance()->has_paid_access(
+ if ($uid > 0 && class_exists('\AKSRT\Payment\Order')) {
+ $has_paid_order = \AKSRT\Payment\Order::get_instance()->has_paid_access(
$uid,
- AKSRT_Domain_Model::ORDER_PRODUCT_RESOURCE,
+ \AKSRT\Core\DomainModel::ORDER_PRODUCT_RESOURCE,
(int) $resource_post->ID
);
}
@@ -114,7 +112,7 @@ class AKSRT_Content_Visibility {
if (function_exists('aksrt_is_vip_exempt') && aksrt_is_vip_exempt($uid)) {
$has_vip_access = true;
$user_vip_level = max($user_vip_level, 2);
- } elseif ($pay_type === AKSRT_Domain_Model::PAY_TYPE_VIP || $pay_limit > 0) {
+ } elseif ($pay_type === \AKSRT\Core\DomainModel::PAY_TYPE_VIP || $pay_limit > 0) {
$has_vip_access = $user_vip_level >= max(1, $pay_limit);
} elseif ($user_vip_level > 0) {
// VIP tier pricing may zero cost; still track membership.
@@ -124,10 +122,10 @@ class AKSRT_Content_Visibility {
$state['user_vip_level'] = $user_vip_level;
// Member-only purchase restriction (Zibll pay_limit).
- if ($pay_limit > 0 && $pay_type !== AKSRT_Domain_Model::PAY_TYPE_NO) {
+ if ($pay_limit > 0 && $pay_type !== \AKSRT\Core\DomainModel::PAY_TYPE_NO) {
$state['need_vip'] = $uid <= 0 || $user_vip_level < $pay_limit;
$allowed_member = $uid > 0 && $user_vip_level >= $pay_limit;
- if ($pay_type === AKSRT_Domain_Model::PAY_TYPE_DOWNLOAD) {
+ if ($pay_type === \AKSRT\Core\DomainModel::PAY_TYPE_DOWNLOAD) {
// Cash: order gate only. Points: cashier once → paid order zeros cost.
$download_cost = 0;
if ($pay_modo === 'points' && $price > 0 && !$has_paid_order) {
@@ -166,7 +164,7 @@ class AKSRT_Content_Visibility {
return $state;
}
- if ($pay_type === AKSRT_Domain_Model::PAY_TYPE_DOWNLOAD) {
+ if ($pay_type === \AKSRT\Core\DomainModel::PAY_TYPE_DOWNLOAD) {
// Zibll: cash = order unlock; points = one-shot cashier order (not per-download deduct).
$download_cost = 0;
if ($pay_modo === 'points' && $price > 0 && !$has_paid_order) {
@@ -188,7 +186,7 @@ class AKSRT_Content_Visibility {
return $state;
}
- if ($pay_type === AKSRT_Domain_Model::PAY_TYPE_VIP) {
+ if ($pay_type === \AKSRT\Core\DomainModel::PAY_TYPE_VIP) {
$state['need_vip'] = true;
$state['has_paid_access'] = $has_vip_access;
$state['can_view'] = $has_vip_access;
@@ -201,7 +199,7 @@ class AKSRT_Content_Visibility {
$state['need_purchase'] = !$has_free_access && !$has_paid_order;
$state['has_paid_access'] = $has_free_access || $has_paid_order;
// VIP free tier for reading etc. via amount.
- if (!$state['has_paid_access'] && $price <= 0 && $pay_type !== AKSRT_Domain_Model::PAY_TYPE_VIP) {
+ if (!$state['has_paid_access'] && $price <= 0 && $pay_type !== \AKSRT\Core\DomainModel::PAY_TYPE_VIP) {
$state['has_paid_access'] = true;
$state['need_purchase'] = false;
}
@@ -217,24 +215,24 @@ class AKSRT_Content_Visibility {
}
/**
- * @param int|WP_Post|null $post
- * @return true|WP_Error
+ * @param int|\WP_Post|null $post
+ * @return true|\WP_Error
*/
public static function can_download_resource($post = null, int $user_id = 0) {
$resource_post = get_post($post);
- if (!($resource_post instanceof WP_Post) || !function_exists('aksrt_is_downloadable_content') || !aksrt_is_downloadable_content($resource_post)) {
- return new WP_Error('aksrt_not_downloadable', __('该内容未启用下载能力。', 'aksrt'));
+ if (!($resource_post instanceof \WP_Post) || !function_exists('aksrt_is_downloadable_content') || !aksrt_is_downloadable_content($resource_post)) {
+ return new \WP_Error('aksrt_not_downloadable', __('该内容未启用下载能力。', 'aksrt'));
}
$state = self::get_post_access_state($resource_post, $user_id);
$uid = $user_id > 0 ? $user_id : get_current_user_id();
- if (($state['pay_type'] ?? '') !== AKSRT_Domain_Model::PAY_TYPE_DOWNLOAD) {
- return new WP_Error('aksrt_not_downloadable', __('该内容未启用下载能力。', 'aksrt'));
+ if (($state['pay_type'] ?? '') !== \AKSRT\Core\DomainModel::PAY_TYPE_DOWNLOAD) {
+ return new \WP_Error('aksrt_not_downloadable', __('该内容未启用下载能力。', 'aksrt'));
}
if (!empty($state['need_login']) && $uid <= 0) {
- return new WP_Error('aksrt_need_login', __('请先登录后再下载。', 'aksrt'), [
+ return new \WP_Error('aksrt_need_login', __('请先登录后再下载。', 'aksrt'), [
'status' => 401,
'login_url' => wp_login_url(get_permalink($resource_post)),
]);
@@ -242,12 +240,12 @@ class AKSRT_Content_Visibility {
// Free download + pay_free_logged_show (belt-and-suspenders with state.need_login).
$cost = (int) ($state['download_cost'] ?? 0);
- $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_credit' => true, 'free_logged_show' => false];
if ($cost <= 0 && !empty($paid_settings['free_logged_show']) && $uid <= 0) {
- return new WP_Error('aksrt_need_login', __('免费资源,请登录后下载。', 'aksrt'), [
+ return new \WP_Error('aksrt_need_login', __('免费资源,请登录后下载。', 'aksrt'), [
'status' => 401,
'login_url' => wp_login_url(get_permalink($resource_post)),
]);
@@ -256,7 +254,7 @@ class AKSRT_Content_Visibility {
// Member-only (pay_limit).
if (!empty($state['need_vip']) && empty($state['has_paid_access']) && empty($state['can_download'])) {
$need_level = (int) ($state['pay_limit'] ?? 1);
- return new WP_Error('aksrt_need_vip', sprintf(
+ return new \WP_Error('aksrt_need_vip', sprintf(
/* translators: %d: required VIP level */
__('该资源仅限 VIP%s 及以上会员购买/下载。', 'aksrt'),
max(1, $need_level)
@@ -270,7 +268,7 @@ class AKSRT_Content_Visibility {
if (!empty($state['need_purchase']) && empty($state['has_paid_access'])) {
$pay_modo = (string) ($state['pay_modo'] ?? '0');
$price = (float) ($state['price'] ?? 0);
- return new WP_Error('aksrt_need_purchase', __('请先购买后再下载。', 'aksrt'), [
+ return new \WP_Error('aksrt_need_purchase', __('请先购买后再下载。', 'aksrt'), [
'status' => 402,
'pay_modo' => $pay_modo,
'amount' => $pay_modo === 'points' ? (int) ceil($price) : $price,
@@ -282,7 +280,7 @@ class AKSRT_Content_Visibility {
if ($cost <= 0 && function_exists('aksrt_check_free_download_quota')) {
// Provide per-post overbuy price to quota error.
$over_cb = static function ($over, $uid) use ($resource_post) {
- if (!($resource_post instanceof WP_Post) || !function_exists('aksrt_get_pay_meta')) {
+ if (!($resource_post instanceof \WP_Post) || !function_exists('aksrt_get_pay_meta')) {
return $over;
}
$m = aksrt_get_pay_meta($resource_post);
@@ -295,7 +293,7 @@ class AKSRT_Content_Visibility {
$data = (array) $quota->get_error_data();
$data['post_id'] = (int) ($state['post_id'] ?? 0);
$data['pay_modo'] = (string) ($state['pay_modo'] ?? '0');
- return new WP_Error($quota->get_error_code(), $quota->get_error_message(), $data);
+ return new \WP_Error($quota->get_error_code(), $quota->get_error_message(), $data);
}
}
diff --git a/inc/classes/core/class-aksrt-category-rewrite.php b/src/AKSRT/Core/CategoryRewrite.php
similarity index 89%
rename from inc/classes/core/class-aksrt-category-rewrite.php
rename to src/AKSRT/Core/CategoryRewrite.php
index fbe86fe8..30cce4eb 100644
--- a/inc/classes/core/class-aksrt-category-rewrite.php
+++ b/src/AKSRT/Core/CategoryRewrite.php
@@ -1,19 +1,13 @@
taxonomy !== 'category') {
+ if ($term instanceof \WP_Term && $term->taxonomy !== 'category') {
return $link;
}
diff --git a/inc/classes/core/class-aksrt-comment-actions.php b/src/AKSRT/Core/CommentActions.php
similarity index 98%
rename from inc/classes/core/class-aksrt-comment-actions.php
rename to src/AKSRT/Core/CommentActions.php
index b1df3767..f20bb720 100644
--- a/inc/classes/core/class-aksrt-comment-actions.php
+++ b/src/AKSRT/Core/CommentActions.php
@@ -1,15 +1,13 @@
posts as $post) {
diff --git a/src/AKSRT/Core/DomainModel.php b/src/AKSRT/Core/DomainModel.php
new file mode 100644
index 00000000..33185acc
--- /dev/null
+++ b/src/AKSRT/Core/DomainModel.php
@@ -0,0 +1,449 @@
+
+ */
+ public static function default_post_meta(): array {
+ return [
+ 'cover_images' => '',
+ 'custom_excerpt' => '',
+ 'layout_override' => '',
+ 'header_image_mode' => '',
+ 'show_toc' => '',
+ 'show_reading_progress' => '',
+ 'enable_lightbox' => '',
+ 'show_related' => '',
+ 'related_count' => 0,
+ 'enable_like' => '',
+ 'enable_favorite' => '',
+ 'enable_share' => '',
+ 'enable_print' => '',
+ 'enable_pdf' => '',
+ 'copyright_text' => '',
+ 'is_featured' => false,
+ // §3.8 文章扩展字段
+ 'thumbnail_url' => '',
+ 'featured_slide' => '',
+ 'featured_video' => '',
+ // Episode list: [ ['url' => string, 'title' => string], ... ]
+ 'featured_video_episode' => [],
+ 'subtitle' => '',
+ 'views' => 0,
+ 'likes' => 0,
+ 'maxheight' => 0,
+ ];
+ }
+
+ /**
+ * @return array
+ */
+ public static function default_term_meta(): array {
+ return [
+ 'cover_url' => '',
+ 'description' => '',
+ 'layout_mode' => '',
+ 'show_sidebar' => '',
+ 'show_header' => true,
+ 'show_featured' => false,
+ ];
+ }
+
+ /**
+ * @return array
+ */
+ public static function default_pay_meta(): array {
+ return [
+ 'pay_type' => self::PAY_TYPE_NO,
+ 'pay_modo' => '0', // '0' cash | 'points' credits (Zibll)
+ 'price' => 0.0,
+ 'points_price' => 0,
+ 'original_price' => 0.0,
+ 'vip1_price' => 0.0,
+ 'vip2_price' => 0.0,
+ 'vip1_points' => 0,
+ 'vip2_points' => 0,
+ 'pay_limit' => 0, // 0 all | 1 VIP1+ | 2 VIP2 only (Zibll)
+ 'version' => '',
+ 'size' => '',
+ 'license' => '',
+ 'compat' => '',
+ 'demo_url' => '',
+ 'video_url' => '',
+ 'downloads' => [],
+ 'attributes' => [],
+ 'gallery' => [],
+ 'require_login' => false,
+ 'require_captcha' => false,
+ // §3.8 电商增强字段
+ 'virtual_sales' => 0,
+ 'stock' => -1,
+ 'card_keys' => [],
+ 'purchase_limit' => 0,
+ 'free_preview' => '',
+ 'show_sales' => true,
+ // Zibll: free daily quota overbuy price (cash or points by pay_modo).
+ 'download_limit_over_price' => 0.0,
+ // Content cashier: coupon + buyer-facing 推广折扣 (zibll posts_zibpay).
+ 'coupon_s' => false,
+ 'coupon_desc' => '',
+ 'pay_rebate_discount' => 0.0,
+ ];
+ }
+
+ /**
+ * @return array
+ */
+ public static function pay_type_labels(): array {
+ return [
+ self::PAY_TYPE_NO => '不付费',
+ self::PAY_TYPE_READING => '付费阅读',
+ self::PAY_TYPE_DOWNLOAD => '付费下载',
+ self::PAY_TYPE_GALLERY => '付费图库',
+ self::PAY_TYPE_VIDEO => '付费视频',
+ self::PAY_TYPE_VIP => 'VIP 专属',
+ ];
+ }
+
+ public static function normalize_pay_type(string $pay_type): string {
+ $pay_type = sanitize_key($pay_type);
+ return array_key_exists($pay_type, self::pay_type_labels()) ? $pay_type : self::PAY_TYPE_NO;
+ }
+
+ public static function is_resource_pay_type(string $pay_type): bool {
+ return self::normalize_pay_type($pay_type) === self::PAY_TYPE_DOWNLOAD;
+ }
+
+ /**
+ * @param mixed $value
+ * @return array>
+ */
+ public static function sanitize_downloads($value): array {
+ if (!is_array($value)) {
+ return [];
+ }
+
+ $allowed_types = ['direct', 'net_disk', 'external'];
+ $downloads = [];
+
+ foreach ($value as $row) {
+ if (!is_array($row)) {
+ continue;
+ }
+
+ $url = isset($row['url']) ? esc_url_raw((string) $row['url']) : '';
+ if ($url === '') {
+ continue;
+ }
+
+ $type = isset($row['type']) && in_array($row['type'], $allowed_types, true)
+ ? (string) $row['type']
+ : 'direct';
+
+ $extract_code = '';
+ foreach ([
+ 'extract_code',
+ 'extractCode',
+ 'extract',
+ 'extract_key',
+ 'extraction_code',
+ 'extractionCode',
+ 'code',
+ 'password',
+ 'pwd',
+ 'pan_code',
+ 'panCode',
+ 'pan_password',
+ 'panPassword',
+ 'access_code',
+ 'accessCode',
+ ] as $extract_key) {
+ if (isset($row[$extract_key]) && !is_array($row[$extract_key])) {
+ $candidate = trim((string) $row[$extract_key]);
+ if ($candidate !== '') {
+ $extract_code = sanitize_text_field($candidate);
+ break;
+ }
+ }
+ }
+
+ $downloads[] = [
+ 'label' => isset($row['label']) ? sanitize_text_field((string) $row['label']) : '',
+ 'url' => $url,
+ 'type' => $type,
+ 'extract_code' => $extract_code,
+ ];
+ }
+
+ return array_values($downloads);
+ }
+
+ /**
+ * @param mixed $value
+ * @return array>
+ */
+ public static function sanitize_attributes($value): array {
+ if (!is_array($value)) {
+ return [];
+ }
+
+ $attributes = [];
+
+ foreach ($value as $row) {
+ if (!is_array($row)) {
+ continue;
+ }
+
+ $key = sanitize_text_field((string) ($row['key'] ?? ''));
+ $item_value = sanitize_text_field((string) ($row['value'] ?? ''));
+
+ if ($key === '' && $item_value === '') {
+ continue;
+ }
+
+ $attributes[] = [
+ 'key' => $key,
+ 'value' => $item_value,
+ ];
+ }
+
+ return array_values($attributes);
+ }
+
+ /**
+ * @param mixed $value
+ * @return string[]
+ */
+ public static function sanitize_gallery($value): array {
+ if (!is_array($value)) {
+ return [];
+ }
+
+ $gallery = [];
+ foreach ($value as $url) {
+ $url = esc_url_raw((string) $url);
+ if ($url !== '') {
+ $gallery[] = $url;
+ }
+ }
+
+ return array_values(array_unique($gallery));
+ }
+
+ /**
+ * Sanitize card/key codes for auto-delivery.
+ * Each entry is a non-empty sanitized string (one code per line).
+ */
+ public static function sanitize_card_keys($value): array {
+ if (!is_array($value)) {
+ return [];
+ }
+
+ $keys = [];
+ foreach ($value as $key) {
+ $key = sanitize_text_field((string) $key);
+ if ($key !== '') {
+ $keys[] = $key;
+ }
+ }
+
+ return $keys;
+ }
+
+ /**
+ * @param array $raw
+ * @return array
+ */
+ public static function sanitize_pay_meta(array $raw): array {
+ $meta = self::default_pay_meta();
+ $meta['pay_type'] = self::normalize_pay_type((string) ($raw['pay_type'] ?? $meta['pay_type']));
+ $pay_modo = sanitize_key((string) ($raw['pay_modo'] ?? '0'));
+ $meta['pay_modo'] = $pay_modo === 'points' ? 'points' : '0';
+ $meta['price'] = max(0, (float) ($raw['price'] ?? 0));
+ $meta['points_price'] = max(0, (int) ($raw['points_price'] ?? $raw['price'] ?? 0));
+ $meta['original_price'] = max(0, (float) ($raw['original_price'] ?? 0));
+ $meta['vip1_price'] = max(0, (float) ($raw['vip1_price'] ?? 0));
+ $meta['vip2_price'] = max(0, (float) ($raw['vip2_price'] ?? 0));
+ $meta['vip1_points'] = max(0, (int) ($raw['vip1_points'] ?? $raw['vip1_price'] ?? 0));
+ $meta['vip2_points'] = max(0, (int) ($raw['vip2_points'] ?? $raw['vip2_price'] ?? 0));
+ $pay_limit = (int) ($raw['pay_limit'] ?? 0);
+ $meta['pay_limit'] = in_array($pay_limit, [0, 1, 2], true) ? $pay_limit : 0;
+ $meta['version'] = sanitize_text_field((string) ($raw['version'] ?? ''));
+ $meta['size'] = sanitize_text_field((string) ($raw['size'] ?? ''));
+ $meta['license'] = sanitize_text_field((string) ($raw['license'] ?? ''));
+ $meta['compat'] = sanitize_text_field((string) ($raw['compat'] ?? ''));
+ $meta['demo_url'] = esc_url_raw((string) ($raw['demo_url'] ?? ''));
+ $meta['video_url'] = esc_url_raw((string) ($raw['video_url'] ?? ''));
+ $meta['downloads'] = self::sanitize_downloads($raw['downloads'] ?? []);
+ $meta['attributes'] = self::sanitize_attributes($raw['attributes'] ?? []);
+ $meta['gallery'] = self::sanitize_gallery($raw['gallery'] ?? []);
+ $meta['require_login'] = !empty($raw['require_login']);
+ $meta['require_captcha'] = !empty($raw['require_captcha']);
+
+ // §3.8 电商增强字段
+ $meta['virtual_sales'] = max(0, (int) ($raw['virtual_sales'] ?? 0));
+ $meta['stock'] = (int) ($raw['stock'] ?? -1);
+ $meta['card_keys'] = self::sanitize_card_keys($raw['card_keys'] ?? []);
+ $meta['purchase_limit'] = max(0, (int) ($raw['purchase_limit'] ?? 0));
+ $meta['free_preview'] = wp_kses_post((string) ($raw['free_preview'] ?? ''));
+ $meta['show_sales'] = !isset($raw['show_sales']) || !empty($raw['show_sales']);
+ $meta['download_limit_over_price'] = max(0, (float) ($raw['download_limit_over_price'] ?? 0));
+ $meta['coupon_s'] = !empty($raw['coupon_s']);
+ $meta['coupon_desc'] = sanitize_textarea_field((string) ($raw['coupon_desc'] ?? ''));
+ $meta['pay_rebate_discount'] = max(0, (float) ($raw['pay_rebate_discount'] ?? 0));
+
+ return $meta;
+ }
+
+ /**
+ * @return array
+ */
+ public static function order_status_labels(): array {
+ return [
+ self::ORDER_STATUS_CREATED => __('已创建', 'aksrt'),
+ self::ORDER_STATUS_PENDING => __('待支付', 'aksrt'),
+ self::ORDER_STATUS_PAID => __('已支付', 'aksrt'),
+ self::ORDER_STATUS_DELIVERED => __('已发货', 'aksrt'),
+ self::ORDER_STATUS_COMPLETED => __('已完成', 'aksrt'),
+ self::ORDER_STATUS_CANCELLED => __('已取消', 'aksrt'),
+ self::ORDER_STATUS_EXPIRED => __('已过期', 'aksrt'),
+ self::ORDER_STATUS_REFUNDING => __('退款中', 'aksrt'),
+ self::ORDER_STATUS_REFUNDED => __('已退款', 'aksrt'),
+ self::ORDER_STATUS_PENDING_REVIEW => __('待评价', 'aksrt'),
+ ];
+ }
+
+ /**
+ * @return array
+ */
+ public static function order_transitions(): array {
+ return [
+ self::ORDER_STATUS_CREATED => [
+ self::ORDER_STATUS_PENDING,
+ self::ORDER_STATUS_CANCELLED,
+ ],
+ self::ORDER_STATUS_PENDING => [
+ self::ORDER_STATUS_PAID,
+ self::ORDER_STATUS_CANCELLED,
+ self::ORDER_STATUS_EXPIRED,
+ ],
+ self::ORDER_STATUS_PAID => [
+ self::ORDER_STATUS_DELIVERED,
+ self::ORDER_STATUS_COMPLETED,
+ self::ORDER_STATUS_REFUNDING,
+ ],
+ self::ORDER_STATUS_DELIVERED => [
+ self::ORDER_STATUS_COMPLETED,
+ self::ORDER_STATUS_PENDING_REVIEW,
+ self::ORDER_STATUS_REFUNDING,
+ ],
+ self::ORDER_STATUS_COMPLETED => [
+ self::ORDER_STATUS_PENDING_REVIEW,
+ self::ORDER_STATUS_REFUNDING,
+ ],
+ self::ORDER_STATUS_CANCELLED => [],
+ self::ORDER_STATUS_EXPIRED => [
+ self::ORDER_STATUS_PENDING,
+ ],
+ self::ORDER_STATUS_REFUNDING => [
+ self::ORDER_STATUS_REFUNDED,
+ self::ORDER_STATUS_PAID,
+ ],
+ self::ORDER_STATUS_REFUNDED => [],
+ self::ORDER_STATUS_PENDING_REVIEW => [
+ self::ORDER_STATUS_COMPLETED,
+ self::ORDER_STATUS_REFUNDING,
+ ],
+ ];
+ }
+
+ public static function normalize_order_status(string $status, string $default = self::ORDER_STATUS_PENDING): string {
+ $status = sanitize_key($status);
+ return array_key_exists($status, self::order_status_labels()) ? $status : $default;
+ }
+
+ public static function can_transition_order_status(string $from, string $to): bool {
+ $from = self::normalize_order_status($from, self::ORDER_STATUS_CREATED);
+ $to = self::normalize_order_status($to);
+ $transitions = self::order_transitions();
+
+ return isset($transitions[$from]) && in_array($to, $transitions[$from], true);
+ }
+
+ /**
+ * @return string[]
+ */
+ public static function paid_order_statuses(): array {
+ return [
+ self::ORDER_STATUS_PAID,
+ self::ORDER_STATUS_DELIVERED,
+ self::ORDER_STATUS_COMPLETED,
+ ];
+ }
+
+ public static function is_paid_order_status(string $status): bool {
+ return in_array(self::normalize_order_status($status), self::paid_order_statuses(), true);
+ }
+
+ /**
+ * @return string[]
+ */
+ public static function vip_active_order_statuses(): array {
+ return self::paid_order_statuses();
+ }
+}
diff --git a/inc/classes/core/class-aksrt-front-submit.php b/src/AKSRT/Core/FrontSubmit.php
similarity index 94%
rename from inc/classes/core/class-aksrt-front-submit.php
rename to src/AKSRT/Core/FrontSubmit.php
index 8be00b85..6bb4b64b 100644
--- a/inc/classes/core/class-aksrt-front-submit.php
+++ b/src/AKSRT/Core/FrontSubmit.php
@@ -1,16 +1,13 @@
0 && class_exists('AKSRT_Credits')) {
- $balance = AKSRT_Credits::balance($user_id);
+ if ($min_credits > 0 && class_exists('\AKSRT\Credits\Credits')) {
+ $balance = \AKSRT\Credits\Credits::balance($user_id);
if ($balance < $min_credits) {
return false;
}
@@ -106,13 +103,13 @@ class AKSRT_Front_Submit {
// Determine review policy: if review is not required and user can publish, auto-publish
if ($status === 'pending') {
$submit_settings = [];
- if (class_exists('AKSRT_Settings')) {
- $submit_settings = AKSRT_Settings::get_value('post_list.submit', []);
+ if (class_exists('\AKSRT\Settings\Settings')) {
+ $submit_settings = \AKSRT\Settings\Settings::get_value('post_list.submit', []);
}
$review_required = $submit_settings['review_required'] ?? true;
$skip_moderation = false;
- if (class_exists('AKSRT_Settings')) {
- $all = AKSRT_Settings::get_all();
+ if (class_exists('\AKSRT\Settings\Settings')) {
+ $all = \AKSRT\Settings\Settings::get_all();
$skip_moderation = !empty($all['skip_submit_moderation']);
}
diff --git a/inc/classes/core/class-aksrt-go-redirect.php b/src/AKSRT/Core/GoRedirect.php
similarity index 90%
rename from inc/classes/core/class-aksrt-go-redirect.php
rename to src/AKSRT/Core/GoRedirect.php
index a0e56b7d..496262e3 100644
--- a/inc/classes/core/class-aksrt-go-redirect.php
+++ b/src/AKSRT/Core/GoRedirect.php
@@ -1,16 +1,13 @@
get_json_params();
if (!is_array($params)) $params = $request->get_params();
$modules = isset($params['modules']) && is_array($params['modules']) ? $params['modules'] : [];
@@ -179,7 +168,7 @@ class AKSRT_Home_Modules {
$id = wp_generate_uuid4();
set_transient(self::PREVIEW_TRANSIENT_PREFIX . $id, $clean, 30 * MINUTE_IN_SECONDS);
- return new WP_REST_Response([
+ return new \WP_REST_Response([
'preview_id' => $id,
'preview_url' => add_query_arg(self::PREVIEW_QUERY_VAR, $id, home_url('/')),
'expires_in' => 30 * MINUTE_IN_SECONDS,
diff --git a/inc/classes/core/class-aksrt-post-meta-box.php b/src/AKSRT/Core/PostMetaBox.php
similarity index 93%
rename from inc/classes/core/class-aksrt-post-meta-box.php
rename to src/AKSRT/Core/PostMetaBox.php
index f1e79b84..c7c938f6 100644
--- a/inc/classes/core/class-aksrt-post-meta-box.php
+++ b/src/AKSRT/Core/PostMetaBox.php
@@ -1,25 +1,17 @@
[]];
if (!empty($filter_settings['custom_filter'])) {
add_meta_box(
@@ -137,7 +129,7 @@ class AKSRT_Post_Meta_Box {
/**
* Render the page meta box (page_header_style / cover override).
*/
- public function render_page_meta_box(WP_Post $post): void {
+ public function render_page_meta_box(\WP_Post $post): void {
$header_style = get_post_meta($post->ID, 'page_header_style', true);
$cover_img = get_post_meta($post->ID, 'page_header_cover_img', true);
wp_nonce_field('aksrt_page_meta', 'aksrt_page_meta_nonce');
@@ -161,7 +153,7 @@ class AKSRT_Post_Meta_Box {
/**
* Render the meta box.
*/
- public function render_meta_box(WP_Post $post): void {
+ public function render_meta_box(\WP_Post $post): void {
$meta = self::get_meta($post->ID);
wp_nonce_field('aksrt_post_meta', 'aksrt_post_meta_nonce');
?>
@@ -305,11 +297,11 @@ class AKSRT_Post_Meta_Box {
* Render the custom filter metabox (per-dimension value selectors).
* §3.8 — stores values as individual post meta keys (_aksrt_cf_{dim_key}).
*/
- public function render_custom_filter_meta_box(WP_Post $post): void {
+ public function render_custom_filter_meta_box(\WP_Post $post): void {
wp_nonce_field('aksrt_custom_filter_meta', 'aksrt_custom_filter_meta_nonce');
- $filter_settings = class_exists('AKSRT_Settings')
- ? AKSRT_Settings::get_post_filter_settings()
+ $filter_settings = class_exists('\AKSRT\Settings\Settings')
+ ? \AKSRT\Settings\Settings::get_post_filter_settings()
: ['custom_filter' => []];
$dimensions = $filter_settings['custom_filter'];
@@ -448,8 +440,8 @@ class AKSRT_Post_Meta_Box {
// §3.8 Save custom filter dimension values as individual post meta
if (isset($_POST['aksrt_custom_filter_meta_nonce']) && wp_verify_nonce($_POST['aksrt_custom_filter_meta_nonce'], 'aksrt_custom_filter_meta')) {
if (!defined('DOING_AUTOSAVE') && current_user_can('edit_post', $post_id)) {
- $cf_settings = class_exists('AKSRT_Settings')
- ? AKSRT_Settings::get_post_filter_settings()
+ $cf_settings = class_exists('\AKSRT\Settings\Settings')
+ ? \AKSRT\Settings\Settings::get_post_filter_settings()
: ['custom_filter' => []];
foreach ($cf_settings['custom_filter'] as $dim) {
$meta_key = '_aksrt_cf_' . $dim['key'];
@@ -497,17 +489,17 @@ class AKSRT_Post_Meta_Box {
* Content-pay sales summary for posts list (zibll 销售数据 column parity).
*/
private function render_sales_column(int $post_id): void {
- if (!function_exists('aksrt_get_pay_meta') || !class_exists('AKSRT_Domain_Model')) {
+ if (!function_exists('aksrt_get_pay_meta') || !class_exists('DomainModel')) {
echo '—';
return;
}
$pay = aksrt_get_pay_meta($post_id);
- $pay_type = AKSRT_Domain_Model::normalize_pay_type((string) ($pay['pay_type'] ?? AKSRT_Domain_Model::PAY_TYPE_NO));
- if ($pay_type === AKSRT_Domain_Model::PAY_TYPE_NO) {
+ $pay_type = DomainModel::normalize_pay_type((string) ($pay['pay_type'] ?? DomainModel::PAY_TYPE_NO));
+ if ($pay_type === DomainModel::PAY_TYPE_NO) {
echo '' . esc_html__('免费', 'aksrt') . '';
return;
}
- $labels = AKSRT_Domain_Model::pay_type_labels();
+ $labels = DomainModel::pay_type_labels();
$type_label = $labels[$pay_type] ?? $pay_type;
$modo = (($pay['pay_modo'] ?? '0') === 'points') ? 'points' : '0';
if ($modo === 'points') {
@@ -515,13 +507,13 @@ class AKSRT_Post_Meta_Box {
} else {
$price_text = '¥' . number_format((float) ($pay['price'] ?? 0), 2);
}
- $meta_sales = (int) get_post_meta($post_id, AKSRT_Domain_Model::RESOURCE_SALES_VOLUME_KEY, true);
+ $meta_sales = (int) get_post_meta($post_id, DomainModel::RESOURCE_SALES_VOLUME_KEY, true);
$db_sales = 0;
$revenue = 0.0;
- if (class_exists('AKSRT_Order_Repository')) {
- $map = AKSRT_Order_Repository::get_instance()->get_content_sales_map(
+ if (class_exists('\AKSRT\Payment\OrderRepository')) {
+ $map = \AKSRT\Payment\OrderRepository::get_instance()->get_content_sales_map(
[$post_id],
- AKSRT_Domain_Model::ORDER_PRODUCT_RESOURCE
+ DomainModel::ORDER_PRODUCT_RESOURCE
);
if (isset($map[$post_id])) {
$db_sales = (int) ($map[$post_id]['sales_count'] ?? 0);
@@ -546,7 +538,7 @@ class AKSRT_Post_Meta_Box {
echo '
' . esc_html__('暂无订单', 'aksrt') . '';
}
echo '
' . esc_html__('付费文章', 'aksrt') . '';
- if ($pay_type === AKSRT_Domain_Model::PAY_TYPE_DOWNLOAD) {
+ if ($pay_type === DomainModel::PAY_TYPE_DOWNLOAD) {
$dl_url = admin_url('admin.php?page=aksrt_download_logs&post_id=' . $post_id);
echo ' · ' . esc_html__('下载记录', 'aksrt') . '';
}
@@ -557,11 +549,11 @@ class AKSRT_Post_Meta_Box {
* Dropdown filter for content pay_type on edit.php?post_type=post.
*/
public function render_pay_type_filter(string $post_type): void {
- if ($post_type !== 'post' || !class_exists('AKSRT_Domain_Model')) {
+ if ($post_type !== 'post' || !class_exists('DomainModel')) {
return;
}
$current = isset($_GET['aksrt_pay_type']) ? sanitize_key((string) wp_unslash($_GET['aksrt_pay_type'])) : '';
- $labels = AKSRT_Domain_Model::pay_type_labels();
+ $labels = DomainModel::pay_type_labels();
echo '
- comment_content, 15, '...')); ?> -
- - ID)); ?> - -