PageRenderTime 21ms CodeModel.GetById 13ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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