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

This commit is contained in:
kate522 committed 2026-08-23 14:55:24 +08:00
1 parent c3f66e9a14
commit bb9a410ad6
14 files changed
+569 -231

No files matched your search

+73 -7
View File
@@ -101,10 +101,7 @@ if (!function_exists('aksrt_get_user_home_page_context')) {
}
}
$active_tab = isset($_GET['tab']) ? sanitize_key(wp_unslash($_GET['tab'])) : $default_tab;
if (!in_array($active_tab, $enabled_tabs, true)) {
$active_tab = $default_tab;
}
$active_tab = $default_tab;
$home_url = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($user) : home_url('/');
@@ -131,9 +128,11 @@ if (!function_exists('aksrt_get_user_home_page_context')) {
'tab_counts' => $tab_counts,
'tab_labels' => $tab_labels,
'home_url' => $home_url,
'posts_page' => max(1, isset($_GET['posts_page']) ? (int) $_GET['posts_page'] : 1),
'comments_page' => max(1, isset($_GET['comments_page']) ? (int) $_GET['comments_page'] : 1),
'favorites_page' => max(1, isset($_GET['favorites_page']) ? (int) $_GET['favorites_page'] : 1),
'posts_page' => 1,
'comments_page' => 1,
'favorites_page' => 1,
'follow_sub' => 'followers',
'follow_page' => 1,
'svg_empty_post' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><path d="M14 2v6h6"/><path d="M9 13h6M9 17h6M9 9h1"/></svg>',
'svg_empty_comment' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>',
'svg_empty_favorite' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/></svg>',
@@ -141,3 +140,70 @@ if (!function_exists('aksrt_get_user_home_page_context')) {
];
}
}
if (!function_exists('aksrt_render_user_home_pagination')) {
/**
* 渲染公开用户主页面板的无刷新数字分页(按钮驱动,无 URL 参数)。
*
* 复用 .profile-pagination / .page-numbers 既有样式契约。
*
* @param int $total_pages 总页数。
* @param int $current 当前页。
*/
function aksrt_render_user_home_pagination(int $total_pages, int $current): void {
$total_pages = max(1, $total_pages);
$current = min(max(1, $current), $total_pages);
if ($total_pages <= 1) {
return;
}
$items = [];
for ($i = 1; $i <= $total_pages; $i++) {
if ($i === 1 || $i === $total_pages || abs($i - $current) <= 1) {
$items[] = (string) $i;
} elseif ($items && end($items) !== '…') {
$items[] = '…';
}
}
echo '<nav class="profile-pagination uh-pagination" aria-label="' . esc_attr__('分页', 'aksrt') . '">';
if ($current > 1) {
echo '<button type="button" class="page-numbers" data-uh-page="' . esc_attr((string) ($current - 1)) . '"><span aria-hidden="true">&lsaquo;</span><span class="screen-reader-text">' . esc_html__('上一页', 'aksrt') . '</span></button>';
}
foreach ($items as $item) {
if ($item === '…') {
echo '<span class="page-numbers dots">&hellip;</span>';
continue;
}
if ((int) $item === $current) {
echo '<span class="page-numbers current" aria-current="page">' . esc_html($item) . '</span>';
continue;
}
echo '<button type="button" class="page-numbers" data-uh-page="' . esc_attr($item) . '">' . esc_html($item) . '</button>';
}
if ($current < $total_pages) {
echo '<button type="button" class="page-numbers" data-uh-page="' . esc_attr((string) ($current + 1)) . '"><span aria-hidden="true">&rsaquo;</span><span class="screen-reader-text">' . esc_html__('下一页', 'aksrt') . '</span></button>';
}
echo '</nav>';
}
}
if (!function_exists('aksrt_capture_user_home_panel')) {
/**
* 捕获公开用户主页面板 body(templates/parts/user-home/panel-{tab}.php)。
*
* @param string $tab 面板键名。
* @param array<string, mixed> $ctx aksrt_get_user_home_page_context() 上下文。
* @return string 捕获的 HTML,模板不存在时为空串。
*/
function aksrt_capture_user_home_panel(string $tab, array $ctx): string {
$template = locate_template(['templates/parts/user-home/panel-' . sanitize_key($tab) . '.php'], false, false);
if (!$template) {
return '';
}
ob_start();
load_template($template, false, $ctx);
return (string) ob_get_clean();
}
}