';
echo '
';
if ($user_id <= 0) {
echo jio_get_null('请先登录后再发布', 40, 'null-user.svg') . '
登录
';
echo '
';
self::close();
return;
}
// Cover
$cover = $post ? get_the_post_thumbnail_url($post, 'large') : '';
echo '
';
echo '
' . ($cover ? '
 . ')
' : '
') . '
';
echo '
';
echo '
';
// Title
echo '
';
// Editor
wp_editor($post ? $post->post_content : '', 'jio_forum_content', [
'textarea_name' => 'content',
'textarea_rows' => 20,
'editor_height' => wp_is_mobile() ? 460 : 486,
'media_buttons' => false,
'quicktags' => false,
'default_editor' => 'tinymce',
'tinymce' => ['placeholder' => (string) jio_get_setting('jio_forum_content_placeholder', '请输入内容')],
]);
echo '
';
foreach (['image' => ['插入图片', 'fa-image'], 'video' => ['插入视频', 'fa-video'], 'resource' => ['插入附件', 'fa-paperclip']] as $kind => [$label, $icon]) {
$setting = 'jio_forum_upload_' . ($kind === 'resource' ? 'file' : $kind);
if (jio_get_setting($setting, $kind === 'image')) {
echo '';
}
}
echo '
';
self::hidden_fields($post, $type, $view_limit);
echo '
'; // editor-main-box
// Sidebar: submit, status, access, plate, topic, tag, type, vote
echo '';
self::close();
}
private static function hidden_fields(?\WP_Post $post, string $type, string $view_limit): void {
echo '
';
echo '
';
echo '
';
}
private static function submit_box(?\WP_Post $post): string {
$last = $post ? get_the_modified_time('Y-m-d H:i:s', $post->ID) : '';
$html = '
';
if (!$post || !in_array($post->post_status, ['publish', 'pending'], true)) {
$html .= '';
}
$html .= '';
$html .= '
';
if ($post && $last !== '') {
$html .= '
编辑内容最后更新:' . esc_html($last) . '
';
}
return $html . '
';
}
private static function status_box(?\WP_Post $post): string {
if (!$post instanceof \WP_Post) return '';
$status = in_array($post->post_status, ['pending', 'draft', 'publish'], true) ? $post->post_status : 'pending';
$list = '';
foreach (['pending' => '待审核', 'draft' => '草稿', 'publish' => '发布'] as $key => $label) {
$list .= '
' . $label . '';
}
return '
';
}
private static function allow_view_box(string $current): string {
$labels = ['all' => '公开', 'login' => '登录后可查看', 'follow' => '关注版块后可查看', 'points' => '支付积分查看', 'pay' => '付费查看'];
$options = '';
foreach ($labels as $key => $label) {
$options .= '
' . esc_html($label) . '
';
}
return '
阅读权限
' . esc_html($labels[$current] ?? '公开') . '
';
}
private static function plate_box(int $current): string {
$plates = get_posts(['post_type' => Core::PLATE, 'post_status' => 'publish', 'posts_per_page' => 200, 'orderby' => 'title', 'order' => 'ASC']);
$options = '';
foreach ($plates as $plate) {
$options .= '
' . esc_html($plate->post_title) . '
';
}
$name = $current > 0 ? get_the_title($current) : '请选择';
return '
版块
' . esc_html($name) . '
';
}
/** @param string[] $selected */
private static function term_box(string $field, string $label, string $taxonomy, array $selected, string $icon): string {
$terms = get_terms(['taxonomy' => $taxonomy, 'hide_empty' => false, 'number' => 200, 'orderby' => 'count', 'order' => 'DESC']);
$selected = array_values(array_filter(array_map('strval', $selected)));
$options = '';
foreach (is_array($terms) ? $terms : [] as $term) {
$active = in_array($term->name, $selected, true);
$options .= '
';
}
return '
' . esc_html($label) . '
' . esc_html($selected ? implode('、', array_slice($selected, 0, 2)) : '请选择') . '
';
}
private static function type_box(string $current): string {
$options = [];
$options['normal'] = '标准';
if (jio_get_setting('jio_forum_question_enabled', true)) $options['question'] = '提问';
if (jio_get_setting('jio_forum_vote_enabled', true)) $options['vote'] = '投票';
if (count($options) < 2) return '';
$list = '';
foreach ($options as $key => $label) {
$list .= '
' . esc_html($label) . '';
}
return '
';
}
/** Hidden-content composer: the block becomes a site visibility shortcode on save. */
private static function hide_box(?\WP_Post $post): string {
$types = '';
foreach (['logged' => '登录可见', 'reply' => '评论可见', 'vip1' => '会员可见', 'payshow' => '付费可见'] as $key => $label) {
$types .= '
' . esc_html($label) . '';
}
return '
';
}
/** @param string[] $options */
private static function vote_box(array $options, ?\WP_Post $post): string {
$type = $post ? (string) get_post_meta($post->ID, '_jio_forum_type', true) : 'normal';
return '
投票设置
'
. '
'
. '
'
. '
'
. '
';
}
private static function close(): void {
echo '