]> git.donarmstrong.com Git - roundcube.git/blob - program/js/tiny_mce/plugins/spellchecker/classes/EnchantSpell.php
Imported Upstream version 0.3.1
[roundcube.git] / program / js / tiny_mce / plugins / spellchecker / classes / EnchantSpell.php
1 <?php\r
2 /**\r
3  * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $\r
4  *\r
5  * This class was contributed by Michel Weimerskirch.\r
6  *\r
7  * @author Moxiecode\r
8  * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.\r
9  */\r
10 \r
11 class EnchantSpell extends SpellChecker {\r
12         /**\r
13          * Spellchecks an array of words.\r
14          *\r
15          * @param String $lang Selected language code (like en_US or de_DE). Shortcodes like "en" and "de" work with enchant >= 1.4.1\r
16          * @param Array $words Array of words to check.\r
17          * @return Array of misspelled words.\r
18          */\r
19         function &checkWords($lang, $words) {\r
20                 $r = enchant_broker_init();\r
21                 \r
22                 if (enchant_broker_dict_exists($r,$lang)) {\r
23                         $d = enchant_broker_request_dict($r, $lang);\r
24                         \r
25                         $returnData = array();\r
26                         foreach($words as $key => $value) {\r
27                                 $correct = enchant_dict_check($d, $value);\r
28                                 if(!$correct) {\r
29                                         $returnData[] = trim($value);\r
30                                 }\r
31                         }\r
32         \r
33                         return $returnData;\r
34                         enchant_broker_free_dict($d);\r
35                 } else {\r
36 \r
37                 }\r
38                 enchant_broker_free($r);\r
39         }\r
40 \r
41         /**\r
42          * Returns suggestions for a specific word.\r
43          *\r
44          * @param String $lang Selected language code (like en_US or de_DE). Shortcodes like "en" and "de" work with enchant >= 1.4.1\r
45          * @param String $word Specific word to get suggestions for.\r
46          * @return Array of suggestions for the specified word.\r
47          */\r
48         function &getSuggestions($lang, $word) {\r
49                 $r = enchant_broker_init();\r
50                 $suggs = array();\r
51 \r
52                 if (enchant_broker_dict_exists($r,$lang)) {\r
53                         $d = enchant_broker_request_dict($r, $lang);\r
54                         $suggs = enchant_dict_suggest($d, $word);\r
55 \r
56                         enchant_broker_free_dict($d);\r
57                 } else {\r
58 \r
59                 }\r
60                 enchant_broker_free($r);\r
61 \r
62                 return $suggs;\r
63         }\r
64 }\r
65 \r
66 ?>\r