add-content.html.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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 id="oldfile" type="hidden" name="oldfile" class="text"/>
  172. <input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">
  173. </div>
  174. </div>
  175. <div class="row">
  176. <div class="col-sm-12" style="text-align:right;">
  177. <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>
  178. </div>
  179. </div>
  180. <div class="row">
  181. <div class="col-sm-6" id="editor-col">
  182. <div>
  183. <input type="hidden" id="pType" name="posttype" value="<?php echo $type; ?>">
  184. <label for="wmd-input"><?php echo i18n('Content');?> <span class="required">*</span></label>
  185. <div id="wmd-button-bar" class="wmd-button-bar"></div>
  186. <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>
  187. <?php if(!empty($fields)):?>
  188. <details id="custom-fields" >
  189. <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>
  190. <div class="row">
  191. <div class="col">
  192. <?php foreach ($fields as $fld):?>
  193. <?php if ($fld->type == 'text'):?>
  194. <label><?php echo $fld->label;?></label>
  195. <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=""/>
  196. <br>
  197. <?php elseif ($fld->type == 'textarea'):?>
  198. <label><?php echo $fld->label;?></label>
  199. <textarea class="form-control text" id="<?php echo $fld->name;?>" rows="3" placeholder="<?php echo $fld->info;?>" name="<?php echo $fld->name;?>"></textarea>
  200. <br>
  201. <?php elseif ($fld->type == 'checkbox'):?>
  202. <input type="<?php echo $fld->type;?>" id="<?php echo $fld->name;?>" name="<?php echo $fld->name;?>" >
  203. <label for="<?php echo $fld->name;?>"><?php echo $fld->label;?></label>
  204. <span class="d-block mt-1"><small><em><?php echo $fld->info;?></em></small></span>
  205. <br>
  206. <?php elseif ($fld->type == 'select'):?>
  207. <label for="<?php echo $fld->name;?>"><?php echo $fld->label;?></label>
  208. <select id="<?php echo $fld->name;?>" class="form-control" name="<?php echo $fld->name;?>">
  209. <?php foreach ($fld->options as $val):?>
  210. <option value="<?php echo $val;?>" ><?php echo $val;?></option>
  211. <?php endforeach;?>
  212. </select>
  213. <span class="d-block mt-1"><small><em><?php echo $fld->info;?></em></small></span>
  214. <br>
  215. <?php endif;?>
  216. <?php endforeach;?>
  217. </div>
  218. </div>
  219. </details>
  220. <br>
  221. <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>
  222. <?php endif;?>
  223. <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');?>"/>
  224. <br>
  225. </div>
  226. </div>
  227. <div class="col-sm-6" id="preview-col">
  228. <label><?php echo i18n('Preview');?></label>
  229. <br>
  230. <div id="wmd-preview" class="wmd-panel wmd-preview <?php if (config('admin.theme') === 'dark'){echo "card";}?>" style="width:100%;overflow:auto;"></div>
  231. </div>
  232. </div>
  233. </form>
  234. </div>
  235. <style>
  236. .wmd-prompt-background {z-index:10!important;}
  237. #wmd-preview img {max-width:100%;}
  238. </style>
  239. <div class="modal fade" id="insertImageDialog" tabindex="-1" role="dialog" aria-labelledby="insertImageDialogTitle" aria-hidden="true">
  240. <div class="modal-dialog modal-xl" role="document">
  241. <div class="modal-content">
  242. <div class="modal-header">
  243. <p class="modal-title" id="insertImageDialogTitle"><?php echo i18n('Insert_Image');?></p>
  244. <button type="button" class="close" id="insertImageDialogClose" data-dismiss="modal" aria-label="Close">
  245. <span aria-hidden="true">&times;</span>
  246. </button>
  247. </div>
  248. <div class="modal-body">
  249. <div class="row">
  250. <div class="col-9">
  251. <div class="form-group">
  252. <div class="row-fluid img-container" id="gallery-1">
  253. <?php echo $images;?>
  254. </div>
  255. </div>
  256. </div>
  257. <div class="col">
  258. <div class="form-group">
  259. <label for="insertImageDialogURL">URL</label>
  260. <textarea class="form-control" id="insertImageDialogURL" rows="5" placeholder="<?php echo i18n('Enter_image_URL');?>" ></textarea>
  261. </div>
  262. <hr>
  263. <div class="form-group">
  264. <label for="insertImageDialogFile"><?php echo i18n('Upload');?></label>
  265. <input type="file" class="form-control-file" name="file" id="insertImageDialogFile" accept="image/png,image/jpeg,image/gif, image/webp" style="display:none;" />
  266. <button id="dropZoneIIDF" class="vs-dropzone" type="button">Drag &amp; Drop image here, or click to browse</button>
  267. </div>
  268. <hr>
  269. <div class="form-group">
  270. <button type="button" class="btn btn-primary" id="insertImageDialogInsert"><?php echo i18n('Insert_Image');?></button>
  271. <button type="button" class="btn btn-secondary" id="insertImageDialogCancel" data-dismiss="modal"><?php echo i18n('Cancel');?></button>
  272. </div>
  273. </div>
  274. </div>
  275. </div>
  276. </div>
  277. </div>
  278. </div>
  279. <?php if ($type == 'is_image'):?>
  280. <div class="modal fade" id="insertMediaDialog" tabindex="-1" role="dialog" aria-labelledby="insertMediaDialogTitle" aria-hidden="true">
  281. <div class="modal-dialog modal-xl" role="document">
  282. <div class="modal-content">
  283. <div class="modal-header">
  284. <p class="modal-title" id="insertMediaDialogTitle"><?php echo i18n('Insert_Image');?></p>
  285. <button type="button" class="close" id="insertMediaDialogClose" data-dismiss="modal" aria-label="Close">
  286. <span aria-hidden="true">&times;</span>
  287. </button>
  288. </div>
  289. <div class="modal-body">
  290. <div class="row">
  291. <div class="col-9">
  292. <div class="form-group">
  293. <div class="row-fluid img-container" id="gallery-2">
  294. <?php echo $images;?>
  295. </div>
  296. </div>
  297. </div>
  298. <div class="col">
  299. <div class="form-group">
  300. <label for="insertMediaDialogURL">URL</label>
  301. <textarea class="form-control" id="insertMediaDialogURL" rows="5" placeholder="<?php echo i18n('Enter_image_URL');?>"></textarea>
  302. </div>
  303. <hr>
  304. <div class="form-group">
  305. <label for="insertMediaDialogFile"><?php echo i18n('Upload');?></label>
  306. <input type="file" class="form-control-file" name="file" id="insertMediaDialogFile" accept="image/png,image/jpeg,image/gif, image/webp" style="display:none;" />
  307. <button id="dropZoneIMDF" class="vs-dropzone" type="button">Drag &amp; Drop image here, or click to browse</button>
  308. </div>
  309. <hr>
  310. <div class="form-group">
  311. <button type="button" class="btn btn-primary" id="insertMediaDialogInsert"><?php echo i18n('Insert_Image');?></button>
  312. <button type="button" class="btn btn-secondary" id="insertMediaDialogCancel" data-dismiss="modal"><?php echo i18n('Cancel');?></button>
  313. </div>
  314. </div>
  315. </div>
  316. </div>
  317. </div>
  318. </div>
  319. </div>
  320. <?php endif;?>
  321. </div>
  322. <!-- Declare the base path. Important -->
  323. <script type="text/javascript">
  324. var base_path = '<?php echo site_url() ?>';
  325. var initial_image = <?php echo json_encode($images); ?>;
  326. var parent_page = '';
  327. var addEdit = 'add';
  328. var saveInterval = 60000;
  329. const field = [<?php foreach ($fields as $f){ echo '"' . $f->name . '", ';}?>];
  330. </script>
  331. <script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/editor.js"></script>
  332. <script type="text/javascript" src="<?php echo site_url() ?>system/resources/js/media.uploader.js"></script>
  333. <script>
  334. function loadImages(page) {
  335. $.ajax({
  336. url: '<?php echo site_url();?>admin/gallery',
  337. type: 'POST',
  338. data: { page: page },
  339. dataType: 'json',
  340. success: function(response) {
  341. $('#gallery-1').html(response.images);
  342. $('#gallery-2').html(response.images);
  343. }
  344. });
  345. }
  346. $('.img-container').on("click", ".the-img", function(e) {
  347. $('#insertMediaDialogURL').val($(e.target).attr('src'));
  348. $('#insertImageDialogURL').val($(e.target).attr('src'));
  349. });
  350. </script>
  351. <script>
  352. function toggleDivs() {
  353. var div1 = document.getElementById('post-settings');
  354. if (div1.style.display === 'none') {
  355. div1.style.display = '';
  356. document.body.classList.add("sidebar-mini");
  357. document.body.classList.remove("sidebar-collapse");
  358. } else {
  359. div1.style.display = 'none';
  360. document.body.classList.remove("sidebar-mini");
  361. document.body.classList.add("sidebar-collapse");
  362. }
  363. }
  364. document.getElementById('hideButton').addEventListener('click', toggleDivs);
  365. </script>
  366. <?php if (config('autosave.enable') == 'true' ):?>
  367. <script src="<?php echo site_url();?>system/resources/js/save_draft.js?v=1"></script>
  368. <?php endif;?>
  369. <script>
  370. if (localStorage.getItem("preview-state") === "open") {
  371. document.getElementById("editor-col").classList.remove('col-sm-12');
  372. document.getElementById("editor-col").classList.add('col-sm-6');
  373. document.getElementById("preview-col").style.display = '';
  374. } else if (localStorage.getItem("preview-state") === "close") {
  375. document.getElementById("editor-col").classList.remove('col-sm-6');
  376. document.getElementById("editor-col").classList.add('col-sm-12');
  377. document.getElementById("preview-col").style.display = 'none';
  378. }
  379. document.getElementById("preview-toggle").addEventListener("click", () => {
  380. if (document.getElementById("editor-col").className.includes("col-sm-6")) {
  381. document.getElementById("editor-col").classList.remove('col-sm-6');
  382. document.getElementById("editor-col").classList.add('col-sm-12');
  383. document.getElementById("preview-col").style.display = 'none';
  384. localStorage.setItem("preview-state", 'close');
  385. } else {
  386. document.getElementById("editor-col").classList.remove('col-sm-12');
  387. document.getElementById("editor-col").classList.add('col-sm-6');
  388. document.getElementById("preview-col").style.display = '';
  389. localStorage.setItem("preview-state", 'open');
  390. }
  391. })
  392. </script>