a112be60ed892c5e16e3b6206f154a69545dd01d
[squirrelmail.git] / plugins / squirrelspell / modules / forget_me_not.mod
1 <?php
2 /**
3 * forget_me_not.mod
4 * ------------------
5 * Squirrelspell module
6 *
7 * Copyright (c) 1999-2005 The SquirrelMail Project Team
8 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 *
10 * This module saves the added words into the user dictionary. Called
11 * after CHECK_ME module.
12 *
13 * @author Konstantin Riabitsev <icon@duke.edu>
14 * @version $Id$
15 * @package plugins
16 * @subpackage squirrelspell
17 */
18
19 global $SQSPELL_VERSION, $SQSPELL_APP_DEFAULT;
20
21 $words = $_POST['words'];
22 $sqspell_use_app = $_POST['sqspell_use_app'];
23
24 /**
25 * Because of the nature of Javascript, there is no way to efficiently
26 * pass an array. Hence, the words will arrive as a string separated by
27 * "%". To get the array, we explode the "%"'s.
28 * Dirty: yes. Is there a better solution? Let me know. ;)
29 */
30 $new_words = ereg_replace("%", "\n", $words);
31 /**
32 * Load the user dictionary and see if there is anything in it.
33 */
34 $words=sqspell_getWords();
35 if (!$words){
36 /**
37 * First time.
38 */
39 $words_dic="# SquirrelSpell User Dictionary $SQSPELL_VERSION\n# Last "
40 . "Revision: " . date("Y-m-d")
41 . "\n# LANG: $SQSPELL_APP_DEFAULT\n# $SQSPELL_APP_DEFAULT\n";
42 $words_dic .= $new_words . "# End\n";
43 } else {
44 /**
45 * Do some fancy stuff in order to save the dictionary and not mangle the
46 * rest.
47 */
48 $langs=sqspell_getSettings($words);
49 $words_dic = "# SquirrelSpell User Dictionary $SQSPELL_VERSION\n# "
50 . "Last Revision: " . date("Y-m-d") . "\n# LANG: " . join(", ", $langs)
51 . "\n";
52 for ($i=0; $i<sizeof($langs); $i++){
53 $lang_words=sqspell_getLang($words, $langs[$i]);
54 if ($langs[$i]==$sqspell_use_app){
55 if (!$lang_words) {
56 $lang_words="# $langs[$i]\n";
57 }
58 $lang_words .= $new_words;
59 }
60 $words_dic .= $lang_words;
61 }
62 $words_dic .= "# End\n";
63 }
64
65 /**
66 * Write out the file
67 */
68 sqspell_writeWords($words_dic);
69 /**
70 * display the splash screen, then close it automatically after 2 sec.
71 */
72 $onload = "setTimeout('self.close()', 2000)";
73 $msg = '<form onsubmit="return false"><div align="center">'
74 . '<input type="submit" value=" '
75 . _("Close") . ' " onclick="self.close()" /></div></form>';
76 sqspell_makeWindow($onload, _("Personal Dictionary Updated"), null, $msg);
77
78 /**
79 * For Emacs weenies:
80 * Local variables:
81 * mode: php
82 * End:
83 * vim: syntax=php
84 */
85
86 ?>