+++ /dev/null
-<?php\r
-/* * \r
- * Tiny Spelling Interface for TinyMCE Spell Checking.\r
- *\r
- * Copyright © 2006 Moxiecode Systems AB\r
- *\r
- */\r
-\r
-\r
-class TinyPspellShell {\r
- var $lang;\r
- var $mode;\r
- var $string;\r
- var $error;\r
- var $errorMsg;\r
-\r
- var $cmd;\r
- var $tmpfile;\r
-\r
- var $jargon;\r
- var $spelling;\r
- var $encoding;\r
-\r
- function TinyPspellShell(&$config, $lang, $mode, $spelling, $jargon, $encoding) {\r
- $this->lang = $lang;\r
- $this->mode = $mode;\r
- $this->error = false;\r
- $this->errorMsg = array();\r
-\r
- $this->tmpfile = tempnam($config['tinypspellshell.tmp'], "tinyspell");\r
-\r
- if(preg_match("#win#i",php_uname()))\r
- $this->cmd = $config['tinypspellshell.aspell'] . " -a --lang=". $this->lang." --encoding=utf-8 -H < $this->tmpfile 2>&1";\r
- else\r
- $this->cmd = "cat ". $this->tmpfile ." | " . $config['tinypspellshell.aspell'] . " -a --encoding=utf-8 -H --lang=". $this->lang;\r
- }\r
-\r
- // Returns array with bad words or false if failed.\r
- function checkWords($wordArray) {\r
- if ($fh = fopen($this->tmpfile, "w")) {\r
- fwrite($fh, "!\n");\r
- foreach($wordArray as $key => $value)\r
- fwrite($fh, "^" . $value . "\n");\r
- fclose($fh);\r
- } else {\r
- $this->errorMsg[] = "PSpell not found.";\r
- return array();\r
- }\r
-\r
- $data = shell_exec($this->cmd);\r
- @unlink($this->tmpfile);\r
- \r
- $returnData = array();\r
- $dataArr = preg_split("/\n/", $data, -1, PREG_SPLIT_NO_EMPTY);\r
-\r
- foreach($dataArr as $dstr) {\r
- $matches = array();\r
-\r
- // Skip this line.\r
- if (strpos($dstr, "@") === 0)\r
- continue;\r
-\r
- preg_match("/\& (.*) .* .*: .*/i", $dstr, $matches);\r
-\r
- if (!empty($matches[1]))\r
- $returnData[] = $matches[1];\r
- }\r
-\r
- return $returnData;\r
- }\r
-\r
- // Returns array with suggestions or false if failed.\r
- function getSuggestion($word) {\r
- if (function_exists("mb_convert_encoding"))\r
- $word = mb_convert_encoding($word, "ISO-8859-1", mb_detect_encoding($word, "UTF-8"));\r
- else\r
- $word = utf8_encode($word);\r
-\r
- if ($fh = fopen($this->tmpfile, "w")) {\r
- fwrite($fh, "!\n");\r
- fwrite($fh, "^$word\n");\r
- fclose($fh);\r
- } else\r
- die("Error opening tmp file.");\r
-\r
- $data = shell_exec($this->cmd);\r
-\r
- @unlink($this->tmpfile);\r
-\r
- $returnData = array();\r
- $dataArr = preg_split("/\n/", $data, -1, PREG_SPLIT_NO_EMPTY);\r
-\r
- foreach($dataArr as $dstr) {\r
- $matches = array();\r
-\r
- // Skip this line.\r
- if (strpos($dstr, "@") === 0)\r
- continue;\r
-\r
- preg_match("/\& .* .* .*: (.*)/i", $dstr, $matches);\r
-\r
- if (!empty($matches[1])) {\r
- // For some reason, the exec version seems to add commas?\r
- $returnData[] = str_replace(",", "", $matches[1]);\r
- }\r
- }\r
- return $returnData;\r
- }\r
-\r
- function _debugData($data) {\r
- $fh = @fopen("debug.log", 'a+');\r
- @fwrite($fh, $data);\r
- @fclose($fh);\r
- }\r
-\r
-}\r
-\r
-// Setup classname, should be the same as the name of the spellchecker class\r
-$spellCheckerConfig['class'] = "TinyPspellShell";\r
-\r
-?>
\ No newline at end of file