进行了一些小优化
This commit is contained in:
@@ -20,6 +20,10 @@ final class UserRenderer {
|
||||
}
|
||||
|
||||
private static function user_card(array $i): string {
|
||||
if (class_exists('AKSRT\\Settings\\Settings') && \AKSRT\Settings\Settings::close_sign()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$user_id = get_current_user_id();
|
||||
if ($user_id <= 0) {
|
||||
return self::guest_card($i);
|
||||
@@ -29,11 +33,11 @@ final class UserRenderer {
|
||||
return '';
|
||||
}
|
||||
|
||||
return self::card_box($user_id, [
|
||||
return '<div class="mb20">' . self::card_box($user_id, [
|
||||
'show_posts' => false,
|
||||
'show_checkin' => true,
|
||||
'show_img_bg' => !isset($i['show_img_bg']) || !empty($i['show_img_bg']),
|
||||
] + self::card_button_args($i));
|
||||
] + self::card_button_args($i)) . '</div>';
|
||||
}
|
||||
|
||||
private static function author_card(array $i): string {
|
||||
@@ -47,13 +51,14 @@ final class UserRenderer {
|
||||
}
|
||||
$post_style = sanitize_key((string) ($i['post_style'] ?? 'mini'));
|
||||
|
||||
return self::card_box((int) $user->ID, [
|
||||
return '<div class="mb20">' . self::card_box((int) $user->ID, [
|
||||
'show_img_bg' => !isset($i['show_img_bg']) || !empty($i['show_img_bg']),
|
||||
'show_posts' => !isset($i['show_posts']) || !empty($i['show_posts']),
|
||||
'limit' => max(0, min(12, (int) ($i['limit'] ?? 6))),
|
||||
'orderby' => sanitize_key((string) ($i['orderby'] ?? 'date')),
|
||||
'post_type' => 'post',
|
||||
'post_style' => $post_style === 'card' ? 'card' : 'mini',
|
||||
] + self::card_button_args($i));
|
||||
] + self::card_button_args($i)) . '</div>';
|
||||
}
|
||||
|
||||
private static function card_button_args(array $i): array {
|
||||
@@ -77,37 +82,60 @@ final class UserRenderer {
|
||||
$title = __('Hi!请登录', 'aksrt');
|
||||
}
|
||||
|
||||
$cover = '';
|
||||
if (!isset($i['show_img_bg']) || !empty($i['show_img_bg'])) {
|
||||
$cover_url = aksrt_get_user_cover_url(0);
|
||||
$cover = '<div class="user-cover graphic" style="padding-bottom: 50%;"><img' . aksrt_get_lazy_attr('lazy_other', $cover_url, 'fit-cover user-cover', aksrt_get_lazy_thumb()) . ' alt="' . esc_attr__('用户封面', 'aksrt') . '"></div>';
|
||||
}
|
||||
|
||||
$avatar = '<span class="avatar-img avatar-lg">' . aksrt_get_avatar_html(0, 80, ['class' => 'fit-cover avatar']) . '</span>';
|
||||
$cover = !isset($i['show_img_bg']) || !empty($i['show_img_bg'])
|
||||
? self::cover(0, 'lazy_other')
|
||||
: '';
|
||||
$avatar = '<span class="avatar-img avatar-lg"><img alt="' . esc_attr__('默认头像', 'aksrt') . '" class="fit-cover avatar" src="' . esc_url(aksrt_get_default_avatar_url()) . '"></span>';
|
||||
|
||||
$buttons = '<a href="javascript:;" class="signin-loader but jb-blue padding-lg"><i class="fa fas fa-fw fa-sign-in" aria-hidden="true"></i>' . esc_html__('登录', 'aksrt') . '</a>';
|
||||
if (get_option('users_can_register')) {
|
||||
$registration_enabled = class_exists('AKSRT\\Settings\\Settings')
|
||||
? \AKSRT\Settings\Settings::registration_enabled()
|
||||
: (bool) get_option('users_can_register');
|
||||
if ($registration_enabled) {
|
||||
$buttons .= '<a href="javascript:;" class="signup-loader ml10 but jb-yellow padding-lg">' . aksrt_renderer_svg_icon('signup') . esc_html__('注册', 'aksrt') . '</a>';
|
||||
}
|
||||
|
||||
$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'));
|
||||
}
|
||||
}
|
||||
|
||||
return '<div class="user-card zib-widget">' . $cover
|
||||
return '<div class="mb20"><div class="user-card zib-widget widget">' . $cover
|
||||
. '<div class="card-content mt10">'
|
||||
. '<div class="user-content">'
|
||||
. '<div class="user-avatar">' . $avatar . '</div>'
|
||||
. '<div class="user-info mt10">'
|
||||
. '<div class="text-center box-body">'
|
||||
. '<div class="text-center">'
|
||||
. '<p class="muted-color box-body em12">' . esc_html($title) . '</p>'
|
||||
. '<p class="user-card__auth-btns">' . $buttons . '</p>'
|
||||
. $oauth_html
|
||||
. '</div></div></div></div></div>';
|
||||
. '<p>' . $buttons . '</p>'
|
||||
. self::social_login()
|
||||
. '</div></div></div></div></div></div>';
|
||||
}
|
||||
|
||||
private static function social_login(): string {
|
||||
if (!class_exists('AKSRT\\Auth\\OAuth')) {
|
||||
return '';
|
||||
}
|
||||
$items = \AKSRT\Auth\OAuth::get_instance()->get_auth_providers_data();
|
||||
if ($items === []) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$html = '<div class="social-separator separator muted-3-color em09 mt20 mb20">' . esc_html__('社交账号登录', 'aksrt') . '</div><div class="social_loginbar">';
|
||||
foreach ($items as $item) {
|
||||
$name = sanitize_html_class((string) ($item['name'] ?? ''));
|
||||
$style_name = str_starts_with($name, 'clogin_') ? substr($name, 7) : $name;
|
||||
$label = trim((string) ($item['label'] ?? ''));
|
||||
$url = (string) ($item['url'] ?? '');
|
||||
if ($name === '' || $style_name === '' || $label === '' || $url === '') {
|
||||
continue;
|
||||
}
|
||||
$html .= '<a rel="nofollow" href="' . esc_url($url) . '" class="social-login-item ' . esc_attr($style_name) . '" data-provider="' . esc_attr($name) . '" aria-label="' . esc_attr(sprintf(__('%s登录', 'aksrt'), $label)) . '" title="' . esc_attr($label) . '">' . (string) ($item['icon'] ?? '') . '</a>';
|
||||
}
|
||||
return $html . '</div>';
|
||||
}
|
||||
|
||||
private static function cover(int $user_id, string $lazy_type): string {
|
||||
$cover_url = aksrt_get_user_cover_url($user_id);
|
||||
if ($cover_url === '') {
|
||||
return '';
|
||||
}
|
||||
return '<div class="user-cover graphic" style="padding-bottom: 50%;"><img' . aksrt_get_lazy_attr($lazy_type, $cover_url, 'fit-cover', aksrt_get_lazy_thumb()) . ' alt="' . esc_attr__('用户封面', 'aksrt') . '"></div>';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,6 +158,7 @@ final class UserRenderer {
|
||||
'button_2_text' => __('用户中心', 'aksrt'),
|
||||
'limit' => 6,
|
||||
'orderby' => 'views',
|
||||
'post_type' => 'post',
|
||||
'post_style' => 'card',
|
||||
]);
|
||||
|
||||
@@ -158,7 +187,7 @@ final class UserRenderer {
|
||||
'user_id' => $user_id,
|
||||
'limit' => (int) $args['limit'],
|
||||
'orderby' => (string) $args['orderby'],
|
||||
'post_type' => 'post',
|
||||
'post_type' => (string) $args['post_type'],
|
||||
'post_style' => (string) $args['post_style'],
|
||||
]);
|
||||
}
|
||||
@@ -176,13 +205,9 @@ final class UserRenderer {
|
||||
$btns = $btns !== '' ? '<div class="user-btns mt20">' . $btns . '</div>' : '';
|
||||
}
|
||||
|
||||
$cover = '';
|
||||
if ($args['show_img_bg']) {
|
||||
$cover_url = aksrt_get_user_cover_url($user_id);
|
||||
$cover = '<div class="user-cover graphic" style="padding-bottom: 50%;"><img' . aksrt_get_lazy_attr('lazy_cover', $cover_url, 'fit-cover user-cover', aksrt_get_lazy_thumb()) . ' alt="' . esc_attr__('用户封面', 'aksrt') . '"></div>';
|
||||
}
|
||||
$cover = !empty($args['show_img_bg']) ? self::cover($user_id, 'lazy_cover') : '';
|
||||
|
||||
return '<div class="user-card zib-widget">' . $cover
|
||||
return '<div class="user-card zib-widget widget">' . $cover
|
||||
. '<div class="card-content mt10 relative">'
|
||||
. '<div class="user-content">' . $checkin
|
||||
. '<div class="user-avatar">' . $avatar . '</div>'
|
||||
|
||||
Reference in New Issue
Block a user