159 lines
5.5 KiB
PHP
159 lines
5.5 KiB
PHP
<?php
|
|
/**
|
|
* Template Name: AKSRT - 写文章/投稿
|
|
* Template Post Type: page
|
|
*
|
|
* 前台文章投稿页(对齐 legacy newposts:双栏 + TinyMCE + 封面 + 付费 + 草稿)。
|
|
* 注意:page-newposts.php 是「最新文章」列表,不是投稿。
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
$ctx = include get_template_directory() . '/templates/parts/submit/context.php';
|
|
if (!is_array($ctx)) {
|
|
$ctx = [];
|
|
}
|
|
|
|
// Feature disabled → soft 404.
|
|
if (empty($ctx['enabled'])) {
|
|
global $wp_query;
|
|
$wp_query->set_404();
|
|
status_header(404);
|
|
nocache_headers();
|
|
include get_query_template('404');
|
|
return;
|
|
}
|
|
|
|
// Guest without guest mode → login.
|
|
if (!empty($ctx['is_guest']) && empty($ctx['settings']['guest_enabled'])) {
|
|
$login = function_exists('aksrt_get_login_url') ? aksrt_get_login_url(get_permalink()) : wp_login_url(get_permalink());
|
|
wp_safe_redirect($login);
|
|
exit;
|
|
}
|
|
|
|
// Invalid edit id → strip.
|
|
if (!empty($_GET['edit']) && empty($ctx['edit_post'])) {
|
|
wp_safe_redirect(remove_query_arg('edit'));
|
|
exit;
|
|
}
|
|
|
|
// wp_editor() is rendered after get_header(); queue its runtime before wp_head.
|
|
wp_enqueue_editor();
|
|
|
|
// Assets.
|
|
$css = get_template_directory() . '/assets/css/frontend/pages/submit.css';
|
|
if (file_exists($css)) {
|
|
wp_enqueue_style(
|
|
'aksrt-submit',
|
|
get_template_directory_uri() . '/assets/css/frontend/pages/submit.css',
|
|
[],
|
|
(string) filemtime($css)
|
|
);
|
|
}
|
|
$js = get_template_directory() . '/assets/js/front-submit.js';
|
|
if (file_exists($js)) {
|
|
wp_enqueue_script(
|
|
'aksrt-front-submit',
|
|
get_template_directory_uri() . '/assets/js/front-submit.js',
|
|
['jquery', 'aksrt-notyf'],
|
|
(string) filemtime($js),
|
|
true
|
|
);
|
|
$mini = get_template_directory() . '/assets/js/mini-upload.js';
|
|
if (file_exists($mini)) {
|
|
wp_enqueue_script(
|
|
'aksrt-mini-upload',
|
|
get_template_directory_uri() . '/assets/js/mini-upload.js',
|
|
[],
|
|
(string) filemtime($mini),
|
|
true
|
|
);
|
|
}
|
|
$attachment_settings = class_exists('\\AKSRT\\Settings\\Settings') ? \AKSRT\Settings\Settings::get_all() : [];
|
|
$submit_image_max_size = max(1, min(20, (int) ($attachment_settings['submit_image_max_size'] ?? 5))) * MB_IN_BYTES;
|
|
$resource_max_size = max(1, min(200, (int) ($attachment_settings['resource_max_size'] ?? 50))) * MB_IN_BYTES;
|
|
|
|
wp_localize_script('aksrt-front-submit', 'aksrtSubmitData', [
|
|
'ajaxUrl' => admin_url('admin-ajax.php'),
|
|
'nonce' => wp_create_nonce('aksrt_submit'),
|
|
'restUrl' => esc_url_raw(rest_url('aksrt/v1')),
|
|
'restNonce' => wp_create_nonce('wp_rest'),
|
|
'leaveWarning' => !empty($ctx['settings']['leave_warning']),
|
|
'ai' => [
|
|
'available' => !empty($ctx['ai_available']),
|
|
'summary' => !empty($ctx['ai_available']),
|
|
'tags' => !empty($ctx['ai_available']),
|
|
],
|
|
'uploads' => [
|
|
'image' => !empty($ctx['can_upload_img']) ? [
|
|
'url' => esc_url_raw(rest_url('aksrt/v1/front-submit/upload/image')),
|
|
'maxSize' => $submit_image_max_size,
|
|
] : null,
|
|
'resource' => !empty($ctx['can_upload_file']) ? [
|
|
'url' => esc_url_raw(rest_url('aksrt/v1/front-submit/upload/resource')),
|
|
'maxSize' => $resource_max_size,
|
|
] : null,
|
|
],
|
|
'i18n' => [
|
|
'confirmLeave' => __('你有未保存的更改,确定要离开吗?', 'aksrt'),
|
|
'saving' => __('保存中...', 'aksrt'),
|
|
'saved' => __('草稿已保存', 'aksrt'),
|
|
'submitting' => __('提交中...', 'aksrt'),
|
|
'submitted' => __('投稿已提交', 'aksrt'),
|
|
'error' => __('操作失败,请重试', 'aksrt'),
|
|
'confirmDelete' => __('确定要删除这个草稿吗?', 'aksrt'),
|
|
'aiGenerating' => __('生成中…', 'aksrt'),
|
|
'aiFailed' => __('AI 生成失败', 'aksrt'),
|
|
'needContent' => __('请先填写正文内容', 'aksrt'),
|
|
'aiFilled' => __('已填入,可继续编辑', 'aksrt'),
|
|
'deleting' => __('正在删除草稿…', 'aksrt'),
|
|
'deleted' => __('草稿已删除', 'aksrt'),
|
|
'uploading' => __('正在上传…', 'aksrt'),
|
|
'uploaded' => __('上传成功', 'aksrt'),
|
|
'fileTooLarge' => __('文件大小超过限制', 'aksrt'),
|
|
'lastSaved' => __('最后保存:', 'aksrt'),
|
|
'preview' => __('预览文章', 'aksrt'),
|
|
'pickImage' => __('选择图片', 'aksrt'),
|
|
'pickVideo' => __('选择视频封面图', 'aksrt'),
|
|
'videoUrl' => __('请输入视频地址', 'aksrt'),
|
|
],
|
|
]);
|
|
}
|
|
|
|
get_header();
|
|
?>
|
|
<main id="main-content" class="site-main container aksrt-article-compose" tabindex="-1">
|
|
<form class="aksrt-submit-form aksrt-article-compose__form" id="aksrt-submit-form" data-aksrt-submit-form data-dirty="false" novalidate>
|
|
<div class="aksrt-article-compose__layout">
|
|
<?php
|
|
$main = get_template_directory() . '/templates/parts/submit/editor-main.php';
|
|
if (file_exists($main)) {
|
|
include $main;
|
|
}
|
|
?>
|
|
<aside class="aksrt-submit-sidebar">
|
|
<?php \AKSRT\WidgetSystem\WidgetAreas::render('newposts_sidebar_top', 'aksrt-submit-sidebar__widgets'); ?>
|
|
<?php
|
|
$terms = get_template_directory() . '/templates/parts/submit/sidebar-terms.php';
|
|
if (file_exists($terms)) {
|
|
include $terms;
|
|
}
|
|
$pay = get_template_directory() . '/templates/parts/submit/sidebar-pay.php';
|
|
if (file_exists($pay)) {
|
|
include $pay;
|
|
}
|
|
$actions = get_template_directory() . '/templates/parts/submit/sidebar-submit.php';
|
|
if (file_exists($actions)) {
|
|
include $actions;
|
|
}
|
|
?>
|
|
<?php \AKSRT\WidgetSystem\WidgetAreas::render('newposts_sidebar_bottom', 'aksrt-submit-sidebar__widgets'); ?>
|
|
</aside>
|
|
</div>
|
|
</form>
|
|
</main>
|
|
<?php
|
|
get_footer();
|