6863e1905740dbb23eef9884248161e018512b90
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 function SpellLink( $cod, $tit, $ln ) {
17 echo "<td><a href=\"javascript:$cod\"".
18 " title=\"$tit\">$ln</a>".
23 // Declaring globals for E_ALL.
24 global $sqspell_text, $SQSPELL_APP, $sqspell_use_app, $attachment_dir,
25 $username, $SQSPELL_EREG, $color;
27 // Now we explode the lines for three reasons:
28 // 1) So we can ignore lines starting with ">" (reply's)
29 // 2) So we can stop processing when we get to "--" on a single line,
30 // which means that the signature is starting
31 // 3) So we can add an extra space at the beginning of each line. This way
32 // ispell/aspell don't treat these as command characters.
33 $sqspell_raw_lines = explode("\n", $sqspell_text);
34 for ($i=0; $i<sizeof($sqspell_raw_lines); $i++
){
35 if (trim($sqspell_raw_lines[$i]) == '--') break;
36 if(substr($sqspell_raw_lines[$i], 0, 1) != '>')
37 $sqspell_new_lines[$i] = ' ' . $sqspell_raw_lines[$i];
38 else $sqspell_new_lines[$i] = '';
40 $sqspell_new_text=implode("\n", $sqspell_new_lines);
42 // Define the command used to spellcheck the document.
43 $sqspell_command=$SQSPELL_APP[$sqspell_use_app];
44 // For the simplicity's sake we'll put all text into a file
45 // in attachment_dir directory, then cat it and pipe it to sqspell_command.
46 // There are other ways to do it, including popen(), but it's unidirectional
48 // NOTE: This will probably change in future releases of squirrelspell
49 // for privacy reasons.
51 $floc = "$attachment_dir/$username_sqspell_data.txt";
52 $fp=fopen($floc, 'w');
53 fwrite($fp, $sqspell_new_text);
55 exec("cat $floc | $sqspell_command", $sqspell_output);
58 // Load the user dictionary.
59 $words=sqspell_getLang(sqspell_getWords(), $sqspell_use_app);
60 // define some variables.
62 $missed_words=Array();
66 // Now we process the output of sqspell_command (ispell or aspell
67 // in ispell compatibility mode, whichever).
68 for ($i=0; $i<sizeof($sqspell_output); $i++
){
69 switch (substr($sqspell_output[$i], 0, 1)){
71 // Ispell adds empty lines when an end of line is reached
76 // This means there's a misspelled word and a few suggestions.
77 list($left, $right) = explode(": ", $sqspell_output[$i]);
78 $tmparray = explode(" ", $left);
79 $sqspell_word=$tmparray[1];
80 // Check if the word is in user dictionary.
81 if (!$SQSPELL_EREG("\n$sqspell_word\n", $words)){
82 $sqspell_symb=intval($tmparray[3])-1;
83 if (!$misses[$sqspell_word]) {
84 $misses[$sqspell_word] = $right;
85 $missed_words[$errors] = $sqspell_word;
88 if ($locations[$sqspell_word])
89 $locations[$sqspell_word] .= ', ';
90 $locations[$sqspell_word] .= "$current_line:$sqspell_symb";
95 // This means a misspelled word and no suggestions.
96 $tmparray = explode(" ", $sqspell_output[$i]);
97 $sqspell_word=$tmparray[1];
98 // Check if the word is in user dictionary.
99 if (!$SQSPELL_EREG("\n$sqspell_word\n", $words)){
100 $sqspell_symb=intval($tmparray[2])-1;
101 if (!$misses[$sqspell_word]) {
102 $misses[$sqspell_word] = '_NONE';
103 $missed_words[$errors] = $sqspell_word;
106 if ($locations[$sqspell_word]) $locations[$sqspell_word] .= ', ';
107 $locations[$sqspell_word] .= "$current_line:$sqspell_symb";
114 // So, there are errors
115 // This is the only place where the generic GUI-wrapper is not
116 // called, but generated right here. This is due to the complexity
121 '<title>' . _("SquirrelSpell Results") . '</title>';
122 if ($theme_css != '') {
123 echo "<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"$theme_css\">\n";
125 // Load the spelling errors into JavaScript arrays
126 echo "<script type=\"text/javascript\">\n".
129 $sqspell_lines = explode("\n", $sqspell_text);
130 // All lines of the message
131 echo "var sqspell_lines=new Array();\n";
132 for ($i=0; $i<sizeof($sqspell_lines); $i++
){
133 echo "sqspell_lines[$i] = \"" . chop(addslashes($sqspell_lines[$i])) . "\";\n";
137 // Misses are all misspelled words
138 echo "var misses=new Array();\n";
139 for ($i=0; $i<sizeof($missed_words); $i++
){
140 echo "misses[$i] = \"" . $missed_words[$i] . "\";\n";
144 // Suggestions are (guess what!) suggestions for misspellings
145 echo "var suggestions = new Array();\n";
147 while (list($word, $value) = each($misses)){
148 if ($value=='_NONE') $value='';
149 echo "suggestions[$i] = \"$value\";\n";
154 // Locations are where those misspellings are located, line:symbol
155 echo "var locations= new Array();\n";
157 while (list($word, $value) = each($locations)){
158 echo "locations[$i] = \"$value\";\n";
161 // Why isn't there a booger fairy?
164 "<script src=\"js/check_me.js\" type=\"text/javascript\"></script>\n".
167 echo "<body bgcolor=\"$color[4]\" text=\"$color[8]\" link=\"$color[7]\" alink=\"$color[7]\" vlink=\"$color[7]\" onload=\"populateSqspellForm()\">\n".
168 '<table width="100%" border="0" cellpadding="2">'.
169 "<tr><td bgcolor=\"$color[9]\" align=center><b>";
170 printf( _("Found %s errors"), $errors );
172 <tr
><td
><hr
></td
></tr
>
175 <input type
="hidden" name
="MOD" value
="forget_me_not">
176 <input type
="hidden" name
="words" value
="">
177 <input type
="hidden" name
="sqspell_use_app" value
="<?php echo $sqspell_use_app ?>">
178 <table border
="0" width
="100%">
182 $sptag = "<span style=\"background-color: $color[9]\">";
183 echo $sptag . _("Line with an error:") . '</span>';
186 <textarea name
="sqspell_line_area" cols
="50" rows
="3" wrap
="hard" onfocus
="this.blur()"></textarea
>
190 <td align
="right" width
="25%">
192 echo $sptag . _("Error:") . '</span>';
195 <td align
="left" width
="25%">
196 <input name
="sqspell_error" size
="10" value
="" onfocus
="this.blur()">
198 <td align
="right" width
="25%">
200 echo $sptag . _("Suggestions:") . '</span>';
203 <td align
="left" width
="25%">
204 <select name
="sqspell_suggestion" onchange
="if (this.options[this.selectedIndex].value != '_NONE') document.forms[0].sqspell_oruse.value=this.options[this.selectedIndex].value">
206 echo '<option>' . _("Suggestions") . '</option>';
214 echo $sptag . _("Change to:") . '</span>';
218 <input name
="sqspell_oruse" size
="15" value
=""
219 onfocus
="if(!this.value) this.value=document.forms[0].sqspell_error.value">
223 echo $sptag . _("Occurs times:") . '</span>';
227 <input name
="sqspell_likethis" size
=3 value
="" onfocus
="this.blur()">
231 <tr
><td colspan
="4"><hr
></td
></tr
>
234 <table border
="0" cellpadding
="0" cellspacing
="3" width
="100%">
236 echo "<tr align=center bgcolor=\"$color[9]\">";
238 SpellLink( 'sqspellChange()',
239 _("Change this word"),
241 SpellLink( 'sqspellChangeAll()',
242 _("Change ALL occurances of this word"),
244 SpellLink( 'sqspellIgnore()',
245 _("Ignore this word"),
247 SpellLink( 'sqspellIgnoreAll()',
248 _("Ignore ALL occurances this word"),
250 SpellLink( 'sqspellRemember()',
251 _("Add this word to your personal dictionary"),
258 <tr
><td colspan
="4"><hr
></td
></tr
>
262 echo "<td colspan=4 align=center bgcolor=\"$color[9]\">" .
263 '<input type="button" value=" ' .
264 _("Close and Commit") .
265 ' " onclick="if (confirm(\''.
266 _("The spellcheck is not finished. Really close and commit changes?").
267 '\')) sqspellCommitChanges()">'.
268 ' <input type="button" value=" '.
269 _("Close and Cancel") .
270 ' " onclick="if (confirm(\''.
271 _("The spellcheck is not finished. Really close and discard changes?").
272 '\')) self.close()">';
284 // AREN'T YOU SUCH A KNOW-IT-ALL!
285 $msg="<form onsubmit=\"return false\"><div align=\"center\"><input type=\"submit\" value=\" " . _("Close") . " \" onclick=\"self.close()\"></div></form>";
286 sqspell_makeWindow(null, _("No errors found"), null, $msg);