| 1 | <cfsetting enablecfoutputonly="true"> |
|---|
| 2 | <!--- |
|---|
| 3 | This code uses a CF User Defined Function and should work in CF version 5.0 |
|---|
| 4 | and up without alteration. |
|---|
| 5 | |
|---|
| 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. |
|---|
| 10 | ---> |
|---|
| 11 | |
|---|
| 12 | <!--- The following variables values must reflect your installation. ---> |
|---|
| 13 | <cfset apsell_dir = "C:\Program Files\Aspell\bin"> |
|---|
| 14 | <cfset lang = "de_DE"> |
|---|
| 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 | <cfloop list="#URLDecode(field)#" index="line" delimiters="#CRLF#"> |
|---|
| 41 | <cfset text = ListAppend(text, "^" & Trim(JSStringFormat(line)), CRLF)> |
|---|
| 42 | </cfloop> |
|---|
| 43 | </cfloop> |
|---|
| 44 | |
|---|
| 45 | <!--- create temp file from the submitted text, this will be passed to aspell to be check for misspelled words ---> |
|---|
| 46 | <cffile action="write" file="#tempfile_in#" output="#text#" charset="utf-8"> |
|---|
| 47 | |
|---|
| 48 | <!--- execute aspell in an UTF-8 console and redirect output to a file. UTF-8 encoding is lost if done differently ---> |
|---|
| 49 | <cfexecute name="cmd.exe" arguments='/c type "#tempfile_in#" | "#apsell_dir#\aspell.exe" #aspell_opts# > "#tempfile_out#"' timeout="10"/> |
|---|
| 50 | |
|---|
| 51 | <!--- read output file for further processing ---> |
|---|
| 52 | <cffile action="read" file="#tempfile_out#" variable="food" charset="utf-8"> |
|---|
| 53 | |
|---|
| 54 | <!--- remove temp files ---> |
|---|
| 55 | <cffile action="delete" file="#tempfile_in#"> |
|---|
| 56 | <cffile action="delete" file="#tempfile_out#"> |
|---|
| 57 | |
|---|
| 58 | <cfset texts = StructNew()> |
|---|
| 59 | <cfset texts.textinputs = ""> |
|---|
| 60 | <cfset texts.words = ""> |
|---|
| 61 | <cfset texts.abort = ""> |
|---|
| 62 | |
|---|
| 63 | <!--- Generate Text Inputs ---> |
|---|
| 64 | <cfset i = 0> |
|---|
| 65 | <cfloop list="#submitted_text#" index="textinput"> |
|---|
| 66 | <cfset texts.textinputs = ListAppend(texts.textinputs, 'textinputs[#i#] = decodeURIComponent("#textinput#");', CRLF)> |
|---|
| 67 | <cfset i = i + 1> |
|---|
| 68 | </cfloop> |
|---|
| 69 | |
|---|
| 70 | <!--- Generate Words Lists ---> |
|---|
| 71 | <cfset word_cnt = 0> |
|---|
| 72 | <cfset input_cnt = -1> |
|---|
| 73 | <cfloop list="#food#" index="aspell_line" delimiters="#CRLF#"> |
|---|
| 74 | <cfswitch expression="#Left(aspell_line, 1)#"> |
|---|
| 75 | <cfcase value="*"> |
|---|
| 76 | <cfset input_cnt = input_cnt + 1> |
|---|
| 77 | <cfset word_cnt = 0> |
|---|
| 78 | <cfset texts.words = ListAppend(texts.words, "words[#input_cnt#] = [];", CRLF)> |
|---|
| 79 | <cfset texts.words = ListAppend(texts.words, "suggs[#input_cnt#] = [];", CRLF)> |
|---|
| 80 | </cfcase> |
|---|
| 81 | <cfcase value="&,##"> |
|---|
| 82 | <!--- word that misspelled ---> |
|---|
| 83 | <cfset bad_word = Trim(ListGetAt(aspell_line, 2, " "))> |
|---|
| 84 | <cfset bad_word = Replace(bad_word, "'", "\'", "ALL")> |
|---|
| 85 | <!--- sugestions ---> |
|---|
| 86 | <cfset sug_list = Trim(ListRest(aspell_line, ":"))> |
|---|
| 87 | <cfset sug_list = ListQualify(Replace(sug_list, "'", "\'", "ALL"), "'")> |
|---|
| 88 | <!--- javascript ---> |
|---|
| 89 | <cfset texts.words = ListAppend(texts.words, "words[#input_cnt#][#word_cnt#] = '#bad_word#';", CRLF)> |
|---|
| 90 | <cfset texts.words = ListAppend(texts.words, "suggs[#input_cnt#][#word_cnt#] = [#sug_list#];", CRLF)> |
|---|
| 91 | <cfset word_cnt = word_cnt + 1> |
|---|
| 92 | </cfcase> |
|---|
| 93 | </cfswitch> |
|---|
| 94 | </cfloop> |
|---|
| 95 | |
|---|
| 96 | <cfif texts.words eq ""> |
|---|
| 97 | <cfset texts.abort = "alert('Spell check complete.\n\nNo misspellings found.'); top.window.close();"> |
|---|
| 98 | </cfif> |
|---|
| 99 | |
|---|
| 100 | <cfcontent type="text/html; charset=utf-8"> |
|---|
| 101 | |
|---|
| 102 | <cfoutput><html> |
|---|
| 103 | <head> |
|---|
| 104 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
|---|
| 105 | <link rel="stylesheet" type="text/css" href="#spellercss#" /> |
|---|
| 106 | <script language="javascript" src="#word_win_src#"></script> |
|---|
| 107 | <script language="javascript"> |
|---|
| 108 | var suggs = new Array(); |
|---|
| 109 | var words = new Array(); |
|---|
| 110 | var textinputs = new Array(); |
|---|
| 111 | var error; |
|---|
| 112 | |
|---|
| 113 | #texts.textinputs##CRLF# |
|---|
| 114 | #texts.words# |
|---|
| 115 | #texts.abort# |
|---|
| 116 | |
|---|
| 117 | var wordWindowObj = new wordWindow(); |
|---|
| 118 | wordWindowObj.originalSpellings = words; |
|---|
| 119 | wordWindowObj.suggestions = suggs; |
|---|
| 120 | wordWindowObj.textInputs = textinputs; |
|---|
| 121 | |
|---|
| 122 | function init_spell() { |
|---|
| 123 | // check if any error occured during server-side processing |
|---|
| 124 | if( error ) { |
|---|
| 125 | alert( error ); |
|---|
| 126 | } else { |
|---|
| 127 | // call the init_spell() function in the parent frameset |
|---|
| 128 | if (parent.frames.length) { |
|---|
| 129 | parent.init_spell( wordWindowObj ); |
|---|
| 130 | } else { |
|---|
| 131 | alert('This page was loaded outside of a frameset. It might not display properly'); |
|---|
| 132 | } |
|---|
| 133 | } |
|---|
| 134 | } |
|---|
| 135 | </script> |
|---|
| 136 | |
|---|
| 137 | </head> |
|---|
| 138 | <body onLoad="init_spell();"> |
|---|
| 139 | |
|---|
| 140 | <script type="text/javascript"> |
|---|
| 141 | wordWindowObj.writeBody(); |
|---|
| 142 | </script> |
|---|
| 143 | |
|---|
| 144 | </body> |
|---|
| 145 | </html></cfoutput> |
|---|
| 146 | <cfsetting enablecfoutputonly="false"> |
|---|