/source/Plug-in/fck/fckeditor.cfc

http://prosporous.googlecode.com/ · ColdFusion CFScript · 232 lines · 192 code · 27 blank · 13 comment · 17 complexity · a86b7d2a44f2e8e7c754ad9f134de60a MD5 · raw file

  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-2007 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. <cfscript>
  104. // append unit "px" for numeric width and/or height values
  105. if( isNumeric( this.width ) )
  106. this.width = this.width & "px";
  107. if( isNumeric( this.height ) )
  108. this.height = this.height & "px";
  109. </cfscript>
  110. <cfscript>
  111. result = result & "<div>" & chr(13) & chr(10);
  112. result = result & "<textarea name=""#this.instanceName#"" rows=""4"" cols=""40"" style=""WIDTH: #this.width#; HEIGHT: #this.height#"">#HTMLEditFormat(this.value)#</textarea>" & chr(13) & chr(10);
  113. result = result & "</div>" & chr(13) & chr(10);
  114. </cfscript>
  115. <cfreturn result />
  116. </cffunction>
  117. <cffunction
  118. name="getHtmlEditor"
  119. access="private"
  120. output="false"
  121. returnType="string"
  122. hint="Create the html editor instance for compatible browsers."
  123. >
  124. <cfset var sURL = "" />
  125. <cfset var result = "" />
  126. <cfscript>
  127. // try to fix the basePath, if ending slash is missing
  128. if( len( this.basePath) and right( this.basePath, 1 ) is not "/" )
  129. this.basePath = this.basePath & "/";
  130. // construct the url
  131. sURL = this.basePath & "editor/fckeditor.html?InstanceName=" & this.instanceName;
  132. // append toolbarset name to the url
  133. if( len( this.toolbarSet ) )
  134. sURL = sURL & "&amp;Toolbar=" & this.toolbarSet;
  135. </cfscript>
  136. <cfscript>
  137. result = result & "<div>" & chr(13) & chr(10);
  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. result = result & "</div>" & chr(13) & chr(10);
  142. </cfscript>
  143. <cfreturn result />
  144. </cffunction>
  145. <cffunction
  146. name="GetConfigFieldString"
  147. access="private"
  148. output="false"
  149. returnType="string"
  150. hint="Create configuration string: Key1=Value1&Key2=Value2&... (Key/Value:HTML encoded)"
  151. >
  152. <cfset var sParams = "" />
  153. <cfset var key = "" />
  154. <cfset var fieldValue = "" />
  155. <cfset var fieldLabel = "" />
  156. <cfset var lConfigKeys = "" />
  157. <cfset var iPos = "" />
  158. <cfscript>
  159. /**
  160. * CFML doesn't store casesensitive names for structure keys, but the configuration names must be casesensitive for js.
  161. * So we need to find out the correct case for the configuration keys.
  162. * We "fix" this by comparing the caseless configuration keys to a list of all available configuration options in the correct case.
  163. * changed 20041206 hk@lwd.de (improvements are welcome!)
  164. */
  165. lConfigKeys = lConfigKeys & "CustomConfigurationsPath,EditorAreaCSS,ToolbarComboPreviewCSS,DocType";
  166. lConfigKeys = lConfigKeys & ",BaseHref,FullPage,Debug,AllowQueryStringDebug,SkinPath";
  167. lConfigKeys = lConfigKeys & ",PreloadImages,PluginsPath,AutoDetectLanguage,DefaultLanguage,ContentLangDirection";
  168. lConfigKeys = lConfigKeys & ",ProcessHTMLEntities,IncludeLatinEntities,IncludeGreekEntities,ProcessNumericEntities,AdditionalNumericEntities";
  169. lConfigKeys = lConfigKeys & ",FillEmptyBlocks,FormatSource,FormatOutput,FormatIndentator";
  170. lConfigKeys = lConfigKeys & ",StartupFocus,ForcePasteAsPlainText,AutoDetectPasteFromWord,ForceSimpleAmpersand";
  171. lConfigKeys = lConfigKeys & ",TabSpaces,ShowBorders,SourcePopup,ToolbarStartExpanded,ToolbarCanCollapse";
  172. lConfigKeys = lConfigKeys & ",IgnoreEmptyParagraphValue,PreserveSessionOnFileBrowser,FloatingPanelsZIndex,TemplateReplaceAll,TemplateReplaceCheckbox";
  173. lConfigKeys = lConfigKeys & ",ToolbarLocation,ToolbarSets,EnterMode,ShiftEnterMode,Keystrokes";
  174. lConfigKeys = lConfigKeys & ",ContextMenu,BrowserContextMenuOnCtrl,FontColors,FontNames,FontSizes";
  175. lConfigKeys = lConfigKeys & ",FontFormats,StylesXmlPath,TemplatesXmlPath,SpellChecker,IeSpellDownloadUrl";
  176. lConfigKeys = lConfigKeys & ",SpellerPagesServerScript,FirefoxSpellChecker,MaxUndoLevels,DisableObjectResizing,DisableFFTableHandles";
  177. lConfigKeys = lConfigKeys & ",LinkDlgHideTarget,LinkDlgHideAdvanced,ImageDlgHideLink,ImageDlgHideAdvanced,FlashDlgHideAdvanced";
  178. lConfigKeys = lConfigKeys & ",ProtectedTags,BodyId,BodyClass,DefaultLinkTarget,CleanWordKeepsStructure";
  179. lConfigKeys = lConfigKeys & ",LinkBrowser,LinkBrowserURL,LinkBrowserWindowWidth,LinkBrowserWindowHeight,ImageBrowser";
  180. lConfigKeys = lConfigKeys & ",ImageBrowserURL,ImageBrowserWindowWidth,ImageBrowserWindowHeight,FlashBrowser,FlashBrowserURL";
  181. lConfigKeys = lConfigKeys & ",FlashBrowserWindowWidth,FlashBrowserWindowHeight,LinkUpload,LinkUploadURL,LinkUploadWindowWidth";
  182. lConfigKeys = lConfigKeys & ",LinkUploadWindowHeight,LinkUploadAllowedExtensions,LinkUploadDeniedExtensions,ImageUpload,ImageUploadURL";
  183. lConfigKeys = lConfigKeys & ",ImageUploadAllowedExtensions,ImageUploadDeniedExtensions,FlashUpload,FlashUploadURL,FlashUploadAllowedExtensions";
  184. lConfigKeys = lConfigKeys & ",FlashUploadDeniedExtensions,SmileyPath,SmileyImages,SmileyColumns,SmileyWindowWidth,SmileyWindowHeight";
  185. for( key in this.config )
  186. {
  187. iPos = listFindNoCase( lConfigKeys, key );
  188. if( iPos GT 0 )
  189. {
  190. if( len( sParams ) )
  191. sParams = sParams & "&amp;";
  192. fieldValue = this.config[key];
  193. fieldName = listGetAt( lConfigKeys, iPos );
  194. // set all boolean possibilities in CFML to true/false values
  195. if( isBoolean( fieldValue) and fieldValue )
  196. fieldValue = "true";
  197. else if( isBoolean( fieldValue) )
  198. fieldValue = "false";
  199. sParams = sParams & HTMLEditFormat( fieldName ) & '=' & HTMLEditFormat( fieldValue );
  200. }
  201. }
  202. return sParams;
  203. </cfscript>
  204. </cffunction>
  205. </cfcomponent>