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());
     }
 }
Beispiel #2
0
	public function __construct($params)
	{
		$this->lang = (isset($params["lang"]) && $params["lang"] != '') ? $params["lang"] : 'en';
		$this->skip_len = $params["skip_length"];

		$this->pspell = (function_exists('pspell_config_create') && ($params["use_pspell"] == "Y"));
		//$this->custom_spell = $params["use_custom_spell"] == "Y";
		$this->custom_spell = false;
		$this->pspell_mode = $params["mode"];

		$this->dics_path = $this->checkDicPath();
		$this->user_dics_path = $this->dics_path."/custom.pws";
		$this->custom_dics_path = $this->dics_path.'/custom_dics/'.$this->lang.'_';

		if($this->custom_spell)
		{
			$this->dic = array();
		}

		if ($this->pspell)
		{
			$pspell_config = pspell_config_create ($this->lang, null, null, 'utf-8');
			pspell_config_ignore($pspell_config, $this->skip_len);
			pspell_config_mode($pspell_config, $params["mode"]);
			pspell_config_personal($pspell_config, $this->user_dics_path);
			$this->pspell_link = pspell_new_config($pspell_config);
		}
	}
 function pspellConfig()
 {
     $pspell_config = pspell_config_create($this->lang);
     pspell_config_ignore($pspell_config, $this->skip_len);
     pspell_config_mode($pspell_config, $this->mode);
     pspell_config_personal($pspell_config, $this->personal_path);
     $this->pspell_link = pspell_new_config($pspell_config);
 }
Beispiel #4
0
 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');
 }
Beispiel #5
0
 private function loadReplacements()
 {
     $path = $this->language_path . $this->language . ".repl";
     if (file_exists($path)) {
         //echo file_get_contents($path);
         $this->pspell_config = pspell_config_create($this->language);
         pspell_config_repl($this->pspell_config, $path);
         $this->pspell = pspell_new_config($this->pspell_config);
     }
 }
Beispiel #6
0
 /**
  * Opens a link for pspell.
  */
 function &_getPLink($lang)
 {
     // Check for native PSpell support
     if (!function_exists("pspell_new")) {
         $this->throwError("PSpell support not found in PHP installation.");
     }
     $pspell_config = pspell_config_create($lang, $this->_config['PSpell.spelling'], $this->_config['PSpell.jargon'], $this->_config['PSpell.encoding']);
     pspell_config_personal($pspell_config, $this->_config['PSpell.dictionary']);
     $plink = pspell_new_config($pspell_config);
     if (!$plink) {
         $this->throwError("No PSpell link found opened.");
     }
     return $plink;
 }
 function init()
 {
     $link = pspell_config_create($this->langcode);
     pspell_config_ignore($link, $this->ignore);
     if ($this->modus == 0) {
         pspell_config_mode($link, PSPELL_FAST);
     } elseif ($this->modus == 2) {
         pspell_config_mode($link, PSPELL_BAD_SPELLERS);
     } else {
         pspell_config_mode($link, PSPELL_NORMAL);
     }
     $this->resid = @pspell_new_config($link);
     if (!$this->resid) {
         $this->errormsg = 'Could not open dictionary "' . $this->langcode . '"';
     }
 }
Beispiel #8
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;
}
Beispiel #9
0
 public static function GetSpellSuggestionsWithPspell($strText, $strSpellLang)
 {
     if (!function_exists('pspell_new')) {
         return true;
     }
     if (file_exists(__DICTIONARY_PATH__ . '/' . $strSpellLang . '.dat')) {
         if (!defined('PSPELL_FAST')) {
             return self::GetSpellSuggestionsWithHunspell($strText, $strSpellLang);
         }
         if (!($pspell_config = pspell_config_create($strSpellLang, null, null, 'utf-8'))) {
             return self::GetSpellSuggestionsWithHunspell($strText, $strSpellLang);
         }
         if (!pspell_config_data_dir($pspell_config, __DICTIONARY_PATH__)) {
             return self::GetSpellSuggestionsWithHunspell($strText, $strSpellLang);
         }
         if (!pspell_config_dict_dir($pspell_config, __DICTIONARY_PATH__)) {
             return self::GetSpellSuggestionsWithHunspell($strText, $strSpellLang);
         }
         if (!($pspell_link = @pspell_new_config($pspell_config))) {
             return self::GetSpellSuggestionsWithHunspell($strText, $strSpellLang);
         }
     } else {
         if (file_exists('/usr/lib/aspell-0.60/' . $strSpellLang . '.dat')) {
             $strDictPath = '/usr/lib/aspell-0.60/';
             $pspell_link = pspell_new($strSpellLang, null, null, 'utf-8');
         } elseif (file_exists('/usr/lib64/aspell-0.60/' . $strSpellLang . '.dat')) {
             $strDictPath = '/usr/lib64/aspell-0.60/';
             $pspell_link = pspell_new($strSpellLang, null, null, 'utf-8');
         } else {
             return self::GetSpellSuggestionsWithHunspell($strText, $strSpellLang);
         }
     }
     $arrSuggestions = array();
     $arrCleanText = mb_split('\\s+', $strText);
     foreach ($arrCleanText as $strCleanText) {
         if (!pspell_check($pspell_link, trim($strCleanText))) {
             $suggestions = pspell_suggest($pspell_link, trim($strCleanText));
             if (in_array($strCleanText, $suggestions)) {
                 continue;
             }
             $arrSuggestions[$strCleanText] = array_slice($suggestions, 0, 3);
         }
     }
     return $arrSuggestions;
 }
Beispiel #10
0
function find_my_page()
{
    // get the name of the 'missing' file
    $page = basename($_SERVER['REDIRECT_URL']);
    // used to pick the correct dictionary
    $dir = dirname($_SERVER['REDIRECT_URL']);
    $key = md5($dir);
    // load spelling dictionaries
    $ps = pspell_config_create("en");
    pspell_config_personal($ps, "./{$key}.pws");
    $pl = pspell_new_config($ps);
    // find alternatives
    $alt = pspell_suggest($pl, $page);
    if (!$alt) {
        // no matches, no choice but to show site map
        display_site_map();
        return;
    }
    // escape data for sqlite
    foreach ($alt as $key => $file) {
        $alt[$key] = sqlite_escape_string($file);
    }
    // fetch all matching pages;
    $db = new sqlite_db("./typos.sqlite");
    $alt = $db->single_query("SELECT url FROM typo WHERE key IN('" . implode("','", $alt) . "')");
    switch (@count($alt)) {
        case 1:
            // if only one suggestion is avaliable redirect the user to that page
            header("Location: {$alt[0]}");
            return;
            break;
        case 0:
            // no matches, no choice but to show site map
            display_site_map();
            break;
        default:
            // show the user possible alternatives if >1 is found
            echo "The page you requested, '{$_SERVER['REDIRECT_URL']}' cannot be found.<br />\nDid you mean:\n";
            foreach ($alt as $url) {
                echo "&nbsp;&nbsp;<a href='{$url}'>{$url}</a><br />\n";
            }
    }
}
/**
 * Initialise our aSpell calling environment.
 *
 * @return array			A tuple of environmental details (dictionary list,aspell call command,temporary file name,language being used)
 */
function aspell_init()
{
    // Find the language
    if (!isset($_REQUEST['dictionary']) || strlen(trim($_REQUEST['dictionary'])) < 1) {
        $lang = function_exists('do_lang') ? do_lang('dictionary') : 'en_GB';
        // Default to UK English (as per ocPortal)
    } else {
        $lang = $_REQUEST['dictionary'];
    }
    $aspellcommand = mixed();
    $force_shell = false;
    if (!function_exists('pspell_check') || $force_shell) {
        if (str_replace(array('on', 'true', 'yes'), array('1', '1', '1'), strtolower(ini_get('safe_mode'))) == '1') {
            exit('Spell Checker does not work with safe mode systems that do not have direct pspell support into PHP');
        }
        if (strpos(@ini_get('disable_functions'), 'shell_exec') !== false) {
            exit('Spell Checker does not work on systems with shell_exec disabled that do not have direct pspell support into PHP');
        }
        // Our temporary spell check file
        $temptext = tempnam(str_replace(array('on', 'true', 'yes'), array('1', '1', '1'), strtolower(ini_get('safe_mode'))) == '1' || @strval(ini_get('open_basedir')) != '' && preg_match('#(^|:|;)/tmp($|:|;|/)#', ini_get('open_basedir')) == 0 ? get_custom_file_base() . '/safe_mode_temp/' : '/tmp/', 'spell_');
        if ($temptext === false) {
            $temptext = tempnam(get_custom_file_base() . '/safe_mode_temp/', 'spell_');
        }
        // Find aspell
        $aspell = 'aspell';
        $aspell_args = '-a --lang=' . _filter_naughty_harsh($lang);
        if (DIRECTORY_SEPARATOR == '\\') {
            // See if there is a local install of aspell here
            if (file_exists(dirname(__FILE__) . '\\aspell\\bin\\aspell.exe')) {
                $aspell = dirname(__FILE__) . '\\aspell\\bin\\aspell.exe';
                if (file_exists(dirname(__FILE__) . '\\aspell\\bin\\aspell_wrap.exe')) {
                    $aspell = dirname(__FILE__) . '\\aspell\\bin\\aspell_wrap.exe ' . dirname(__FILE__) . '\\aspell\\bin\\';
                }
                //$dic_dir=wrap_exec($aspell.' config dict-dir');
                //$dicfil=preg_replace('/^.*\/lib\/(aspell\S*)\n.*/s','$1',$dic_dir);
                //$aspell_args.=' --dict-dir='.$dicfil;
            } else {
                $aspell = 'C:\\Progra~1\\Aspell\\bin\\aspell.exe';
            }
            if (!file_exists($aspell)) {
                exit('ASpell not installed in default locations.');
            }
            $aspell_version = wrap_exec($aspell . ' version');
        } else {
            // See if there is a local install of aspell here
            if (file_exists(dirname(__FILE__) . '/aspell/bin/aspell')) {
                putenv('PATH=' . dirname(__FILE__) . '/aspell/bin:' . getenv('PATH'));
                putenv('LD_LIBRARY_PATH=' . dirname(__FILE__) . '/aspell/lib:' . getenv('LD_LIBRARY_PATH'));
                //$dic_dir=wrap_exec($aspell.' config dict-dir');
                //$dicfil=dirname(__FILE__).'/aspell/lib/'.preg_replace('/^.*\/lib\/(aspell\S*)\n.*/s','$1',$dic_dir);
                //$aspell_args.=' --dict-dir='.$dicfil.' --add-filter-path='.$dicfil;
            }
            $aspell_version = wrap_exec($aspell . ' version');
        }
        if ($aspell_version === false) {
            exit('ASpell would not execute. It is most likely not installed, or a security measure is in place, or file permissions are not correctly set. If on Windows, you may need to give windows\\system32\\cmd.exe execute permissions to the web user.');
        }
        // Old aspell doesn't know about encoding, which means that unicode will be broke, but we should at least let it try.
        $a_ver = array();
        preg_match('/really [aA]spell ([0-9]+)\\.([0-9]+)(?:\\.([0-9]+))?/i', $aspell_version, $a_ver);
        if (!array_key_exists(1, $a_ver)) {
            $a_ver[1] = '1';
        }
        if (!array_key_exists(2, $a_ver)) {
            $a_ver[2] = '0';
        }
        if (!array_key_exists(3, $a_ver)) {
            $a_ver[3] = '0';
        }
        $a_ver = array('major' => (int) $a_ver[1], 'minor' => (int) $a_ver[2], 'release' => (int) $a_ver[3]);
        if ($a_ver['major'] >= 0 && $a_ver['minor'] >= 60) {
            $aspell_args .= ' -H --encoding=utf-8';
        } elseif (preg_match('/--encoding/', wrap_exec($aspell . ' 2>&1')) != 0) {
            $aspell_args .= ' --mode=none --add-filter=sgml --encoding=utf-8';
        } else {
            $aspell_args .= ' --mode=none --add-filter=sgml';
        }
        $aspelldictionaries = $aspell . ' dump dicts';
        $aspellcommand = $aspell . ' ' . $aspell_args . ' < ' . $temptext;
    } else {
        //list($lang,$spelling)=explode('_',$lang);
        $spelling = '';
        $temptext = NULL;
        $aspelldictionaries = NULL;
    }
    // Personal dictionaries
    global $SITE_INFO;
    if (!isset($SITE_INFO)) {
        require_once '../../../../info.php';
    }
    $cookie_member_id = $SITE_INFO['user_cookie'];
    $p_dicts_name = array_key_exists($cookie_member_id, $_COOKIE) ? _filter_naughty_harsh($_COOKIE[$cookie_member_id]) : 'guest';
    $p_dict_path = get_custom_file_base() . '/data_custom/spelling/personal_dicts' . DIRECTORY_SEPARATOR . $p_dicts_name;
    if (!file_exists($p_dict_path)) {
        mkdir($p_dict_path, 02770);
    }
    if (is_null($temptext)) {
        list($lang_stub, ) = explode('_', $lang);
        $charset = str_replace('ISO-', 'iso', str_replace('iso-', 'iso', do_lang('charset')));
        if (DIRECTORY_SEPARATOR == '\\') {
            $aspellcommand = @pspell_new_personal($p_dict_path . '/' . $lang_stub . '.pws', $lang, $spelling, '', $charset);
            if ($aspellcommand === false) {
                $aspellcommand = pspell_new_personal($p_dict_path . '/' . $lang_stub . '.pws', $lang, $spelling, '', $charset);
            }
        } else {
            $aspellconfig = @pspell_config_create($lang, $spelling, '', $charset);
            if ($aspellconfig === false) {
                $aspellconfig = pspell_config_create('en', $spelling, '', $charset);
            }
            pspell_config_personal($aspellconfig, $p_dict_path . '/' . $lang_stub . '.pws');
            pspell_config_repl($aspellconfig, $p_dict_path . '/' . $lang_stub . '.prepl');
            $aspellcommand = @pspell_new_config($aspellconfig);
            if ($aspellcommand === false && $lang != 'en') {
                $aspellconfig = pspell_config_create('en', $spelling, '', $charset);
                pspell_config_personal($aspellconfig, $p_dict_path . '/' . $lang_stub . '.pws');
                pspell_config_repl($aspellconfig, $p_dict_path . '/' . $lang_stub . '.prepl');
                $aspellcommand = pspell_new_config($aspellconfig);
            }
        }
        if (is_null($aspellcommand)) {
            exit;
        }
    }
    return array($aspelldictionaries, $aspellcommand, $temptext, $lang);
}
 }
 $words = split(" ", $document);
 # 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);
     error_log("setting the spellcheck data dir to " . $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);
 $words = array_unique($words);
 $ret = "";
 foreach ($words as $word) {
     if (!is_numeric($word) && !pspell_check($pspell_link, $word)) {
         $suggestions = pspell_suggest($pspell_link, "{$word}");
         $formattedSuggestion = '';
         foreach ($suggestions as $suggestion) {
             $formattedSuggestion .= "<suggest>{$suggestion}</suggest>";
         }
         $ret .= "<suggestion><word>{$word}</word>" . $formattedSuggestion . "</suggestion>";
     }
 }
 $xmlFile = "<spellcheck>" . $ret . "</spellcheck>";
 #error_log($xmlFile);
 print $xmlFile;
Beispiel #13
0
 /**
  * Konstrukor zapewniaj±cy ogóln± inicjalizacjê systemu przygotowywania danych:
  * tokenizer, korekta ortograficzna, uzupe³nianie polskich znaków, wulgaryzmy.
  *
  * @param mysqli $dbconn Obiekt po³±czenia z baz± danych u¿ywany w podklasach.
  * @param string $dictdir Folder ze s³ownikami, stoplistami itp.
  * @param int $idc Identyfikator wykorzystywanego zestawu komentarzy.
  * @param bool $copy_unknown Czy pozostawiaæ nierozpoznane wyrazy?
  * @param array $options Parametry konkretnego klasyfikatora jako tab. asocjacyjna.
  */
 function __construct($dbconn, $dictdir, $idc, $copy_unknown, $options = null)
 {
     $this->idc = $idc;
     $this->copy_unknown = $copy_unknown;
     $this->dbconn = $dbconn;
     if (is_null(self::$validation)) {
         self::$validation = new Validation($dictdir . '/vulgarism.txt');
     }
     if (is_null(self::$tokenizer)) {
         self::$tokenizer = new Tokenizer($dictdir . '/stoplist.txt');
     }
     if (is_null(self::$fsaa)) {
         self::$fsaa = new Fsaa($dictdir . '/lort_acc_full.fsa');
     }
     if (is_null(self::$fsal)) {
         self::$fsal = new Fsal($dictdir . '/llems_full.fsa');
     }
     if (is_null(self::$pspell)) {
         $pspell_config = pspell_config_create("pl");
         // opcje zapewniaj±ce wiêksz± szybko¶æ dzia³ania aspell
         pspell_config_ignore($pspell_config, 4);
         pspell_config_mode($pspell_config, PSPELL_FAST);
         pspell_config_runtogether($pspell_config, false);
         self::$pspell = pspell_new_config($pspell_config);
     }
 }
function parseStringP($txt, $dialects)
{
    global $errorstring, $parameters;
    $dialect = "british";
    if (isset($dialects[1]) && $dialects[1] != "") {
        $dialect = $dialects[1];
        $lang = $dialects[0];
    }
    //pspell parse initialisation
    //$psp_conf = pspell_config_create ("en", $dialect);
    $psp_conf = pspell_config_create($lang);
    pspell_config_runtogether($psp_conf, false);
    pspell_config_mode($psp_conf, PSPELL_NORMAL);
    $psp = pspell_new_config($psp_conf);
    //join the string so that it is easier to parse - does not matter when formatting because it is html
    $txt = str_replace("\r\n", " ", $txt);
    $txt = str_replace("\r", " ", $txt);
    $txt = str_replace("\n", " ", $txt);
    $jstext = "";
    $jsarrindex = 0;
    //split string by html tags
    $regexp = "#(<[^>]*>)#";
    $arr = preg_split($regexp, $txt, -1, PREG_SPLIT_OFFSET_CAPTURE | PREG_SPLIT_DELIM_CAPTURE);
    foreach ($arr as $comp) {
        $arr2[] = $comp[0];
    }
    //we now have the $arr2 - containing html tags and plain text portions
    for ($i = 0; $i < count($arr2); $i++) {
        $portion = $arr2[$i];
        //the part
        if (strstr($portion, "<a")) {
            //we have a link
            //$arr2[$i] = str_replace('href', 'href1', $arr2[$i]); //replace so when clicking on the content we do not redirect
        }
        if (!strstr($portion, "<") && $portion != "") {
            //we do not work on html portions and empty text - which should be resolved in the preg_split function
            $portion = str_replace("&nbsp;", " ", $portion);
            //replace for parsing
            //get distinct words from string portion
            $words = explode(" ", $portion);
            $arr2[$i] = $words;
            for ($j = 0; $j < count($arr2[$i]); $j++) {
                $word = $arr2[$i][$j];
                //we check if the "word" is really a word
                $cond = true;
                //is it a link address ?
                if (strstr($word, "http://")) {
                    $cond = false;
                }
                /*
                //is it a number?
                if (preg_match("/^[0-9\.%]*$/", $word)) {
                	$cond = false;
                }
                //does it begin with a capital letter ?
                if (ucwords($word) == $word) {
                	//$cond = false;
                }
                */
                if ($cond) {
                    $regexp3 = "/([^a-zA-Z]*)([a-zA-Z']*)([^a-zA-Z]*)/";
                    //get the actual words - we can have strings like ",something.". We separate in 3 portions
                    preg_match($regexp3, $word, $mt);
                    $beforeword = $mt[1];
                    $inword = $mt[2];
                    if (addedWord($inword)) {
                        continue;
                    }
                    $afterword = $mt[3];
                    if (!pspell_check($psp, $inword)) {
                        $sugs = pspell_suggest($psp, $inword);
                        if (count($sugs) > 0) {
                            //build the option string
                            //$arr2[$i][$j] = $beforeword.'<span onclick="fillOptions(this)" options="'.implode('|', $sugs).'" class="havesuggestion">'.$inword.'</span>'.$afterword;
                            $arr2[$i][$j] = $beforeword . '<span badword=1>' . $inword . '</span>' . $afterword;
                            $jstext .= "\nwords[" . $jsarrindex . "] = new Object();";
                            $jstext .= "\nwords[" . $jsarrindex . "].status = 0;";
                            $jstext .= "\nwords[" . $jsarrindex . "].word = \"" . $word . "\";";
                            $jstext .= "\nwords[" . $jsarrindex . "].suggestions = new Array();";
                            $jsarrindex2 = 0;
                            foreach ($sugs as $suggestion) {
                                $jstext .= "\nwords[" . $jsarrindex . "].suggestions[" . $jsarrindex2 . "] = \"" . str_replace(array("\r", "\n"), array("", ""), $suggestion) . "\";";
                                $jsarrindex2++;
                            }
                            $jsarrindex++;
                        } else {
                            //build the option string with red so that we know there is no replacement
                            //$arr2[$i][$j] = $beforeword.'<span onclick="fillOptions(this)" options="'.implode('|', $sugs).'" class="nosuggestion">'.$inword.'</span>'.$afterword;
                            $arr2[$i][$j] = $beforeword . '<span badword=1>' . $inword . '</span>' . $afterword;
                            $jstext .= "\nwords[" . $jsarrindex . "] = new Object();";
                            $jstext .= "\nwords[" . $jsarrindex . "].status = 0;";
                            $jstext .= "\nwords[" . $jsarrindex . "].word = \"" . $word . "\";";
                            $jstext .= "\nwords[" . $jsarrindex . "].suggestions = new Array();";
                            $jsarrindex2 = 0;
                            foreach ($sugs as $suggestion) {
                                $jstext .= "\nwords[" . $jsarrindex . "].suggestions[" . $jsarrindex2 . "] = \"" . str_replace(array("\r", "\n"), array("", ""), $suggestion) . "\";";
                                $jsarrindex2++;
                            }
                            $jsarrindex++;
                        }
                    }
                }
            }
        }
    }
    //implosion of the parts to reconstitute the string
    $toret = "";
    foreach ($arr2 as $portion) {
        if (is_array($portion)) {
            $toret .= implode(" ", $portion);
        } else {
            $toret .= $portion;
        }
    }
    //$toret = str_replace("\"", "&quot;", $toret);
    return array($toret, $jstext);
}
 static function getLibrary()
 {
     global $IP;
     $pspell_config = pspell_config_create("en", 'american');
     pspell_config_mode($pspell_config, PSPELL_FAST);
     //no longer using the custom dictionary
     //pspell_config_personal($pspell_config, $IP . wikiHowDictionary::DICTIONARY_LOC);
     $pspell_link = pspell_new_config($pspell_config);
     return $pspell_link;
 }
Beispiel #16
0
	
	$words=array();
	$htmlitems = preg_split('/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/',$fieldtext);//"
	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;
Beispiel #17
0
 function pspell_check($text, $lang = false)
 {
     global $charset;
     if ($lang) {
         $lang = $GLOBALS['LANG'];
     }
     $words = preg_split('/[\\W]+?/', $text);
     $misspelled = $return = array();
     $pspell_config = pspell_config_create($lang, "", "", $charset, PSPELL_NORMAL | PSPELL_RUN_TOGETHER);
     //pspell_config_runtogether($pspell_config, true);
     if (PSPELL_PWL) {
         pspell_config_personal($pspell_config, PSPELL_PWL);
     }
     if (PSPELL_REPL) {
         pspell_config_repl($pspell_config, PSPELL_REPL);
     }
     $pspell = pspell_new_config($pspell_config);
     foreach ($words as $value) {
         // SplitPagename $value
         if (!pspell_check($pspell, $value)) {
             $misspelled[] = $value;
         }
     }
     foreach ($misspelled as $value) {
         $return[$value] = pspell_suggest($pspell, $value);
     }
     return $return;
 }
function init_spell($type, $dict)
{
    $pspell_config = pspell_config_create($dict);
    pspell_config_mode($pspell_config, $type);
    pspell_config_personal($pspell_config, $GLOBALS['FORUM_SETTINGS_PATH'] . "forum.pws");
    pspell_config_ignore($pspell_config, 2);
    define('__FUD_PSPELL_LINK__', pspell_new_config($pspell_config));
    return true;
}
 /**
  * Creates a new Pspell spell checker
  *
  * @param string $language the language used by this spell checker. This
  *                          should be a two-letter ISO 639 language code
  *                          followed by an optional two digit ISO 3166
  *                          country code separated by a dash or underscore.
  *                          For example, 'en', 'en-CA' and 'en_CA' are
  *                          valid languages.
  * @param string $personal_wordlist optional. The filename of the personal
  *                                   wordlist for this spell checker. If not
  *                                   specified, no personal wordlist is
  *                                   used. The personal wordlist may contain
  *                                   spellings for words that are correct
  *                                   but are not in the regular dictionary.
  *
  * @throws NateGoSearchException if the Pspell extension is not available.
  * @throws NateGoSearchtException if a dictionary in the specified language
  *                                could not be loaded.
  */
 public function __construct($language, $path_to_data = '', $repl_pairs = '', $personal_wordlist = '')
 {
     if (!extension_loaded('pspell')) {
         throw new NateGoSearchException('The Pspell PHP extension is ' . 'required for NateGoSearchPSpellSpellChecker.');
     }
     $config = pspell_config_create($language, '', '', 'utf-8');
     pspell_config_mode($config, PSPELL_FAST);
     if ($path_to_data != '') {
         pspell_config_data_dir($config, $path_to_data);
         pspell_config_dict_dir($config, $path_to_data);
     }
     if ($repl_pairs != '') {
         pspell_config_repl($config, $repl_pairs);
     }
     if ($personal_wordlist != '') {
         pspell_config_personal($config, $personal_wordlist);
         if (file_exists($personal_wordlist) && fileowner($personal_wordlist) == posix_getuid()) {
             // update permissions (-rw-rw----)
             chmod($personal_wordlist, 0666);
         }
         $this->personal_wordlist = $personal_wordlist;
     }
     $this->dictionary = pspell_new_config($config);
     if ($this->dictionary === false) {
         throw new NateGoSearchException(sprintf("Could not create Pspell dictionary with language '%s'.", $this->language));
     }
     $this->loadBlacklistedSuggestions();
 }