Skip to content
This repository has been archived by the owner on Aug 21, 2020. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'alecpl/bugfix'
Browse files Browse the repository at this point in the history
  • Loading branch information
spocke committed Apr 13, 2011
2 parents 65be0ae + 0ca0911 commit be7509c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Version 2.0.6 (2011-??-??)
Fixed handling of mispelled words with no suggestions in PSpellShell engine.
Fixed PSpellShell command on Windows.
Fixed bug where Javascript error is produced when enchant_dict_suggest() returns unexpected result.
Version 2.0.5 (2011-03-24)
Merged with the latest TinyMCE spellchecker version.
Version 2.0.4 (2010-12-20)
Expand Down
8 changes: 6 additions & 2 deletions classes/EnchantSpell.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,20 @@ function &checkWords($lang, $words) {
*/
function &getSuggestions($lang, $word) {
$r = enchant_broker_init();
$suggs = array();

if (enchant_broker_dict_exists($r,$lang)) {
$d = enchant_broker_request_dict($r, $lang);
$suggs = enchant_dict_suggest($d, $word);

// enchant_dict_suggest() sometimes returns NULL
if (!is_array($suggs))
$suggs = array();

enchant_broker_free_dict($d);
} else {

$suggs = array();
}

enchant_broker_free($r);

return $suggs;
Expand Down
20 changes: 12 additions & 8 deletions classes/PSpellShell.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ function &checkWords($lang, $words) {
$matches = array();

// Skip this line.
if (strpos($dstr, "@") === 0)
if ($dstr[0] == "@")
continue;

preg_match("/\& ([^ ]+) .*/i", $dstr, $matches);
preg_match("/(\&|#) ([^ ]+) .*/i", $dstr, $matches);

if (!empty($matches[1]))
$returnData[] = utf8_encode(trim($matches[1]));
if (!empty($matches[2]))
$returnData[] = utf8_encode(trim($matches[2]));
}

return $returnData;
Expand Down Expand Up @@ -82,7 +82,7 @@ function &getSuggestions($lang, $word) {
$matches = array();

// Skip this line.
if (strpos($dstr, "@") === 0)
if ($dstr[0] == "@")
continue;

preg_match("/\&[^:]+:(.*)/i", $dstr, $matches);
Expand All @@ -103,10 +103,14 @@ function &getSuggestions($lang, $word) {
function _getCMD($lang) {
$this->_tmpfile = tempnam($this->_config['PSpellShell.tmp'], "tinyspell");

if(preg_match("#win#i", php_uname()))
return $this->_config['PSpellShell.aspell'] . " -a --lang=". escapeshellarg($lang) . " --encoding=utf-8 -H < " . $this->_tmpfile . " 2>&1";
$file = $this->_tmpfile;
$lang = preg_replace("/[^-_a-z]/", "", strtolower($lang));
$bin = $this->_config['PSpellShell.aspell'];

return "cat ". $this->_tmpfile ." | " . $this->_config['PSpellShell.aspell'] . " -a --encoding=utf-8 -H --lang=". escapeshellarg($lang);
if (preg_match("#win#i", php_uname()))
return "$bin -a --lang=$lang --encoding=utf-8 -H < $file 2>&1";

return "cat $file | $bin -a --lang=$lang --encoding=utf-8 -H");
}
}

Expand Down

0 comments on commit be7509c

Please sign in to comment.