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