1<cfsetting enablecfoutputonly="Yes">
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 integration.
23 * Note this module is created for use with Coldfusion 4.52 and above.
24 * For a cfc version for coldfusion mx check the fckeditor.cfc.
25 *
26 * Syntax:
27 *
28 * <cfmodule name="path/to/cfc/fckeditor"
29 * 	instanceName="myEditor"
30 * 	toolbarSet="..."
31 * 	width="..."
32 * 	height="..:"
33 * 	value="..."
34 * 	config="..."
35 * >
36--->
37<!--- ::
38	 * 	Attribute validation
39	:: --->
40<cfparam name="attributes.instanceName" type="string">
41<cfparam name="attributes.width" 		type="string" default="100%">
42<cfparam name="attributes.height" 		type="string" default="200">
43<cfparam name="attributes.toolbarSet" 	type="string" default="Default">
44<cfparam name="attributes.value" 		type="string" default="">
45<cfparam name="attributes.basePath" 	type="string" default="/fckeditor/">
46<cfparam name="attributes.checkBrowser" type="boolean" default="true">
47<cfparam name="attributes.config" 		type="struct" default="#structNew()#">
48
49<!--- ::
50	 * check browser compatibility via HTTP_USER_AGENT, if checkBrowser is true
51	:: --->
52
53<cfscript>
54if( attributes.checkBrowser )
55{
56	sAgent = lCase( cgi.HTTP_USER_AGENT );
57	isCompatibleBrowser = false;
58
59	// check for Internet Explorer ( >= 5.5 )
60	if( find( "msie", sAgent ) and not find( "mac", sAgent ) and not find( "opera", sAgent ) )
61	{
62		// try to extract IE version
63		stResult = reFind( "msie ([5-9]\.[0-9])", sAgent, 1, true );
64		if( arrayLen( stResult.pos ) eq 2 )
65		{
66			// get IE Version
67			sBrowserVersion = mid( sAgent, stResult.pos[2], stResult.len[2] );
68			if( sBrowserVersion GTE 5.5 )
69				isCompatibleBrowser = true;
70		}
71	}
72	// check for Gecko ( >= 20030210+ )
73	else if( find( "gecko/", sAgent ) )
74	{
75		// try to extract Gecko version date
76		stResult = reFind( "gecko/(200[3-9][0-1][0-9][0-3][0-9])", sAgent, 1, true );
77		if( arrayLen( stResult.pos ) eq 2 )
78		{
79			// get Gecko build (i18n date)
80			sBrowserVersion = mid( sAgent, stResult.pos[2], stResult.len[2] );
81			if( sBrowserVersion GTE 20030210 )
82				isCompatibleBrowser = true;
83		}
84	}
85	else if( find( "opera/", sAgent ) )
86	{
87		// try to extract Opera version
88		stResult = reFind( "opera/([0-9]+\.[0-9]+)", sAgent, 1, true );
89		if( arrayLen( stResult.pos ) eq 2 )
90		{
91			if ( mid( sAgent, stResult.pos[2], stResult.len[2] ) gte 9.5)
92				isCompatibleBrowser = true;
93		}
94	}
95	else if( find( "applewebkit", sAgent ) )
96	{
97		// try to extract Gecko version date
98		stResult = reFind( "applewebkit/([0-9]+)", sAgent, 1, true );
99		if( arrayLen( stResult.pos ) eq 2 )
100		{
101			if( mid( sAgent, stResult.pos[2], stResult.len[2] ) gte 522 )
102				isCompatibleBrowser = true;
103		}
104	}
105}
106else
107{
108	// If we should not check browser compatibility, assume true
109	isCompatibleBrowser = true;
110}
111</cfscript>
112
113<cfif isCompatibleBrowser>
114
115	<!--- ::
116		 * show html editor area for compatible browser
117		:: --->
118
119	<cfscript>
120		// try to fix the basePath, if ending slash is missing
121		if( len( attributes.basePath) and right( attributes.basePath, 1 ) is not "/" )
122			attributes.basePath = attributes.basePath & "/";
123
124		// construct the url
125		sURL = attributes.basePath & "editor/fckeditor.html?InstanceName=" & attributes.instanceName;
126
127		// append toolbarset name to the url
128		if( len( attributes.toolbarSet ) )
129			sURL = sURL & "&amp;Toolbar=" & attributes.toolbarSet;
130
131		// create configuration string: Key1=Value1&Key2=Value2&... (Key/Value:HTML encoded)
132
133		/**
134		 * CFML doesn't store casesensitive names for structure keys, but the configuration names must be casesensitive for js.
135		 * So we need to find out the correct case for the configuration keys.
136		 * We "fix" this by comparing the caseless configuration keys to a list of all available configuration options in the correct case.
137		 * changed 20041206 hk@lwd.de (improvements are welcome!)
138		 */
139		lConfigKeys = "";
140		lConfigKeys = lConfigKeys & "CustomConfigurationsPath,EditorAreaCSS,ToolbarComboPreviewCSS,DocType";
141		lConfigKeys = lConfigKeys & ",BaseHref,FullPage,Debug,AllowQueryStringDebug,SkinPath";
142		lConfigKeys = lConfigKeys & ",PreloadImages,PluginsPath,AutoDetectLanguage,DefaultLanguage,ContentLangDirection";
143		lConfigKeys = lConfigKeys & ",ProcessHTMLEntities,IncludeLatinEntities,IncludeGreekEntities,ProcessNumericEntities,AdditionalNumericEntities";
144		lConfigKeys = lConfigKeys & ",FillEmptyBlocks,FormatSource,FormatOutput,FormatIndentator";
145		lConfigKeys = lConfigKeys & ",GeckoUseSPAN,StartupFocus,ForcePasteAsPlainText,AutoDetectPasteFromWord,ForceSimpleAmpersand";
146		lConfigKeys = lConfigKeys & ",TabSpaces,ShowBorders,SourcePopup,ToolbarStartExpanded,ToolbarCanCollapse";
147		lConfigKeys = lConfigKeys & ",IgnoreEmptyParagraphValue,PreserveSessionOnFileBrowser,FloatingPanelsZIndex,TemplateReplaceAll,TemplateReplaceCheckbox";
148		lConfigKeys = lConfigKeys & ",ToolbarLocation,ToolbarSets,EnterMode,ShiftEnterMode,Keystrokes";
149		lConfigKeys = lConfigKeys & ",ContextMenu,BrowserContextMenuOnCtrl,FontColors,FontNames,FontSizes";
150		lConfigKeys = lConfigKeys & ",FontFormats,StylesXmlPath,TemplatesXmlPath,SpellChecker,IeSpellDownloadUrl";
151		lConfigKeys = lConfigKeys & ",SpellerPagesServerScript,FirefoxSpellChecker,MaxUndoLevels,DisableObjectResizing,DisableFFTableHandles";
152		lConfigKeys = lConfigKeys & ",LinkDlgHideTarget	,LinkDlgHideAdvanced,ImageDlgHideLink	,ImageDlgHideAdvanced,FlashDlgHideAdvanced";
153		lConfigKeys = lConfigKeys & ",ProtectedTags,BodyId,BodyClass,DefaultLinkTarget,CleanWordKeepsStructure";
154		lConfigKeys = lConfigKeys & ",LinkBrowser,LinkBrowserURL,LinkBrowserWindowWidth,LinkBrowserWindowHeight,ImageBrowser";
155		lConfigKeys = lConfigKeys & ",ImageBrowserURL,ImageBrowserWindowWidth,ImageBrowserWindowHeight,FlashBrowser,FlashBrowserURL";
156		lConfigKeys = lConfigKeys & ",FlashBrowserWindowWidth ,FlashBrowserWindowHeight,LinkUpload,LinkUploadURL,LinkUploadWindowWidth";
157		lConfigKeys = lConfigKeys & ",LinkUploadWindowHeight,LinkUploadAllowedExtensions,LinkUploadDeniedExtensions,ImageUpload,ImageUploadURL";
158		lConfigKeys = lConfigKeys & ",ImageUploadAllowedExtensions,ImageUploadDeniedExtensions,FlashUpload,FlashUploadURL,FlashUploadAllowedExtensions";
159		lConfigKeys = lConfigKeys & ",FlashUploadDeniedExtensions,SmileyPath,SmileyImages,SmileyColumns,SmileyWindowWidth,SmileyWindowHeight";
160
161		sConfig = "";
162
163		for( key in attributes.config )
164		{
165			iPos = listFindNoCase( lConfigKeys, key );
166			if( iPos GT 0 )
167			{
168				if( len( sConfig ) )
169					sConfig = sConfig & "&amp;";
170
171				fieldValue = attributes.config[key];
172				fieldName = listGetAt( lConfigKeys, iPos );
173
174				sConfig = sConfig & urlEncodedFormat( fieldName ) & '=' & urlEncodedFormat( fieldValue );
175			}
176		}
177	</cfscript>
178
179	<cfoutput>
180	<div>
181	<input type="hidden" id="#attributes.instanceName#" name="#attributes.instanceName#" value="#HTMLEditFormat(attributes.value)#" style="display:none" />
182	<input type="hidden" id="#attributes.instanceName#___Config" value="#sConfig#" style="display:none" />
183	<iframe id="#attributes.instanceName#___Frame" src="#sURL#" width="#attributes.width#" height="#attributes.height#" frameborder="0" scrolling="no"></iframe>
184	</div>
185	</cfoutput>
186
187<cfelse>
188
189	<!--- ::
190		 * show	plain textarea for non compatible browser
191		:: --->
192
193	<cfscript>
194		// append unit "px" for numeric width and/or height values
195		if( isNumeric( attributes.width ) )
196			attributes.width = attributes.width & "px";
197		if( isNumeric( attributes.height ) )
198			attributes.height = attributes.height & "px";
199	</cfscript>
200
201	<!--- Fixed Bug ##1075166. hk@lwd.de 20041206 --->
202	<cfoutput>
203	<div>
204	<textarea name="#attributes.instanceName#" rows="4" cols="40" style="WIDTH: #attributes.width#; HEIGHT: #attributes.height#">#HTMLEditFormat(attributes.value)#</textarea>
205	</div>
206	</cfoutput>
207
208</cfif>
209
210<cfsetting enablecfoutputonly="No"><cfexit method="exittag">
211