fckeditor.asp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <!--
  2. * FCKeditor - The text editor for Internet - http://www.fckeditor.net
  3. * Copyright (C) 2003-2009 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. * This is the integration file for ASP.
  22. *
  23. * It defines the FCKeditor class that can be used to create editor
  24. * instances in ASP pages on server side.
  25. -->
  26. <%
  27. Class FCKeditor
  28. private sBasePath
  29. private sInstanceName
  30. private sWidth
  31. private sHeight
  32. private sToolbarSet
  33. private sValue
  34. private oConfig
  35. Private Sub Class_Initialize()
  36. sBasePath = "/fckeditor/"
  37. sWidth = "100%"
  38. sHeight = "200"
  39. sToolbarSet = "Default"
  40. sValue = ""
  41. Set oConfig = CreateObject("Scripting.Dictionary")
  42. End Sub
  43. Public Property Let BasePath( basePathValue )
  44. sBasePath = basePathValue
  45. End Property
  46. Public Property Let InstanceName( instanceNameValue )
  47. sInstanceName = instanceNameValue
  48. End Property
  49. Public Property Let Width( widthValue )
  50. sWidth = widthValue
  51. End Property
  52. Public Property Let Height( heightValue )
  53. sHeight = heightValue
  54. End Property
  55. Public Property Let ToolbarSet( toolbarSetValue )
  56. sToolbarSet = toolbarSetValue
  57. End Property
  58. Public Property Let Value( newValue )
  59. If ( IsNull( newValue ) OR IsEmpty( newValue ) ) Then
  60. sValue = ""
  61. Else
  62. sValue = newValue
  63. End If
  64. End Property
  65. Public Property Let Config( configKey, configValue )
  66. oConfig.Add configKey, configValue
  67. End Property
  68. ' Generates the instace of the editor in the HTML output of the page.
  69. Public Sub Create( instanceName )
  70. response.write CreateHtml( instanceName )
  71. end Sub
  72. ' Returns the html code that must be used to generate an instance of FCKeditor.
  73. Public Function CreateHtml( instanceName )
  74. dim html
  75. If IsCompatible() Then
  76. Dim sFile, sLink
  77. If Request.QueryString( "fcksource" ) = "true" Then
  78. sFile = "fckeditor.original.html"
  79. Else
  80. sFile = "fckeditor.html"
  81. End If
  82. sLink = sBasePath & "editor/" & sFile & "?InstanceName=" + instanceName
  83. If (sToolbarSet & "") <> "" Then
  84. sLink = sLink + "&amp;Toolbar=" & sToolbarSet
  85. End If
  86. html = ""
  87. ' Render the linked hidden field.
  88. html = html & "<input type=""hidden"" id=""" & instanceName & """ name=""" & instanceName & """ value=""" & Server.HTMLEncode( sValue ) & """ style=""display:none"" />"
  89. ' Render the configurations hidden field.
  90. html = html & "<input type=""hidden"" id=""" & instanceName & "___Config"" value=""" & GetConfigFieldString() & """ style=""display:none"" />"
  91. ' Render the editor IFRAME.
  92. html = html & "<iframe id=""" & instanceName & "___Frame"" src=""" & sLink & """ width=""" & sWidth & """ height=""" & sHeight & """ frameborder=""0"" scrolling=""no""></iframe>"
  93. Else
  94. Dim sWidthCSS, sHeightCSS
  95. If InStr( sWidth, "%" ) > 0 Then
  96. sWidthCSS = sWidth
  97. Else
  98. sWidthCSS = sWidth & "px"
  99. End If
  100. If InStr( sHeight, "%" ) > 0 Then
  101. sHeightCSS = sHeight
  102. Else
  103. sHeightCSS = sHeight & "px"
  104. End If
  105. html = "<textarea name=""" & instanceName & """ rows=""4"" cols=""40"" style=""width: " & sWidthCSS & "; height: " & sHeightCSS & """>" & Server.HTMLEncode( sValue ) & "</textarea>"
  106. End If
  107. CreateHtml = html
  108. End Function
  109. Private Function IsCompatible()
  110. IsCompatible = FCKeditor_IsCompatibleBrowser()
  111. End Function
  112. Private Function GetConfigFieldString()
  113. Dim sParams
  114. Dim bFirst
  115. bFirst = True
  116. Dim sKey
  117. For Each sKey in oConfig
  118. If bFirst = False Then
  119. sParams = sParams & "&amp;"
  120. Else
  121. bFirst = False
  122. End If
  123. sParams = sParams & EncodeConfig( sKey ) & "=" & EncodeConfig( oConfig(sKey) )
  124. Next
  125. GetConfigFieldString = sParams
  126. End Function
  127. Private Function EncodeConfig( valueToEncode )
  128. ' The locale of the asp server makes the conversion of a boolean to string different to "true" or "false"
  129. ' so we must do it manually
  130. If vartype(valueToEncode) = vbBoolean then
  131. If valueToEncode=True Then
  132. EncodeConfig="True"
  133. Else
  134. EncodeConfig="False"
  135. End If
  136. Else
  137. EncodeConfig = Replace( valueToEncode, "&", "%26" )
  138. EncodeConfig = Replace( EncodeConfig , "=", "%3D" )
  139. EncodeConfig = Replace( EncodeConfig , """", "%22" )
  140. End if
  141. End Function
  142. End Class
  143. ' A function that can be used to check if the current browser is compatible with FCKeditor
  144. ' without the need to create an instance of the class.
  145. Function FCKeditor_IsCompatibleBrowser()
  146. Dim sAgent
  147. sAgent = Request.ServerVariables("HTTP_USER_AGENT")
  148. Dim iVersion
  149. Dim re, Matches
  150. If InStr(sAgent, "MSIE") > 0 AND InStr(sAgent, "mac") <= 0 AND InStr(sAgent, "Opera") <= 0 Then
  151. iVersion = CInt( FCKeditor_ToNumericFormat( Mid(sAgent, InStr(sAgent, "MSIE") + 5, 3) ) )
  152. FCKeditor_IsCompatibleBrowser = ( iVersion >= 5.5 )
  153. ElseIf InStr(sAgent, "Gecko/") > 0 Then
  154. iVersion = CLng( Mid( sAgent, InStr( sAgent, "Gecko/" ) + 6, 8 ) )
  155. FCKeditor_IsCompatibleBrowser = ( iVersion >= 20030210 )
  156. ElseIf InStr(sAgent, "Opera/") > 0 Then
  157. iVersion = CSng( FCKeditor_ToNumericFormat( Mid( sAgent, InStr( sAgent, "Opera/" ) + 6, 4 ) ) )
  158. FCKeditor_IsCompatibleBrowser = ( iVersion >= 9.5 )
  159. ElseIf InStr(sAgent, "AppleWebKit/") > 0 Then
  160. Set re = new RegExp
  161. re.IgnoreCase = true
  162. re.global = false
  163. re.Pattern = "AppleWebKit/(\d+)"
  164. Set Matches = re.Execute(sAgent)
  165. FCKeditor_IsCompatibleBrowser = ( re.Replace(Matches.Item(0).Value, "$1") >= 522 )
  166. Else
  167. FCKeditor_IsCompatibleBrowser = False
  168. End If
  169. End Function
  170. ' By Agrotic
  171. ' On ASP, when converting string to numbers, the number decimal separator is localized
  172. ' so 5.5 will not work on systems were the separator is "," and vice versa.
  173. Private Function FCKeditor_ToNumericFormat( numberStr )
  174. If IsNumeric( "5.5" ) Then
  175. FCKeditor_ToNumericFormat = Replace( numberStr, ",", ".")
  176. Else
  177. FCKeditor_ToNumericFormat = Replace( numberStr, ".", ",")
  178. End If
  179. End Function
  180. %>