コード例 #1
0
 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());
     }
 }
コード例 #2
0
ファイル: spellchecker.php プロジェクト: ASDAFF/entask.ru
	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);
		}
	}
コード例 #3
0
 /**
  * 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();
 }
コード例 #4
0
 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);
 }
コード例 #5
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');
 }
コード例 #6
0
ファイル: pspell.php プロジェクト: romuland/khparts
 /**
  * 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;
 }
コード例 #7
0
 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);
     }
     pspell_config_personal($link, "classes/spellchecker/dict/" . $this->langcode . ".pws");
     $this->resid = @pspell_new_config($link);
     if (!$this->resid) {
         $this->errormsg = 'Could not open dictionary "' . $this->langcode . '"';
     }
 }
コード例 #8
0
ファイル: spelling.php プロジェクト: SandyS1/presentations
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";
            }
    }
}
コード例 #9
0
ファイル: easyspell.php プロジェクト: suratpyari/blogging_app
	
	
	$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;
コード例 #10
0
 # include_once("../../LocalSettings.php");
 header('Content-Type: text/xml');
 if (isset($_POST["document"])) {
     $document = $_POST["document"];
 }
 #    error_log(print_r($_POST, true));
 if (get_magic_quotes_gpc()) {
     $document = stripslashes($document);
 }
 $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) {
コード例 #11
0
/**
 * 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);
}
コード例 #12
0
ファイル: SpellCheck.php プロジェクト: hugcoday/wiki
 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;
 }
コード例 #13
0
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;
}
コード例 #14
0
* Free Software Foundation; either version 2 of the License, or 
* (at your option) any later version.
***************************************************************************/
require './GLOBALS.php';
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 
コード例 #15
0
$allowed_html = '<strong><small><p><br><a href><b><u><i><img src,alt,width,height><code><ul><ol><li>';
$usePersonalDict = true;
//set to false if you don't want to use a personal dictionary.
//if pspell doesn't exist, then include the pspell wrapper for aspell
if (!function_exists('pspell_suggest')) {
    define('ASPELL_BIN', '/path/to/aspell');
    //set path to aspell if you need to and uncomment this line
    require_once "pspell_comp.php";
}
//these four lines create and configure a link to the pspell module
$path_to_personal_dictionary = "personal_dictionary/personal_dictionary.txt";
// custom dictionary file
$pspell_config = pspell_config_create("en");
pspell_config_mode($pspell_config, PSPELL_FAST);
if ($usePersonalDict) {
    pspell_config_personal($pspell_config, $path_to_personal_dictionary);
    // allows the use of a custom dictionary (Thanks to Dylan Thurston for this addition).
}
$pspell_link = pspell_new_config($pspell_config);
require_once "cpaint2.inc.php";
//AJAX library file
$cp = new cpaint();
$cp->register('showSuggestions');
$cp->register('spellCheck');
$cp->register('switchText');
$cp->register('addWord');
$cp->start();
$cp->return_data();
/*************************************************************
 * showSuggestions($word, $id)
 *
コード例 #16
0
 * @package queXC
 * @subpackage functions
 * @link http://www.deakin.edu.au/dcarf/ queXC was writen for DCARF - Deakin Computer Assisted Research Facility
 * @license http://opensource.org/licenses/agpl-v3.html The GNU Affero General Public License (AGPL) Version 3
 * 
 */
/**
 * Configuration file
 */
include_once dirname(__FILE__) . '/../config.inc.php';
/**
 * Spell checking needs to be global or memory leak occurs
 */
$pspell_config = pspell_config_create(SPELL_LANGUAGE, SPELL_SPELLING);
pspell_config_mode($pspell_config, PSPELL_FAST);
pspell_config_personal($pspell_config, SPELL_DICTIONARY_FILE);
$pspell_link = pspell_new_config($pspell_config);
/**
 * 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);
}
/**
 * Check an entire string