Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/editor/tinymce/tiny_mce/3.4.6/plugins/spellchecker/classes/PSpellShell.php
Go to the documentation of this file.
00001 <?php
00010 class PSpellShell extends SpellChecker {
00018         function &checkWords($lang, $words) {
00019                 $cmd = $this->_getCMD($lang);
00020 
00021                 if ($fh = fopen($this->_tmpfile, "w")) {
00022                         fwrite($fh, "!\n");
00023 
00024                         foreach($words as $key => $value)
00025                                 fwrite($fh, "^" . $value . "\n");
00026 
00027                         fclose($fh);
00028                 } else
00029                         $this->throwError("PSpell support was not found.");
00030 
00031                 $data = shell_exec($cmd);
00032                 @unlink($this->_tmpfile);
00033 
00034                 $returnData = array();
00035                 $dataArr = preg_split("/[\r\n]/", $data, -1, PREG_SPLIT_NO_EMPTY);
00036 
00037                 foreach ($dataArr as $dstr) {
00038                         $matches = array();
00039 
00040                         // Skip this line.
00041                         if ($dstr[0] == "@")
00042                                 continue;
00043 
00044                         preg_match("/(\&|#) ([^ ]+) .*/i", $dstr, $matches);
00045 
00046                         if (!empty($matches[2]))
00047                                 $returnData[] = utf8_encode(trim($matches[2]));
00048                 }
00049 
00050                 return $returnData;
00051         }
00052 
00060         function &getSuggestions($lang, $word) {
00061                 $cmd = $this->_getCMD($lang);
00062 
00063         if (function_exists("mb_convert_encoding"))
00064             $word = mb_convert_encoding($word, "ISO-8859-1", mb_detect_encoding($word, "UTF-8"));
00065         else
00066             $word = utf8_encode($word);
00067 
00068                 if ($fh = fopen($this->_tmpfile, "w")) {
00069                         fwrite($fh, "!\n");
00070                         fwrite($fh, "^$word\n");
00071                         fclose($fh);
00072                 } else
00073                         $this->throwError("Error opening tmp file.");
00074 
00075                 $data = shell_exec($cmd);
00076                 @unlink($this->_tmpfile);
00077 
00078                 $returnData = array();
00079                 $dataArr = preg_split("/\n/", $data, -1, PREG_SPLIT_NO_EMPTY);
00080 
00081                 foreach($dataArr as $dstr) {
00082                         $matches = array();
00083 
00084                         // Skip this line.
00085                         if ($dstr[0] == "@")
00086                                 continue;
00087 
00088                         preg_match("/\&[^:]+:(.*)/i", $dstr, $matches);
00089 
00090                         if (!empty($matches[1])) {
00091                                 $words = array_slice(explode(',', $matches[1]), 0, 10);
00092 
00093                                 for ($i=0; $i<count($words); $i++)
00094                                         $words[$i] = trim($words[$i]);
00095 
00096                                 return $words;
00097                         }
00098                 }
00099 
00100                 return array();
00101         }
00102 
00103         function _getCMD($lang) {
00104                 $this->_tmpfile = tempnam($this->_config['PSpellShell.tmp'], "tinyspell");
00105 
00106                 $file = $this->_tmpfile;
00107                 $lang = preg_replace("/[^-_a-z]/", "", strtolower($lang));
00108                 $bin  = $this->_config['PSpellShell.aspell'];
00109 
00110                 if (preg_match("#win#i", php_uname()))
00111                         return "$bin -a --lang=$lang --encoding=utf-8 -H < $file 2>&1";
00112 
00113                 return "cat $file | $bin -a --lang=$lang --encoding=utf-8 -H";
00114         }
00115 }
00116 
00117 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations