Move 288 types from global AKSRT_* + inc/classes manual requires into
namespace AKSRT\{Domain} under src/AKSRT/, wire composer.json psr-4,
and slim bootstrap to helpers/modules/hooks only. Split multi-class
widget/gateway files, update admin contract audit paths, and document
the layout in ADR/README.
222 lines
9.4 KiB
PHP
222 lines
9.4 KiB
PHP
<?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)) : ?>
|
|
<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,
|
|
'update_post_meta_cache' => false,
|
|
]);
|
|
if ($author_posts->have_posts()) :
|
|
?>
|
|
<div class="profile-list">
|
|
<?php while ($author_posts->have_posts()) : $author_posts->the_post(); ?>
|
|
<?php
|
|
get_template_part('templates/parts/content', 'profile-list-item', [
|
|
'action' => [
|
|
'type' => 'view',
|
|
'url' => get_permalink(),
|
|
'label' => __('阅读', 'aksrt'),
|
|
],
|
|
]);
|
|
?>
|
|
<?php endwhile; ?>
|
|
</div>
|
|
<?php
|
|
aksrt_render_profile_pagination((int) $author_posts->max_num_pages, $posts_page, 'posts_page');
|
|
wp_reset_postdata();
|
|
else :
|
|
aksrt_render_profile_empty($svg_empty_post, __('TA 还没有发布文章', 'aksrt'));
|
|
endif;
|
|
?>
|
|
</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,
|
|
]);
|
|
if ($favorites_query->have_posts()) :
|
|
?>
|
|
<div class="profile-list">
|
|
<?php while ($favorites_query->have_posts()) : $favorites_query->the_post(); ?>
|
|
<?php
|
|
get_template_part('templates/parts/content', 'profile-list-item', [
|
|
'action' => [
|
|
'type' => 'view',
|
|
'url' => get_permalink(),
|
|
'label' => __('阅读', 'aksrt'),
|
|
],
|
|
]);
|
|
?>
|
|
<?php endwhile; ?>
|
|
</div>
|
|
<?php
|
|
aksrt_render_profile_pagination((int) $favorites_query->max_num_pages, $favorites_page, 'favorites_page');
|
|
wp_reset_postdata();
|
|
else :
|
|
aksrt_render_profile_empty($svg_empty_favorite, __('TA 还没有收藏文章', 'aksrt'));
|
|
endif;
|
|
?>
|
|
<?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; ?>
|
|
|
|
<?php if (in_array('product', $enabled_tabs, true)) : ?>
|
|
<div id="panel-product" class="dashboard-panel<?php echo $active_tab === 'product' ? ' is-active' : ''; ?>" role="tabpanel"<?php echo $active_tab !== 'product' ? ' hidden' : ''; ?>>
|
|
<?php
|
|
$product_page = max(1, isset($_GET['product_page']) ? (int) $_GET['product_page'] : 1);
|
|
$product_view = ['items' => [], 'total' => 0, 'max_pages' => 0];
|
|
if (class_exists('\AKSRT\Shop\Shop')) {
|
|
$product_view = \AKSRT\Shop\Shop::get_instance()->get_store_products((int) $user_id, $product_page, (int) $per_page);
|
|
}
|
|
$product_items = is_array($product_view['items'] ?? null) ? $product_view['items'] : [];
|
|
$product_max_pages = (int) ($product_view['max_pages'] ?? 0);
|
|
if (!empty($product_items)) :
|
|
?>
|
|
<div class="aksrt-product-archive__grid aksrt-product-archive__grid--default uh-product-grid">
|
|
<?php foreach ($product_items as $product) :
|
|
get_template_part('templates/parts/shop/product', 'card', [
|
|
'product' => $product,
|
|
'show_sales' => ((int) ($product['sales'] ?? 0) > 0),
|
|
]);
|
|
endforeach; ?>
|
|
</div>
|
|
<?php if ($product_max_pages > 1 && function_exists('aksrt_render_profile_pagination')) : ?>
|
|
<?php aksrt_render_profile_pagination($product_max_pages, $product_page, 'product_page'); ?>
|
|
<?php elseif ($product_max_pages > 1) : ?>
|
|
<?php
|
|
echo paginate_links([
|
|
'base' => add_query_arg(['tab' => 'product', 'product_page' => '%#%'], $home_url),
|
|
'format' => '',
|
|
'current' => $product_page,
|
|
'total' => $product_max_pages,
|
|
'add_args' => ['tab' => 'product'],
|
|
]);
|
|
?>
|
|
<?php endif; ?>
|
|
<?php else : ?>
|
|
<?php aksrt_render_profile_empty($svg_empty_post, __('暂无商品内容', 'aksrt')); ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (in_array('plate', $enabled_tabs, true)) : ?>
|
|
<div id="panel-plate" class="dashboard-panel<?php echo $active_tab === 'plate' ? ' is-active' : ''; ?>" role="tabpanel"<?php echo $active_tab !== 'plate' ? ' hidden' : ''; ?>>
|
|
<?php
|
|
$plate_items = [];
|
|
if ($forum_instance) {
|
|
if (method_exists($forum_instance, 'get_user_followed_plates')) {
|
|
$plate_items = array_merge($plate_items, (array) $forum_instance->get_user_followed_plates((int) $user_id));
|
|
}
|
|
if (method_exists($forum_instance, 'get_user_managed_plates')) {
|
|
$managed = (array) $forum_instance->get_user_managed_plates((int) $user_id);
|
|
foreach (['owned', 'moderating'] as $bucket) {
|
|
foreach ((array) ($managed[$bucket] ?? []) as $plate) {
|
|
$plate_items[] = $plate;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// de-dupe by id
|
|
$seen = [];
|
|
$unique_plates = [];
|
|
foreach ($plate_items as $plate) {
|
|
$pid = (int) ($plate['id'] ?? 0);
|
|
if ($pid <= 0 || isset($seen[$pid])) {
|
|
continue;
|
|
}
|
|
$seen[$pid] = true;
|
|
$unique_plates[] = $plate;
|
|
}
|
|
if (!empty($unique_plates)) :
|
|
?>
|
|
<div class="uh-forum__plate-grid">
|
|
<?php foreach ($unique_plates as $plate) :
|
|
$purl = !empty($plate['url']) ? (string) $plate['url'] : get_permalink((int) ($plate['id'] ?? 0));
|
|
?>
|
|
<a class="uh-forum__plate-card" href="<?php echo esc_url((string) $purl); ?>">
|
|
<div class="uh-forum__plate-name"><?php echo esc_html((string) ($plate['name'] ?? '')); ?></div>
|
|
<div class="uh-forum__plate-stats">
|
|
<span><?php printf(esc_html__('%d 帖子', 'aksrt'), (int) ($plate['topic_count'] ?? $plate['post_count'] ?? 0)); ?></span>
|
|
<span><?php printf(esc_html__('%d 关注', 'aksrt'), (int) ($plate['follow_count'] ?? 0)); ?></span>
|
|
</div>
|
|
</a>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php else :
|
|
aksrt_render_profile_empty($svg_empty_post, __('暂无圈子内容', 'aksrt'));
|
|
endif;
|
|
?>
|
|
</div>
|
|
<?php endif; ?>
|