add-content.html.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. <?php if (!defined('HTMLY')) die('HTMLy'); ?>
  2. <?php
  3. $type = $type;
  4. if ($type != 'is_post' && $type != 'is_image' && $type != 'is_video' && $type != 'is_audio' && $type != 'is_link' && $type != 'is_quote') {
  5. $add = site_url() . 'admin/content';
  6. header("location: $add");
  7. }
  8. $desc = get_category_info(null);
  9. $tags = tag_cloud(true);
  10. $tagslang = "content/data/tags.lang";
  11. if (file_exists($tagslang)) {
  12. $ptags = unserialize(file_get_contents($tagslang));
  13. $tkey = array_keys($tags);
  14. if (!empty($ptags)) {
  15. $newlang = array_intersect_key($ptags, array_flip($tkey));
  16. } else {
  17. $newlang = array_combine($tkey, $tkey);
  18. }
  19. $tmp = serialize($newlang);
  20. file_put_contents($tagslang, print_r($tmp, true), LOCK_EX);
  21. }
  22. $images = image_gallery(null, 1, 40);
  23. $fields = array();
  24. $field_file= 'content/data/field/post.json';
  25. if (file_exists($field_file)) {
  26. $fields = json_decode(file_get_contents($field_file, true));
  27. }
  28. ?>
  29. <link rel="stylesheet" type="text/css" href="<?php echo site_url() ?>system/admin/editor/css/editor.css"/>
  30. <script src="<?php echo site_url() ?>system/resources/js/jquery-ui.min.js"></script>
  31. <script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Converter.js"></script>
  32. <script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Sanitizer.js"></script>
  33. <script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Editor.js"></script>
  34. <script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Extra.js"></script>
  35. <link rel="stylesheet" href="<?php echo site_url() ?>system/resources/css/jquery-ui.css">
  36. <script>
  37. $( function() {
  38. // Decode HTML entities
  39. function decodeHtml(html) {
  40. var txt = document.createElement("textarea");
  41. txt.innerHTML = html;
  42. return txt.value;
  43. }
  44. var availableTags = [
  45. <?php foreach ($tags as $tag => $count):?>
  46. "<?php echo tag_i18n($tag) ?>",
  47. <?php endforeach;?>
  48. ].map(decodeHtml); // Decoding all tags
  49. function split( val ) {
  50. return val.split( /,\s*/ );
  51. }
  52. function extractLast( term ) {
  53. return split( term ).pop();
  54. }
  55. $( "#pTag" )
  56. // don't navigate away from the field on tab when selecting an item
  57. .on( "keydown", function( event ) {
  58. if ( event.keyCode === 9 && // 9 = tab
  59. $( this ).autocomplete( "instance" ).menu.active ) {
  60. event.preventDefault();
  61. }
  62. })
  63. .autocomplete({
  64. minLength: 0,
  65. source: function( request, response ) {
  66. // delegate back to autocomplete, but extract the last term
  67. response( $.ui.autocomplete.filter(
  68. availableTags, extractLast( request.term ) ) );
  69. },
  70. focus: function() {
  71. // prevent value inserted on focus
  72. return false;
  73. },
  74. select: function( event, ui ) {
  75. var terms = split( this.value );
  76. // remove the current input
  77. terms.pop();
  78. // add the selected item
  79. terms.push( ui.item.value );
  80. // add placeholder to get the comma-and-space at the end
  81. terms.push( "" );
  82. this.value = terms.join( ", " );
  83. return false;
  84. }
  85. });
  86. } );
  87. </script>
  88. <?php if (isset($error)) { ?>
  89. <div class="error-message"><?php echo $error ?></div>
  90. <?php } ?>
  91. <div class="notice error" id="response-error"></div>
  92. <div class="notice" id="response"></div>
  93. <div class="row">
  94. <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>
  95. <div class="wmd-panel" style="width:100%;">
  96. <form method="POST">
  97. <div id="post-settings" class="row">
  98. <div class="col-sm-6">
  99. <label for="pTitle"><?php echo i18n('Title');?> <span class="required">*</span></label>
  100. <input autofocus 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;} ?>"/>
  101. <br>
  102. <label for="pCategory"><?php echo i18n('Category');?> <span class="required">*</span></label>
  103. <select id="pCategory" class="form-control" name="category">
  104. <?php foreach ($desc as $d):?>
  105. <option value="<?php echo $d->slug;?>"><?php echo $d->title;?></option>
  106. <?php endforeach;?>
  107. </select>
  108. <br>
  109. <label for="pTag"><?php echo i18n('Tags');?> <span class="required">*</span></label>
  110. <input type="text" class="form-control text <?php if (isset($postTag)) { if (empty($postTag)) { echo 'error';}} ?>" id="pTag" name="tag" value="<?php if (isset($postTag)) { echo $postTag; } ?>" placeholder="<?php echo i18n('Comma_separated_values');?>"/>
  111. <br>
  112. <label for="pMeta"><?php echo i18n('Meta_description');?> (<?php echo i18n('optional');?>)</label>
  113. <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>
  114. <br>
  115. </div>
  116. <div class="col-sm-6">
  117. <div class="form-row">
  118. <div class="col">
  119. <label for="pDate"><?php echo i18n('Date');?></label>
  120. <input type="date" id="pDate" name="date" class="form-control text" value="<?php echo date('Y-m-d'); ?>">
  121. </div>
  122. <div class="col">
  123. <label for="pTime"><?php echo i18n('Time');?></label>
  124. <input step="1" type="time" id="pTime" name="time" class="form-control text" value="<?php echo date('H:i:s'); ?>">
  125. </div>
  126. <small style="margin-top:10px;"><em><?php echo i18n('Scheduled_tips');?></em></small>
  127. </div>
  128. <br>
  129. <label for="pURL"><?php echo i18n('Slug');?> (<?php echo i18n('optional');?>)</label>
  130. <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_post_title');?>"/>
  131. <br>
  132. <?php if ($type == 'is_audio'):?>
  133. <label for="pAudio"><?php echo i18n('Featured_Audio');?> <span class="required">*</span> (e.g Soundcloud)</label>
  134. <textarea rows="2" cols="20" class="media-uploader form-control text <?php if (isset($postAudio)) { if (empty($postAudio)) { echo 'error';} } ?>" id="pAudio" name="audio"><?php if (isset($postAudio)) { echo $postAudio;} ?></textarea>
  135. <input type="hidden" name="is_audio" value="is_audio">
  136. <br>
  137. <?php endif;?>
  138. <?php if ($type == 'is_video'):?>
  139. <label for="pVideo"><?php echo i18n('Featured_Video');?> <span class="required">*</span> (e.g Youtube)</label>
  140. <textarea rows="2" cols="20" class="media-uploader form-control text <?php if (isset($postVideo)) { if (empty($postVideo)) { echo 'error';} } ?>" id="pVideo" name="video"><?php if (isset($postVideo)) { echo $postVideo;} ?></textarea>
  141. <input type="hidden" name="is_video" value="is_video">
  142. <br>
  143. <?php endif;?>
  144. <?php if ($type == 'is_image'):?>
  145. <style>.imgPrev img {width:50%;} </style>
  146. <label for="pImage"><?php echo i18n('Featured_Image');?> <span class="required">*</span></label>
  147. <br>
  148. <label class="btn btn-primary btn-sm" id="insertButton"><?php echo i18n('Insert_Image');?></label>
  149. <br>
  150. <div class="imgPrev"><?php if (isset($postImage)) { echo '<img id="imgFile" src="' . $postImage . '"/>';} ?></div>
  151. <br>
  152. <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 if (isset($postImage)) { echo $postImage;} ?>">
  153. <input type="hidden" name="is_image" value="is_image">
  154. <br>
  155. <?php endif;?>
  156. <?php if ($type == 'is_quote'):?>
  157. <label for="pQuote"><?php echo i18n('Featured_Quote');?> <span class="required">*</span></label>
  158. <textarea rows="3" cols="20" class="form-control text <?php if (isset($postQuote)) { if (empty($postQuote)) { echo 'error';} } ?>" id="pQuote" name="quote"><?php if (isset($postQuote)) { echo $postQuote;} ?></textarea>
  159. <input type="hidden" name="is_quote" value="is_quote">
  160. <br>
  161. <?php endif;?>
  162. <?php if ($type == 'is_link'):?>
  163. <label for="pLink"><?php echo i18n('Featured_Link');?> <span class="required">*</span></label>
  164. <textarea rows="2" cols="20" class="form-control text <?php if (isset($postLink)) { if (empty($postLink)) { echo 'error';} } ?>" id="pLink" name="link"><?php if (isset($postLink)) { echo $postLink;} ?></textarea>
  165. <input type="hidden" name="is_link" value="is_link">
  166. <br>
  167. <?php endif;?>
  168. <?php if ($type == 'is_post'):?>
  169. <input type="hidden" name="is_post" value="is_post">
  170. <?php endif;?>
  171. <input type="checkbox" id="pAI" name="ai" value="yes">
  172. <label for="pAI"><?php echo i18n('AI_assisted');?></label>
  173. <span class="d-block mt-1"><small><em><?php echo i18n('AI_assisted_info');?></em></small></span>
  174. <br>
  175. <input id="oldfile" type="hidden" name="oldfile" class="text"/>
  176. <input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">
  177. </div>
  178. </div>
  179. <div class="row">
  180. <div class="col-sm-12" style="text-align:right;">
  181. <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>
  182. </div>
  183. </div>
  184. <div class="row">
  185. <div class="col-sm-6" id="editor-col">
  186. <div>
  187. <input type="hidden" id="pType" name="posttype" value="<?php echo $type; ?>">
  188. <label for="wmd-input"><?php echo i18n('Content');?> <span class="required">*</span></label>
  189. <div id="wmd-button-bar" class="wmd-button-bar"></div>
  190. <textarea id="wmd-input" class="form-control wmd-input <?php if (isset($postContent)) { if (empty($postContent)) { echo 'error'; } } ?>" name="content" cols="20" rows="15"><?php if (isset($postContent)) { echo $postContent;} ?></textarea><br>
  191. <?php if(!empty($fields)):?>
  192. <details id="custom-fields" >
  193. <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>
  194. <div class="row">
  195. <div class="col">
  196. <?php foreach ($fields as $fld):?>
  197. <?php if ($fld->type == 'text'):?>
  198. <label><?php echo $fld->label;?></label>
  199. <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=""/>
  200. <br>
  201. <?php elseif ($fld->type == 'textarea'):?>
  202. <label><?php echo $fld->label;?></label>
  203. <textarea class="form-control text" id="<?php echo $fld->name;?>" rows="3" placeholder="<?php echo $fld->info;?>" name="<?php echo $fld->name;?>"></textarea>
  204. <br>
  205. <?php elseif ($fld->type == 'checkbox'):?>
  206. <input type="<?php echo $fld->type;?>" id="<?php echo $fld->name;?>" name="<?php echo $fld->name;?>" >
  207. <label for="<?php echo $fld->name;?>"><?php echo $fld->label;?></label>
  208. <span class="d-block mt-1"><small><em><?php echo $fld->info;?></em></small></span>
  209. <br>
  210. <?php elseif ($fld->type == 'select'):?>
  211. <label for="<?php echo $fld->name;?>"><?php echo $fld->label;?></label>
  212. <select id="<?php echo $fld->name;?>" class="form-control" name="<?php echo $fld->name;?>">
  213. <?php foreach ($fld->options as $val):?>
  214. <option value="<?php echo $val;?>" ><?php echo $val;?></option>
  215. <?php endforeach;?>
  216. </select>
  217. <span class="d-block mt-1"><small><em><?php echo $fld->info;?></em></small></span>
  218. <br>
  219. <?php endif;?>
  220. <?php endforeach;?>
  221. </div>
  222. </div>
  223. </details>
  224. <br>
  225. <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>
  226. <?php endif;?>
  227. <input type="submit" name="publish" 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');?>"/>
  228. <br>
  229. </div>
  230. </div>
  231. <div class="col-sm-6" id="preview-col">
  232. <label><?php echo i18n('Preview');?></label>
  233. <br>
  234. <div id="wmd-preview" class="wmd-panel wmd-preview <?php if (config('admin.theme') === 'dark'){echo "card";}?>" style="width:100%;overflow:auto;"></div>
  235. </div>
  236. </div>
  237. </form>
  238. </div>
  239. <style>
  240. .wmd-prompt-background {z-index:10!important;}
  241. #wmd-preview img {max-width:100%;}
  242. </style>
  243. <div class="modal fade" id="insertImageDialog" tabindex="-1" role="dialog" aria-labelledby="insertImageDialogTitle" aria-hidden="true">
  244. <div class="modal-dialog modal-xl" role="document">
  245. <div class="modal-content">
  246. <div class="modal-header">
  247. <p class="modal-title" id="insertImageDialogTitle"><?php echo i18n('Insert_Image');?></p>
  248. <button type="button" class="close" id="insertImageDialogClose" data-dismiss="modal" aria-label="Close">
  249. <span aria-hidden="true">&times;</span>
  250. </button>
  251. </div>
  252. <div class="modal-body">
  253. <div class="row">
  254. <div class="col-9">
  255. <div class="form-group">
  256. <div class="row-fluid img-container" id="gallery-1">
  257. <?php echo $images;?>
  258. </div>
  259. </div>
  260. </div>
  261. <div class="col">
  262. <div class="form-group">
  263. <label for="insertImageDialogURL">URL</label>
  264. <textarea class="form-control" id="insertImageDialogURL" rows="5" placeholder="<?php echo i18n('Enter_image_URL');?>" ></textarea>
  265. </div>
  266. <hr>
  267. <div class="form-group">
  268. <label for="insertImageDialogFile"><?php echo i18n('Upload');?></label>
  269. <input type="file" class="form-control-file" name="file" id="insertImageDialogFile" accept="image/png,image/jpeg,image/gif, image/webp" style="display:none;" />
  270. <button id="dropZoneIIDF" class="vs-dropzone" type="button">Drag &amp; Drop image here, or click to browse</button>
  271. </div>
  272. <hr>
  273. <div class="form-group">
  274. <button type="button" class="btn btn-primary" id="insertImageDialogInsert"><?php echo i18n('Insert_Image');?></button>
  275. <button type="button" class="btn btn-secondary" id="insertImageDialogCancel" data-dismiss="modal"><?php echo i18n('Cancel');?></button>
  276. </div>
  277. </div>
  278. </div>
  279. </div>
  280. </div>
  281. </div>
  282. </div>
  283. <?php if ($type == 'is_image'):?>
  284. <div class="modal fade" id="insertMediaDialog" tabindex="-1" role="dialog" aria-labelledby="insertMediaDialogTitle" aria-hidden="true">
  285. <div class="modal-dialog modal-xl" role="document">
  286. <div class="modal-content">
  287. <div class="modal-header">
  288. <p class="modal-title" id="insertMediaDialogTitle"><?php echo i18n('Insert_Image');?></p>
  289. <button type="button" class="close" id="insertMediaDialogClose" data-dismiss="modal" aria-label="Close">
  290. <span aria-hidden="true">&times;</span>
  291. </button>
  292. </div>
  293. <div class="modal-body">
  294. <div class="row">
  295. <div class="col-9">
  296. <div class="form-group">
  297. <div class="row-fluid img-container" id="gallery-2">
  298. <?php echo $images;?>
  299. </div>
  300. </div>
  301. </div>
  302. <div class="col">
  303. <div class="form-group">
  304. <label for="insertMediaDialogURL">URL</label>
  305. <textarea class="form-control" id="insertMediaDialogURL" rows="5" placeholder="<?php echo i18n('Enter_image_URL');?>"></textarea>
  306. </div>
  307. <hr>
  308. <div class="form-group">
  309. <label for="insertMediaDialogFile"><?php echo i18n('Upload');?></label>
  310. <input type="file" class="form-control-file" name="file" id="insertMediaDialogFile" accept="image/png,image/jpeg,image/gif, image/webp" style="display:none;" />
  311. <button id="dropZoneIMDF" class="vs-dropzone" type="button">Drag &amp; Drop image here, or click to browse</button>
  312. </div>
  313. <hr>
  314. <div class="form-group">
  315. <button type="button" class="btn btn-primary" id="insertMediaDialogInsert"><?php echo i18n('Insert_Image');?></button>
  316. <button type="button" class="btn btn-secondary" id="insertMediaDialogCancel" data-dismiss="modal"><?php echo i18n('Cancel');?></button>
  317. </div>
  318. </div>
  319. </div>
  320. </div>
  321. </div>
  322. </div>
  323. </div>
  324. <?php endif;?>
  325. </div>
  326. <!-- Declare the base path. Important -->
  327. <script type="text/javascript">
  328. var base_path = '<?php echo site_url() ?>';
  329. var initial_image = <?php echo json_encode($images); ?>;
  330. var parent_page = '';
  331. var addEdit = 'add';
  332. var saveInterval = 60000;
  333. const field = [<?php foreach ($fields as $f){ echo '"' . $f->name . '", ';}?>];
  334. </script>
  335. <script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/editor.js"></script>
  336. <script type="text/javascript" src="<?php echo site_url() ?>system/resources/js/media.uploader.js"></script>
  337. <script>
  338. function loadImages(page) {
  339. $.ajax({
  340. url: '<?php echo site_url();?>admin/gallery',
  341. type: 'POST',
  342. data: { page: page },
  343. dataType: 'json',
  344. success: function(response) {
  345. $('#gallery-1').html(response.images);
  346. $('#gallery-2').html(response.images);
  347. }
  348. });
  349. }
  350. $('.img-container').on("click", ".the-img", function(e) {
  351. $('#insertMediaDialogURL').val($(e.target).attr('src'));
  352. $('#insertImageDialogURL').val($(e.target).attr('src'));
  353. });
  354. </script>
  355. <script>
  356. function toggleDivs() {
  357. var div1 = document.getElementById('post-settings');
  358. if (div1.style.display === 'none') {
  359. div1.style.display = '';
  360. document.body.classList.add("sidebar-mini");
  361. document.body.classList.remove("sidebar-collapse");
  362. } else {
  363. div1.style.display = 'none';
  364. document.body.classList.remove("sidebar-mini");
  365. document.body.classList.add("sidebar-collapse");
  366. }
  367. }
  368. document.getElementById('hideButton').addEventListener('click', toggleDivs);
  369. </script>
  370. <?php if (config('autosave.enable') == 'true' ):?>
  371. <script src="<?php echo site_url();?>system/resources/js/save_draft.js?v=1"></script>
  372. <?php endif;?>
  373. <script>
  374. if (localStorage.getItem("preview-state") === "open") {
  375. document.getElementById("editor-col").classList.remove('col-sm-12');
  376. document.getElementById("editor-col").classList.add('col-sm-6');
  377. document.getElementById("preview-col").style.display = '';
  378. } else if (localStorage.getItem("preview-state") === "close") {
  379. document.getElementById("editor-col").classList.remove('col-sm-6');
  380. document.getElementById("editor-col").classList.add('col-sm-12');
  381. document.getElementById("preview-col").style.display = 'none';
  382. }
  383. document.getElementById("preview-toggle").addEventListener("click", () => {
  384. if (document.getElementById("editor-col").className.includes("col-sm-6")) {
  385. document.getElementById("editor-col").classList.remove('col-sm-6');
  386. document.getElementById("editor-col").classList.add('col-sm-12');
  387. document.getElementById("preview-col").style.display = 'none';
  388. localStorage.setItem("preview-state", 'close');
  389. } else {
  390. document.getElementById("editor-col").classList.remove('col-sm-12');
  391. document.getElementById("editor-col").classList.add('col-sm-6');
  392. document.getElementById("preview-col").style.display = '';
  393. localStorage.setItem("preview-state", 'open');
  394. }
  395. })
  396. </script>