6 This module is the main workhorse of SquirrelSpell. It submits
7 the message to the spell-checker, parses the output, and loads
10 // Declaring globals for E_ALL.
11 global $sqspell_text, $SQSPELL_APP, $sqspell_use_app, $attachment_dir,
12 $username, $SQSPELL_EREG, $color;
14 // Now we explode the lines for three reasons:
15 // 1) So we can ignore lines starting with ">" (reply's)
16 // 2) So we can stop processing when we get to "--" on a single line,
17 // which means that the signature is starting
18 // 3) So we can add an extra space at the beginning of each line. This way
19 // ispell/aspell don't treat these as command characters.
20 $sqspell_raw_lines = explode("\n", $sqspell_text);
21 for ($i=0; $i<sizeof($sqspell_raw_lines); $i++
){
22 if (trim($sqspell_raw_lines[$i]) == "--") break;
23 if(substr($sqspell_raw_lines[$i], 0, 1) != ">")
24 $sqspell_new_lines[$i] = " " . $sqspell_raw_lines[$i];
25 else $sqspell_new_lines[$i] = "";
27 $sqspell_new_text=implode("\n", $sqspell_new_lines);
29 // Define the command used to spellcheck the document.
30 $sqspell_command=$SQSPELL_APP[$sqspell_use_app];
31 // For the simplicity's sake we'll put all text into a file
32 // in attachment_dir directory, then cat it and pipe it to sqspell_command.
33 // There are other ways to do it, including popen(), but it's unidirectional
35 // NOTE: This will probably change in future releases of squirrelspell
36 // for privacy reasons.
38 $floc = "$attachment_dir/$username" . "_sqspell_data.txt";
39 $fp=fopen($floc, "w");
40 fwrite($fp, $sqspell_new_text);
42 exec("cat $floc | $sqspell_command", $sqspell_output);
45 // Load the user dictionary.
46 $words=sqspell_getLang(sqspell_getWords(), $sqspell_use_app);
47 // define some variables.
49 $missed_words=Array();
53 // Now we process the output of sqspell_command (ispell or aspell
54 // in ispell compatibility mode, whichever).
55 for ($i=0; $i<sizeof($sqspell_output); $i++
){
56 switch (substr($sqspell_output[$i], 0, 1)){
58 // Ispell adds empty lines when an end of line is reached
63 // This means there's a misspelled word and a few suggestions.
64 list($left, $right) = explode(": ", $sqspell_output[$i]);
65 $tmparray = explode(" ", $left);
66 $sqspell_word=$tmparray[1];
67 // Check if the word is in user dictionary.
68 if (!$SQSPELL_EREG("\n$sqspell_word\n", $words)){
69 $sqspell_symb=intval($tmparray[3])-1;
70 if (!$misses[$sqspell_word]) {
71 $misses[$sqspell_word] = $right;
72 $missed_words[$errors] = $sqspell_word;
75 if ($locations[$sqspell_word]) $locations[$sqspell_word] .= ", ";
76 $locations[$sqspell_word] .= "$current_line:$sqspell_symb";
81 // This means a misspelled word and no suggestions.
82 $tmparray = explode(" ", $sqspell_output[$i]);
83 $sqspell_word=$tmparray[1];
84 // Check if the word is in user dictionary.
85 if (!$SQSPELL_EREG("\n$sqspell_word\n", $words)){
86 $sqspell_symb=intval($tmparray[2])-1;
87 if (!$misses[$sqspell_word]) {
88 $misses[$sqspell_word] = "_NONE";
89 $missed_words[$errors] = $sqspell_word;
92 if ($locations[$sqspell_word]) $locations[$sqspell_word] .= ", ";
93 $locations[$sqspell_word] .= "$current_line:$sqspell_symb";
100 // So, there are errors
101 // This is the only place where the generic GUI-wrapper is not
102 // called, but generated right here. This is due to the complexity
107 <title
>SquirrelSpell Results
</title
>
108 <script type
="text/javascript">
109 // Load the spelling errors into JavaScript arrays
112 $sqspell_lines = explode("\n", $sqspell_text);
113 echo "// All lines of the message
114 var sqspell_lines=new Array();\n";
115 for ($i=0; $i<sizeof($sqspell_lines); $i++
){
116 echo "sqspell_lines[$i] = \"" . chop(addslashes($sqspell_lines[$i])) . "\";\n";
120 echo "// Misses are all misspelled words
121 var misses=new Array();\n";
122 for ($i=0; $i<sizeof($missed_words); $i++
){
123 echo "misses[$i] = \"" . $missed_words[$i] . "\";\n";
127 echo "// Suggestions are (guess what!) suggestions for misspellings
128 var suggestions = new Array();\n";
130 while (list($word, $value) = each($misses)){
131 if ($value=="_NONE") $value="";
132 echo "suggestions[$i] = \"$value\";\n";
137 echo "// Locations are where those misspellings are located, line:symbol
138 var locations= new Array();\n";
140 while (list($word, $value) = each($locations)){
141 echo "locations[$i] = \"$value\";\n";
145 // Why isn't there a booger fairy?
148 <script src
="js/check_me.js" type
="text/javascript"></script
>
151 printf('<body bgcolor="%s" text="%s" link="%s" alink="%s" vlink="%s" onload="populateSqspellForm()">', $color[4], $color[8], $color[7], $color[7], $color[7]);
153 <table width
="100%" border
="0" cellpadding
="2">
154 <tr
><td bgcolor
="<?php echo $color[9] ?>" align
="center"><b
>Found
<?php
155 echo $errors ?
> errors
</b
></td
></tr
>
156 <tr
><td
><hr
></td
></tr
>
159 <input type
="hidden" name
="MOD" value
="forget_me_not">
160 <input type
="hidden" name
="words" value
="">
161 <input type
="hidden" name
="sqspell_use_app" value
="<?php echo $sqspell_use_app ?>">
162 <table border
="0" width
="100%">
165 <span style
="background-color:<?php echo $color[9] ?>">Line with an error
:</span
><br
>
166 <textarea name
="sqspell_line_area" cols
="50" rows
="3" wrap
="hard" onfocus
="this.blur()"></textarea
>
170 <td align
="right" width
="25%">
171 <span style
="background-color: <?php echo $color[9] ?>">Error
:</span
>
173 <td align
="left" width
="25%">
174 <input name
="sqspell_error" size
="10" value
="" onfocus
="this.blur()">
176 <td align
="right" width
="25%">
177 <span style
="background-color: <?php echo $color[9] ?>">Suggestions
:</span
>
179 <td align
="left" width
="25%">
180 <select name
="sqspell_suggestion" onchange
="if (this.options[this.selectedIndex].value != '_NONE') document.forms[0].sqspell_oruse.value=this.options[this.selectedIndex].value">
181 <option
>Suggestions
</option
>
187 <span style
="background-color: <?php echo $color[9] ?>">Change to
:</span
>
190 <input name
="sqspell_oruse" size
="15" value
=""
191 onfocus
="if(!this.value) this.value=document.forms[0].sqspell_error.value">
194 <span style
="background-color: <?php echo $color[9] ?>">Occurs times
:</span
>
197 <input name
="sqspell_likethis" size
=3 value
=""
198 onfocus
="this.blur()">
202 <tr
><td colspan
="4"><hr
></td
></tr
>
205 <table border
="0" cellpadding
="0" cellspacing
="3" width
="100%">
206 <tr align
="center" bgcolor
="<?php echo $color[9] ?>">
208 <a href
="javascript:sqspellChange()"
209 title
="Change this word">Change
</a
>
212 <a href
="javascript:sqspellChangeAll()"
213 title
="Change ALL occurances of this word">Change All
</a
>
216 <a href
="javascript:sqspellIgnore()"
217 title
="Ignore this word">Ignore
</a
>
220 <a href
="javascript:sqspellIgnoreAll()"
221 title
="Ignore ALL occurances of this word">Ignore All
</a
>
224 <a href
="javascript:sqspellRemember()"
225 title
="Add this word to your personal dictionary">Add to Dic
</a
>
231 <tr
><td colspan
="4"><hr
></td
></tr
>
233 <td colspan
="4" align
="center" bgcolor
="<?php echo $color[9] ?>">
234 <input type
="button" value
=" Close and Commit " onclick
="if (confirm('The spellcheck is not finished. Really close and commit changes?')) sqspellCommitChanges()">
235 <input type
="button" value
=" Close and Cancel " onclick
="if (confirm('The spellcheck is not finished. Really close and discard changes?')) self.close()">
246 // AREN'T YOU SUCH A KNOW-IT-ALL!
247 $msg="<form onsubmit=\"return false\"><div align=\"center\"><input type=\"submit\" value=\" Close \" onclick=\"self.close()\"></div></form>";
248 sqspell_makeWindow(null, "No errors found", null, $msg);