if 'js' => TRUE, javascript support is checked by src/options.php
[squirrelmail.git] / plugins / squirrelspell / setup.php
CommitLineData
849bdf42 1<?php
d112ed5a 2/**
3 * setup.php
4 * -----------
5 * Squirrelspell setup file, as defined by the SquirrelMail-1.2 API.
91e0dccc 6 *
9eb3fcb3 7 * Copyright (c) 1999-2005 The SquirrelMail Project Team
d112ed5a 8 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 *
7996c920 10 * @author Konstantin Riabitsev <icon@duke.edu>
11 * @version $Id$
ea5f4b8e 12 * @package plugins
13 * @subpackage squirrelspell
d112ed5a 14 */
849bdf42 15
7996c920 16/** @ignore */
17if (! defined('SM_PATH')) define('SM_PATH','../../');
18
d112ed5a 19/**
598294a7 20 * Standard SquirrelMail plugin initialization API.
90ad8cd1 21 *
d112ed5a 22 * @return void
23 */
24function squirrelmail_plugin_init_squirrelspell() {
7996c920 25 global $squirrelmail_plugin_hooks;
26 $squirrelmail_plugin_hooks['compose_button_row']['squirrelspell'] =
90ad8cd1 27 'squirrelspell_setup';
7996c920 28 $squirrelmail_plugin_hooks['optpage_register_block']['squirrelspell'] =
90ad8cd1 29 'squirrelspell_optpage_register_block';
7996c920 30 $squirrelmail_plugin_hooks['options_link_and_description']['squirrelspell'] =
90ad8cd1 31 'squirrelspell_options';
7996c920 32 $squirrelmail_plugin_hooks['right_main_after_header']['squirrelspell'] =
90ad8cd1 33 'squirrelspell_upgrade';
d112ed5a 34}
849bdf42 35
d112ed5a 36/**
37 * This function formats and adds the plugin and its description to the
38 * Options screen.
90ad8cd1 39 *
d112ed5a 40 * @return void
41 */
42function squirrelspell_optpage_register_block() {
7996c920 43 global $optpage_blocks;
44 /**
45 * Check if this browser is capable of using the plugin
46 */
47 if (checkForJavascript()) {
d112ed5a 48 /**
7996c920 49 * The browser checks out.
50 * Register Squirrelspell with the $optpage_blocks array.
d112ed5a 51 */
7996c920 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 }
d112ed5a 59}
849bdf42 60
d112ed5a 61/**
62 * This function adds a "Check Spelling" link to the "Compose" row
63 * during message composition.
90ad8cd1 64 *
d112ed5a 65 * @return void
66 */
67function squirrelspell_setup() {
7996c920 68 /**
69 * Check if this browser is capable of displaying SquirrelSpell
70 * correctly.
71 */
72 if (checkForJavascript()) {
d112ed5a 73 /**
7996c920 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.
d112ed5a 78 */
7996c920 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 */
95function 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)!='') {
773d8dcd 113 $new_words[]=$word;
7996c920 114 }
115 }
116 sqspell_writeWords($new_words,$lang);
04fa3c41 117 }
7996c920 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 */
130function squirrelspell_version() {
131 return '0.5cvs';
d112ed5a 132}
90ad8cd1 133
f8a1ed5a 134?>