3 ** check_me.mod.php -- Squirrelspell module
5 ** Copyright (c) 1999-2001 The SquirrelMail development team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
8 ** This module is the main workhorse of SquirrelSpell. It submits
9 ** the message to the spell-checker, parses the output, and loads
10 ** the interface window.
15 // Declaring globals for E_ALL.
16 global $sqspell_text, $SQSPELL_APP, $sqspell_use_app, $attachment_dir,
17 $username, $SQSPELL_EREG, $color;
19 // Now we explode the lines for three reasons:
20 // 1) So we can ignore lines starting with ">" (reply's)
21 // 2) So we can stop processing when we get to "--" on a single line,
22 // which means that the signature is starting
23 // 3) So we can add an extra space at the beginning of each line. This way
24 // ispell/aspell don't treat these as command characters.
25 $sqspell_raw_lines = explode("\n", $sqspell_text);
26 for ($i=0; $i<sizeof($sqspell_raw_lines); $i++
){
27 if (trim($sqspell_raw_lines[$i]) == "--") break;
28 if(substr($sqspell_raw_lines[$i], 0, 1) != ">")
29 $sqspell_new_lines[$i] = " " . $sqspell_raw_lines[$i];
30 else $sqspell_new_lines[$i] = "";
32 $sqspell_new_text=implode("\n", $sqspell_new_lines);
34 // Define the command used to spellcheck the document.
35 $sqspell_command=$SQSPELL_APP[$sqspell_use_app];
36 // For the simplicity's sake we'll put all text into a file
37 // in attachment_dir directory, then cat it and pipe it to sqspell_command.
38 // There are other ways to do it, including popen(), but it's unidirectional
40 // NOTE: This will probably change in future releases of squirrelspell
41 // for privacy reasons.
43 $floc = "$attachment_dir/$username" . "_sqspell_data.txt";
44 $fp=fopen($floc, "w");
45 fwrite($fp, $sqspell_new_text);
47 exec("cat $floc | $sqspell_command", $sqspell_output);
50 // Load the user dictionary.
51 $words=sqspell_getLang(sqspell_getWords(), $sqspell_use_app);
52 // define some variables.
54 $missed_words=Array();
58 // Now we process the output of sqspell_command (ispell or aspell
59 // in ispell compatibility mode, whichever).
60 for ($i=0; $i<sizeof($sqspell_output); $i++
){
61 switch (substr($sqspell_output[$i], 0, 1)){
63 // Ispell adds empty lines when an end of line is reached
68 // This means there's a misspelled word and a few suggestions.
69 list($left, $right) = explode(": ", $sqspell_output[$i]);
70 $tmparray = explode(" ", $left);
71 $sqspell_word=$tmparray[1];
72 // Check if the word is in user dictionary.
73 if (!$SQSPELL_EREG("\n$sqspell_word\n", $words)){
74 $sqspell_symb=intval($tmparray[3])-1;
75 if (!$misses[$sqspell_word]) {
76 $misses[$sqspell_word] = $right;
77 $missed_words[$errors] = $sqspell_word;
80 if ($locations[$sqspell_word]) $locations[$sqspell_word] .= ", ";
81 $locations[$sqspell_word] .= "$current_line:$sqspell_symb";
86 // This means a misspelled word and no suggestions.
87 $tmparray = explode(" ", $sqspell_output[$i]);
88 $sqspell_word=$tmparray[1];
89 // Check if the word is in user dictionary.
90 if (!$SQSPELL_EREG("\n$sqspell_word\n", $words)){
91 $sqspell_symb=intval($tmparray[2])-1;
92 if (!$misses[$sqspell_word]) {
93 $misses[$sqspell_word] = "_NONE";
94 $missed_words[$errors] = $sqspell_word;
97 if ($locations[$sqspell_word]) $locations[$sqspell_word] .= ", ";
98 $locations[$sqspell_word] .= "$current_line:$sqspell_symb";
105 // So, there are errors
106 // This is the only place where the generic GUI-wrapper is not
107 // called, but generated right here. This is due to the complexity
112 <title
>SquirrelSpell Results
</title
>
113 <script type
="text/javascript">
114 // Load the spelling errors into JavaScript arrays
117 $sqspell_lines = explode("\n", $sqspell_text);
118 echo "// All lines of the message
119 var sqspell_lines=new Array();\n";
120 for ($i=0; $i<sizeof($sqspell_lines); $i++
){
121 echo "sqspell_lines[$i] = \"" . chop(addslashes($sqspell_lines[$i])) . "\";\n";
125 echo "// Misses are all misspelled words
126 var misses=new Array();\n";
127 for ($i=0; $i<sizeof($missed_words); $i++
){
128 echo "misses[$i] = \"" . $missed_words[$i] . "\";\n";
132 echo "// Suggestions are (guess what!) suggestions for misspellings
133 var suggestions = new Array();\n";
135 while (list($word, $value) = each($misses)){
136 if ($value=="_NONE") $value="";
137 echo "suggestions[$i] = \"$value\";\n";
142 echo "// Locations are where those misspellings are located, line:symbol
143 var locations= new Array();\n";
145 while (list($word, $value) = each($locations)){
146 echo "locations[$i] = \"$value\";\n";
150 // Why isn't there a booger fairy?
153 <script src
="js/check_me.js" type
="text/javascript"></script
>
156 printf('<body bgcolor="%s" text="%s" link="%s" alink="%s" vlink="%s" onload="populateSqspellForm()">', $color[4], $color[8], $color[7], $color[7], $color[7]);
158 <table width
="100%" border
="0" cellpadding
="2">
159 <tr
><td bgcolor
="<?php echo $color[9] ?>" align
="center"><b
>Found
<?php
160 echo $errors ?
> errors
</b
></td
></tr
>
161 <tr
><td
><hr
></td
></tr
>
164 <input type
="hidden" name
="MOD" value
="forget_me_not">
165 <input type
="hidden" name
="words" value
="">
166 <input type
="hidden" name
="sqspell_use_app" value
="<?php echo $sqspell_use_app ?>">
167 <table border
="0" width
="100%">
170 <span style
="background-color:<?php echo $color[9] . '">' . _("Line with an error:"); ?></span><br>
171 <textarea name="sqspell_line_area" cols="50" rows="3" wrap="hard" onfocus="this.blur()"></textarea>
175 <td align="right" width="25%">
176 <span style="background-color: <?php echo $color[9] ?>">Error:</span>
178 <td align="left" width="25%">
179 <input name="sqspell_error" size="10" value="" onfocus="this.blur()">
181 <td align="right" width="25%">
182 <span style="background-color: <?php echo $color[9] ?>">Suggestions:</span>
184 <td align="left" width="25%">
185 <select name="sqspell_suggestion" onchange="if (this.options[this.selectedIndex].value != '_NONE
') document.forms[0].sqspell_oruse.value=this.options[this.selectedIndex].value">
186 <option>Suggestions</option>
192 <span style="background-color: <?php echo $color[9] ?>">Change to:</span>
195 <input name="sqspell_oruse" size="15" value=""
196 onfocus="if(!this.value) this.value=document.forms[0].sqspell_error.value">
199 <span style="background-color: <?php echo $color[9] ?>">Occurs times:</span>
202 <input name="sqspell_likethis" size=3 value=""
203 onfocus="this.blur()">
207 <tr><td colspan="4"><hr></td></tr>
210 <table border="0" cellpadding="0" cellspacing="3" width="100%">
211 <tr align="center" bgcolor="<?php echo $color[9] ?>">
213 <a href="javascript:sqspellChange()"
214 title="Change this word">Change</a>
217 <a href="javascript:sqspellChangeAll()"
218 title="Change ALL occurances of this word">Change All</a>
221 <a href="javascript:sqspellIgnore()"
222 title="Ignore this word">Ignore</a>
225 <a href="javascript:sqspellIgnoreAll()"
226 title="Ignore ALL occurances of this word">Ignore All</a>
229 <a href="javascript:sqspellRemember()"
230 title="Add this word to your personal dictionary">Add to Dic</a>
236 <tr><td colspan="4"><hr></td></tr>
238 <td colspan="4" align="center" bgcolor="<?php echo $color[9] ?>">
239 <input type="button" value=" Close and Commit " onclick="if (confirm('The spellcheck is not finished
. Really close
and commit changes?
')) sqspellCommitChanges()">
240 <input type="button" value=" Close and Cancel " onclick="if (confirm('The spellcheck is not finished
. Really close
and discard changes?
')) self.close()">
251 // AREN'T YOU SUCH A KNOW
-IT
-ALL
!
252 $msg="<form onsubmit=\"return false\"><div align=\"center\"><input type=\"submit\" value=\" Close \" onclick=\"self.close()\"></div></form>";
253 sqspell_makeWindow(null, "No errors found", null, $msg);