Some uniformity into the sec index.php flavor
[squirrelmail.git] / plugins / squirrelspell / modules / forget_me.mod
1 <?php
2 /**
3 * forget_me.mod
4 * --------------
5 * Squirrelspell module
6 *
7 * Copyright (c) 1999-2002 The SquirrelMail development team
8 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 *
10 * This module deletes the words from the user dictionary. Called
11 * after EDIT_DIC module.
12 *
13 * $Id$
14 *
15 * @author Konstantin Riabitsev <icon@duke.edu> ($Author$)
16 * @version $Date$
17 */
18
19 global $words_ary, $sqspell_use_app, $SQSPELL_VERSION;
20 /**
21 * If something needs to be deleted, then $words_ary will be
22 * non-zero length.
23 */
24 if (sizeof($words_ary)){
25 $words=sqspell_getWords();
26 $lang_words = sqspell_getLang($words, $sqspell_use_app);
27 $msg = '<p>'
28 . sprintf(_("Deleting the following entries from <strong>%s</strong> dictionary:"), $sqspell_use_app)
29 . '</p>'
30 . "<ul>\n";
31 for ($i=0; $i<sizeof($words_ary); $i++){
32 /**
33 * Remove word by word...
34 */
35 $lang_words=str_replace("$words_ary[$i]\n", "", $lang_words);
36 $msg .= "<li>$words_ary[$i]</li>\n";
37 }
38 $new_words_ary=split("\n", $lang_words);
39 /**
40 * Wipe this lang, if only 2 members in array (no words left).
41 * # Language
42 * # End
43 */
44 if (sizeof($new_words_ary)<=2) {
45 $lang_words='';
46 }
47 $new_lang_words = $lang_words;
48 /**
49 * Write the dictionary back to the disk.
50 */
51 $langs=sqspell_getSettings($words);
52 $words_dic = "# SquirrelSpell User Dictionary $SQSPELL_VERSION\n# "
53 . "Last Revision: " . date("Y-m-d") . "\n# LANG: "
54 . join(", ", $langs) . "\n";
55 for ($i=0; $i<sizeof($langs); $i++){
56 /**
57 * Only rewrite the contents of the selected language.
58 * Otherwise just write the contents back.
59 */
60 if ($langs[$i]==$sqspell_use_app) {
61 $lang_words = $new_lang_words;
62 } else {
63 $lang_words = sqspell_getLang($words, $langs[$i]);
64 }
65 if ($lang_words) {
66 $words_dic .= $lang_words;
67 }
68 }
69 $words_dic .= "# End\n";
70 sqspell_writeWords($words_dic);
71 $msg .= '</ul><p>' . _("All done!") . "</p>\n";
72 sqspell_makePage(_("Personal Dictionary Updated"), null, $msg);
73 } else {
74 /**
75 * Click on some words first, Einstein!
76 */
77 sqspell_makePage(_("Personal Dictionary"), null,
78 '<p>' . _("No changes requested.") . '</p>');
79 }
80
81 /**
82 * For Emacs weenies:
83 * Local variables:
84 * mode: php
85 * End:
86 */
87 ?>