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.
326 lines
19 KiB
PHP
326 lines
19 KiB
PHP
<?php
|
|
/**
|
|
* Plate CPT single template (§7.2 板块独立页面).
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
get_header();
|
|
|
|
$forum = class_exists('\AKSRT\Forum\Forum') ? \AKSRT\Forum\Forum::get_instance() : null;
|
|
$current_user_id = get_current_user_id();
|
|
$plate_id = get_queried_object_id();
|
|
$paged = max(1, (int) get_query_var('paged', 1));
|
|
$forum_sort = isset($_GET['forum_sort']) ? sanitize_key(wp_unslash((string) $_GET['forum_sort'])) : '';
|
|
|
|
$view = $forum ? $forum->get_board_view($plate_id, [
|
|
'user_id' => $current_user_id,
|
|
'paged' => $paged,
|
|
'orderby' => $forum_sort,
|
|
]) : [
|
|
'board' => null,
|
|
'topics' => [],
|
|
'sticky_topics' => [],
|
|
'moderators' => [],
|
|
'pagination' => ['page' => 1, 'max_pages' => 1, 'total' => 0],
|
|
'permissions' => [],
|
|
'application' => null,
|
|
'board_options' => [],
|
|
'tabs' => [],
|
|
'active_sort' => 'date',
|
|
'top_info' => true,
|
|
'compose_url' => function_exists('aksrt_get_forum_compose_url') ? aksrt_get_forum_compose_url() : home_url('/'),
|
|
];
|
|
|
|
$board_data = $view['board'] ?? null;
|
|
$topics = $view['topics'] ?? [];
|
|
$sticky_topics = $view['sticky_topics'] ?? [];
|
|
$moderators = $view['moderators'] ?? [];
|
|
$permissions = $view['permissions'] ?? [];
|
|
$application = $view['application'] ?? null;
|
|
$tabs = is_array($view['tabs'] ?? null) ? $view['tabs'] : [];
|
|
$active_sort = sanitize_key((string) ($view['active_sort'] ?? 'date'));
|
|
$top_info = !isset($view['top_info']) || !empty($view['top_info']);
|
|
$compose_url = (string) ($view['compose_url'] ?? (function_exists('aksrt_get_forum_compose_url') ? aksrt_get_forum_compose_url(['board' => $plate_id]) : home_url('/')));
|
|
$plate_url = !empty($board_data['url']) ? (string) $board_data['url'] : (string) get_permalink($plate_id);
|
|
$nonce = wp_create_nonce('aksrt_public_nonce');
|
|
|
|
$forum_settings = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_forum_settings() : [];
|
|
$forum_names = $forum_settings['names'] ?? [];
|
|
$name_topic = $forum_names['posts'] ?? __('主题', 'aksrt');
|
|
$name_reply = $forum_names['comment'] ?? __('回复', 'aksrt');
|
|
$is_followed = $forum && $current_user_id > 0 ? $forum->is_user_following_plate($current_user_id, $plate_id) : false;
|
|
$max_pages = (int) ($view['pagination']['max_pages'] ?? 1);
|
|
?>
|
|
|
|
<main id="main-content" class="site-main content-shell content-shell--stream content-shell--forum" tabindex="-1">
|
|
<div class="content-wrap container">
|
|
<div class="content-layout content-layout--no-sidebar">
|
|
<div class="content-layout__primary">
|
|
|
|
<?php if (function_exists('aksrt_breadcrumbs')) { aksrt_breadcrumbs(); } ?>
|
|
|
|
<?php if (!empty($permissions['access_denied'])) : ?>
|
|
<div class="aksrt-forum-board">
|
|
<div class="aksrt-forum-board__access-denied">
|
|
<i class="fas fa-lock"></i>
|
|
<h2><?php esc_html_e('访问受限', 'aksrt'); ?></h2>
|
|
<p><?php
|
|
$reason = $permissions['access_reason'] ?? 'login';
|
|
if ($reason === 'login') {
|
|
esc_html_e('请登录后访问此版块。', 'aksrt');
|
|
} elseif ($reason === 'follow') {
|
|
esc_html_e('请先关注此版块后才能浏览内容。', 'aksrt');
|
|
} elseif ($reason === 'role') {
|
|
esc_html_e('你当前的角色无权访问此版块。', 'aksrt');
|
|
}
|
|
?></p>
|
|
</div>
|
|
</div>
|
|
<?php else : ?>
|
|
|
|
<div class="aksrt-forum-board container"
|
|
data-plate-id="<?php echo esc_attr((string) $plate_id); ?>"
|
|
data-nonce="<?php echo esc_attr($nonce); ?>"
|
|
data-active-sort="<?php echo esc_attr($active_sort); ?>">
|
|
|
|
<?php if ($top_info) : ?>
|
|
<div class="aksrt-forum-board__header">
|
|
<div class="aksrt-forum-board__info">
|
|
<?php if (!empty($board_data['cover_url'])) : ?>
|
|
<img class="aksrt-forum-board__cover" src="<?php echo esc_url((string) $board_data['cover_url']); ?>" alt="" loading="lazy">
|
|
<?php endif; ?>
|
|
<h1 class="aksrt-forum-board__title"><?php echo esc_html((string) ($board_data['name'] ?? '')); ?></h1>
|
|
<?php if (!empty($board_data['description'])) : ?>
|
|
<p class="aksrt-forum-board__desc"><?php echo esc_html((string) $board_data['description']); ?></p>
|
|
<?php endif; ?>
|
|
<div class="aksrt-forum-board__meta">
|
|
<span><i class="fas fa-list-alt"></i> <?php printf(esc_html__('%1$d 个%2$s', 'aksrt'), (int) ($board_data['post_count'] ?? $board_data['topic_count'] ?? 0), esc_html($name_topic)); ?></span>
|
|
<span><i class="fas fa-comments"></i> <?php printf(esc_html__('%d 条%s', 'aksrt'), (int) ($board_data['reply_count'] ?? 0), esc_html($name_reply)); ?></span>
|
|
<span><i class="fas fa-eye"></i> <?php printf(esc_html__('%d 浏览', 'aksrt'), (int) ($board_data['views'] ?? 0)); ?></span>
|
|
<span><i class="fas fa-heart"></i> <?php printf(esc_html__('%d 关注', 'aksrt'), (int) ($board_data['follow_count'] ?? 0)); ?></span>
|
|
<span><i class="fas fa-shield-alt"></i> <?php printf(esc_html__('%d 位版主', 'aksrt'), count($moderators)); ?></span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="aksrt-forum-board__actions">
|
|
<?php
|
|
$follow_pay_on = $forum && method_exists($forum, 'is_plate_follow_pay_enabled')
|
|
? $forum->is_plate_follow_pay_enabled($plate_id)
|
|
: ((int) get_post_meta($plate_id, '_aksrt_follow_pay', true) === 1);
|
|
$follow_pay_modo = sanitize_key((string) (get_post_meta($plate_id, '_aksrt_follow_pay_modo', true) ?: 'money'));
|
|
$allow_guest_plate = $current_user_id <= 0
|
|
&& $follow_pay_on
|
|
&& $follow_pay_modo === 'money'
|
|
&& function_exists('aksrt_allow_guest_forum_pay')
|
|
&& aksrt_allow_guest_forum_pay(get_post($plate_id));
|
|
$guest_followed = $current_user_id <= 0
|
|
&& function_exists('aksrt_guest_has_plate_follow_access')
|
|
&& aksrt_guest_has_plate_follow_access($plate_id);
|
|
?>
|
|
<?php if ($current_user_id > 0) : ?>
|
|
<button type="button"
|
|
class="aksrt-forum-board__follow-btn js-aksrt-follow-plate"
|
|
data-plate-id="<?php echo esc_attr((string) $plate_id); ?>"
|
|
data-followed="<?php echo $is_followed ? '1' : '0'; ?>">
|
|
<i class="fas fa-heart"></i>
|
|
<?php echo $is_followed ? esc_html__('已关注', 'aksrt') : esc_html__('关注', 'aksrt'); ?>
|
|
</button>
|
|
<?php elseif ($guest_followed) : ?>
|
|
<button type="button" class="aksrt-forum-board__follow-btn is-followed" disabled>
|
|
<i class="fas fa-heart"></i>
|
|
<?php esc_html_e('已关注', 'aksrt'); ?>
|
|
</button>
|
|
<?php elseif ($allow_guest_plate) : ?>
|
|
<button type="button"
|
|
class="aksrt-forum-board__follow-btn"
|
|
data-aksrt-pay-plate-follow="<?php echo esc_attr((string) $plate_id); ?>">
|
|
<i class="fas fa-heart"></i>
|
|
<?php esc_html_e('付费关注', 'aksrt'); ?>
|
|
</button>
|
|
<p class="description" style="margin-top:6px;font-size:12px;">
|
|
<?php esc_html_e('未登录关注通过 Cookie 生效;建议登录后关注以便保存订单。', 'aksrt'); ?>
|
|
</p>
|
|
<?php endif; ?>
|
|
|
|
<?php if (!empty($permissions['can_compose'])) : ?>
|
|
<a href="<?php echo esc_url($compose_url); ?>" class="aksrt-forum-board__compose-btn">
|
|
<i class="fas fa-pen"></i>
|
|
<?php esc_html_e('发布新主题', 'aksrt'); ?>
|
|
</a>
|
|
<?php endif; ?>
|
|
|
|
<?php
|
|
$is_forum_admin = $forum && $forum->is_forum_admin($current_user_id);
|
|
$is_plate_author = $board_data && (int) ($board_data['author_id'] ?? 0) === $current_user_id;
|
|
?>
|
|
<?php if ($is_forum_admin || $is_plate_author) : ?>
|
|
<button type="button" class="aksrt-forum-board__manage-btn js-aksrt-edit-plate"
|
|
data-plate-id="<?php echo esc_attr((string) $plate_id); ?>"
|
|
data-name="<?php echo esc_attr((string) ($board_data['name'] ?? '')); ?>"
|
|
data-description="<?php echo esc_attr((string) ($board_data['description'] ?? '')); ?>"
|
|
data-icon="<?php echo esc_attr((string) ($board_data['icon'] ?? '')); ?>"
|
|
data-cover="<?php echo esc_attr((string) ($board_data['cover_url'] ?? '')); ?>">
|
|
<i class="fas fa-cog"></i> <?php esc_html_e('编辑版块', 'aksrt'); ?>
|
|
</button>
|
|
<?php endif; ?>
|
|
<?php if ($is_forum_admin) : ?>
|
|
<button type="button" class="aksrt-forum-board__manage-btn aksrt-forum-board__manage-btn--danger js-aksrt-delete-plate"
|
|
data-plate-id="<?php echo esc_attr((string) $plate_id); ?>"
|
|
data-topic-count="<?php echo esc_attr((string) ($board_data['post_count'] ?? $board_data['topic_count'] ?? 0)); ?>">
|
|
<i class="fas fa-trash-alt"></i> <?php esc_html_e('删除版块', 'aksrt'); ?>
|
|
</button>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (!empty($board_data['content'])) : ?>
|
|
<div class="aksrt-forum-board__content entry-content">
|
|
<?php echo wp_kses_post((string) $board_data['content']); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (!empty($sticky_topics)) : ?>
|
|
<div class="aksrt-forum-board__sticky">
|
|
<h3><i class="fas fa-thumbtack"></i> <?php esc_html_e('置顶主题', 'aksrt'); ?></h3>
|
|
<?php foreach ($sticky_topics as $topic) : ?>
|
|
<a href="<?php echo esc_url((string) ($topic['permalink'] ?? '#')); ?>" class="aksrt-forum-board__sticky-item">
|
|
<?php $sticky_label = (string) ($topic['sticky_label'] ?? __('置顶', 'aksrt')); ?>
|
|
<span class="aksrt-forum-board__sticky-badge"><?php echo esc_html($sticky_label); ?></span>
|
|
<span class="aksrt-forum-board__sticky-title"><?php echo esc_html((string) ($topic['title'] ?? '')); ?></span>
|
|
<span class="aksrt-forum-board__sticky-meta">
|
|
<?php echo esc_html((string) ($topic['author']['display_name'] ?? '')); ?>
|
|
· <?php echo esc_html((string) ($topic['date'] ?? '')); ?>
|
|
</span>
|
|
</a>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (!empty($tabs)) : ?>
|
|
<nav class="aksrt-forum-board__tabs" aria-label="<?php esc_attr_e('版块栏目', 'aksrt'); ?>">
|
|
<?php foreach ($tabs as $tab) :
|
|
$sort = sanitize_key((string) ($tab['sort'] ?? 'date'));
|
|
$label = (string) ($tab['label'] ?? $sort);
|
|
$tab_url = add_query_arg('forum_sort', $sort, $plate_url);
|
|
$is_active = $sort === $active_sort;
|
|
?>
|
|
<a class="aksrt-forum-board__tab js-aksrt-board-sort-tab<?php echo $is_active ? ' is-active' : ''; ?>"
|
|
href="<?php echo esc_url($tab_url); ?>"
|
|
data-sort="<?php echo esc_attr($sort); ?>"
|
|
<?php echo $is_active ? 'aria-current="page"' : ''; ?>>
|
|
<?php echo esc_html($label); ?>
|
|
</a>
|
|
<?php endforeach; ?>
|
|
</nav>
|
|
<?php endif; ?>
|
|
|
|
<div class="aksrt-forum-board__topics">
|
|
<div class="aksrt-forum-topics__list js-aksrt-board-topic-list">
|
|
<?php if (!empty($topics) && $forum) : ?>
|
|
<?php foreach ($topics as $topic) { $forum->render_topic_row($topic); } ?>
|
|
<?php else : ?>
|
|
<div class="aksrt-forum-board__empty aksrt-forum__empty">
|
|
<i class="fas fa-comments"></i>
|
|
<p><?php esc_html_e('内容空空如也', 'aksrt'); ?></p>
|
|
<?php if (!empty($permissions['can_compose'])) : ?>
|
|
<a href="<?php echo esc_url($compose_url); ?>"><?php esc_html_e('发布第一个主题', 'aksrt'); ?></a>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<?php if ($max_pages > 1) : ?>
|
|
<div class="aksrt-forum-board__pagination">
|
|
<?php
|
|
echo paginate_links([
|
|
'total' => $max_pages,
|
|
'current' => $paged,
|
|
'prev_text' => '<i class="fas fa-chevron-left"></i>',
|
|
'next_text' => '<i class="fas fa-chevron-right"></i>',
|
|
'add_args' => $active_sort !== '' ? ['forum_sort' => $active_sort] : [],
|
|
]);
|
|
?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<section class="aksrt-forum-board__governance aksrt-forum-board__governance--footer">
|
|
<div class="aksrt-forum-board__governance-card">
|
|
<h2 class="aksrt-forum-board__section-title"><?php esc_html_e('版主团队', 'aksrt'); ?></h2>
|
|
<?php if (!empty($moderators)) : ?>
|
|
<div class="aksrt-forum-board__moderators">
|
|
<?php foreach ($moderators as $moderator) : ?>
|
|
<div class="aksrt-forum-board__moderator">
|
|
<?php if (!empty($moderator['avatar'])) : ?>
|
|
<img src="<?php echo esc_url((string) $moderator['avatar']); ?>" alt="" width="36" height="36">
|
|
<?php endif; ?>
|
|
<span><?php echo esc_html((string) ($moderator['name'] ?? $moderator['display_name'] ?? '')); ?></span>
|
|
<?php if (!empty($moderator['role'])) : ?>
|
|
<small class="aksrt-forum-board__moderator-role"><?php echo esc_html((string) $moderator['role']); ?></small>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php else : ?>
|
|
<p><?php esc_html_e('当前还没有设置版主。', 'aksrt'); ?></p>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<div class="aksrt-forum-board__governance-card">
|
|
<h2 class="aksrt-forum-board__section-title"><?php esc_html_e('版主申请', 'aksrt'); ?></h2>
|
|
<?php if (!is_user_logged_in()) : ?>
|
|
<p class="aksrt-forum-board__application-note"><?php esc_html_e('登录后可申请协助管理本版块。', 'aksrt'); ?></p>
|
|
<a href="<?php echo esc_url(wp_login_url(get_permalink())); ?>" class="aksrt-forum-board__apply-btn"><?php esc_html_e('登录后申请', 'aksrt'); ?></a>
|
|
<?php elseif (!empty($application)) : ?>
|
|
<p class="aksrt-forum-board__application-note">
|
|
<?php printf(
|
|
esc_html__('你最近一次申请状态:%s', 'aksrt'),
|
|
esc_html((string) ($application['status_label'] ?? __('待处理', 'aksrt')))
|
|
); ?>
|
|
</p>
|
|
<?php if (!empty($application['reason'])) : ?>
|
|
<blockquote class="aksrt-forum-board__application-reason"><?php echo esc_html((string) $application['reason']); ?></blockquote>
|
|
<?php endif; ?>
|
|
<?php if (!empty($application['review_note'])) : ?>
|
|
<p class="aksrt-forum-board__application-note"><?php printf(esc_html__('审核备注:%s', 'aksrt'), esc_html((string) $application['review_note'])); ?></p>
|
|
<?php endif; ?>
|
|
<?php if (($application['status'] ?? '') !== 'pending' && !empty($permissions['can_apply_moderator'])) : ?>
|
|
<form class="aksrt-forum-board__application-form js-aksrt-moderator-apply-form" data-board-id="<?php echo esc_attr((string) $plate_id); ?>">
|
|
<label for="aksrt-plate-apply-reason"><?php esc_html_e('重新申请理由', 'aksrt'); ?></label>
|
|
<textarea id="aksrt-plate-apply-reason" name="reason" rows="4" placeholder="<?php esc_attr_e('请简要说明你的社区经验、擅长领域或管理计划。', 'aksrt'); ?>"></textarea>
|
|
<div class="aksrt-forum-board__application-actions">
|
|
<button type="submit" class="aksrt-forum-board__apply-btn"><?php esc_html_e('重新提交申请', 'aksrt'); ?></button>
|
|
<span class="aksrt-forum-board__application-feedback js-aksrt-action-feedback" aria-live="polite"></span>
|
|
</div>
|
|
</form>
|
|
<?php endif; ?>
|
|
<?php elseif (!empty($permissions['can_apply_moderator'])) : ?>
|
|
<p class="aksrt-forum-board__application-note"><?php esc_html_e('如果你熟悉本版块内容并愿意协助维护秩序,可以提交版主申请。', 'aksrt'); ?></p>
|
|
<form class="aksrt-forum-board__application-form js-aksrt-moderator-apply-form" data-board-id="<?php echo esc_attr((string) $plate_id); ?>">
|
|
<label for="aksrt-plate-apply-reason"><?php esc_html_e('申请理由', 'aksrt'); ?></label>
|
|
<textarea id="aksrt-plate-apply-reason" name="reason" rows="4" placeholder="<?php esc_attr_e('请简要说明你的社区经验、擅长领域或管理计划。', 'aksrt'); ?>"></textarea>
|
|
<div class="aksrt-forum-board__application-actions">
|
|
<button type="submit" class="aksrt-forum-board__apply-btn"><?php esc_html_e('提交版主申请', 'aksrt'); ?></button>
|
|
<span class="aksrt-forum-board__application-feedback js-aksrt-action-feedback" aria-live="polite"></span>
|
|
</div>
|
|
</form>
|
|
<?php else : ?>
|
|
<p class="aksrt-forum-board__application-note"><?php esc_html_e('你当前已是本版块管理成员,或暂不满足申请条件。', 'aksrt'); ?></p>
|
|
<?php endif; ?>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
|
|
<?php endif; ?>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<?php get_footer(); ?>
|