用户公开主页全局采用DOM无刷新加载

This commit is contained in:
2026-08-23 14:55:24 +08:00
parent c3f66e9a14
commit bb9a410ad6
14 changed files with 569 additions and 231 deletions
+9 -3
View File
@@ -48,7 +48,7 @@ require_once AKSRT_DIR . '/templates/parts/user-shared-helpers.php';
]);
?>
<div class="dashboard dashboard--public" data-default-tab="<?php echo esc_attr($default_tab); ?>">
<div class="dashboard dashboard--public" data-default-tab="<?php echo esc_attr($default_tab); ?>" data-user-id="<?php echo (int) $user_id; ?>">
<div class="dashboard-tabs" role="tablist">
<?php foreach ($enabled_tabs as $tab_key) :
$tab_class = $tab_key === $active_tab ? 'is-active' : '';
@@ -68,9 +68,15 @@ require_once AKSRT_DIR . '/templates/parts/user-shared-helpers.php';
</div>
<?php
get_template_part('templates/parts/user-home/panels', 'core', $ctx);
get_template_part('templates/parts/user-home/panel', 'follow', $ctx);
foreach ($enabled_tabs as $panel_tab) :
if (!locate_template(['templates/parts/user-home/panel-' . $panel_tab . '.php'], false, false)) {
continue;
}
?>
<div id="panel-<?php echo esc_attr($panel_tab); ?>" class="dashboard-panel<?php echo $panel_tab === $active_tab ? ' is-active' : ''; ?>" role="tabpanel"<?php echo $panel_tab !== $active_tab ? ' hidden' : ''; ?>>
<?php get_template_part('templates/parts/user-home/panel', $panel_tab, $ctx); ?>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
+2 -2
View File
@@ -103,8 +103,8 @@ $is_can_new = !empty($ctx['is_can_new']);
<?php endif; ?>
<?php elseif (!empty($ctx['draft_count']) && $ctx['user_id'] > 0) : ?>
<?php
$draft_url = function_exists('aksrt_get_user_home_url')
? add_query_arg(['tab' => 'post', 'post_status' => 'draft'], aksrt_get_user_home_url($ctx['user_id']))
$draft_url = function_exists('aksrt_get_user_center_url')
? add_query_arg('post_status', 'draft', aksrt_get_user_center_url('posts'))
: '';
?>
<?php if ($draft_url !== '') : ?>
@@ -0,0 +1,39 @@
<?php
/**
* Public user home — comments tab panel body.
*
* Rendered inside the #panel-comments wrapper on the public user home and via
* the aksrt/v1 user-home panel REST fragment. Pagination is button-driven
* (aksrt_render_user_home_pagination) and never touches the URL.
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
$args = is_array($args ?? null) ? $args : [];
extract($args, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
$user_comments = get_comments([
'user_id' => $user_id,
'status' => 'approve',
'number' => $per_page,
'offset' => ($comments_page - 1) * $per_page,
'type' => 'comment',
'update_comment_meta_cache' => false,
]);
if ($user_comments) :
?>
<div class="profile-comment-list">
<?php foreach ($user_comments as $c) : ?>
<?php
get_template_part('templates/parts/content', 'profile-comment-item', ['comment' => $c]);
?>
<?php endforeach; ?>
</div>
<?php
aksrt_render_user_home_pagination((int) ceil($comment_count / max(1, $per_page)), (int) $comments_page);
else :
aksrt_render_profile_empty($svg_empty_comment, __('TA 还没有发表评论', 'aksrt'));
endif;
@@ -0,0 +1,25 @@
<?php
/**
* Public user home — credits tab panel body (own profile only).
*
* Rendered inside the #panel-credits wrapper on the public user home. Static
* balance card; no pagination, no REST swapping needed.
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
$args = is_array($args ?? null) ? $args : [];
extract($args, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
if (empty($credits_enabled) || empty($is_own_profile)) {
return;
}
?>
<div class="user-home-balance-card">
<p class="user-home-balance-card__label"><?php echo esc_html(sprintf(__('当前%s余额', 'aksrt'), $currency_name)); ?></p>
<div class="user-home-balance-card__value"><?php echo esc_html(aksrt_format_credits($credit_balance)); ?></div>
<p class="user-home-balance-card__hint"><?php esc_html_e('完整账单和赚取/消费记录请在用户中心查看。', 'aksrt'); ?></p>
<a href="<?php echo esc_url(aksrt_get_user_center_url('credits')); ?>" class="btn-outline btn-sm"><?php esc_html_e('进入用户中心', 'aksrt'); ?></a>
</div>
@@ -0,0 +1,43 @@
<?php
/**
* Public user home — favorites tab panel body.
*
* Rendered inside the #panel-favorites wrapper on the public user home and via
* the aksrt/v1 user-home panel REST fragment. Pagination is button-driven
* (aksrt_render_user_home_pagination) and never touches the URL.
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
$args = is_array($args ?? null) ? $args : [];
extract($args, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
if (!empty($favorite_post_ids)) :
$user_home_render_config = aksrt_resolve_post_list_render_config([
'context' => 'author',
'overrides' => [
'type' => 'list',
'no_author' => true,
'no_margin' => true,
],
]);
$favorites_query = new WP_Query([
'post_type' => 'post',
'post_status' => 'publish',
'post__in' => $favorite_post_ids,
'orderby' => 'post__in',
'posts_per_page' => $per_page,
'paged' => $favorites_page,
'ignore_sticky_posts' => true,
'no_found_rows' => false,
'update_post_meta_cache' => false,
]);
aksrt_render_post_list(array_merge($user_home_render_config, ['wrapper_class' => 'aksrt-user-home__post-list']), $favorites_query);
aksrt_render_user_home_pagination((int) $favorites_query->max_num_pages, (int) $favorites_page);
wp_reset_postdata();
else :
aksrt_render_profile_empty($svg_empty_favorite, __('TA 还没有收藏文章', 'aksrt'));
endif;
+48 -65
View File
@@ -1,11 +1,15 @@
<?php
/**
* Public user home — follow tab panel (social following/followers).
* Public user home — follow tab panel body (social following/followers).
*
* Legacy parity: 粉丝/关注用户列表复刻 zib_get_follow_user_list + zib_author_card
* (inc/functions/zib-author.php:395-454, 685-716):子切换「粉丝 | 关注」居中文字链接,
* 列表项走 aksrt_author_minicard(.author-minicard 三列 inline-block 卡片流)。
*
* Rendered inside the #panel-follow wrapper on the public user home and via
* the aksrt/v1 user-home panel REST fragment. Sub-tabs and pagination are
* button-driven ([data-uh-sub] / [data-uh-page]) and never touch the URL.
*
* @package AKSRT
*/
@@ -14,69 +18,48 @@ defined('ABSPATH') || exit;
$args = is_array($args ?? null) ? $args : [];
extract($args, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
$follow_page = max(1, (int) ($follow_page ?? 1));
$follow_sub = in_array($follow_sub ?? 'followers', ['following', 'followers'], true) ? $follow_sub : 'followers';
$follow_instance = class_exists('\AKSRT\User\Follow') ? \AKSRT\User\Follow::get_instance() : null;
$following_count = $follow_instance ? (int) $follow_instance->get_following_count((int) $user_id) : 0;
$follower_count = $follow_instance ? (int) $follow_instance->get_follower_count((int) $user_id) : 0;
$list = ['items' => [], 'total' => 0, 'total_pages' => 1];
if ($follow_instance) {
$list = $follow_sub === 'followers'
? $follow_instance->get_followers((int) $user_id, $follow_page, (int) $per_page)
: $follow_instance->get_following((int) $user_id, $follow_page, (int) $per_page);
}
$items = is_array($list['items'] ?? null) ? $list['items'] : [];
$total_pages = max(1, (int) ($list['total_pages'] ?? 1));
?>
<?php if (in_array('follow', $enabled_tabs, true)) : ?>
<div id="panel-follow" class="dashboard-panel<?php echo $active_tab === 'follow' ? ' is-active' : ''; ?>" role="tabpanel"<?php echo $active_tab !== 'follow' ? ' hidden' : ''; ?>>
<?php
$follow_page = max(1, isset($_GET['follow_page']) ? (int) $_GET['follow_page'] : 1);
$follow_sub = isset($_GET['follow_sub']) ? sanitize_key(wp_unslash($_GET['follow_sub'])) : 'followers';
$follow_sub = in_array($follow_sub, ['following', 'followers'], true) ? $follow_sub : 'followers';
<ul class="uh-follow__subtabs list-inline splitters">
<li>
<button type="button" class="uh-follow__subtab<?php echo $follow_sub === 'followers' ? ' is-active focus-color' : ' muted-color'; ?>" data-uh-sub="followers">
<?php esc_html_e('粉丝', 'aksrt'); ?>
<span class="uh-follow__subtab-count"><?php echo esc_html((string) $follower_count); ?></span>
</button>
</li>
<li>
<button type="button" class="uh-follow__subtab<?php echo $follow_sub === 'following' ? ' is-active focus-color' : ' muted-color'; ?>" data-uh-sub="following">
<?php esc_html_e('关注', 'aksrt'); ?>
<span class="uh-follow__subtab-count"><?php echo esc_html((string) $following_count); ?></span>
</button>
</li>
</ul>
$follow_instance = class_exists('\AKSRT\User\Follow') ? \AKSRT\User\Follow::get_instance() : null;
$following_count = $follow_instance ? (int) $follow_instance->get_following_count((int) $user_id) : 0;
$follower_count = $follow_instance ? (int) $follow_instance->get_follower_count((int) $user_id) : 0;
$list = ['items' => [], 'total' => 0, 'total_pages' => 1];
if ($follow_instance) {
$list = $follow_sub === 'followers'
? $follow_instance->get_followers((int) $user_id, $follow_page, (int) $per_page)
: $follow_instance->get_following((int) $user_id, $follow_page, (int) $per_page);
}
$items = is_array($list['items'] ?? null) ? $list['items'] : [];
$total_pages = max(1, (int) ($list['total_pages'] ?? 1));
?>
<ul class="uh-follow__subtabs list-inline splitters">
<li>
<a class="uh-follow__subtab<?php echo $follow_sub === 'followers' ? ' is-active focus-color' : ' muted-color'; ?>"
href="<?php echo esc_url(add_query_arg(['tab' => 'follow', 'follow_sub' => 'followers', 'follow_page' => 1], $home_url)); ?>">
<?php esc_html_e('粉丝', 'aksrt'); ?>
<span class="uh-follow__subtab-count"><?php echo esc_html((string) $follower_count); ?></span>
</a>
</li>
<li>
<a class="uh-follow__subtab<?php echo $follow_sub === 'following' ? ' is-active focus-color' : ' muted-color'; ?>"
href="<?php echo esc_url(add_query_arg(['tab' => 'follow', 'follow_sub' => 'following', 'follow_page' => 1], $home_url)); ?>">
<?php esc_html_e('关注', 'aksrt'); ?>
<span class="uh-follow__subtab-count"><?php echo esc_html((string) $following_count); ?></span>
</a>
</li>
</ul>
<?php if (!empty($items)) : ?>
<div class="uh-follow__list">
<?php foreach ($items as $row) :
echo aksrt_author_minicard((int) ($row['user_id'] ?? 0)); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
endforeach; ?>
</div>
<?php if ($total_pages > 1) : ?>
<div class="uh-follow__pagination">
<?php
echo paginate_links([
'base' => add_query_arg(['tab' => 'follow', 'follow_sub' => $follow_sub, 'follow_page' => '%#%'], $home_url),
'format' => '',
'current' => $follow_page,
'total' => $total_pages,
'add_args' => ['tab' => 'follow', 'follow_sub' => $follow_sub],
]);
?>
</div>
<?php endif; ?>
<?php else : ?>
<?php
$empty_msg = $follow_sub === 'followers'
? __('暂无粉丝', 'aksrt')
: __('暂未关注任何人', 'aksrt');
aksrt_render_profile_empty($svg_empty_follow ?? $svg_empty_post ?? '', $empty_msg);
?>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if (!empty($items)) : ?>
<div class="uh-follow__list">
<?php foreach ($items as $row) :
echo aksrt_author_minicard((int) ($row['user_id'] ?? 0)); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
endforeach; ?>
</div>
<?php aksrt_render_user_home_pagination($total_pages, $follow_page); ?>
<?php else : ?>
<?php
$empty_msg = $follow_sub === 'followers'
? __('暂无粉丝', 'aksrt')
: __('暂未关注任何人', 'aksrt');
aksrt_render_profile_empty($svg_empty_follow ?? $svg_empty_post ?? '', $empty_msg);
?>
<?php endif; ?>
+35
View File
@@ -0,0 +1,35 @@
<?php
/**
* Public user home — posts tab panel body.
*
* Rendered inside the #panel-posts wrapper on the public user home and via
* the aksrt/v1 user-home panel REST fragment. Pagination is button-driven
* (aksrt_render_user_home_pagination) and never touches the URL.
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
$args = is_array($args ?? null) ? $args : [];
extract($args, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
$user_home_render_config = aksrt_resolve_post_list_render_config([
'context' => 'author',
'overrides' => [
'type' => 'list',
'no_author' => true,
'no_margin' => true,
],
]);
$author_posts = new WP_Query([
'author' => $user_id,
'posts_per_page' => $per_page,
'post_status' => 'publish',
'paged' => $posts_page,
'no_found_rows' => false,
]);
aksrt_render_post_list(array_merge($user_home_render_config, ['wrapper_class' => 'aksrt-user-home__post-list']), $author_posts);
aksrt_render_user_home_pagination((int) $author_posts->max_num_pages, (int) $posts_page);
wp_reset_postdata();
-118
View File
@@ -1,118 +0,0 @@
<?php
/**
* Public user home — core content panels (posts/comments/favorites/credits/placeholders).
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
$args = is_array($args ?? null) ? $args : [];
extract($args, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
?>
<?php if (in_array('posts', $enabled_tabs, true) || in_array('favorites', $enabled_tabs, true)) : ?>
<?php
$user_home_render_config = aksrt_resolve_post_list_render_config([
'context' => 'author',
'overrides' => [
'type' => 'list',
'no_author' => true,
'no_margin' => true,
],
]);
?>
<?php endif; ?>
<?php if (in_array('posts', $enabled_tabs, true)) : ?>
<div id="panel-posts" class="dashboard-panel<?php echo $active_tab === 'posts' ? ' is-active' : ''; ?>" role="tabpanel"<?php echo $active_tab !== 'posts' ? ' hidden' : ''; ?>>
<?php
$author_posts = new WP_Query([
'author' => $user_id,
'posts_per_page' => $per_page,
'post_status' => 'publish',
'paged' => $posts_page,
'no_found_rows' => false,
]);
aksrt_render_post_list(array_merge($user_home_render_config, ['wrapper_class' => 'aksrt-user-home__post-list']), $author_posts);
aksrt_render_pagination($author_posts, [
'query_context' => 'author',
'render_config' => $user_home_render_config,
'page_var' => 'posts_page',
'current_page' => $posts_page,
]);
wp_reset_postdata();
?>
</div>
<?php endif; ?>
<?php if (in_array('comments', $enabled_tabs, true)) : ?>
<div id="panel-comments" class="dashboard-panel<?php echo $active_tab === 'comments' ? ' is-active' : ''; ?>" role="tabpanel"<?php echo $active_tab !== 'comments' ? ' hidden' : ''; ?>>
<?php
$user_comments = get_comments([
'user_id' => $user_id,
'status' => 'approve',
'number' => $per_page,
'offset' => ($comments_page - 1) * $per_page,
'type' => 'comment',
'update_comment_meta_cache' => false,
]);
if ($user_comments) :
?>
<div class="profile-comment-list">
<?php foreach ($user_comments as $c) : ?>
<?php
get_template_part('templates/parts/content', 'profile-comment-item', ['comment' => $c]);
?>
<?php endforeach; ?>
</div>
<?php
$cm_total_pages = (int) ceil($comment_count / $per_page);
aksrt_render_profile_pagination($cm_total_pages, $comments_page, 'comments_page');
else :
aksrt_render_profile_empty($svg_empty_comment, __('TA 还没有发表评论', 'aksrt'));
endif;
?>
</div>
<?php endif; ?>
<?php if (in_array('favorites', $enabled_tabs, true)) : ?>
<div id="panel-favorites" class="dashboard-panel<?php echo $active_tab === 'favorites' ? ' is-active' : ''; ?>" role="tabpanel"<?php echo $active_tab !== 'favorites' ? ' hidden' : ''; ?>>
<?php if (!empty($favorite_post_ids)) : ?>
<?php
$favorites_query = new WP_Query([
'post_type' => 'post',
'post_status' => 'publish',
'post__in' => $favorite_post_ids,
'orderby' => 'post__in',
'posts_per_page' => $per_page,
'paged' => $favorites_page,
'ignore_sticky_posts' => true,
'no_found_rows' => false,
'update_post_meta_cache' => false,
]);
aksrt_render_post_list(array_merge($user_home_render_config, ['wrapper_class' => 'aksrt-user-home__post-list']), $favorites_query);
aksrt_render_pagination($favorites_query, [
'query_context' => 'author',
'render_config' => $user_home_render_config,
'page_var' => 'favorites_page',
'current_page' => $favorites_page,
]);
wp_reset_postdata();
?>
<?php else : ?>
<?php aksrt_render_profile_empty($svg_empty_favorite, __('TA 还没有收藏文章', 'aksrt')); ?>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if (in_array('credits', $enabled_tabs, true) && $credits_enabled && $is_own_profile) : ?>
<div id="panel-credits" class="dashboard-panel<?php echo $active_tab === 'credits' ? ' is-active' : ''; ?>" role="tabpanel"<?php echo $active_tab !== 'credits' ? ' hidden' : ''; ?>>
<div class="user-home-balance-card">
<p class="user-home-balance-card__label"><?php echo esc_html(sprintf(__('当前%s余额', 'aksrt'), $currency_name)); ?></p>
<div class="user-home-balance-card__value"><?php echo esc_html(aksrt_format_credits($credit_balance)); ?></div>
<p class="user-home-balance-card__hint"><?php esc_html_e('完整账单和赚取/消费记录请在用户中心查看。', 'aksrt'); ?></p>
<a href="<?php echo esc_url(aksrt_get_user_center_url('credits')); ?>" class="btn-outline btn-sm"><?php esc_html_e('进入用户中心', 'aksrt'); ?></a>
</div>
</div>
<?php endif; ?>