fckeditor.cfc 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <cfcomponent output="false" displayname="FCKeditor" hint="Create an instance of the FCKeditor.">
  2. <!---
  3. * FCKeditor - The text editor for Internet - http://www.fckeditor.net
  4. * Copyright (C) 2003-2009 Frederico Caldeira Knabben
  5. *
  6. * == BEGIN LICENSE ==
  7. *
  8. * Licensed under the terms of any of the following licenses at your
  9. * choice:
  10. *
  11. * - GNU General Public License Version 2 or later (the "GPL")
  12. * http://www.gnu.org/licenses/gpl.html
  13. *
  14. * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
  15. * http://www.gnu.org/licenses/lgpl.html
  16. *
  17. * - Mozilla Public License Version 1.1 or later (the "MPL")
  18. * http://www.mozilla.org/MPL/MPL-1.1.html
  19. *
  20. * == END LICENSE ==
  21. *
  22. * ColdFusion MX integration.
  23. * Note this CFC is created for use only with Coldfusion MX and above.
  24. * For older version, check the fckeditor.cfm.
  25. *
  26. * Syntax:
  27. *
  28. * <cfscript>
  29. * fckEditor = createObject("component", "fckeditor.fckeditor");
  30. * fckEditor.instanceName="myEditor";
  31. * fckEditor.basePath="/fckeditor/";
  32. * fckEditor.value="<p>This is my <strong>initial</strong> html text.</p>";
  33. * fckEditor.width="100%";
  34. * fckEditor.height="200";
  35. * // ... additional parameters ...
  36. * fckEditor.create(); // create instance now.
  37. * </cfscript>
  38. *
  39. * See your macromedia coldfusion mx documentation for more info.
  40. *
  41. * *** Note:
  42. * Do not use path names with a "." (dot) in the name. This is a coldfusion
  43. * limitation with the cfc invocation.
  44. --->
  45. <cfinclude template="fckutils.cfm">
  46. <cffunction
  47. name="Create"
  48. access="public"
  49. output="true"
  50. returntype="void"
  51. hint="Outputs the editor HTML in the place where the function is called"
  52. >
  53. <cfoutput>#CreateHtml()#</cfoutput>
  54. </cffunction>
  55. <cffunction
  56. name="CreateHtml"
  57. access="public"
  58. output="false"
  59. returntype="string"
  60. hint="Retrieves the editor HTML"
  61. >
  62. <cfparam name="this.instanceName" type="string" />
  63. <cfparam name="this.width" type="string" default="100%" />
  64. <cfparam name="this.height" type="string" default="200" />
  65. <cfparam name="this.toolbarSet" type="string" default="Default" />
  66. <cfparam name="this.value" type="string" default="" />
  67. <cfparam name="this.basePath" type="string" default="/fckeditor/" />
  68. <cfparam name="this.checkBrowser" type="boolean" default="true" />
  69. <cfparam name="this.config" type="struct" default="#structNew()#" />
  70. <cfscript>
  71. // display the html editor or a plain textarea?
  72. if( isCompatible() )
  73. return getHtmlEditor();
  74. else
  75. return getTextArea();
  76. </cfscript>
  77. </cffunction>
  78. <cffunction
  79. name="isCompatible"
  80. access="private"
  81. output="false"
  82. returnType="boolean"
  83. hint="Check browser compatibility via HTTP_USER_AGENT, if checkBrowser is true"
  84. >
  85. <cfscript>
  86. var sAgent = lCase( cgi.HTTP_USER_AGENT );
  87. var stResult = "";
  88. var sBrowserVersion = "";
  89. // do not check if argument "checkBrowser" is false
  90. if( not this.checkBrowser )
  91. return true;
  92. return FCKeditor_IsCompatibleBrowser();
  93. </cfscript>
  94. </cffunction>
  95. <cffunction
  96. name="getTextArea"
  97. access="private"
  98. output="false"
  99. returnType="string"
  100. hint="Create a textarea field for non-compatible browsers."
  101. >
  102. <cfset var result = "" />
  103. <cfset var sWidthCSS = "" />
  104. <cfset var sHeightCSS = "" />
  105. <cfscript>
  106. if( Find( "%", this.width ) gt 0)
  107. sWidthCSS = this.width;
  108. else
  109. sWidthCSS = this.width & "px";
  110. if( Find( "%", this.width ) gt 0)
  111. sHeightCSS = this.height;
  112. else
  113. sHeightCSS = this.height & "px";
  114. result = "<textarea name=""#this.instanceName#"" rows=""4"" cols=""40"" style=""width: #sWidthCSS#; height: #sHeightCSS#"">#HTMLEditFormat(this.value)#</textarea>" & chr(13) & chr(10);
  115. </cfscript>
  116. <cfreturn result />
  117. </cffunction>
  118. <cffunction
  119. name="getHtmlEditor"
  120. access="private"
  121. output="false"
  122. returnType="string"
  123. hint="Create the html editor instance for compatible browsers."
  124. >
  125. <cfset var sURL = "" />
  126. <cfset var result = "" />
  127. <cfscript>
  128. // try to fix the basePath, if ending slash is missing
  129. if( len( this.basePath) and right( this.basePath, 1 ) is not "/" )
  130. this.basePath = this.basePath & "/";
  131. // construct the url
  132. sURL = this.basePath & "editor/fckeditor.html?InstanceName=" & this.instanceName;
  133. // append toolbarset name to the url
  134. if( len( this.toolbarSet ) )
  135. sURL = sURL & "&amp;Toolbar=" & this.toolbarSet;
  136. </cfscript>
  137. <cfscript>
  138. result = result & "<input type=""hidden"" id=""#this.instanceName#"" name=""#this.instanceName#"" value=""#HTMLEditFormat(this.value)#"" style=""display:none"" />" & chr(13) & chr(10);
  139. result = result & "<input type=""hidden"" id=""#this.instanceName#___Config"" value=""#GetConfigFieldString()#"" style=""display:none"" />" & chr(13) & chr(10);
  140. result = result & "<iframe id=""#this.instanceName#___Frame"" src=""#sURL#"" width=""#this.width#"" height=""#this.height#"" frameborder=""0"" scrolling=""no""></iframe>" & chr(13) & chr(10);
  141. </cfscript>
  142. <cfreturn result />
  143. </cffunction>
  144. <cffunction
  145. name="GetConfigFieldString"
  146. access="private"
  147. output="false"
  148. returnType="string"
  149. hint="Create configuration string: Key1=Value1&Key2=Value2&... (Key/Value:HTML encoded)"
  150. >
  151. <cfset var sParams = "" />
  152. <cfset var key = "" />
  153. <cfset var fieldValue = "" />
  154. <cfset var fieldLabel = "" />
  155. <cfset var lConfigKeys = "" />
  156. <cfset var iPos = "" />
  157. <cfscript>
  158. /**
  159. * CFML doesn't store casesensitive names for structure keys, but the configuration names must be casesensitive for js.
  160. * So we need to find out the correct case for the configuration keys.
  161. * We "fix" this by comparing the caseless configuration keys to a list of all available configuration options in the correct case.
  162. * changed 20041206 hk@lwd.de (improvements are welcome!)
  163. */
  164. lConfigKeys = lConfigKeys & "CustomConfigurationsPath,EditorAreaCSS,ToolbarComboPreviewCSS,DocType";
  165. lConfigKeys = lConfigKeys & ",BaseHref,FullPage,Debug,AllowQueryStringDebug,SkinPath";
  166. lConfigKeys = lConfigKeys & ",PreloadImages,PluginsPath,AutoDetectLanguage,DefaultLanguage,ContentLangDirection";
  167. lConfigKeys = lConfigKeys & ",ProcessHTMLEntities,IncludeLatinEntities,IncludeGreekEntities,ProcessNumericEntities,AdditionalNumericEntities";
  168. lConfigKeys = lConfigKeys & ",FillEmptyBlocks,FormatSource,FormatOutput,FormatIndentator";
  169. lConfigKeys = lConfigKeys & ",StartupFocus,ForcePasteAsPlainText,AutoDetectPasteFromWord,ForceSimpleAmpersand";
  170. lConfigKeys = lConfigKeys & ",TabSpaces,ShowBorders,SourcePopup,ToolbarStartExpanded,ToolbarCanCollapse";
  171. lConfigKeys = lConfigKeys & ",IgnoreEmptyParagraphValue,FloatingPanelsZIndex,TemplateReplaceAll,TemplateReplaceCheckbox";
  172. lConfigKeys = lConfigKeys & ",ToolbarLocation,ToolbarSets,EnterMode,ShiftEnterMode,Keystrokes";
  173. lConfigKeys = lConfigKeys & ",ContextMenu,BrowserContextMenuOnCtrl,FontColors,FontNames,FontSizes";
  174. lConfigKeys = lConfigKeys & ",FontFormats,StylesXmlPath,TemplatesXmlPath,SpellChecker,IeSpellDownloadUrl";
  175. lConfigKeys = lConfigKeys & ",SpellerPagesServerScript,FirefoxSpellChecker,MaxUndoLevels,DisableObjectResizing,DisableFFTableHandles";
  176. lConfigKeys = lConfigKeys & ",LinkDlgHideTarget,LinkDlgHideAdvanced,ImageDlgHideLink,ImageDlgHideAdvanced,FlashDlgHideAdvanced";
  177. lConfigKeys = lConfigKeys & ",ProtectedTags,BodyId,BodyClass,DefaultLinkTarget,CleanWordKeepsStructure";
  178. lConfigKeys = lConfigKeys & ",LinkBrowser,LinkBrowserURL,LinkBrowserWindowWidth,LinkBrowserWindowHeight,ImageBrowser";
  179. lConfigKeys = lConfigKeys & ",ImageBrowserURL,ImageBrowserWindowWidth,ImageBrowserWindowHeight,FlashBrowser,FlashBrowserURL";
  180. lConfigKeys = lConfigKeys & ",FlashBrowserWindowWidth,FlashBrowserWindowHeight,LinkUpload,LinkUploadURL,LinkUploadWindowWidth";
  181. lConfigKeys = lConfigKeys & ",LinkUploadWindowHeight,LinkUploadAllowedExtensions,LinkUploadDeniedExtensions,ImageUpload,ImageUploadURL";
  182. lConfigKeys = lConfigKeys & ",ImageUploadAllowedExtensions,ImageUploadDeniedExtensions,FlashUpload,FlashUploadURL,FlashUploadAllowedExtensions";
  183. lConfigKeys = lConfigKeys & ",FlashUploadDeniedExtensions,SmileyPath,SmileyImages,SmileyColumns,SmileyWindowWidth,SmileyWindowHeight";
  184. for( key in this.config )
  185. {
  186. iPos = listFindNoCase( lConfigKeys, key );
  187. if( iPos GT 0 )
  188. {
  189. if( len( sParams ) )
  190. sParams = sParams & "&amp;";
  191. fieldValue = this.config[key];
  192. fieldName = listGetAt( lConfigKeys, iPos );
  193. // set all boolean possibilities in CFML to true/false values
  194. if( isBoolean( fieldValue) and fieldValue )
  195. fieldValue = "true";
  196. else if( isBoolean( fieldValue) )
  197. fieldValue = "false";
  198. sParams = sParams & HTMLEditFormat( fieldName ) & '=' & HTMLEditFormat( fieldValue );
  199. }
  200. }
  201. return sParams;
  202. </cfscript>
  203. </cffunction>
  204. </cfcomponent>