5 // . security fix on unchecked variables. Original author missed quite a few
9 $temptext = tempnam('/tmp', 'spell_');
10 if ((!isset($_POST['dictionary'])) ||
(strlen(trim($_POST['dictionary'])) < 1))
16 $lang = $_POST['dictionary'];
18 $lang = preg_replace('/[^a-z0-9_]/i', '', $lang);
21 $aspell_args = '-a --lang=' . $lang;
23 if(DIRECTORY_SEPARATOR
== '\\') //windows
25 $aspell = 'C:\Progra~1\Aspell\bin\aspell.exe';
29 // See if there is a local install of aspell here
30 if(file_exists(dirname(__FILE__
) . '/aspell/bin/aspell'))
32 putenv('PATH=' . dirname(__FILE__
) . '/aspell/bin:' . getenv('PATH'));
33 putenv('LD_LIBRARY_PATH=' . dirname(__FILE__
) . '/aspell/lib:' . getenv('LD_LIBRARY_PATH'));
34 $dicfil = dirname(__FILE__
) .'/aspell/lib/' . preg_replace('/^.*\/lib\/(aspell\S*)\n.*/s', '$1', `aspell config dict
-dir`
);
35 $aspell_args .= ' --dict-dir=' . $dicfil . ' --add-filter-path=' . $dicfil ;
40 // Old aspell doesn't know about encoding, which means that unicode will be broke, but
41 // we should at least let it try.
42 preg_match('/really aspell ([0-9]+)\.([0-9]+)(?:\.([0-9]+))?/i', `
$aspell version`
, $aVer);
44 $aVer = array('major' => (int)$aVer[1], 'minor' => (int)$aVer[2], 'release' => (int)@$aVer[3]);
45 if($aVer['major'] >= 0 && $aVer['minor'] >= 60)
47 $aspell_args .= ' -H --encoding=utf-8';
49 elseif(preg_match('/--encoding/', shell_exec('aspell 2>&1')))
51 $aspell_args .= ' --mode=none --add-filter=sgml --encoding=utf-8';
55 $aspell_args .= ' --mode=none --add-filter=sgml';
58 // Personal dictionaries
59 $p_dicts_path = dirname(__FILE__
) . DIRECTORY_SEPARATOR
. 'personal_dicts';
61 if(isset($_REQUEST['p_dicts_path']) && file_exists($_REQUEST['p_dicts_path']) && is_writable($_REQUEST['p_dicts_path']))
63 if(!isset($_REQUEST['p_dicts_name']))
65 if(isset($_COOKIE['SpellChecker_p_dicts_name']))
67 $_REQUEST['p_dicts_name'] = $_COOKIE['SpellChecker_p_dicts_name'];
71 $_REQUEST['p_dicts_name'] = uniqid('dict');
72 setcookie('SpellChecker_p_dicts_name', $_REQUEST['p_dicts_name'], time() +
60*60*24*365*10);
75 $p_dict_path = $_REQUEST['p_dicts_path'] . DIRECTORY_SEPARATOR
. preg_replace('/[^a-z0-9_]/i', '', $_REQUEST['p_dicts_name']);
77 if(!file_exists($p_dict_path))
79 // since there is a single directory for all users this could end up containing
80 // quite a few subdirectories. To prevent a DOS situation we'll limit the
81 // total directories created to 2000 (arbitrary). Adjust to suit your installation.
85 if( $dir = @opendir
( $p_dicts_path ) )
88 while( FALSE !== ($file = readdir($dir)) )
94 // TODO: make this a config value.
99 // either very heavy use or a DOS attempt
106 chmod($p_dict_path, 02770);
109 if(file_exists($p_dict_path) && is_writable($p_dict_path))
112 $aspell_args .= ' --home-dir=' . $p_dict_path ;
116 // as an additional precaution check the aspell_args for illegal
118 $aspell_args = preg_replace( "/[|><;\$]+/", '', $aspell_args );
119 $aspelldictionaries = "$aspell dump dicts";
120 $aspellcommand = "$aspell $aspell_args < $temptext";