diff -ruN moodle-vanila/config-dist.php moodle/config-dist.php --- moodle-vanila/config-dist.php 2006-09-10 20:25:02.000000000 -0600 +++ moodle/config-dist.php 2007-02-06 14:48:23.000000000 -0700 @@ -287,6 +287,21 @@ // NOTE: if you are using custompix in your theme, see /fixpix.php. //========================================================================= +// ASPELL fixes +//========================================================================= +// Use PHP built-in pspell bindings: +// $CFG->pspell= +// +$CFG->pspell=false; + +// +// Use fixes specific to RedHat AS3 (or other distribution +// running older version of aspell +// $CFG->redhatas3aspellfix= +// +$CFG->redhatas3aspellfix=false; + +//========================================================================= // ALL DONE! To continue installation, visit your main page with a browser //========================================================================= if ($CFG->wwwroot == 'http://example.com/moodle') { @@ -308,6 +323,8 @@ } die; } + + // MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES, // RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE. ?> diff -ruN moodle-vanila/lib/adminlib.php moodle/lib/adminlib.php --- moodle-vanila/lib/adminlib.php 2007-02-05 19:20:04.000000000 -0700 +++ moodle/lib/adminlib.php 2007-02-06 13:27:25.000000000 -0700 @@ -1855,6 +1855,8 @@ } +include_once("speller/server-scripts/aspell_pspell.php"); + class admin_setting_special_editordictionary extends admin_setting_configselect { function admin_setting_special_editordictionary() { @@ -1878,43 +1880,47 @@ // error_reporting(E_ALL); // for debug, final version shouldn't have this... clearstatcache(); - // If aspellpath isn't set don't even bother ;-) - if (empty($CFG->aspellpath)) { - return 'Empty aspell path!'; - } - - // Do we have access to popen function? - if (!function_exists('popen')) { - return 'Popen function disabled!'; - } - - $cmd = $CFG->aspellpath; - $output = ''; - $dictionaries = array(); - $dicts = array(); - - if(!($handle = @popen(escapeshellarg($cmd) .' dump dicts', 'r'))) { - return 'Couldn\'t create handle!'; - } - - while(!feof($handle)) { - $output .= fread($handle, 1024); - } - @pclose($handle); - - $dictionaries = explode(chr(10), $output); - - // Get rid of possible empty values - if (is_array($dictionaries)) { - - $cnt = count($dictionaries); - - for ($i = 0; $i < $cnt; $i++) { - if (!empty($dictionaries[$i])) { - $dicts[$dictionaries[$i]] = $dictionaries[$i]; - } - } - } + if($CFG->pspell || $CFG->redhatas3aspellfix){ + $dictionaries=aspell_dict_list(); + } else { + // If aspellpath isn't set don't even bother ;-) + if (empty($CFG->aspellpath)) { + return 'Empty aspell path!'; + } + + // Do we have access to popen function? + if (!function_exists('popen')) { + return 'Popen function disabled!'; + } + + $cmd = $CFG->aspellpath; + $output = ''; + $dictionaries = array(); + $dicts = array(); + + if(!($handle = @popen(escapeshellarg($cmd) .' dump dicts', 'r'))) { + return 'Couldn\'t create handle!'; + } + + while(!feof($handle)) { + $output .= fread($handle, 1024); + } + @pclose($handle); + + $dictionaries = explode(chr(10), $output); + + } + // Get rid of possible empty values + if (is_array($dictionaries)) { + + $cnt = count($dictionaries); + + for ($i = 0; $i < $cnt; $i++) { + if (!empty($dictionaries[$i])) { + $dicts[$dictionaries[$i]] = $dictionaries[$i]; + } + } + } if (count($dicts) >= 1) { return $dicts; diff -ruN moodle-vanila/lib/speller/server-scripts/aspell_pspell.php moodle/lib/speller/server-scripts/aspell_pspell.php --- moodle-vanila/lib/speller/server-scripts/aspell_pspell.php 1969-12-31 17:00:00.000000000 -0700 +++ moodle/lib/speller/server-scripts/aspell_pspell.php 2007-02-06 12:50:48.000000000 -0700 @@ -0,0 +1,72 @@ +skip_len); + pspell_config_mode($pspell_cfg_handle, $this->mode); + + if($pconfig != "") { + $pspell_handle = pspell_config_personal($pspell_cfg_handle, $personal_path.$pconfig.".pws"); + $personal = true; + } + $this->pspell_handle = pspell_new_config($pspell_cfg_handle); + } + + function check($word) { + return pspell_check($this->pspell_handle, $word); + } + + function suggest($word) { + return pspell_suggest($this->pspell_handle, $word); + } + + function add($word) { + if(!$personal) return false; + return pspell_add_to_personal($this->pspell_handle, $word); + } + + function close() { + if(!$personal) return; + return pspell_save_wordlist($this->pspell_handle); + } + +}; + +?> diff -ruN moodle-vanila/lib/speller/server-scripts/spellchecker.php moodle/lib/speller/server-scripts/spellchecker.php --- moodle-vanila/lib/speller/server-scripts/spellchecker.php 2006-09-30 20:01:28.000000000 -0600 +++ moodle/lib/speller/server-scripts/spellchecker.php 2007-02-06 13:27:01.000000000 -0700 @@ -1,5 +1,6 @@ redhatas3aspellfix ){ + $aspell_opts = '-a -H --lang='. $lang; +} else { + $aspell_opts = '-a -H --lang='. $lang .' --encoding=utf-8'; +} if (!empty($CFG->aspellextradicts)) { // eg /usr/bin/.aspell.en.pws $aspell_opts .= ' --add-extra-dicts='.$CFG->aspellextradicts; } $tempfiledir = $CFG->dataroot; // Use dataroot since it must be writable $input_separator = 'A'; + function check_language($cmd) { /// return users current language if its /// dictionary is found installed in system @@ -40,17 +46,23 @@ $current_lang = current_language(); $output = ''; - if(!($handle = popen($cmd .' dump dicts', 'r'))) { - error_handler("Couldn't create handle!"); - exit; - } + if ( $CFG->pspell || $CFG->redhatas3aspellfix ) { + $dicts=aspell_dict_list(); + } else { + $handle = @popen(escapeshellarg($cmd) .' dump dicts', 'r'); + if(!$handle) { + error_handler("Couldn't create handle!"); + exit; + } + + while(!feof($handle)) { + $output .= fread($handle, 1024); + } + @pclose($handle); + + $dicts = explode(chr(10), strtolower($output)); - while(!feof($handle)) { - $output .= fread($handle, 1024); } - @pclose($handle); - - $dicts = explode(chr(10), strtolower($output)); if(is_array($dicts)) { if(in_array($current_lang,$dicts)) { @@ -66,6 +78,12 @@ } +function normalize_text($t){ + // echo $t; + $ret=stripslashes(strip_tags(preg_replace('/\> <",urldecode($t)))); + // echo $ret; + return $ret; +} // set the JavaScript variable to the submitted text. // textinputs is an array, each element corresponding to the (url-encoded) // value of the text control submitted for spell-checking @@ -73,7 +91,11 @@ global $textinputs; foreach( $textinputs as $key=>$val ) { // $val = str_replace( "'", "%27", $val ); - echo "textinputs[$key] = decodeURIComponent(\"" . $val . "\");\n"; + $t=normalize_text($val); + $t=html_entity_decode(urldecode($val)); + $t=$val; + echo "textinputs[$key] = decodeURIComponent(\"" . $t . "\");\n"; + // echo "textinputs[$key] = \"" . $t . "\";\n"; } } @@ -116,6 +138,56 @@ // get the list of misspelled words. Put the results in the javascript words array // for each misspelled word, get suggestions and put in the javascript suggs array + +function print_checker_results_pspell() { + + global $aspell_prog; + global $aspell_opts; + global $tempfiledir; + global $textinputs; + global $input_separator; + global $lang; + + // regexp to nuke HTML tags in input + // handles cases when tags are spanning across 2 lines + // gets more tricky with more line spanning... + // Full HTML filter would be: + // $noHTML_re=array("/(<[^<>]+>)|(^[^<>]+>)|(<[^<>]+$)/"=>"","/(&#.{3})|(&\w+\;)/"=>""); + // However if we're spanning tags across lines it's safer to use + // built-in strip_tags and clean-up entities manually: + // $noHTML_re=array("/(&#.{3})|(&\w+\;)/"=>""); + $dicts=aspell_dict_list(); + $sc=new spell_checker($lang); + + $index=0; + $text_input_index=-1; + for( $i = 0; $i < count( $textinputs ); $i++ ) { + $text=normalize_text($textinputs[$i]); + // echo "'$text'"; + $lines = explode( "\n", $text ); + $text_input_index++; + print_textindex_decl($text_input_index); + foreach($lines as $line){ + // $clean_line=preg_replace(array_keys($noHTML_re),array_values($noHTML_re),$line); + $clean_line=html_entity_decode($line,ENT_COMPAT); + $words = split("[^[:alpha:]']+", $clean_line); + foreach($words as $word){ + if(!$sc->check($word)){ + // word is misspelled + print_words_elem($word,$index,$text_input_index); + $suggs=$sc->suggest($word); + if(empty($suggs)){$suggs=array();} + print_suggs_elem($suggs,$index,$text_input_index); + $index++; + } // we're not catching delimiters and errors from aspell + // like original did... hopefuly it wouldn't hurt + + } + } + } +} + + function print_checker_results() { global $aspell_prog; @@ -186,7 +258,7 @@ } // close temp file, delete file - unlink( $tempfile ); + // unlink( $tempfile ); } @@ -205,7 +277,11 @@ print_textinputs_var(); -print_checker_results(); +if ( $CFG->pspell ) { + print_checker_results_pspell(); +} else { + print_checker_results(); +} ?> diff -ruN moodle-vanila/lib/speller/wordWindow.js moodle/lib/speller/wordWindow.js --- moodle-vanila/lib/speller/wordWindow.js 2004-08-21 04:12:09.000000000 -0600 +++ moodle/lib/speller/wordWindow.js 2007-02-06 12:04:31.000000000 -0700 @@ -216,6 +216,9 @@ } function printForHtml( n ) { + // DIMON HACK + // we don't need to post-process so that we have WYSIWYG + return n; var htmlstr = n; if( htmlstr.length == 1 ) { // do simple case statement if it's just one character