write-post.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php
  2. include 'common.php';
  3. include 'header.php';
  4. include 'menu.php';
  5. \Widget\Contents\Post\Edit::alloc()->to($post);
  6. ?>
  7. <div class="main">
  8. <div class="body container">
  9. <?php include 'page-title.php'; ?>
  10. <div class="row typecho-page-main typecho-post-area" role="form">
  11. <form action="<?php $security->index('/action/contents-post-edit'); ?>" method="post" name="write_post">
  12. <div class="col-mb-12 col-tb-9" role="main">
  13. <?php if ($post->draft): ?>
  14. <?php if ($post->draft['cid'] != $post->cid): ?>
  15. <?php $postModifyDate = new \Typecho\Date($post->draft['modified']); ?>
  16. <cite
  17. class="edit-draft-notice"><?php _e('你正在编辑的是保存于 %s 的草稿, 你也可以 <a href="%s">删除它</a>', $postModifyDate->word(),
  18. $security->getIndex('/action/contents-post-edit?do=deleteDraft&cid=' . $post->cid)); ?></cite>
  19. <?php else: ?>
  20. <cite class="edit-draft-notice"><?php _e('当前正在编辑的是未发布的草稿'); ?></cite>
  21. <?php endif; ?>
  22. <input name="draft" type="hidden" value="<?php echo $post->draft['cid'] ?>"/>
  23. <?php endif; ?>
  24. <p class="title">
  25. <label for="title" class="sr-only"><?php _e('标题'); ?></label>
  26. <input type="text" id="title" name="title" autocomplete="off" value="<?php $post->title(); ?>"
  27. placeholder="<?php _e('标题'); ?>" class="w-100 text title"/>
  28. </p>
  29. <?php $permalink = \Typecho\Common::url($options->routingTable['post']['url'], $options->index);
  30. [$scheme, $permalink] = explode(':', $permalink, 2);
  31. $permalink = ltrim($permalink, '/');
  32. $permalink = preg_replace("/\[([_a-z0-9-]+)[^\]]*\]/i", "{\\1}", $permalink);
  33. if ($post->have()) {
  34. $permalink = str_replace([
  35. '{cid}', '{category}', '{year}', '{month}', '{day}'
  36. ], [
  37. $post->cid, $post->category, $post->year, $post->month, $post->day
  38. ], $permalink);
  39. }
  40. $input = '<input type="text" id="slug" name="slug" autocomplete="off" value="' . htmlspecialchars($post->slug ?? '') . '" class="mono" />';
  41. ?>
  42. <p class="mono url-slug">
  43. <label for="slug" class="sr-only"><?php _e('网址缩略名'); ?></label>
  44. <?php echo preg_replace("/\{slug\}/i", $input, $permalink); ?>
  45. </p>
  46. <p>
  47. <label for="text" class="sr-only"><?php _e('文章内容'); ?></label>
  48. <textarea style="height: <?php $options->editorSize(); ?>px" autocomplete="off" id="text"
  49. name="text" class="w-100 mono"><?php echo htmlspecialchars($post->text ?? ''); ?></textarea>
  50. </p>
  51. <?php include 'custom-fields.php'; ?>
  52. <p class="submit clearfix">
  53. <span class="left">
  54. <button type="button" id="btn-cancel-preview" class="btn"><i
  55. class="i-caret-left"></i> <?php _e('取消预览'); ?></button>
  56. </span>
  57. <span class="right">
  58. <input type="hidden" name="cid" value="<?php $post->cid(); ?>"/>
  59. <button type="button" id="btn-preview" class="btn"><i
  60. class="i-exlink"></i> <?php _e('预览文章'); ?></button>
  61. <button type="submit" name="do" value="save" id="btn-save"
  62. class="btn"><?php _e('保存草稿'); ?></button>
  63. <button type="submit" name="do" value="publish" class="btn primary"
  64. id="btn-submit"><?php _e('发布文章'); ?></button>
  65. <?php if ($options->markdown && (!$post->have() || $post->isMarkdown)): ?>
  66. <input type="hidden" name="markdown" value="1"/>
  67. <?php endif; ?>
  68. </span>
  69. </p>
  70. <?php \Typecho\Plugin::factory('admin/write-post.php')->content($post); ?>
  71. </div>
  72. <div id="edit-secondary" class="col-mb-12 col-tb-3" role="complementary">
  73. <ul class="typecho-option-tabs clearfix">
  74. <li class="active w-50"><a href="#tab-advance"><?php _e('选项'); ?></a></li>
  75. <li class="w-50"><a href="#tab-files" id="tab-files-btn"><?php _e('附件'); ?></a></li>
  76. </ul>
  77. <div id="tab-advance" class="tab-content">
  78. <section class="typecho-post-option" role="application">
  79. <label for="date" class="typecho-label"><?php _e('发布日期'); ?></label>
  80. <p><input class="typecho-date w-100" type="text" name="date" id="date" autocomplete="off"
  81. value="<?php $post->have() && $post->created > 0 ? $post->date('Y-m-d H:i') : ''; ?>"/>
  82. </p>
  83. </section>
  84. <section class="typecho-post-option category-option">
  85. <label class="typecho-label"><?php _e('分类'); ?></label>
  86. <?php \Widget\Metas\Category\Rows::alloc()->to($category); ?>
  87. <ul>
  88. <?php
  89. if ($post->have()) {
  90. $categories = array_column($post->categories, 'mid');
  91. } else {
  92. $categories = [];
  93. }
  94. ?>
  95. <?php while ($category->next()): ?>
  96. <li><?php echo str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $category->levels); ?><input
  97. type="checkbox" id="category-<?php $category->mid(); ?>"
  98. value="<?php $category->mid(); ?>" name="category[]"
  99. <?php if (in_array($category->mid, $categories)): ?>checked="true"<?php endif; ?>/>
  100. <label
  101. for="category-<?php $category->mid(); ?>"><?php $category->name(); ?></label>
  102. </li>
  103. <?php endwhile; ?>
  104. </ul>
  105. </section>
  106. <section class="typecho-post-option">
  107. <label for="token-input-tags" class="typecho-label"><?php _e('标签'); ?></label>
  108. <p><input id="tags" name="tags" type="text" value="<?php $post->tags(',', false); ?>"
  109. class="w-100 text"/></p>
  110. </section>
  111. <?php \Typecho\Plugin::factory('admin/write-post.php')->option($post); ?>
  112. <button type="button" id="advance-panel-btn" class="btn btn-xs"><?php _e('高级选项'); ?> <i
  113. class="i-caret-down"></i></button>
  114. <div id="advance-panel">
  115. <?php if ($user->pass('editor', true)): ?>
  116. <section class="typecho-post-option visibility-option">
  117. <label for="visibility" class="typecho-label"><?php _e('公开度'); ?></label>
  118. <p>
  119. <select id="visibility" name="visibility">
  120. <?php if ($user->pass('editor', true)): ?>
  121. <option
  122. value="publish"<?php if (($post->status == 'publish' && !$post->password) || !$post->status): ?> selected<?php endif; ?>><?php _e('公开'); ?></option>
  123. <option
  124. value="hidden"<?php if ($post->status == 'hidden'): ?> selected<?php endif; ?>><?php _e('隐藏'); ?></option>
  125. <option
  126. value="password"<?php if (strlen($post->password ?? '') > 0): ?> selected<?php endif; ?>><?php _e('密码保护'); ?></option>
  127. <option
  128. value="private"<?php if ($post->status == 'private'): ?> selected<?php endif; ?>><?php _e('私密'); ?></option>
  129. <?php endif; ?>
  130. <option
  131. value="waiting"<?php if (!$user->pass('editor', true) || $post->status == 'waiting'): ?> selected<?php endif; ?>><?php _e('待审核'); ?></option>
  132. </select>
  133. </p>
  134. <p id="post-password"<?php if (strlen($post->password ?? '') == 0): ?> class="hidden"<?php endif; ?>>
  135. <label for="protect-pwd" class="sr-only">内容密码</label>
  136. <input type="text" name="password" id="protect-pwd" class="text-s"
  137. value="<?php $post->password(); ?>" size="16"
  138. placeholder="<?php _e('内容密码'); ?>" autocomplete="off"/>
  139. </p>
  140. </section>
  141. <?php endif; ?>
  142. <section class="typecho-post-option allow-option">
  143. <label class="typecho-label"><?php _e('权限控制'); ?></label>
  144. <ul>
  145. <li><input id="allowComment" name="allowComment" type="checkbox" value="1"
  146. <?php if ($post->allow('comment')): ?>checked="true"<?php endif; ?> />
  147. <label for="allowComment"><?php _e('允许评论'); ?></label></li>
  148. <li><input id="allowPing" name="allowPing" type="checkbox" value="1"
  149. <?php if ($post->allow('ping')): ?>checked="true"<?php endif; ?> />
  150. <label for="allowPing"><?php _e('允许被引用'); ?></label></li>
  151. <li><input id="allowFeed" name="allowFeed" type="checkbox" value="1"
  152. <?php if ($post->allow('feed')): ?>checked="true"<?php endif; ?> />
  153. <label for="allowFeed"><?php _e('允许在聚合中出现'); ?></label></li>
  154. </ul>
  155. </section>
  156. <section class="typecho-post-option">
  157. <label for="trackback" class="typecho-label"><?php _e('引用通告'); ?></label>
  158. <p><textarea id="trackback" class="w-100 mono" name="trackback" rows="2"></textarea></p>
  159. <p class="description"><?php _e('每一行一个引用地址, 用回车隔开'); ?></p>
  160. </section>
  161. <?php \Typecho\Plugin::factory('admin/write-post.php')->advanceOption($post); ?>
  162. </div><!-- end #advance-panel -->
  163. <?php if ($post->have()): ?>
  164. <?php $modified = new \Typecho\Date($post->modified); ?>
  165. <section class="typecho-post-option">
  166. <p class="description">
  167. <br>&mdash;<br>
  168. <?php _e('本文由 <a href="%s">%s</a> 撰写',
  169. \Typecho\Common::url('manage-posts.php?uid=' . $post->author->uid, $options->adminUrl), $post->author->screenName); ?>
  170. <br>
  171. <?php _e('最后更新于 %s', $modified->word()); ?>
  172. </p>
  173. </section>
  174. <?php endif; ?>
  175. </div><!-- end #tab-advance -->
  176. <div id="tab-files" class="tab-content hidden">
  177. <?php include 'file-upload.php'; ?>
  178. </div><!-- end #tab-files -->
  179. </div>
  180. </form>
  181. </div>
  182. </div>
  183. </div>
  184. <?php
  185. include 'copyright.php';
  186. include 'common-js.php';
  187. include 'form-js.php';
  188. include 'write-js.php';
  189. \Typecho\Plugin::factory('admin/write-post.php')->trigger($plugged)->richEditor($post);
  190. if (!$plugged) {
  191. include 'editor-js.php';
  192. }
  193. include 'file-upload-js.php';
  194. include 'custom-fields-js.php';
  195. \Typecho\Plugin::factory('admin/write-post.php')->bottom($post);
  196. include 'footer.php';
  197. ?>