2
FCKeditor - The text editor for internet
3
Copyright (C) 2003-2005 Frederico Caldeira Knabben
5
Licensed under the terms of the GNU Lesser General Public License:
6
http://www.opensource.org/licenses/lgpl-license.php
8
For further information visit:
9
http://www.fckeditor.net/
11
"Support Open Source software. What about a donation today?"
13
File Name: fckeditor.py
14
This is the integration file for Python.
17
Andrew Liu (andrew@liuholdings.com)
24
def escape(text, replace=string.replace):
25
"""Converts the special characters '<', '>', and '&'.
27
RFC 1866 specifies that these characters be represented
28
in HTML as < > and & respectively. In Python
29
1.5 we use the new string.replace() function for speed.
31
text = replace(text, '&', '&') # must be done 1st
32
text = replace(text, '<', '<')
33
text = replace(text, '>', '>')
34
text = replace(text, '"', '"')
35
text = replace(text, "'", ''')
39
class FCKeditor(object):
40
def __init__(self, instanceName):
41
self.InstanceName = instanceName
42
self.BasePath = '/FCKeditor/'
45
self.ToolbarSet = 'Default'
51
return self.CreateHtml()
54
HtmlValue = escape(self.Value)
57
if (self.IsCompatible()):
58
File = "fckeditor.html"
59
Link = "%seditor/%s?InstanceName=%s" % (
64
if (self.ToolbarSet is not None):
65
Link += "&ToolBar=%s" % self.ToolbarSet
67
# Render the linked hidden field
68
Html += "<input type=\"hidden\" id=\"%s\" name=\"%s\" value=\"%s\" style=\"display:none\" />" % (
74
# Render the configurations hidden field
75
Html += "<input type=\"hidden\" id=\"%s___Config\" value=\"%s\" style=\"display:none\" />" % (
77
self.GetConfigFieldString()
80
# Render the editor iframe
81
Html += "<iframe id=\"%s\__Frame\" src=\"%s\" width=\"%s\" height=\"%s\" frameborder=\"no\" scrolling=\"no\"></iframe>" % (
88
if (self.Width.find("%%") < 0):
89
WidthCSS = "%spx" % self.Width
92
if (self.Height.find("%%") < 0):
93
HeightCSS = "%spx" % self.Height
95
HeightCSS = self.Height
97
Html += "<textarea name=\"%s\" rows=\"4\" cols=\"40\" style=\"width: %s; height: %s;\" wrap=\"virtual\">%s</textarea>" % (
106
def IsCompatible(self):
107
if (os.environ.has_key("HTTP_USER_AGENT")):
108
sAgent = os.environ.get("HTTP_USER_AGENT", "")
111
if (sAgent.find("MSIE") >= 0) and (sAgent.find("mac") < 0) and (sAgent.find("Opera") < 0):
112
i = sAgent.find("MSIE")
113
iVersion = float(sAgent[i+5:i+5+3])
114
if (iVersion >= 5.5):
117
elif (sAgent.find("Gecko/") >= 0):
118
i = sAgent.find("Gecko/")
119
iVersion = int(sAgent[i+6:i+6+8])
120
if (iVersion >= 20030210):
126
def GetConfigFieldString(self):
129
for sKey in self.Config.keys():
130
sValue = self.Config[sKey]
138
if (sValue == "true"):
139
sParams += "%s=true" % k
140
elif (sValue == "false"):
141
sParams += "%s=false" % k
143
sParams += "%s=%s" % (k, v)