'; } else { $card_classes .= ' no-cover'; } $buttons = '' . esc_html__('登录', 'aksrt') . ''; if (get_option('users_can_register')) { $buttons .= '' . esc_html__('注册', 'aksrt') . ''; } $oauth_html = ''; if (class_exists('AKSRT\\Auth\\OAuth')) { $oauth = \AKSRT\Auth\OAuth::get_instance(); if (is_callable([$oauth, 'render_social_buttons'])) { $oauth_html = (string) $oauth->render_social_buttons(__('社交账号登录', 'aksrt')); } } $avatar = '' . aksrt_get_avatar_html(0, 80, ['class' => 'avatar fit-cover']) . ''; return '
' . $cover . '
' . $avatar . '

' . esc_html($title) . '

' . '
' . $buttons . '
' . $oauth_html . '
'; } private static function author_card(array $i): string { $post = get_post(); if (!$post instanceof \WP_Post) { return ''; } $user = get_userdata((int) $post->post_author); return $user instanceof \WP_User ? self::profile_card($user, $i, false) : ''; } private static function profile_card(\WP_User $user, array $i, bool $self_card): string { $user_id = (int) $user->ID; $home = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($user) : get_author_posts_url($user_id); $cover = function_exists('aksrt_get_user_cover_url') ? aksrt_get_user_cover_url($user_id) : ''; $description = function_exists('aksrt_get_user_description') ? aksrt_get_user_description($user_id) : (string) $user->description; $followers = class_exists('AKSRT\\User\\Follow') ? \AKSRT\User\Follow::get_instance()->get_follower_count($user_id) : 0; $following = class_exists('AKSRT\\User\\Follow') ? \AKSRT\User\Follow::get_instance()->get_following_count($user_id) : 0; $html = '
'; if (!empty($i['show_cover'])) { $html .= '
'; } $html .= '
' . (function_exists('aksrt_get_avatar_html') ? aksrt_get_avatar_html($user_id, 96) : get_avatar($user_id, 96)) . '

' . esc_html($user->display_name) . '

'; if (function_exists('aksrt_render_user_identity_chips')) { $html .= '
' . aksrt_render_user_identity_chips($user_id, 'widget') . '
'; } $html .= '

' . esc_html(wp_trim_words($description, 24)) . '

' . number_format_i18n(count_user_posts($user_id, 'post', true)) . '' . esc_html__('文章', 'aksrt') . '' . number_format_i18n($followers) . '' . esc_html__('粉丝', 'aksrt') . '' . number_format_i18n($following) . '' . esc_html__('关注', 'aksrt') . '
'; if (!empty($i['show_buttons'])) { $html .= '
' . self::action((string) $i['primary_action'], $user, true) . self::action((string) $i['secondary_action'], $user, false) . '
'; } if (!$self_card && get_current_user_id() > 0 && get_current_user_id() !== $user_id) { $active = class_exists('AKSRT\\User\\Follow') && \AKSRT\User\Follow::get_instance()->is_following(get_current_user_id(), $user_id); $html .= ''; } $html .= '
'; if (!empty($i['show_posts']) && function_exists('aksrt_render_user_card_posts')) { $html .= '
' . aksrt_render_user_card_posts(['user_id' => $user_id, 'count' => 4, 'post_style' => 'mini', 'show_empty' => false]) . '
'; } return $html . '
'; } private static function action(string $action, \WP_User $user, bool $primary): string { $labels = ['home' => __('个人主页', 'aksrt'), 'submit' => __('发布文章', 'aksrt'), 'vip' => __('会员中心', 'aksrt'), 'orders' => __('订单中心', 'aksrt'), 'recharge' => __('余额充值', 'aksrt'), 'signin' => __('签到', 'aksrt')]; $variant = $primary ? ' is-primary' : ' is-secondary'; if ($action === 'signin' && function_exists('aksrt_header_user_checkin_btn') && get_current_user_id() === (int) $user->ID) { return '' . aksrt_header_user_checkin_btn((int) $user->ID, true) . ''; } if ($action === 'home') { $url = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($user) : get_author_posts_url((int) $user->ID); } elseif ($action === 'submit') { $url = function_exists('aksrt_get_new_post_url') ? aksrt_get_new_post_url() : home_url('/submit/'); } else { $tab = $action === 'signin' ? 'credits' : $action; $url = function_exists('aksrt_get_user_center_url') ? aksrt_get_user_center_url($tab) : home_url('/user/'); } if ($url === '') { return ''; } return '' . esc_html($labels[$action] ?? $labels['home']) . ''; } private static function ranking(array $i): string { $users = get_users(['number' => 200, 'orderby' => 'registered', 'order' => 'DESC']); $metric = (string) $i['orderby']; usort($users, static fn(\WP_User $a, \WP_User $b): int => self::metric($b, $metric) <=> self::metric($a, $metric)); $users = array_slice($users, 0, (int) $i['number']); if (!$users) { return RendererHelpers::empty_state(__('暂无用户数据', 'aksrt')); } $html = '
    '; foreach ($users as $index => $user) { $html .= '
  1. ' . ($index + 1) . '' . self::user_tile($user, self::metric($user, $metric), self::metric_label($metric)) . '
  2. '; } return $html . '
'; } private static function user_list(array $i): string { $args = ['number' => 200]; if (!empty($i['include'])) { $args['include'] = RendererHelpers::ids((string) $i['include']); } if (!empty($i['exclude'])) { $args['exclude'] = RendererHelpers::ids((string) $i['exclude']); } $users = get_users($args); $orderby = (string) $i['orderby']; usort($users, static function (\WP_User $a, \WP_User $b) use ($orderby): int { if ($orderby === 'display_name') { return strcasecmp($a->display_name, $b->display_name); } if ($orderby === 'registered') { return strcmp($b->user_registered, $a->user_registered); } return self::metric($b, $orderby) <=> self::metric($a, $orderby); }); $html = '
'; foreach (array_slice($users, 0, (int) $i['number']) as $user) { $html .= '
' . self::user_tile($user, self::metric($user, $orderby), self::metric_label($orderby)) . '
'; } return $html . '
'; } private static function user_tile(\WP_User $user, int $value, string $label): string { $url = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($user) : get_author_posts_url((int) $user->ID); return '' . (function_exists('aksrt_get_avatar_html') ? aksrt_get_avatar_html($user->ID, 64) : get_avatar($user->ID, 64)) . '' . esc_html($user->display_name) . '' . esc_html($label) . ' ' . number_format_i18n($value) . ''; } private static function metric(\WP_User $user, string $metric): int { $id = (int) $user->ID; if ($metric === 'points') { return aksrt_user_points($id); } if ($metric === 'followers') { return class_exists('AKSRT\\User\\Follow') ? (int) \AKSRT\User\Follow::get_instance()->get_follower_count($id) : 0; } if ($metric === 'post_count') { return (int) count_user_posts($id, 'post', true); } $key = $metric === 'checkin_continuous_day' ? 'aksrt_checkin_continuous_day' : 'aksrt_checkin_all_day'; return (int) get_user_meta($id, $key, true); } private static function metric_label(string $metric): string { $labels = ['points' => __('积分', 'aksrt'), 'followers' => __('粉丝', 'aksrt'), 'post_count' => __('文章', 'aksrt'), 'registered' => __('新加入', 'aksrt'), 'display_name' => __('用户', 'aksrt'), 'checkin_all_day' => __('累计签到', 'aksrt'), 'checkin_continuous_day' => __('连续签到', 'aksrt')]; return $labels[$metric] ?? $labels['points']; } }