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