Moved dictionaries and settings to SM prefs system
authortokul <tokul@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 5 May 2005 13:08:37 +0000 (13:08 +0000)
committertokul <tokul@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 5 May 2005 13:08:37 +0000 (13:08 +0000)
Fixed use of $SCRIPT_NAME globals
Removed SQSPELL_EREG setting. Internal dictionary format was changed, use
of ereg is unstable due to mbstring.fu*** :). It would be better to use
boolean configuration option.
Fixed use of php 4.1+ POST and GET vars
Fixed some script errors that might appear when SQSPELL_APP is changed or
invalid module name used in URL.

git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@9403 7612ce4b-ef26-0410-bec9-ea0150e637f0

22 files changed:
plugins/squirrelspell/INSTALL
plugins/squirrelspell/doc/CRYPTO
plugins/squirrelspell/doc/README
plugins/squirrelspell/doc/index.php
plugins/squirrelspell/js/index.php
plugins/squirrelspell/modules/check_me.mod
plugins/squirrelspell/modules/crypto.mod
plugins/squirrelspell/modules/crypto_badkey.mod
plugins/squirrelspell/modules/edit_dic.mod
plugins/squirrelspell/modules/enc_setup.mod
plugins/squirrelspell/modules/forget_me.mod
plugins/squirrelspell/modules/forget_me_not.mod
plugins/squirrelspell/modules/index.php
plugins/squirrelspell/modules/init.mod
plugins/squirrelspell/modules/lang_change.mod
plugins/squirrelspell/modules/lang_setup.mod
plugins/squirrelspell/modules/options_main.mod
plugins/squirrelspell/setup.php
plugins/squirrelspell/sqspell_config.php
plugins/squirrelspell/sqspell_functions.php
plugins/squirrelspell/sqspell_interface.php
plugins/squirrelspell/sqspell_options.php

index 1ac0c51b8a010cc5d98ee2b5d63762fcf9b8cc34..0844f8faeee402d757cd6d1abc943e971df80e26 100644 (file)
@@ -25,99 +25,44 @@ Enjoy and report bugs. ;)
 This is an options commented sqspell_config.php
 
 <?php
-
-   /**
-    **  sqspell_config.php -- SquirrelSpell Configuration file.
-    **
-    **  Copyright (c) 1999-2000 The SquirrelMail Project Team
-    **  Licensed under the GNU GPL. For full terms see the file COPYING.
-    **
-    **
-    **
-    **  $Id$
-    **/
-
-    /* Just for poor wretched souls with E_ALL. :) */
-    global $username, $data_dir;
-
-    /**
-       SPELL-CHECKING APPLICATIONS:
-       ----------------------------
-       This feature was added/changed in 0.3. Use this array to set up
-       which dictionaries are available to users. If you only have
-       English spellchecker on your system, then let this line be:
-
-       $SQSPELL_APP = array("English" => "ispell -a");
-
-       or
-
-       $SQSPELL_APP = array("English" => "/usr/local/bin/aspell -a");
-
-       Sometimes you have to specify full path for PHP to find it.
-       Aspell is a better spell-checker than Ispell, so you're encouraged
-       to use it.
-
-       If you want to have more than one dictionary available to users,
-       configure the array to look something like this:
-
-       $SQSPELL_APP = array(
-                            "English" => "aspell -a",
-                            "Russian" => "ispell -d russian -a",
-                            ...
-                            "Swahili" => "ispell -d swahili -a"
-                           );
-
-       Watch the commas, making sure there isn't one after your last
-       dictionary declaration. Also, make sure all these dictionaries
-       are available on your system before you specify them here.
-
-       Whatever your setting is, don't omit the "-a" flag.
-
-    **/
-    $SQSPELL_APP = array('English' => 'ispell -a');
-
-    /**
-       DEFAULT DICTIONARY
-       -------------------
-       Even if you're only running one dictionary, still specify which one
-       is the default. Watch the case -- it has to be exactly as in array
-       you declared in $SQSPELL_APP.
-    **/
-    $SQSPELL_APP_DEFAULT='English';
-
-    /**
-       USER DICTIONARY:
-       -----------------
-       $SQSPELL_WORDS_FILE is a location and mask of a user dictionary file.
-       The default setting should be OK for most everyone. Read PRIVACY and
-       CRYPTO in the "doc" directory.
-    **/
-    $SQSPELL_WORDS_FILE = "$data_dir/$username.words";
-
-    /**
-       CASE SENSITIVITY:
-       ------------------
-       Use $SQSPELL_EREG="ereg" for case-sensitive matching of user
-       dictionary, or $SQSPELL_EREG="eregi" for case-insensitive
-       matching. It is advised to use case-sensitive matching.
-    **/
-    $SQSPELL_EREG="ereg";
-
-    /**
-       SOUP NAZI (AVOIDING BAD BROWSERS)
-       -------------------------------------
-       Since some browsers choke on JavaScript, here is an option to disable the
-       browsers with known problems. All you do is add some part of an USER_AGENT
-       string of an offending browser which you want to disable and users will not
-       know about this plugin. E.g. browsers with "Mozilla/4.61 (Macintosh, I, PPC)"
-       USER_AGENT string will get weeded out if you provide "Macintosh" in the
-       config string.
-
-       Mozilla/2 -- You're kidding, right?
-       Mozilla/3 -- known not to work
-       Opera -- known not to work
-       Macintosh -- Netscape 4.x on Macintosh chokes for some reason.
-                    Adding until resolved.
-    **/
-    $SQSPELL_SOUP_NAZI = 'Mozilla/3, Mozilla/2, Opera 4, Opera/4, Macintosh';
+/**
+ *  sqspell_config.php -- SquirrelSpell Configuration file.
+ *
+ *  Copyright (c) 1999-2000 The SquirrelMail Project Team
+ *  Licensed under the GNU GPL. For full terms see the file COPYING.
+ */
+
+/** @ignore */
+if (! defined('SM_PATH')) define('SM_PATH','../../');
+
+/**
+ * getHashedFile() function for SQSPELL_WORDS_FILE and 
+ * sqgetGlobalVar() from global.php
+ */
+include_once(SM_PATH . 'functions/prefs.php');
+
+/** vars needed for getHashedFile() */
+global $data_dir;
+sqgetGlobalVar('username', $username, SQ_SESSION);
+
+/**
+ * List of configured dictionaries
+ */
+$SQSPELL_APP = array('English' => 'ispell -a',
+                     'Spanish' => 'ispell -d spanish -a');
+
+/**
+ * Default dictionary
+ */
+$SQSPELL_APP_DEFAULT = 'English';
+
+/**
+ * File that stores user's dictionary
+ *     
+ * This setting is used only when squirrelspell is upgraded from
+ * older setup. Since 1.5.1 SquirrelSpell stores all settings in
+ * same place that stores other SquirrelMail user preferences.
+ */
+$SQSPELL_WORDS_FILE =
+   getHashedFile($username, $data_dir, "$username.words");
 ?>
index 1ae82ed4e047417d706b7cdb36ebdd892219ad7f..d64e444ea39dfbe892f1bfd10b85ef0a93e7a733 100644 (file)
@@ -6,7 +6,7 @@ user dictionaries. However, this option is only available when PHP
 is compiled with support for MCRYPT. This is relatively easy -- to enable
 MCRYPT support, follow instructions at:
 
-http://www.php.net/manual/en/ref.mcrypt.php
+http://www.php.net/mcrypt
 
 NOTE: You will need libmcrypt version 2.4.x or above for SquirrelSpell
 to work.
index 4abcf6d1fa176d41934e6b46627485ee67e5dd97..805d12569ee3b809c7d3fb677f687aafc433aed0 100644 (file)
@@ -2,7 +2,7 @@ SquirrelSpell
 --------------
 
 SquirrelSpell is a JavaScript-powered spellchecker written to work with
-SquirrelMail versions 0.5 and higher.
+SquirrelMail webmail interface.
 
 LICENSE: 
 --------- 
@@ -14,7 +14,7 @@ license at http://www.gnu.org/
 FEATURES:
 ----------
 SquirrelSpell works with UN*X's ISPELL or ASPELL libraries and
-SquirrelMail version 0.5 and higher. No PHP recompilation required,
+SquirrelMail version 1.4 and higher. No PHP recompilation required,
 unless you wish to enable MCRYPT support.
 
 * SpellChecker:
@@ -39,13 +39,13 @@ in English.
 
 AUTHOR:
 --------
-This plugin was origintally authored by Konstantin Riabitsev
+This plugin was originally authored by Konstantin Riabitsev
 (http://www.mricon.com/) and is now maintained by the SquirrelMail Project
 Team.
 
 SUPPORT:
 ---------
-Send suppot questions and bug reports to the plugins mailing list:
+Send support questions and bug reports to the plugins mailing list:
 squirrelmail-plugins@lists.sourceforge.net. When reporting a bug
 don't forget to mention your browser version, SquirrelMail and
 SquirrelSpell versions, as well as any other useful info.
index f720a4350dd51421ab59fc721e58d9b6ad499bc2..0a9f0f87c2f5d16d3be599b54b546f63c7e30b3c 100644 (file)
@@ -1,19 +1,16 @@
 <?php
-
-   /**
-    **  index.php -- Displays the main frameset
-    **
-    **  Copyright (c) 1999-2005 The SquirrelMail Project Team
-    **  Licensed under the GNU GPL. For full terms see the file COPYING.
-    **
-    **  Redirects to the login page.
-    **
-    **  $Id$
-    * @package plugins
-    * @subpackage squirrelspell
-    **/
-
-   header("Location:../../../src/login.php\n\n");
-   exit();
-
+/**
+ * index.php -- Displays the main frameset
+ *
+ * Copyright (c) 1999-2005 The SquirrelMail Project Team
+ * Licensed under the GNU GPL. For full terms see the file COPYING.
+ *
+ * Redirects to the initial SquirrelMail page.
+ *
+ * @version $Id$
+ * @package plugins
+ * @subpackage squirrelspell
+ */
+header("Location:../../../index.php\n\n");
+exit();
 ?>
\ No newline at end of file
index f720a4350dd51421ab59fc721e58d9b6ad499bc2..0a9f0f87c2f5d16d3be599b54b546f63c7e30b3c 100644 (file)
@@ -1,19 +1,16 @@
 <?php
-
-   /**
-    **  index.php -- Displays the main frameset
-    **
-    **  Copyright (c) 1999-2005 The SquirrelMail Project Team
-    **  Licensed under the GNU GPL. For full terms see the file COPYING.
-    **
-    **  Redirects to the login page.
-    **
-    **  $Id$
-    * @package plugins
-    * @subpackage squirrelspell
-    **/
-
-   header("Location:../../../src/login.php\n\n");
-   exit();
-
+/**
+ * index.php -- Displays the main frameset
+ *
+ * Copyright (c) 1999-2005 The SquirrelMail Project Team
+ * Licensed under the GNU GPL. For full terms see the file COPYING.
+ *
+ * Redirects to the initial SquirrelMail page.
+ *
+ * @version $Id$
+ * @package plugins
+ * @subpackage squirrelspell
+ */
+header("Location:../../../index.php\n\n");
+exit();
 ?>
\ No newline at end of file
index bc5aea8852c5026c517dc731ebc43f97ffca5ed4..98e1c78f87b9295a5d36d384812b2aed98c46dfe 100644 (file)
@@ -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:
@@ -146,7 +150,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.
  */
@@ -182,7 +186,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;
@@ -208,7 +212,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';
@@ -307,7 +311,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>
index a161eb2f23e0a4d23f6a68d92036ca430dd18f64..91d2ff5ab3485ca8a2a48cee03ee56aef38bad30 100644 (file)
  */
 global $SQSPELL_CRYPTO;
 
-switch ($_POST['action']){
+$langs=sqspell_getSettings();
+
+if (! sqgetGlobalVar('action', $crypt_action, SQ_POST)) {
+    $crypt_action = 'noaction';
+}
+
+switch ($crypt_action){
     case 'encrypt':
-        /**
-         * Let's encrypt the file and save it in an encrypted format.
-         */
-        $words=sqspell_getWords();
-        /**
-         * Flip the flag so the sqspell_writeWords function knows to encrypt
-         * the message before writing it to the disk.
-         */
-        $SQSPELL_CRYPTO=true;
-        /**
-         * Call the function that does the actual encryption_decryption.
-         */
-        sqspell_writeWords($words);
+        $SQSPELL_CRYPTO_ORIG=$SQSPELL_CRYPTO;
+
+        foreach ($langs as $lang) {
+            $SQSPELL_CRYPTO = $SQSPELL_CRYPTO_ORIG;
+            /**
+             * Let's encrypt the file and save it in an encrypted format.
+             */
+            $words=sqspell_getLang($lang);
+            /**
+             * Flip the flag so the sqspell_writeWords function knows to encrypt
+             * the message before writing it to the disk.
+             */
+            $SQSPELL_CRYPTO=true;
+            /**
+             * Call the function that does the actual encryption_decryption.
+             */
+            sqspell_writeWords($words,$lang);
+        }
         $msg='<p>'
             . _("Your personal dictionary has been encrypted and is now stored in an encrypted format.")
             . '</p>';
     break;
     case 'decrypt':
-        /**
-         * Let's decrypt the file and save it as plain text.
-         */
-        $words=sqspell_getWords();
-        /**
-         * Flip the flag and tell the sqspell_writeWords() function that we
-         * want to save it plaintext.
-         */
-        $SQSPELL_CRYPTO=false;
-        sqspell_writeWords($words);
+        $SQSPELL_CRYPTO_ORIG=$SQSPELL_CRYPTO;
+
+        foreach ($langs as $lang) {
+            $SQSPELL_CRYPTO = $SQSPELL_CRYPTO_ORIG;
+            /**
+             * Let's encrypt the file and save it in an encrypted format.
+             */
+            $words=sqspell_getLang($lang);
+            /**
+             * Flip the flag so the sqspell_writeWords function knows to decrypt
+             * the message before writing it to the disk.
+             */
+            $SQSPELL_CRYPTO=false;
+            /**
+             * Call the function that does the actual encryption_decryption.
+             */
+            sqspell_writeWords($words,$lang);
+        }
         $msg='<p>'
             . _("Your personal dictionary has been decrypted and is now stored as plain text.")
             . '</p>';
     break;
-    case '':
+    default:
         /**
          * Wait, this shouldn't happen! :)
          */
-        $msg = '<p>No action requested.</p>';
+        $msg = '<p>'._("No action requested.").'</p>';
     break;
 }
 sqspell_makePage( _("Personal Dictionary Crypto Settings"), null, $msg);
index c9ff535e60c3701ee0d8513802af7d550802b447..e1ca3b42f84311ddeff89621226e6a8835eb1fc3 100644 (file)
  * @subpackage squirrelspell
  */
 
-global $SCRIPT_NAME;
+/** get script name*/
+sqgetGlobalVar('SCRIPT_NAME',$SCRIPT_NAME,SQ_SERVER);
 
-$delete_words = $_POST['delete_words'];
-if(isset($_POST['old_key'])) {
-    $old_key = $_POST['old_key'];
+if (! sqgetGlobalVar('delete_words',$delete_words,SQ_POST)){ 
+  $delete_words = 'OFF';
+}
+if (! sqgetGlobalVar('old_key',$old_key,SQ_POST)) {
+  $old_key=null;
 }
 
-if ($delete_words=='ON'){
-  /**
-   * $delete_words is passed via the query_string. If it's set, then
-   * the user asked to delete the file. Erase the bastard and hope
-   * this never happens again.
-   */
-  sqspell_deleteWords();
+if (! sqgetGlobalVar('old_setup',$temp,SQ_POST)) {
+  $old_setup = false;
+} else {
+  $old_setup = true;
+}
+
+/**
+ * Displays information about deleted dictionary
+ * @since 1.5.1 (sqspell 0.5)
+ */
+function sqspell_dict_deleted() {
+  global $SCRIPT_NAME;
   /**
    * See where we were called from -- pop-up window or options page
    * and call whichever wrapper is appropriate.
-   * I agree, this is dirty. TODO: make it so it's not dirty.
+   * I agree, this is dirty.
+   * TODO: make it so it's not dirty.
+   * TODO: add upgrade handing
    */
   if (strstr($SCRIPT_NAME, 'sqspell_options')){
     $msg='<p>' . _("Your personal dictionary was erased.") . '</p>';
@@ -44,49 +54,84 @@ if ($delete_words=='ON'){
      * on getting the strings.
      */
     $msg = '<p>'
-       . _("Your personal dictionary was erased. Please close this window and click \"Check Spelling\" button again to start your spellcheck over.")
-       . '</p> '
-       . '<p align="center"><form>'
-       . '<input type="button" value=" '
-       . _("Close this Window") . ' " onclick="self.close()" />'
-       . '</form></p>';
+      . _("Your personal dictionary was erased. Please close this window and click \"Check Spelling\" button again to start your spellcheck over.")
+      . '</p> '
+      . '<p align="center"><form>'
+      . '<input type="button" value=" '
+      . _("Close this Window") . ' " onclick="self.close()" />'
+      . '</form></p>';
     sqspell_makeWindow(null, _("Dictionary Erased"), null, $msg);
   }
   exit;
 }
 
-if ($old_key){
-  /**
-   * User provided another key to try and decrypt the dictionary.
-   * Call sqspell_getWords. If this key fails, the function will
-   * handle it.
-   */
-  $words=sqspell_getWords();
-  /**
-   * It worked! Pinky, you're a genius!
-   * Write it back this time encrypted with a new key.
-   */
-  sqspell_writeWords($words);
+/**
+ * Displays information about reencrypted dictionary
+ * @since 1.5.1 (sqspell 0.5)
+ */
+function sqspell_dict_reencrypted() {
+  global $SCRIPT_NAME;
   /**
    * See where we are and call a necessary GUI-wrapper.
-   * Also dirty. TODO: Make this not dirty.
+   * Also dirty.
+   * TODO: Make this not dirty.
+   * TODO: add upgrade handing
    */
   if (strstr($SCRIPT_NAME, 'sqspell_options')){
     $msg = '<p>'
-       . _("Your personal dictionary was re-encrypted successfully. Now return to the &quot;SpellChecker options&quot; menu and make your selection again." )
-       . '</p>';
+      . _("Your personal dictionary was re-encrypted successfully. Now return to the &quot;SpellChecker options&quot; menu and make your selection again." )
+      . '</p>';
     sqspell_makePage(_("Successful re-encryption"), null, $msg);
   } else {
     $msg = '<p>'
-       . _("Your personal dictionary was re-encrypted successfully. Please close this window and click \"Check Spelling\" button again to start your spellcheck over.")
-       . '</p><form><p align="center"><input type="button" value=" '
-       . _("Close this Window") . ' "'
-       . 'onclick="self.close()" /></p></form>';
+      . _("Your personal dictionary was re-encrypted successfully. Please close this window and click \"Check Spelling\" button again to start your spellcheck over.")
+      . '</p><form><p align="center"><input type="button" value=" '
+      . _("Close this Window") . ' "'
+      . 'onclick="self.close()" /></p></form>';
     sqspell_makeWindow(null, _("Dictionary re-encrypted"), null, $msg);
   }
   exit;
 }
 
+// main code 
+if (! $old_setup && $delete_words=='ON') {
+  if (sqgetGlobalVar('dict_lang',$dict_lang,SQ_POST)) {
+    sqspell_deleteWords($dict_lang);
+    sqspell_dict_deleted();
+  }
+} elseif ($delete_words=='ON'){
+  /**
+   * $delete_words is passed via the query_string. If it's set, then
+   * the user asked to delete the file. Erase the bastard and hope
+   * this never happens again.
+   */
+  sqspell_deleteWords_old();
+  sqspell_dict_deleted();
+}
+
+if (! $old_setup && $old_key) {
+  if (sqgetGlobalVar('dict_lang',$dict_lang,SQ_POST)) {
+    $words=sqspell_getLang($dict_lang);
+    sqspell_writeWords($words,$dict_lang);
+    sqspell_dict_reencrypted();
+  }
+} elseif ($old_key){
+  /**
+   * User provided another key to try and decrypt the dictionary.
+   * Call sqspell_getWords. If this key fails, the function will
+   * handle it.
+   */
+  $words=sqspell_getWords_old();
+  /**
+   * It worked! Pinky, you're a genius!
+   * Write it back this time encrypted with a new key.
+   */
+  sqspell_writeWords_old($words);
+  sqspell_dict_reencrypted();
+}
+
+// TODO: handle broken calls
+
 /**
  * For Emacs weenies:
  * Local variables:
index 7507d4dd4d79ecfba742bb0c646be3744d457bb5..dd4ea26d7c90e8f8256516eebbbb6bd2cc4e092f 100644 (file)
  */
 
 global $color;
+
+$pre_msg = '<p>'
+  . _("Please check any words you wish to delete from your dictionary.")
+  . "</p>\n";
+$pre_msg .= "<table border=\"0\" width=\"95%\" align=\"center\">\n";
+
 /**
- * Get the user dictionary and see if it's empty or not.
+ * Get how many dictionaries this user has defined.
  */
-$words=sqspell_getWords();
-if (!$words){
-  /**
-   * Agt. Smith: "You're empty."
-   * Neo: "So are you."
-   */
-  sqspell_makePage(_("Personal Dictionary"), null,
-      '<p>' . _("No words in your personal dictionary.")
-      . '</p>');
-} else {
-  /**
-   * We're loaded with booty.
-   */
-  $pre_msg = '<p>'
-     . _("Please check any words you wish to delete from your dictionary.")
-     . "</p>\n";
-  $pre_msg .= "<table border=\"0\" width=\"95%\" align=\"center\">\n";
+$langs=sqspell_getSettings();
+
+foreach ($langs as $lang) {
   /**
-   * Get how many dictionaries this user has defined.
+   * Get all words from this language dictionary.
    */
-  $langs=sqspell_getSettings($words);
-  for ($i=0; $i<sizeof($langs); $i++){
+  $lang_words = sqspell_getLang($lang);
+  if (! empty($lang_words)){
     /**
-     * Get all words from this language dictionary.
+     * There are words in this dictionary. If this is the first
+     * language we're processing, prepend the output with the
+     * "header" message.
      */
-    $lang_words = sqspell_getLang($words, $langs[$i]);
-    if ($lang_words){
-      /**
-       * There are words in this dictionary. If this is the first
-       * language we're processing, prepend the output with the
-       * "header" message.
-       */
-      if (!isset($msg) || !$msg) {
-          $msg = $pre_msg;
-      }
-      $msg .= "<tr bgcolor=\"$color[0]\" align=\"center\"><th>"
-          . sprintf( _("%s dictionary"), $langs[$i] ) . '</th></tr>'
-          . '<tr><td align="center">'
-          . '<form method="post">'
-          . '<input type="hidden" name="MOD" value="forget_me" />'
-          . '<input type="hidden" name="sqspell_use_app" value="'
-          . $langs[$i] . '" />'
-          . '<table border="0" width="95%" align="center">'
-          . '<tr>'
-          . "<td valign=\"top\">\n";
-      $words_ary=explode("\n", $lang_words);
-      /**
-       * There are two lines we need to remove:
-       * 1st:  # Language
-       * last: # End
-       */
-      array_pop($words_ary);
-      array_shift($words_ary);
-      /**
-       * Do some fancy stuff to separate the words into three
-       * columns.
-       */
-      for ($j=0; $j<sizeof($words_ary); $j++){
-          if ($j==intval(sizeof($words_ary)/3)
-              || $j==intval(sizeof($words_ary)/3*2)){
-              $msg .= "</td><td valign=\"top\">\n";
-          }
-          $msg .= "<input type=\"checkbox\" name=\"words_ary[]\" "
-              . 'value="'.htmlspecialchars($words_ary[$j]). '" /> '
-              . htmlspecialchars($words_ary[$j]) . "<br />\n";
+    if (!isset($msg) || !$msg) {
+      $msg = $pre_msg;
+    }
+    $msg .= "<tr bgcolor=\"$color[0]\" align=\"center\"><th>"
+      . sprintf( _("%s dictionary"), $lang ) . '</th></tr>'
+      . '<tr><td align="center">'
+      . '<form method="post">'
+      . '<input type="hidden" name="MOD" value="forget_me" />'
+      . '<input type="hidden" name="sqspell_use_app" value="'
+      . $lang . '" />'
+      . '<table border="0" width="95%" align="center">'
+      . '<tr>'
+      . "<td valign=\"top\">\n";
+    /**
+     * Do some fancy stuff to separate the words into three
+     * columns.
+     */
+    for ($j=0; $j<sizeof($lang_words); $j++){
+      if ($j==intval(sizeof($lang_words)/3)
+          || $j==intval(sizeof($lang_words)/3*2)){
+        $msg .= "</td><td valign=\"top\">\n";
       }
-      $msg .= '</td></tr></table></td></tr>'
-          . "<tr bgcolor=\"$color[0]\" align=\"center\"><td>"
-          . '<input type="submit" value="' . _("Delete checked words")
-          . '" /></form>'
-          . '</td></tr><tr><td><hr />'
-          . "</td></tr>\n";
+      $msg .= "<input type=\"checkbox\" name=\"words_ary[]\" "
+        . 'value="'.htmlspecialchars($lang_words[$j]). '" /> '
+        . htmlspecialchars($lang_words[$j]) . "<br />\n";
     }
+    $msg .= '</td></tr></table></td></tr>'
+      . "<tr bgcolor=\"$color[0]\" align=\"center\"><td>"
+      . '<input type="submit" value="' . _("Delete checked words")
+      . '" /></form>'
+      . '</td></tr><tr><td><hr />'
+      . "</td></tr>\n";
   }
-  /**
-   * Check if all dictionaries were empty.
-   */
-  if (! isset($msg)) {
-    $msg = '<p>' . _("No words in your personal dictionary.") . '</p>';
-  } else {
-    $msg .= '</table>';
-  }
-  sqspell_makePage(_("Edit your Personal Dictionary"), null, $msg);
 }
+/**
+ * Check if all dictionaries were empty.
+ */
+if (! isset($msg)) {
+  $msg = '<p>' . _("No words in your personal dictionary.") . '</p>';
+} else {
+  $msg .= '</table>';
+}
+sqspell_makePage(_("Edit your Personal Dictionary"), null, $msg);
 
 /**
  * For Emacs weenies:
index b7b2bac095139a83e9b3f709eec05d5675f050ca..ed1d1a138bb76aab710d5854dce4f92bebc58aad 100644 (file)
@@ -31,13 +31,19 @@ $msg = '<script type="text/javascript"><!--'."\n"
     . "\";\n"
     . "//-->\n</script>";
 
-$words=sqspell_getWords();
+$crypted=false;
+$langs=sqspell_getSettings();
+foreach ($langs as $lang) {
+    $words=sqspell_getLang($lang);
+    if ($SQSPELL_CRYPTO) $crypted = true;
+}
+
 /**
  * When getting the user dictionary, the SQSPELL_CRYPTO flag will be
  * set to "true" if the dictionary is encrypted, or "false" if it is
  * in plain text.
  */
-if ($SQSPELL_CRYPTO){
+if ($crypted){
     /**
      * Current format is encrypted.
      * Unfortunately, the following text needs to be all on one line,
index e108ee02f618ba44346f767762a9620223a49d42..b137663d209396a7708c934b6396264666f92a16 100644 (file)
  * @subpackage squirrelspell
  */
 
-global $SQSPELL_VERSION;
+global $SQSPELL_VERSION, $SQSPELL_APP_DEFAULT;
 
-$words_ary = $_POST['words_ary'];
-$sqspell_use_app = $_POST['sqspell_use_app'];
+if (! sqgetGlobalVar('words_ary',$words_ary,SQ_POST) || ! is_array($words_ary)) {
+    $words_ary = array();
+}
+
+if (! sqgetGlobalVar('sqspell_use_app',$sqspell_use_app,SQ_POST)){
+    $sqspell_use_app = $SQSPELL_APP_DEFAULT;
+}
 
 /**
  * If something needs to be deleted, then $words_ary will be
  * non-zero length.
  */
-if (sizeof($words_ary)){
-  $words=sqspell_getWords();
-  $lang_words = sqspell_getLang($words, $sqspell_use_app);
+if (! empty($words_ary)){
+  $lang_words = sqspell_getLang($sqspell_use_app);
   $msg = '<p>'
      . sprintf(_("Deleting the following entries from %s dictionary:"), '<strong>'.$sqspell_use_app.'</strong>')
      . '</p>'
      . "<ul>\n";
-  for ($i=0; $i<sizeof($words_ary); $i++){
-    /**
-     * Remove word by word...
-     */
-    $lang_words=str_replace("$words_ary[$i]\n", "", $lang_words);
-    $msg .= '<li>' . htmlspecialchars($words_ary[$i]) . "</li>\n";
-  }
-  $new_words_ary=split("\n", $lang_words);
-  /**
-   * Wipe this lang, if only 2 members in array (no words left).
-   * # Language
-   * # End
-   */
-  if (sizeof($new_words_ary)<=2) {
-    $lang_words='';
+
+  // print list of deleted words
+  foreach ($words_ary as $deleted_word) {
+    $msg.= '<li>'.htmlspecialchars($deleted_word)."</li>\n";
   }
-  $new_lang_words = $lang_words;
-  /**
-   * Write the dictionary back to the disk.
-   */
-  $langs=sqspell_getSettings($words);
-  $words_dic = "# SquirrelSpell User Dictionary $SQSPELL_VERSION\n# "
-     . "Last Revision: " . date("Y-m-d") . "\n# LANG: "
-     . join(", ", $langs) . "\n";
-  for ($i=0; $i<sizeof($langs); $i++){
-    /**
-     * Only rewrite the contents of the selected language.
-     * Otherwise just write the contents back.
-     */
-    if ($langs[$i]==$sqspell_use_app) {
-      $lang_words = $new_lang_words;
-    } else {
-      $lang_words = sqspell_getLang($words, $langs[$i]);
-    }
-    if ($lang_words) {
-      $words_dic .= $lang_words;
-    }
+
+  // rebuild dictionary
+  $new_words_ary = array();
+  foreach ($lang_words as $word){
+      if (! in_array($word,$words_ary)) {
+          $new_words_ary[].= $word;
+      }
   }
-  $words_dic .= "# End\n";
-  sqspell_writeWords($words_dic);
+  // save it
+  sqspell_writeWords($new_words_ary,$sqspell_use_app);
   $msg .= '</ul><p>' . _("All done!") . "</p>\n";
   sqspell_makePage(_("Personal Dictionary Updated"), null, $msg);
 } else {
index a112be60ed892c5e16e3b6206f154a69545dd01d..c85dbea95a36c2247107b6f1dc4c0d12107e8957 100644 (file)
 
 global $SQSPELL_VERSION, $SQSPELL_APP_DEFAULT;
 
-$words = $_POST['words'];
-$sqspell_use_app = $_POST['sqspell_use_app'];
+if (! sqgetGlobalVar('words',$words,SQ_POST)) {
+    $words='';
+}
+if (! sqgetGlobalVar('sqspell_use_app',$sqspell_use_app,SQ_POST)) {
+    $sqspell_use_app = $SQSPELL_APP_DEFAYLT;
+}
 
 /**
  * Because of the nature of Javascript, there is no way to efficiently
@@ -27,45 +31,25 @@ $sqspell_use_app = $_POST['sqspell_use_app'];
  * "%". To get the array, we explode the "%"'s.
  * Dirty: yes. Is there a better solution? Let me know. ;)
  */
-$new_words = ereg_replace("%", "\n", $words);
+$new_words = explode("%",$words);
 /**
  * Load the user dictionary and see if there is anything in it.
  */
-$words=sqspell_getWords();
-if (!$words){
-  /**
-   * First time.
-   */
-  $words_dic="# SquirrelSpell User Dictionary $SQSPELL_VERSION\n# Last "
-     . "Revision: " . date("Y-m-d")
-     . "\n# LANG: $SQSPELL_APP_DEFAULT\n# $SQSPELL_APP_DEFAULT\n";
-  $words_dic .= $new_words . "# End\n";
+$old_words=sqspell_getLang($sqspell_use_app);
+if (empty($old_words)){
+    $word_dic = $new_words;
 } else {
-  /**
-   * Do some fancy stuff in order to save the dictionary and not mangle the
-   * rest.
-   */
-  $langs=sqspell_getSettings($words);
-  $words_dic = "# SquirrelSpell User Dictionary $SQSPELL_VERSION\n# "
-     . "Last Revision: " . date("Y-m-d") . "\n# LANG: " . join(", ", $langs)
-     . "\n";
-  for ($i=0; $i<sizeof($langs); $i++){
-    $lang_words=sqspell_getLang($words, $langs[$i]);
-    if ($langs[$i]==$sqspell_use_app){
-      if (!$lang_words) {
-          $lang_words="# $langs[$i]\n";
-      }
-      $lang_words .= $new_words;
+    foreach($new_words as $new_word) {
+        $old_words[].=$new_word;
     }
-    $words_dic .= $lang_words;
-  }
-  $words_dic .= "# End\n";
+    // make sure that dictionary contains only unique values
+    $word_dic = array_unique($old_words);
 }
 
 /**
  * Write out the file
  */
-sqspell_writeWords($words_dic);
+sqspell_writeWords($word_dic,$sqspell_use_app);
 /**
  * display the splash screen, then close it automatically after 2 sec.
  */
index 273d0ea3d7ce939ff221af6b1df722341afcb2b6..0a9f0f87c2f5d16d3be599b54b546f63c7e30b3c 100644 (file)
@@ -5,12 +5,12 @@
  * Copyright (c) 1999-2005 The SquirrelMail Project Team
  * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
- * Redirects to the login page.
+ * Redirects to the initial SquirrelMail page.
  *
  * @version $Id$
  * @package plugins
  * @subpackage squirrelspell
  */
-header("Location:../../../src/login.php\n\n");
+header("Location:../../../index.php\n\n");
 exit();
 ?>
\ No newline at end of file
index a3c7d9988a826c3020c09bfc43a10c2fe6323034..4ca76fb93597a346b2f3adf0b7f2cd928b72ba85 100644 (file)
@@ -19,7 +19,7 @@
  * See if we need to give user the option of choosing which dictionary
  * s/he wants to use to spellcheck his message.
  */
-$langs=sqspell_getSettings(null);
+$langs=sqspell_getSettings();
 $msg = '<form method="post">'
   . '<input type="hidden" name="MOD" value="check_me" />'
   . '<input type="hidden" name="sqspell_text" />'
index 7284102580a466fd0fdc826638e37c7673930598..cc80c3d6c54453bc9e54e92cfaa8187ed4717dc2 100644 (file)
 
 global $SQSPELL_APP_DEFAULT;
 
-$use_langs = $_POST['use_langs'];
-$lang_default = $_POST['lang_default'];
+if (! sqgetGlobalVar('use_langs',$use_langs,SQ_POST)) {
+    $use_langs = array($SQSPELL_APP_DEFAULT);
+}
 
-$words = sqspell_getWords();
-if (!$words) {
-  $words = sqspell_makeDummy();
+if (! sqgetGlobalVar('lang_default',$lang_default,SQ_POST)) {
+    $lang_default = $SQSPELL_APP_DEFAULT;
 }
-$langs = sqspell_getSettings($words);
-if (sizeof($use_langs)){
-  /**
-   * See if the user clicked any options on the previous page.
-   */
-  if (sizeof($use_langs)>1){
-    /**
-     * See if s/he wants more than one dictionary.
-     */
-    if ($use_langs[0]!=$lang_default){
-      /**
-       * See if we need to juggle the order of the dictionaries
-       * to make the default dictionary first in line.
-       */
-      if (in_array($lang_default, $use_langs)){
-          /**
-           * See if the user was dumb and chose a default dictionary
-           * to be something other than the ones he selected.
-           */
-          $hold = array_shift($use_langs);
-          $lang_string = join(", ", $use_langs);
-          $lang_string = str_replace("$lang_default", "$hold", $lang_string);
-          $lang_string = $lang_default . ", " . $lang_string;
-      } else {
-          /**
-           * Yes, he is dumb.
-           */
-          $lang_string = join(', ', $use_langs);
-      }
-    } else {
-      /**
-       * No need to juggle the order -- preferred is already first.
-       */
-      $lang_string = join(', ', $use_langs);
+
+/**
+ * Rebuild languages. Default language is first one.
+ */
+$new_langs = array($lang_default);
+foreach ($use_langs as $lang) {
+    if (! in_array($lang,$new_langs)) {
+        $new_langs[].=$lang;
     }
-  } else {
-    /**
-     * Just one dictionary, please.
-     */
-    $lang_string = $use_langs[0];
-  }
-  $lang_array = explode( ',', $lang_string );
+}
+
+if (sizeof($new_langs)>1) {
   $dsp_string = '';
-  foreach( $lang_array as $a) {
+  foreach( $new_langs as $a) {
     $dsp_string .= _(trim($a)) . ', ';
   }
+  // remove last comma and space
   $dsp_string = substr( $dsp_string, 0, -2 );
+
+  /**
+   * i18n: first %s is comma separated list of languages, second %s - default language.
+   * Language names are translated, if they are present in squirrelmail.po file.
+   * make sure that you don't use html codes in language name translations
+   */
   $msg = '<p>'
-    . sprintf(_("Settings adjusted to: %s with %s as default dictionary."), '<strong>'.$dsp_string.'</strong>', '<strong>'._($lang_default).'</strong>')
+    . sprintf(_("Settings adjusted to: %s with %s as default dictionary."),
+             '<strong>'.htmlspecialchars($dsp_string).'</strong>',
+             '<strong>'.htmlspecialchars(_($lang_default)).'</strong>')
     . '</p>';
 } else {
   /**
-   * No dictionaries selected. Use system default.
+   * Only one dictionary is selected.
    */
   $msg = '<p>'
-    . sprintf(_("Using %s dictionary (system default) for spellcheck." ), '<strong>'.$SQSPELL_APP_DEFAULT.'</strong>')
+    . sprintf(_("Using %s dictionary for spellcheck." ), '<strong>'.htmlspecialchars(_($new_langs[0])).'</strong>')
     . '</p>';
-  $lang_string = $SQSPELL_APP_DEFAULT;
 }
-$old_lang_string = join(", ", $langs);
-$words = str_replace("# LANG: $old_lang_string", "# LANG: $lang_string",
-     $words);
-/**
- * Write it down where the sun don't shine.
- */
-sqspell_writeWords($words);
+
+/** save settings */
+sqspell_saveSettings($new_langs);
+
 sqspell_makePage(_("International Dictionaries Preferences Updated"),
     null, $msg);
 
index ec910d6bb585165ecf4735d79894a9181779ecc1..02b1e6d1c702860f4adfbf4ff7a3ca37401d5ec1 100644 (file)
@@ -27,7 +27,7 @@ $msg = '<p>'
 /**
  * Present a nice listing.
  */
-$langs = sqspell_getSettings(null);
+$langs = sqspell_getSettings();
 $add = '<p>'
   . _("Make this dictionary my default selection:")
   . " <select name=\"lang_default\">\n";
index 5771d99324aae5fa9c818765c93ea0dafab587e1..3834a592d64aa221638093161fccf7166b2a9f40 100644 (file)
@@ -41,8 +41,8 @@ if (function_exists("mcrypt_generic")) {
     . "</a></li>\n";
 } else {
   $msg .= '<li>'
-    . _("Encrypt or decrypt your personal dictionary") . ' <em>('
-    . _("not available") . ')</em></li>';
+    . _("Personal dictionary encryption options are not available") 
+    . ')</em></li>';
 }
 $msg .= "</ul>\n";
 sqspell_makePage( _("SquirrelSpell Options Menu"), null, $msg);
index a30c54818a1a266ace1822398cf076f6fc8c260a..f8017a373447238283a1cf9fc8ed9bfe2c598048 100644 (file)
  * Copyright (c) 1999-2005 The SquirrelMail Project Team
  * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
- * $Id$
- *
- * @author Konstantin Riabitsev <icon@duke.edu> ($Author$)
- * @version $Date$
+ * @author Konstantin Riabitsev <icon@duke.edu>
+ * @version $Id$
  * @package plugins
  * @subpackage squirrelspell
  */
 
+/** @ignore */
+if (! defined('SM_PATH')) define('SM_PATH','../../');
+
 /**
  * Standard SquirrelMail plugin initialization API.
- *
  * @return void
  */
 function squirrelmail_plugin_init_squirrelspell() {
-    global $squirrelmail_plugin_hooks;
-    $squirrelmail_plugin_hooks['compose_button_row']['squirrelspell'] =
-        'squirrelspell_setup';
-    $squirrelmail_plugin_hooks['optpage_register_block']['squirrelspell'] =
-        'squirrelspell_optpage_register_block';
-    $squirrelmail_plugin_hooks['options_link_and_description']['squirrelspell'] =
-        'squirrelspell_options';
+  global $squirrelmail_plugin_hooks;
+  $squirrelmail_plugin_hooks['compose_button_row']['squirrelspell'] =
+    'squirrelspell_setup';
+  $squirrelmail_plugin_hooks['optpage_register_block']['squirrelspell'] =
+    'squirrelspell_optpage_register_block';
+  $squirrelmail_plugin_hooks['options_link_and_description']['squirrelspell'] =
+    'squirrelspell_options';
+  $squirrelmail_plugin_hooks['right_main_after_header']['squirrelspell'] =
+    'squirrelspell_upgrade';
 }
 
 /**
  * This function formats and adds the plugin and its description to the
  * Options screen.
- *
  * @return void
  */
 function squirrelspell_optpage_register_block() {
-    global $optpage_blocks;
+  global $optpage_blocks;
+  /**
+   * Check if this browser is capable of using the plugin
+   */
+  if (checkForJavascript()) {
     /**
-     * Check if this browser is capable of using the plugin
+     * The browser checks out.
+     * Register Squirrelspell with the $optpage_blocks array.
      */
-    if (checkForJavascript()) {
-        /**
-         * The browser checks out.
-         * Register Squirrelspell with the $optionpages array.
-         */
-        $optpage_blocks[] =
-            array(
-                'name' => _("SpellChecker Options"),
-                'url'  => '../plugins/squirrelspell/sqspell_options.php',
-                'desc' => _("Here you may set up how your personal dictionary is stored, edit it, or choose which languages should be available to you when spell-checking."),
-                'js'   => TRUE);
-    }
+    $optpage_blocks[] =
+      array(
+        'name' => _("SpellChecker Options"),
+        'url'  => '../plugins/squirrelspell/sqspell_options.php',
+        'desc' => _("Here you may set up how your personal dictionary is stored, edit it, or choose which languages should be available to you when spell-checking."),
+        'js'   => TRUE);
+  }
 }
 
 /**
  * This function adds a "Check Spelling" link to the "Compose" row
  * during message composition.
- *
  * @return void
  */
 function squirrelspell_setup() {
+  /**
+   * Check if this browser is capable of displaying SquirrelSpell
+   * correctly.
+   */
+  if (checkForJavascript()) {
     /**
-     * Check if this browser is capable of displaying SquirrelSpell
-     * correctly.
+     * Some people may choose to disable javascript even though their
+     * browser is capable of using it. So these freaks don't complain,
+     * use document.write() so the "Check Spelling" button is not
+     * displayed if js is off in the browser.
      */
-    if (checkForJavascript()) {
-        /**
-         * Some people may choose to disable javascript even though their
-         * browser is capable of using it. So these freaks don't complain,
-         * use document.write() so the "Check Spelling" button is not
-         * displayed if js is off in the browser.
-         */
-        echo "<script type=\"text/javascript\">\n".
-             "<!--\n".
-             'document.write("<input type=\"button\" value=\"'.
-             _("Check Spelling").
-             '\" name=\"check_spelling\" onclick=\"window.open(\'../plugins/squirrelspell/sqspell_'.
-             'interface.php\', \'sqspell\', \'status=yes,width=550,height=370,'.
-             'resizable=yes\')\" />");' . "\n".
-             "//-->\n".
-             "</script>\n";
+    echo "<script type=\"text/javascript\">\n".
+      "<!--\n".
+      'document.write("<input type=\"button\" value=\"'.
+      _("Check Spelling").
+      '\" name=\"check_spelling\" onclick=\"window.open(\'../plugins/squirrelspell/sqspell_'.
+      'interface.php\', \'sqspell\', \'status=yes,width=550,height=370,'.
+      'resizable=yes\')\" />");' . "\n".
+      "//-->\n".
+      "</script>\n";
+  }
+}
+
+/**
+ * Transparently upgrades user's dictionaries when message listing is loaded
+ * @since 1.5.1 (sqspell 0.5)
+ */
+function squirrelspell_upgrade() {
+  // globalize configuration vars before loading config.
+  // Vars are not available to scripts if not globalized before loading config.
+  // FIXME: move configuration loading to loading_prefs hook.
+  global $SQSPELL_APP, $SQSPELL_APP_DEFAULT, $SQSPELL_WORDS_FILE, $SQSPELL_CRYPTO;
+  include_once(SM_PATH . 'plugins/squirrelspell/sqspell_config.php');
+  include_once(SM_PATH . 'plugins/squirrelspell/sqspell_functions.php');
+  
+  if (! sqspell_check_version(0,5)) {
+    $langs=sqspell_getSettings_old(null);
+    $words=sqspell_getWords_old();
+    sqspell_saveSettings($langs);
+    foreach ($langs as $lang) {
+      $lang_words=sqspell_getLang_old($words,$lang);
+      $aLang_words=explode("\n",$lang_words);
+      $new_words=array();
+      foreach($aLang_words as $word) {
+        if (! preg_match("/^#/",$word) && trim($word)!='') {
+          $new_words[].=$word;
+        }
+      }
+      sqspell_writeWords($new_words,$lang);
     }
+    // bump up version number
+    setPref($data_dir,$username,'sqspell_version','0.5');
+  }
+}
+
+/**
+ * Function that displays internal squirrelspell version
+ * @since 1.5.1 (sqspell 0.5)
+ * @return string plugin's version
+ * @todo remove 'cvs' part from version when plugin's code is 
+ * stable enough
+ */
+function squirrelspell_version() {
+  return '0.5cvs';
 }
 ?>
\ No newline at end of file
index b97ddaa04245841fa42f5f3b4e742f3386c9ba8c..489703460994678e4e35e848d4960c4421d52d82 100644 (file)
@@ -5,33 +5,94 @@
  * Copyright (c) 1999-2005 The SquirrelMail Project Team
  * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
- *
- *
- * $Id$
+ * @version $Id$
  * @package plugins
  * @subpackage squirrelspell
  */
 
-/** */
-require_once(SM_PATH . 'functions/prefs.php');
+/** @ignore */
+if (! defined('SM_PATH')) define('SM_PATH','../../');
 
-/* Just for poor wretched souls with E_ALL. :) */
-global $data_dir;
+/** getHashedFile() function for SQSPELL_WORDS_FILE and sqgetGlobalVar() from global.php */
+include_once(SM_PATH . 'functions/prefs.php');
 
+/** vars needed for getHashedFile() */
+global $data_dir;
 sqgetGlobalVar('username', $username, SQ_SESSION);
 
 /**
+ * List of configured dictionaries
+ *
+ * This feature was added/changed in 0.3. Use this array to set up
+ * which dictionaries are available to users. If you only have
+ * English spellchecker on your system, then let this line be:
+ *<pre>
+ *   $SQSPELL_APP = array('English' => 'ispell -a');
+ *     or
+ *   $SQSPELL_APP = array('English' => '/usr/local/bin/aspell -a');
+ *</pre>
+ * Sometimes you have to specify full path for PHP to find it.
+ * 
+ * You can use Aspell or Ispell spellcheckers. Aspell might provide
+ * better spellchecking for Western languages.
+ *
+ * If you want to have more than one dictionary available to users,
+ * configure the array to look something like this:
+ *<pre>
+ *   $SQSPELL_APP = array('English' => 'aspell -a',
+ *                        'Russian' => 'ispell -d russian -a',
+ *                        ...
+ *                        'Swahili' => 'ispell -d swahili -a'
+ *                        );
+ *</pre>
+ * WARNINGS:
+ * <ul>
+ * <li>Watch the commas, making sure there isn't one after your last
+ *     dictionary declaration. Also, make sure all these dictionaries
+ *     are available on your system before you specify them here.</li>
+ * <li>Whatever your setting is, don't omit the "-a" flag.</li>
+ * <li>Remember to keep same array keys during upgrades. Don't rename them.
+ *   Users' dictionary settings use it.</li>
+ * <li>Interface might translate array key, if used key is present in 
+ *   SquirrelMail translations.</li>
+ * </ul>
+ * <pre>
  * Example:
+ * $SQSPELL_APP = array('English' => 'ispell -a',
+ *                      'Spanish' => 'ispell -d spanish -a' );
+ * </pre>
  *
- * $SQSPELL_APP = array( 'English' => 'ispell -a',
- *                     'Spanish' => 'ispell -d spanish -a' );
+ * @global array $SQSPELL_APP
  */
 $SQSPELL_APP = array('English' => 'ispell -a',
-                        'Spanish' => 'ispell -d spanish -a');
+                     'Spanish' => 'ispell -d spanish -a');
+
+/**
+ * Default dictionary
+ * @global string $SQSPELL_APP_DEFAULT
+ */
 $SQSPELL_APP_DEFAULT = 'English';
+
+/**
+ * File that stores user's dictionary
+ *
+ * $SQSPELL_WORDS_FILE is a location and mask of a user dictionary file.
+ * The default setting should be OK for most everyone.
+ *     
+ * This setting is used only when SquirrelSpell is upgraded from
+ * older setup. Since SquirrelMail 1.5.1 SquirrelSpell stores all settings in
+ * same place that stores other SquirrelMail user preferences.
+ * @global string $SQSPELL_WORDS_FILE
+ * @deprecated setting is still needed in order to handle upgrades
+ */
 $SQSPELL_WORDS_FILE =
    getHashedFile($username, $data_dir, "$username.words");
 
+/**
+ * Function used cheching words in user's dictionary
+ * @global string $SQSPELL_EREG
+ * @deprecated It is not used since 1.5.1 (sqspell 0.5)
+ */
 $SQSPELL_EREG = 'ereg';
 
 ?>
\ No newline at end of file
index 85dae527279195c397c749861d1b915b21501765..cbf38b99d88fc874e39efcbc9b76fbcfaf6ca5ee 100644 (file)
@@ -7,10 +7,8 @@
  * Copyright (c) 1999-2005 The SquirrelMail Project Team
  * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
- * $Id$
- *
- * @author Konstantin Riabitsev <icon@duke.edu> ($Author$)
- * @version $Date$
+ * @author Konstantin Riabitsev <icon@duke.edu>
+ * @version $Id$
  * @package plugins
  * @subpackage squirrelspell
  */
  * This function is the GUI wrapper for the options page. SquirrelSpell
  * uses it for creating all Options pages.
  *
- * @param  $title     The title of the page to display
- * @param  $scriptsrc This is used to link a file.js into the
+ * @param  string $title     The title of the page to display
+ * @param  string $scriptsrc This is used to link a file.js into the
  *                    <script src="file.js"></script> format. This
  *                    allows to separate javascript from the rest of the
  *                    plugin and place it into the js/ directory.
- * @param  $body      The body of the message to display.
+ * @param  string $body      The body of the message to display.
  * @return            void
  */
 function sqspell_makePage($title, $scriptsrc, $body){
@@ -74,7 +72,7 @@ function sqspell_makePage($title, $scriptsrc, $body){
               html_tag( 'td', '<hr />', 'left' )
           ) . "\n"
     . html_tag( 'tr',
-          html_tag( 'td', 'SquirrelSpell ' . $SQSPELL_VERSION, 'center', $color[9] )
+          html_tag( 'td', 'SquirrelSpell ' . squirrelspell_version(), 'center', $color[9] )
       ) . "\n</table>\n";
   echo '</body></html>';
 }
@@ -85,13 +83,13 @@ function sqspell_makePage($title, $scriptsrc, $body){
  * everywhere, except the check_me module, since that one is highly
  * customized.
  *
- * @param  $onload    Used to indicate and pass the name of a js function
+ * @param  string $onload    Used to indicate and pass the name of a js function
  *                    to call in a <body onload="function()" for automatic
  *                    onload script execution.
- * @param  $title     Title of the page.
- * @param  $scriptsrc If defined, link this javascript source page into
+ * @param  string $title     Title of the page.
+ * @param  string $scriptsrc If defined, link this javascript source page into
  *                    the document using <script src="file.js"> format.
- * @param  $body      The content to include.
+ * @param  string $body      The content to include.
  * @return            void
  */
 function sqspell_makeWindow($onload, $title, $scriptsrc, $body){
@@ -126,13 +124,15 @@ function sqspell_makeWindow($onload, $title, $scriptsrc, $body){
               html_tag( 'td', '<hr />', 'left' )
           ) . "\n" .
           html_tag( 'tr', "\n" .
-              html_tag( 'td', 'SquirrelSpell ' . $SQSPELL_VERSION, 'center', $color[9] )
+              html_tag( 'td', 'SquirrelSpell ' . squirrelspell_version(), 'center', $color[9] )
           ) ,
       '', '', 'width="100%" border="0" cellpadding="2"' )
     . "</body>\n</html>\n";
 }
 
 /**
+ * Encryption function used by plugin (old format)
+ *
  * This function does the encryption and decryption of the user
  * dictionary. It is only available when PHP is compiled with
  * mcrypt support (--with-mcrypt). See doc/CRYPTO for more
@@ -145,8 +145,10 @@ function sqspell_makeWindow($onload, $title, $scriptsrc, $body){
  * @param  $input Content to decrypt or encrypt, according to $mode.
  * @return        encrypted/decrypted content, or "PANIC" if the
  *                process bails out.
+ * @since 1.5.1 (sqspell 0.5)
+ * @deprecated
  */
-function sqspell_crypto($mode, $ckey, $input){
+function sqspell_crypto_old($mode, $ckey, $input){
   /**
    * Double-check if we have the mcrypt_generic function. Bail out if
    * not so.
@@ -194,6 +196,68 @@ function sqspell_crypto($mode, $ckey, $input){
   return $crypto;
 }
 
+/**
+ * Encryption function used by plugin
+ *
+ * This function does the encryption and decryption of the user
+ * dictionary. It is only available when PHP is compiled with
+ * mcrypt support (--with-mcrypt). See doc/CRYPTO for more
+ * information.
+ *
+ * @param  $mode  A string with either of the two recognized values:
+ *                "encrypt" or "decrypt".
+ * @param  $ckey  The key to use for processing (the user's password
+ *                in our case.
+ * @param  $input Content to decrypt or encrypt, according to $mode.
+ * @return        encrypted/decrypted content, or "PANIC" if the
+ *                process bails out.
+ */
+function sqspell_crypto($mode, $ckey, $input){
+  /**
+   * Double-check if we have the mcrypt_generic function. Bail out if
+   * not so.
+   */
+    if (!function_exists('mcrypt_generic')) {
+        return 'PANIC';
+    }
+    /**
+     * Setup mcrypt routines.
+     */
+    $td = mcrypt_module_open(MCRYPT_Blowfish, "", MCRYPT_MODE_ECB, "");
+    $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size ($td), MCRYPT_RAND);
+    mcrypt_generic_init($td, $ckey, $iv);
+    /**
+     * See what we have to do depending on $mode.
+     * 'encrypt' -- Encrypt the content.
+     * 'decrypt' -- Decrypt the content.
+     */
+    switch ($mode){
+    case 'encrypt':
+        $crypto = mcrypt_generic($td, '{sqspell}'.$input);
+        break;
+    case 'decrypt':
+        $crypto = mdecrypt_generic($td, $input);
+        if (preg_match("/^\{sqspell\}(.*)/",$crypto,$match)){
+            $crypto = trim($match[1]);
+        } else {
+            $crypto='PANIC';
+        }
+        break;
+    }
+    /**
+     * Finish up the mcrypt routines and return the processed content.
+     */
+    if (function_exists('mcrypt_generic_deinit')) {
+        // php 4.1.1+ syntax
+        mcrypt_generic_deinit ($td);
+        mcrypt_module_close ($td);
+    } else {
+        // older deprecated function
+        mcrypt_generic_end ($td);
+    }
+    return $crypto;
+}
+
 /**
  * This function transparently upgrades the 0.2 dictionary format to the
  * 0.3 format, since user-defined languages have been added in 0.3 and
@@ -204,6 +268,7 @@ function sqspell_crypto($mode, $ckey, $input){
  *
  * @param  $words_string Contents of the 0.2-style user dictionary.
  * @return               Contents of the 0.3-style user dictionary.
+ * @deprecated
  */
 function sqspell_upgradeWordsFile($words_string){
   global $SQSPELL_APP_DEFAULT, $SQSPELL_VERSION;
@@ -223,15 +288,54 @@ function sqspell_upgradeWordsFile($words_string){
 }
 
 /**
+ * gets list of available dictionaries from user's prefs.
+ * Function was modified in 1.5.1 (sqspell 0.5). 
+ * Older function is suffixed with '_old'
+ * @return array list of dictionaries used by end user.
+ */
+function sqspell_getSettings(){
+    global $data_dir, $username, $SQSPELL_APP_DEFAULT, $SQSPELL_APP;
+
+    $ret=array();
+
+    $sLangs=getPref($data_dir,$username,'sqspell_langs','');
+    if ($sLangs=='') {
+        $ret[0]=$SQSPELL_APP_DEFAULT;
+    } else {
+        $aLangs = explode(',',$sLangs);
+        foreach ($aLangs as $lang) {
+            if (array_key_exists($lang,$SQSPELL_APP)) {
+                $ret[].=$lang;
+            }
+        }
+    }
+    return $ret;
+}
+
+/**
+ * Saves user's language preferences
+ * @param array $langs languages array (first key is default language)
+ * @since 1.5.1 (sqspell 0.5)
+ */
+function sqspell_saveSettings($langs) {
+  global $data_dir, $username;
+  setPref($data_dir,$username,'sqspell_langs',implode(',',$langs));
+}
+
+/**
+ * Get list of enabled languages.
+ *
  * Right now it just returns an array with the dictionaries
  * available to the user for spell-checking. It will probably
  * do more in the future, as features are added.
  *
- * @param  $words The contents of the user's ".words" file.
- * @return        a strings array with dictionaries available
+ * @param string $words The contents of the user's ".words" file.
+ * @return array a strings array with dictionaries available
  *                to this user, e.g. {"English", "Spanish"}, etc.
+ * @since 1.5.1 (sqspell 0.5)
+ * @deprecated
  */
-function sqspell_getSettings($words){
+function sqspell_getSettings_old($words){
   global $SQSPELL_APP, $SQSPELL_APP_DEFAULT;
   /**
    * Check if there is more than one dictionary configured in the
@@ -243,7 +347,7 @@ function sqspell_getSettings($words){
      * a dirty fall-back. TODO: make it so this is not required.
      */
     if(!$words){
-      $words=sqspell_getWords();
+      $words=sqspell_getWords_old();
     }
     if ($words){
       /**
@@ -253,6 +357,17 @@ function sqspell_getSettings($words){
        */
       preg_match("/# LANG: (.*)/i", $words, $matches);
       $langs=explode(", ", $matches[1]);
+
+      // make sure that langs are contains values that are present in
+      /*
+      $rebuild_langs=array();
+      foreach ($langs as $lang) {
+          if (array_key_exists($lang,$SQSPELL_APP)) {
+              $rebuild_langs[].=$lang;
+          }
+      }
+      $langs=$rebuild_langs;
+      */
     } else {
       /**
        * User doesn't have a personal dictionary. Grab the default
@@ -271,6 +386,71 @@ function sqspell_getSettings($words){
 }
 
 /**
+ * Get user dictionary for selected language
+ * Function was modified in 1.5.1 (sqspell 0.5).
+ * Older function is suffixed with '_old'
+ * @param string $lang language
+ * @param array words stored in selected language dictionary
+ */
+function sqspell_getLang($lang) {
+  global $data_dir, $username,$SQSPELL_CRYPTO;
+  $sWords=getPref($data_dir,$username,'sqspell_dict_' . $lang,'');
+  if (preg_match("/^\{crypt\}(.*)/i",$sWords,$match)) {
+    /**
+     * Dictionary is encrypted or mangled. Try to decrypt it.
+     * If fails, complain loudly.
+     *
+     * $old_key would be a value submitted by one of the modules with
+     * the user's old mailbox password. I admin, this is rather dirty,
+     * but efficient. ;)
+     */
+    if (sqgetGlobalVar('old_key', $old_key, SQ_POST)) {
+      $clear_key=$old_key;
+    } else {
+      sqgetGlobalVar('key', $key, SQ_COOKIE);
+      sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
+      /**
+       * Get user's password (the key).
+       */
+      $clear_key = OneTimePadDecrypt($key, $onetimepad);
+    }
+    /**
+     * Invoke the decryption routines.
+     */
+    $sWords=sqspell_crypto("decrypt", $clear_key, $match[1]);
+    /**
+     * See if decryption failed.
+     */
+    if ($sWords=="PANIC"){
+      sqspell_handle_crypt_panic($lang);
+      // script execution stops here
+    } else {
+      /**
+       * OK! Phew. Set the encryption flag to true so we can later on
+       * encrypt it again before saving to HDD.
+       */
+      $SQSPELL_CRYPTO=true;
+    }
+  } else {
+    /**
+     * No encryption is/was used. Set $SQSPELL_CRYPTO to false,
+     * in case we have to save the dictionary later.
+     */
+    $SQSPELL_CRYPTO=false;
+  }
+  // rebuild word list and remove empty entries
+  $aWords=array();
+  foreach (explode(',',$sWords) as $word) {
+    if (trim($word) !='') {
+      $aWords[].=trim($word);
+      }
+  }
+  return $aWords;
+}
+
+/**
+ * Get user's dictionary (old format)
+ *
  * This function returns only user-defined dictionary words that correspond
  * to the requested language.
  *
@@ -280,8 +460,10 @@ function sqspell_getSettings($words){
  *                English dictionary, disregarding any others.
  * @return        The list of words corresponding to the language
  *                requested.
+ * @since 1.5.1 (sqspell 0.5)
+ * @deprecated
  */
-function sqspell_getLang($words, $lang){
+function sqspell_getLang_old($words, $lang){
   $start=strpos($words, "# $lang\n");
   /**
    * strpos() will return -1 if no # $lang\n string was found.
@@ -300,6 +482,8 @@ function sqspell_getLang($words, $lang){
 }
 
 /**
+ * Saves user's dictionary (old format)
+ *
  * This function operates the user dictionary. If the format is
  * clear-text, then it just reads the file and returns it. However, if
  * the file is encrypted (well, "garbled"), then it tries to decrypt
@@ -308,8 +492,10 @@ function sqspell_getLang($words, $lang){
  *
  * @return the contents of the user's ".words" file, decrypted if
  *         necessary.
+ * @since 1.5.1 (sqspell 0.5)
+ * @deprecated
  */
-function sqspell_getWords(){
+function sqspell_getWords_old(){
   global $SQSPELL_WORDS_FILE, $SQSPELL_CRYPTO;
   $words="";
   if (file_exists($SQSPELL_WORDS_FILE)){
@@ -350,61 +536,13 @@ function sqspell_getWords(){
     /**
      * Invoke the decryption routines.
      */
-    $words=sqspell_crypto("decrypt", $clear_key, $words);
+    $words=sqspell_crypto_old("decrypt", $clear_key, $words);
     /**
      * See if decryption failed.
      */
     if ($words=="PANIC"){
-      /**
-       * AAAAAAAAAAAH!!!!! OK, ok, breathe!
-       * Let's hope the decryption failed because the user changed his
-       * password. Bring up the option to key in the old password
-       * or wipe the file and start over if everything else fails.
-       *
-       * The _("SquirrelSpell...) line has to be on one line, otherwise
-       * gettext will bork. ;(
-       */
-      $msg = html_tag( 'p', "\n" .
-                     '<strong>' . _("ATTENTION:") . '</strong><br />'
-                     .  _("SquirrelSpell was unable to decrypt your personal dictionary. This is most likely due to the fact that you have changed your mailbox password. In order to proceed, you will have to supply your old password so that SquirrelSpell can decrypt your personal dictionary. It will be re-encrypted with your new password after this. If you haven't encrypted your dictionary, then it got mangled and is no longer valid. You will have to delete it and start anew. This is also true if you don't remember your old password -- without it, the encrypted data is no longer accessible.") ,
-                 'left' ) .  "\n"
-         . '<blockquote>' . "\n"
-         . '<form method="post" onsubmit="return AYS()">' . "\n"
-         . '<input type="hidden" name="MOD" value="crypto_badkey" />' . "\n"
-         . html_tag( 'p',  "\n" .
-               '<input type="checkbox" name="delete_words" value="ON" />'
-               . _("Delete my dictionary and start a new one") . '<br />'
-               . _("Decrypt my dictionary with my old password:")
-               . '<input name="old_key" size="10" />' ,
-           'left' ) . "\n"
-         . '</blockquote>' . "\n"
-         . html_tag( 'p', "\n" .
-               '<input type="submit" value="'
-               . _("Proceed") . ' &gt;&gt;" />' ,
-           'center' ) . "\n"
-         . '</form>' . "\n";
-      /**
-       * Add some string vars so they can be i18n'd.
-       */
-      $msg .= "<script type='text/javascript'><!--\n"
-         . "var ui_choice = \"" . _("You must make a choice") ."\";\n"
-         . "var ui_candel = \"" . _("You can either delete your dictionary or type in the old password. Not both.") . "\";\n"
-         . "var ui_willdel = \"" . _("This will delete your personal dictionary file. Proceed?") . "\";\n"
-         . "//--></script>\n";
-      /**
-       * See if this happened in the pop-up window or when accessing
-       * the SpellChecker options page.
-       * This is a dirty solution, I agree. TODO: make this prettier.
-       */
-      global $SCRIPT_NAME;
-      if (strstr($SCRIPT_NAME, "sqspell_options")){
-        sqspell_makePage(_("Error Decrypting Dictionary"),
-                          "decrypt_error.js", $msg);
-      } else {
-        sqspell_makeWindow(null, _("Error Decrypting Dictionary"),
-                           "decrypt_error.js", $msg);
-      }
-      exit;
+      sqspell_handle_crypt_panic();
+      // script execution stops here.
     } else {
       /**
        * OK! Phew. Set the encryption flag to true so we can later on
@@ -429,14 +567,51 @@ function sqspell_getWords(){
   return $words;
 }
 
+/**
+ * Saves user's dictionary
+ * Function was replaced in 1.5.1 (sqspell 0.5).
+ * Older function is suffixed with '_old'
+ * @param array $words words that should be stored in dictionary
+ * @param string $lang language
+ */
+function sqspell_writeWords($words,$lang){
+  global $SQSPELL_CRYPTO,$username,$data_dir;
+
+  $sWords = implode(',',$words);
+  if ($SQSPELL_CRYPTO){
+    /**
+     * User wants to encrypt the file. So be it.
+     * Get the user's password to use as a key.
+     */
+    sqgetGlobalVar('key', $key, SQ_COOKIE);
+    sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
+    
+    $clear_key=OneTimePadDecrypt($key, $onetimepad);
+    /**
+     * Try encrypting it. If fails, scream bloody hell.
+     */
+    $save_words = sqspell_crypto("encrypt", $clear_key, $sWords);
+    if ($save_words == 'PANIC'){
+      // FIXME: handle errors here
+
+    }
+    $save_words='{crypt}'.$save_words;
+  } else {
+    $save_words=$sWords;
+  }
+  setPref($data_dir,$username,'sqspell_dict_'.$lang,$save_words);
+}
+
 /**
  * Writes user dictionary into the $username.words file, then changes mask
  * to 0600. If encryption is needed -- does that, too.
  *
  * @param  $words The contents of the ".words" file to write.
  * @return        void
+ * @since 1.5.1 (sqspell 0.5)
+ * @deprecated
  */
-function sqspell_writeWords($words){
+function sqspell_writeWords_old($words){
   global $SQSPELL_WORDS_FILE, $SQSPELL_CRYPTO;
   /**
    * if $words is empty, create a template entry by calling the
@@ -467,6 +642,8 @@ function sqspell_writeWords($words){
        * with some work-around... Right now, do nothing. Let the Admin's
        * head hurt.. ;)))
        */
+      /** save some hairs on admin's head and store error message in logs */
+      error_log('SquirrelSpell: php does not have mcrypt support');
     }
   } else {
     $save_words = $words;
@@ -480,7 +657,23 @@ function sqspell_writeWords($words){
   chmod($SQSPELL_WORDS_FILE, 0600);
 }
 
-function sqspell_deleteWords(){
+/**
+ * Deletes user's dictionary
+ * Function was modified in 1.5.1 (sqspell 0.5). Older function is suffixed 
+ * with '_old'
+ * @param string $lang dictionary
+ */
+function sqspell_deleteWords($lang) {
+  global $data_dir, $username;
+  removePref($data_dir,$username,'sqspell_dict_'.$lang);
+}
+
+/**
+ * Deletes user's dictionary when it is corrupted.
+ * @since 1.5.1 (sqspell 0.5)
+ * @deprecated
+ */
+function sqspell_deleteWords_old(){
   /**
    * So I open the door to my enemies,
    * and I ask can we wipe the slate clean,
@@ -497,6 +690,7 @@ function sqspell_deleteWords(){
  * whatever.
  *
  * @return The template to use when storing the user dictionary.
+ * @deprecated
  */
 function sqspell_makeDummy(){
   global $SQSPELL_VERSION, $SQSPELL_APP_DEFAULT;
@@ -513,8 +707,8 @@ function sqspell_makeDummy(){
  * of the modules directory by providing dots, unicode strings, or
  * slashes.
  *
- * @param  $rMOD the name of the module requested to include.
- * @return       void, since it bails out with an access error if needed.
+ * @param  string $rMOD the name of the module requested to include.
+ * @return void, since it bails out with an access error if needed.
  */
 function sqspell_ckMOD($rMOD){
   if (strstr($rMOD, '.')
@@ -526,10 +720,101 @@ function sqspell_ckMOD($rMOD){
   }
 }
 
+/**
+ * Used to check internal version of SquirrelSpell dictionary
+ * @param integer $major main version number
+ * @param integer $minor second version number
+ * @return boolean true if stored dictionary version is $major.$minor or newer
+ * @since 1.5.1 (sqspell 0.5)
+ */
+function sqspell_check_version($major,$minor) {
+  global $data_dir, $username;
+  // 0.4 version is internal version number that is used to indicate upgrade from
+  // separate files to generic SquirrelMail prefs storage.
+  $sqspell_version=getPref($data_dir,$username,'sqspell_version','0.4');
+
+  $aVersion=explode('.',$sqspell_version);
+
+  if ($aVersion[0] < $major ||
+      ( $aVersion[0] == $major && $aVersion[1] < $minor)) {
+    return false;
+  }
+  return true;
+}
+
+/**
+ * Displays form that allows to enter different password for dictionary decryption.
+ * If language is not set, function provides form to handle older dictionary files.
+ * @param string $lang language
+ * @since 1.5.1 (sqspell 0.5)
+ */
+function sqspell_handle_crypt_panic($lang=false) {
+  if (! sqgetGlobalVar('SCRIPT_NAME',$SCRIPT_NAME,SQ_SERVER))
+    $SCRIPT_NAME='';
+
+  /**
+   * AAAAAAAAAAAH!!!!! OK, ok, breathe!
+   * Let's hope the decryption failed because the user changed his
+   * password. Bring up the option to key in the old password
+   * or wipe the file and start over if everything else fails.
+   *
+   * The _("SquirrelSpell...) line has to be on one line, otherwise
+   * gettext will bork. ;(
+   */
+  $msg = html_tag( 'p', "\n" .
+    '<strong>' . _("ATTENTION:") . '</strong><br />'
+    .  _("SquirrelSpell was unable to decrypt your personal dictionary. This is most likely due to the fact that you have changed your mailbox password. In order to proceed, you will have to supply your old password so that SquirrelSpell can decrypt your personal dictionary. It will be re-encrypted with your new password after this. If you haven't encrypted your dictionary, then it got mangled and is no longer valid. You will have to delete it and start anew. This is also true if you don't remember your old password -- without it, the encrypted data is no longer accessible.") ,
+    'left' ) .  "\n"
+    . (($lang) ? html_tag('p',sprintf(_("Your %s dictionary is encrypted with password that differs from your current password."),
+                                      htmlspecialchars($lang)),'left') : '') 
+    . '<blockquote>' . "\n"
+    . '<form method="post" onsubmit="return AYS()">' . "\n"
+    . '<input type="hidden" name="MOD" value="crypto_badkey" />' . "\n"
+    . (($lang) ? 
+       '<input type="hidden" name="dict_lang" value="'.htmlspecialchars($lang).'" />' : 
+       '<input type="hidden" name="old_setup" value="yes" />')
+    . html_tag( 'p',  "\n" .
+        '<input type="checkbox" name="delete_words" value="ON" />'
+        . _("Delete my dictionary and start a new one") . '<br />'
+        . _("Decrypt my dictionary with my old password:")
+        . '<input name="old_key" size="10" />' ,
+        'left' ) . "\n"
+        . '</blockquote>' . "\n"
+        . html_tag( 'p', "\n"
+               . '<input type="submit" value="'
+               . _("Proceed") . ' &gt;&gt;" />' ,
+           'center' ) . "\n"
+         . '</form>' . "\n";
+  /**
+   * Add some string vars so they can be i18n'd.
+   */
+  $msg .= "<script type='text/javascript'><!--\n"
+    . "var ui_choice = \"" . _("You must make a choice") ."\";\n"
+    . "var ui_candel = \"" . _("You can either delete your dictionary or type in the old password. Not both.") . "\";\n"
+    . "var ui_willdel = \"" . _("This will delete your personal dictionary file. Proceed?") . "\";\n"
+    . "//--></script>\n";
+  /**
+   * See if this happened in the pop-up window or when accessing
+   * the SpellChecker options page.
+   * This is a dirty solution, I agree.
+   * TODO: make this prettier.
+   */
+  if (strstr($SCRIPT_NAME, "sqspell_options")){
+    sqspell_makePage(_("Error Decrypting Dictionary"),
+                     "decrypt_error.js", $msg);
+  } else {
+    sqspell_makeWindow(null, _("Error Decrypting Dictionary"),
+                       "decrypt_error.js", $msg);
+  }
+  exit;
+}
+
 /**
  * SquirrelSpell version. Don't modify, since it identifies the format
  * of the user dictionary files and messing with this can do ugly
  * stuff. :)
+ * @global string $SQSPELL_VERSION
+ * @deprecated
  */
 $SQSPELL_VERSION="v0.3.8";
 ?>
\ No newline at end of file
index 79a4f45b0b291e53456d5ddd93370c1091650da6..6e3b71be3903471fe9b35898c5d74acbe1285df2 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 /**
  * sqspell_interface.php
  *
  * This is a main wrapper for the pop-up window interface of
  * SquirrelSpell.
  *
- * $Id$
- *
- * @author Konstantin Riabitsev <icon@duke.edu> ($Author$)
- * @version $Date$
+ * @author Konstantin Riabitsev <icon@duke.edu>
+ * @version $Id$
  * @package plugins
  * @subpackage squirrelspell
  */
@@ -35,28 +32,25 @@ define('SM_PATH','../../');
 
 /* SquirrelMail required files. */
 require_once(SM_PATH . 'include/validate.php');
-require_once(SM_PATH . 'include/load_prefs.php');
-require_once(SM_PATH . $SQSPELL_DIR . 'sqspell_config.php');
-require_once(SM_PATH . $SQSPELL_DIR . 'sqspell_functions.php');
+include_once(SM_PATH . 'functions/display_messages.php');
+include_once(SM_PATH . $SQSPELL_DIR . 'sqspell_config.php');
+include_once(SM_PATH . $SQSPELL_DIR . 'sqspell_functions.php');
 
 /**
  * $MOD is the name of the module to invoke.
- * If $MOD is undefined, use "init", else check for security
- * breaches.
+ * If $MOD is unspecified, assign "init" to it. Else check for
+ * security breach attempts.
  */
-if(isset($_POST['MOD'])) {
-    $MOD = $_POST['MOD'];
-} elseif (isset($_GET['MOD'])) {
-    $MOD = $_GET['MOD'];
+if(! sqgetGlobalVar('MOD',$MOD,SQ_FORM)) {
+    $MOD = 'init';
 }
+sqspell_ckMOD($MOD);
 
-if (!isset($MOD) || !$MOD){
-    $MOD='init';
+/* Load the stuff already. */
+if (file_exists(SM_PATH . $SQSPELL_DIR . "modules/$MOD.mod")) {
+    require_once(SM_PATH . $SQSPELL_DIR . "modules/$MOD.mod");
 } else {
-    sqspell_ckMOD($MOD);
+    error_box(_("Invalid SquirrelSpell module."),$color);
+    echo '</body></html>';
 }
-
-/* Include the module. */
-require_once(SM_PATH . $SQSPELL_DIR . "modules/$MOD.mod");
-
 ?>
\ No newline at end of file
index ae1a5160715e018c9a6177e8e234e469e875b78f..5e99de8f773537534684cfdbf182bddcecd9442d 100644 (file)
@@ -7,10 +7,8 @@
  * Copyright (c) 1999-2005 The SquirrelMail Project Team
  * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
- * $Id$
- *
- * @author Konstantin Riabitsev <icon@duke.edu> ($Author$)
- * @version $Date$
+ * @author Konstantin Riabitsev <icon@duke.edu>
+ * @version $Id$
  * @package plugins
  * @subpackage squirrelspell
  */
@@ -30,30 +28,25 @@ define('SM_PATH','../../');
 
 /* SquirrelMail required files. */
 require_once(SM_PATH . 'include/validate.php');
-require_once(SM_PATH . 'include/load_prefs.php');
-require_once(SM_PATH . 'functions/strings.php');
-require_once(SM_PATH . 'functions/page_header.php');
-require_once(SM_PATH . $SQSPELL_DIR . 'sqspell_config.php');
-require_once(SM_PATH . $SQSPELL_DIR . 'sqspell_functions.php');
+include_once(SM_PATH . 'functions/display_messages.php');
+include_once(SM_PATH . $SQSPELL_DIR . 'sqspell_config.php');
+include_once(SM_PATH . $SQSPELL_DIR . 'sqspell_functions.php');
 
 /**
  * $MOD is the name of the module to invoke.
- * If $MOD is unspecified, assign "init" to it. Else check for
+ * If $MOD is unspecified, assign "options_main" to it. Else check for
  * security breach attempts.
  */
-if(isset($_POST['MOD'])) {
-    $MOD = $_POST['MOD'];
-} elseif (isset($_GET['MOD'])) {
-    $MOD = $_GET['MOD'];
+if(! sqgetGlobalVar('MOD',$MOD,SQ_FORM)) {
+    $MOD = 'options_main';
 }
+sqspell_ckMOD($MOD);
 
-if(!isset($MOD) || !$MOD) {
-  $MOD = 'options_main';
+/* Load the stuff already. */
+if (file_exists(SM_PATH . $SQSPELL_DIR . "modules/$MOD.mod")) {
+    require_once(SM_PATH . $SQSPELL_DIR . "modules/$MOD.mod");
 } else {
-  sqspell_ckMOD($MOD);
+    error_box(_("Invalid SquirrelSpell module."),$color);
+    echo '</body></html>';
 }
-
-/* Load the stuff already. */
-require_once(SM_PATH . $SQSPELL_DIR . "modules/$MOD.mod");
-
 ?>
\ No newline at end of file