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