From 6649b1f0a5db6160d197a13ca79cfd67fbb02d77 Mon Sep 17 00:00:00 2001 From: svncommit Date: Sat, 23 Sep 2006 23:37:29 +0000 Subject: added TinyMCE spellchecker plugin, configured to use GoogleSpell --- .../spellchecker/classes/TinyPspellShell.class.php | 121 +++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 program/js/tiny_mce/plugins/spellchecker/classes/TinyPspellShell.class.php (limited to 'program/js/tiny_mce/plugins/spellchecker/classes/TinyPspellShell.class.php') diff --git a/program/js/tiny_mce/plugins/spellchecker/classes/TinyPspellShell.class.php b/program/js/tiny_mce/plugins/spellchecker/classes/TinyPspellShell.class.php new file mode 100644 index 000000000..348cac3d8 --- /dev/null +++ b/program/js/tiny_mce/plugins/spellchecker/classes/TinyPspellShell.class.php @@ -0,0 +1,121 @@ +lang = $lang; + $this->mode = $mode; + $this->error = false; + $this->errorMsg = array(); + + $this->tmpfile = tempnam($config['tinypspellshell.tmp'], "tinyspell"); + + if(preg_match("#win#i",php_uname())) + $this->cmd = $config['tinypspellshell.aspell'] . " -a --lang=". $this->lang." --encoding=utf-8 -H < $this->tmpfile 2>&1"; + else + $this->cmd = "cat ". $this->tmpfile ." | " . $config['tinypspellshell.aspell'] . " -a --encoding=utf-8 -H --lang=". $this->lang; + } + + // Returns array with bad words or false if failed. + function checkWords($wordArray) { + if ($fh = fopen($this->tmpfile, "w")) { + fwrite($fh, "!\n"); + foreach($wordArray as $key => $value) + fwrite($fh, "^" . $value . "\n"); + fclose($fh); + } else { + $this->errorMsg[] = "PSpell not found."; + return array(); + } + + $data = shell_exec($this->cmd); + @unlink($this->tmpfile); + + $returnData = array(); + $dataArr = preg_split("/\n/", $data, -1, PREG_SPLIT_NO_EMPTY); + + foreach($dataArr as $dstr) { + $matches = array(); + + // Skip this line. + if (strpos($dstr, "@") === 0) + continue; + + preg_match("/\& (.*) .* .*: .*/i", $dstr, $matches); + + if (!empty($matches[1])) + $returnData[] = $matches[1]; + } + + return $returnData; + } + + // Returns array with suggestions or false if failed. + function getSuggestion($word) { + if (function_exists("mb_convert_encoding")) + $word = mb_convert_encoding($word, "ISO-8859-1", mb_detect_encoding($word, "UTF-8")); + else + $word = utf8_encode($word); + + if ($fh = fopen($this->tmpfile, "w")) { + fwrite($fh, "!\n"); + fwrite($fh, "^$word\n"); + fclose($fh); + } else + die("Error opening tmp file."); + + $data = shell_exec($this->cmd); + + @unlink($this->tmpfile); + + $returnData = array(); + $dataArr = preg_split("/\n/", $data, -1, PREG_SPLIT_NO_EMPTY); + + foreach($dataArr as $dstr) { + $matches = array(); + + // Skip this line. + if (strpos($dstr, "@") === 0) + continue; + + preg_match("/\& .* .* .*: (.*)/i", $dstr, $matches); + + if (!empty($matches[1])) { + // For some reason, the exec version seems to add commas? + $returnData[] = str_replace(",", "", $matches[1]); + } + } + return $returnData; + } + + function _debugData($data) { + $fh = @fopen("debug.log", 'a+'); + @fwrite($fh, $data); + @fclose($fh); + } + +} + +// Setup classname, should be the same as the name of the spellchecker class +$spellCheckerConfig['class'] = "TinyPspellShell"; + +?> \ No newline at end of file -- cgit v1.2.3