index.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <[email protected]>
  16. Portions created by the Initial Developer are Copyright (C) 2008-2018
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. James Rose <[email protected]>
  21. */
  22. //includes
  23. include "root.php";
  24. require_once "resources/require.php";
  25. require_once "resources/check_auth.php";
  26. //check permissions
  27. if (permission_exists('script_editor_view')) {
  28. //access granted
  29. }
  30. else {
  31. echo "access denied";
  32. exit;
  33. }
  34. //add multi-lingual support
  35. $language = new text;
  36. $text = $language->get();
  37. //set the directory title and mode
  38. $_SESSION["app"]["edit"]["dir"] = $_GET["dir"];
  39. $title = escape($_GET["dir"]);
  40. unset($mode);
  41. switch ($_GET["dir"]) {
  42. case 'xml':
  43. $title = 'XML';
  44. $mode = 'xml';
  45. break;
  46. case 'provision':
  47. $title = 'Provision';
  48. $mode = 'xml';
  49. break;
  50. case 'php':
  51. $title = 'PHP';
  52. $mode = 'php';
  53. break;
  54. case 'scripts':
  55. $title = 'Scripts';
  56. $mode = 'lua';
  57. break;
  58. case 'grammar':
  59. $title = 'Grammar';
  60. $mode = 'xml';
  61. default: $mode = 'text';
  62. }
  63. //load editor preferences/defaults
  64. $setting_size = ($_SESSION["editor"]["font_size"]["text"] != '') ? $_SESSION["editor"]["font_size"]["text"] : '12px';
  65. $setting_theme = ($_SESSION["editor"]["theme"]["text"] != '') ? $_SESSION["editor"]["theme"]["text"] : 'cobalt';
  66. $setting_invisibles = ($_SESSION["editor"]["invisibles"]["boolean"] != '') ? $_SESSION["editor"]["invisibles"]["boolean"] : 'false';
  67. $setting_indenting = ($_SESSION["editor"]["indent_guides"]["boolean"] != '') ? $_SESSION["editor"]["indent_guides"]["boolean"] : 'false';
  68. $setting_numbering = ($_SESSION["editor"]["line_numbers"]["boolean"] != '') ? $_SESSION["editor"]["line_numbers"]["boolean"] : 'true';
  69. $setting_preview = ($_SESSION["editor"]["live_preview"]["boolean"] != '') ? $_SESSION["editor"]["live_preview"]["boolean"] : 'true';
  70. //get and then set the favicon
  71. if (isset($_SESSION['theme']['favicon']['text'])){
  72. $favicon = $_SESSION['theme']['favicon']['text'];
  73. }
  74. else {
  75. $favicon = '<!--{project_path}-->/themes/default/favicon.ico';
  76. }
  77. ?>
  78. <html>
  79. <head>
  80. <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
  81. <title><?php echo $title; ?></title>
  82. <link rel="icon" type="image/x-icon" href="<?php echo $favicon; ?>">
  83. <script language="JavaScript" type="text/javascript" src="<?php echo PROJECT_PATH; ?>/resources/jquery/jquery-1.11.1.js"></script>
  84. <script language="JavaScript" type="text/javascript">
  85. function submit_check() {
  86. if (document.getElementById('filepath').value != '') {
  87. document.getElementById('editor_source').value = editor.getSession().getValue();
  88. return true;
  89. }
  90. focus_editor();
  91. return false;
  92. }
  93. function toggle_option(opt) {
  94. switch (opt) {
  95. case 'numbering': toggle_option_do('showLineNumbers'); toggle_option_do('fadeFoldWidgets'); break;
  96. case 'invisibles': toggle_option_do('showInvisibles'); break;
  97. case 'indenting': toggle_option_do('displayIndentGuides'); break;
  98. }
  99. focus_editor();
  100. }
  101. function toggle_option_do(opt_name) {
  102. var opt_val = editor.getOption(opt_name);
  103. editor.setOption(opt_name, ((opt_val) ? false : true));
  104. }
  105. function toggle_sidebar() {
  106. var td_sidebar = document.getElementById('sidebar');
  107. td_sidebar.style.display = (td_sidebar.style.display == '') ? 'none' : '';
  108. focus_editor();
  109. }
  110. function insert_clip(before, after) {
  111. var selected_text = editor.session.getTextRange(editor.getSelectionRange());
  112. editor.insert(before + selected_text + after);
  113. focus_editor();
  114. }
  115. function focus_editor() {
  116. editor.focus();
  117. }
  118. </script>
  119. <style>
  120. img.control {
  121. cursor: pointer;
  122. width: auto;
  123. height: 23px;
  124. border: none;
  125. opacity: 0.5;
  126. }
  127. img.control:hover {
  128. opacity: 1.0;
  129. }
  130. div#editor {
  131. box-shadow: 0 5px 15px #333;
  132. }
  133. </style>
  134. </head>
  135. <body style='padding: 0; margin: 0; overflow: hidden;'>
  136. <table id='frame' cellpadding='0' cellspacing='0' border='0' style="height: 100%; width: 100%;">
  137. <tr>
  138. <td id='sidebar' valign='top' style="width: 300px; height: 100%;">
  139. <iframe id='file_list' src='filelist.php' style='border: none; height: 65%; width: 100%;'></iframe><br>
  140. <iframe id='clip_list' src='cliplist.php' style='border: none; border-top: 1px solid #ccc; height: calc(35% - 1px); width: 100%;'></iframe>
  141. </td>
  142. <td align='right' valign='top' style='height: 100%;'>
  143. <form style='margin: 0;' name='frm_edit' id='frm_edit' method='post' target='proc' action='filesave.php' onsubmit="return submit_check();">
  144. <textarea name='content' id='editor_source' style='display: none;'></textarea>
  145. <input type='hidden' name='filepath' id='filepath' value=''>
  146. <table cellpadding='0' cellspacing='0' border='0' style='width: 100%;'>
  147. <tr>
  148. <td valign='middle'><img src='resources/images/icon_save.png' title='Save Changes [Ctrl+S]' class='control' onclick="$('form#frm_edit').submit();";></td>
  149. <td align='left' valign='middle' width='100%' style='padding: 0 4px 0 6px;'><input id='current_file' type='text' style='height: 23px; width: 100%;'></td>
  150. <td style='padding: 0;'><img src='resources/images/blank.gif' style='width: 1px; height: 30px; border: none;'></td>
  151. <td valign='middle' style='padding-left: 6px;'><img src='resources/images/icon_sidebar.png' title='Toggle Side Bar [Ctrl+Q]' class='control' onclick="toggle_sidebar();"></td>
  152. <td valign='middle' style='padding-left: 6px;'><img src='resources/images/icon_numbering.png' title='Toggle Line Numbers' class='control' onclick="toggle_option('numbering');"></td>
  153. <td valign='middle' style='padding-left: 6px;'><img src='resources/images/icon_invisibles.png' title='Toggle Invisibles' class='control' onclick="toggle_option('invisibles');"></td>
  154. <td valign='middle' style='padding-left: 6px;'><img src='resources/images/icon_indenting.png' title='Toggle Indent Guides' class='control' onclick="toggle_option('indenting');"></td>
  155. <td valign='middle' style='padding-left: 6px;'><img src='resources/images/icon_replace.png' title='Show Find/Replace [Ctrl+H]' class='control' onclick="editor.execCommand('replace');"></td>
  156. <td valign='middle' style='padding-left: 6px;'><img src='resources/images/icon_goto.png' title='Show Go To Line' class='control' onclick="editor.execCommand('gotoline');"></td>
  157. <td valign='middle' style='padding-left: 10px;'>
  158. <select id='mode' style='height: 23px;' onchange="editor.getSession().setMode('ace/mode/' + this.options[this.selectedIndex].value); focus_editor();">
  159. <?php
  160. $modes['php'] = 'PHP';
  161. $modes['css'] = 'CSS';
  162. $modes['html'] = 'HTML';
  163. $modes['javascript'] = 'JS';
  164. $modes['json'] = 'JSON';
  165. $modes['ini'] = 'Conf';
  166. $modes['lua'] = 'Lua';
  167. $modes['text'] = 'Text';
  168. $modes['xml'] = 'XML';
  169. $modes['sql'] = 'SQL';
  170. $modes['sh'] = 'SH';
  171. $modes['smarty'] = 'Smarty';
  172. $modes['svg'] = 'SVG';
  173. $modes['makefile'] = 'Makefile';
  174. $modes['c_cpp'] = 'C';
  175. $modes['c_cpp'] = 'CPP';
  176. $modes['pgsql'] = 'PGSQL';
  177. $preview = ($setting_preview == 'true') ? "onmouseover=\"editor.getSession().setMode('ace/mode/' + this.value);\"" : null;
  178. foreach ($modes as $value => $label) {
  179. $selected = ($value == $mode) ? 'selected' : null;
  180. echo "<option value='".$value."' ".$selected." ".$preview.">".$label."</option>\n";
  181. }
  182. ?>
  183. </select>
  184. </td>
  185. <td valign='middle' style='padding-left: 4px;'>
  186. <select id='size' style='height: 23px;' onchange="document.getElementById('editor').style.fontSize = this.options[this.selectedIndex].value; focus_editor();">
  187. <?php
  188. $sizes = explode(',','9px,10px,11px,12px,14px,16px,18px,20px');
  189. $preview = ($setting_preview == 'true') ? "onmouseover=\"document.getElementById('editor').style.fontSize = this.value;\"" : null;
  190. if (!in_array($setting_size, $sizes)) {
  191. echo "<option value='".$setting_size."' ".$preview.">".$setting_size."</option>\n";
  192. echo "<option value='' disabled='disabled'></option>\n";
  193. }
  194. foreach ($sizes as $size) {
  195. $selected = ($size == $setting_size) ? 'selected' : null;
  196. echo "<option value='".$size."' ".$selected." ".$preview.">".$size."</option>\n";
  197. }
  198. ?>
  199. </select>
  200. </td>
  201. <td valign='middle' style='padding-left: 4px; padding-right: 4px;'>
  202. <select id='theme' style='height: 23px;' onchange="editor.setTheme('ace/theme/' + this.options[this.selectedIndex].value); focus_editor();">
  203. <?php
  204. $themes['Bright']['chrome']= 'Chrome';
  205. $themes['Bright']['clouds']= 'Clouds';
  206. $themes['Bright']['crimson_editor']= 'Crimson Editor';
  207. $themes['Bright']['dawn']= 'Dawn';
  208. $themes['Bright']['dreamweaver']= 'Dreamweaver';
  209. $themes['Bright']['eclipse']= 'Eclipse';
  210. $themes['Bright']['github']= 'GitHub';
  211. $themes['Bright']['iplastic']= 'IPlastic';
  212. $themes['Bright']['solarized_light']= 'Solarized Light';
  213. $themes['Bright']['textmate']= 'TextMate';
  214. $themes['Bright']['tomorrow']= 'Tomorrow';
  215. $themes['Bright']['xcode']= 'XCode';
  216. $themes['Bright']['kuroir']= 'Kuroir';
  217. $themes['Bright']['katzenmilch']= 'KatzenMilch';
  218. $themes['Bright']['sqlserver']= 'SQL Server';
  219. $themes['Dark']['ambiance']= 'Ambiance';
  220. $themes['Dark']['chaos']= 'Chaos';
  221. $themes['Dark']['clouds_midnight']= 'Clouds Midnight';
  222. $themes['Dark']['cobalt']= 'Cobalt';
  223. $themes['Dark']['idle_fingers']= 'idle Fingers';
  224. $themes['Dark']['kr_theme']= 'krTheme';
  225. $themes['Dark']['merbivore']= 'Merbivore';
  226. $themes['Dark']['merbivore_soft']= 'Merbivore Soft';
  227. $themes['Dark']['mono_industrial']= 'Mono Industrial';
  228. $themes['Dark']['monokai']= 'Monokai';
  229. $themes['Dark']['pastel_on_dark']= 'Pastel on dark';
  230. $themes['Dark']['solarized_dark']= 'Solarized Dark';
  231. $themes['Dark']['terminal']= 'Terminal';
  232. $themes['Dark']['tomorrow_night']= 'Tomorrow Night';
  233. $themes['Dark']['tomorrow_night_blue']= 'Tomorrow Night Blue';
  234. $themes['Dark']['tomorrow_night_bright']= 'Tomorrow Night Bright';
  235. $themes['Dark']['tomorrow_night_eighties']= 'Tomorrow Night 80s';
  236. $themes['Dark']['twilight']= 'Twilight';
  237. $themes['Dark']['vibrant_ink']= 'Vibrant Ink';
  238. $preview = ($setting_preview == 'true') ? "onmouseover=\"editor.setTheme('ace/theme/' + this.value);\"" : null;
  239. foreach ($themes as $optgroup => $theme) {
  240. echo "<optgroup label='".$optgroup."'>\n";
  241. foreach ($theme as $value => $label) {
  242. $selected = (strtolower($label) == strtolower($setting_theme)) ? 'selected' : null;
  243. echo "<option value='".$value."' ".$selected." ".$preview.">".$label."</option>\n";
  244. }
  245. echo "</optgroup>\n";
  246. }
  247. ?>
  248. </select>
  249. </td>
  250. </tr>
  251. </table>
  252. </form>
  253. <div id='editor' style="text-align: left; width: 100%; height: calc(100% - 30px); font-size: 12px;"></div>
  254. <iframe id='proc' name='proc' src='#' style='display: none;'></iframe>
  255. </td>
  256. </tr>
  257. </table>
  258. <script type="text/javascript" src="<?php echo PROJECT_PATH; ?>/resources/ace/ace.js" charset="utf-8"></script>
  259. <script type="text/javascript">
  260. //load ace editor
  261. var editor = ace.edit("editor");
  262. editor.setOptions({
  263. mode: 'ace/mode/<?php echo $mode;?>',
  264. theme: 'ace/theme/'+document.getElementById('theme').options[document.getElementById('theme').selectedIndex].value,
  265. selectionStyle: 'text',
  266. cursorStyle: 'smooth',
  267. showInvisibles: <?php echo $setting_invisibles;?>,
  268. displayIndentGuides: <?php echo $setting_indenting;?>,
  269. showLineNumbers: <?php echo $setting_numbering;?>,
  270. showGutter: true,
  271. scrollPastEnd: true,
  272. fadeFoldWidgets: <?php echo $setting_numbering;?>,
  273. showPrintMargin: false,
  274. highlightGutterLine: false,
  275. useSoftTabs: false
  276. });
  277. document.getElementById('editor').style.fontSize='<?php echo $setting_size;?>';
  278. focus_editor();
  279. //prevent form submit with enter key on file path input
  280. <?php key_press('enter', 'down', '#current_file', null, null, 'return false;', false); ?>
  281. //save file
  282. <?php key_press('ctrl+s', 'down', 'window', null, null, "$('form#frm_edit').submit(); return false;", false); ?>
  283. //open file manager/clip library pane
  284. <?php key_press('ctrl+q', 'down', 'window', null, null, 'toggle_sidebar(); focus_editor(); return false;', false); ?>
  285. //remove certain keyboard shortcuts
  286. editor.commands.bindKey("Ctrl-T", null); //new browser tab
  287. </script>
  288. </body>
  289. </html>