add-page.html.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?php if (!defined('HTMLY')) die('HTMLy'); ?>
  2. <?php $images = image_gallery(null, 1, 40); ?>
  3. <?php
  4. $fields = array();
  5. if ($type == 'is_page') {
  6. $field_file = 'content/data/field/page.json';
  7. if (file_exists($field_file)) {
  8. $fields = json_decode(file_get_contents($field_file, true));
  9. }
  10. } elseif ($type == 'is_subpage') {
  11. $field_file = 'content/data/field/subpage.json';
  12. if (file_exists($field_file)) {
  13. $fields = json_decode(file_get_contents($field_file, true));
  14. }
  15. }
  16. ?>
  17. <link rel="stylesheet" type="text/css" href="<?php echo site_url() ?>system/admin/editor/css/editor.css"/>
  18. <script src="<?php echo site_url() ?>system/resources/js/jquery.min.js"></script>
  19. <script src="<?php echo site_url() ?>system/resources/js/jquery-ui.min.js"></script>
  20. <script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Converter.js"></script>
  21. <script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Sanitizer.js"></script>
  22. <script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Editor.js"></script>
  23. <script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Extra.js"></script>
  24. <link rel="stylesheet" href="<?php echo site_url() ?>system/resources/css/jquery-ui.css">
  25. <?php if (isset($error)) { ?>
  26. <div class="error-message"><?php echo $error ?></div>
  27. <?php } ?>
  28. <div class="notice error" id="response-error"></div>
  29. <div class="notice" id="response"></div>
  30. <div class="row">
  31. <div class="hide-button" style="margin-bottom:1em;width:100%;text-align:right;"><button type="button" title="<?php echo i18n('Focus_mode');?>" id="hideButton" class="note-btn btn btn-sm <?php echo ((config('admin.theme') === 'light' || is_null(config('admin.theme'))) ? "btn-light" : "btn-dark");?>" style="width:38px;height:38px;font-size:18px;" ><i class="fa fa-eye" aria-hidden="true"></i></button></div>
  32. <div class="wmd-panel" style="width:100%;">
  33. <form method="POST">
  34. <div id="post-settings" class="row">
  35. <div class="col-sm-6">
  36. <label for="pTitle"><?php echo i18n('Title');?> <span class="required">*</span></label>
  37. <input type="text" class="form-control text <?php if (isset($postTitle)) {if (empty($postTitle)) {echo 'error';}} ?>" id="pTitle" name="title" value="<?php if (isset($postTitle)) {echo $postTitle;} ?>"/>
  38. <br>
  39. <label for="pMeta"><?php echo i18n('Meta_description');?> (<?php echo i18n('optional');?>)</label>
  40. <textarea id="pMeta" class="form-control" name="description" rows="3" cols="20" placeholder="<?php echo i18n('If_left_empty_we_will_excerpt_it_from_the_content_below');?>"><?php if (isset($p->description)) {echo $p->description;} ?></textarea>
  41. <br>
  42. </div>
  43. <div class="col-sm-6">
  44. <?php if ($type == 'is_page' || $type == 'is_subpage') :?>
  45. <label for="pURL"><?php echo i18n('Slug');?> (<?php echo i18n('optional');?>)</label>
  46. <input type="text" class="form-control text" id="pURL" name="url" value="<?php if (isset($postUrl)) {echo $postUrl;} ?>" placeholder="<?php echo i18n('If_the_url_is_left_empty_we_will_use_the_page_title');?>"/>
  47. <br>
  48. <?php endif;?>
  49. </div>
  50. </div>
  51. <div class="row">
  52. <div class="col-sm-12" style="text-align:right;">
  53. <button class="note-btn btn btn-sm <?php echo ((config('admin.theme') === 'light' || is_null(config('admin.theme'))) ? "btn-light" : "btn-dark");?>" style="width:38px;height:38px;font-size:18px;" type="button" title="Toggle <?php echo i18n('Preview');?>" id="preview-toggle" class="btn btn-secondary btn-xs"><i class="fa fa-columns" aria-hidden="true"></i></button>
  54. </div>
  55. </div>
  56. <div class="row">
  57. <div class="col-sm-6" id="editor-col">
  58. <div>
  59. <label for="wmd-input"><?php echo i18n('Content');?> <span class="required">*</span></label>
  60. <div id="wmd-button-bar" class="wmd-button-bar"></div>
  61. <textarea id="wmd-input" class="form-control wmd-input <?php if (isset($postContent)) {if (empty($postContent)) {echo 'error';}} ?>" name="content" cols="20" rows="10"><?php if (isset($postContent)) {echo $postContent;} ?></textarea>
  62. <br>
  63. <?php if(!empty($fields) && $type != 'is_category'):?>
  64. <details id="custom-fields" >
  65. <summary id="custom-fields-click" style="padding:10px; margin-bottom:10px; <?php echo ((config('admin.theme') === 'light' || is_null(config('admin.theme'))) ? "background-color: #E4EBF1;" : "background-color: rgba(255,255,255,.1);");?>"><strong><?php echo i18n('custom_fields');?></strong></summary>
  66. <div class="row">
  67. <div class="col">
  68. <?php foreach ($fields as $fld):?>
  69. <?php if ($fld->type == 'text'):?>
  70. <label><?php echo $fld->label;?></label>
  71. <input type="<?php echo $fld->type;?>" placeholder="<?php echo $fld->info;?>" class="form-control text" id="<?php echo $fld->name;?>" name="<?php echo $fld->name;?>" value=""/>
  72. <br>
  73. <?php elseif ($fld->type == 'textarea'):?>
  74. <label><?php echo $fld->label;?></label>
  75. <textarea class="form-control text" id="<?php echo $fld->name;?>" rows="3" placeholder="<?php echo $fld->info;?>" name="<?php echo $fld->name;?>"></textarea>
  76. <br>
  77. <?php elseif ($fld->type == 'checkbox'):?>
  78. <input type="<?php echo $fld->type;?>" id="<?php echo $fld->name;?>" name="<?php echo $fld->name;?>" >
  79. <label for="<?php echo $fld->name;?>"><?php echo $fld->label;?></label>
  80. <span class="d-block mt-1"><small><em><?php echo $fld->info;?></em></small></span>
  81. <br>
  82. <?php elseif ($fld->type == 'select'):?>
  83. <label for="<?php echo $fld->name;?>"><?php echo $fld->label;?></label>
  84. <select id="<?php echo $fld->name;?>" class="form-control" name="<?php echo $fld->name;?>">
  85. <?php foreach ($fld->options as $val):?>
  86. <option value="<?php echo $val;?>" ><?php echo $val;?></option>
  87. <?php endforeach;?>
  88. </select>
  89. <span class="d-block mt-1"><small><em><?php echo $fld->info;?></em></small></span>
  90. <br>
  91. <?php endif;?>
  92. <?php endforeach;?>
  93. </div>
  94. </div>
  95. </details>
  96. <br>
  97. <script>if(localStorage.getItem("custom-fields-state")==="open"){document.getElementById("custom-fields").setAttribute("open","")}document.getElementById("custom-fields-click").addEventListener("click",()=>{if(document.getElementById("custom-fields").open){localStorage.setItem("custom-fields-state",'close')}else{localStorage.setItem("custom-fields-state",'open')}})</script>
  98. <?php endif;?>
  99. <input type="hidden" id="pType" name="posttype" value="<?php echo $type; ?>">
  100. <input id="oldfile" type="hidden" name="oldfile" class="text"/>
  101. <input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">
  102. <?php if ($type == 'is_page' || $type == 'is_subpage') :?>
  103. <input type="submit" name="submit" class="btn btn-primary submit" value="<?php echo i18n('Publish');?>"/> <input type="submit" name="draft" class="btn btn-primary draft" value="<?php echo i18n('Save_as_draft');?>"/>
  104. <?php endif;?>
  105. <?php if ($type == 'is_category') :?>
  106. <input type="submit" name="submit" class="btn btn-primary submit" value="<?php echo i18n('Add_category');?>"/>
  107. <?php endif;?>
  108. </div>
  109. </div>
  110. <div class="col-sm-6" id="preview-col">
  111. <label><?php echo i18n('Preview');?></label>
  112. <br>
  113. <div id="wmd-preview" class="wmd-panel wmd-preview <?php if (config('admin.theme') === 'dark'){echo "card";}?>" style="width:100%;overflow:auto;"></div>
  114. </div>
  115. </div>
  116. </form>
  117. </div>
  118. <style>
  119. .wmd-prompt-background {z-index:10!important;}
  120. #wmd-preview img {max-width:100%;}
  121. </style>
  122. <div class="modal fade" id="insertImageDialog" tabindex="-1" role="dialog" aria-labelledby="insertImageDialogTitle" aria-hidden="true">
  123. <div class="modal-dialog modal-xl" role="document">
  124. <div class="modal-content">
  125. <div class="modal-header">
  126. <p class="modal-title" id="insertImageDialogTitle"><?php echo i18n('Insert_Image');?></p>
  127. <button type="button" class="close" id="insertImageDialogClose" data-dismiss="modal" aria-label="Close">
  128. <span aria-hidden="true">&times;</span>
  129. </button>
  130. </div>
  131. <div class="modal-body">
  132. <div class="row">
  133. <div class="col-9">
  134. <div class="form-group">
  135. <div class="row-fluid img-container" id="gallery-1">
  136. <?php echo $images;?>
  137. </div>
  138. </div>
  139. </div>
  140. <div class="col">
  141. <div class="form-group">
  142. <label for="insertImageDialogURL">URL</label>
  143. <textarea class="form-control" id="insertImageDialogURL" rows="5" placeholder="<?php echo i18n('Enter_image_URL');?>" ></textarea>
  144. </div>
  145. <hr>
  146. <div class="form-group">
  147. <label for="insertImageDialogFile"><?php echo i18n('Upload');?></label>
  148. <input type="file" class="form-control-file" name="file" id="insertImageDialogFile" accept="image/png,image/jpeg,image/gif, image/webp" style="display:none;" />
  149. <button id="dropZoneIIDF" class="vs-dropzone" type="button">Drag &amp; Drop image here, or click to browse</button>
  150. </div>
  151. <hr>
  152. <div class="form-group">
  153. <button type="button" class="btn btn-primary" id="insertImageDialogInsert"><?php echo i18n('Insert_Image');?></button>
  154. <button type="button" class="btn btn-secondary" id="insertImageDialogCancel" data-dismiss="modal"><?php echo i18n('Cancel');?></button>
  155. </div>
  156. </div>
  157. </div>
  158. </div>
  159. </div>
  160. </div>
  161. </div>
  162. </div>
  163. <!-- Declare the base path. Important -->
  164. <script type="text/javascript">
  165. var base_path = '<?php echo site_url() ?>';
  166. var initial_image = <?php echo json_encode($images); ?>;
  167. var parent_page = '<?php echo isset($parent) ? $parent : '';?>';
  168. var addEdit = 'add';
  169. var saveInterval = 60000;
  170. const field = [<?php foreach ($fields as $f){ echo '"' . $f->name . '", ';}?>];
  171. </script>
  172. <script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/editor.js"></script>
  173. <script>
  174. function loadImages(page) {
  175. $.ajax({
  176. url: '<?php echo site_url();?>admin/gallery',
  177. type: 'POST',
  178. data: { page: page },
  179. dataType: 'json',
  180. success: function(response) {
  181. $('#gallery-1').html(response.images);
  182. $('#gallery-2').html(response.images);
  183. }
  184. });
  185. }
  186. $('.img-container').on("click", ".the-img", function(e) {
  187. $('#insertMediaDialogURL').val($(e.target).attr('src'));
  188. $('#insertImageDialogURL').val($(e.target).attr('src'));
  189. });
  190. </script>
  191. <script>
  192. function toggleDivs() {
  193. var div1 = document.getElementById('post-settings');
  194. if (div1.style.display === 'none') {
  195. div1.style.display = '';
  196. document.body.classList.add("sidebar-mini");
  197. document.body.classList.remove("sidebar-collapse");
  198. } else {
  199. div1.style.display = 'none';
  200. document.body.classList.remove("sidebar-mini");
  201. document.body.classList.add("sidebar-collapse");
  202. }
  203. }
  204. document.getElementById('hideButton').addEventListener('click', toggleDivs);
  205. </script>
  206. <?php if (config('autosave.enable') == 'true' ):?>
  207. <?php if ($type == 'is_page' || $type == 'is_subpage') :?>
  208. <script src="<?php echo site_url();?>system/resources/js/save_draft.js?v=1"></script>
  209. <?php endif;?>
  210. <?php endif;?>
  211. <script>
  212. if (localStorage.getItem("preview-state") === "open") {
  213. document.getElementById("editor-col").classList.remove('col-sm-12');
  214. document.getElementById("editor-col").classList.add('col-sm-6');
  215. document.getElementById("preview-col").style.display = '';
  216. } else if (localStorage.getItem("preview-state") === "close") {
  217. document.getElementById("editor-col").classList.remove('col-sm-6');
  218. document.getElementById("editor-col").classList.add('col-sm-12');
  219. document.getElementById("preview-col").style.display = 'none';
  220. }
  221. document.getElementById("preview-toggle").addEventListener("click", () => {
  222. if (document.getElementById("editor-col").className.includes("col-sm-6")) {
  223. document.getElementById("editor-col").classList.remove('col-sm-6');
  224. document.getElementById("editor-col").classList.add('col-sm-12');
  225. document.getElementById("preview-col").style.display = 'none';
  226. localStorage.setItem("preview-state", 'close');
  227. } else {
  228. document.getElementById("editor-col").classList.remove('col-sm-12');
  229. document.getElementById("editor-col").classList.add('col-sm-6');
  230. document.getElementById("preview-col").style.display = '';
  231. localStorage.setItem("preview-state", 'open');
  232. }
  233. })
  234. </script>