Files
wordpress-theme-aksrt/templates/parts/user-home/panels-core.php
T

122 lines
5.1 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,
]);
$author_render_config = aksrt_resolve_post_list_render_config([
'context' => 'author',
]);
aksrt_render_post_list(array_merge($author_render_config, ['wrapper_class' => 'profile-list']), $author_posts);
aksrt_render_pagination($author_posts, [
'query_context' => 'author',
'render_config' => $author_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,
]);
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; ?>