/** * Add a word to the default dictionary * * @param string $word The word to add to the dictionary */ function add_to_dictionary($word) { global $pspell_link; pspell_add_to_personal($pspell_link, $word); //save additions pspell_save_wordlist($pspell_link); }
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()); } }
/** * Add a word to the PSPell personal dictionary * From http://slack5.com/blog/2008/12/tinymce-add-to-dictionary/ * @param object $lang * @param object $word * @return */ function &addToDictionary($lang, $word) { $plink = $this->_getPLink($lang); pspell_add_to_personal($plink, $word); pspell_save_wordlist($plink); return true; }
public function add_to_dictionary() { $pspell_config = pspell_config_create('en'); pspell_config_personal($pspell_config, $this->pspell_personal_dictionary) or die('can\'t find pspell dictionary'); $this->pspell_link = pspell_new_config($pspell_config); pspell_add_to_personal($this->pspell_link, strtolower($addtodictionary)) or die('You can\'t add a word to the dictionary that contains any punctuation.'); pspell_save_wordlist($this->pspell_link); $this->send_data('success'); }
function add($word) { if (is_string($word)) { pspell_add_to_personal($this->resid, $word); } if (is_array($word)) { foreach ($word as $w) { pspell_add_to_personal($this->resid, $w); } } return pspell_save_wordlist($this->resid); }
function make_page_lookup_dict($dir) { $old_dir = chdir($dir); // generate dictionary key $key = md5($dir); // create dictionary where the spelling alternatives will be stored $ps = pspell_config_create("en"); pspell_config_personal($ps, "./{$key}.pws"); $pl = pspell_new_config($ps); // fetch all files inside the directory $files = glob("*"); // open db for URL storage $db = new sqlite_db("./typos.sqlite"); $db->query("CREATE TABLE typo (url, key)"); // append names to dictionary foreach ($files as $file) { if (preg_match('!^([A-Za-z]+)!', $file, $match)) { pspell_add_to_personal($pl, $match[1]); $db->query("INSERT INTO typo (url, key)\n\t\t\t\tVALUES(\n\t\t\t\t '" . sqlite_escape_string($dir . "/" . $file) . "',\n\t\t\t\t '" . sqlite_escape_string($match[0]) . "')\n\t\t\t\t"); } } // save dictionary pspell_save_wordlist($pl); }
/** * Do aSpell dictionary save * * @param mixed aSpell call command * @param string Temporary file name */ function aspell_save($aspellcommand, $temptext) { $to_p_dict = isset($_REQUEST['to_p_dict']) ? is_array($_REQUEST['to_p_dict']) ? $_REQUEST['to_p_dict'] : explode(',', $_REQUEST['to_p_dict']) : array(); // List of words to add to personal dictionary. $to_r_list = isset($_REQUEST['to_r_list']) ? is_array($_REQUEST['to_r_list']) ? $_REQUEST['to_r_list'] : explode(',', $_REQUEST['to_r_list']) : array(); // List of words to add to replacement list. ob_start(); //print_r($to_r_list); if (count($to_p_dict) > 0 || count($to_r_list) > 0) { if (!is_integer($aspellcommand)) { $fh = fopen($temptext, 'wb'); if ($fh !== false) { foreach ($to_p_dict as $personal_word) { $cmd = '&' . $personal_word . "\n"; //echo $cmd; fwrite($fh, $cmd, strlen($cmd)); } foreach ($to_r_list as $replace_pair) { $cmd = '$$ra ' . $replace_pair[0] . ' , ' . $replace_pair[1] . "\n"; //echo $cmd; fwrite($fh, $cmd, strlen($cmd)); } $cmd = "#\n"; //echo $cmd; fwrite($fh, $cmd, strlen($cmd)); fclose($fh); } else { exit("Can't Write"); } //echo $aspellcommand."\n"; /*echo */ wrap_exec($aspellcommand . ' 2>&1'); } else { foreach ($to_p_dict as $personal_word) { pspell_add_to_personal($aspellcommand, $personal_word); } foreach ($to_r_list as $replace_pair) { pspell_store_replacement($aspellcommand, $replace_pair[0], $replace_pair[1]); } pspell_save_wordlist($aspellcommand); } } }
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; }
static function batchAddWordsToDictionary() { $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select(self::WHITELIST_TABLE, '*', array(self::ACTIVE_FIELD => 0), __METHOD__); $words = array(); while ($row = $dbr->fetchObject($res)) { $words[] = $row; } if (count($words) <= 0) { return; } $dbw = wfGetDB(DB_MASTER); $pspell = self::getLibrary(); if (count($words)) { echo "Adding to whitelist: "; } foreach ($words as $wordRow) { $word = $wordRow->{self::WORD_FIELD}; //check to see if its an ALL CAPS word if (!preg_match('@[^A-Z]@', $word)) { $dbw->insert(self::CAPS_TABLE, array('sc_word' => $word, 'sc_user' => $wordRow->{self::USER_FIELD}), __METHOD__, "IGNORE"); $dbw->delete(self::WHITELIST_TABLE, array(self::WORD_FIELD => $word), __FUNCTION__); } else { pspell_add_to_personal($pspell, $word); } echo $word . ","; //now go through and check articles that contain that word. $sql = "SELECT * FROM `" . self::WORD_TABLE . "` JOIN `spellchecker_page` ON `sp_word` = `sw_id` WHERE sw_word = " . $dbr->addQuotes($word); $res = $dbr->query($sql, __METHOD__); while ($row = $dbr->fetchObject($res)) { $page_id = $row->sp_page; $dbw->update('spellchecker', array('sc_dirty' => "1"), array('sc_page' => $page_id), __METHOD__); } } echo "\n"; if (pspell_save_wordlist($pspell)) { foreach ($words as $wordRow) { $word = $wordRow->{self::WORD_FIELD}; $dbw->update(self::WHITELIST_TABLE, array(self::ACTIVE_FIELD => 1), array(self::WORD_FIELD => $word), __METHOD__); } } else { mail('*****@*****.**', 'spellchecker error', 'Unable to save new words to the spellchecker whitelist.'); } }
function addWord($word = '') { //pspell if ($this->pspell) { if (!pspell_add_to_personal($this->pspell_link, $word) || !pspell_save_wordlist($this->pspell_link)) { return false; } } //custom // elseif($this->custom_spell) // { // if ($this->lang == 'ru') // { // $word = $APPLICATION->ConvertCharset($word, "UTF-8", "Windows-1251"); // } // $path = $this->dic_path.'/dics/'.$this->lang.'_'; // // $letter = $this->codeLetter(strtolower($word{0})); // $path .= $letter.'.dic'; // if (!$handle = fopen($path, 'a')) // return false; // if (fwrite($handle, $word."\n") === FALSE) // return false; // fclose($handle); // return true; // } }
fud_egw(); if (!($FUD_OPT_1 & 2097152)) { exit("Cannot use this control panel, your forum's spell checker is disabled."); } fud_use('adm.inc', true); fud_use('widgets.inc', true); $status = 0; if (!empty($_POST['words'])) { $wl = explode("\n", trim($_POST['words'])); if (count($wl)) { $pspell_config = pspell_config_create($usr->pspell_lang); pspell_config_personal($pspell_config, $FORUM_SETTINGS_PATH . "forum.pws"); $pspell_link = pspell_new_config($pspell_config); foreach ($wl as $w) { if ($w = trim($w)) { pspell_add_to_personal($pspell_link, $w); pspell_save_wordlist($pspell_link); ++$status; } } } } require $WWW_ROOT_DISK . 'adm/admpanel.php'; ?> <h2>Custom Dictionary Spell Checker</h2> <form method="post" name="spell" action="admspell.php"> <?php echo _hs; if ($status) { echo '<div style="text-align: center; color: green; font-size: 125%">' . $status . ' word(s) were added successfully.</div>'; }
function addWord($word) { //pspell if ($this->pspell) { if ($this->lang == 'ru') { $word = convertCharsetInKOI8($word); } if (!pspell_add_to_personal($this->pspell_link, $word)) { return false; } if (!pspell_save_wordlist($this->pspell_link)) { return false; } //custom } elseif ($this->custom_spell) { if ($this->lang == 'ru') { $word = convertCharsetInWIN1251($word); } $path = $this->dic_path . '/dics/' . $this->lang . '_'; $letter = $this->codeLetter(string_lower($word[0])); $path .= $letter . '.dic'; if (!($handle = fopen($path, 'a'))) { return false; } if (fwrite($handle, $word . "\n") === FALSE) { return false; } fclose($handle); return true; } }
# define( 'MEDIAWIKI', true ); # include_once("../../LocalSettings.php"); header('Content-Type: text/xml'); if (isset($_POST["word"])) { $word = $_POST["word"]; } # error_log("words is " . $word . "."); if (get_magic_quotes_gpc()) { $word = stripslashes($word); } # myLog(" **- user: "******" **- language: " . $wgUser->getOption( 'language' )); $spellcheckext_language = "" . $wgUser->getOption('language'); $pspell_config = pspell_config_create($spellcheckext_language); global $personalDictionaryLocation, $pspell_data_dir, $pspell_dict_dir; pspell_config_personal($pspell_config, $personalDictionaryLocation . "_" . $spellcheckext_language); if (strcmp($pspell_data_dir, "") != 0) { pspell_config_data_dir($pspell_config, $pspell_data_dir); } if (strcmp($pspell_dict_dir, "") != 0) { pspell_config_dict_dir($pspell_config, $pspell_dict_dir); } $pspell_link = pspell_new_config($pspell_config); // $word might have to be checked more carefully since it comes from the user. // I am counting on pspell to sanitize it $ret = "add return value is " . pspell_add_to_personal($pspell_link, $word); $ret .= " save retval is " . pspell_save_wordlist($pspell_link); $xmlFile = "<spellcheck>" . $ret . "</spellcheck>"; error_log($xmlFile); print $xmlFile; }
function addWord($str) { global $editablePersonalDict; global $pspell_link; //the global link to the pspell module $retVal = ""; pspell_add_to_personal($pspell_link, $str); if ($editablePersonalDict && pspell_save_wordlist($pspell_link)) { $retVal = 1; } else { $retVal = 0; } echo $retVal; }
foreach($htmlitems as $item) { if(strpos($item, "<")===false) { $wordarray=preg_split('/[\W]+?/', $item); foreach($wordarray as $worditem) { if($worditem!=""&&$worditem!=" "&&$worditem!="nbsp") $words[]=$worditem; } } } $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; } }
function addWord($str) { global $editablePersonalDict; global $allowCustomInserts; global $pspell_link; //the global link to the pspell module global $cp; //the CPAINT object $retVal = ""; pspell_add_to_personal($pspell_link, $str); if ($editablePersonalDict && pspell_save_wordlist($pspell_link)) { $retVal = "Save successful!"; } else { $retVal = "Save Failed!"; } $cp->set_data($retVal); }
/** * Adds a word to the personal wordlist * * @param string $word the word to add to the list. * * @throws NateGoSearchException if no personal wordlist is set for this * spell checker or if the word does not * contain at least one alphabetic character. */ public function addToPersonalWordList($word) { if ($this->personal_wordlist == '') { throw new NateGoSearchException(sprintf("The word '%s' cannot " . "be added to the personal wordlist because no personal " . "wordlist is set.", $word)); } // make sure word contains a letter $word_regexp = '/\\pL/u'; if (preg_match($word_regexp, $word) === 0) { throw new NateGoSearchException(sprintf("The word '%s' cannot " . "be added to the custom wordlist because it contains no " . "alphabetic characters.", $word)); } pspell_add_to_personal($this->dictionary, $word); pspell_save_wordlist($this->dictionary); // update permissions (-rw-rw----) if (fileowner($this->personal_wordlist) == posix_getuid()) { chmod($this->personal_wordlist, 0660); } }