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.") - . '

'); -} else { - /** - * We're loaded with booty. - */ - $pre_msg = '

' - . _("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 .= '
" - . sprintf( _("%s dictionary"), $langs[$i] ) . '
' - . '
' - . '' - . '' - . '' - . '' - . "' + . '' - . "\n"; + $msg .= " ' + . htmlspecialchars($lang_words[$j]) . "
\n"; } + $msg .= '
\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\n"; - } - $msg .= " ' - . htmlspecialchars($words_ary[$j]) . "
\n"; + if (!isset($msg) || !$msg) { + $msg = $pre_msg; + } + $msg .= "
" + . sprintf( _("%s dictionary"), $lang ) . '
' + . '' + . '' + . '' + . '' + . '' + . "
\n"; + /** + * Do some fancy stuff to separate the words into three + * columns. + */ + for ($j=0; $j\n"; } - $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.'') . '

' . "