summaryrefslogtreecommitdiffstats
path: root/wp-includes/js/tinymce/plugins/spellchecker/classes/TinyPspell.class.php
blob: 21fb19448e7ac21a2b6ed29a8cc6b512ed0e64e2 (plain)
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
<?php
/* * 

 * Tiny Spelling Interface for TinyMCE Spell Checking.

 *

 * Copyright © 2006 Moxiecode Systems AB

 *

 */

class TinyPSpell {
	var $lang;
	var $mode;
	var $string;
	var $plink;
	var $errorMsg;

	var $jargon;
	var $spelling;
	var $encoding;

	function TinyPSpell(&$config, $lang, $mode, $spelling, $jargon, $encoding) {
		$this->lang = $lang;
		$this->mode = $mode;
		$this->plink = false;
		$this->errorMsg = array();

		if (!function_exists("pspell_new")) {
			$this->errorMsg[] = "PSpell not found.";
			return;
		}

		$this->plink = pspell_new($this->lang, $this->spelling, $this->jargon, $this->encoding, $this->mode);
	}

	// Returns array with bad words or false if failed.

	function checkWords($wordArray) {
		if (!$this->plink) {
			$this->errorMsg[] = "No PSpell link found for checkWords.";
			return array();
		}

		$wordError = array();
		foreach($wordArray as $word) {
			if(!pspell_check($this->plink, trim($word)))
				$wordError[] = $word;
		}

		return $wordError;
	}

	// Returns array with suggestions or false if failed.

	function getSuggestion($word) {
		if (!$this->plink) {
			$this->errorMsg[] = "No PSpell link found for getSuggestion.";
			return array();
		}

		return pspell_suggest($this->plink, $word);
	}
}

// Setup classname, should be the same as the name of the spellchecker class

$spellCheckerConfig['class'] = "TinyPspell";

?>