65 lines
4.1 KiB
PHP
65 lines
4.1 KiB
PHP
<?php
|
|
/**
|
|
* Private follow management panel.
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
$context = is_array($args['context'] ?? null) ? $args['context'] : [];
|
|
extract($context, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
|
|
|
|
$follow = class_exists('\\AKSRT\\User\\Follow') ? \AKSRT\User\Follow::get_instance() : null;
|
|
$active_list = isset($_GET['follow_list']) ? sanitize_key(wp_unslash($_GET['follow_list'])) : 'followers';
|
|
if (!in_array($active_list, ['followers', 'following'], true)) {
|
|
$active_list = 'followers';
|
|
}
|
|
$page = max(1, isset($_GET['follow_page']) ? (int) $_GET['follow_page'] : 1);
|
|
$result = $follow
|
|
? ($active_list === 'following' ? $follow->get_following((int) $user_id, $page, 20) : $follow->get_followers((int) $user_id, $page, 20))
|
|
: ['items' => [], 'total_pages' => 1];
|
|
?>
|
|
<div class="widget-card uc-follow-management">
|
|
<div class="profile-list-header">
|
|
<div>
|
|
<h2 class="widget-title widget-title--inline"><?php esc_html_e('粉丝与关注', 'aksrt'); ?></h2>
|
|
<p class="muted-2-color em09"><?php esc_html_e('查看谁关注了你,并管理你关注的作者。', 'aksrt'); ?></p>
|
|
</div>
|
|
</div>
|
|
<div class="profile-status-filter" role="tablist" aria-label="<?php esc_attr_e('关注关系筛选', 'aksrt'); ?>">
|
|
<?php foreach (['followers' => __('粉丝', 'aksrt'), 'following' => __('我关注的', 'aksrt')] as $key => $label) :
|
|
$url = add_query_arg(['follow_list' => $key, 'follow_page' => 1], aksrt_get_user_center_tab_url('follow'));
|
|
?>
|
|
<a class="profile-status-chip<?php echo $active_list === $key ? ' is-active' : ''; ?>" href="<?php echo esc_url($url); ?>" data-tab="follow" role="tab" aria-selected="<?php echo $active_list === $key ? 'true' : 'false'; ?>">
|
|
<?php echo esc_html($label); ?> <span class="profile-status-chip__count"><?php echo esc_html(number_format_i18n((int) ($key === 'followers' ? $follower_count : $following_count))); ?></span>
|
|
</a>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php if (!empty($result['items'])) : ?>
|
|
<div class="uc-follow-management__list">
|
|
<?php foreach ($result['items'] as $item) :
|
|
$member_id = (int) ($item['user_id'] ?? 0);
|
|
$home_url = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($member_id) : '';
|
|
?>
|
|
<div class="uc-follow-management__item" data-follow-user="<?php echo esc_attr((string) $member_id); ?>">
|
|
<a href="<?php echo esc_url($home_url); ?>" class="uc-follow-management__avatar"><?php echo get_avatar($member_id, 48, '', (string) ($item['display_name'] ?? '')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></a>
|
|
<div class="uc-follow-management__identity"><a href="<?php echo esc_url($home_url); ?>"><?php echo esc_html((string) ($item['display_name'] ?? '')); ?></a><span><?php echo esc_html(sprintf(__('关注于 %s', 'aksrt'), get_date_from_gmt((string) ($item['created_at'] ?? ''), get_option('date_format')))); ?></span></div>
|
|
<div class="uc-follow-management__actions">
|
|
<a class="btn-ghost btn-sm" href="<?php echo esc_url($home_url); ?>"><?php esc_html_e('主页', 'aksrt'); ?></a>
|
|
<?php if ($active_list === 'following') : ?><button type="button" class="btn-outline btn-sm is-following" data-aksrt-follow="<?php echo esc_attr((string) $member_id); ?>"><i class="fa fas fa-heart" aria-hidden="true"></i><span data-aksrt-follow-label><?php esc_html_e('已关注', 'aksrt'); ?></span></button><?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php aksrt_render_profile_pagination(
|
|
(int) ($result['total_pages'] ?? 1),
|
|
$page,
|
|
'follow_page',
|
|
add_query_arg('follow_list', $active_list, aksrt_get_user_center_tab_url('follow'))
|
|
); ?>
|
|
<?php else : ?>
|
|
<?php aksrt_render_profile_empty('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M22 21v-2a4 4 0 0 0-3-3.87M16 3.13a4 4 0 0 1 0 7.75"/></svg>', $active_list === 'followers' ? __('还没有粉丝', 'aksrt') : __('还没有关注任何作者', 'aksrt')); ?>
|
|
<?php endif; ?>
|
|
</div>
|