From 7996c92035dda79d42c5922c225dd62c1e73ecb3 Mon Sep 17 00:00:00 2001
From: tokul
Date: Thu, 5 May 2005 13:08:37 +0000
Subject: [PATCH] Moved dictionaries and settings to SM prefs system 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
---
plugins/squirrelspell/INSTALL | 135 ++----
plugins/squirrelspell/doc/CRYPTO | 2 +-
plugins/squirrelspell/doc/README | 8 +-
plugins/squirrelspell/doc/index.php | 31 +-
plugins/squirrelspell/js/index.php | 31 +-
plugins/squirrelspell/modules/check_me.mod | 18 +-
plugins/squirrelspell/modules/crypto.mod | 71 +--
.../squirrelspell/modules/crypto_badkey.mod | 119 +++--
plugins/squirrelspell/modules/edit_dic.mod | 132 +++---
plugins/squirrelspell/modules/enc_setup.mod | 10 +-
plugins/squirrelspell/modules/forget_me.mod | 67 +--
.../squirrelspell/modules/forget_me_not.mod | 46 +-
plugins/squirrelspell/modules/index.php | 4 +-
plugins/squirrelspell/modules/init.mod | 2 +-
plugins/squirrelspell/modules/lang_change.mod | 91 ++--
plugins/squirrelspell/modules/lang_setup.mod | 2 +-
.../squirrelspell/modules/options_main.mod | 4 +-
plugins/squirrelspell/setup.php | 135 ++++--
plugins/squirrelspell/sqspell_config.php | 81 +++-
plugins/squirrelspell/sqspell_functions.php | 435 +++++++++++++++---
plugins/squirrelspell/sqspell_interface.php | 36 +-
plugins/squirrelspell/sqspell_options.php | 35 +-
22 files changed, 900 insertions(+), 595 deletions(-)
diff --git a/plugins/squirrelspell/INSTALL b/plugins/squirrelspell/INSTALL
index 1ac0c51b..0844f8fa 100644
--- a/plugins/squirrelspell/INSTALL
+++ b/plugins/squirrelspell/INSTALL
@@ -25,99 +25,44 @@ Enjoy and report bugs. ;)
This is an options 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';
+/**
+ * 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");
?>
diff --git a/plugins/squirrelspell/doc/CRYPTO b/plugins/squirrelspell/doc/CRYPTO
index 1ae82ed4..d64e444e 100644
--- a/plugins/squirrelspell/doc/CRYPTO
+++ b/plugins/squirrelspell/doc/CRYPTO
@@ -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.
diff --git a/plugins/squirrelspell/doc/README b/plugins/squirrelspell/doc/README
index 4abcf6d1..805d1256 100644
--- a/plugins/squirrelspell/doc/README
+++ b/plugins/squirrelspell/doc/README
@@ -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.
diff --git a/plugins/squirrelspell/doc/index.php b/plugins/squirrelspell/doc/index.php
index f720a435..0a9f0f87 100644
--- a/plugins/squirrelspell/doc/index.php
+++ b/plugins/squirrelspell/doc/index.php
@@ -1,19 +1,16 @@
\ No newline at end of file
diff --git a/plugins/squirrelspell/js/index.php b/plugins/squirrelspell/js/index.php
index f720a435..0a9f0f87 100644
--- a/plugins/squirrelspell/js/index.php
+++ b/plugins/squirrelspell/js/index.php
@@ -1,19 +1,16 @@
\ No newline at end of file
diff --git a/plugins/squirrelspell/modules/check_me.mod b/plugins/squirrelspell/modules/check_me.mod
index bc5aea88..98e1c78f 100644
--- a/plugins/squirrelspell/modules/check_me.mod
+++ b/plugins/squirrelspell/modules/check_me.mod
@@ -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
-
+
diff --git a/plugins/squirrelspell/modules/crypto.mod b/plugins/squirrelspell/modules/crypto.mod
index a161eb2f..91d2ff5a 100644
--- a/plugins/squirrelspell/modules/crypto.mod
+++ b/plugins/squirrelspell/modules/crypto.mod
@@ -21,45 +21,64 @@
*/
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='
'
. _("Your personal dictionary has been encrypted and is now stored in an encrypted format.")
. '
';
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='
'
. _("Your personal dictionary has been decrypted and is now stored as plain text.")
. '
';
break;
- case '':
+ default:
/**
* Wait, this shouldn't happen! :)
*/
- $msg = '
No action requested.
';
+ $msg = '
'._("No action requested.").'
';
break;
}
sqspell_makePage( _("Personal Dictionary Crypto Settings"), null, $msg);
diff --git a/plugins/squirrelspell/modules/crypto_badkey.mod b/plugins/squirrelspell/modules/crypto_badkey.mod
index c9ff535e..e1ca3b42 100644
--- a/plugins/squirrelspell/modules/crypto_badkey.mod
+++ b/plugins/squirrelspell/modules/crypto_badkey.mod
@@ -16,24 +16,34 @@
* @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='
' . _("Your personal dictionary was erased.") . '
';
@@ -44,49 +54,84 @@ if ($delete_words=='ON'){
* on getting the strings.
*/
$msg = '
'
- . _("Your personal dictionary was erased. Please close this window and click \"Check Spelling\" button again to start your spellcheck over.")
- . '
'
- . '
';
+ . _("Your personal dictionary was erased. Please close this window and click \"Check Spelling\" button again to start your spellcheck over.")
+ . ' '
+ . '';
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 = '
'
- . _("Your personal dictionary was re-encrypted successfully. Now return to the "SpellChecker options" menu and make your selection again." )
- . '
';
+ . _("Your personal dictionary was re-encrypted successfully. Now return to the "SpellChecker options" menu and make your selection again." )
+ . '';
sqspell_makePage(_("Successful re-encryption"), null, $msg);
} else {
$msg = '
'
- . _("Your personal dictionary was re-encrypted successfully. Please close this window and click \"Check Spelling\" button again to start your spellcheck over.")
- . '
';
+ . _("Your personal dictionary was re-encrypted successfully. Please close this window and click \"Check Spelling\" button again to start your spellcheck over.")
+ . '';
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:
diff --git a/plugins/squirrelspell/modules/edit_dic.mod b/plugins/squirrelspell/modules/edit_dic.mod
index 7507d4dd..dd4ea26d 100644
--- a/plugins/squirrelspell/modules/edit_dic.mod
+++ b/plugins/squirrelspell/modules/edit_dic.mod
@@ -16,93 +16,71 @@
*/
global $color;
+
+$pre_msg = '
'
+ . _("Please check any words you wish to delete from your dictionary.")
+ . "
\n";
+$pre_msg .= "
\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,
- '
' . _("No words in your personal dictionary.")
- . '
'
- . _("Please check any words you wish to delete from your dictionary.")
- . "
\n";
- $pre_msg .= "
\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
\n";
}
- /**
- * Check if all dictionaries were empty.
- */
- if (! isset($msg)) {
- $msg = '
' . _("No words in your personal dictionary.") . '
';
- } else {
- $msg .= '
';
- }
- sqspell_makePage(_("Edit your Personal Dictionary"), null, $msg);
}
+/**
+ * Check if all dictionaries were empty.
+ */
+if (! isset($msg)) {
+ $msg = '
' . _("No words in your personal dictionary.") . '
';
+} else {
+ $msg .= '
';
+}
+sqspell_makePage(_("Edit your Personal Dictionary"), null, $msg);
/**
* For Emacs weenies:
diff --git a/plugins/squirrelspell/modules/enc_setup.mod b/plugins/squirrelspell/modules/enc_setup.mod
index b7b2bac0..ed1d1a13 100644
--- a/plugins/squirrelspell/modules/enc_setup.mod
+++ b/plugins/squirrelspell/modules/enc_setup.mod
@@ -31,13 +31,19 @@ $msg = '";
-$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,
diff --git a/plugins/squirrelspell/modules/forget_me.mod b/plugins/squirrelspell/modules/forget_me.mod
index e108ee02..b137663d 100644
--- a/plugins/squirrelspell/modules/forget_me.mod
+++ b/plugins/squirrelspell/modules/forget_me.mod
@@ -18,62 +18,41 @@
* @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 = '
'
. sprintf(_("Deleting the following entries from %s dictionary:"), ''.$sqspell_use_app.'')
. '
'
. "
\n";
- for ($i=0; $i\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.= '
'.htmlspecialchars($deleted_word)."
\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\n";
sqspell_makePage(_("Personal Dictionary Updated"), null, $msg);
} else {
diff --git a/plugins/squirrelspell/modules/forget_me_not.mod b/plugins/squirrelspell/modules/forget_me_not.mod
index a112be60..c85dbea9 100644
--- a/plugins/squirrelspell/modules/forget_me_not.mod
+++ b/plugins/squirrelspell/modules/forget_me_not.mod
@@ -18,8 +18,12 @@
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
\ No newline at end of file
diff --git a/plugins/squirrelspell/modules/init.mod b/plugins/squirrelspell/modules/init.mod
index a3c7d998..4ca76fb9 100644
--- a/plugins/squirrelspell/modules/init.mod
+++ b/plugins/squirrelspell/modules/init.mod
@@ -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 = '
'
. ''
. ''
diff --git a/plugins/squirrelspell/modules/lang_change.mod b/plugins/squirrelspell/modules/lang_change.mod
index 72841025..cc80c3d6 100644
--- a/plugins/squirrelspell/modules/lang_change.mod
+++ b/plugins/squirrelspell/modules/lang_change.mod
@@ -18,79 +18,54 @@
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 = '
'
- . sprintf(_("Settings adjusted to: %s with %s as default dictionary."), ''.$dsp_string.'', ''._($lang_default).'')
+ . sprintf(_("Settings adjusted to: %s with %s as default dictionary."),
+ ''.htmlspecialchars($dsp_string).'',
+ ''.htmlspecialchars(_($lang_default)).'')
. '
';
} else {
/**
- * No dictionaries selected. Use system default.
+ * Only one dictionary is selected.
*/
$msg = '
'
. _("Make this dictionary my default selection:")
. "
\n";
sqspell_makePage( _("SquirrelSpell Options Menu"), null, $msg);
diff --git a/plugins/squirrelspell/setup.php b/plugins/squirrelspell/setup.php
index a30c5481..f8017a37 100644
--- a/plugins/squirrelspell/setup.php
+++ b/plugins/squirrelspell/setup.php
@@ -7,81 +7,124 @@
* Copyright (c) 1999-2005 The SquirrelMail Project Team
* Licensed under the GNU GPL. For full terms see the file COPYING.
*
- * $Id$
- *
- * @author Konstantin Riabitsev ($Author$)
- * @version $Date$
+ * @author Konstantin Riabitsev
+ * @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 "\n";
+ echo "\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
diff --git a/plugins/squirrelspell/sqspell_config.php b/plugins/squirrelspell/sqspell_config.php
index b97ddaa0..48970346 100644
--- a/plugins/squirrelspell/sqspell_config.php
+++ b/plugins/squirrelspell/sqspell_config.php
@@ -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:
+ *
+ * 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:
+ *
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.
+ *
Remember to keep same array keys during upgrades. Don't rename them.
+ * Users' dictionary settings use it.
+ *
Interface might translate array key, if used key is present in
+ * SquirrelMail translations.
*
- * $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
diff --git a/plugins/squirrelspell/sqspell_functions.php b/plugins/squirrelspell/sqspell_functions.php
index 85dae527..cbf38b99 100644
--- a/plugins/squirrelspell/sqspell_functions.php
+++ b/plugins/squirrelspell/sqspell_functions.php
@@ -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 ($Author$)
- * @version $Date$
+ * @author Konstantin Riabitsev
+ * @version $Id$
* @package plugins
* @subpackage squirrelspell
*/
@@ -19,12 +17,12 @@
* 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
* 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', '', 'left' )
) . "\n"
. html_tag( 'tr',
- html_tag( 'td', 'SquirrelSpell ' . $SQSPELL_VERSION, 'center', $color[9] )
+ html_tag( 'td', 'SquirrelSpell ' . squirrelspell_version(), 'center', $color[9] )
) . "\n\n";
echo '