editor.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. <?php
  2. include '../../auth.php';
  3. ?>
  4. <!DOCTYPE html>
  5. <html lang="en">
  6. <!-- Special modification for NotepadA system, ArOZ Online Beta-->
  7. <head>
  8. <?php
  9. //Init of the editor
  10. function mv($var){
  11. if (isset($_GET[$var]) == true && $_GET[$var] != ""){
  12. return $_GET[$var];
  13. }else{
  14. return "";
  15. }
  16. }
  17. //Default value
  18. $filename = "";
  19. $displayName = "";
  20. $fileExt = "";
  21. $theme = "tomorrow_night";
  22. $mode = "php";
  23. $fontsize = "12";
  24. //check if a correct filename has been provided
  25. if (mv("filename") != ""){
  26. //Editing an existed file
  27. $filename = mv("filename");
  28. if (!file_exists($filename)){
  29. //File not found, creating a new one instead
  30. $file = fopen($filename, 'w') or die('Error opening file: ' + $filename);
  31. fclose($file);
  32. }
  33. $displayName = $filename;
  34. $fileExt = pathinfo($filename, PATHINFO_EXTENSION);
  35. //Handle the AOB Upload Manger type of naming methods
  36. if (substr($filename,0,5) == "inith"){
  37. $nameOnly = basename($filename, "." . $fileExt);
  38. $nameOnly = str_replace("inith","",$nameOnly);
  39. $displayName = hex2bin($nameOnly) . "." . $fileExt . " (Encoded Filename)";
  40. }else{
  41. $displayName = basename($filename);
  42. }
  43. //Set the mode of the editor to the extension of the file, but something this might be incorrect.
  44. $mode = $fileExt;
  45. }else{
  46. //Creating a new file instead
  47. $filename = "";
  48. $displayName = "untitled";
  49. }
  50. if (mv("theme") != ""){
  51. $theme = mv("theme");
  52. }
  53. if (mv("fontsize") != ""){
  54. $fontsize = mv("fontsize");
  55. }
  56. ?>
  57. <meta charset="UTF-8">
  58. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  59. <title><?php echo "Editing " . $displayName;?></title>
  60. <script src="../../script/jquery.min.js"></script>
  61. <style type="text/css" media="screen">
  62. body {
  63. overflow: hidden;
  64. padding-bottom:5px;
  65. }
  66. #editor {
  67. margin: 0;
  68. position: absolute;
  69. top: 0;
  70. bottom: 15px;
  71. left: 0;
  72. right: 0;
  73. }
  74. </style>
  75. </head>
  76. <body>
  77. <pre id="editor"><?php
  78. if ($filename != ""){
  79. echo str_replace("<","&lt;",file_get_contents($filename));
  80. }
  81. ?></pre>
  82. <script src="src-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
  83. <script>
  84. var filename = "<?php echo $filename;?>";
  85. var filepath = "<?php echo str_replace("\\",'/',realpath($filename));?>";
  86. var lastSave = "";
  87. //Init editor
  88. var editor = ace.edit("editor");
  89. editor.setTheme("ace/theme/<?php echo $theme;?>");
  90. var detectMode = getMode(filepath);
  91. //console.log("[NotepadA] Chaning mode to " + detectMode.toLowerCase());
  92. if ( detectMode != undefined){
  93. editor.session.setMode("ace/mode/" + detectMode.toLowerCase());
  94. }else{
  95. //Default mode: php
  96. editor.session.setMode("ace/mode/php");
  97. }
  98. editor.setOptions({
  99. //fontFamily: "tahoma",
  100. fontSize: "<?php echo $fontsize;?>pt"
  101. });
  102. $(document).ready(function(){
  103. //Initial assume saved
  104. lastSave = editor.getValue();
  105. });
  106. //Listener for Ctrl+S
  107. $(window).keypress(function(event) {
  108. if (!(event.which == 115 && event.ctrlKey) && !(event.which == 19)) return true;
  109. //console.log(filepath);
  110. Save();
  111. event.preventDefault();
  112. return false;
  113. });
  114. $(document).on("click","#editor",function() {
  115. //Hide the parent window in NotepadA condition
  116. window.parent.hideToggleMenu();
  117. });
  118. function Print() {
  119. try {
  120. var printWindow = window.open("", "", "height=400,width=800");
  121. printWindow.document.write("<html><head><title>NotepadA Print Window</title>");
  122. printWindow.document.write("</head><xmp>");
  123. printWindow.document.write("filename: " + filename + " \nprint-time: " + new Date().toLocaleString() + "\n");
  124. printWindow.document.write(editor.getSession().getDocument().getValue());
  125. printWindow.document.write("</xmp></html>");
  126. printWindow.document.close();
  127. printWindow.print();
  128. }catch (ex) {
  129. console.error("Error: " + ex.message);
  130. }
  131. }
  132. //Absolute path is used for saving. So no need to worry about the relative path over php issues
  133. function Save(){
  134. code = editor.getValue();
  135. $.post("../writeCode.php", { filename: filepath, content: code })
  136. .done(function( data ) {
  137. if (data.includes("ERROR") == false){
  138. console.log("Saved!");
  139. lastSave = code;
  140. }else{
  141. console.log(data);
  142. }
  143. });
  144. }
  145. function checkIsSaved(){
  146. if (lastSave == editor.getValue()){
  147. return true;
  148. }else{
  149. return false;
  150. }
  151. }
  152. var nameOverrides = {
  153. ObjectiveC: "Objective-C",
  154. CSharp: "C#",
  155. golang: "Go",
  156. C_Cpp: "C and C++",
  157. Csound_Document: "Csound Document",
  158. Csound_Orchestra: "Csound",
  159. Csound_Score: "Csound Score",
  160. coffee: "CoffeeScript",
  161. HTML_Ruby: "HTML (Ruby)",
  162. HTML_Elixir: "HTML (Elixir)",
  163. FTL: "FreeMarker"
  164. };
  165. function getMode(filePath){
  166. var ext = filePath.split(".").pop();
  167. var supportedModes = {
  168. ABAP: ["abap"],
  169. ABC: ["abc"],
  170. ActionScript:["as"],
  171. ADA: ["ada|adb"],
  172. Apache_Conf: ["^htaccess|^htgroups|^htpasswd|^conf|htaccess|htgroups|htpasswd"],
  173. AsciiDoc: ["asciidoc|adoc"],
  174. ASL: ["dsl|asl"],
  175. Assembly_x86:["asm|a"],
  176. AutoHotKey: ["ahk"],
  177. BatchFile: ["bat|cmd"],
  178. Bro: ["bro"],
  179. C_Cpp: ["cpp|c|cc|cxx|h|hh|hpp|ino"],
  180. C9Search: ["c9search_results"],
  181. Cirru: ["cirru|cr"],
  182. Clojure: ["clj|cljs"],
  183. Cobol: ["CBL|COB"],
  184. coffee: ["coffee|cf|cson|^Cakefile"],
  185. ColdFusion: ["cfm"],
  186. CSharp: ["cs"],
  187. Csound_Document: ["csd"],
  188. Csound_Orchestra: ["orc"],
  189. Csound_Score: ["sco"],
  190. CSS: ["css"],
  191. Curly: ["curly"],
  192. D: ["d|di"],
  193. Dart: ["dart"],
  194. Diff: ["diff|patch"],
  195. Dockerfile: ["^Dockerfile"],
  196. Dot: ["dot"],
  197. Drools: ["drl"],
  198. Edifact: ["edi"],
  199. Eiffel: ["e|ge"],
  200. EJS: ["ejs"],
  201. Elixir: ["ex|exs"],
  202. Elm: ["elm"],
  203. Erlang: ["erl|hrl"],
  204. Forth: ["frt|fs|ldr|fth|4th"],
  205. Fortran: ["f|f90"],
  206. FTL: ["ftl"],
  207. Gcode: ["gcode"],
  208. Gherkin: ["feature"],
  209. Gitignore: ["^.gitignore"],
  210. Glsl: ["glsl|frag|vert"],
  211. Gobstones: ["gbs"],
  212. golang: ["go"],
  213. GraphQLSchema: ["gql"],
  214. Groovy: ["groovy"],
  215. HAML: ["haml"],
  216. Handlebars: ["hbs|handlebars|tpl|mustache"],
  217. Haskell: ["hs"],
  218. Haskell_Cabal: ["cabal"],
  219. haXe: ["hx"],
  220. Hjson: ["hjson"],
  221. HTML: ["html|htm|xhtml|vue|we|wpy"],
  222. HTML_Elixir: ["eex|html.eex"],
  223. HTML_Ruby: ["erb|rhtml|html.erb"],
  224. INI: ["ini|conf|cfg|prefs"],
  225. Io: ["io"],
  226. Jack: ["jack"],
  227. Jade: ["jade|pug"],
  228. Java: ["java"],
  229. JavaScript: ["js|jsm|jsx"],
  230. JSON: ["json"],
  231. JSONiq: ["jq"],
  232. JSP: ["jsp"],
  233. JSSM: ["jssm|jssm_state"],
  234. JSX: ["jsx"],
  235. Julia: ["jl"],
  236. Kotlin: ["kt|kts"],
  237. LaTeX: ["tex|latex|ltx|bib"],
  238. LESS: ["less"],
  239. Liquid: ["liquid"],
  240. Lisp: ["lisp"],
  241. LiveScript: ["ls"],
  242. LogiQL: ["logic|lql"],
  243. LSL: ["lsl"],
  244. Lua: ["lua"],
  245. LuaPage: ["lp"],
  246. Lucene: ["lucene"],
  247. Makefile: ["^Makefile|^GNUmakefile|^makefile|^OCamlMakefile|make"],
  248. Markdown: ["md|markdown"],
  249. Mask: ["mask"],
  250. MATLAB: ["matlab"],
  251. Maze: ["mz"],
  252. MEL: ["mel"],
  253. MIXAL: ["mixal"],
  254. MUSHCode: ["mc|mush"],
  255. MySQL: ["mysql"],
  256. Nix: ["nix"],
  257. NSIS: ["nsi|nsh"],
  258. ObjectiveC: ["m|mm"],
  259. OCaml: ["ml|mli"],
  260. Pascal: ["pas|p"],
  261. Perl: ["pl|pm"],
  262. pgSQL: ["pgsql"],
  263. PHP: ["php|phtml|shtml|php3|php4|php5|phps|phpt|aw|ctp|module"],
  264. Pig: ["pig"],
  265. Powershell: ["ps1"],
  266. Praat: ["praat|praatscript|psc|proc"],
  267. Prolog: ["plg|prolog"],
  268. Properties: ["properties"],
  269. Protobuf: ["proto"],
  270. Python: ["py"],
  271. R: ["r"],
  272. Razor: ["cshtml|asp"],
  273. RDoc: ["Rd"],
  274. Red: ["red|reds"],
  275. RHTML: ["Rhtml"],
  276. RST: ["rst"],
  277. Ruby: ["rb|ru|gemspec|rake|^Guardfile|^Rakefile|^Gemfile"],
  278. Rust: ["rs"],
  279. SASS: ["sass"],
  280. SCAD: ["scad"],
  281. Scala: ["scala"],
  282. Scheme: ["scm|sm|rkt|oak|scheme"],
  283. SCSS: ["scss"],
  284. SH: ["sh|bash|^.bashrc"],
  285. SJS: ["sjs"],
  286. Smarty: ["smarty|tpl"],
  287. snippets: ["snippets"],
  288. Soy_Template:["soy"],
  289. Space: ["space"],
  290. SQL: ["sql"],
  291. SQLServer: ["sqlserver"],
  292. Stylus: ["styl|stylus"],
  293. SVG: ["svg"],
  294. Swift: ["swift"],
  295. Tcl: ["tcl"],
  296. Tex: ["tex"],
  297. Text: ["txt"],
  298. Textile: ["textile"],
  299. Toml: ["toml"],
  300. TSX: ["tsx"],
  301. Twig: ["twig|swig"],
  302. Typescript: ["ts|typescript|str"],
  303. Vala: ["vala"],
  304. VBScript: ["vbs|vb"],
  305. Velocity: ["vm"],
  306. Verilog: ["v|vh|sv|svh"],
  307. VHDL: ["vhd|vhdl"],
  308. Wollok: ["wlk|wpgm|wtest"],
  309. XML: ["xml|rdf|rss|wsdl|xslt|atom|mathml|mml|xul|xbl|xaml"],
  310. XQuery: ["xq"],
  311. YAML: ["yaml|yml"],
  312. Django: ["html"]
  313. };
  314. for (var key in supportedModes) {
  315. if (supportedModes.hasOwnProperty(key)) {
  316. var thisExtension = supportedModes[key][0].split("|");
  317. if (thisExtension.length == 1){
  318. if (ext == thisExtension[0]){
  319. return key;
  320. }
  321. }else{
  322. for(var i =0; i < thisExtension.length;i++){
  323. if (ext == thisExtension[i]){
  324. return key;
  325. }
  326. }
  327. }
  328. }
  329. }
  330. }
  331. </script>
  332. </body>
  333. </html>