<?php
+
/**
* check_me.mod
- * -------------
- * Squirrelspell module.
*
- * Copyright (c) 1999-2005 The SquirrelMail development team
- * Licensed under the GNU GPL. For full terms see the file COPYING.
+ * Squirrelspell module.
*
* This module is the main workhorse of SquirrelSpell. It submits
* the message to the spell-checker, parses the output, and loads
* the interface window.
*
- * @author Konstantin Riabitsev <icon@duke.edu>
+ * @author Konstantin Riabitsev <icon at duke.edu>
+ * @copyright © 1999-2006 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id$
* @package plugins
* @subpackage squirrelspell
/**
* Declaring globals for users with E_ALL set.
*/
-global $SQSPELL_APP, $attachment_dir, $SQSPELL_EREG, $color;
+global $SQSPELL_APP_DEFAULT, $SQSPELL_APP, $attachment_dir, $color;
-$sqspell_text = $_POST['sqspell_text'];
-$sqspell_use_app = $_POST['sqspell_use_app'];
+if (! sqgetGlobalVar('sqspell_text',$sqspell_text,SQ_POST)) {
+ $sqspell_text = '';
+}
+if (! sqgetGlobalVar('sqspell_use_app',$sqspell_use_app,SQ_POST)) {
+ $sqspell_use_app = $SQSPELL_APP_DEFAULT;
+}
/**
* Now we explode the lines for three reasons:
);
$spell_proc = @proc_open($sqspell_command, $descriptorspec, $pipes);
if ( ! is_resource ( $spell_proc ) ) {
- error_box ( _("Could not run the spellchecker command (%s).",
+ // TODO: replace error_box() with sqspell_makeWindow()
+ error_box ( sprintf(_("Could not run the spellchecker command (%s)."),
htmlspecialchars($sqspell_command) ) , $color );
+ // close html tags and abort script.
+ echo "</body></html>";
+ exit();
+ }
+ if ( ! @fwrite($pipes[0], $sqspell_new_text) ) {
+ // TODO: replace error_box() with sqspell_makeWindow()
+ error_box ( _("Error while writing to pipe.") , $color );
+ // close all three $pipes here.
+ for($i=0; $i<=2; $i++) {
+ // disable all fclose error messages
+ @fclose($pipes[$i]);
+ }
+ // close html tags and abort script.
+ echo "</body></html>";
+ exit();
}
- fwrite($pipes[0], $sqspell_new_text);
fclose($pipes[0]);
$sqspell_output = array();
for($i=1; $i<=2; $i++) {
while(!feof($pipes[$i])) {
- array_push($sqspell_output, rtrim(fgetss($pipes[$i],999),"\n"));
+ array_push($sqspell_output, rtrim(fgetss($pipes[$i],999),"\r\n"));
}
fclose($pipes[$i]);
}
$sqspell_exitcode=proc_close($spell_proc);
} else {
+ // add slash to attachment directory, if it does not end with slash.
+ if (substr($attachment_dir, -1) != '/')
+ $attachment_dir = $attachment_dir . '/';
+
+ // find unused file in attachment directory
do {
- $floc = "$attachment_dir/" . md5($sqspell_new_text . microtime());
+ $floc = $attachment_dir . md5($sqspell_new_text . microtime());
} while (file_exists($floc));
+
$fp = @fopen($floc, 'w');
if ( ! is_resource ($fp) ) {
- error_box ( _("Could not open temporary file '%s'.",
+ // TODO: replace error_box() with sqspell_makeWindow()
+ error_box ( sprintf(_("Could not open temporary file '%s'."),
+ htmlspecialchars($floc) ) , $color );
+ // failed to open temp file. abort script.
+ echo "</body></html>";
+ exit();
+ }
+ if ( ! @fwrite($fp, $sqspell_new_text) ) {
+ // TODO: replace error_box() with sqspell_makeWindow()
+ error_box ( sprintf(_("Error while writing to temporary file '%s'."),
htmlspecialchars($floc) ) , $color );
+ // close file descriptor
+ fclose($fp);
+ // failed writing to temp file. abort script.
+ echo "</body></html>";
+ exit();
}
- fwrite($fp, $sqspell_new_text);
fclose($fp);
exec("$sqspell_command < $floc 2>&1", $sqspell_output, $sqspell_exitcode);
unlink($floc);
* Check if the execution was successful. Bail out if it wasn't.
*/
if ($sqspell_exitcode){
- $msg= "<div align='center'>"
+ $msg= '<div style="text-align: center;">'
. sprintf(_("I tried to execute '%s', but it returned:"),
$sqspell_command) . "<pre>"
. htmlspecialchars(join("\n", $sqspell_output)) . '</pre>'
/**
* Load the user dictionary.
*/
-$words=sqspell_getLang(sqspell_getWords(), $sqspell_use_app);
+$words=sqspell_getLang($sqspell_use_app);
/**
* Define some variables to be used during the processing.
*/
/**
* Check if the word is in user dictionary.
*/
- if (!$SQSPELL_EREG("\n$sqspell_word\n", $words)){
+ if (! in_array($sqspell_word,$words)){
$sqspell_symb=intval($tmparray[3])-1;
if (!isset($misses[$sqspell_word])) {
$misses[$sqspell_word] = $right;
*
* Check if the word is in user dictionary.
*/
- if (!$SQSPELL_EREG("\n$sqspell_word\n", $words)){
+ if (!in_array($sqspell_word,$words)){
$sqspell_symb=intval($tmparray[2])-1;
if (!isset($misses[$sqspell_word])) {
$misses[$sqspell_word] = '_NONE';
<tr>
<td bgcolor="<?php echo $color[9] ?>" align="center">
<b>
- <?php printf( _("Found %s errors"), $errors ) ?>
+ <?php printf( ngettext("Found %d error","Found %d errors",$errors), $errors ) ?>
</b>
</td>
</tr>
<tr>
<td colspan="4">
<table border="0" cellpadding="0" cellspacing="3" width="100%">
- <tr align="center" bgcolor="<?php echo $color[9] ?>">
+ <tr align="center" bgcolor="<?php echo $color[9] ?>">
<?php
- SpellLink('sqspellChange()',
- _("Change this word"),
- _("Change"));
- SpellLink('sqspellChangeAll()',
- _("Change ALL occurances of this word"),
- _("Change All"));
- SpellLink('sqspellIgnore()',
- _("Ignore this word"),
- _("Ignore"));
- SpellLink('sqspellIgnoreAll()',
- _("Ignore ALL occurances this word"),
- _("Ignore All"));
- SpellLink('sqspellRemember()',
- _("Add this word to your personal dictionary"),
- _("Add to Dic"));
+ SpellLink('sqspellChange()',
+ _("Change this word"),
+ _("Change"));
+ SpellLink('sqspellChangeAll()',
+ _("Change ALL occurances of this word"),
+ _("Change All"));
+ SpellLink('sqspellIgnore()',
+ _("Ignore this word"),
+ _("Ignore"));
+ SpellLink('sqspellIgnoreAll()',
+ _("Ignore ALL occurances this word"),
+ _("Ignore All"));
+ SpellLink('sqspellRemember()',
+ _("Add this word to your personal dictionary"),
+ _("Add to Dic"));
?>
</tr>
</table>
<td colspan="4" align="center" bgcolor="<?php echo $color[9] ?>">
<?php
echo '<input type="button" value=" '
- . _("Close and Commit")
- . ' " onclick="if (confirm(\''
- . _("The spellcheck is not finished. Really close and commit changes?")
- . '\')) sqspellCommitChanges()" />'
- . ' <input type="button" value=" '
- . _("Close and Cancel")
- . ' " onclick="if (confirm(\''
- . _("The spellcheck is not finished. Really close and discard changes?")
- . '\')) self.close()" />';
+ . _("Close and Commit")
+ . ' " onclick="if (confirm(\''
+ . _("The spellcheck is not finished. Really close and commit changes?")
+ . '\')) sqspellCommitChanges()" />'
+ . ' <input type="button" value=" '
+ . _("Close and Cancel")
+ . ' " onclick="if (confirm(\''
+ . _("The spellcheck is not finished. Really close and discard changes?")
+ . '\')) self.close()" />';
?>
</td>
</tr>
/**
* AREN'T YOU SUCH A KNOW-IT-ALL!
*/
- $msg='<form onsubmit="return false"><div align="center">'.
+ $msg='<form onsubmit="return false"><div style="text-align: center;">' .
'<input type="submit" value=" ' . _("Close") .
' " onclick="self.close()" /></div></form>';
sqspell_makeWindow(null, _("No errors found"), null, $msg);
* End:
* vim: syntax=php et ts=4
*/
-?>
+?>
\ No newline at end of file