Files
wordpress-theme-aksrt/inc/helpers/jio-user-dashboard.php
T
kate522andClaude Opus 5 35bb96e82f refactor: rename the theme brand and every identifier from AKSRT to Jio
Full-project rename. `git grep -i aksrt` is now empty apart from the
DBMigrator 3.3.0 changelog note that documents the rename itself.

Code identifiers
- PHP namespace AKSRT\ -> Jio\ (composer PSR-4 + 378 declarations)
- global constants AKSRT_* -> JIO_* (VERSION/DIR/URI, PAY_TYPE_*, CAPTCHA_*)
- procedural functions, hooks, options, meta keys, table names,
  cookies, query vars, ajax actions and nonces: aksrt_ -> jio_
- text domain aksrt -> jio; Theme Name -> Jio
- JS globals: aksrtData/aksrtAdminData/... -> jioData/jioAdminData/...,
  window.AKSRTCaptcha & friends -> window.JioCaptcha, Aksrt* -> Jio*
- Vue components Aks*.vue -> Jio*.vue (15 files renamed + imports)
- CSS classes/data-attrs/custom properties: aksrt- -> jio-
- REST namespace aksrt/v1 -> jio/v1 (incl. payment gateway callbacks)

Storage layer
- DB tables {prefix}aksrt_* -> {prefix}jio_*; SCHEMA_VERSION 3.2.0 -> 3.3.0
  so dbDelta creates the new names on install
- widget id_base aksrt_widget_* -> jio_widget_*
- uninstall.php drop list rebuilt from the actual migrator tables
  (dropped 3 stale entries, added the 17 missing ones)

Removed
- hardcoded https://api.aksrt.com/version.json default update endpoint;
  get_endpoint() now reads the 「更新端点」 setting and do_check() no-ops
  when it is empty

Files renamed: inc/helpers/aksrt-*.php -> jio-*.php (54),
assets/admin/src/components/form/Aks*.vue -> Jio*.vue (15).
Build artifacts regenerated: assets/css/build, assets/js/runtime,
assets/admin/build.

Verified: audit-psr4-paths errors=0, audit-admin-contracts errors=0
(warnings=56, unchanged baseline), 813/813 widget-system tests,
44/44 phpunit, php -l clean across all PHP.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-11-01 20:05:04 +08:00

124 lines
5.4 KiB
PHP

<?php
/**
* User Dashboard Data Helper
*
* Aggregates user data for author pages and public user homepages.
* Shared between author.php and page-user-home.php to avoid duplicate queries.
*
* @package Jio
*/
defined('ABSPATH') || exit;
/**
* Get aggregated dashboard view data for a user.
*
* @param int $user_id Target user ID.
* @param array $args Optional. Supported keys:
* - viewer_id: Current viewer ID.
* - include_recent_posts: Whether to query recent posts.
* - include_governance: Whether to resolve notice/report data.
* @return array {
* @type int $post_count Published post count.
* @type int $comment_count Approved comment count.
* @type int $favorite_count Favorited post count.
* @type array $favorite_post_ids Array of favorited post IDs.
* @type array $profile_details Server-filtered fixed public profile fields.
* @type array $profile_signals Identity chips (verified, level, badges).
* @type array $verify_state Verification tri-state {state,label} for the details dialog.
* @type string $background_url Cover image URL.
* @type float $credit_balance Credit balance (own profile only).
* @type string $currency_name Currency/credits display name.
* @type bool $credits_enabled Whether credits system is active.
* @type bool $is_own_profile Whether viewer is the user themselves.
* }
*/
function jio_get_user_dashboard_view(int $user_id, array $args = []): array {
$viewer_id = (int) ($args['viewer_id'] ?? get_current_user_id());
$include_recent_posts = !array_key_exists('include_recent_posts', $args) || (bool) $args['include_recent_posts'];
$include_governance = !array_key_exists('include_governance', $args) || (bool) $args['include_governance'];
$is_own_profile = is_user_logged_in() && $viewer_id === $user_id;
$post_count = (int) count_user_posts($user_id, 'post', true);
$comment_count = (int) get_comments([
'user_id' => $user_id,
'count' => true,
'status' => 'approve',
'type' => 'comment',
'post_type' => ['post'],
]);
$favorite_post_ids = function_exists('jio_get_user_interaction_posts')
? jio_get_user_interaction_posts('_jio_favorite_posts', $user_id)
: [];
$favorite_count = count($favorite_post_ids);
$recent_posts = $include_recent_posts
? get_posts([
'author' => $user_id,
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 5,
'orderby' => 'date',
'order' => 'DESC',
'no_found_rows' => true,
])
: [];
$profile_details = function_exists('jio_get_visible_user_profile_details')
? jio_get_visible_user_profile_details($user_id, $viewer_id)
: ['gender' => '', 'website' => '', 'qq' => '', 'wechat' => '', 'weibo' => '', 'github' => '', 'address' => ''];
$background_url = function_exists('jio_get_user_cover_url') ? jio_get_user_cover_url($user_id) : '';
$credits_enabled = class_exists('\Jio\Settings\Settings') && \Jio\Settings\Settings::credits_enabled();
$credit_balance = $credits_enabled && $is_own_profile
? (float) jio_user_points($user_id)
: 0.0;
$currency_name = $credits_enabled && class_exists('\Jio\Settings\Settings')
? \Jio\Settings\Settings::get_currency_name()
: __('积分', 'jio');
$recharge = class_exists('\Jio\Settings\Settings') ? \Jio\Settings\Settings::get_payment_recharge_settings() : [];
$balance_enabled = $is_own_profile && !empty($recharge['enabled']);
$wallet_balance = $balance_enabled ? jio_user_balance_decimal($user_id) : '0.00';
$user_home_manager = $include_governance && class_exists('\Jio\User\Home')
? \Jio\User\Home::get_instance()
: null;
$profile_signals = $user_home_manager ? $user_home_manager->get_profile_signals($user_id) : [];
$show_report = $user_home_manager ? $user_home_manager->show_report_entry() : false;
$verify_state = $user_home_manager ? $user_home_manager->get_verify_state($user_id) : ['state' => '', 'label' => ''];
return [
'post_count' => $post_count,
'comment_count' => $comment_count,
'favorite_count' => $favorite_count,
'favorite_post_ids'=> $favorite_post_ids,
'recent_posts' => $recent_posts,
'profile_details' => $profile_details,
'profile_signals' => $profile_signals,
'verify_state' => $verify_state,
'show_report' => $show_report,
'background_url' => $background_url,
'credit_balance' => $credit_balance,
'currency_name' => $currency_name,
'credits_enabled' => $credits_enabled,
'balance_enabled' => $balance_enabled,
'wallet_balance' => $wallet_balance,
'is_own_profile' => $is_own_profile,
];
}
add_action('wp_login', static function ($user_login, $user = null): void {
$user_id = 0;
if ($user instanceof WP_User) {
$user_id = (int) $user->ID;
} elseif (is_string($user_login) && $user_login !== '') {
$found = get_user_by('login', $user_login);
$user_id = $found instanceof WP_User ? (int) $found->ID : 0;
}
if ($user_id > 0) {
update_user_meta($user_id, 'jio_last_login', time());
}
}, 20, 2);