fix(users): keep center navigation local and restore public home
This commit is contained in:
@@ -28,7 +28,7 @@
|
||||
if (!tabContainer) return;
|
||||
|
||||
var tabs = tabContainer.querySelectorAll('[data-tab]');
|
||||
var sidebarBtns = document.querySelectorAll('.uc-sidebar__btn[data-tab], .uc-service-grid__item[data-tab]');
|
||||
var sidebarBtns = document.querySelectorAll('.uc-sidebar [data-tab]');
|
||||
var panels = {};
|
||||
var defaultTab = cfg.defaultTab || 'profile';
|
||||
var drawerTrigger = document.getElementById('uc-drawer-trigger');
|
||||
@@ -82,9 +82,12 @@
|
||||
}
|
||||
target.classList.add('is-loading');
|
||||
var url = restUrl.replace(/\/$/, '') + '/user-center/panel/' + encodeURIComponent(name);
|
||||
if (name === 'creator') {
|
||||
if (name === 'creator' || name === 'revenue') {
|
||||
var params = queryParams || new URLSearchParams(window.location.search);
|
||||
['income_page'].forEach(function(key) {
|
||||
var allowedParams = name === 'creator'
|
||||
? ['income_page']
|
||||
: ['reward_tab', 'commission_page', 'invite_page'];
|
||||
allowedParams.forEach(function(key) {
|
||||
if (params.get(key)) url += (url.indexOf('?') === -1 ? '?' : '&') + key + '=' + encodeURIComponent(params.get(key));
|
||||
});
|
||||
}
|
||||
@@ -131,24 +134,34 @@
|
||||
return tabAliases[name] || name;
|
||||
}
|
||||
|
||||
function updateUrl(name) {
|
||||
function updateUrl(name, sourceUrl) {
|
||||
if (!window.history.replaceState) return;
|
||||
var pathTab = name === 'credits' ? 'balance' : name;
|
||||
var u = new URL('/user/' + pathTab + '/', window.location.origin);
|
||||
window.history.replaceState({}, '', u);
|
||||
if (sourceUrl) {
|
||||
var source = new URL(sourceUrl, window.location.href);
|
||||
source.searchParams.forEach(function(value, key) { u.searchParams.set(key, value); });
|
||||
}
|
||||
window.history.pushState({}, '', u);
|
||||
}
|
||||
|
||||
tabs.forEach(function(tab) {
|
||||
tab.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
activate(this.getAttribute('data-tab'), true);
|
||||
});
|
||||
});
|
||||
sidebarBtns.forEach(function(btn) {
|
||||
btn.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
activate(this.getAttribute('data-tab'), true);
|
||||
});
|
||||
// Delegate every internal user-center link. This also covers markup injected
|
||||
// after a REST panel refresh, so panel navigation never falls back to a full load.
|
||||
document.addEventListener('click', function(e) {
|
||||
var link = e.target && e.target.closest ? e.target.closest('a[href]') : null;
|
||||
if (!link || e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || link.target === '_blank') return;
|
||||
var url;
|
||||
try { url = new URL(link.href, window.location.href); } catch (_) { return; }
|
||||
if (url.origin !== window.location.origin) return;
|
||||
var parts = url.pathname.replace(/\/+$/, '').split('/');
|
||||
var pathTab = parts.length > 2 && parts[parts.length - 2] === 'user' ? parts[parts.length - 1] : '';
|
||||
var name = link.getAttribute('data-tab') || pathTab;
|
||||
if (name === 'balance') name = 'credits';
|
||||
name = tabAliases[name] || name;
|
||||
if (!name || !panels[name]) return;
|
||||
e.preventDefault();
|
||||
var hasQuery = url.search !== '';
|
||||
activate(name, false, hasQuery, url.searchParams).then(function() { updateUrl(name, url.href); });
|
||||
});
|
||||
var creatorPanel = panels.creator ? panels.creator.panel : null;
|
||||
if (creatorPanel) {
|
||||
@@ -166,7 +179,9 @@
|
||||
});
|
||||
});
|
||||
}
|
||||
window.addEventListener('popstate', function() { activate(tabFromUrl(), false, true); });
|
||||
window.addEventListener('popstate', function() {
|
||||
activate(tabFromUrl(), false, window.location.search !== '', new URLSearchParams(window.location.search));
|
||||
});
|
||||
if (drawerTrigger) drawerTrigger.addEventListener('click', openDrawer);
|
||||
if (drawerOverlay) drawerOverlay.addEventListener('click', closeDrawer);
|
||||
activate(tabFromUrl(), false);
|
||||
|
||||
@@ -19,7 +19,7 @@ $points = (float) ($credit_balance ?? 0);
|
||||
?>
|
||||
<div class="uc-sidebar__pair uc-sidebar__pair--assets">
|
||||
<?php if ($show_wallet) : ?>
|
||||
<a class="uc-summary-card uc-summary-card--wallet" href="<?php echo esc_url($assets_url); ?>">
|
||||
<a class="uc-summary-card uc-summary-card--wallet" href="<?php echo esc_url($assets_url); ?>" data-tab="credits">
|
||||
<span class="uc-summary-card__head"><?php esc_html_e('账户余额', 'aksrt'); ?><i class="fas fa-angle-right" aria-hidden="true"></i></span>
|
||||
<span class="uc-summary-card__body">
|
||||
<strong><?php echo esc_html(class_exists('\AKSRT\Credits\Balance') ? \AKSRT\Credits\Balance::format($wallet) : number_format_i18n($wallet, 2)); ?></strong>
|
||||
@@ -28,7 +28,7 @@ $points = (float) ($credit_balance ?? 0);
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php if ($show_credits) : ?>
|
||||
<a class="uc-summary-card uc-summary-card--points" href="<?php echo esc_url(add_query_arg('asset_tab', 'points', $assets_url)); ?>">
|
||||
<a class="uc-summary-card uc-summary-card--points" href="<?php echo esc_url(add_query_arg('asset_tab', 'points', $assets_url)); ?>" data-tab="credits">
|
||||
<span class="uc-summary-card__head"><?php echo esc_html((string) ($currency_name ?? __('积分', 'aksrt'))); ?><i class="fas fa-angle-right" aria-hidden="true"></i></span>
|
||||
<span class="uc-summary-card__body">
|
||||
<strong><?php echo esc_html(function_exists('aksrt_format_credits') ? aksrt_format_credits((int) $points) : number_format_i18n((int) $points)); ?></strong>
|
||||
|
||||
@@ -16,14 +16,14 @@ if ($creation_url === '' && $revenue_url === '') {
|
||||
?>
|
||||
<div class="uc-sidebar__pair uc-sidebar__pair--centers">
|
||||
<?php if ($creation_url !== '') : ?>
|
||||
<a class="uc-center-card uc-center-card--creation" href="<?php echo esc_url($creation_url); ?>">
|
||||
<a class="uc-center-card uc-center-card--creation" href="<?php echo esc_url($creation_url); ?>" data-tab="creator">
|
||||
<span class="uc-center-card__icon"><i class="fas fa-feather-alt" aria-hidden="true"></i></span>
|
||||
<span><strong><?php esc_html_e('创作收益', 'aksrt'); ?></strong><small><?php esc_html_e('作者收益明细', 'aksrt'); ?></small></span>
|
||||
<i class="fas fa-angle-right" aria-hidden="true"></i>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php if ($revenue_url !== '') : ?>
|
||||
<a class="uc-center-card uc-center-card--revenue" href="<?php echo esc_url($revenue_url); ?>">
|
||||
<a class="uc-center-card uc-center-card--revenue" href="<?php echo esc_url($revenue_url); ?>" data-tab="revenue">
|
||||
<span class="uc-center-card__icon"><i class="fas fa-chart-line" aria-hidden="true"></i></span>
|
||||
<span><strong><?php esc_html_e('推广收益', 'aksrt'); ?></strong><small><?php esc_html_e('返佣与收益提现', 'aksrt'); ?></small></span>
|
||||
<i class="fas fa-angle-right" aria-hidden="true"></i>
|
||||
|
||||
@@ -13,16 +13,19 @@ $stats = [
|
||||
'label' => __('文章', 'aksrt'),
|
||||
'value' => (int) ($post_count ?? 0),
|
||||
'url' => isset($dashboard_tabs['posts']) ? aksrt_get_user_center_tab_url('posts') : $public_home_url,
|
||||
'tab' => isset($dashboard_tabs['posts']) ? 'posts' : '',
|
||||
],
|
||||
[
|
||||
'label' => __('评论', 'aksrt'),
|
||||
'value' => (int) ($comment_count ?? 0),
|
||||
'url' => isset($dashboard_tabs['comments']) ? aksrt_get_user_center_tab_url('comments') : $public_home_url,
|
||||
'tab' => isset($dashboard_tabs['comments']) ? 'comments' : '',
|
||||
],
|
||||
[
|
||||
'label' => __('收藏', 'aksrt'),
|
||||
'value' => (int) ($favorite_count ?? 0),
|
||||
'url' => isset($dashboard_tabs['favorites']) ? aksrt_get_user_center_tab_url('favorites') : $public_home_url,
|
||||
'tab' => isset($dashboard_tabs['favorites']) ? 'favorites' : '',
|
||||
],
|
||||
[
|
||||
'label' => __('粉丝', 'aksrt'),
|
||||
@@ -34,7 +37,7 @@ $stats = [
|
||||
<div class="uc-sidebar__section uc-sidebar__section--stats" aria-label="<?php esc_attr_e('账号统计', 'aksrt'); ?>">
|
||||
<div class="uc-stats">
|
||||
<?php foreach ($stats as $stat) : ?>
|
||||
<a class="uc-stats__item" href="<?php echo esc_url((string) $stat['url']); ?>">
|
||||
<a class="uc-stats__item" href="<?php echo esc_url((string) $stat['url']); ?>"<?php if (!empty($stat['tab'])) : ?> data-tab="<?php echo esc_attr((string) $stat['tab']); ?>"<?php endif; ?>>
|
||||
<span class="uc-stats__value"><?php echo esc_html(number_format_i18n((int) $stat['value'])); ?></span>
|
||||
<span class="uc-stats__label"><?php echo esc_html((string) $stat['label']); ?></span>
|
||||
</a>
|
||||
|
||||
@@ -51,7 +51,7 @@ $sidebar_icon = $sidebar_icon_url !== ''
|
||||
? '<img class="aksrt-vip-level-icon" src="' . $sidebar_icon_url . '" alt="" loading="lazy" decoding="async">'
|
||||
: '<i class="fas fa-crown" aria-hidden="true"></i>';
|
||||
?>
|
||||
<a class="uc-sidebar-vip" href="<?php echo esc_url($vip_url); ?>">
|
||||
<a class="uc-sidebar-vip" href="<?php echo esc_url($vip_url); ?>" data-tab="vip">
|
||||
<span class="uc-sidebar-vip__icon"><?php echo $sidebar_icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></span>
|
||||
<span class="uc-sidebar-vip__content">
|
||||
<strong><?php echo esc_html($title); ?></strong>
|
||||
|
||||
@@ -12,8 +12,10 @@ defined('ABSPATH') || exit;
|
||||
|
||||
get_header();
|
||||
|
||||
$target_user_nicename = get_query_var('user_nicename');
|
||||
$user = $target_user_nicename ? get_user_by('slug', $target_user_nicename) : null;
|
||||
$author_identifier = (string) get_query_var('aksrt_author_identifier');
|
||||
$user = $author_identifier !== '' && function_exists('aksrt_resolve_public_user')
|
||||
? aksrt_resolve_public_user($author_identifier)
|
||||
: null;
|
||||
|
||||
if (!$user instanceof WP_User) {
|
||||
wp_safe_redirect(home_url('/'));
|
||||
|
||||
Reference in New Issue
Block a user