Adding template for error box.
[squirrelmail.git] / plugins / squirrelspell / modules / check_me.mod
index d0594fd1d49e9670f8afa6a7e5e9021138e7cc71..7f0273bdca7400625eda7f37eb238efb39dd3819 100644 (file)
@@ -1,17 +1,17 @@
 <?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 &copy; 1999-2006 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package plugins
  * @subpackage squirrelspell
@@ -36,10 +36,14 @@ function SpellLink($jscode, $title, $link) {
 /**
  * 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:
@@ -94,29 +98,63 @@ if( check_php_version ( 4, 3 ) ) {
     );
     $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);
@@ -126,7 +164,7 @@ if( check_php_version ( 4, 3 ) ) {
  * 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>'
@@ -140,7 +178,7 @@ if ($sqspell_exitcode){
 /**
  * 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.
  */
@@ -176,7 +214,7 @@ for ($i=0; $i<sizeof($sqspell_output); $i++){
     /**
      * 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;
@@ -202,7 +240,7 @@ for ($i=0; $i<sizeof($sqspell_output); $i++){
      *
      * 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';
@@ -301,7 +339,7 @@ if ($errors){
    <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>
@@ -379,23 +417,23 @@ if ($errors){
        <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>
@@ -408,15 +446,15 @@ if ($errors){
         <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>
@@ -431,7 +469,7 @@ if ($errors){
   /**
    * 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);
@@ -444,4 +482,4 @@ if ($errors){
  * End:
  * vim: syntax=php et ts=4
  */
-?>
+?>
\ No newline at end of file