import rt 3.8.7
[freeside.git] / rt / share / html / NoAuth / RichText / FCKeditor / editor / dialog / fck_spellerpages / spellerpages / server-scripts / spellchecker.cfm
1 <cfsetting enablecfoutputonly="true">\r
2 <!---\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
5 \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
10 --->\r
11 \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
20 \r
21 <cfset form.checktext = form["textinputs[]"]>\r
22 \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
26 \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
29 \r
30 <!--- submitted_text now is ready for processing --->\r
31 \r
32 <!--- use carat on each line to escape possible aspell commands --->\r
33 <cfset text = "">\r
34 <cfset CRLF = Chr(13) & Chr(10)>\r
35 \r
36 <cfloop list="#submitted_text#" index="field" delimiters=",">\r
37         <cfset text = text & "%"  & CRLF\r
38                       & "^A" & CRLF\r
39                       & "!"  & 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
44         </cfloop>\r
45 </cfloop>\r
46 \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
49 \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
52 \r
53 <!--- read output file for further processing --->\r
54 <cffile action="read" file="#tempfile_out#" variable="food" charset="utf-8">\r
55 \r
56 <!--- remove temp files --->\r
57 <cffile action="delete" file="#tempfile_in#">\r
58 <cffile action="delete" file="#tempfile_out#">\r
59 \r
60 <cfset texts = StructNew()>\r
61 <cfset texts.textinputs = "">\r
62 <cfset texts.words      = "">\r
63 <cfset texts.abort      = "">\r
64 \r
65 <!--- Generate Text Inputs --->\r
66 <cfset i = 0>\r
67 <cfloop list="#submitted_text#" index="textinput">\r
68   <cfset texts.textinputs = ListAppend(texts.textinputs, 'textinputs[#i#] = decodeURIComponent("#textinput#");', CRLF)>\r
69   <cfset i = i + 1>\r
70 </cfloop>\r
71 \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
82     <cfelse>\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
94                 </cfif>\r
95      </cfif>\r
96 </cfloop>\r
97 \r
98 <cfif texts.words eq "">\r
99   <cfset texts.abort = "alert('Spell check complete.\n\nNo misspellings found.'); top.window.close();">\r
100 </cfif>\r
101 \r
102 <cfcontent type="text/html; charset=utf-8">\r
103 \r
104 <cfoutput><html>\r
105 <head>\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
113 var error;\r
114 \r
115 #texts.textinputs##CRLF#\r
116 #texts.words#\r
117 #texts.abort#\r
118 \r
119 var wordWindowObj = new wordWindow();\r
120 wordWindowObj.originalSpellings = words;\r
121 wordWindowObj.suggestions = suggs;\r
122 wordWindowObj.textInputs = textinputs;\r
123 \r
124 function init_spell() {\r
125         // check if any error occured during server-side processing\r
126         if( error ) {\r
127                 alert( error );\r
128         } else {\r
129                 // call the init_spell() function in the parent frameset\r
130                 if (parent.frames.length) {\r
131                         parent.init_spell( wordWindowObj );\r
132                 } else {\r
133                         alert('This page was loaded outside of a frameset. It might not display properly');\r
134                 }\r
135         }\r
136 }\r
137 </script>\r
138 \r
139 </head>\r
140 <body onLoad="init_spell();">\r
141 \r
142 <script type="text/javascript">\r
143 wordWindowObj.writeBody();\r
144 </script>\r
145 \r
146 </body>\r
147 </html></cfoutput>\r
148 <cfsetting enablecfoutputonly="false">\r