| 1 | <?php |
| 2 | /** |
| 3 | * setup.php |
| 4 | * ----------- |
| 5 | * Squirrelspell setup file, as defined by the SquirrelMail-1.2 API. |
| 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 | * @author Konstantin Riabitsev <icon@duke.edu> |
| 11 | * @version $Id$ |
| 12 | * @package plugins |
| 13 | * @subpackage squirrelspell |
| 14 | */ |
| 15 | |
| 16 | /** @ignore */ |
| 17 | if (! defined('SM_PATH')) define('SM_PATH','../../'); |
| 18 | |
| 19 | /** |
| 20 | * Standard SquirrelMail plugin initialization API. |
| 21 | * |
| 22 | * @return void |
| 23 | */ |
| 24 | function squirrelmail_plugin_init_squirrelspell() { |
| 25 | global $squirrelmail_plugin_hooks; |
| 26 | $squirrelmail_plugin_hooks['compose_button_row']['squirrelspell'] = |
| 27 | 'squirrelspell_setup'; |
| 28 | $squirrelmail_plugin_hooks['optpage_register_block']['squirrelspell'] = |
| 29 | 'squirrelspell_optpage_register_block'; |
| 30 | $squirrelmail_plugin_hooks['options_link_and_description']['squirrelspell'] = |
| 31 | 'squirrelspell_options'; |
| 32 | $squirrelmail_plugin_hooks['right_main_after_header']['squirrelspell'] = |
| 33 | 'squirrelspell_upgrade'; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * This function formats and adds the plugin and its description to the |
| 38 | * Options screen. |
| 39 | * |
| 40 | * @return void |
| 41 | */ |
| 42 | function squirrelspell_optpage_register_block() { |
| 43 | global $optpage_blocks; |
| 44 | /** |
| 45 | * Check if this browser is capable of using the plugin |
| 46 | */ |
| 47 | if (checkForJavascript()) { |
| 48 | /** |
| 49 | * The browser checks out. |
| 50 | * Register Squirrelspell with the $optpage_blocks array. |
| 51 | */ |
| 52 | $optpage_blocks[] = |
| 53 | array( |
| 54 | 'name' => _("SpellChecker Options"), |
| 55 | 'url' => '../plugins/squirrelspell/sqspell_options.php', |
| 56 | '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."), |
| 57 | 'js' => TRUE); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * This function adds a "Check Spelling" link to the "Compose" row |
| 63 | * during message composition. |
| 64 | * |
| 65 | * @return void |
| 66 | */ |
| 67 | function squirrelspell_setup() { |
| 68 | /** |
| 69 | * Check if this browser is capable of displaying SquirrelSpell |
| 70 | * correctly. |
| 71 | */ |
| 72 | if (checkForJavascript()) { |
| 73 | /** |
| 74 | * Some people may choose to disable javascript even though their |
| 75 | * browser is capable of using it. So these freaks don't complain, |
| 76 | * use document.write() so the "Check Spelling" button is not |
| 77 | * displayed if js is off in the browser. |
| 78 | */ |
| 79 | echo "<script type=\"text/javascript\">\n". |
| 80 | "<!--\n". |
| 81 | 'document.write("<input type=\"button\" value=\"'. |
| 82 | _("Check Spelling"). |
| 83 | '\" name=\"check_spelling\" onclick=\"window.open(\'../plugins/squirrelspell/sqspell_'. |
| 84 | 'interface.php\', \'sqspell\', \'status=yes,width=550,height=370,'. |
| 85 | 'resizable=yes\')\" />");' . "\n". |
| 86 | "//-->\n". |
| 87 | "</script>\n"; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Transparently upgrades user's dictionaries when message listing is loaded |
| 93 | * @since 1.5.1 (sqspell 0.5) |
| 94 | */ |
| 95 | function squirrelspell_upgrade() { |
| 96 | // globalize configuration vars before loading config. |
| 97 | // Vars are not available to scripts if not globalized before loading config. |
| 98 | // FIXME: move configuration loading to loading_prefs hook. |
| 99 | global $SQSPELL_APP, $SQSPELL_APP_DEFAULT, $SQSPELL_WORDS_FILE, $SQSPELL_CRYPTO; |
| 100 | include_once(SM_PATH . 'plugins/squirrelspell/sqspell_config.php'); |
| 101 | include_once(SM_PATH . 'plugins/squirrelspell/sqspell_functions.php'); |
| 102 | |
| 103 | if (! sqspell_check_version(0,5)) { |
| 104 | $langs=sqspell_getSettings_old(null); |
| 105 | $words=sqspell_getWords_old(); |
| 106 | sqspell_saveSettings($langs); |
| 107 | foreach ($langs as $lang) { |
| 108 | $lang_words=sqspell_getLang_old($words,$lang); |
| 109 | $aLang_words=explode("\n",$lang_words); |
| 110 | $new_words=array(); |
| 111 | foreach($aLang_words as $word) { |
| 112 | if (! preg_match("/^#/",$word) && trim($word)!='') { |
| 113 | $new_words[]=$word; |
| 114 | } |
| 115 | } |
| 116 | sqspell_writeWords($new_words,$lang); |
| 117 | } |
| 118 | // bump up version number |
| 119 | setPref($data_dir,$username,'sqspell_version','0.5'); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Function that displays internal squirrelspell version |
| 125 | * @since 1.5.1 (sqspell 0.5) |
| 126 | * @return string plugin's version |
| 127 | * @todo remove 'cvs' part from version when plugin's code is |
| 128 | * stable enough |
| 129 | */ |
| 130 | function squirrelspell_version() { |
| 131 | return '0.5cvs'; |
| 132 | } |
| 133 | |
| 134 | ?> |