Skip to content

Commit 9422eff

Browse files
committed
增加HTML编辑器
1 parent 86d7398 commit 9422eff

File tree

255 files changed

+28247
-11
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

255 files changed

+28247
-11
lines changed

app.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ handlers:
1414
- url: /img
1515
static_dir: static/img
1616

17+
- url: /editor
18+
static_dir: static/editor
19+
1720
- url: /bdsitemap.txt
1821
static_files: static/bdsitemap.txt
22+
upload: static/bdsitemap.txt
1923

2024
- url: /favicon.ico
2125
static_files: static/favicon.ico

gorbled/index.go

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package gorbled
33
import (
44
"net/http"
55
"strconv"
6-
76
"appengine"
87
"appengine/datastore"
98
)

gorbled/page.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ type PageData struct {
2525

2626
const (
2727
// Folder setting
28-
STATIC_FOLDER = "gorbled/static/html/"
29-
LAYOUT_FOLDER = "gorbled/static/html/layouts/"
28+
STATIC_FOLDER = "static/html/"
29+
LAYOUT_FOLDER = "static/html/layouts/"
3030

3131
// Default layout setting
3232
DEFAULT_LAYOUT = "column2"

static/editor/asp.net/README.txt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
KindEditor ASP.NET
2+
3+
本ASP.NET程序是演示程序,建议不要直接在实际项目中使用。
4+
如果您确定直接使用本程序,使用之前请仔细确认相关安全设置。
5+
6+
使用方法:
7+
8+
1. 解压zip文件,将所有文件复制到IIS的wwwroot/kindeditor目录下。
9+
10+
2. 将kindeditor/asp.net/bin目录下的dll文件复制到wwwroot/bin目录下。
11+
12+
3. 打开浏览器,输入http://localhost:[P0RT]/kindeditor/asp.net/demo.aspx。

static/editor/asp.net/bin/LitJSON.dll

48.5 KB
Binary file not shown.

static/editor/asp.net/demo.aspx

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<%@ Page Language="C#" AutoEventWireup="true" validateRequest="false" %>
2+
3+
<script runat="server">
4+
protected void Page_Load(object sender, EventArgs e)
5+
{
6+
this.Label1.Text = Request.Form["content1"];
7+
}
8+
9+
</script>
10+
11+
<!doctype html>
12+
13+
<html>
14+
<head runat="server">
15+
<meta charset="utf-8" />
16+
<title>KindEditor ASP.NET</title>
17+
<link rel="stylesheet" href="../themes/default/default.css" />
18+
<link rel="stylesheet" href="../plugins/code/prettify.css" />
19+
<script charset="utf-8" src="../kindeditor.js"></script>
20+
<script charset="utf-8" src="../lang/zh_CN.js"></script>
21+
<script charset="utf-8" src="../plugins/code/prettify.js"></script>
22+
<script>
23+
KindEditor.ready(function(K) {
24+
var editor1 = K.create('#content1', {
25+
cssPath : '../plugins/code/prettify.css',
26+
uploadJson : '../asp.net/upload_json.ashx',
27+
fileManagerJson : '../asp.net/file_manager_json.ashx',
28+
allowFileManager : true,
29+
afterCreate : function() {
30+
var self = this;
31+
K.ctrl(document, 13, function() {
32+
self.sync();
33+
K('form[name=example]')[0].submit();
34+
});
35+
K.ctrl(self.edit.doc, 13, function() {
36+
self.sync();
37+
K('form[name=example]')[0].submit();
38+
});
39+
}
40+
});
41+
prettyPrint();
42+
});
43+
</script>
44+
</head>
45+
<body>
46+
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
47+
<form id="example" runat="server">
48+
<textarea id="content1" cols="100" rows="8" style="width:700px;height:200px;visibility:hidden;" runat="server"></textarea>
49+
<br />
50+
<asp:Button ID="Button1" runat="server" Text="提交内容" /> (提交快捷键: Ctrl + Enter)
51+
</form>
52+
</body>
53+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
<%@ webhandler Language="C#" class="FileManager" %>
2+
3+
/**
4+
* KindEditor ASP.NET
5+
*
6+
* 本ASP.NET程序是演示程序,建议不要直接在实际项目中使用。
7+
* 如果您确定直接使用本程序,使用之前请仔细确认相关安全设置。
8+
*
9+
*/
10+
11+
using System;
12+
using System.Collections;
13+
using System.Web;
14+
using System.IO;
15+
using System.Text.RegularExpressions;
16+
using LitJson;
17+
using System.Collections.Generic;
18+
19+
public class FileManager : IHttpHandler
20+
{
21+
public void ProcessRequest(HttpContext context)
22+
{
23+
String aspxUrl = context.Request.Path.Substring(0, context.Request.Path.LastIndexOf("/") + 1);
24+
25+
//根目录路径,相对路径
26+
String rootPath = "../attached/";
27+
//根目录URL,可以指定绝对路径,比如 http://www.yoursite.com/attached/
28+
String rootUrl = aspxUrl + "../attached/";
29+
//图片扩展名
30+
String fileTypes = "gif,jpg,jpeg,png,bmp";
31+
32+
String currentPath = "";
33+
String currentUrl = "";
34+
String currentDirPath = "";
35+
String moveupDirPath = "";
36+
37+
String dirPath = context.Server.MapPath(rootPath);
38+
String dirName = context.Request.QueryString["dir"];
39+
if (!String.IsNullOrEmpty(dirName)) {
40+
if (Array.IndexOf("image,flash,media,file".Split(','), dirName) == -1) {
41+
context.Response.Write("Invalid Directory name.");
42+
context.Response.End();
43+
}
44+
dirPath += dirName + "/";
45+
rootUrl += dirName + "/";
46+
if (!Directory.Exists(dirPath)) {
47+
Directory.CreateDirectory(dirPath);
48+
}
49+
}
50+
51+
//根据path参数,设置各路径和URL
52+
String path = context.Request.QueryString["path"];
53+
path = String.IsNullOrEmpty(path) ? "" : path;
54+
if (path == "")
55+
{
56+
currentPath = dirPath;
57+
currentUrl = rootUrl;
58+
currentDirPath = "";
59+
moveupDirPath = "";
60+
}
61+
else
62+
{
63+
currentPath = dirPath + path;
64+
currentUrl = rootUrl + path;
65+
currentDirPath = path;
66+
moveupDirPath = Regex.Replace(currentDirPath, @"(.*?)[^\/]+\/$", "$1");
67+
}
68+
69+
//排序形式,name or size or type
70+
String order = context.Request.QueryString["order"];
71+
order = String.IsNullOrEmpty(order) ? "" : order.ToLower();
72+
73+
//不允许使用..移动到上一级目录
74+
if (Regex.IsMatch(path, @"\.\."))
75+
{
76+
context.Response.Write("Access is not allowed.");
77+
context.Response.End();
78+
}
79+
//最后一个字符不是/
80+
if (path != "" && !path.EndsWith("/"))
81+
{
82+
context.Response.Write("Parameter is not valid.");
83+
context.Response.End();
84+
}
85+
//目录不存在或不是目录
86+
if (!Directory.Exists(currentPath))
87+
{
88+
context.Response.Write("Directory does not exist.");
89+
context.Response.End();
90+
}
91+
92+
//遍历目录取得文件信息
93+
string[] dirList = Directory.GetDirectories(currentPath);
94+
string[] fileList = Directory.GetFiles(currentPath);
95+
96+
switch (order)
97+
{
98+
case "size":
99+
Array.Sort(dirList, new NameSorter());
100+
Array.Sort(fileList, new SizeSorter());
101+
break;
102+
case "type":
103+
Array.Sort(dirList, new NameSorter());
104+
Array.Sort(fileList, new TypeSorter());
105+
break;
106+
case "name":
107+
default:
108+
Array.Sort(dirList, new NameSorter());
109+
Array.Sort(fileList, new NameSorter());
110+
break;
111+
}
112+
113+
Hashtable result = new Hashtable();
114+
result["moveup_dir_path"] = moveupDirPath;
115+
result["current_dir_path"] = currentDirPath;
116+
result["current_url"] = currentUrl;
117+
result["total_count"] = dirList.Length + fileList.Length;
118+
List<Hashtable> dirFileList = new List<Hashtable>();
119+
result["file_list"] = dirFileList;
120+
for (int i = 0; i < dirList.Length; i++)
121+
{
122+
DirectoryInfo dir = new DirectoryInfo(dirList[i]);
123+
Hashtable hash = new Hashtable();
124+
hash["is_dir"] = true;
125+
hash["has_file"] = (dir.GetFileSystemInfos().Length > 0);
126+
hash["filesize"] = 0;
127+
hash["is_photo"] = false;
128+
hash["filetype"] = "";
129+
hash["filename"] = dir.Name;
130+
hash["datetime"] = dir.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss");
131+
dirFileList.Add(hash);
132+
}
133+
for (int i = 0; i < fileList.Length; i++)
134+
{
135+
FileInfo file = new FileInfo(fileList[i]);
136+
Hashtable hash = new Hashtable();
137+
hash["is_dir"] = false;
138+
hash["has_file"] = false;
139+
hash["filesize"] = file.Length;
140+
hash["is_photo"] = (Array.IndexOf(fileTypes.Split(','), file.Extension.Substring(1).ToLower()) >= 0);
141+
hash["filetype"] = file.Extension.Substring(1);
142+
hash["filename"] = file.Name;
143+
hash["datetime"] = file.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss");
144+
dirFileList.Add(hash);
145+
}
146+
context.Response.AddHeader("Content-Type", "application/json; charset=UTF-8");
147+
context.Response.Write(JsonMapper.ToJson(result));
148+
context.Response.End();
149+
}
150+
151+
public class NameSorter : IComparer
152+
{
153+
public int Compare(object x, object y)
154+
{
155+
if (x == null && y == null)
156+
{
157+
return 0;
158+
}
159+
if (x == null)
160+
{
161+
return -1;
162+
}
163+
if (y == null)
164+
{
165+
return 1;
166+
}
167+
FileInfo xInfo = new FileInfo(x.ToString());
168+
FileInfo yInfo = new FileInfo(y.ToString());
169+
170+
return xInfo.FullName.CompareTo(yInfo.FullName);
171+
}
172+
}
173+
174+
public class SizeSorter : IComparer
175+
{
176+
public int Compare(object x, object y)
177+
{
178+
if (x == null && y == null)
179+
{
180+
return 0;
181+
}
182+
if (x == null)
183+
{
184+
return -1;
185+
}
186+
if (y == null)
187+
{
188+
return 1;
189+
}
190+
FileInfo xInfo = new FileInfo(x.ToString());
191+
FileInfo yInfo = new FileInfo(y.ToString());
192+
193+
return xInfo.Length.CompareTo(yInfo.Length);
194+
}
195+
}
196+
197+
public class TypeSorter : IComparer
198+
{
199+
public int Compare(object x, object y)
200+
{
201+
if (x == null && y == null)
202+
{
203+
return 0;
204+
}
205+
if (x == null)
206+
{
207+
return -1;
208+
}
209+
if (y == null)
210+
{
211+
return 1;
212+
}
213+
FileInfo xInfo = new FileInfo(x.ToString());
214+
FileInfo yInfo = new FileInfo(y.ToString());
215+
216+
return xInfo.Extension.CompareTo(yInfo.Extension);
217+
}
218+
}
219+
220+
public bool IsReusable
221+
{
222+
get
223+
{
224+
return true;
225+
}
226+
}
227+
}

0 commit comments

Comments
 (0)