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}
86else
87{
88	// If we should not check browser compatibility, assume true
89	isCompatibleBrowser = true;
90}
91</cfscript>
92
93<cfif isCompatibleBrowser>
94
95	<!--- ::
96		 * show html editor area for compatible browser
97		:: --->
98
99	<cfscript>
100		// try to fix the basePath, if ending slash is missing
101		if( len( attributes.basePath) and right( attributes.basePath, 1 ) is not "/" )
102			attributes.basePath = attributes.basePath & "/";
103
104		// construct the url
105		sURL = attributes.basePath & "editor/fckeditor.html?InstanceName=" & attributes.instanceName;
106
107		// append toolbarset name to the url
108		if( len( attributes.toolbarSet ) )
109			sURL = sURL & "&amp;Toolbar=" & attributes.toolbarSet;
110
111		// create configuration string: Key1=Value1&Key2=Value2&... (Key/Value:HTML encoded)
112
113		/**
114		 * CFML doesn't store casesensitive names for structure keys, but the configuration names must be casesensitive for js.
115		 * So we need to find out the correct case for the configuration keys.
116		 * We "fix" this by comparing the caseless configuration keys to a list of all available configuration options in the correct case.
117		 * changed 20041206 hk@lwd.de (improvements are welcome!)
118		 */
119		lConfigKeys = "";
120		lConfigKeys = lConfigKeys & "CustomConfigurationsPath,EditorAreaCSS,DocType,BaseHref,FullPage,Debug,SkinPath,PluginsPath,AutoDetectLanguage,DefaultLanguage,ContentLangDirection,EnableXHTML,EnableSourceXHTML,ProcessHTMLEntities,IncludeLatinEntities,IncludeGreekEntities";
121		lConfigKeys = lConfigKeys & ",FillEmptyBlocks,FormatSource,FormatOutput,FormatIndentator,GeckoUseSPAN,StartupFocus,ForcePasteAsPlainText,ForceSimpleAmpersand,TabSpaces,ShowBorders,UseBROnCarriageReturn";
122		lConfigKeys = lConfigKeys & ",ToolbarStartExpanded,ToolbarCanCollapse,ToolbarSets,ContextMenu,FontColors,FontNames,FontSizes,FontFormats,StylesXmlPath,SpellChecker,IeSpellDownloadUrl,MaxUndoLevels";
123		lConfigKeys = lConfigKeys & ",LinkBrowser,LinkBrowserURL,LinkBrowserWindowWidth,LinkBrowserWindowHeight";
124		lConfigKeys = lConfigKeys & ",LinkUpload,LinkUploadURL,LinkUploadWindowWidth,LinkUploadWindowHeight,LinkUploadAllowedExtensions,LinkUploadDeniedExtensions";
125		lConfigKeys = lConfigKeys & ",ImageBrowser,ImageBrowserURL,ImageBrowserWindowWidth,ImageBrowserWindowHeight,SmileyPath,SmileyImages,SmileyColumns,SmileyWindowWidth,SmileyWindowHeight";
126
127		sConfig = "";
128
129		for( key in attributes.config )
130		{
131			iPos = listFindNoCase( lConfigKeys, key );
132			if( iPos GT 0 )
133			{
134				if( len( sConfig ) )
135					sConfig = sConfig & "&amp;";
136
137				fieldValue = attributes.config[key];
138				fieldName = listGetAt( lConfigKeys, iPos );
139
140				sConfig = sConfig & urlEncodedFormat( fieldName ) & '=' & urlEncodedFormat( fieldValue );
141			}
142		}
143	</cfscript>
144
145	<cfoutput>
146	<div>
147	<input type="hidden" id="#attributes.instanceName#" name="#attributes.instanceName#" value="#HTMLEditFormat(attributes.value)#" style="display:none" />
148	<input type="hidden" id="#attributes.instanceName#___Config" value="#sConfig#" style="display:none" />
149	<iframe id="#attributes.instanceName#___Frame" src="#sURL#" width="#attributes.width#" height="#attributes.height#" frameborder="0" scrolling="no"></iframe>
150	</div>
151	</cfoutput>
152
153<cfelse>
154
155	<!--- ::
156		 * show	plain textarea for non compatible browser
157		:: --->
158
159	<cfscript>
160		// append unit "px" for numeric width and/or height values
161		if( isNumeric( attributes.width ) )
162			attributes.width = attributes.width & "px";
163		if( isNumeric( attributes.height ) )
164			attributes.height = attributes.height & "px";
165	</cfscript>
166
167	<!--- Fixed Bug ##1075166. hk@lwd.de 20041206 --->
168	<cfoutput>
169	<div>
170	<textarea name="#attributes.instanceName#" rows="4" cols="40" style="WIDTH: #attributes.width#; HEIGHT: #attributes.height#">#HTMLEditFormat(attributes.value)#</textarea>
171	</div>
172	</cfoutput>
173
174</cfif>
175
176<cfsetting enablecfoutputonly="No"><cfexit method="exittag">