1<cfsetting enablecfoutputonly="true"> 2<!--- 3This code uses a CF User Defined Function and should work in CF version 5.0 4and up without alteration. 5 6Also if you are hosting your site at an ISP, you will have to check with them 7to see if the use of <CFEXECUTE> is allowed. In most cases ISP will not allow 8the use of that tag for security reasons. Clients would be able to access each 9others files in certain cases. 10---> 11 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"> 20 21<cfset form.checktext = form["textinputs[]"]> 22 23<!--- make no difference between URL and FORM scopes ---> 24<cfparam name="url.checktext" default=""> 25<cfparam name="form.checktext" default="#url.checktext#"> 26 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")> 29 30<!--- submitted_text now is ready for processing ---> 31 32<!--- use carat on each line to escape possible aspell commands ---> 33<cfset text = ""> 34<cfset CRLF = Chr(13) & Chr(10)> 35 36<cfloop list="#submitted_text#" index="field" delimiters=","> 37 <cfset text = text & "%" & CRLF 38 & "^A" & CRLF 39 & "!" & 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)> 44 </cfloop> 45</cfloop> 46 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"> 49 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"/> 52 53<!--- read output file for further processing ---> 54<cffile action="read" file="#tempfile_out#" variable="food" charset="utf-8"> 55 56<!--- remove temp files ---> 57<cffile action="delete" file="#tempfile_in#"> 58<cffile action="delete" file="#tempfile_out#"> 59 60<cfset texts = StructNew()> 61<cfset texts.textinputs = ""> 62<cfset texts.words = ""> 63<cfset texts.abort = ""> 64 65<!--- Generate Text Inputs ---> 66<cfset i = 0> 67<cfloop list="#submitted_text#" index="textinput"> 68 <cfset texts.textinputs = ListAppend(texts.textinputs, 'textinputs[#i#] = decodeURIComponent("#textinput#");', CRLF)> 69 <cfset i = i + 1> 70</cfloop> 71 72<!--- Generate Words Lists ---> 73<cfset word_cnt = 0> 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> 79 <cfset word_cnt = 0> 80 <cfset texts.words = ListAppend(texts.words, "words[#input_cnt#] = [];", CRLF)> 81 <cfset texts.words = ListAppend(texts.words, "suggs[#input_cnt#] = [];", CRLF)> 82 <cfelse> 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")> 87 <!--- sugestions ---> 88 <cfset sug_list = Trim(ListRest(aspell_line, ":"))> 89 <cfset sug_list = ListQualify(Replace(sug_list, "'", "\'", "ALL"), "'")> 90 <!--- javascript ---> 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> 94 </cfif> 95 </cfif> 96</cfloop> 97 98<cfif texts.words eq ""> 99 <cfset texts.abort = "alert('Spell check complete.\n\nNo misspellings found.'); top.window.close();"> 100</cfif> 101 102<cfcontent type="text/html; charset=utf-8"> 103 104<cfoutput><html> 105<head> 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"> 110var suggs = new Array(); 111var words = new Array(); 112var textinputs = new Array(); 113var error; 114 115#texts.textinputs##CRLF# 116#texts.words# 117#texts.abort# 118 119var wordWindowObj = new wordWindow(); 120wordWindowObj.originalSpellings = words; 121wordWindowObj.suggestions = suggs; 122wordWindowObj.textInputs = textinputs; 123 124function init_spell() { 125 // check if any error occured during server-side processing 126 if( error ) { 127 alert( error ); 128 } else { 129 // call the init_spell() function in the parent frameset 130 if (parent.frames.length) { 131 parent.init_spell( wordWindowObj ); 132 } else { 133 alert('This page was loaded outside of a frameset. It might not display properly'); 134 } 135 } 136} 137</script> 138 139</head> 140<body onLoad="init_spell();"> 141 142<script type="text/javascript"> 143wordWindowObj.writeBody(); 144</script> 145 146</body> 147</html></cfoutput> 148<cfsetting enablecfoutputonly="false"> 149