-
+ 90248AA6FE389C724EA753E028D686C377731BD29EA69AE49CC983CD66B2997EE7132153C8D1E9E565DE879C55ECE13E6972ECA17FBDC112DADE45641CCC611B
mp-wp/wp-includes/js/tinymce/plugins/spellchecker/classes/PSpellShell.php
(0 . 0)(1 . 112)
122765 <?php
122766 /**
122767 * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $
122768 *
122769 * @package MCManager.includes
122770 * @author Moxiecode
122771 */
122772
122773 class PSpellShell extends SpellChecker {
122774 /**
122775 * Spellchecks an array of words.
122776 *
122777 * @param {String} $lang Language code like sv or en.
122778 * @param {Array} $words Array of words to spellcheck.
122779 * @return {Array} Array of misspelled words.
122780 */
122781 function &checkWords($lang, $words) {
122782 $cmd = $this->_getCMD($lang);
122783
122784 if ($fh = fopen($this->_tmpfile, "w")) {
122785 fwrite($fh, "!\n");
122786
122787 foreach($words as $key => $value)
122788 fwrite($fh, "^" . $value . "\n");
122789
122790 fclose($fh);
122791 } else
122792 $this->throwError("PSpell support was not found.");
122793
122794 $data = shell_exec($cmd);
122795 @unlink($this->_tmpfile);
122796
122797 $returnData = array();
122798 $dataArr = preg_split("/[\r\n]/", $data, -1, PREG_SPLIT_NO_EMPTY);
122799
122800 foreach ($dataArr as $dstr) {
122801 $matches = array();
122802
122803 // Skip this line.
122804 if (strpos($dstr, "@") === 0)
122805 continue;
122806
122807 preg_match("/\& ([^ ]+) .*/i", $dstr, $matches);
122808
122809 if (!empty($matches[1]))
122810 $returnData[] = utf8_encode(trim($matches[1]));
122811 }
122812
122813 return $returnData;
122814 }
122815
122816 /**
122817 * Returns suggestions of for a specific word.
122818 *
122819 * @param {String} $lang Language code like sv or en.
122820 * @param {String} $word Specific word to get suggestions for.
122821 * @return {Array} Array of suggestions for the specified word.
122822 */
122823 function &getSuggestions($lang, $word) {
122824 $cmd = $this->_getCMD($lang);
122825
122826 if (function_exists("mb_convert_encoding"))
122827 $word = mb_convert_encoding($word, "ISO-8859-1", mb_detect_encoding($word, "UTF-8"));
122828 else
122829 $word = utf8_encode($word);
122830
122831 if ($fh = fopen($this->_tmpfile, "w")) {
122832 fwrite($fh, "!\n");
122833 fwrite($fh, "^$word\n");
122834 fclose($fh);
122835 } else
122836 $this->throwError("Error opening tmp file.");
122837
122838 $data = shell_exec($cmd);
122839 @unlink($this->_tmpfile);
122840
122841 $returnData = array();
122842 $dataArr = preg_split("/\n/", $data, -1, PREG_SPLIT_NO_EMPTY);
122843
122844 foreach($dataArr as $dstr) {
122845 $matches = array();
122846
122847 // Skip this line.
122848 if (strpos($dstr, "@") === 0)
122849 continue;
122850
122851 preg_match("/\&[^:]+:(.*)/i", $dstr, $matches);
122852
122853 if (!empty($matches[1])) {
122854 $words = array_slice(explode(',', $matches[1]), 0, 10);
122855
122856 for ($i=0; $i<count($words); $i++)
122857 $words[$i] = trim($words[$i]);
122858
122859 return $words;
122860 }
122861 }
122862
122863 return array();
122864 }
122865
122866 function _getCMD($lang) {
122867 $this->_tmpfile = tempnam($this->_config['PSpellShell.tmp'], "tinyspell");
122868
122869 if(preg_match("#win#i", php_uname()))
122870 return $this->_config['PSpellShell.aspell'] . " -a --lang=". escapeshellarg($lang) . " --encoding=utf-8 -H < " . $this->_tmpfile . " 2>&1";
122871
122872 return "cat ". $this->_tmpfile ." | " . $this->_config['PSpellShell.aspell'] . " -a --encoding=utf-8 -H --lang=". escapeshellarg($lang);
122873 }
122874 }
122875
122876 ?>