{"id":446,"date":"2016-12-15T18:16:48","date_gmt":"2016-12-15T10:16:48","guid":{"rendered":"http:\/\/writingbaby.com\/?p=133"},"modified":"2016-12-15T18:16:48","modified_gmt":"2016-12-15T10:16:48","slug":"share-a-single-file-online-code-text-editor-php-version","status":"publish","type":"post","link":"https:\/\/ihongchao.com\/post\/446\/","title":{"rendered":"\u5206\u4eab\u4e00\u4e2a\u5355\u6587\u4ef6\u5728\u7ebf\u6587\u672c\u7f16\u8f91\u5668\uff08PHP\u7248\uff09"},"content":{"rendered":"

\u6709\u7684\u65f6\u5019\u9700\u8981\u968f\u65f6\u968f\u5730\u7684\u5bf9\u9879\u76ee\u8fdb\u884c\u4fee\u6539\uff0c\u4f46\u662f\u767b\u5f55\u670d\u52a1\u5668\u5bf9\u4ee3\u7801\u8fdb\u884c\u4fee\u6539\u53c8\u592a\u9ebb\u70e6\u3002\u6709\u6ca1\u6709\u7b80\u4fbf\u7684\u65b9\u6cd5\u5462\uff1f\u7b54\u6848\u662f\uff1a\u6709\u3002\u5206\u4eab\u4e00\u4e2aPHP\u7248\u672c\u7684\u5728\u7ebf\u4ee3\u7801\u7f16\u8f91\u5668\u3002\u867d\u7136\u53ea\u6709\u4e00\u4e2a\u6587\u4ef6\uff0c\u4f46\u662f\u771f\u7684\u65e0\u6240\u4e0d\u80fd\uff01<\/p>\n

\u4f7f\u7528\u65b9\u6cd5<\/strong>\uff1a\u5c06\u4e00\u4e0b\u4ee3\u7801\u53e6\u5b58\u4e3a\u4e00\u4e2aPHP\u6587\u4ef6\uff0c\u4e0a\u4f20\u5230\u4f60\u7684\u7a7a\u95f4\u4e2d\uff0c\u7136\u540e\u901a\u8fc7\u6d4f\u89c8\u5668\u8bbf\u95ee\u3002\u7b2c\u4e00\u6b21\u4f7f\u7528\u9700\u8981\u8bbe\u7f6e\u5bc6\u7801\uff0c\u4ee5\u540e\u51ed\u7b2c\u4e00\u6b21\u8bbe\u7f6e\u7684\u5bc6\u7801\u767b\u5f55\u3002<\/p>\n

\u5df2\u77e5\u95ee\u9898<\/strong>\uff1a\u4f7f\u7528\u8f93\u5165\u6cd5\u8f93\u5165\u4e2d\u6587\u7684\u65f6\u5019\u9700\u8981\u6572\u51fb\u4e24\u6b21\u7a7a\u683c\u624d\u80fd\u663e\u793a\u4e2d\u6587\uff0c\u800c\u4e14\u8f93\u5165\u7684\u62fc\u97f3\u4e0d\u4f1a\u88ab\u66ff\u6362\u6389\uff0c\u9700\u8981\u624b\u52a8\u5220\u9664\u3002<\/p>\n

<?php\n\/**\n * \u5355\u6587\u4ef6\u7248\u5728\u7ebf\u4ee3\u7801\u7f16\u8f91\u5668 editor.php \u7248\u672c: v1.21\n * \n * \u5bc6\u7801\u52a0\u5bc6\u65b9\u5f0f: \n * md5(\u81ea\u8bbe\u5bc6\u7801+$ace) \/\/$ace\u4e3acdn\u955c\u50cf\u5730\u5740\n * \n * \u4f7f\u7528\u65b9\u6cd5: \n * 1.\u786e\u8ba4 $pwd \u53d8\u91cf\u503c\u4e3a false, \u4e0a\u4f20\u672c\u6587\u4ef6\u5230PHP\u7a7a\u95f4\u5e76\u8bbf\u95ee\n * 2.\u7b2c\u4e00\u6b21\u8bbf\u95ee\u63d0\u793a\u8bbe\u7f6e\u5bc6\u7801,\u8bbe\u7f6e\u5bc6\u7801\u5e76\u7262\u8bb0\n * 3.\u4f7f\u7528\u7b2c\u4e00\u6b21\u8bbe\u7f6e\u7684\u5bc6\u7801\u767b\u5f55\u540e,\u9ed8\u8ba4\u7f16\u8f91\u7684\u662f\u672cphp\u6587\u4ef6,\n * 4.\u672c\u6587\u4ef6\u662f\u7f16\u8f91\u5668\u6838\u5fc3\u6587\u4ef6,\u8bf7\u4e0d\u8981\u968f\u610f\u4fee\u6539\n * 5.\u4fdd\u5b58\u7f16\u8f91\u7684\u6587\u4ef6\u8bf7\u7528 Ctrl + S \u6309\u952e\u7ec4\u5408,\u7b49\u5f85\u6267\u884c\u7ed3\u679c\n * 6.\u4fdd\u5b58\u52a8\u4f5c\u6267\u884c\u540e\u8bf7\u52a1\u5fc5\u7b49\u5f85\u4fdd\u5b58\u6210\u529f\u4fe1\u606f\u8fd4\u56de\n * 7.\u91cd\u7f6e\u64cd\u4f5c\u4f1a\u4fee\u6539\u672c\u7a0b\u5e8f\u7684\u6587\u4ef6\u540d\uff0c\u4ee5\u9632\u4ed6\u4eba\u731c\u6d4b\u8def\u5f84\n * 8.\u5237\u65b0\u529f\u80fd\u4ec5\u662f\u5237\u65b0\u672c\u7a0b\u5e8f\u6587\u4ef6\uff0c\u4e0d\u80fd\u5237\u65b0\u5176\u4ed6\n * \n * \u5efa\u8bae\u5728 chrome \u6d4f\u89c8\u5668\u4e2d\u4f7f\u7528\u672c\u7f16\u8f91\u5668\n *\/\nsession_start();\n$curr_file = __FILE__; \/\/\u9ed8\u8ba4\u7f16\u8f91\u5f53\u524d\u6587\u4ef6\n$curr_file_path = str_replace(dirname(__FILE__), '', __FILE__);\n$pwd = false; \/\/\u5bc6\u7801\u521d\u59cb\u5316\u9ed8\u8ba4\u503c\u4e3a false\n\/\/$ace = 'http:\/\/cdn.staticfile.org\/ace\/1.1.3\/ace.js'; \/\/\u7f16\u8f91\u5668\u6838\u5fc3js\n\/\/$tip['core'] = 'http:\/\/cdn.staticfile.org\/alertify.js\/0.3.11\/alertify.core.min.css';\n\/\/$tip['css'] = 'http:\/\/cdn.staticfile.org\/alertify.js\/0.3.11\/alertify.default.min.css';\n\/\/$tip['js'] = 'http:\/\/cdn.staticfile.org\/alertify.js\/0.3.11\/alertify.min.js';\n\/\/$jquery = 'http:\/\/cdn.staticfile.org\/jquery\/2.1.1-rc2\/jquery.min.js';\n\n$ace = '\/\/lib.baomitu.com\/ace\/1.1.3\/ace.js'; \/\/\u7f16\u8f91\u5668\u6838\u5fc3js\n$tip['core'] = '\/\/lib.baomitu.com\/alertify.js\/0.3.11\/alertify.core.min.css';\n$tip['css'] = '\/\/lib.baomitu.com\/alertify.js\/0.3.11\/alertify.default.min.css';\n$tip['js'] = '\/\/lib.baomitu.com\/alertify.js\/0.3.11\/alertify.min.js';\n$jquery = '\/\/lib.baomitu.com\/jquery\/2.1.1-rc2\/jquery.min.js';\n \nif ( false !== $pwd ) {\n define('DEFAULT_PWD', $pwd);\n}\n \n\/\/\u6587\u4ef6\u540e\u7f00\u540d\u5bf9\u5e94\u7684\u8bed\u6cd5\u89e3\u6790\u5668\n$lng = array(\n 'as' => 'actionscript', 'js' => 'javascript',\n 'php' => 'php', 'css' => 'css', 'html' => 'html',\n 'htm' => 'html', 'ini' => 'ini', 'json' => 'json',\n 'jsp' => 'jsp', 'txt' => 'text', 'sql' => 'mysql',\n 'xml' => 'xml', 'yaml' => 'yaml', 'py' => 'python',\n 'md' => 'markdown', 'htaccess' => 'apache_conf',\n 'bat' => 'batchfile', 'go' => 'golang',\n);\n \n\/\/\u5224\u65ad\u7528\u6237\u662f\u5426\u767b\u5f55\nfunction is_logged() {\n $flag = false;\n if ( isset($_SESSION['pwd']) && defined('DEFAULT_PWD') ) {\n if ( $_SESSION['pwd'] === DEFAULT_PWD ) {\n $flag = true;\n }\n }\n return $flag;\n}\n \n\/\/\u91cd\u65b0\u8f7d\u5165\u5230\u672c\u9875\u9762\nfunction reload() {\n $file = pathinfo(__FILE__, PATHINFO_BASENAME);\n die(header(\"Location: {$file}\"));\n}\n \n\/\/\u5224\u65ad\u8bf7\u6c42\u662f\u5426\u662fajax\u8bf7\u6c42\nfunction is_ajax() {\n $flag = false;\n if ( isset($_SERVER['HTTP_X_REQUESTED_WITH']) ) {\n $flag = strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest';\n }\n return $flag;\n}\n \n\/\/\u9500\u6bc1SESSION\u548cCOOKIE\nfunction exterminate() {\n $_SESSION = array();\n foreach ( $_COOKIE as $key ) {\n setcookie($key, null);\n }\n session_destroy();\n $_COOKIE = array();\n return true;\n}\n \n\/\/\u83b7\u53d6\u4e00\u4e2a\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\u5217\u8868\nfunction list_dir($path, $type = 'array') {\n $flag = false;\n $lst = array('dir'=>array(), 'file'=>array());\n $base = !is_dir($path) ? dirname($path) : $path;\n $tmp = scandir($base);\n foreach ( $tmp as $k=>$v ) {\n \/\/\u8fc7\u6ee4\u6389\u4e0a\u7ea7\u76ee\u5f55,\u672c\u7ea7\u76ee\u5f55\u548c\u7a0b\u5e8f\u81ea\u8eab\u6587\u4ef6\u540d\n if ( !in_array($v, array('.', '..')) ) {\n $file = $full_path = rtrim($base, '\/').DIRECTORY_SEPARATOR.$v;\n if ( $full_path == __FILE__ ) {\n continue; \/\/\u5c4f\u853d\u81ea\u8eab\u6587\u4ef6\u4e0d\u5728\u5217\u8868\u51fa\u73b0\n }\n $file = str_replace(dirname(__FILE__), '', $file);\n $file = str_replace(\"\\\\\", '\/', $file); \/\/\u8fc7\u6ee4win\u4e0b\u7684\u8def\u5f84\n $file = str_replace('\/\/', '\/', $file); \/\/\u8fc7\u6ee4\u53cc\u659c\u6760\n if ( is_dir($full_path) ) {\n if ( 'html' === $type ) {\n $v = '<li class=\"dir\" path=\"'.$file\n .'\" onclick=\"load();\"><span>'.$v.'<\/span><\/li>';\n }\n array_push($lst['dir'], $v);\n } else {\n if ( 'html' === $type ) {\n $v = '<li class=\"file\" path=\"'.$file\n .'\" onclick=\"load()\"><span>'.$v.'<\/span><\/li>';\n }\n array_push($lst['file'], $v);\n }\n }\n }\n $lst = array_merge($lst['dir'], $lst['file']);\n $lst = array_filter($lst);\n $flag = $lst;\n if ( 'html' === $type ) {\n $flag = '<ul>'. implode('', $lst) .'<\/ul>';\n }\n return $flag;\n}\n \n\/\/\u9012\u5f52\u5220\u9664\u4e00\u4e2a\u975e\u7a7a\u76ee\u5f55\nfunction deldir($dir) {\n $dh = opendir($dir);\n while ( $file = readdir($dh) ) {\n if ( $file != '.' && $file != '..' ) {\n $fullpath = $dir.'\/'.$file;\n if ( !is_dir($fullpath) ) {\n unlink($fullpath);\n } else {\n deldir($fullpath);\n }\n }\n }\n return rmdir($dir);\n}\n \n\/\/\u9000\u51fa\u767b\u5f55\nif ( isset($_GET['logout']) ) {\n if ( exterminate() ) {\n reload();\n }\n}\n \n\/\/ajax\u8f93\u51fa\u6587\u4ef6\u5185\u5bb9\nif ( is_logged() && is_ajax() && isset($_POST['file']) ) {\n $file = dirname(__FILE__).$_POST['file'];\n $ext = pathinfo($file, PATHINFO_EXTENSION);\n $mode = isset($lng[$ext]) ? $lng[$ext] : false;\n die(json_encode(array(\n 'file' => $file, 'html' => file_get_contents($file),\n 'mode' => $mode, \n )));\n}\n \n\/\/ajax\u8f93\u51fa\u76ee\u5f55\u5217\u8868\nif ( is_logged() && is_ajax() && isset($_POST['dir']) ) {\n $dir = dirname(__FILE__).$_POST['dir'];\n $list_dir = list_dir($dir, 'html');\n die(json_encode(array(\n 'dir' => $dir, 'html' => $list_dir,\n )));\n}\n \n\/\/ajax\u4fdd\u5b58\u6587\u4ef6\nif ( is_logged() && is_ajax() && isset($_POST['action']) ) {\n $arr = array('result'=>'error', 'msg'=>'\u6587\u4ef6\u4fdd\u5b58\u5931\u8d25\uff01');\n $content = $_POST['content'];\n if ( 'save_file' === $_POST['action'] ) {\n if ( isset($_POST['file_path']) ) {\n $file = dirname(__FILE__).$_POST['file_path'];\n } else {\n $file = __FILE__;\n }\n file_put_contents($file, $content);\n $arr['result'] = 'success';\n $arr['msg'] = '\u4fdd\u5b58\u6210\u529f\uff01';\n }\n die(json_encode($arr));\n}\n \n\/\/ajax\u5220\u9664\u6587\u4ef6\u6216\u6587\u4ef6\u5939\nif ( is_logged() && is_ajax() && isset($_POST['del']) ) {\n $path = dirname(__FILE__).$_POST['del'];\n $arr = array('result'=>'error', 'msg'=>'\u5220\u9664\u64cd\u4f5c\u5931\u8d25\uff01');\n if ( $_POST['del'] && $path ) {\n $flag = is_dir($path) ? deldir($path) : unlink($path);\n if ( $flag ) {\n $arr['msg'] = '\u5220\u9664\u64cd\u4f5c\u6210\u529f\uff01';\n $arr['result'] = 'success';\n }\n }\n die(json_encode($arr));\n}\n \n\/\/ajax\u65b0\u5efa\u6587\u4ef6\u6216\u6587\u4ef6\u5939\nif ( is_logged() && is_ajax() && isset($_POST['create']) ) {\n $flag = false;\n $arr = array('result'=>'error', 'msg'=>'\u64cd\u4f5c\u5931\u8d25\uff01');\n if ( isset($_POST['target']) ) {\n $target = dirname(__FILE__).$_POST['target'];\n $target = is_dir($target) ? $target : dirname($target);\n }\n if ( $_POST['create'] && $target ) {\n $base_name = pathinfo($_POST['create'], PATHINFO_BASENAME);\n $exp = explode('.', $base_name);\n $full_path = $target.'\/'.$base_name;\n $new_path = str_replace(dirname(__FILE__), '', $full_path);\n if ( count($exp) > 1 && isset($lng[array_pop($exp)]) ) {\n file_put_contents($full_path, '');\n $arr['result'] = 'success';\n $arr['msg'] = '\u65b0\u5efa\u6587\u4ef6\u6210\u529f\uff01';\n $arr['type'] = 'file';\n } else {\n mkdir($full_path, 0777, true);\n $arr['result'] = 'success';\n $arr['msg'] = '\u65b0\u5efa\u76ee\u5f55\u6210\u529f\uff01';\n $arr['type'] = 'dir';\n }\n if ( $base_name && $new_path ) {\n $arr['new_name'] = $base_name;\n $arr['new_path'] = $new_path;\n }\n }\n die(json_encode($arr));\n}\n \n\/\/ajax\u91cd\u547d\u540d\u6587\u4ef6\u6216\u6587\u4ef6\u5939\nif ( is_logged() && is_ajax() && isset($_POST['rename']) ) {\n $arr = array('result'=>'error', 'msg'=>'\u91cd\u547d\u540d\u64cd\u4f5c\u5931\u8d25\uff01');\n if ( isset($_POST['target']) ) {\n $target = dirname(__FILE__).$_POST['target'];\n }\n if ( $_POST['rename'] ) {\n $base_name = pathinfo($_POST['rename'], PATHINFO_BASENAME);\n if ( $base_name ) {\n $rename = dirname($target).'\/'.$base_name;\n $new_path = str_replace(dirname(__FILE__), '', $rename);\n }\n }\n if ( $rename && $target && rename($target, $rename) ) {\n $arr['new_name'] = $base_name;\n $arr['new_path'] = $new_path;\n $arr['msg'] = '\u91cd\u547d\u540d\u64cd\u4f5c\u6210\u529f\uff01';\n $arr['result'] = 'success';\n }\n if ( $target == __FILE__ ) {\n $arr['redirect'] = $new_path;\n }\n die(json_encode($arr));\n}\n \n\/\/\u83b7\u53d6\u4ee3\u7801\u6587\u4ef6\u5185\u5bb9\n$code = file_get_contents($curr_file);\n$tree = '<ul id=\"dir_tree\">\n <li class=\"dir\" path=\"\/\" onclick=\"load()\">ROOT'.list_dir($curr_file, 'html').'<\/li>\n<\/ul>';\n \n\/\/\u767b\u9646\u548c\u8bbe\u7f6e\u5bc6\u7801\u5171\u7528\u6a21\u7248\n$first = <<<HTMLSTR\n<!DOCTYPE html>\n<html><head><meta charset=\"UTF-8\">\n<title>\u3010\u6807\u9898\u3011<\/title>\n<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\">\n<style type=\"text\/css\" media=\"screen\">\nbody {\n overflow: hidden; background-color: #2D2D2D; color: #CCCCCC; font-size: 12px; margin: 0;\n font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;\n}\nform { display: none; position: absolute; }\nform h5 { font-size: 14px; font-weight: normal; margin: 0; line-height: 2em; }\nform input {\n color: #fff; border: 1px solid #369; border-radius: 3px; background: #333; height: 22px;\n line-height: 1.6em; width: 125px; margin-right: 5px; vertical-align: middle;\n}\nform button {\n line-height: 1.6em; border: 1px solid #369; border-radius: 3px;\n background: #369; color: #fff; vertical-align: middle;\n}\n<\/style>\n<link rel=\"stylesheet\" href=\"{$tip['core']}\" \/>\n<link rel=\"stylesheet\" href=\"{$tip['css']}\" \/>\n<\/head>\n<body>\n <form method=\"post\">\n <input name=\"pwd\" type=\"password\" \/><button type=\"submit\">\u3010\u52a8\u4f5c\u3011<\/button>\n <\/form>\n <script src=\"{$jquery}\" type=\"text\/javascript\" charset=\"utf-8\"><\/script>\n <script src=\"{$ace}\" type=\"text\/javascript\" charset=\"utf-8\"><\/script>\n <script src=\"{$tip['js']}\" type=\"text\/javascript\"><\/script>\n <script type=\"text\/javascript\">\n var editor = false;\n $(function(){\n $('form').prepend('<h5>'+ document.title +'<\/h5>');\n $('form').css({\n left: ($(window).width()-$('form').width())\/2,\n top: ($(window).height()-$('form').height())\/2\n });\n $('form').show();\n });\n <\/script>\n<\/body><\/html>\nHTMLSTR;\n \n\/\/\u5224\u65ad\u662f\u5426\u7b2c\u4e00\u6b21\u767b\u5f55\nif ( false === $pwd && empty($_POST) ) {\n die(str_replace(\n array('\u3010\u6807\u9898\u3011', '\u3010\u52a8\u4f5c\u3011'),\n array('\u7b2c\u4e00\u6b21\u4f7f\u7528\uff0c\u8bf7\u5148\u8bbe\u7f6e\u5bc6\u7801\uff01', '\u8bbe\u7f6e'),\n $first\n ));\n}\n \n\/\/\u7b2c\u4e00\u6b21\u8bbe\u7f6e\u767b\u5f55\u5bc6\u7801\nif ( false === $pwd && !empty($_POST) ) {\n if ( isset($_POST['pwd']) && strlen($_POST['pwd']) ) {\n $pwd = $_SESSION['pwd'] = md5($_POST['pwd'].$ace);\n $code = preg_replace('#\\$pwd = false;#', '$pwd = \"'.$pwd.'\";', $code, 1);\n file_put_contents($curr_file, $code);\n } else {\n reload();\n }\n}\n \n\/\/\u7528\u6237\u767b\u5f55\u9a8c\u8bc1\nif ( false !== $pwd && !empty($_POST) ) {\n $tmp = md5($_POST['pwd'].$ace);\n if ( $tmp && $pwd && $tmp === $pwd ) {\n $_SESSION['pwd'] = $pwd;\n reload();\n }\n}\n \n\/\/\u5904\u7406\u4e00\u4e0bhtml\u5b9e\u4f53\n$code = htmlspecialchars($code);\n \n$dir_icon = str_replace(array(\"\\r\\n\", \"\\r\", \"\\n\"), '',\n'data:image\/jpg;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAANCAYAAACgu+4kAAAAGXRFWHRTb2Z0d2\nFyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQVJREFUeNqkkk1uwjAQhd84bsNP1FUXLCtu0H3XPSoX4Qrd9wR\nsCjQEcIY3DiiJUYiqRhp5Mra\/92YSUVVgLSW49B7H+NApRh75XkHfFoCG+02tyflUeQTw2y9UYYP8cCStc9SM\nPeVA\/Sy6Dw555q3au1z+EhBYk1cgO7OSNdaFNT0x5sCkYDha0WPiHZgVqPzLO+8seai6E2jed42bCL06tNyEH\nAX9kv3jh3HqH7BctFWLMOmAbcg05mHK5+sQpd1HYijN47zcDUCShGEHtzxtwQS9WTcAQmJROrJDLXQB9s1Tu6\nMtRED4bwsHLnUzxEeKac3+GeP6eo8yevhjC3F1qC4CDAAl3HwuyNAIdwAAAABJRU5ErkJggg==');\n \n$file_icon = str_replace(array(\"\\r\\n\", \"\\r\", \"\\n\"), '',\n'data:image\/jpg;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAQCAYAAADJViUEAAAAGXRFWHRTb2Z0d2\nFyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAS1JREFUeNqMU01KxkAMTaez7aYbNwreQdBzeopS6EXEW+jug7Z\nC6X+\/iUloSr6xioFHJkPee5mUJgBwT7gjpPB3XAgfiBjs5dOyLF\/btl0pkEFngdbzPGNRFK\/U+0hwJAAMjmcm\nDsOA4zge6Pseu67DpmlEqK5rLMvyRkDJor6uq2SGktu2FfdpmpANqqoSASYnO\/kthABJkoCOxCASkCBkWSYuQ\nqCeNE1fqHz3fMkXzjnJ2sRinL33QBNIzWJ5nh\/L8npQohVTJwYTyfFm\/d6Oo2HGE8ffwseuZ1PEjhrOutmsRF\n0iC8QmPibEtT4hftrhHI95JqJT\/HC2JOt0to+zN6MVsZ\/oZKqwmyCTA33DkbN1sws0i+Pega6v0kd42H9JB\/8\nLJl5I6PNbgAEAa9MP7QWoNLoAAAAASUVORK5CYII=');\n \n$loading = str_replace(array(\"\\r\\n\", \"\\r\", \"\\n\"), '',\n'data:image\/gif;base64,R0lGODlhFAAUALMIAPh2AP+TMsZiALlcAKNOAOp4ANVqAP+PFv\/\/\/wAAAAAAAA\nAAAAAAAAAAAAAAAAAAACH\/C05FVFNDQVBFMi4wAwEAAAAh+QQFCgAIACwAAAAAFAAUAAAEUxDJSau9iBDMteb\nTMEjehgTBJYqkiaLWOlZvGs8WDO6UIPCHw8TnAwWDEuKPcxQml0Ynj2cwYACAS7VqwWItWyuiUJB4s2AxmWxG\ng9bl6YQtl0cAACH5BAUKAAgALAEAAQASABIAAAROEMkpx6A4W5upENUmEQT2feFIltMJYivbvhnZ3Z1h4FMQI\nDodz+cL7nDEn5CH8DGZhcLtcMBEoxkqlXKVIgAAibbK9YLBYvLtHH5K0J0IACH5BAUKAAgALAEAAQASABIAAA\nROEMkphaA4W5upMdUmDQP2feFIltMJYivbvhnZ3V1R4BNBIDodz+cL7nDEn5CH8DGZAMAtEMBEoxkqlXKVIg4\nHibbK9YLBYvLtHH5K0J0IACH5BAUKAAgALAEAAQASABIAAAROEMkpjaE4W5tpKdUmCQL2feFIltMJYivbvhnZ\n3R0A4NMwIDodz+cL7nDEn5CH8DGZh8ONQMBEoxkqlXKVIgIBibbK9YLBYvLtHH5K0J0IACH5BAUKAAgALAEAA\nQASABIAAAROEMkpS6E4W5spANUmGQb2feFIltMJYivbvhnZ3d1x4JMgIDodz+cL7nDEn5CH8DGZgcBtMMBEox\nkqlXKVIggEibbK9YLBYvLtHH5K0J0IACH5BAUKAAgALAEAAQASABIAAAROEMkpAaA4W5vpOdUmFQX2feFIltM\nJYivbvhnZ3V0Q4JNhIDodz+cL7nDEn5CH8DGZBMJNIMBEoxkqlXKVIgYDibbK9YLBYvLtHH5K0J0IACH5BAUK\nAAgALAEAAQASABIAAAROEMkpz6E4W5tpCNUmAQD2feFIltMJYivbvhnZ3R1B4FNRIDodz+cL7nDEn5CH8DGZg\n8HNYMBEoxkqlXKVIgQCibbK9YLBYvLtHH5K0J0IACH5BAkKAAgALAEAAQASABIAAAROEMkpQ6A4W5spIdUmHQ\nf2feFIltMJYivbvhnZ3d0w4BMAIDodz+cL7nDEn5CH8DGZAsGtUMBEoxkqlXKVIgwGibbK9YLBYvLtHH5K0J0\nIADs=');\n \n\/\/\u7f16\u8f91\u5668\u6a21\u7248\n$html = <<<HTMLSTR\n<!DOCTYPE html>\n<html><head><meta charset=\"UTF-8\">\n<title>ACE\u4ee3\u7801\u7f16\u8f91\u5668<\/title>\n<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\">\n<style type=\"text\/css\" media=\"screen\">\na { text-decoration: none; }\nbody {\n overflow: hidden; background-color: #2D2D2D; font-size: 12px;\n font-family: 'Consolas', 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;\n scrollbar-arrow-color: #ccc; scrollbar-base-color: #333;\n scrollbar-dark-shadow-color: #00ffff; scrollbar-track-color: #272822;\n scrollbar-highlight-color: #272822; scrollbar-3d-light-color: #272822;\n scrollbar-face-color: #2D2D2D; scrollbar-shadow-color: #333;\n}\n::-webkit-scrollbar { width:5px; height:6px; background-color:#444; }\n::-webkit-scrollbar:hover { background-color:#444; }\n::-webkit-scrollbar-thumb:hover { min-height:5px; min-width:5px; background-color: #AAA; }\n::-webkit-scrollbar-thumb:active { -webkit-border-radius:20px; background-color: #AAA; }\n::-webkit-scrollbar-thumb {\n min-height:5px; min-width:5px; -webkit-border-radius:20px; \n ::-webkit-border-radius:1px; background-color: #AAA;\n}\nbody > pre { color: #666; }\n#sider { margin: 0; position: absolute; top: 25px; bottom: 0; left: 0; right: 85%; }\n#editor { margin: 0; position: absolute; top: 0; bottom: 0; left: 15%; right: 0; }\n#dir_tree { margin:0; padding: 0; height: 100%; overflow: auto; position: relative; left: 5px; } \n#dir_tree, #dir_tree ul, #dir_tree li { margin: 0; padding: 0; list-style: none inside; }\n#dir_tree ul { padding-left: 20px; position: relative; }\n#dir_tree li { text-indent: 2em; line-height: 1.6em; cursor: default; color: #ccc; }\n#dir_tree li.hover > span, #dir_tree li:hover > span { color: #66D9EF; }\n#dir_tree li#on > span { color: red; }\n#dir_tree li.dir { background: url({$dir_icon}) no-repeat 3px 3px; }\n#dir_tree li.file { background: url({$file_icon}) no-repeat 3px 0; }\n#dir_tree li.loading { background: url({$loading}) no-repeat 3px 0; }\n#logout { position: absolute; top: 0; left: 0; }\n#logout a { display: inline-block; color: #aaa; line-height: 25px; padding: 0 4px; }\n#logout a:hover { background: #000; color: #ddd; }\n#contextmenu { position: absolute; top: 0; left: 0; background: #fff; color: #333; border: 1px solid #000; padding: 1px; }\n#contextmenu span { display: block; line-height: 24px; text-indent: 20px; width: 80px; cursor: default; }\n#contextmenu span:hover { background-color: #369; color: #fff; }\n#alertify .alertify-message, #alertify .alertify-message {\n text-align: left !important; text-indent: 0; font-weight: bold; font-size: 16px;\n}\n#alertify .alertify-dialog, #alertify .alertify-dialog {\n font-family: 'Consolas'; padding: 10px !important; color: #333 !important;\n}\n#alertify .alertify-button { \n border-radius: 3px !important; font-weight: normal !important; \n font-size: 14px !important; padding: 3px 15px !important;\n}\n.alertify-buttons { text-align: right !important; }\n<\/style>\n<link rel=\"stylesheet\" href=\"{$tip['core']}\" \/>\n<link rel=\"stylesheet\" href=\"{$tip['css']}\" \/>\n<\/head><body>\n<div id=\"logout\">\n <a href=\"javascript:void(0);\">\u4fdd\u5b58<\/a>\n <a href=\"javascript:void(0);\">\u5237\u65b0<\/a>\n <a href=\"javascript:void(0);\">\u91cd\u7f6e<\/a>\n <a href=\"?logout\">\u9000\u51fa<\/a>\n<\/div>\n<div id=\"sider\">{$tree}<\/div><pre id=\"editor\">{$code}<\/pre>\n<script src=\"{$jquery}\" type=\"text\/javascript\" charset=\"utf-8\"><\/script>\n<script src=\"{$ace}\" type=\"text\/javascript\" charset=\"utf-8\"><\/script>\n<script src=\"{$tip['js']}\" type=\"text\/javascript\"><\/script>\n<script type=\"text\/javascript\">\nvar load = false;\nvar curr_file = false;\nwindow.location.hash = '';\nalertify.set({delay: 1000}); \/\/n\u79d2\u540e\u81ea\u52a8\u6d88\u5931\nalertify.set({labels: {ok:'\u786e\u5b9a',cancel:'\u53d6\u6d88'}});\nvar editor = false;\n$(function(){\n \/\/\u5b9e\u4f8b\u5316\u4ee3\u7801\u7f16\u8f91\u5668\n editor = ace.edit(\"editor\");\n \/\/\u8bbe\u7f6e\u7f16\u8f91\u5668\u7684\u8bed\u6cd5\u548c\u9ad8\u4eae\n editor.setTheme(\"ace\/theme\/monokai\");\n editor.getSession().setMode(\"ace\/mode\/php\");\n \/\/\u8bbe\u7f6e\u7f16\u8f91\u5668\u81ea\u52a8\u6362\u884c\n editor.getSession().setWrapLimitRange(null, null);\n editor.getSession().setUseWrapMode(true);\n \/\/\u4e0d\u663e\u793a\u5782\u76f4\u886c\u7ebf\n editor.renderer.setShowPrintMargin(false);\n \/\/editor.setReadOnly(true); \/\/\u8bbe\u7f6e\u7f16\u8f91\u5668\u4e3a\u53ea\u8bfb\n \/\/editor.gotoLine(325); \/\/\u8df3\u8f6c\u5230\u6307\u5b9a\u884c\n \/\/\u4f7f\u7f16\u8f91\u5668\u83b7\u5f97\u8f93\u5165\u7126\u70b9\n editor.focus();\n \/\/\u7ed1\u5b9a\u7ec4\u5408\u6309\u952e\n var commands = editor.commands;\n commands.addCommand({\n name: \"save\",\n bindKey: {win: \"Ctrl-S\", mac: \"Command-S\"},\n exec: save_file\n });\n \/\/\u4fdd\u5b58\u52a8\u4f5c\n function save_file() {\n if ( false == editor ) { return false; }\n var obj = {\n content: editor.getValue(),\n action: 'save_file'\n };\n if ( false !== curr_file ) {\n obj.file_path = curr_file;\n }\n alertify.log('\u6b63\u5728\u4fdd\u5b58...');\n $.post(window.location.href, obj, function(data){\n if ( data.msg && 'success' == data.result ) {\n alertify.success(data.msg);\n } else {\n alertify.error(data.msg);\n }\n }, 'json');\n }\n \/\/\u52a0\u8f7d\u76ee\u5f55\u5217\u8868\u6216\u6587\u4ef6\n load = function(ele) {\n var curr = $(event.srcElement);\n if ( ele ) { curr = ele; }\n if ( curr.is('span') ) { curr = curr.parent('li'); }\n $('#dir_tree #on').removeAttr('id');\n curr.attr('id', 'on');\n var type = curr.attr('class');\n var path = curr.attr('path');\n window.location.hash = path;\n if ( 'file' === type ) {\n alertify.log('\u6b63\u5728\u52a0\u8f7d...');\n curr.addClass('loading');\n $.post(window.location.href, {file:path}, function(data){\n curr.removeClass('loading');\n if ( data.mode ) {\n editor.getSession().setMode(\"ace\/mode\/\"+data.mode);\n }\n \/\/\u6ce8\u610f\uff0c\u7a7a\u6587\u4ef6\u5e94\u5f53\u5141\u8bb8\u7f16\u8f91\n if ( true || data.html ) {\n curr.attr('disabled', 'disabled');\n curr_file = path; \/\/\u5f53\u524d\u7f16\u8f91\u7684\u6587\u4ef6\u8def\u5f84\n \/\/\u52a8\u6001\u8d4b\u503c\u7f16\u8f91\u5668\u4e2d\u7684\u5185\u5bb9\n editor.session.doc.setValue(data.html);\n editor.renderer.scrollToRow(0); \/\/\u6eda\u52a8\u5230\u7b2c\u4e00\u884c\n editor.focus(); \/\/\u7f16\u8f91\u5668\u83b7\u5f97\u7126\u70b9\n setTimeout(function(){\n editor.gotoLine(0);\n }, 800);\n }\n }, 'json');\n event.stopPropagation();\n event.preventDefault();\n return false;\n }\n if ( 'dir' === type ) {\n if ( curr.attr('loaded') ) {\n curr.children('ul').toggle();\n event.stopPropagation();\n event.preventDefault();\n return false;\n } else {\n curr.attr('loaded', 'yes');\n }\n alertify.log('\u6b63\u5728\u52a0\u8f7d...');\n curr.addClass('loading');\n $.post(window.location.href, {dir:path}, function(data){\n curr.find('ul').remove();\n curr.removeClass('loading');\n if ( data.html ) {\n curr.append(data.html);\n }\n }, 'json');\n }\n return false;\n }\n \/\/\u7ed1\u5b9a\u53f3\u952e\u83dc\u5355\n $('#sider').bind('contextmenu', function(e){\n var path = false;\n var target = $(event.srcElement);\n if ( target.is('span') ) {\n target = target.parent('li');\n }\n if ( target.attr('path') ) {\n path = target.attr('path');\n } else {\n return false;\n }\n target.addClass('hover');\n var right_menu = $('#contextmenu');\n if ( !right_menu.get(0) ) {\n var timer = false;\n right_menu = $('<div id=\"contextmenu\"><\/div>');\n right_menu.hover(function(){\n if ( timer ) { clearTimeout(timer); }\n }, function(){\n timer = setTimeout(function(){\n hide_menu(right_menu);\n }, 500);\n });\n $('body').append(right_menu);\n }\n if ( path ) {\n right_menu.html('');\n var menu = $('<span>\u65b0\u5efa<\/span><span>\u6d4f\u89c8<\/span><span>\u91cd\u547d\u540d<\/span><span>\u5220\u9664<\/span>');\n right_menu.append(menu);\n menu_area(right_menu, {left: e.pageX, top: e.pageY});\n right_menu.find('span').click(function(){\n switch ( $(this).text() ) {\n case '\u65b0\u5efa' : create_new(target, path); break;\n case '\u6d4f\u89c8' : preview(target, path); break;\n case '\u91cd\u547d\u540d' : re_name(target, path); break;\n case '\u5220\u9664' : del_file(target, path); break;\n }\n hide_menu(right_menu);\n });\n }\n path ? right_menu.show() : hide_menu(right_menu);\n return false;\n });\n \/\/\u9690\u85cf\u53f3\u952e\u83dc\u5355\n function hide_menu(menu) {\n $('#sider li.hover').removeClass('hover');\n if ( menu ) {\n menu.hide();\n }\n }\n \/\/\u53f3\u952e\u83dc\u5355\u533a\u57df\n function menu_area(menu, cfg) {\n if ( menu && cfg ) {\n var w = $('#sider').width() - menu.width();\n var h = $('#sider').height() - menu.height();\n if ( cfg.left > w ) { cfg.left = w; }\n if ( cfg.top > h ) { cfg.top = h; }\n menu.css(cfg);\n }\n }\n \/\/\u4fdd\u5b58\u6309\u94ae\n $('#logout>a:contains(\"\u4fdd\u5b58\")').click(function(){\n save_file();\n return false;\n });\n \/\/\u5237\u65b0\u6309\u94ae\n $('#logout>a:contains(\"\u5237\u65b0\")').click(function(){\n window.location.href = window.location.pathname;\n return false;\n });\n \/\/\u91cd\u7f6e\u6309\u94ae\n $('#logout>a:contains(\"\u91cd\u7f6e\")').click(function(){\n alertify.confirm('\u662f\u5426\u4fee\u6539 {$curr_file_path} \u7a0b\u5e8f\u6587\u4ef6\u540d\uff1f', function (e) {\n if ( !e ) { return 'cancel'; }\n re_name($('<a>'), '{$curr_file_path}');\n });\n return false;\n });\n \/\/\u65b0\u5efa\u64cd\u4f5c\n function create_new(obj, path) {\n if ( !obj || !path ) { return false; }\n alertify.prompt('\u8bf7\u8f93\u5165\u65b0\u5efa\u6587\u4ef6\u6216\u6587\u4ef6\u5939\u540d\uff1a', function (e, str) {\n if ( !e || !str ) { return false; }\n alertify.log('\u6b63\u5728\u64cd\u4f5c\u4e2d...');\n $('#dir_tree #on').removeAttr('loaded').removeAttr('id');\n $.post(window.location.href, {create:str,target:path}, function(data){\n if ( data.msg && 'success' == data.result ) {\n alertify.success(data.msg);\n if ( obj.attr('class') == 'dir' ) {\n load(obj); \/\/\u91cd\u65b0\u52a0\u8f7d\u5b50\u8282\u70b9\n } else {\n load(obj.parent().parent());\n }\n } else {\n alertify.error(data.msg);\n }\n }, 'json');\n });\n }\n \/\/\u6d4f\u89c8\u64cd\u4f5c\n function preview(obj, path) {\n if ( !obj || !path ) { return false; }\n window.open(path, '_blank');\n }\n \/\/\u91cd\u547d\u540d\n function re_name(obj, path) {\n if ( !obj || !path ) { return false; }\n alertify.prompt('\u91cd\u547d\u540d '+path+' \u4e3a\uff1a', function (e, str) {\n if ( !e || !str ) { return false; }\n alertify.log('\u6b63\u5728\u64cd\u4f5c\u4e2d...');\n $.post(window.location.href, {rename:str,target:path}, function(data){\n if ( data.msg && 'success' == data.result ) {\n alertify.success(data.msg);\n if ( data.redirect ) {\n window.location.href = data.redirect;\n }\n if ( data.new_name ) {\n obj.children('span').first().text(data.new_name);\n obj.attr('path', data.new_path);\n }\n } else {\n alertify.error(data.msg);\n }\n }, 'json');\n });\n }\n \/\/\u5220\u9664\u6587\u4ef6\u52a8\u4f5c\n function del_file(obj, path) {\n if ( !obj || !path ) { return false; }\n alertify.confirm('\u60a8\u786e\u5b9a\u8981\u5220\u9664\uff1a'+path+' \u5417\uff1f', function (e) {\n if ( !e ) { return 'cancel'; }\n alertify.log('\u6b63\u5728\u5220\u9664\u4e2d...');\n $.post(window.location.href, {del:path}, function(data){\n if ( data.msg && 'success' == data.result ) {\n alertify.success(data.msg);\n obj.remove();\n } else {\n alertify.error(data.msg);\n }\n }, 'json');\n });\n }\n});\n<\/script>\n<\/body><\/html>\nHTMLSTR;\n \n\/\/\u5224\u65ad\u662f\u5426\u5df2\u7ecf\u767b\u5f55\nif ( !is_logged() ) {\n die(str_replace(\n array('\u3010\u6807\u9898\u3011', '\u3010\u52a8\u4f5c\u3011'),\n array('\u8bf7\u8f93\u5165\u60a8\u7b2c\u4e00\u6b21\u8bbe\u7f6e\u7684\u5bc6\u7801\uff01', '\u767b\u5f55'),\n $first\n )); \n} else {\n echo $html;\n}\n?><\/code><\/pre>\n

 <\/p>\n","protected":false},"excerpt":{"rendered":"

\u6709\u7684\u65f6\u5019\u9700\u8981\u968f\u65f6\u968f\u5730\u7684\u5bf9\u9879\u76ee\u8fdb\u884c\u4fee\u6539\uff0c\u4f46\u662f\u767b\u5f55\u670d\u52a1\u5668\u5bf9\u4ee3\u7801\u8fdb\u884c\u4fee\u6539\u53c8\u592a\u9ebb\u70e6\u3002\u6709\u6ca1\u6709\u7b80\u4fbf\u7684\u65b9\u6cd5\u5462\uff1f\u7b54\u6848\u662f\uff1a\u6709\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28],"tags":[],"_links":{"self":[{"href":"https:\/\/ihongchao.com\/wp-json\/wp\/v2\/posts\/446"}],"collection":[{"href":"https:\/\/ihongchao.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ihongchao.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ihongchao.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ihongchao.com\/wp-json\/wp\/v2\/comments?post=446"}],"version-history":[{"count":0,"href":"https:\/\/ihongchao.com\/wp-json\/wp\/v2\/posts\/446\/revisions"}],"wp:attachment":[{"href":"https:\/\/ihongchao.com\/wp-json\/wp\/v2\/media?parent=446"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ihongchao.com\/wp-json\/wp\/v2\/categories?post=446"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ihongchao.com\/wp-json\/wp\/v2\/tags?post=446"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}