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