From 9804bcdefd81265ec3e9f00d9147d647acf23ba5 Mon Sep 17 00:00:00 2001 From: philippe_mingo Date: Thu, 8 Nov 2001 16:00:33 +0000 Subject: [PATCH] start of squirrelspell internationalization git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@1706 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- plugins/squirrelspell/INSTALL | 100 +++ .../squirrelspell/modules/check_me.mod.php | 21 +- plugins/squirrelspell/modules/crypto.mod.php | 74 ++- .../modules/forget_me_not.mod.php | 2 +- plugins/squirrelspell/setup.php | 119 ++-- plugins/squirrelspell/sqspell_config.php | 100 +-- plugins/squirrelspell/sqspell_functions.php | 617 +++++++++--------- plugins/squirrelspell/sqspell_interface.php | 76 ++- plugins/squirrelspell/sqspell_options.php | 73 ++- 9 files changed, 626 insertions(+), 556 deletions(-) diff --git a/plugins/squirrelspell/INSTALL b/plugins/squirrelspell/INSTALL index 01c2c384..87750c7b 100644 --- a/plugins/squirrelspell/INSTALL +++ b/plugins/squirrelspell/INSTALL @@ -17,3 +17,103 @@ Enable the plugin either by hand or by running the configure script from your squirrelmail install directory. Enjoy and report bugs. ;) + +This is a commented sqspell_config.php + + "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'; +?> \ No newline at end of file diff --git a/plugins/squirrelspell/modules/check_me.mod.php b/plugins/squirrelspell/modules/check_me.mod.php index 0a650944..c700240f 100644 --- a/plugins/squirrelspell/modules/check_me.mod.php +++ b/plugins/squirrelspell/modules/check_me.mod.php @@ -1,12 +1,17 @@ - Line with an error:
+ ' . _("Line with an error:"); ?>
diff --git a/plugins/squirrelspell/modules/crypto.mod.php b/plugins/squirrelspell/modules/crypto.mod.php index dce29801..5ae0833d 100644 --- a/plugins/squirrelspell/modules/crypto.mod.php +++ b/plugins/squirrelspell/modules/crypto.mod.php @@ -1,36 +1,46 @@ Your personal dictionary has been encrypted and is now stored in an encrypted format.

"; - break; + /** + ** crypto.mod.php -- Squirrelspell module + ** + ** Copyright (c) 1999-2001 The SquirrelMail development team + ** Licensed under the GNU GPL. For full terms see the file COPYING. + ** + ** This module handles the encryption/decryption of the user dictionary + ** if the user so chooses from the options page. + ** + ** $Id$ + **/ - case "decrypt": - // Decrypt the file and save plain text. - $words=sqspell_getWords(); - // flip the flag. - $SQSPELL_CRYPTO=false; - sqspell_writeWords($words); - $msg="

Your personal dictionary has been decrypted and is now stored as clear text.

"; - break; - - case "": - // Wait, this shouldn't happen! :) - $msg = "

No action requested.

"; - break; -} - sqspell_makePage("Personal Dictionary Crypto Settings", null, $msg); + // Declaring globals for E_ALL + global $action, $SQSPELL_CRYPTO; + switch ($action){ + case 'encrypt': + // Let's encrypt the file. + $words=sqspell_getWords(); + // flip the flag. + $SQSPELL_CRYPTO=true; + sqspell_writeWords($words); + $msg='

' . + _("Your personal dictionary has been encrypted and is now stored in an encrypted format"=. + '.

'; + break; + + case 'decrypt': + // Decrypt the file and save plain text. + $words=sqspell_getWords(); + // flip the flag. + $SQSPELL_CRYPTO=false; + sqspell_writeWords($words); + $msg='

' . + _("Your personal dictionary has been decrypted and is now stored as clear text") . + '.

'; + break; + + case "": + // Wait, this shouldn't happen! :) + $msg = "

No action requested.

"; + break; + } + sqspell_makePage( _("Personal Dictionary Crypto Settings"), null, $msg); ?> diff --git a/plugins/squirrelspell/modules/forget_me_not.mod.php b/plugins/squirrelspell/modules/forget_me_not.mod.php index 0770ba92..f52a867f 100644 --- a/plugins/squirrelspell/modules/forget_me_not.mod.php +++ b/plugins/squirrelspell/modules/forget_me_not.mod.php @@ -38,6 +38,6 @@ // display the splash screen, then close it automatically after 2 sec. $onload="setTimeout('self.close()', 2000)"; $msg="
"; - sqspell_makeWindow($onload, "Personal Dictionary Updated", null, $msg); + sqspell_makeWindow($onload, _("Personal Dictionary Updated"), null, $msg); ?> diff --git a/plugins/squirrelspell/setup.php b/plugins/squirrelspell/setup.php index 671b63ad..351bb266 100644 --- a/plugins/squirrelspell/setup.php +++ b/plugins/squirrelspell/setup.php @@ -1,73 +1,70 @@ '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 - ); -} + if ( !soupNazi() ) { -function squirrelspell_setup() { - /* Gets added to the COMPOSE buttons row. */ - if (soupNazi()) { - return; - } + /* Register Squirrelspell with the $optionpages array. */ + $optionpages[] = 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 + ); + } + } -?> - -\n". + "\n". + "\n"; + } + } -?> +?> \ No newline at end of file diff --git a/plugins/squirrelspell/sqspell_config.php b/plugins/squirrelspell/sqspell_config.php index e0405b4b..a34a856f 100644 --- a/plugins/squirrelspell/sqspell_config.php +++ b/plugins/squirrelspell/sqspell_config.php @@ -1,88 +1,24 @@ "ispell -a"); - or + $SQSPELL_APP = array( 'English' => 'ispell -a' ); + $SQSPELL_APP_DEFAULT = 'English'; + $SQSPELL_WORDS_FILE = "$data_dir/$username.words"; + $SQSPELL_EREG = 'ereg'; + $SQSPELL_SOUP_NAZI = 'Mozilla/3, Mozilla/2, Opera 4, Opera/4, Macintosh'; - $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"; - -?> +?> \ No newline at end of file diff --git a/plugins/squirrelspell/sqspell_functions.php b/plugins/squirrelspell/sqspell_functions.php index 5eaa4615..c53018f2 100644 --- a/plugins/squirrelspell/sqspell_functions.php +++ b/plugins/squirrelspell/sqspell_functions.php @@ -1,311 +1,310 @@ -  
- - - - - - - - - - - - - - - - - -
- -

- -

Back to "SpellChecker Options" page

- SquirrelSpell -
- - - - <?php echo $title ?> - - - - - > - - - - - - - - - - - - - - - - -
- -

- -

- SquirrelSpell -
- - - 1){ - // OK, so there are more than one dictionary option. - // Now load the user prefs. - if(!$words) $words=sqspell_getWords(); - if ($words){ - // find which dictionaries user wants to use - preg_match("/# LANG: (.*)/i", $words, $matches); - $langs=explode(", ", $matches[1]); - } else { - // User doesn't have a personal dictionary. Set him up with - // a default setting. - $langs[0]=$SQSPELL_APP_DEFAULT; - } - } else { - // There is only one dictionary defined system-wide. - $langs[0]=$SQSPELL_APP_DEFAULT; - } - return $langs; -} - -function sqspell_getLang($words, $lang){ - // - // Returns words of a specific user dictionary. - // - $start=strpos($words, "# $lang\n"); - if (!$start) return ""; - $end=strpos($words, "#", $start+1); - $lang_words = substr($words, $start, $end-$start); - return $lang_words; -} - -function sqspell_getWords(){ - // - // This baby 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, then it decrypts it, checks whether the decryption was - // successful, troubleshoots if not, then returns the clear-text dictionary - // to the app. - // - global $SQSPELL_WORDS_FILE, $SQSPELL_CRYPTO; - $words=""; - if (file_exists($SQSPELL_WORDS_FILE)){ - // Gobble it up. - $fp=fopen($SQSPELL_WORDS_FILE, "r"); - $words=fread($fp, filesize($SQSPELL_WORDS_FILE)); - fclose($fp); - } - // Check if this is an encrypted file by looking for - // the string "# SquirrelSpell" in it. - if ($words && !strstr($words, "# SquirrelSpell")){ - // This file is encrypted or mangled. Try to decrypt it. - // If fails, raise hell. - global $key, $onetimepad, $old_key; - if ($old_key) { - // an override in case user is trying to decrypt a dictionary - // with his old password - $clear_key=$old_key; - } else { - // get user's password (the key). - $clear_key = OneTimePadDecrypt($key, $onetimepad); - } - // decrypt - $words=sqspell_crypto("decrypt", $clear_key, $words); - 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. - $msg="

- ATTENTION:
- 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.

-
-
- -

Delete my dictionary and start a new one
- Decrypt my dictionary with my old password:

-
-

- - "; - // See if this happened in the pop-up window or when accessing - // the SpellChecker options page. - 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; - } 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 used. Set $SQSPELL_CRYPTO to false, in case we have to - // save the dictionary later. - $SQSPELL_CRYPTO=false; - } - // Check if we need to upgrade the dictionary from version 0.2.x - if (strstr($words, "Dictionary v0.2")) $words=sqspell_upgradeWordsFile($words); - return $words; -} -function sqspell_writeWords($words){ - // - // Writes user dictionary into the $username.words file, then changes mask - // to 0600. If encryption is needed -- does that, too. - // - global $SQSPELL_WORDS_FILE, $SQSPELL_CRYPTO; - // if $words is empty, create a template entry. - if (!$words) $words=sqspell_makeDummy(); - if ($SQSPELL_CRYPTO){ - // User wants to encrypt the file. So be it. - // get his password to use as a key. - global $key, $onetimepad; - $clear_key=OneTimePadDecrypt($key, $onetimepad); - // Try encrypting it. If fails, scream bloody hell. - $save_words = sqspell_crypto("encrypt", $clear_key, $words); - if ($save_words=="PANIC"){ - // AAAAAAAAH! I'm not handling this yet, since obviously - // the admin of the site forgot to compile the MCRYPT support in. - // I will add a handler for this case later, when I can come up - // with some work-around... Right now, do nothing. Let the Admin's - // head hurt.. ;))) - } - } else { - $save_words = $words; - } - $fp=fopen($SQSPELL_WORDS_FILE, "w"); - fwrite($fp, $save_words); - fclose($fp); - chmod($SQSPELL_WORDS_FILE, 0600); -} - -function sqspell_deleteWords(){ - // - // so I open the door to my enemies, - // and I ask can we wipe the slate clean, - // but they tell me to please go... - // uhm... Well, this just erases the user dictionary file. - // - global $SQSPELL_WORDS_FILE; - if (file_exists($SQSPELL_WORDS_FILE)) unlink($SQSPELL_WORDS_FILE); -} - -function sqspell_makeDummy(){ - // - // Creates an empty user dictionary for the sake of saving prefs or - // whatever. - // - global $SQSPELL_VERSION, $SQSPELL_APP_DEFAULT; - $words="# SquirrelSpell User Dictionary $SQSPELL_VERSION\n# Last Revision: " . date("Y-m-d") . "\n# LANG: $SQSPELL_APP_DEFAULT\n# End\n"; - return $words; -} - -/** - VERSION: - --------- - SquirrelSpell version. Don't modify, since it identifies the format - of the user dictionary files and messing with this can do ugly - stuff. :) - **/ -$SQSPELL_VERSION="v0.3.5"; - - -?> + /** + ** sqspell_functions.php -- All SquirrelSpell-wide functions are in this file. + ** + ** Copyright (c) 1999-2001 The SquirrelMail development team + ** Licensed under the GNU GPL. For full terms see the file COPYING. + ** + ** + ** + ** $Id$ + **/ + + function sqspell_makePage($title, $scriptsrc, $body){ + /* + ** GUI wrap-around for the OPTIONS page. + */ + global $color, $SQSPELL_VERSION, $MOD; + displayPageHeader($color, 'None'); + + echo " 
\n"; + if($scriptsrc) { + echo "\n"; + } + echo ''. + ''. + "'. + ''. + ''. + ""; + if ($MOD!="options_main"){ + // Generate a nice return-to-main link. + echo ''. + ''; + } + echo ''. + ''. + "'. + ''. + '
". + "$title". + '

$body

' . + _("Back to "SpellChecker Options" page") . '

". + "SquirrelSpell $SQSPELL_VERSION". + '
'; + } + + function sqspell_makeWindow($onload, $title, $scriptsrc, $body){ + + /* + ** GUI wrap-around for the pop-up window interface. + */ + global $color, $SQSPELL_VERSION, $theme_css; + + echo "\n". + "\n". + "$title\n"; + if ($theme_css != "") { + echo "\n"; + } + if ($scriptsrc){ + echo "\n"; + } + echo "\n". + "'. + ''. + ''. + "'. + ''. + ''. + ''. + "". + ''. + ''. + ''. + "'. + ''. + '
". + "$title". + '

$body

". + "SquirrelSpell $SQSPELL_VERSION". + '
'. + "\n\n"; + } + + function sqspell_crypto($mode, $ckey, $input){ + // + // This function does the encryption and decryption of the user + // dictionary. It is only available when PHP is compiled + // --with-mcrypt. See doc/CRYPTO for more information. + // + if (!function_exists(mcrypt_generic)) { + return 'PANIC'; + } + $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); + switch ($mode){ + case 'encrypt': + $crypto = mcrypt_generic($td, $input); + break; + case 'decrypt': + $crypto = mdecrypt_generic($td, $input); + // See if it decrypted successfully. If so, it should contain + // the string "# SquirrelSpell". + if (!strstr($crypto, "# SquirrelSpell")) + $crypto='PANIC'; + break; + } + mcrypt_generic_end ($td); + return $crypto; + } + + function sqspell_upgradeWordsFile($words_string){ + /* + ** This function transparently upgrades the 0.2 dictionary format to + ** 0.3, since user-defined languages have been added in 0.3 and + ** the new format keeps user dictionaries selection in the file. + */ + global $SQSPELL_APP_DEFAULT, $SQSPELL_VERSION; + + /* Define just one dictionary for this user -- the default. + ** If the user wants more, s/he can set them up in personal + ** preferences. See doc/UPGRADING for more info. + */ + $new_words_string=substr_replace($words_string, "# SquirrelSpell User Dictionary $SQSPELL_VERSION\n# Last Revision: " . date("Y-m-d") . "\n# LANG: $SQSPELL_APP_DEFAULT\n# $SQSPELL_APP_DEFAULT", 0, strpos($words_string, "\n")) . "# End\n"; + sqspell_writeWords($new_words_string); + return $new_words_string; + } + + function sqspell_getSettings($words){ + /* + ** 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. + */ + global $SQSPELL_APP, $SQSPELL_APP_DEFAULT; + if (sizeof($SQSPELL_APP) > 1){ + // OK, so there are more than one dictionary option. + // Now load the user prefs. + if(!$words) + $words=sqspell_getWords(); + if ($words){ + // find which dictionaries user wants to use + preg_match("/# LANG: (.*)/i", $words, $matches); + $langs=explode(", ", $matches[1]); + } else { + // User doesn't have a personal dictionary. Set him up with + // a default setting. + $langs[0]=$SQSPELL_APP_DEFAULT; + } + } else { + // There is only one dictionary defined system-wide. + $langs[0]=$SQSPELL_APP_DEFAULT; + } + return $langs; + } + + function sqspell_getLang($words, $lang){ + // + // Returns words of a specific user dictionary. + // + $start=strpos($words, "# $lang\n"); + if (!$start) return ''; + $end=strpos($words, "#", $start+1); + $lang_words = substr($words, $start, $end-$start); + return $lang_words; + } + + function sqspell_getWords(){ + // + // This baby 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, then it decrypts it, checks whether the decryption was + // successful, troubleshoots if not, then returns the clear-text dictionary + // to the app. + // + global $SQSPELL_WORDS_FILE, $SQSPELL_CRYPTO; + $words=""; + if (file_exists($SQSPELL_WORDS_FILE)){ + // Gobble it up. + $fp=fopen($SQSPELL_WORDS_FILE, 'r'); + $words=fread($fp, filesize($SQSPELL_WORDS_FILE)); + fclose($fp); + } + // Check if this is an encrypted file by looking for + // the string "# SquirrelSpell" in it. + if ($words && !strstr($words, "# SquirrelSpell")){ + // This file is encrypted or mangled. Try to decrypt it. + // If fails, raise hell. + global $key, $onetimepad, $old_key; + if ($old_key) { + // an override in case user is trying to decrypt a dictionary + // with his old password + $clear_key=$old_key; + } else { + // get user's password (the key). + $clear_key = OneTimePadDecrypt($key, $onetimepad); + } + // decrypt + $words=sqspell_crypto("decrypt", $clear_key, $words); + 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. + $msg='

'. + '' . _("ATTENTION:") . '
' . + _("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."). + "

+
+
+ +

" . _("Delete my dictionary and start a new one") . '
'. + _("Decrypt my dictionary with my old password:") . "

+
+

+ + "; + // See if this happened in the pop-up window or when accessing + // the SpellChecker options page. + 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; + } 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 used. Set $SQSPELL_CRYPTO to false, in case we have to + // save the dictionary later. + $SQSPELL_CRYPTO=false; + } + // Check if we need to upgrade the dictionary from version 0.2.x + if (strstr($words, "Dictionary v0.2")) $words=sqspell_upgradeWordsFile($words); + return $words; + } + + function sqspell_writeWords($words){ + // + // Writes user dictionary into the $username.words file, then changes mask + // to 0600. If encryption is needed -- does that, too. + // + global $SQSPELL_WORDS_FILE, $SQSPELL_CRYPTO; + // if $words is empty, create a template entry. + if (!$words) $words=sqspell_makeDummy(); + if ($SQSPELL_CRYPTO){ + // User wants to encrypt the file. So be it. + // get his password to use as a key. + global $key, $onetimepad; + $clear_key=OneTimePadDecrypt($key, $onetimepad); + // Try encrypting it. If fails, scream bloody hell. + $save_words = sqspell_crypto("encrypt", $clear_key, $words); + if ($save_words == 'PANIC'){ + /* + ** AAAAAAAAH! I'm not handling this yet, since obviously + ** the admin of the site forgot to compile the MCRYPT support in. + ** I will add a handler for this case later, when I can come up + ** with some work-around... Right now, do nothing. Let the Admin's + ** head hurt.. ;))) + */ + } + } else { + $save_words = $words; + } + $fp=fopen($SQSPELL_WORDS_FILE, "w"); + fwrite($fp, $save_words); + fclose($fp); + chmod($SQSPELL_WORDS_FILE, 0600); + } + + function sqspell_deleteWords(){ + /* + ** so I open the door to my enemies, + ** and I ask can we wipe the slate clean, + ** but they tell me to please go... + ** uhm... Well, this just erases the user dictionary file. + */ + global $SQSPELL_WORDS_FILE; + if (file_exists($SQSPELL_WORDS_FILE)) unlink($SQSPELL_WORDS_FILE); + } + + function sqspell_makeDummy(){ + // + // Creates an empty user dictionary for the sake of saving prefs or + // whatever. + // + global $SQSPELL_VERSION, $SQSPELL_APP_DEFAULT; + $words="# SquirrelSpell User Dictionary $SQSPELL_VERSION\n# Last Revision: " . date('Y-m-d') . "\n# LANG: $SQSPELL_APP_DEFAULT\n# End\n"; + return $words; + } + + /** + VERSION: + --------- + SquirrelSpell version. Don't modify, since it identifies the format + of the user dictionary files and messing with this can do ugly + stuff. :) + **/ + $SQSPELL_VERSION="v0.3.5"; + +?> \ No newline at end of file diff --git a/plugins/squirrelspell/sqspell_interface.php b/plugins/squirrelspell/sqspell_interface.php index fa81e4f6..9da06c75 100644 --- a/plugins/squirrelspell/sqspell_interface.php +++ b/plugins/squirrelspell/sqspell_interface.php @@ -1,36 +1,48 @@ + } + /* fetch the module now. */ + require_once("$SQSPELL_DIR/modules/$MOD.mod.php"); +?> \ No newline at end of file diff --git a/plugins/squirrelspell/sqspell_options.php b/plugins/squirrelspell/sqspell_options.php index 86c75cd3..348034b9 100644 --- a/plugins/squirrelspell/sqspell_options.php +++ b/plugins/squirrelspell/sqspell_options.php @@ -1,35 +1,46 @@ + } + /* load the stuff already. */ + require_once("$SQSPELL_DIR/modules/$MOD.mod.php"); +?> \ No newline at end of file -- 2.25.1