| 1 | <?php |
| 2 | /** |
| 3 | * forget_me.mod |
| 4 | * -------------- |
| 5 | * Squirrelspell module |
| 6 | * |
| 7 | * Copyright (c) 1999-2003 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 $SQSPELL_VERSION; |
| 20 | |
| 21 | $words_ary = $_POST['words_ary']; |
| 22 | $sqspell_use_app = $_POST['sqspell_use_app']; |
| 23 | |
| 24 | /** |
| 25 | * If something needs to be deleted, then $words_ary will be |
| 26 | * non-zero length. |
| 27 | */ |
| 28 | if (sizeof($words_ary)){ |
| 29 | $words=sqspell_getWords(); |
| 30 | $lang_words = sqspell_getLang($words, $sqspell_use_app); |
| 31 | $msg = '<p>' |
| 32 | . sprintf(_("Deleting the following entries from %s dictionary:"), '<strong>'.$sqspell_use_app.'</strong>') |
| 33 | . '</p>' |
| 34 | . "<ul>\n"; |
| 35 | for ($i=0; $i<sizeof($words_ary); $i++){ |
| 36 | /** |
| 37 | * Remove word by word... |
| 38 | */ |
| 39 | $lang_words=str_replace("$words_ary[$i]\n", "", $lang_words); |
| 40 | $msg .= '<li>' . htmlspecialchars($words_ary[$i]) . "</li>\n"; |
| 41 | } |
| 42 | $new_words_ary=split("\n", $lang_words); |
| 43 | /** |
| 44 | * Wipe this lang, if only 2 members in array (no words left). |
| 45 | * # Language |
| 46 | * # End |
| 47 | */ |
| 48 | if (sizeof($new_words_ary)<=2) { |
| 49 | $lang_words=''; |
| 50 | } |
| 51 | $new_lang_words = $lang_words; |
| 52 | /** |
| 53 | * Write the dictionary back to the disk. |
| 54 | */ |
| 55 | $langs=sqspell_getSettings($words); |
| 56 | $words_dic = "# SquirrelSpell User Dictionary $SQSPELL_VERSION\n# " |
| 57 | . "Last Revision: " . date("Y-m-d") . "\n# LANG: " |
| 58 | . join(", ", $langs) . "\n"; |
| 59 | for ($i=0; $i<sizeof($langs); $i++){ |
| 60 | /** |
| 61 | * Only rewrite the contents of the selected language. |
| 62 | * Otherwise just write the contents back. |
| 63 | */ |
| 64 | if ($langs[$i]==$sqspell_use_app) { |
| 65 | $lang_words = $new_lang_words; |
| 66 | } else { |
| 67 | $lang_words = sqspell_getLang($words, $langs[$i]); |
| 68 | } |
| 69 | if ($lang_words) { |
| 70 | $words_dic .= $lang_words; |
| 71 | } |
| 72 | } |
| 73 | $words_dic .= "# End\n"; |
| 74 | sqspell_writeWords($words_dic); |
| 75 | $msg .= '</ul><p>' . _("All done!") . "</p>\n"; |
| 76 | sqspell_makePage(_("Personal Dictionary Updated"), null, $msg); |
| 77 | } else { |
| 78 | /** |
| 79 | * Click on some words first, Einstein! |
| 80 | */ |
| 81 | sqspell_makePage(_("Personal Dictionary"), null, |
| 82 | '<p>' . _("No changes requested.") . '</p>'); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * For Emacs weenies: |
| 87 | * Local variables: |
| 88 | * mode: php |
| 89 | * End: |
| 90 | * vim: syntax=php |
| 91 | */ |
| 92 | ?> |