edit-page.html.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <?php if (!defined('HTMLY')) die('HTMLy'); ?>
  2. <?php
  3. if ($type == 'is_frontpage') {
  4. $filename = 'content/data/frontpage/frontpage.md';
  5. if (file_exists($filename)) {
  6. $content = file_get_contents($filename);
  7. $oldtitle = get_content_tag('t', $content, 'Welcome');
  8. $oldcontent = remove_html_comments($content);
  9. } else {
  10. $content = 'Welcome to our website.';
  11. $oldtitle = 'Welcome';
  12. $oldcontent = 'Welcome to our website.';
  13. }
  14. } elseif ($type == 'is_profile') {
  15. if (isset($_SESSION[site_url()]['user'])) {
  16. $user = $_SESSION[site_url()]['user'];
  17. }
  18. $filename = 'content/' . $user . '/author.md';
  19. if (file_exists($filename)) {
  20. $content = file_get_contents($filename);
  21. $oldtitle = get_content_tag('t', $content, 'user');
  22. $olddescription = get_content_tag('d', $content, remove_html_comments($content));
  23. $oldcontent = remove_html_comments($content);
  24. $oldimage = get_content_tag('image', $content);
  25. } else {
  26. $content = i18n('Author_Description');
  27. $oldtitle = $user;
  28. $olddescription = i18n('Author_Description');
  29. $oldcontent = i18n('Author_Description');
  30. $oldimage = '';
  31. }
  32. } elseif ($type == 'is_category') {
  33. $url = 'content/data/category/'. $p->slug . '.md';
  34. if (file_exists($url)) {
  35. $content = file_get_contents($url);
  36. $oldtitle = get_content_tag('t', $content, $p->slug);
  37. $olddescription = get_content_tag('d', $content, remove_html_comments($content));
  38. $oldcontent = remove_html_comments($content);
  39. $oldmd = $p->slug;
  40. } else {
  41. $content = $p->body;
  42. $oldtitle = $p->title;
  43. $olddescription = $p->description;
  44. $oldcontent = $p->body;
  45. $oldmd = $p->slug;
  46. }
  47. } else {
  48. if (isset($p->file)) {
  49. $url = $p->file;
  50. } else {
  51. $url = $oldfile;
  52. }
  53. $content = file_get_contents($url);
  54. $oldtitle = get_content_tag('t', $content, 'Untitled');
  55. $olddescription = get_content_tag('d', $content);
  56. $oldcontent = remove_html_comments($content);
  57. if (isset($_GET['destination'])) {
  58. $destination = _h($_GET['destination']);
  59. } else {
  60. $destination = 'admin';
  61. }
  62. $dir = pathinfo($url, PATHINFO_DIRNAME);
  63. $oldurl = pathinfo($url, PATHINFO_BASENAME);
  64. $fn = explode('.', pathinfo($url, PATHINFO_FILENAME));
  65. if (isset($fn[1])) {
  66. $oldmd = $fn[1];
  67. } else {
  68. $oldmd = pathinfo($url, PATHINFO_FILENAME);
  69. }
  70. if (isset($p->url)) {
  71. $delete = $p->url . '/delete?destination=' . $destination;
  72. }
  73. else {
  74. if(empty($sub)) {
  75. $delete = site_url() . $oldmd . '/delete?destination=' . $destination;
  76. }
  77. else {
  78. $delete = site_url() . $static .'/'. $sub . '/delete?destination=' . $destination;
  79. }
  80. }
  81. }
  82. $images = image_gallery(null, 1, 40);
  83. $fields = array();
  84. if ($type == 'is_page' || $type == 'is_frontpage') {
  85. $field_file = 'content/data/field/page.json';
  86. if (file_exists($field_file)) {
  87. $fields = json_decode(file_get_contents($field_file, true));
  88. }
  89. } elseif ($type == 'is_subpage') {
  90. $field_file = 'content/data/field/subpage.json';
  91. if (file_exists($field_file)) {
  92. $fields = json_decode(file_get_contents($field_file, true));
  93. }
  94. } elseif ($type == 'is_profile') {
  95. $field_file = 'content/data/field/profile.json';
  96. if (file_exists($field_file)) {
  97. $fields = json_decode(file_get_contents($field_file, true));
  98. }
  99. }
  100. ?>
  101. <link rel="stylesheet" type="text/css" href="<?php echo site_url() ?>system/admin/editor/css/editor.css"/>
  102. <script src="<?php echo site_url() ?>system/resources/js/jquery.min.js"></script>
  103. <script src="<?php echo site_url() ?>system/resources/js/jquery-ui.min.js"></script>
  104. <script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Converter.js"></script>
  105. <script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Sanitizer.js"></script>
  106. <script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Editor.js"></script>
  107. <script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Extra.js"></script>
  108. <link rel="stylesheet" href="<?php echo site_url() ?>system/resources/css/jquery-ui.css">
  109. <?php if (isset($error)) { ?>
  110. <div class="error-message"><?php echo $error ?></div>
  111. <?php } ?>
  112. <div class="notice error" id="response-error"></div>
  113. <div class="notice" id="response"></div>
  114. <div class="row">
  115. <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>
  116. <div class="wmd-panel" style="width:100%;">
  117. <form method="POST">
  118. <div id="post-settings" class="row">
  119. <div class="col-sm-6">
  120. <label for="pTitle"><?php echo i18n('Title');?> <span class="required">*</span></label>
  121. <input type="text" id="pTitle" name="title" class="form-control text <?php if (isset($postTitle)) { if (empty($postTitle)) { echo 'error'; } } ?>" value="<?php echo $oldtitle ?>"/>
  122. <br>
  123. <?php if($type != 'is_frontpage') { ?>
  124. <label for="pMeta"><?php echo i18n('Meta_description');?> (<?php echo i18n('optional');?>)</label>
  125. <br />
  126. <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;} else {echo $olddescription;}?></textarea>
  127. <br /><br />
  128. <?php } ?>
  129. </div>
  130. <div class="col-sm-6">
  131. <?php if($type != 'is_frontpage' && $type != 'is_profile') { ?>
  132. <label for="pURL"><?php echo i18n('Slug');?> (<?php echo i18n('optional');?>)</label>
  133. <br>
  134. <input type="text" id="pURL" name="url" class="form-control text" value="<?php echo $oldmd ?>" placeholder="<?php echo i18n('If_the_url_is_left_empty_we_will_use_the_page_title');?>"/>
  135. <br>
  136. <?php } ?>
  137. <?php if ($type == 'is_profile'):?>
  138. <style>.imgPrev img {width:50%;} </style>
  139. <label for="pImage">Avatar (<?php echo i18n('optional');?>)</label>
  140. <br>
  141. <label class="btn btn-primary btn-sm" id="insertButton"><?php echo i18n('Insert_Image');?></label>
  142. <br>
  143. <div class="imgPrev"><img id="imgFile" src="<?php echo $oldimage; ?>"/></div>
  144. <br>
  145. <input type="text" class="media-uploader form-control text <?php if (isset($postImage)) { if (empty($postImage)) { echo 'error';}} ?>" id="pImage" name="image" readonly value="<?php echo $oldimage; ?>">
  146. <input type="hidden" name="is_image" value="is_image">
  147. <br>
  148. <?php endif;?>
  149. </div>
  150. </div>
  151. <div class="row">
  152. <div class="col-sm-12" style="text-align:right;">
  153. <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>
  154. </div>
  155. </div>
  156. <div class="row">
  157. <div class="col-sm-6" id="editor-col">
  158. <div>
  159. <label for="wmd-input"><?php echo i18n('Content');?> <span class="required">*</span></label>
  160. <div id="wmd-button-bar" class="wmd-button-bar"></div>
  161. <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 echo $oldcontent ?></textarea>
  162. <br>
  163. <?php if(!empty($fields) && $type != 'is_category'):?>
  164. <details id="custom-fields" >
  165. <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>
  166. <div class="row">
  167. <div class="col">
  168. <?php foreach ($fields as $fld):?>
  169. <?php if ($fld->type == 'text'):?>
  170. <label><?php echo $fld->label;?></label>
  171. <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="<?php echo get_field($fld->name, $content);?>"/>
  172. <br>
  173. <?php elseif ($fld->type == 'textarea'):?>
  174. <label><?php echo $fld->label;?></label>
  175. <textarea class="form-control text" id="<?php echo $fld->name;?>" rows="3" placeholder="<?php echo $fld->info;?>" name="<?php echo $fld->name;?>"><?php echo get_field($fld->name, $content);?></textarea>
  176. <br>
  177. <?php elseif ($fld->type == 'checkbox'):?>
  178. <input type="<?php echo $fld->type;?>" id="<?php echo $fld->name;?>" name="<?php echo $fld->name;?>" <?php echo get_field($fld->name, $content);?>>
  179. <label for="<?php echo $fld->name;?>"><?php echo $fld->label;?></label>
  180. <span class="d-block mt-1"><small><em><?php echo $fld->info;?></em></small></span>
  181. <br>
  182. <?php elseif ($fld->type == 'select'):?>
  183. <label for="<?php echo $fld->name;?>"><?php echo $fld->label;?></label>
  184. <select id="<?php echo $fld->name;?>" class="form-control" name="<?php echo $fld->name;?>">
  185. <?php foreach ($fld->options as $val):?>
  186. <option value="<?php echo $val;?>" <?php if (get_field($fld->name, $content) === $val) { echo 'selected="selected"';} ?>><?php echo $val;?></option>
  187. <?php endforeach;?>
  188. </select>
  189. <span class="d-block mt-1"><small><em><?php echo $fld->info;?></em></small></span>
  190. <br>
  191. <?php endif;?>
  192. <?php endforeach;?>
  193. </div>
  194. </div>
  195. </details>
  196. <br>
  197. <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>
  198. <?php endif;?>
  199. <input type="hidden" id="pType" name="posttype" value="<?php echo $type; ?>">
  200. <input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">
  201. <?php if($type == 'is_frontpage' || $type == 'is_profile') { ?>
  202. <input type="submit" name="submit" class="btn btn-primary submit" value="<?php echo i18n('Save');?>"/>
  203. <?php } elseif ($type == 'is_category') {?>
  204. <input id="oldfile" type="hidden" name="oldfile" class="text" value="<?php echo $url ?>"/>
  205. <input type="submit" name="submit" class="btn btn-primary submit" value="<?php echo i18n('Save_category');?>"/>
  206. <?php } else {?>
  207. <input id="oldfile" type="hidden" name="oldfile" class="text" value="<?php echo $url ?>"/>
  208. <?php $dd = find_subpage($oldmd); ?>
  209. <?php $dr = find_draft_subpage($oldmd);?>
  210. <?php if (stripos($dir . '/', '/draft/') !== false) { ?>
  211. <input type="submit" name="publishdraft" class="btn btn-primary submit" value="<?php echo i18n('Publish_draft');?>"/> <input type="submit" name="updatedraft" class="btn btn-primary draft" value="<?php echo i18n('Update_draft');?>"/> <?php if (empty($dd) && empty($dr)):?><a class="btn btn-danger" href="<?php echo $delete ?>"><?php echo i18n('Delete');?></a><?php endif;?>
  212. <?php } else { ?>
  213. <input type="submit" name="submit" class="btn btn-primary submit" value="<?php echo i18n('Save');?>"/> <?php if (empty($dd) && empty($dr)):?><input type="submit" name="revertpage" class="btn btn-primary revert" value="<?php echo i18n('Revert_to_draft');?>"/> <a class="btn btn-danger" href="<?php echo $delete ?>"><?php echo i18n('Delete');?></a><?php endif;?>
  214. <?php } ?>
  215. <?php } ?>
  216. </div>
  217. </div>
  218. <div class="col-sm-6" id="preview-col">
  219. <label><?php echo i18n('Preview');?></label>
  220. <br>
  221. <div id="wmd-preview" class="wmd-panel wmd-preview <?php if (config('admin.theme') === 'dark'){echo "card";}?>" style="width:100%;overflow:auto;"></div>
  222. </div>
  223. </div>
  224. </form>
  225. </div>
  226. <style>
  227. .wmd-prompt-background {z-index:10!important;}
  228. #wmd-preview img {max-width:100%;}
  229. </style>
  230. <div class="modal fade" id="insertImageDialog" tabindex="-1" role="dialog" aria-labelledby="insertImageDialogTitle" aria-hidden="true">
  231. <div class="modal-dialog modal-xl" role="document">
  232. <div class="modal-content">
  233. <div class="modal-header">
  234. <p class="modal-title" id="insertImageDialogTitle"><?php echo i18n('Insert_Image');?></p>
  235. <button type="button" class="close" id="insertImageDialogClose" data-dismiss="modal" aria-label="Close">
  236. <span aria-hidden="true">&times;</span>
  237. </button>
  238. </div>
  239. <div class="modal-body">
  240. <div class="row">
  241. <div class="col-9">
  242. <div class="form-group">
  243. <div class="row-fluid img-container" id="gallery-1">
  244. <?php echo $images;?>
  245. </div>
  246. </div>
  247. </div>
  248. <div class="col">
  249. <div class="form-group">
  250. <label for="insertImageDialogURL">URL</label>
  251. <textarea class="form-control" id="insertImageDialogURL" rows="5" placeholder="<?php echo i18n('Enter_image_URL');?>" ></textarea>
  252. </div>
  253. <hr>
  254. <div class="form-group">
  255. <label for="insertImageDialogFile"><?php echo i18n('Upload');?></label>
  256. <input type="file" class="form-control-file" name="file" id="insertImageDialogFile" accept="image/png,image/jpeg,image/gif, image/webp" style="display:none;" />
  257. <button id="dropZoneIIDF" class="vs-dropzone" type="button">Drag &amp; Drop image here, or click to browse</button>
  258. </div>
  259. <hr>
  260. <div class="form-group">
  261. <button type="button" class="btn btn-primary" id="insertImageDialogInsert"><?php echo i18n('Insert_Image');?></button>
  262. <button type="button" class="btn btn-secondary" id="insertImageDialogCancel" data-dismiss="modal"><?php echo i18n('Cancel');?></button>
  263. </div>
  264. </div>
  265. </div>
  266. </div>
  267. </div>
  268. </div>
  269. </div>
  270. <?php if ($type == 'is_profile'):?>
  271. <div class="modal fade" id="insertMediaDialog" tabindex="-1" role="dialog" aria-labelledby="insertMediaDialogTitle" aria-hidden="true">
  272. <div class="modal-dialog modal-xl" role="document">
  273. <div class="modal-content">
  274. <div class="modal-header">
  275. <p class="modal-title" id="insertMediaDialogTitle"><?php echo i18n('Insert_Image');?></p>
  276. <button type="button" class="close" id="insertMediaDialogClose" data-dismiss="modal" aria-label="Close">
  277. <span aria-hidden="true">&times;</span>
  278. </button>
  279. </div>
  280. <div class="modal-body">
  281. <div class="row">
  282. <div class="col-9">
  283. <div class="form-group">
  284. <div class="row-fluid img-container" id="gallery-2">
  285. <?php echo $images;?>
  286. </div>
  287. </div>
  288. </div>
  289. <div class="col">
  290. <div class="form-group">
  291. <label for="insertMediaDialogURL">URL</label>
  292. <textarea class="form-control" id="insertMediaDialogURL" rows="5" placeholder="<?php echo i18n('Enter_image_URL');?>"></textarea>
  293. </div>
  294. <hr>
  295. <div class="form-group">
  296. <label for="insertMediaDialogFile"><?php echo i18n('Upload');?></label>
  297. <input type="file" class="form-control-file" name="file" id="insertMediaDialogFile" accept="image/png,image/jpeg,image/gif, image/webp" style="display:none;" />
  298. <button id="dropZoneIMDF" class="vs-dropzone" type="button">Drag &amp; Drop image here, or click to browse</button>
  299. </div>
  300. <hr>
  301. <div class="form-group">
  302. <button type="button" class="btn btn-primary" id="insertMediaDialogInsert"><?php echo i18n('Insert_Image');?></button>
  303. <button type="button" class="btn btn-secondary" id="insertMediaDialogCancel" data-dismiss="modal"><?php echo i18n('Cancel');?></button>
  304. </div>
  305. </div>
  306. </div>
  307. </div>
  308. </div>
  309. </div>
  310. </div>
  311. <?php endif;?>
  312. </div>
  313. <!-- Declare the base path. Important -->
  314. <script type="text/javascript">
  315. var base_path = '<?php echo site_url() ?>';
  316. var initial_image = <?php echo json_encode($images); ?>;
  317. var parent_page = '<?php echo isset($parent) ? $parent : '';?>';
  318. var addEdit = 'edit';
  319. var saveInterval = 60000;
  320. const field = [<?php foreach ($fields as $f){ echo '"' . $f->name . '", ';}?>];
  321. </script>
  322. <script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/editor.js"></script>
  323. <?php if ($type == 'is_profile'):?>
  324. <script type="text/javascript" src="<?php echo site_url() ?>system/resources/js/media.uploader.js"></script>
  325. <?php endif;?>
  326. <script>
  327. function loadImages(page) {
  328. $.ajax({
  329. url: '<?php echo site_url();?>admin/gallery',
  330. type: 'POST',
  331. data: { page: page },
  332. dataType: 'json',
  333. success: function(response) {
  334. $('#gallery-1').html(response.images);
  335. $('#gallery-2').html(response.images);
  336. }
  337. });
  338. }
  339. $('.img-container').on("click", ".the-img", function(e) {
  340. $('#insertMediaDialogURL').val($(e.target).attr('src'));
  341. $('#insertImageDialogURL').val($(e.target).attr('src'));
  342. });
  343. </script>
  344. <script>
  345. function toggleDivs() {
  346. var div1 = document.getElementById('post-settings');
  347. if (div1.style.display === 'none') {
  348. div1.style.display = '';
  349. document.body.classList.add("sidebar-mini");
  350. document.body.classList.remove("sidebar-collapse");
  351. } else {
  352. div1.style.display = 'none';
  353. document.body.classList.remove("sidebar-mini");
  354. document.body.classList.add("sidebar-collapse");
  355. }
  356. }
  357. document.getElementById('hideButton').addEventListener('click', toggleDivs);
  358. </script>
  359. <?php if (config('autosave.enable') == 'true'):?>
  360. <?php if ($type !== 'is_category' && $type !== 'is_profile' && $type !== 'is_frontpage') :?>
  361. <?php if (stripos($dir . '/', '/draft/') !== false): ?>
  362. <script src="<?php echo site_url();?>system/resources/js/save_draft.js?v=1"></script>
  363. <?php endif;?>
  364. <?php endif;?>
  365. <?php endif;?>
  366. <script>
  367. if (localStorage.getItem("preview-state") === "open") {
  368. document.getElementById("editor-col").classList.remove('col-sm-12');
  369. document.getElementById("editor-col").classList.add('col-sm-6');
  370. document.getElementById("preview-col").style.display = '';
  371. } else if (localStorage.getItem("preview-state") === "close") {
  372. document.getElementById("editor-col").classList.remove('col-sm-6');
  373. document.getElementById("editor-col").classList.add('col-sm-12');
  374. document.getElementById("preview-col").style.display = 'none';
  375. }
  376. document.getElementById("preview-toggle").addEventListener("click", () => {
  377. if (document.getElementById("editor-col").className.includes("col-sm-6")) {
  378. document.getElementById("editor-col").classList.remove('col-sm-6');
  379. document.getElementById("editor-col").classList.add('col-sm-12');
  380. document.getElementById("preview-col").style.display = 'none';
  381. localStorage.setItem("preview-state", 'close');
  382. } else {
  383. document.getElementById("editor-col").classList.remove('col-sm-12');
  384. document.getElementById("editor-col").classList.add('col-sm-6');
  385. document.getElementById("preview-col").style.display = '';
  386. localStorage.setItem("preview-state", 'open');
  387. }
  388. })
  389. </script>