1
<cfsetting enablecfoutputonly="true">
3
This code uses a CF User Defined Function and should work in CF version 5.0
4
and up without alteration.
6
Also if you are hosting your site at an ISP, you will have to check with them
7
to see if the use of <CFEXECUTE> is allowed. In most cases ISP will not allow
8
the use of that tag for security reasons. Clients would be able to access each
9
others files in certain cases.
12
<!--- The following variables values must reflect your installation. --->
13
<cfset aspell_dir = "C:\Program Files\Aspell\bin">
14
<cfset lang = "en_US">
15
<cfset aspell_opts = "-a --lang=#lang# --encoding=utf-8 -H --rem-sgml-check=alt">
16
<cfset tempfile_in = GetTempFile(GetTempDirectory(), "spell_")>
17
<cfset tempfile_out = GetTempFile(GetTempDirectory(), "spell_")>
18
<cfset spellercss = "../spellerStyle.css">
19
<cfset word_win_src = "../wordWindow.js">
21
<cfset form.checktext = form["textinputs[]"]>
23
<!--- make no difference between URL and FORM scopes --->
24
<cfparam name="url.checktext" default="">
25
<cfparam name="form.checktext" default="#url.checktext#">
27
<!--- Takes care of those pesky smart quotes from MS apps, replaces them with regular quotes --->
28
<cfset submitted_text = ReplaceList(form.checktext,"%u201C,%u201D","%22,%22")>
30
<!--- submitted_text now is ready for processing --->
32
<!--- use carat on each line to escape possible aspell commands --->
34
<cfset CRLF = Chr(13) & Chr(10)>
36
<cfloop list="#submitted_text#" index="field" delimiters=",">
37
<cfset text = text & "%" & CRLF
40
<!--- Strip all tags for the text. (by FredCK - #339 / #681) --->
41
<cfset field = REReplace(URLDecode(field), "<[^>]+>", " ", "all")>
42
<cfloop list="#field#" index="line" delimiters="#CRLF#">
43
<cfset text = ListAppend(text, "^" & Trim(JSStringFormat(line)), CRLF)>
47
<!--- create temp file from the submitted text, this will be passed to aspell to be check for misspelled words --->
48
<cffile action="write" file="#tempfile_in#" output="#text#" charset="utf-8">
50
<!--- execute aspell in an UTF-8 console and redirect output to a file. UTF-8 encoding is lost if done differently --->
51
<cfexecute name="cmd.exe" arguments='/c type "#tempfile_in#" | "#aspell_dir#\aspell.exe" #aspell_opts# > "#tempfile_out#"' timeout="100"/>
53
<!--- read output file for further processing --->
54
<cffile action="read" file="#tempfile_out#" variable="food" charset="utf-8">
56
<!--- remove temp files --->
57
<cffile action="delete" file="#tempfile_in#">
58
<cffile action="delete" file="#tempfile_out#">
60
<cfset texts = StructNew()>
61
<cfset texts.textinputs = "">
62
<cfset texts.words = "">
63
<cfset texts.abort = "">
65
<!--- Generate Text Inputs --->
67
<cfloop list="#submitted_text#" index="textinput">
68
<cfset texts.textinputs = ListAppend(texts.textinputs, 'textinputs[#i#] = decodeURIComponent("#textinput#");', CRLF)>
72
<!--- Generate Words Lists --->
74
<cfset input_cnt = -1>
75
<cfloop list="#food#" index="aspell_line" delimiters="#CRLF#">
76
<cfset leftChar = Left(aspell_line, 1)>
77
<cfif leftChar eq "*">
78
<cfset input_cnt = input_cnt + 1>
80
<cfset texts.words = ListAppend(texts.words, "words[#input_cnt#] = [];", CRLF)>
81
<cfset texts.words = ListAppend(texts.words, "suggs[#input_cnt#] = [];", CRLF)>
83
<cfif leftChar eq "&" or leftChar eq "##">
84
<!--- word that misspelled --->
85
<cfset bad_word = Trim(ListGetAt(aspell_line, 2, " "))>
86
<cfset bad_word = Replace(bad_word, "'", "\'", "ALL")>
88
<cfset sug_list = Trim(ListRest(aspell_line, ":"))>
89
<cfset sug_list = ListQualify(Replace(sug_list, "'", "\'", "ALL"), "'")>
91
<cfset texts.words = ListAppend(texts.words, "words[#input_cnt#][#word_cnt#] = '#bad_word#';", CRLF)>
92
<cfset texts.words = ListAppend(texts.words, "suggs[#input_cnt#][#word_cnt#] = [#sug_list#];", CRLF)>
93
<cfset word_cnt = word_cnt + 1>
98
<cfif texts.words eq "">
99
<cfset texts.abort = "alert('Spell check complete.\n\nNo misspellings found.'); top.window.close();">
102
<cfcontent type="text/html; charset=utf-8">
106
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
107
<link rel="stylesheet" type="text/css" href="#spellercss#" />
108
<script language="javascript" src="#word_win_src#"></script>
109
<script language="javascript">
110
var suggs = new Array();
111
var words = new Array();
112
var textinputs = new Array();
115
#texts.textinputs##CRLF#
119
var wordWindowObj = new wordWindow();
120
wordWindowObj.originalSpellings = words;
121
wordWindowObj.suggestions = suggs;
122
wordWindowObj.textInputs = textinputs;
124
function init_spell() {
125
// check if any error occured during server-side processing
129
// call the init_spell() function in the parent frameset
130
if (parent.frames.length) {
131
parent.init_spell( wordWindowObj );
133
alert('This page was loaded outside of a frameset. It might not display properly');
140
<body onLoad="init_spell();">
142
<script type="text/javascript">
143
wordWindowObj.writeBody();
148
<cfsetting enablecfoutputonly="false">