Rev 1075 | Blame | Last modification | View Log | RSS feed
"""FCKeditor - The text editor for internetCopyright (C) 2003-2006 Frederico Caldeira KnabbenLicensed under the terms of the GNU Lesser General Public License:http://www.opensource.org/licenses/lgpl-license.phpFor further information visit:http://www.fckeditor.net/"Support Open Source software. What about a donation today?"File Name: fckeditor.pyThis is the integration file for Python.File Authors:Andrew Liu (andrew@liuholdings.com)"""import cgiimport osimport stringdef escape(text, replace=string.replace):"""Converts the special characters '<', '>', and '&'.RFC 1866 specifies that these characters be representedin HTML as < > and & respectively. In Python1.5 we use the new string.replace() function for speed."""text = replace(text, '&', '&') # must be done 1sttext = replace(text, '<', '<')text = replace(text, '>', '>')text = replace(text, '"', '"')text = replace(text, "'", ''')return text# The FCKeditor classclass FCKeditor(object):def __init__(self, instanceName):self.InstanceName = instanceNameself.BasePath = '/fckeditor/'self.Width = '100%'self.Height = '200'self.ToolbarSet = 'Default'self.Value = '';self.Config = {}def Create(self):return self.CreateHtml()def CreateHtml(self):HtmlValue = escape(self.Value)Html = "<div>"if (self.IsCompatible()):File = "fckeditor.html"Link = "%seditor/%s?InstanceName=%s" % (self.BasePath,File,self.InstanceName)if (self.ToolbarSet is not None):Link += "&ToolBar=%s" % self.ToolbarSet# Render the linked hidden fieldHtml += "<input type=\"hidden\" id=\"%s\" name=\"%s\" value=\"%s\" style=\"display:none\" />" % (self.InstanceName,self.InstanceName,HtmlValue)# Render the configurations hidden fieldHtml += "<input type=\"hidden\" id=\"%s___Config\" value=\"%s\" style=\"display:none\" />" % (self.InstanceName,self.GetConfigFieldString())# Render the editor iframeHtml += "<iframe id=\"%s\__Frame\" src=\"%s\" width=\"%s\" height=\"%s\" frameborder=\"0\" scrolling=\"no\"></iframe>" % (self.InstanceName,Link,self.Width,self.Height)else:if (self.Width.find("%%") < 0):WidthCSS = "%spx" % self.Widthelse:WidthCSS = self.Widthif (self.Height.find("%%") < 0):HeightCSS = "%spx" % self.Heightelse:HeightCSS = self.HeightHtml += "<textarea name=\"%s\" rows=\"4\" cols=\"40\" style=\"width: %s; height: %s;\" wrap=\"virtual\">%s</textarea>" % (self.InstanceName,WidthCSS,HeightCSS,HtmlValue)Html += "</div>"return Htmldef IsCompatible(self):if (os.environ.has_key("HTTP_USER_AGENT")):sAgent = os.environ.get("HTTP_USER_AGENT", "")else:sAgent = ""if (sAgent.find("MSIE") >= 0) and (sAgent.find("mac") < 0) and (sAgent.find("Opera") < 0):i = sAgent.find("MSIE")iVersion = float(sAgent[i+5:i+5+3])if (iVersion >= 5.5):return Truereturn Falseelif (sAgent.find("Gecko/") >= 0):i = sAgent.find("Gecko/")iVersion = int(sAgent[i+6:i+6+8])if (iVersion >= 20030210):return Truereturn Falseelse:return Falsedef GetConfigFieldString(self):sParams = ""bFirst = Truefor sKey in self.Config.keys():sValue = self.Config[sKey]if (not bFirst):sParams += "&"else:bFirst = Falseif (sValue):k = escape(sKey)v = escape(sValue)if (sValue == "true"):sParams += "%s=true" % kelif (sValue == "false"):sParams += "%s=false" % kelse:sParams += "%s=%s" % (k, v)return sParams