function check($word)
 {
     //pspell
     if ($this->pspell) {
         if ($this->lang == 'ru') {
             $word = convertCharsetInKOI8($word);
         }
         return pspell_check($this->pspell_link, $word);
         //custom
     } elseif ($this->custom_spell) {
         if ($this->lang == 'ru') {
             $word = convertCharsetInWIN1251($word);
         }
         if (strlen($word) <= $this->skip_len) {
             return true;
         }
         $first_let = $this->codeLetter(string_lower($word[0]));
         if (!isset($this->dic[$first_let])) {
             $this->loadDic($first_let);
         }
         //check if word exist in array
         if (isset($this->dic[$first_let][string_lower($word)])) {
             return true;
         }
         return false;
     }
 }
Ejemplo n.º 2
0
function obtainData($objDb, $id)
{
    $aRes = $objDb->GetDetails($id);
    $sText = $objDb->GetRawText($id);
    if ($aRes === FALSE || $sText === FALSE) {
        // No such record!
        return FALSE;
    }
    // Clean up list of words
    $aWords = array_filter(array_unique(str_word_count($sText, 1)), "filter_words");
    // Split words into likely and unlikely (based on spelling)
    $aLikely = array();
    $aUnlikely = array();
    $hSpell = pspell_new("en");
    if ($hSpell !== FALSE) {
        foreach ($aWords as $sWord) {
            // Make a spellcheck on it
            if (pspell_check($hSpell, $sWord)) {
                array_push($aLikely, $sWord);
            } else {
                array_push($aUnlikely, $sWord);
            }
        }
    } else {
        $aLikely = $aWords;
    }
    return array("likely" => $aLikely, "unlikely" => $aUnlikely);
}
Ejemplo n.º 3
0
 /**
  * Check a word for spelling errors, add to $this->miss_spelled_words
  * array if miss spelled
  *
  * @param string $word
  * @return void
  */
 function check($word)
 {
     global $atmail;
     $word = preg_replace('/[^a-zA-Z\\-]/', '', $word);
     // if the word is in the personal_words array
     // or the ignore list then it is OK. If it is already
     // in the $suggestions array then ignore it
     if (in_array($word, $this->personal_words) || $atmail->isset_chk($this->suggestions[$word]) || in_array($word, $_SESSION['spellcheck_ignore'])) {
         return;
     }
     // if word is OK ignore it
     if ($this->use_pspell) {
         if (pspell_check($this->dict, $word)) {
             return;
         }
         $this->suggestions[$word] = pspell_suggest($this->dict, $word);
     } else {
         fwrite($this->aspell_input, "{$word}\n");
         $result = fgets($this->aspell_output);
         // remove trash from stream
         $trash = fgets($this->aspell_output);
         unset($trash);
         if (preg_match('/.+?\\d:(.+)/', $result, $m)) {
             $this->suggestions[$word] = explode(', ', $m[1]);
         } else {
             return;
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Checks spelling.
  *
  * @since 150424 Adding password strength.
  *
  * @param string $word  Input word to check.
  * @param int    $flags Dictionary flags.
  *
  * @return bool True if spelled correctly.
  */
 public function __invoke(string $word, int $flags = PSPELL_NORMAL) : bool
 {
     if (is_null($dictionary =& $this->cacheKey(__FUNCTION__, $flags))) {
         $dictionary = pspell_new('en', '', '', 'utf-8', $flags);
     }
     return pspell_check($dictionary, $word);
 }
Ejemplo n.º 5
0
function spellCheckWord($word)
{
    global $pspell, $bad;
    $autocorrect = TRUE;
    $ignore_words = array("wikihows", "blog", "online", "ipod", "nano");
    // Take the string match from preg_replace_callback's array
    $word = $word[0];
    // Ignore ALL CAPS, and numbers
    if (preg_match('/^[A-Z]*$/', $word)) {
        return;
    }
    if (preg_match('/^[0-9]*$/', $word)) {
        return;
    }
    if (in_array(strtolower($word), $ignore_words)) {
        return;
    }
    // Return dictionary words
    if (pspell_check($pspell, $word)) {
        // this word is OK
        return;
    }
    echo "Bad word {$word} - ";
    $bad++;
    $suggestions = pspell_suggest($pspell, $word);
    if (sizeof($suggestions) > 0) {
        if (sizeof($suggestions) > 5) {
            echo implode(",", array_splice($suggestions, 0, 5)) . "\n";
        } else {
            echo implode(",", $suggestions) . "\n";
        }
    } else {
        echo "no suggestions\n";
    }
}
Ejemplo n.º 6
0
 /**
  * Spellchecks an array of words.
  *
  * @param String $lang Selected language code (like en_US or de_DE). Shortcodes like "en" and "de" work with enchant >= 1.4.1
  * @param Array $words Array of words to check.
  * @return Name/value object with arrays of suggestions.
  */
 public function getSuggestions($lang, $words)
 {
     $config = $this->getConfig();
     switch ($config['PSpell.mode']) {
         case "fast":
             $mode = PSPELL_FAST;
             break;
         case "slow":
             $mode = PSPELL_SLOW;
             break;
         default:
             $mode = PSPELL_NORMAL;
     }
     // Setup PSpell link
     $plink = pspell_new($lang, $config['pspell.spelling'], $config['pspell.jargon'], $config['pspell.encoding'], $mode);
     if (!$plink) {
         throw new Exception("No PSpell link found opened.");
     }
     $outWords = array();
     foreach ($words as $word) {
         if (!pspell_check($plink, trim($word))) {
             $outWords[] = utf8_encode($word);
         }
     }
     return $outWords;
 }
Ejemplo n.º 7
0
 function check($word)
 {
     $word = trim($word);
     $ret = pspell_check($this->resid, $word);
     $this->lastword = $word;
     return $ret;
 }
 private function pspell()
 {
     foreach ($_REQUEST as $key => $value) {
         ${$key} = html_entity_decode(urldecode(stripslashes(trim($value))));
     }
     // load the dictionary
     $pspell_link = pspell_new_personal($this->pspell_personal_dictionary, $this->lang);
     // return suggestions
     if (isset($suggest)) {
         exit(json_encode(pspell_suggest($pspell_link, urldecode($suggest))));
     } elseif (isset($text)) {
         $words = array();
         foreach ($text = explode(' ', urldecode($text)) as $word) {
             if (!pspell_check($pspell_link, $word) and !in_array($word, $words)) {
                 $words[] = $word;
             }
         }
         exit(json_encode($words));
     } elseif (isset($addtodictionary)) {
         $pspell_config = pspell_config_create('en');
         @pspell_config_personal($pspell_config, $this->pspell_personal_dictionary) or die('can\'t find pspell dictionary');
         $pspell_link = pspell_new_config($pspell_config);
         @pspell_add_to_personal($pspell_link, strtolower($addtodictionary)) or die('You can\'t add a word to the dictionary that contains any punctuation.');
         pspell_save_wordlist($pspell_link);
         exit(array());
     }
 }
Ejemplo n.º 9
0
 public function checkWord($word)
 {
     //pspell
     if ($this->pspell) {
         return pspell_check($this->pspell_link, $word);
     }
     //custom
     //		elseif($this->custom_spell)
     //		{
     //			if ($this->lang == 'ru')
     //			{
     //				$word = $APPLICATION->ConvertCharset($word, "UTF-8", "Windows-1251");
     //			}
     //
     //			if (strlen($word) <= $this->skip_len)
     //			{
     //				return true;
     //			}
     //
     //			$first_let = $this->codeLetter(strtolower($word{0}));
     //
     //			if (!isset($this->dic[$first_let]))
     //			{
     //				$this->loadDic($first_let);
     //			}
     //			//check if word exist in array
     //			if (isset($this->dic[$first_let][strtolower($word)]))
     //			{
     //				return true;
     //			}
     //			return false;
     //		}
 }
 /**
  * Use pspell to get word suggestions
  * @param string $word
  * @return array
  */
 public function suggest($word)
 {
     if (!pspell_check($this->pSpell, $word)) {
         return pspell_suggest($this->pSpell, $word);
     } else {
         return [$word];
     }
 }
 /**
  * Validates word first in cache then in pspell
  * @param string $word
  * @return boolean
  */
 public function valid($word)
 {
     $wordLower = mb_strtolower($word, 'UTF-8');
     $this->parseCache();
     if (!isset($this->words[$wordLower])) {
         $this->words[$wordLower] = pspell_check($this->getPspell(), $word);
     }
     return $this->words[$wordLower];
 }
	/**
	 * Checks a word against the dictionary.
	 *
	 * @param boolean Returns true if word is in dictionary, false if not.
	 */
	public function check($word) {
		$this->word = $word;
		if ($this->handle !== false && pspell_check($this->handle, $word) == true) {
			return true;
		}
		else {
			return false;
		}
	}
Ejemplo n.º 13
0
 /**
  * Spellchecks an array of words.
  *
  * @param {String} $lang Language code like sv or en.
  * @param {Array} $words Array of words to spellcheck.
  * @return {Array} Array of misspelled words.
  */
 function &checkWords($lang, $words)
 {
     $plink = $this->_getPLink($lang);
     $outWords = array();
     foreach ($words as $word) {
         if (!pspell_check($plink, trim($word))) {
             $outWords[] = utf8_encode($word);
         }
     }
     return $outWords;
 }
Ejemplo n.º 14
0
 function check($data)
 {
     $recognized = array();
     if (is_string($data)) {
         $data = array($data);
     }
     foreach ($data as $word) {
         if (pspell_check($this->_ps, $word)) {
             $recognized[] = $word;
         }
     }
     return $recognized;
 }
Ejemplo n.º 15
0
function ewiki_spellcheck_list($ws)
{
    global $spell_bin, $pspell_h;
    #-- every word once only
    $words = array();
    foreach (array_unique($ws) as $word) {
        if (!empty($word)) {
            $words[] = $word;
        }
    }
    #print_r($words);
    #-- PHP internal pspell
    if ($pspell_h) {
        #-- build ispell like check list
        $results = array();
        foreach ($words as $w) {
            if (pspell_check($pspell_h, $w)) {
                $results[$word] = "*";
            } else {
                $results[$word] = "& " . implode(", ", pspell_suggest($pspell_h, $w));
            }
        }
    } elseif ($spell_bin) {
        #-- pipe word list through ispell
        $r = implode(" ", $words);
        $results = explode("\n", $r = `echo {$r} | {$spell_bin}`);
        $results = array_slice($results, 1);
    }
    #print_r($results);
    #-- build replacement html hash from results
    $r = array();
    foreach ($words as $n => $word) {
        if ($repl = $results[$n]) {
            switch ($repl[0]) {
                case "-":
                case "+":
                case "*":
                    $repl = $word;
                    break;
                default:
                    $repl = '<s title="' . htmlentities($repl) . '" style="color:#ff5555;" class="wrong">' . $word . '</s>';
            }
        } else {
            $repl = $word;
        }
        $r[$word] = $repl;
    }
    #print_r($r);
    return $r;
}
Ejemplo n.º 16
0
 function checkWords($wordArray)
 {
     if (!$this->plink) {
         $this->errorMsg[] = "No PSpell link found for checkWords.";
         return array();
     }
     $wordError = array();
     foreach ($wordArray as $word) {
         if (!pspell_check($this->plink, trim($word))) {
             $wordError[] = $word;
         }
     }
     return $wordError;
 }
Ejemplo n.º 17
0
 public function get_incorrect_words()
 {
     $texts = (array) $_POST['text'];
     $response = array();
     foreach ($texts as $text) {
         $words = explode(' ', $text);
         $incorrect_words = array();
         foreach ($words as $word) {
             if (!pspell_check($this->pspell_link, $word)) {
                 $incorrect_words[] = $word;
             }
         }
         $response[] = $incorrect_words;
     }
     $this->send_data('success', $response);
 }
Ejemplo n.º 18
0
 public function getCorrections()
 {
     $wordMatcher = "/\\w+/u";
     preg_match_all($wordMatcher, $this->rawInput, $words);
     if (count($words[0]) == 0) {
         return array();
     }
     foreach ($words[0] as $k => $word) {
         if (!pspell_check($this->pspell, $word)) {
             $suggestions = pspell_suggest($this->pspell, $word);
             $this->corrections[$word]['offset'] = $k;
             $this->corrections[$word]['suggestions'] = $suggestions;
         }
     }
     return $this->corrections;
 }
Ejemplo n.º 19
0
function check($word)
{
    $pspell_config = pspell_config_create("ru", "", "", "UTF-8");
    pspell_config_mode($pspell_config, PSPELL_FAST);
    $pspell_link = pspell_new_config($pspell_config);
    if (!pspell_check($pspell_link, $word)) {
        $arr = array();
        $suggestions = pspell_suggest($pspell_link, $word);
        foreach ($suggestions as $suggestion) {
            array_push($arr, $suggestion);
        }
        $json = json_encode($arr);
    } else {
        $json = true;
    }
    echo $json;
}
Ejemplo n.º 20
0
function check_data($xml, $data)
{
    global $element, $dict, $check_tags, $current_file, $word_count;
    if (!in_array($element, $check_tags)) {
        return;
    }
    if (trim($data) == '') {
        return;
    }
    $words = preg_split('/\\W+/', trim($data));
    if (is_array($words)) {
        foreach ($words as $word) {
            if (trim($word) == '' || is_numeric($word) || preg_match('/[^a-z]/', $word)) {
                continue;
            }
            $word_count++;
            $word = strtolower($word);
            if (!pspell_check($dict, $word)) {
                /* known bug: due to trim()ing and whitespace removal, the
                 * line number shown here might not match the actual line
                 * number in the file, but it's usually pretty close
                 */
                $note = "{$current_file}:" . xml_get_current_line_number($xml) . ": {$word}   (in element {$element})\n";
                echo $note;
                echo "================\nContext:\n{$data}\n================\n";
                do {
                    $response = read_line("Add this word to personal wordlist? (yes/no/save/later): ");
                    if ($response[0] == 's') {
                        pspell_save_wordlist($dict);
                        echo "Wordlist saved.\n";
                    }
                } while ($response[0] != 'y' && $response[0] != 'n' && $response[0] != 'l');
                if ($response[0] == 'y') {
                    pspell_add_to_personal($dict, $word);
                    echo "Added '{$word}' to personal wordlist.\n";
                }
                if ($response[0] == 'l') {
                    file_put_contents('/tmp/fix-me-later.txt', $note, FILE_APPEND);
                    echo "You will deal with '{$word}' later.\n";
                }
            }
        }
    }
    return;
}
Ejemplo n.º 21
0
 function checkSpelling($text)
 {
     $list = array();
     $this->checked = array();
     $words = $this->getWords($text);
     foreach ($words as $k => $w) {
         // don't check the same word twice
         if (isset($this->checked[$w])) {
             if (is_array($this->checked[$w])) {
                 $list[] = array('word' => $this->escape($w), 'offset' => $k, 'length' => strlen($w), 'suggestions' => $this->escape($this->checked[$w]));
             }
             continue;
         }
         // if it's in the personal dictionary, it's valid
         if ($this->checkPersonal($w)) {
             $this->checked[$w] = true;
             continue;
         }
         // if it's in the suggestions table, we can avoid pspell
         $sug = $this->checkSuggestions($w);
         // if it's an array, the word is incorrect
         if (is_array($sug)) {
             $list[] = array('word' => $this->escape($w), 'offset' => $k, 'length' => strlen($w), 'suggestions' => $this->escape($sug));
             $this->checked[$w] = $sug;
             continue;
             // if it's a boolean true, the word is correct
         } elseif ($sug === true) {
             $this->checked[$w] = true;
             continue;
         }
         // finally, we check with pspell...
         // if it comes up false, it's a mistake
         if (!pspell_check($this->pspell, $w)) {
             $sug = pspell_suggest($this->pspell, $w);
             $list[] = array('word' => $this->escape($w), 'offset' => $k, 'length' => strlen($w), 'suggestions' => $this->escape($sug));
             $this->addSuggestion($w, $sug);
             $this->checked[$w] = $sug;
             // the word is correct, let's have Xspel learn it
         } else {
             $this->addSuggestion($w);
             $this->checked[$w] = true;
         }
     }
     return $list;
 }
Ejemplo n.º 22
0
 function getErrors($text, $max = 10)
 {
     $separator = "!\$%^&*()-_=+{}[]\\|;:\",.?/\n\r|\t ";
     $errors = array('word' => array(), 'suggest' => array());
     $word = strtok($text, $separator);
     while ($word !== false) {
         if (!is_numeric($word) && !in_array($word, $errors['word']) && !pspell_check($this->link, $word)) {
             $errors['word'][] = $word;
             $suggests = pspell_suggest($this->link, $word);
             if (array_key_exists($max, $suggests)) {
                 array_splice($suggests, $max);
             }
             $errors['suggest'][] = $suggests;
         }
         $word = strtok($separator);
     }
     return $errors;
 }
Ejemplo n.º 23
0
 /**
  * Intercepts and handles requests for spell checks.
  *
  * @param string $word the string to perform checks against
  *
  * @return void
  */
 public function onCommandSpell($word)
 {
     $source = $this->event->getSource();
     $target = $this->event->getNick();
     $message = $target . ': The word "' . $word;
     $message .= '" seems to be spelled correctly.';
     if (!pspell_check($this->pspell, $word)) {
         $suggestions = pspell_suggest($this->pspell, $word);
         $message = $target;
         $message .= ': I could not find any suggestions for "' . $word . '".';
         if (!empty($suggestions)) {
             $suggestions = array_splice($suggestions, 0, $this->limit);
             $message = $target . ': Suggestions for "';
             $message .= $word . '": ' . implode(', ', $suggestions) . '.';
         }
     }
     $this->doPrivmsg($source, $message);
 }
 function check($string)
 {
     if (is_null($this->pspell_link)) {
         return NULL;
     }
     $words = explode(' ', $string);
     $new_words = array();
     foreach ($words as $word) {
         if (!pspell_check($this->pspell_link, $word)) {
             $suggestions = pspell_suggest($this->pspell_link, $word);
             // get suggestions from pspell
             // for now simply use the first suggestion in the list
             if (count($suggestions) > 0) {
                 $has_hyphen = strpos($word, '-') !== FALSE;
                 $suggestion = $suggestions[0];
                 // look for a suggestion that is one word (not two as pspell sometimes does)
                 // also ignore suggestions with hyphens if the given word is not hyphenated
                 if (strpos($suggestion, ' ') !== FALSE || !$has_hyphen && strpos($suggestion, '-') !== FALSE) {
                     // only search through the first 20 suggestions
                     $count = min(20, count($suggestions));
                     for ($i = 1; $i < $count; $i++) {
                         if (strpos($suggestions[$i], ' ') === FALSE && $has_hyphen) {
                             $suggestion = $suggestions[$i];
                             break;
                         } else {
                             if (strpos($suggestions[$i], ' ') === FALSE && !$has_hyphen && strpos($suggestions[$i], '-') === FALSE) {
                                 $suggestion = $suggestions[$i];
                                 break;
                             }
                         }
                     }
                 }
                 $new_words[] = strtolower($suggestion);
             } else {
                 $new_words[] = $word;
             }
         } else {
             $new_words[] = $word;
         }
     }
     $suggestion = join(' ', $new_words);
     return $suggestion != $string ? $suggestion : '';
 }
Ejemplo n.º 25
0
 public function checkWords($adjust = 1, $length = 4, $percent = 0.2)
 {
     if ($this->length == 0) {
         return;
     }
     $dict = pspell_new('en', null, null, 'utf-8', PSPELL_FAST);
     preg_match_all('/[a-z]+/i', $this->password, $words);
     foreach ($words[0] as $word) {
         if (strlen($word) < $length) {
             continue;
         }
         if (strlen($word) / $this->length < $percent) {
             continue;
         }
         if (!pspell_check($dict, $word)) {
             continue;
         }
         $this->change($this->max * max(1.5 + strlen($word) / $this->length / 2 * $adjust, 1), "Found the word '%s'", array($word));
     }
 }
Ejemplo n.º 26
0
 public function arrCheck($words)
 {
     //find misspelled words
     foreach ($words as $word) {
         if (!pspell_check($this->speller, $word)) {
             $misspelled[] = $word;
         }
     }
     $suggestions = array();
     if (!empty($misspelled)) {
         // return contains a list of suggestions for each mispelled words
         foreach ($misspelled as $value) {
             // don't get suggestions for the same word twice
             if (!array_key_exists($value, $suggestions)) {
                 $suggestions[$value] = pspell_suggest($this->speller, $value);
             }
         }
     }
     return $suggestions;
 }
Ejemplo n.º 27
0
    function _spell($params)
    {
        $user = $params['user'];
        $channel = $params['channel'];
        $presence = DB::get()->row('SELECT status, data FROM presence WHERE user_id = :user_id AND data <> "" ORDER BY msgtime DESC LIMIT 1', array('user_id' => $user->id));
        $data = $presence->data;
        $words = preg_split('%\\W+%', $data);
        $words = array_unique($words);
        $words = array_combine($words, $words);
        $pspell_link = pspell_new("en");
        foreach ($words as $word) {
            if (!pspell_check($pspell_link, $word)) {
                $suggestions = pspell_suggest($pspell_link, $word);
                if (count($suggestions) > 0) {
                    $presence->data = str_replace($word, reset($suggestions), $presence->data);
                } else {
                    $presence->data = str_replace($word, '<s>' . $word . '</s>', $presence->data);
                }
            }
        }
        if ($presence->data == $data) {
            Immediate::ok('No spelling corrections.', $user);
        } else {
            include_once "Text/Diff.php";
            include_once "Text/Diff/Renderer.php";
            include_once "Text/Diff/Renderer/inline.php";
            $diff =& new Text_Diff(explode("\n", $data), explode("\n", htmlspecialchars_decode($presence->data)));
            $renderer =& new Text_Diff_Renderer_inline();
            $replacement = $renderer->render($diff);
            $replacement = addslashes($replacement);
            $replacement = str_replace("\n", '\\n', $replacement);
            $js = <<<REPLJS
retcon({$presence->status}, '{$replacement}');
REPLJS;
            Status::create()->user_id($user->id)->js($js)->channel($channel)->cssclass('spell')->insert();
        }
        return true;
    }
Ejemplo n.º 28
0
 /**
  * Handler for the content of a tag
  */
 public function spellCheckHandler($xml_parser, $string)
 {
     $incurrent = array();
     $stringText = $string;
     $words = preg_split($this->parserCharset == 'utf-8' ? '/\\P{L}+/u' : '/\\W+/', $stringText);
     foreach ($words as $word) {
         $word = preg_replace('/ /' . ($this->parserCharset == 'utf-8' ? 'u' : ''), '', $word);
         if ($word && !is_numeric($word)) {
             if ($this->pspell_is_available && !$this->forceCommandMode) {
                 if (!pspell_check($this->pspell_link, $word)) {
                     if (!in_array($word, $this->misspelled)) {
                         if (sizeof($this->misspelled) != 0) {
                             $this->suggestedWords .= ',';
                         }
                         $suggest = array();
                         $suggest = pspell_suggest($this->pspell_link, $word);
                         if (sizeof($suggest) != 0) {
                             $this->suggestionCount++;
                             $this->suggestedWordCount += sizeof($suggest);
                         }
                         $this->suggestedWords .= '"' . $word . '":"' . implode(',', $suggest) . '"';
                         $this->misspelled[] = $word;
                         unset($suggest);
                     }
                     if (!in_array($word, $incurrent)) {
                         $stringText = preg_replace('/\\b' . $word . '\\b/' . ($this->parserCharset == 'utf-8' ? 'u' : ''), '<span class="htmlarea-spellcheck-error">' . $word . '</span>', $stringText);
                         $incurrent[] = $word;
                     }
                 }
             } else {
                 $tmpFileName = GeneralUtility::tempnam($this->filePrefix);
                 if (!($filehandle = fopen($tmpFileName, 'wb'))) {
                     echo 'SpellChecker tempfile open error';
                 }
                 if (!fwrite($filehandle, $word)) {
                     echo 'SpellChecker tempfile write error';
                 }
                 if (!fclose($filehandle)) {
                     echo 'SpellChecker tempfile close error';
                 }
                 $catCommand = TYPO3_OS === 'WIN' ? 'type' : 'cat';
                 $AspellCommand = $catCommand . ' ' . escapeshellarg($tmpFileName) . ' | ' . $this->AspellDirectory . ' -a check' . ' --mode=none' . ' --sug-mode=' . escapeshellarg($this->pspellMode) . ($this->personalDictionaryPath ? ' --home-dir=' . escapeshellarg($this->personalDictionaryPath) : '') . ' --lang=' . escapeshellarg($this->dictionary) . ' --encoding=' . escapeshellarg($this->aspellEncoding) . ' 2>&1';
                 $AspellAnswer = shell_exec($AspellCommand);
                 $AspellResultLines = array();
                 $AspellResultLines = GeneralUtility::trimExplode(LF, $AspellAnswer, TRUE);
                 if (substr($AspellResultLines[0], 0, 6) == 'Error:') {
                     echo '{' . $AspellAnswer . '}';
                 }
                 GeneralUtility::unlink_tempfile($tmpFileName);
                 if ($AspellResultLines['1'][0] !== '*') {
                     if (!in_array($word, $this->misspelled)) {
                         if (sizeof($this->misspelled) != 0) {
                             $this->suggestedWords .= ',';
                         }
                         $suggest = array();
                         $suggestions = array();
                         if ($AspellResultLines['1'][0] === '&') {
                             $suggestions = GeneralUtility::trimExplode(':', $AspellResultLines['1'], TRUE);
                             $suggest = GeneralUtility::trimExplode(',', $suggestions['1'], TRUE);
                         }
                         if (sizeof($suggest) != 0) {
                             $this->suggestionCount++;
                             $this->suggestedWordCount += sizeof($suggest);
                         }
                         $this->suggestedWords .= '"' . $word . '":"' . implode(',', $suggest) . '"';
                         $this->misspelled[] = $word;
                         unset($suggest);
                         unset($suggestions);
                     }
                     if (!in_array($word, $incurrent)) {
                         $stringText = preg_replace('/\\b' . $word . '\\b/' . ($this->parserCharset == 'utf-8' ? 'u' : ''), '<span class="htmlarea-spellcheck-error">' . $word . '</span>', $stringText);
                         $incurrent[] = $word;
                     }
                 }
                 unset($AspellResultLines);
             }
             $this->wordCount++;
         }
     }
     $this->text .= $stringText;
     unset($incurrent);
 }
Ejemplo n.º 29
0
	}

	$pspell_config = pspell_config_create("en");
	pspell_config_personal($pspell_config, "./dict/".$user_dictionary_file);
	$int = pspell_new_config($pspell_config);
	
	if($_POST['dictadd']!="") {
		pspell_add_to_personal($int, $_POST['dictadd']);
		pspell_save_wordlist($int);
	}
	
	for($i=$start;$i<count($words);$i++) {
		$currentword=$words[$i];
		if(strlen(trim($words[$i]))>2) {
			
			if (!pspell_check($int, $currentword)) {
			   $suggestions = pspell_suggest($int, $currentword);
			   $found_misspell=true;
			   $start=$i;
			   $misspell_index=$i;
			   break;
   			}
		}
	}
	?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Spell Checker</title>
<link rel="stylesheet" type="text/css" href="easyspell.css" />
<script src="easyspell.js" type="text/javascript"></script>
Ejemplo n.º 30
0
function SpellCheck()
{
    global $txt, $context, $func;
    // A list of "words" we know about but pspell doesn't.
    $known_words = array('smf', 'php', 'mysql', 'www', 'gif', 'jpeg', 'png', 'http', 'smfisawesome', 'grandia', 'terranigma', 'rpgs');
    loadLanguage('Post');
    loadTemplate('Post');
    // Okay, this looks funny, but it actually fixes a weird bug.
    ob_start();
    $old = error_reporting(0);
    // See, first, some windows machines don't load pspell properly on the first try.  Dumb, but this is a workaround.
    pspell_new('en');
    // Next, the dictionary in question may not exist.  So, we try it... but...
    $pspell_link = pspell_new($txt['lang_dictionary'], $txt['lang_spelling'], '', strtr($context['character_set'], array('iso-' => 'iso', 'ISO-' => 'iso')), PSPELL_FAST | PSPELL_RUN_TOGETHER);
    error_reporting($old);
    ob_end_clean();
    // Most people don't have anything but english installed... so we use english as a last resort.
    if (!$pspell_link) {
        $pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
    }
    if (!isset($_POST['spellstring']) || !$pspell_link) {
        die;
    }
    // Construct a bit of Javascript code.
    $context['spell_js'] = '
		var txt = {"done": "' . $txt['spellcheck_done'] . '"};
		var mispstr = window.opener.document.forms[spell_formname][spell_fieldname].value;
		var misps = Array(';
    // Get all the words (Javascript already seperated them).
    $alphas = explode("\n", stripslashes(strtr($_POST['spellstring'], array("\r" => ''))));
    $found_words = false;
    for ($i = 0, $n = count($alphas); $i < $n; $i++) {
        // Words are sent like 'word|offset_begin|offset_end'.
        $check_word = explode('|', $alphas[$i]);
        // If the word is a known word, or spelled right...
        if (in_array($func['strtolower']($check_word[0]), $known_words) || pspell_check($pspell_link, $check_word[0]) || !isset($check_word[2])) {
            continue;
        }
        // Find the word, and move up the "last occurance" to here.
        $found_words = true;
        // Add on the javascript for this misspelling.
        $context['spell_js'] .= '
			new misp("' . strtr($check_word[0], array('\\' => '\\\\', '"' => '\\"', '<' => '', '&gt;' => '')) . '", ' . (int) $check_word[1] . ', ' . (int) $check_word[2] . ', [';
        // If there are suggestions, add them in...
        $suggestions = pspell_suggest($pspell_link, $check_word[0]);
        if (!empty($suggestions)) {
            $context['spell_js'] .= '"' . join('", "', $suggestions) . '"';
        }
        $context['spell_js'] .= ']),';
    }
    // If words were found, take off the last comma.
    if ($found_words) {
        $context['spell_js'] = substr($context['spell_js'], 0, -1);
    }
    $context['spell_js'] .= '
		);';
    // And instruct the template system to just show the spellcheck sub template.
    $context['template_layers'] = array();
    $context['sub_template'] = 'spellcheck';
}