[ Index ]
 

Code source de FCKeditor 2.4

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/ -> fckeditor.py (source)

   1  """
   2  FCKeditor - The text editor for Internet - http://www.fckeditor.net
   3  Copyright (C) 2003-2007 Frederico Caldeira Knabben
   4  
   5  == BEGIN LICENSE ==
   6  
   7  Licensed under the terms of any of the following licenses at your
   8  choice:
   9  
  10   - GNU General Public License Version 2 or later (the "GPL")
  11     http://www.gnu.org/licenses/gpl.html
  12  
  13   - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
  14     http://www.gnu.org/licenses/lgpl.html
  15  
  16   - Mozilla Public License Version 1.1 or later (the "MPL")
  17     http://www.mozilla.org/MPL/MPL-1.1.html
  18  
  19  == END LICENSE ==
  20  
  21  File Name: fckeditor.py
  22      This is the integration file for Python.
  23  
  24  File Authors:
  25          Andrew Liu (andrew@liuholdings.com)
  26  """
  27  
  28  import cgi
  29  import os
  30  import string
  31  
  32  def escape(text, replace=string.replace):
  33      """Converts the special characters '<', '>', and '&'.
  34  
  35      RFC 1866 specifies that these characters be represented
  36      in HTML as &lt; &gt; and &amp; respectively. In Python
  37      1.5 we use the new string.replace() function for speed.
  38      """
  39      text = replace(text, '&', '&amp;') # must be done 1st
  40      text = replace(text, '<', '&lt;')
  41      text = replace(text, '>', '&gt;')
  42      text = replace(text, '"', '&quot;')
  43      text = replace(text, "'", '&#39;')
  44      return text
  45  
  46  # The FCKeditor class
  47  class FCKeditor(object):
  48      def __init__(self, instanceName):
  49          self.InstanceName = instanceName
  50          self.BasePath = '/fckeditor/'
  51          self.Width = '100%'
  52          self.Height = '200'
  53          self.ToolbarSet = 'Default'
  54          self.Value = '';
  55  
  56          self.Config = {}
  57  
  58      def Create(self):
  59          return self.CreateHtml()
  60  
  61      def CreateHtml(self):
  62          HtmlValue = escape(self.Value)
  63          Html = "<div>"
  64  
  65          if (self.IsCompatible()):
  66              File = "fckeditor.html"
  67              Link = "%seditor/%s?InstanceName=%s" % (
  68                      self.BasePath,
  69                      File,
  70                      self.InstanceName
  71                      )
  72              if (self.ToolbarSet is not None):
  73                  Link += "&amp;ToolBar=%s" % self.ToolbarSet
  74  
  75              # Render the linked hidden field
  76              Html += "<input type=\"hidden\" id=\"%s\" name=\"%s\" value=\"%s\" style=\"display:none\" />" % (
  77                      self.InstanceName,
  78                      self.InstanceName,
  79                      HtmlValue
  80                      )
  81  
  82              # Render the configurations hidden field
  83              Html += "<input type=\"hidden\" id=\"%s___Config\" value=\"%s\" style=\"display:none\" />" % (
  84                      self.InstanceName,
  85                      self.GetConfigFieldString()
  86                      )
  87  
  88              # Render the editor iframe
  89              Html += "<iframe id=\"%s\__Frame\" src=\"%s\" width=\"%s\" height=\"%s\" frameborder=\"0\" scrolling=\"no\"></iframe>" % (
  90                      self.InstanceName,
  91                      Link,
  92                      self.Width,
  93                      self.Height
  94                      )
  95          else:
  96              if (self.Width.find("%%") < 0):
  97                  WidthCSS = "%spx" % self.Width
  98              else:
  99                  WidthCSS = self.Width
 100              if (self.Height.find("%%") < 0):
 101                  HeightCSS = "%spx" % self.Height
 102              else:
 103                  HeightCSS = self.Height
 104  
 105              Html += "<textarea name=\"%s\" rows=\"4\" cols=\"40\" style=\"width: %s; height: %s;\" wrap=\"virtual\">%s</textarea>" % (
 106                      self.InstanceName,
 107                      WidthCSS,
 108                      HeightCSS,
 109                      HtmlValue
 110                      )
 111          Html += "</div>"
 112          return Html
 113      
 114      def IsCompatible(self):
 115          if (os.environ.has_key("HTTP_USER_AGENT")):
 116              sAgent = os.environ.get("HTTP_USER_AGENT", "")
 117          else:
 118              sAgent = ""
 119          if (sAgent.find("MSIE") >= 0) and (sAgent.find("mac") < 0) and (sAgent.find("Opera") < 0):
 120              i = sAgent.find("MSIE")
 121              iVersion = float(sAgent[i+5:i+5+3])
 122              if (iVersion >= 5.5):
 123                  return True
 124              return False
 125          elif (sAgent.find("Gecko/") >= 0):
 126              i = sAgent.find("Gecko/")
 127              iVersion = int(sAgent[i+6:i+6+8])
 128              if (iVersion >= 20030210):
 129                  return True
 130              return False
 131          else:
 132              return False
 133  
 134      def GetConfigFieldString(self):
 135          sParams = ""
 136          bFirst = True
 137          for sKey in self.Config.keys():
 138              sValue = self.Config[sKey]
 139              if (not bFirst):
 140                  sParams += "&amp;"
 141              else:
 142                  bFirst = False
 143              if (sValue):
 144                  k = escape(sKey)
 145                  v = escape(sValue)
 146                  if (sValue == "true"):
 147                      sParams += "%s=true" % k
 148                  elif (sValue == "false"):
 149                      sParams += "%s=false" % k
 150                  else:
 151                      sParams += "%s=%s" % (k, v)
 152          return sParams
 153                      


Généré le : Sun Feb 25 15:28:05 2007 par Balluche grâce à PHPXref 0.7