0 ? get_post($edit_id) : null; if ($edit_id > 0 && (!$post instanceof \WP_Post || !Access::can_manage_post(get_current_user_id(), $edit_id))) { status_header(403); echo '
' . jio_get_null('抱歉!您暂无编辑此内容的权限', 60, 'null-post.svg') . '
'; get_footer(); return; } $user_id = get_current_user_id(); $type = $post ? (string) get_post_meta($post->ID, '_jio_forum_type', true) : 'normal'; $plate_id = $post ? (int) get_post_meta($post->ID, '_jio_forum_plate_id', true) : absint(is_scalar($_GET['plate'] ?? 0) ? $_GET['plate'] : 0); $view_limit = $post ? (string) get_post_meta($post->ID, '_jio_forum_view_limit', true) : 'all'; $vote_options = $post ? (array) get_post_meta($post->ID, '_jio_forum_vote_options', true) : []; $topics = $post ? wp_get_post_terms($post->ID, Core::TOPIC, ['fields' => 'names']) : []; $tags = $post ? wp_get_post_terms($post->ID, Core::TAG, ['fields' => 'names']) : []; wp_enqueue_editor(); echo '
'; 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 ''; // 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 '
设置状态
' . $list . '
'; } 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 ''; } 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 ''; } /** @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 ''; } 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 '
发布类型
' . $list . '
'; } /** 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 '
'; get_footer(); } }