Files
wordpress-theme-aksrt/templates/pages/page-forum-post.php
T

86 lines
6.2 KiB
PHP

<?php
defined('ABSPATH') || exit;
use Jio\Forum\Access;
use Jio\Forum\Core;
use Jio\Forum\View;
the_post();
$post = get_post();
$id = (int) $post->ID;
$plate_id = (int) get_post_meta($id, '_jio_forum_plate_id', true);
$type = (string) get_post_meta($id, '_jio_forum_type', true);
$user_id = get_current_user_id();
$can_view = Access::can_view($user_id, $id);
$can_manage = Access::can_manage_post($user_id, $id);
$can_moderate = Access::is_moderator($user_id, $plate_id);
View::open($post->post_title, 'post');
\Jio\WidgetSystem\WidgetAreas::render('forum_post_top_fluid');
?>
<div class="jio-forum__layout"><div class="jio-forum__main">
<article class="jio-forum__single">
<header class="jio-forum__single-head">
<div class="jio-forum__single-meta"><?php echo get_avatar((int) $post->post_author, 40); ?><span><?php echo esc_html(get_the_author_meta('display_name', (int) $post->post_author)); ?></span><time datetime="<?php echo esc_attr(get_the_date(DATE_W3C)); ?>"><?php echo esc_html(get_the_date()); ?></time></div>
<h1><?php echo esc_html($post->post_title); ?></h1>
<div class="jio-forum__badges">
<?php if (get_post_meta($id, '_jio_forum_pinned', true)) : ?><span>置顶</span><?php endif; ?>
<?php if ($type === 'question') : ?><span>问答</span><?php elseif ($type === 'vote') : ?><span>投票</span><?php endif; ?>
<?php if ($type === 'question' && get_post_meta($id, '_jio_forum_adopted_comment', true)) : ?><span>已解决</span><?php endif; ?>
<?php if (get_post_meta($id, '_jio_forum_essence', true)) : ?><span>精华</span><?php endif; ?>
<?php if ($plate_id > 0) : ?><a href="<?php echo esc_url(get_permalink($plate_id)); ?>"><?php echo esc_html(get_the_title($plate_id)); ?></a><?php endif; ?>
<?php foreach (wp_get_post_terms($id, Core::TOPIC) as $term) : ?><a href="<?php echo esc_url(get_term_link($term)); ?>">#<?php echo esc_html($term->name); ?></a><?php endforeach; ?>
</div>
</header>
<?php if ($can_view) : ?>
<div class="jio-forum__single-content"><?php echo apply_filters('the_content', $post->post_content); ?></div>
<?php if ($type === 'vote') : ?>
<?php
$options = (array) get_post_meta($id, '_jio_forum_vote_options', true);
$votes = (array) get_post_meta($id, '_jio_forum_vote_counts', true);
$vote_type = (string) get_post_meta($id, '_jio_forum_vote_type', true);
$deadline = (int) get_post_meta($id, '_jio_forum_vote_deadline', true);
$expired = $deadline > 0 && current_time('timestamp') > $deadline;
$vote_display = (string) jio_get_setting('jio_forum_vote_number_type', 'percentage');
$already_voted = $user_id > 0 && get_user_meta($user_id, '_jio_forum_vote_' . $id, true) !== '';
?>
<form class="jio-forum__vote" data-forum-form="vote" data-id="<?php echo esc_attr((string) $id); ?>"><h2><?php echo esc_html((string) get_post_meta($id, '_jio_forum_vote_title', true) ?: '参与投票'); ?></h2>
<?php foreach ($options as $index => $option) : ?>
<label><input type="<?php echo $vote_type === 'multiple' ? 'checkbox' : 'radio'; ?>" name="<?php echo $vote_type === 'multiple' ? 'option[]' : 'option'; ?>" value="<?php echo esc_attr((string) $index); ?>" <?php disabled($already_voted || $expired); ?> <?php if ($vote_type !== 'multiple') echo 'required'; ?>><span><?php echo esc_html($option); ?></span>
<?php if ($vote_display !== 'hide') : ?><span class="jio-forum__vote-count"><?php echo esc_html($vote_display === 'number' ? (string) (int) ($votes[$index] ?? 0) : (string) ((int) get_post_meta($id, '_jio_forum_vote_total', true) > 0 ? round(100 * (int) ($votes[$index] ?? 0) / (int) get_post_meta($id, '_jio_forum_vote_total', true)) : 0) . '%'); ?></span><?php endif; ?></label>
<?php endforeach; ?>
<p class="jio-forum__message" role="status"></p><?php if ($already_voted) : ?><p>已投票</p><?php elseif ($expired) : ?><p>投票已截止</p><?php else : ?><button type="submit" class="jio-forum__primary">提交投票</button><?php endif; ?>
</form>
<?php endif; ?>
<?php else : ?>
<section class="jio-forum__locked"><h2>内容已隐藏</h2><p>请完成访问条件后查看。</p>
<?php if ($user_id > 0) : ?>
<?php
$plate_rule = (string) get_post_meta($plate_id, '_jio_forum_view_limit', true);
$post_rule = (string) get_post_meta($id, '_jio_forum_view_limit', true);
if (in_array($plate_rule, ['points', 'pay'], true) && !\Jio\Forum\Commerce::has_plate_entitlement($user_id, $plate_id)) {
View::action('plate-unlock', $plate_id, '解锁版块');
} elseif (($plate_rule === 'follow' || $post_rule === 'follow') && !Access::follows($user_id, $plate_id)) {
echo '<a href="' . esc_url(get_permalink($plate_id)) . '">关注版块</a>';
} elseif (in_array($post_rule, ['points', 'pay'], true)) {
View::action('unlock', $id, '解锁帖子');
}
?>
<?php else : ?><a href="<?php echo esc_url(jio_get_login_url(get_permalink($id))); ?>">登录查看</a><?php endif; ?>
</section>
<?php endif; ?>
<div class="jio-forum__actions">
<?php View::action('score', $id, '赞 ' . (int) get_post_meta($id, '_jio_forum_score', true)); ?>
<button type="button" class="jio-forum__action" data-forum-action="score" data-direction="down" data-id="<?php echo esc_attr((string) $id); ?>">踩</button>
<?php View::action('favorite', $id, '收藏'); ?>
<?php View::action('report', $id, '举报'); ?>
<?php if ($can_manage) : ?><a href="<?php echo esc_url(Core::edit_url($id)); ?>">编辑</a><?php View::action('delete', $id, '删除'); endif; ?>
<?php if ($can_moderate) : View::action('essence', $id, '精华'); View::action('pin', $id, '置顶'); View::action('audit', $id, '审核'); View::action('comments', $id, $post->comment_status === 'open' ? '关闭回复' : '开放回复'); View::action('move', $id, '移动版块'); endif; ?>
</div>
</article>
<?php if ($can_view) : ?>
<?php if ($type === 'question' && get_post_meta($id, '_jio_forum_adopted_comment', true)) : ?><p class="jio-forum__adopted">已采纳回复 #<?php echo (int) get_post_meta($id, '_jio_forum_adopted_comment', true); ?></p><?php endif; ?>
<?php View::replies($id); ?>
<?php endif; ?>
</div><?php View::sidebar('post'); ?></div>
<?php \Jio\WidgetSystem\WidgetAreas::render('forum_post_bottom_fluid'); View::close(); ?>