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