]> git.donarmstrong.com Git - roundcube.git/blob - program/js/tiny_mce/plugins/spellchecker/classes/PSpell.php
Imported Upstream version 0.2~stable
[roundcube.git] / program / js / tiny_mce / plugins / spellchecker / classes / PSpell.php
1 <?php\r
2 /**\r
3  * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $\r
4  *\r
5  * @author Moxiecode\r
6  * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.\r
7  */\r
8 \r
9 class PSpell extends SpellChecker {\r
10         /**\r
11          * Spellchecks an array of words.\r
12          *\r
13          * @param {String} $lang Language code like sv or en.\r
14          * @param {Array} $words Array of words to spellcheck.\r
15          * @return {Array} Array of misspelled words.\r
16          */\r
17         function &checkWords($lang, $words) {\r
18                 $plink = $this->_getPLink($lang);\r
19 \r
20                 $outWords = array();\r
21                 foreach ($words as $word) {\r
22                         if (!pspell_check($plink, trim($word)))\r
23                                 $outWords[] = utf8_encode($word);\r
24                 }\r
25 \r
26                 return $outWords;\r
27         }\r
28 \r
29         /**\r
30          * Returns suggestions of for a specific word.\r
31          *\r
32          * @param {String} $lang Language code like sv or en.\r
33          * @param {String} $word Specific word to get suggestions for.\r
34          * @return {Array} Array of suggestions for the specified word.\r
35          */\r
36         function &getSuggestions($lang, $word) {\r
37                 $words = pspell_suggest($this->_getPLink($lang), $word);\r
38 \r
39                 for ($i=0; $i<count($words); $i++)\r
40                         $words[$i] = $words[$i];\r
41 \r
42                 return $words;\r
43         }\r
44 \r
45         /**\r
46          * Opens a link for pspell.\r
47          */\r
48         function &_getPLink($lang) {\r
49                 // Check for native PSpell support\r
50                 if (!function_exists("pspell_new"))\r
51                         $this->throwError("PSpell support not found in PHP installation.");\r
52 \r
53                 // Setup PSpell link\r
54                 $plink = pspell_new(\r
55                         $lang,\r
56                         $this->_config['PSpell.spelling'],\r
57                         $this->_config['PSpell.jargon'],\r
58                         $this->_config['PSpell.encoding'],\r
59                         $this->_config['PSpell.mode']\r
60                 );\r
61 \r
62                 // Setup PSpell link\r
63 /*              if (!$plink) {\r
64                         $pspellConfig = pspell_config_create(\r
65                                 $lang,\r
66                                 $this->_config['PSpell.spelling'],\r
67                                 $this->_config['PSpell.jargon'],\r
68                                 $this->_config['PSpell.encoding']\r
69                         );\r
70 \r
71                         $plink = pspell_new_config($pspell_config);\r
72                 }*/\r
73 \r
74                 if (!$plink)\r
75                         $this->throwError("No PSpell link found opened.");\r
76 \r
77                 return $plink;\r
78         }\r
79 }\r
80 \r
81 ?>\r