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

58 lines
6.0 KiB
PHP

<?php
defined('ABSPATH') || exit;
use Jio\Forum\Access;
use Jio\Forum\Core;
use Jio\Forum\View;
$edit_id = absint(get_query_var('jio_forum_edit'));
$post = $edit_id > 0 ? get_post($edit_id) : null;
if (!is_user_logged_in()) {
wp_safe_redirect(jio_get_login_url(Core::edit_url($edit_id)));
exit;
}
if ($edit_id > 0 && (!$post instanceof WP_Post || !Access::can_manage_post(get_current_user_id(), $edit_id))) {
status_header(403);
wp_die(esc_html__('无权编辑此帖子', 'jio'));
}
wp_enqueue_editor();
$plate_id = $post ? (int) get_post_meta($post->ID, '_jio_forum_plate_id', true) : absint($_GET['plate'] ?? 0);
$vote_started = $post ? (int) get_post_meta($post->ID, '_jio_forum_vote_started', true) : 0;
$vote_deadline = $post ? (int) get_post_meta($post->ID, '_jio_forum_vote_deadline', true) : 0;
$vote_days = $vote_started && $vote_deadline ? (int) round(($vote_deadline - $vote_started) / DAY_IN_SECONDS) : 0;
$plates = get_posts(['post_type' => Core::PLATE, 'post_status' => 'publish', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC']);
View::open($post ? '编辑帖子' : '发布帖子', 'edit');
?>
<div class="jio-forum__layout"><div class="jio-forum__main">
<h1><?php echo $post ? '编辑帖子' : '发布帖子'; ?></h1>
<form class="jio-forum__form" data-forum-form="post" data-id="<?php echo esc_attr((string) $edit_id); ?>">
<label>标题<input name="title" required maxlength="120" value="<?php echo esc_attr($post ? $post->post_title : ''); ?>"></label>
<label>版块<select name="plate_id" required><option value="">选择版块</option><?php foreach ($plates as $plate) : ?><option value="<?php echo esc_attr((string) $plate->ID); ?>" <?php selected($plate_id, $plate->ID); ?>><?php echo esc_html($plate->post_title); ?></option><?php endforeach; ?></select></label>
<label>类型<select name="type"><option value="normal">普通帖子</option><option value="question" <?php selected($post ? get_post_meta($post->ID, '_jio_forum_type', true) : '', 'question'); ?>>问答</option><option value="vote" <?php selected($post ? get_post_meta($post->ID, '_jio_forum_type', true) : '', 'vote'); ?>>投票</option></select></label>
<label>正文</label>
<?php wp_editor($post ? $post->post_content : '', 'jio_forum_content', ['textarea_name' => 'content', 'textarea_rows' => 16, 'media_buttons' => false, 'quicktags' => true, 'tinymce' => ['toolbar1' => 'formatselect,bold,italic,bullist,numlist,blockquote,link,unlink,alignleft,aligncenter,alignright,undo,redo', 'toolbar2' => 'forecolor,removeformat']]); ?>
<div class="jio-forum__editor-tools">
<?php foreach (['image' => '插入图片', 'video' => '插入视频', 'resource' => '插入附件'] as $kind => $label) : ?>
<?php if (jio_get_setting('jio_forum_upload_' . ($kind === 'resource' ? 'file' : $kind), $kind === 'image')) : ?><button type="button" class="jio-forum__action" data-forum-upload="<?php echo esc_attr($kind); ?>"><?php echo esc_html($label); ?></button><?php endif; ?>
<?php endforeach; ?>
<input type="file" data-forum-file hidden>
</div>
<label>话题<input name="topics" value="<?php echo esc_attr($post ? implode(', ', wp_get_post_terms($post->ID, Core::TOPIC, ['fields' => 'names'])) : ''); ?>" placeholder="多个话题以逗号分隔"></label>
<label>标签<input name="tags" value="<?php echo esc_attr($post ? implode(', ', wp_get_post_terms($post->ID, Core::TAG, ['fields' => 'names'])) : ''); ?>" placeholder="多个标签以逗号分隔"></label>
<div class="jio-forum__form-extra" data-forum-type="vote">
<label>投票标题<input name="vote_title" maxlength="60" value="<?php echo esc_attr($post ? (string) get_post_meta($post->ID, '_jio_forum_vote_title', true) : ''); ?>"></label>
<label>投票方式<select name="vote_type"><option value="single">单选</option><option value="multiple" <?php selected($post ? get_post_meta($post->ID, '_jio_forum_vote_type', true) : '', 'multiple'); ?>>多选</option><option value="pk" <?php selected($post ? get_post_meta($post->ID, '_jio_forum_vote_type', true) : '', 'pk'); ?>>双选 PK</option></select></label>
<label>投票选项<textarea name="vote_options" rows="4" placeholder="每行一个选项"><?php echo esc_textarea($post ? implode("\n", (array) get_post_meta($post->ID, '_jio_forum_vote_options', true)) : ''); ?></textarea></label>
<label>有效期<select name="vote_days"><option value="0" <?php selected($vote_days, 0); ?>>永久</option><option value="1" <?php selected($vote_days, 1); ?>>1 天</option><option value="7" <?php selected($vote_days, 7); ?>>7 天</option><option value="30" <?php selected($vote_days, 30); ?>>30 天</option></select></label>
</div>
<label>访问权限<select name="view_limit"><option value="all">所有人</option><option value="login" <?php selected($post ? get_post_meta($post->ID, '_jio_forum_view_limit', true) : '', 'login'); ?>>登录后</option><option value="follow" <?php selected($post ? get_post_meta($post->ID, '_jio_forum_view_limit', true) : '', 'follow'); ?>>关注版块后</option><option value="points" <?php selected($post ? get_post_meta($post->ID, '_jio_forum_view_limit', true) : '', 'points'); ?>>积分解锁</option><option value="pay" <?php selected($post ? get_post_meta($post->ID, '_jio_forum_view_limit', true) : '', 'pay'); ?>>付费解锁</option></select></label>
<label>解锁价格<input name="price" type="number" min="0" step="0.01" value="<?php echo esc_attr($post ? (string) get_post_meta($post->ID, '_jio_forum_price', true) : '0'); ?>"></label>
<label>会员一级价格<input name="price_vip1" type="number" min="0" step="0.01" value="<?php echo esc_attr($post ? (string) get_post_meta($post->ID, '_jio_forum_price_vip1', true) : ''); ?>"></label>
<label>会员二级价格<input name="price_vip2" type="number" min="0" step="0.01" value="<?php echo esc_attr($post ? (string) get_post_meta($post->ID, '_jio_forum_price_vip2', true) : ''); ?>"></label>
<p class="jio-forum__message" role="status" aria-live="polite"></p><button type="submit" class="jio-forum__primary">保存帖子</button>
</form>
</div><?php View::sidebar('edit'); ?></div>
<?php View::close(); ?>