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