0

0

单文件版在线代码编辑器 aceditor

php中文网

php中文网

发布时间:2016-07-25 08:47:33

|

2302人浏览过

|

来源于php中文网

原创

* 单文件版在线代码编辑器 editor.php 版本: v1.21
* 非常方便地在线编辑您网站上的任意文本文件,对于维护网站,和在线写代码非常好用
* 密码加密方式:
* md5(自设密码+$ace) //$ace为cdn镜像地址
*
* 使用方法:
* 1.确认 $pwd 变量值为 false, 上传本文件到PHP空间并访问
* 2.第一次访问提示设置密码,设置密码并牢记
* 3.使用第一次设置的密码登录后,默认编辑的是本php文件,
* 4.本文件是编辑器核心文件,请不要随意修改
* 5.保存编辑的文件请用 Ctrl + S 按键组合,等待执行结果
* 6.保存动作执行后请务必等待保存成功信息返回
* 7.重置操作会修改本程序的文件名,以防他人猜测路径
* 8.刷新功能仅是刷新本程序文件,不能刷新其他
*
* 建议在 chrome 浏览器中使用本编辑器

项目详细见
http://git.oschina.net/ymk18/aceditor 单文件版在线代码编辑器 aceditor
  1. /**
  2. * 单文件版在线代码编辑器 editor.php 版本: v1.21
  3. *
  4. * 密码加密方式:
  5. * md5(自设密码+$ace) //$ace为cdn镜像地址
  6. *
  7. * 使用方法:
  8. * 1.确认 $pwd 变量值为 false, 上传本文件到PHP空间并访问
  9. * 2.第一次访问提示设置密码,设置密码并牢记
  10. * 3.使用第一次设置的密码登录后,默认编辑的是本php文件,
  11. * 4.本文件是编辑器核心文件,请不要随意修改
  12. * 5.保存编辑的文件请用 Ctrl + S 按键组合,等待执行结果
  13. * 6.保存动作执行后请务必等待保存成功信息返回
  14. * 7.重置操作会修改本程序的文件名,以防他人猜测路径
  15. * 8.刷新功能仅是刷新本程序文件,不能刷新其他
  16. *
  17. * 建议在 chrome 浏览器中使用本编辑器
  18. */
  19. session_start();
  20. $curr_file = __FILE__; //默认编辑当前文件
  21. $curr_file_path = str_replace(dirname(__FILE__), '', __FILE__);
  22. $pwd = false; //密码初始化默认值为 false
  23. $ace = 'http://cdn.staticfile.org/ace/1.1.3/ace.js'; //编辑器核心js
  24. $tip['core'] = 'http://cdn.staticfile.org/alertify.js/0.3.11/alertify.core.min.css';
  25. $tip['css'] = 'http://cdn.staticfile.org/alertify.js/0.3.11/alertify.default.min.css';
  26. $tip['js'] = 'http://cdn.staticfile.org/alertify.js/0.3.11/alertify.min.js';
  27. $jquery = 'http://cdn.staticfile.org/jquery/2.1.1-rc2/jquery.min.js';
  28. if ( false !== $pwd ) {
  29. define('DEFAULT_PWD', $pwd);
  30. }
  31. //文件后缀名对应的语法解析器
  32. $lng = array(
  33. 'as' => 'actionscript', 'js' => 'javascript',
  34. 'php' => 'php', 'css' => 'css', 'html' => 'html',
  35. 'htm' => 'html', 'ini' => 'ini', 'json' => 'json',
  36. 'jsp' => 'jsp', 'txt' => 'text', 'sql' => 'mysql',
  37. 'xml' => 'xml', 'yaml' => 'yaml', 'py' => 'python',
  38. 'md' => 'markdown', 'htaccess' => 'apache_conf',
  39. 'bat' => 'batchfile', 'go' => 'golang',
  40. );
  41. //判断用户是否登录
  42. function is_logged() {
  43. $flag = false;
  44. if ( isset($_SESSION['pwd']) && defined('DEFAULT_PWD') ) {
  45. if ( $_SESSION['pwd'] === DEFAULT_PWD ) {
  46. $flag = true;
  47. }
  48. }
  49. return $flag;
  50. }
  51. //重新载入到本页面
  52. function reload() {
  53. $file = pathinfo(__FILE__, PATHINFO_BASENAME);
  54. die(header("Location: {$file}"));
  55. }
  56. //判断请求是否是ajax请求
  57. function is_ajax() {
  58. $flag = false;
  59. if ( isset($_SERVER['HTTP_X_REQUESTED_WITH']) ) {
  60. $flag = strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest';
  61. }
  62. return $flag;
  63. }
  64. //销毁SESSION和COOKIE
  65. function exterminate() {
  66. $_SESSION = array();
  67. foreach ( $_COOKIE as $key ) {
  68. setcookie($key, null);
  69. }
  70. session_destroy();
  71. $_COOKIE = array();
  72. return true;
  73. }
  74. //获取一个目录下的文件列表
  75. function list_dir($path, $type = 'array') {
  76. $flag = false;
  77. $lst = array('dir'=>array(), 'file'=>array());
  78. $base = !is_dir($path) ? dirname($path) : $path;
  79. $tmp = scandir($base);
  80. foreach ( $tmp as $k=>$v ) {
  81. //过滤掉上级目录,本级目录和程序自身文件名
  82. if ( !in_array($v, array('.', '..')) ) {
  83. $file = $full_path = rtrim($base, '/').DIRECTORY_SEPARATOR.$v;
  84. if ( $full_path == __FILE__ ) {
  85. continue; //屏蔽自身文件不在列表出现
  86. }
  87. $file = str_replace(dirname(__FILE__), '', $file);
  88. $file = str_replace("\", '/', $file); //过滤win下的路径
  89. $file = str_replace('//', '/', $file); //过滤双斜杠
  90. if ( is_dir($full_path) ) {
  91. if ( 'html' === $type ) {
  92. $v = '
  93. '.$v.'
  94. ';
  95. }
  96. array_push($lst['dir'], $v);
  97. } else {
  98. if ( 'html' === $type ) {
  99. $v = '
  100. '.$v.'
  101. ';
  102. }
  103. array_push($lst['file'], $v);
  104. }
  105. }
  106. }
  107. $lst = array_merge($lst['dir'], $lst['file']);
  108. $lst = array_filter($lst);
  109. $flag = $lst;
  110. if ( 'html' === $type ) {
  111. $flag = '
      '. implode('', $lst) .'
    ';
  112. }
  113. return $flag;
  114. }
  115. //递归删除一个非空目录
  116. function deldir($dir) {
  117. $dh = opendir($dir);
  118. while ( $file = readdir($dh) ) {
  119. if ( $file != '.' && $file != '..' ) {
  120. $fullpath = $dir.'/'.$file;
  121. if ( !is_dir($fullpath) ) {
  122. unlink($fullpath);
  123. } else {
  124. deldir($fullpath);
  125. }
  126. }
  127. }
  128. return rmdir($dir);
  129. }
  130. //退出登录
  131. if ( isset($_GET['logout']) ) {
  132. if ( exterminate() ) {
  133. reload();
  134. }
  135. }
  136. //ajax输出文件内容
  137. if ( is_logged() && is_ajax() && isset($_POST['file']) ) {
  138. $file = dirname(__FILE__).$_POST['file'];
  139. $ext = pathinfo($file, PATHINFO_EXTENSION);
  140. $mode = isset($lng[$ext]) ? $lng[$ext] : false;
  141. die(json_encode(array(
  142. 'file' => $file, 'html' => file_get_contents($file),
  143. 'mode' => $mode,
  144. )));
  145. }
  146. //ajax输出目录列表
  147. if ( is_logged() && is_ajax() && isset($_POST['dir']) ) {
  148. $dir = dirname(__FILE__).$_POST['dir'];
  149. $list_dir = list_dir($dir, 'html');
  150. die(json_encode(array(
  151. 'dir' => $dir, 'html' => $list_dir,
  152. )));
  153. }
  154. //ajax保存文件
  155. if ( is_logged() && is_ajax() && isset($_POST['action']) ) {
  156. $arr = array('result'=>'error', 'msg'=>'文件保存失败!');
  157. $content = $_POST['content'];
  158. if ( 'save_file' === $_POST['action'] ) {
  159. if ( isset($_POST['file_path']) ) {
  160. $file = dirname(__FILE__).$_POST['file_path'];
  161. } else {
  162. $file = __FILE__;
  163. }
  164. file_put_contents($file, $content);
  165. $arr['result'] = 'success';
  166. $arr['msg'] = '保存成功!';
  167. }
  168. die(json_encode($arr));
  169. }
  170. //ajax删除文件或文件夹
  171. if ( is_logged() && is_ajax() && isset($_POST['del']) ) {
  172. $path = dirname(__FILE__).$_POST['del'];
  173. $arr = array('result'=>'error', 'msg'=>'删除操作失败!');
  174. if ( $_POST['del'] && $path ) {
  175. $flag = is_dir($path) ? deldir($path) : unlink($path);
  176. if ( $flag ) {
  177. $arr['msg'] = '删除操作成功!';
  178. $arr['result'] = 'success';
  179. }
  180. }
  181. die(json_encode($arr));
  182. }
  183. //ajax新建文件或文件夹
  184. if ( is_logged() && is_ajax() && isset($_POST['create']) ) {
  185. $flag = false;
  186. $arr = array('result'=>'error', 'msg'=>'操作失败!');
  187. if ( isset($_POST['target']) ) {
  188. $target = dirname(__FILE__).$_POST['target'];
  189. $target = is_dir($target) ? $target : dirname($target);
  190. }
  191. if ( $_POST['create'] && $target ) {
  192. $base_name = pathinfo($_POST['create'], PATHINFO_BASENAME);
  193. $exp = explode('.', $base_name);
  194. $full_path = $target.'/'.$base_name;
  195. $new_path = str_replace(dirname(__FILE__), '', $full_path);
  196. if ( count($exp) > 1 && isset($lng[array_pop($exp)]) ) {
  197. file_put_contents($full_path, '');
  198. $arr['result'] = 'success';
  199. $arr['msg'] = '新建文件成功!';
  200. $arr['type'] = 'file';
  201. } else {
  202. mkdir($full_path, 0777, true);
  203. $arr['result'] = 'success';
  204. $arr['msg'] = '新建目录成功!';
  205. $arr['type'] = 'dir';
  206. }
  207. if ( $base_name && $new_path ) {
  208. $arr['new_name'] = $base_name;
  209. $arr['new_path'] = $new_path;
  210. }
  211. }
  212. die(json_encode($arr));
  213. }
  214. //ajax重命名文件或文件夹
  215. if ( is_logged() && is_ajax() && isset($_POST['rename']) ) {
  216. $arr = array('result'=>'error', 'msg'=>'重命名操作失败!');
  217. if ( isset($_POST['target']) ) {
  218. $target = dirname(__FILE__).$_POST['target'];
  219. }
  220. if ( $_POST['rename'] ) {
  221. $base_name = pathinfo($_POST['rename'], PATHINFO_BASENAME);
  222. if ( $base_name ) {
  223. $rename = dirname($target).'/'.$base_name;
  224. $new_path = str_replace(dirname(__FILE__), '', $rename);
  225. }
  226. }
  227. if ( $rename && $target && rename($target, $rename) ) {
  228. $arr['new_name'] = $base_name;
  229. $arr['new_path'] = $new_path;
  230. $arr['msg'] = '重命名操作成功!';
  231. $arr['result'] = 'success';
  232. }
  233. if ( $target == __FILE__ ) {
  234. $arr['redirect'] = $new_path;
  235. }
  236. die(json_encode($arr));
  237. }
  238. //获取代码文件内容
  239. $code = file_get_contents($curr_file);
  240. $tree = '
    • ROOT'.list_dir($curr_file, 'html').'
    • ';
    • //登陆和设置密码共用模版
    • $first =
    • 【标题】
    • body {
    • overflow: hidden; background-color: #2D2D2D; color: #CCCCCC; font-size: 12px; margin: 0;
    • font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;
    • }
    • form { display: none; position: absolute; }
    • form h5 { font-size: 14px; font-weight: normal; margin: 0; line-height: 2em; }
    • form input {
    • color: #fff; border: 1px solid #369; border-radius: 3px; background: #333; height: 22px;
    • line-height: 1.6em; width: 125px; margin-right: 5px; vertical-align: middle;
    • }
    • form button {
    • line-height: 1.6em; border: 1px solid #369; border-radius: 3px;
    • background: #369; color: #fff; vertical-align: middle;
    • }
    • <script src="%7B%24jquery%7D" type="text/javascript" charset="utf-8"></script>
    • <script src="%7B%24ace%7D" type="text/javascript" charset="utf-8"></script>
    • <script src="%7B%24tip['js']%7D" type="text/javascript"></script>
    • <script type="text/javascript"></script>
    • var editor = false;
    • $(function(){
    • $('form').prepend('
      '+ document.title +'
      ');
    • $('form').css({
    • left: ($(window).width()-$('form').width())/2,
    • top: ($(window).height()-$('form').height())/2
    • });
    • $('form').show();
    • });
    • HTMLSTR;
    • //判断是否第一次登录
    • if ( false === $pwd && empty($_POST) ) {
    • die(str_replace(
    • array('【标题】', '【动作】'),
    • array('第一次使用,请先设置密码!', '设置'),
    • $first
    • ));
    • }
    • //第一次设置登录密码
    • if ( false === $pwd && !empty($_POST) ) {
    • if ( isset($_POST['pwd']) && strlen($_POST['pwd']) ) {
    • $pwd = $_SESSION['pwd'] = md5($_POST['pwd'].$ace);
    • $code = preg_replace('#$pwd = false;#', '$pwd = "'.$pwd.'";', $code, 1);
    • file_put_contents($curr_file, $code);
    • } else {
    • reload();
    • }
    • }
    • //用户登录验证
    • if ( false !== $pwd && !empty($_POST) ) {
    • $tmp = md5($_POST['pwd'].$ace);
    • if ( $tmp && $pwd && $tmp === $pwd ) {
    • $_SESSION['pwd'] = $pwd;
    • reload();
    • }
    • }
    • //处理一下html实体
    • $code = htmlspecialchars($code);
    • $dir_icon = str_replace(array(" ", " ", " "), '',
    • 'data:image/jpg;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAANCAYAAACgu+4kAAAAGXRFWHRTb2Z0d2
    • FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQVJREFUeNqkkk1uwjAQhd84bsNP1FUXLCtu0H3XPSoX4Qrd9wR
    • sCjQEcIY3DiiJUYiqRhp5Mra/92YSUVVgLSW49B7H+NApRh75XkHfFoCG+02tyflUeQTw2y9UYYP8cCStc9SM
    • PeVA/Sy6Dw555q3au1z+EhBYk1cgO7OSNdaFNT0x5sCkYDha0WPiHZgVqPzLO+8seai6E2jed42bCL06tNyEH
    • AX9kv3jh3HqH7BctFWLMOmAbcg05mHK5+sQpd1HYijN47zcDUCShGEHtzxtwQS9WTcAQmJROrJDLXQB9s1Tu6
    • MtRED4bwsHLnUzxEeKac3+GeP6eo8yevhjC3F1qC4CDAAl3HwuyNAIdwAAAABJRU5ErkJggg==');
    • $file_icon = str_replace(array(" ", " ", " "), '',
    • 'data:image/jpg;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAQCAYAAADJViUEAAAAGXRFWHRTb2Z0d2
    • FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAS1JREFUeNqMU01KxkAMTaez7aYbNwreQdBzeopS6EXEW+jug7Z
    • C6X+/iUloSr6xioFHJkPee5mUJgBwT7gjpPB3XAgfiBjs5dOyLF/btl0pkEFngdbzPGNRFK/U+0hwJAAMjmcm
    • DsOA4zge6Pseu67DpmlEqK5rLMvyRkDJor6uq2SGktu2FfdpmpANqqoSASYnO/kthABJkoCOxCASkCBkWSYuQ
    • qCeNE1fqHz3fMkXzjnJ2sRinL33QBNIzWJ5nh/L8npQohVTJwYTyfFm/d6Oo2HGE8ffwseuZ1PEjhrOutmsRF
    • 0iC8QmPibEtT4hftrhHI95JqJT/HC2JOt0to+zN6MVsZ/oZKqwmyCTA33DkbN1sws0i+Pega6v0kd42H9JB/8
    • LJl5I6PNbgAEAa9MP7QWoNLoAAAAASUVORK5CYII=');
    • $loading = str_replace(array(" ", " ", " "), '',
    • 'data:image/gif;base64,R0lGODlhFAAUALMIAPh2AP+TMsZiALlcAKNOAOp4ANVqAP+PFv///wAAAAAAAA
    • AAAAAAAAAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQFCgAIACwAAAAAFAAUAAAEUxDJSau9iBDMteb
    • TMEjehgTBJYqkiaLWOlZvGs8WDO6UIPCHw8TnAwWDEuKPcxQml0Ynj2cwYACAS7VqwWItWyuiUJB4s2AxmWxG
    • g9bl6YQtl0cAACH5BAUKAAgALAEAAQASABIAAAROEMkpx6A4W5upENUmEQT2feFIltMJYivbvhnZ3Z1h4FMQI
    • Dodz+cL7nDEn5CH8DGZhcLtcMBEoxkqlXKVIgAAibbK9YLBYvLtHH5K0J0IACH5BAUKAAgALAEAAQASABIAAA
    • ROEMkphaA4W5upMdUmDQP2feFIltMJYivbvhnZ3V1R4BNBIDodz+cL7nDEn5CH8DGZAMAtEMBEoxkqlXKVIg4
    • HibbK9YLBYvLtHH5K0J0IACH5BAUKAAgALAEAAQASABIAAAROEMkpjaE4W5tpKdUmCQL2feFIltMJYivbvhnZ
    • 3R0A4NMwIDodz+cL7nDEn5CH8DGZh8ONQMBEoxkqlXKVIgIBibbK9YLBYvLtHH5K0J0IACH5BAUKAAgALAEAA
    • QASABIAAAROEMkpS6E4W5spANUmGQb2feFIltMJYivbvhnZ3d1x4JMgIDodz+cL7nDEn5CH8DGZgcBtMMBEox
    • kqlXKVIggEibbK9YLBYvLtHH5K0J0IACH5BAUKAAgALAEAAQASABIAAAROEMkpAaA4W5vpOdUmFQX2feFIltM
    • JYivbvhnZ3V0Q4JNhIDodz+cL7nDEn5CH8DGZBMJNIMBEoxkqlXKVIgYDibbK9YLBYvLtHH5K0J0IACH5BAUK
    • AAgALAEAAQASABIAAAROEMkpz6E4W5tpCNUmAQD2feFIltMJYivbvhnZ3R1B4FNRIDodz+cL7nDEn5CH8DGZg
    • 8HNYMBEoxkqlXKVIgQCibbK9YLBYvLtHH5K0J0IACH5BAkKAAgALAEAAQASABIAAAROEMkpQ6A4W5spIdUmHQ
    • f2feFIltMJYivbvhnZ3d0w4BMAIDodz+cL7nDEn5CH8DGZAsGtUMBEoxkqlXKVIgwGibbK9YLBYvLtHH5K0J0
    • IADs=');
    • //编辑器模版
    • $html =
    • ACE代码编辑器
    • a { text-decoration: none; }
    • body {
    • overflow: hidden; background-color: #2D2D2D; font-size: 12px;
    • font-family: 'Consolas', 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    • scrollbar-arrow-color: #ccc; scrollbar-base-color: #333;
    • scrollbar-dark-shadow-color: #00ffff; scrollbar-track-color: #272822;
    • scrollbar-highlight-color: #272822; scrollbar-3d-light-color: #272822;
    • scrollbar-face-color: #2D2D2D; scrollbar-shadow-color: #333;
    • }
    • ::-webkit-scrollbar { width:5px; height:6px; background-color:#444; }
    • ::-webkit-scrollbar:hover { background-color:#444; }
    • ::-webkit-scrollbar-thumb:hover { min-height:5px; min-width:5px; background-color: #AAA; }
    • ::-webkit-scrollbar-thumb:active { -webkit-border-radius:20px; background-color: #AAA; }
    • ::-webkit-scrollbar-thumb {
    • min-height:5px; min-width:5px; -webkit-border-radius:20px;
    • ::-webkit-border-radius:1px; background-color: #AAA;
    • }
    • body > pre { color: #666; }
    • #sider { margin: 0; position: absolute; top: 25px; bottom: 0; left: 0; right: 85%; }
    • #editor { margin: 0; position: absolute; top: 0; bottom: 0; left: 15%; right: 0; }
    • #dir_tree { margin:0; padding: 0; height: 100%; overflow: auto; position: relative; left: 5px; }
    • #dir_tree, #dir_tree ul, #dir_tree li { margin: 0; padding: 0; list-style: none inside; }
    • #dir_tree ul { padding-left: 20px; position: relative; }
    • #dir_tree li { text-indent: 2em; line-height: 1.6em; cursor: default; color: #ccc; }
    • #dir_tree li.hover > span, #dir_tree li:hover > span { color: #66D9EF; }
    • #dir_tree li#on > span { color: red; }
    • #dir_tree li.dir { background: url({$dir_icon}) no-repeat 3px 3px; }
    • #dir_tree li.file { background: url({$file_icon}) no-repeat 3px 0; }
    • #dir_tree li.loading { background: url({$loading}) no-repeat 3px 0; }
    • #logout { position: absolute; top: 0; left: 0; }
    • #logout a { display: inline-block; color: #aaa; line-height: 25px; padding: 0 4px; }
    • #logout a:hover { background: #000; color: #ddd; }
    • #contextmenu { position: absolute; top: 0; left: 0; background: #fff; color: #333; border: 1px solid #000; padding: 1px; }
    • #contextmenu span { display: block; line-height: 24px; text-indent: 20px; width: 80px; cursor: default; }
    • #contextmenu span:hover { background-color: #369; color: #fff; }
    • #alertify .alertify-message, #alertify .alertify-message {
    • text-align: left !important; text-indent: 0; font-weight: bold; font-size: 16px;
    • }
    • #alertify .alertify-dialog, #alertify .alertify-dialog {
    • font-family: 'Consolas'; padding: 10px !important; color: #333 !important;
    • }
    • #alertify .alertify-button {
    • border-radius: 3px !important; font-weight: normal !important;
    • font-size: 14px !important; padding: 3px 15px !important;
    • }
    • .alertify-buttons { text-align: right !important; }
    • 保存
    • 刷新
    • 重置
    • 退出
  241. {$tree}
    {$code}
  242. <script src="%7B%24jquery%7D" type="text/javascript" charset="utf-8"></script>
  243. <script src="%7B%24ace%7D" type="text/javascript" charset="utf-8"></script>
  244. <script src="%7B%24tip['js']%7D" type="text/javascript"></script>
  245. <script type="text/javascript"></script>
  246. var load = false;
  247. var curr_file = false;
  248. window.location.hash = '';
  249. alertify.set({delay: 1000}); //n秒后自动消失
  250. alertify.set({labels: {ok:'确定',cancel:'取消'}});
  251. var editor = false;
  252. $(function(){
  253. //实例化代码编辑器
  254. editor = ace.edit("editor");
  255. //设置编辑器的语法和高亮
  256. editor.setTheme("ace/theme/monokai");
  257. editor.getSession().setMode("ace/mode/php");
  258. //设置编辑器自动换行
  259. editor.getSession().setWrapLimitRange(null, null);
  260. editor.getSession().setUseWrapMode(true);
  261. //不显示垂直衬线
  262. editor.renderer.setShowPrintMargin(false);
  263. //editor.setReadOnly(true); //设置编辑器为只读
  264. //editor.gotoLine(325); //跳转到指定行
  265. //使编辑器获得输入焦点
  266. editor.focus();
  267. //绑定组合按键
  268. var commands = editor.commands;
  269. commands.addCommand({
  270. name: "save",
  271. bindKey: {win: "Ctrl-S", mac: "Command-S"},
  272. exec: save_file
  273. });
  274. //保存动作
  275. function save_file() {
  276. if ( false == editor ) { return false; }
  277. var obj = {
  278. content: editor.getValue(),
  279. action: 'save_file'
  280. };
  281. if ( false !== curr_file ) {
  282. obj.file_path = curr_file;
  283. }
  284. alertify.log('正在保存...');
  285. $.post(window.location.href, obj, function(data){
  286. if ( data.msg && 'success' == data.result ) {
  287. alertify.success(data.msg);
  288. } else {
  289. alertify.error(data.msg);
  290. }
  291. }, 'json');
  292. }
  293. //加载目录列表或文件
  294. load = function(ele) {
  295. var curr = $(event.srcElement);
  296. if ( ele ) { curr = ele; }
  297. if ( curr.is('span') ) { curr = curr.parent('li'); }
  298. $('#dir_tree #on').removeAttr('id');
  299. curr.attr('id', 'on');
  300. var type = curr.attr('class');
  301. var path = curr.attr('path');
  302. window.location.hash = path;
  303. if ( 'file' === type ) {
  304. alertify.log('正在加载...');
  305. curr.addClass('loading');
  306. $.post(window.location.href, {file:path}, function(data){
  307. curr.removeClass('loading');
  308. if ( data.mode ) {
  309. editor.getSession().setMode("ace/mode/"+data.mode);
  310. }
  311. //注意,空文件应当允许编辑
  312. if ( true || data.html ) {
  313. curr.attr('disabled', 'disabled');
  314. curr_file = path; //当前编辑的文件路径
  315. //动态赋值编辑器中的内容
  316. editor.session.doc.setValue(data.html);
  317. editor.renderer.scrollToRow(0); //滚动到第一行
  318. editor.focus(); //编辑器获得焦点
  319. setTimeout(function(){
  320. editor.gotoLine(0);
  321. }, 800);
  322. }
  323. }, 'json');
  324. event.stopPropagation();
  325. event.preventDefault();
  326. return false;
  327. }
  328. if ( 'dir' === type ) {
  329. if ( curr.attr('loaded') ) {
  330. curr.children('ul').toggle();
  331. event.stopPropagation();
  332. event.preventDefault();
  333. return false;
  334. } else {
  335. curr.attr('loaded', 'yes');
  336. }
  337. alertify.log('正在加载...');
  338. curr.addClass('loading');
  339. $.post(window.location.href, {dir:path}, function(data){
  340. curr.find('ul').remove();
  341. curr.removeClass('loading');
  342. if ( data.html ) {
  343. curr.append(data.html);
  344. }
  345. }, 'json');
  346. }
  347. return false;
  348. }
  349. //绑定右键菜单
  350. $('#sider').bind('contextmenu', function(e){
  351. var path = false;
  352. var target = $(event.srcElement);
  353. if ( target.is('span') ) {
  354. target = target.parent('li');
  355. }
  356. if ( target.attr('path') ) {
  357. path = target.attr('path');
  358. } else {
  359. return false;
  360. }
  361. target.addClass('hover');
  362. var right_menu = $('#contextmenu');
  363. if ( !right_menu.get(0) ) {
  364. var timer = false;
  365. right_menu = $('
    ');
  366. right_menu.hover(function(){
  367. if ( timer ) { clearTimeout(timer); }
  368. }, function(){
  369. timer = setTimeout(function(){
  370. hide_menu(right_menu);
  371. }, 500);
  372. });
  373. $('body').append(right_menu);
  374. }
  375. if ( path ) {
  376. right_menu.html('');
  377. var menu = $('新建浏览重命名删除');
  378. right_menu.append(menu);
  379. menu_area(right_menu, {left: e.pageX, top: e.pageY});
  380. right_menu.find('span').click(function(){
  381. switch ( $(this).text() ) {
  382. case '新建' : create_new(target, path); break;
  383. case '浏览' : preview(target, path); break;
  384. case '重命名' : re_name(target, path); break;
  385. case '删除' : del_file(target, path); break;
  386. }
  387. hide_menu(right_menu);
  388. });
  389. }
  390. path ? right_menu.show() : hide_menu(right_menu);
  391. return false;
  392. });
  393. //隐藏右键菜单
  394. function hide_menu(menu) {
  395. $('#sider li.hover').removeClass('hover');
  396. if ( menu ) {
  397. menu.hide();
  398. }
  399. }
  400. //右键菜单区域
  401. function menu_area(menu, cfg) {
  402. if ( menu && cfg ) {
  403. var w = $('#sider').width() - menu.width();
  404. var h = $('#sider').height() - menu.height();
  405. if ( cfg.left > w ) { cfg.left = w; }
  406. if ( cfg.top > h ) { cfg.top = h; }
  407. menu.css(cfg);
  408. }
  409. }
  410. //保存按钮
  411. $('#logout>a:contains("保存")').click(function(){
  412. save_file();
  413. return false;
  414. });
  415. //刷新按钮
  416. $('#logout>a:contains("刷新")').click(function(){
  417. window.location.href = window.location.pathname;
  418. return false;
  419. });
  420. //重置按钮
  421. $('#logout>a:contains("重置")').click(function(){
  422. alertify.confirm('是否修改 {$curr_file_path} 程序文件名?', function (e) {
  423. if ( !e ) { return 'cancel'; }
  424. re_name($(''), '{$curr_file_path}');
  425. });
  426. return false;
  427. });
  428. //新建操作
  429. function create_new(obj, path) {
  430. if ( !obj || !path ) { return false; }
  431. alertify.prompt('请输入新建文件或文件夹名:', function (e, str) {
  432. if ( !e || !str ) { return false; }
  433. alertify.log('正在操作中...');
  434. $('#dir_tree #on').removeAttr('loaded').removeAttr('id');
  435. $.post(window.location.href, {create:str,target:path}, function(data){
  436. if ( data.msg && 'success' == data.result ) {
  437. alertify.success(data.msg);
  438. if ( obj.attr('class') == 'dir' ) {
  439. load(obj); //重新加载子节点
  440. } else {
  441. load(obj.parent().parent());
  442. }
  443. } else {
  444. alertify.error(data.msg);
  445. }
  446. }, 'json');
  447. });
  448. }
  449. //浏览操作
  450. function preview(obj, path) {
  451. if ( !obj || !path ) { return false; }
  452. window.open(path, '_blank');
  453. }
  454. //重命名
  455. function re_name(obj, path) {
  456. if ( !obj || !path ) { return false; }
  457. alertify.prompt('重命名 '+path+' 为:', function (e, str) {
  458. if ( !e || !str ) { return false; }
  459. alertify.log('正在操作中...');
  460. $.post(window.location.href, {rename:str,target:path}, function(data){
  461. if ( data.msg && 'success' == data.result ) {
  462. alertify.success(data.msg);
  463. if ( data.redirect ) {
  464. window.location.href = data.redirect;
  465. }
  466. if ( data.new_name ) {
  467. obj.children('span').first().text(data.new_name);
  468. obj.attr('path', data.new_path);
  469. }
  470. } else {
  471. alertify.error(data.msg);
  472. }
  473. }, 'json');
  474. });
  475. }
  476. //删除文件动作
  477. function del_file(obj, path) {
  478. if ( !obj || !path ) { return false; }
  479. alertify.confirm('您确定要删除:'+path+' 吗?', function (e) {
  480. if ( !e ) { return 'cancel'; }
  481. alertify.log('正在删除中...');
  482. $.post(window.location.href, {del:path}, function(data){
  483. if ( data.msg && 'success' == data.result ) {
  484. alertify.success(data.msg);
  485. obj.remove();
  486. } else {
  487. alertify.error(data.msg);
  488. }
  489. }, 'json');
  490. });
  491. }
  492. });
  493. HTMLSTR;
  494. //判断是否已经登录
  495. if ( !is_logged() ) {
  496. die(str_replace(
  497. array('【标题】', '【动作】'),
  498. array('请输入您第一次设置的密码!', '登录'),
  499. $first
  500. ));
  501. } else {
  502. echo $html;
  503. }
  504. 复制代码


    热门AI工具

    更多
    DeepSeek
    DeepSeek

    幻方量化公司旗下的开源大模型平台

    豆包大模型
    豆包大模型

    字节跳动自主研发的一系列大型语言模型

    通义千问
    通义千问

    阿里巴巴推出的全能AI助手

    腾讯元宝
    腾讯元宝

    腾讯混元平台推出的AI助手

    文心一言
    文心一言

    文心一言是百度开发的AI聊天机器人,通过对话可以生成各种形式的内容。

    讯飞写作
    讯飞写作

    基于讯飞星火大模型的AI写作工具,可以快速生成新闻稿件、品宣文案、工作总结、心得体会等各种文文稿

    即梦AI
    即梦AI

    一站式AI创作平台,免费AI图片和视频生成。

    ChatGPT
    ChatGPT

    最最强大的AI聊天机器人程序,ChatGPT不单是聊天机器人,还能进行撰写邮件、视频脚本、文案、翻译、代码等任务。

    相关专题

    更多
    pixiv网页版官网登录与阅读指南_pixiv官网直达入口与在线访问方法
    pixiv网页版官网登录与阅读指南_pixiv官网直达入口与在线访问方法

    本专题系统整理pixiv网页版官网入口及登录访问方式,涵盖官网登录页面直达路径、在线阅读入口及快速进入方法说明,帮助用户高效找到pixiv官方网站,实现便捷、安全的网页端浏览与账号登录体验。

    1142

    2026.02.13

    微博网页版主页入口与登录指南_官方网页端快速访问方法
    微博网页版主页入口与登录指南_官方网页端快速访问方法

    本专题系统整理微博网页版官方入口及网页端登录方式,涵盖首页直达地址、账号登录流程与常见访问问题说明,帮助用户快速找到微博官网主页,实现便捷、安全的网页端登录与内容浏览体验。

    371

    2026.02.13

    Flutter跨平台开发与状态管理实战
    Flutter跨平台开发与状态管理实战

    本专题围绕Flutter框架展开,系统讲解跨平台UI构建原理与状态管理方案。内容涵盖Widget生命周期、路由管理、Provider与Bloc状态管理模式、网络请求封装及性能优化技巧。通过实战项目演示,帮助开发者构建流畅、可维护的跨平台移动应用。

    245

    2026.02.13

    TypeScript工程化开发与Vite构建优化实践
    TypeScript工程化开发与Vite构建优化实践

    本专题面向前端开发者,深入讲解 TypeScript 类型系统与大型项目结构设计方法,并结合 Vite 构建工具优化前端工程化流程。内容包括模块化设计、类型声明管理、代码分割、热更新原理以及构建性能调优。通过完整项目示例,帮助开发者提升代码可维护性与开发效率。

    37

    2026.02.13

    Redis高可用架构与分布式缓存实战
    Redis高可用架构与分布式缓存实战

    本专题围绕 Redis 在高并发系统中的应用展开,系统讲解主从复制、哨兵机制、Cluster 集群模式及数据分片原理。内容涵盖缓存穿透与雪崩解决方案、分布式锁实现、热点数据优化及持久化策略。通过真实业务场景演示,帮助开发者构建高可用、可扩展的分布式缓存系统。

    114

    2026.02.13

    c语言 数据类型
    c语言 数据类型

    本专题整合了c语言数据类型相关内容,阅读专题下面的文章了解更多详细内容。

    77

    2026.02.12

    雨课堂网页版登录入口与使用指南_官方在线教学平台访问方法
    雨课堂网页版登录入口与使用指南_官方在线教学平台访问方法

    本专题系统整理雨课堂网页版官方入口及在线登录方式,涵盖账号登录流程、官方直连入口及平台访问方法说明,帮助师生用户快速进入雨课堂在线教学平台,实现便捷、高效的课程学习与教学管理体验。

    17

    2026.02.12

    豆包AI网页版入口与智能创作指南_官方在线写作与图片生成使用方法
    豆包AI网页版入口与智能创作指南_官方在线写作与图片生成使用方法

    本专题汇总豆包AI官方网页版入口及在线使用方式,涵盖智能写作工具、图片生成体验入口和官网登录方法,帮助用户快速直达豆包AI平台,高效完成文本创作与AI生图任务,实现便捷智能创作体验。

    863

    2026.02.12

    PostgreSQL性能优化与索引调优实战
    PostgreSQL性能优化与索引调优实战

    本专题面向后端开发与数据库工程师,深入讲解 PostgreSQL 查询优化原理与索引机制。内容包括执行计划分析、常见索引类型对比、慢查询优化策略、事务隔离级别以及高并发场景下的性能调优技巧。通过实战案例解析,帮助开发者提升数据库响应速度与系统稳定性。

    123

    2026.02.12

    热门下载

    更多
    网站特效
    /
    网站源码
    /
    网站素材
    /
    前端模板

    精品课程

    更多
    相关推荐
    /
    热门推荐
    /
    最新课程
    php初学者入门课程
    php初学者入门课程

    共10课时 | 0.7万人学习

    PHP基础入门课程
    PHP基础入门课程

    共33课时 | 2.2万人学习

    关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
    php中文网:公益在线php培训,帮助PHP学习者快速成长!
    关注服务号 技术交流群
    PHP中文网订阅号
    每天精选资源文章推送

    Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号