Replacing tabs with spaces, trimming white space at EOL and newline at EOF
[squirrelmail.git] / plugins / squirrelspell / modules / check_me.mod
index 3281d6ed66814343c67e28e9db87dac2809f7e78..b0797e51b39839a6fd065567913595179c4e7f0f 100644 (file)
  * the message to the spell-checker, parses the output, and loads
  * the interface window.
  *
- * $Id$
- *
- * @author Konstantin Riabitsev <icon@duke.edu> ($Author$)
- * @version $Date$
+ * @author Konstantin Riabitsev <icon@duke.edu>
+ * @version $Id$
+ * @package plugins
+ * @subpackage squirrelspell
  */
 
 /**
@@ -66,7 +66,7 @@ for ($i=0; $i<sizeof($sqspell_raw_lines); $i++){
   if(substr($sqspell_raw_lines[$i], 0, 1) != '>'){
     $sqspell_new_lines[$i] = ' ' . $sqspell_raw_lines[$i];
   } else {
-    $sqspell_new_lines[$i] = '';
+    $sqspell_new_lines[$i] = ' ';
   }
 }
 /**
@@ -82,7 +82,7 @@ $sqspell_command=$SQSPELL_APP[$sqspell_use_app];
 /**
  * If you have php >= 4.3.0, we can use proc_open and safe mode
  * and not mess w/ temp files.  Otherwise we will do it the old
- * way, (minus the uneeded call to cat that messes up Wintel 
+ * way, (minus the uneeded call to cat that messes up Wintel
  * boxen.)
  * Thanks Ray Ferguson for providing this patch.
  */
@@ -98,8 +98,8 @@ if( check_php_version ( 4, 3 ) ) {
     $sqspell_output = array();
     for($i=1; $i<=2; $i++){
         while(!feof($pipes[$i]))
-           array_push($sqspell_output, rtrim(fgetss($pipes[$i],999),"\n")); 
-       fclose($pipes[$i]);
+           array_push($sqspell_output, rtrim(fgetss($pipes[$i],999),"\n"));
+        fclose($pipes[$i]);
     }
     $sqspell_exitcode=proc_close($spell_proc);
 } else {
@@ -120,7 +120,7 @@ if ($sqspell_exitcode){
   $msg= "<div align='center'>"
      . sprintf(_("I tried to execute '%s', but it returned:"),
                $sqspell_command) . "<pre>"
-     . join("\n", htmlspecialchars($sqspell_output)) . "</pre>"
+     . htmlspecialchars(join("\n", $sqspell_output)) . '</pre>'
      . '<form onsubmit="return false">'
      . '<input type="submit" value="  ' . _("Close")
      . '  " onclick="self.close()" /></form></div>';
@@ -176,7 +176,7 @@ for ($i=0; $i<sizeof($sqspell_output); $i++){
       }
       if (isset($locations[$sqspell_word])){
         $locations[$sqspell_word] .= ', ';
-      } else { 
+      } else {
         $locations[$sqspell_word] = '';
       }
       $locations[$sqspell_word] .= "$current_line:$sqspell_symb";
@@ -190,21 +190,21 @@ for ($i=0; $i<sizeof($sqspell_output); $i++){
     $tmparray = explode(" ", $sqspell_output[$i]);
     $sqspell_word=$tmparray[1];
     /**
-     * 
+     *
      * Check if the word is in user dictionary.
      */
     if (!$SQSPELL_EREG("\n$sqspell_word\n", $words)){
       $sqspell_symb=intval($tmparray[2])-1;
       if (!isset($misses[$sqspell_word])) {
-           $misses[$sqspell_word] = '_NONE';
-           $missed_words[$errors] = $sqspell_word;
-           $errors++;
+          $misses[$sqspell_word] = '_NONE';
+          $missed_words[$errors] = $sqspell_word;
+          $errors++;
       }
       if (isset($locations[$sqspell_word])) {
-           $locations[$sqspell_word] .= ', ';
+          $locations[$sqspell_word] .= ', ';
       } else {
-           $locations[$sqspell_word] = '';
-         }
+          $locations[$sqspell_word] = '';
+      }
       $locations[$sqspell_word] .= "$current_line:$sqspell_symb";
     }
   break;
@@ -212,91 +212,78 @@ for ($i=0; $i<sizeof($sqspell_output); $i++){
 }
 
 if ($errors){
-  /**
-   * So, there are errors
-   * This is the only place where the generic GUI-wrapper is not
-   * called, but generated right here. This is due to the complexity
-   * of the output.
-   */
-  echo "<html>\n"
-    . "<head>\n"
-    . '<title>' . _("SquirrelSpell Results") . '</title>';
-  /**
-   * Check if there are user-defined stylesheets.
-   */
-  if ($theme_css != '') {
-    echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$theme_css\" />\n";
-  }
   /**
    * Load the spelling errors into JavaScript arrays
    * (More dark magic!)
    */
-  echo "<script type=\"text/javascript\">\n"
+  $extrajs="<script type=\"text/javascript\">\n"
     . "<!--\n";
-  
+
   $sqspell_lines = explode("\n", $sqspell_text);
   /**
    * The javascript array sqspell_lines[] contains all lines of
    * the message we've been checking.
    */
-  echo "var sqspell_lines=new Array();\n";
+  $extrajs.= "var sqspell_lines=new Array();\n";
   for ($i=0; $i<sizeof($sqspell_lines); $i++){
-    echo "sqspell_lines[$i] = \"" 
+    $extrajs.= "sqspell_lines[$i] = \""
       . chop(addslashes($sqspell_lines[$i])) . "\";\n";
-  }  
-  echo "\n\n";
+  }
+  $extrajs.= "\n\n";
 
   /**
    * The javascript array misses[] contais all misspelled words.
    */
-  echo "var misses=new Array();\n";
+  $extrajs.= "var misses=new Array();\n";
   for ($i=0; $i<sizeof($missed_words); $i++){
-    echo "misses[$i] = \"" . $missed_words[$i] . "\";\n";
+    $extrajs.= "misses[$i] = \"" . $missed_words[$i] . "\";\n";
   }
-  echo "\n\n";
-  
+  $extrajs.= "\n\n";
+
   /**
    * Suggestions are (guess what!) suggestions for misspellings
    */
-  echo "var suggestions = new Array();\n";
+  $extrajs.= "var suggestions = new Array();\n";
   $i=0;
   while (list($word, $value) = each($misses)){
     if ($value=='_NONE') $value='';
-    echo "suggestions[$i] = \"$value\";\n";
+    $extrajs.= "suggestions[$i] = \"$value\";\n";
     $i++;
   }
-  echo "\n\n";
+  $extrajs.= "\n\n";
 
   /**
    * Locations are where those misspellings are located, line:symbol
    */
-  echo "var locations= new Array();\n";
+  $extrajs.= "var locations= new Array();\n";
   $i=0;
   while (list($word, $value) = each($locations)){
-    echo "locations[$i] = \"$value\";\n";
+    $extrajs.= "locations[$i] = \"$value\";\n";
     $i++;
   }
 
-  /** 
+  /**
    * Add some strings so they can be i18n'd.
    */
-  echo "var ui_completed = \"" . _("Spellcheck completed. Commit changes?")
+  $extrajs.= "var ui_completed = \"" . _("Spellcheck completed. Commit changes?")
     . "\";\n";
-  echo "var ui_nochange = \"" . _("No changes were made.") . "\";\n";
-  echo "var ui_wait = \"" 
+  $extrajs.= "var ui_nochange = \"" . _("No changes were made.") . "\";\n";
+  $extrajs.= "var ui_wait = \""
     . _("Now saving your personal dictionary... Please wait.")
     . "\";\n";
-  
+
 
   /**
    * Did I mention that I hate dots on the end of contcatenated lines?
    * Dots at the beginning make so much more sense!
    */
-  echo "//-->\n"
+  $extrajs.= "//-->\n"
     . "</script>\n"
-    . "<script src=\"js/check_me.js\" type=\"text/javascript\"></script>\n"
-    . "</head>\n";
-  
+    . "<script src=\"js/check_me.js\" type=\"text/javascript\"></script>\n";
+
+
+  displayHtmlHeader(_("SquirrelSpell Results"),$extrajs);
+
   echo "<body bgcolor=\"$color[4]\" text=\"$color[8]\" link=\"$color[7]\" "
     . "alink=\"$color[7]\" vlink=\"$color[7]\" "
     . "onload=\"populateSqspellForm()\">\n";
@@ -319,7 +306,7 @@ if ($errors){
      <form method="post">
       <input type="hidden" name="MOD" value="forget_me_not" />
       <input type="hidden" name="words" value="" />
-      <input type="hidden" name="sqspell_use_app" 
+      <input type="hidden" name="sqspell_use_app"
              value="<?php echo $sqspell_use_app ?>" />
       <table border="0" width="100%">
        <tr align="center">
@@ -329,7 +316,7 @@ if ($errors){
           echo $sptag . _("Line with an error:") . '</span>';
          ?>
          <br />
-         <textarea name="sqspell_line_area" cols="50" rows="3" 
+         <textarea name="sqspell_line_area" cols="50" rows="3"
                    wrap="hard" onfocus="this.blur()"></textarea>
         </td>
        </tr>
@@ -340,7 +327,7 @@ if ($errors){
          ?>
         </td>
         <td align="left" width="25%">
-         <input name="sqspell_error" size="10" value="" 
+         <input name="sqspell_error" size="10" value=""
                 onfocus="this.blur()" />
         </td>
         <td align="right" width="25%">
@@ -349,7 +336,7 @@ if ($errors){
          ?>
         </td>
         <td align="left" width="25%">
-         <select name="sqspell_suggestion" 
+         <select name="sqspell_suggestion"
                  onchange="if (this.options[this.selectedIndex].value != '_NONE') document.forms[0].sqspell_oruse.value=this.options[this.selectedIndex].value">
           <?php
            echo '<option>' . _("Suggestions") . '</option>';
@@ -383,23 +370,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>