+++ /dev/null
-<?php\r
-header('Content-type: text/html; charset=utf-8');\r
-\r
-// The following variables values must reflect your installation needs.\r
-\r
-$aspell_prog = '"C:\Program Files\Aspell\bin\aspell.exe"'; // by FredCK (for Windows)\r
-//$aspell_prog = 'aspell'; // by FredCK (for Linux)\r
-\r
-$lang = 'en_US';\r
-$aspell_opts = "-a --lang=$lang --encoding=utf-8 -H --rem-sgml-check=alt"; // by FredCK\r
-\r
-$tempfiledir = "./";\r
-\r
-$spellercss = '../spellerStyle.css'; // by FredCK\r
-$word_win_src = '../wordWindow.js'; // by FredCK\r
-\r
-$textinputs = $_POST['textinputs']; # array\r
-$input_separator = "A";\r
-\r
-# set the JavaScript variable to the submitted text.\r
-# textinputs is an array, each element corresponding to the (url-encoded)\r
-# value of the text control submitted for spell-checking\r
-function print_textinputs_var() {\r
- global $textinputs;\r
- foreach( $textinputs as $key=>$val ) {\r
- # $val = str_replace( "'", "%27", $val );\r
- echo "textinputs[$key] = decodeURIComponent(\"" . $val . "\");\n";\r
- }\r
-}\r
-\r
-# make declarations for the text input index\r
-function print_textindex_decl( $text_input_idx ) {\r
- echo "words[$text_input_idx] = [];\n";\r
- echo "suggs[$text_input_idx] = [];\n";\r
-}\r
-\r
-# set an element of the JavaScript 'words' array to a misspelled word\r
-function print_words_elem( $word, $index, $text_input_idx ) {\r
- echo "words[$text_input_idx][$index] = '" . escape_quote( $word ) . "';\n";\r
-}\r
-\r
-\r
-# set an element of the JavaScript 'suggs' array to a list of suggestions\r
-function print_suggs_elem( $suggs, $index, $text_input_idx ) {\r
- echo "suggs[$text_input_idx][$index] = [";\r
- foreach( $suggs as $key=>$val ) {\r
- if( $val ) {\r
- echo "'" . escape_quote( $val ) . "'";\r
- if ( $key+1 < count( $suggs )) {\r
- echo ", ";\r
- }\r
- }\r
- }\r
- echo "];\n";\r
-}\r
-\r
-# escape single quote\r
-function escape_quote( $str ) {\r
- return preg_replace ( "/'/", "\\'", $str );\r
-}\r
-\r
-\r
-# handle a server-side error.\r
-function error_handler( $err ) {\r
- echo "error = '" . preg_replace( "/['\\\\]/", "\\\\$0", $err ) . "';\n";\r
-}\r
-\r
-## get the list of misspelled words. Put the results in the javascript words array\r
-## for each misspelled word, get suggestions and put in the javascript suggs array\r
-function print_checker_results() {\r
-\r
- global $aspell_prog;\r
- global $aspell_opts;\r
- global $tempfiledir;\r
- global $textinputs;\r
- global $input_separator;\r
- $aspell_err = "";\r
- # create temp file\r
- $tempfile = tempnam( $tempfiledir, 'aspell_data_' );\r
-\r
- # open temp file, add the submitted text.\r
- if( $fh = fopen( $tempfile, 'w' )) {\r
- for( $i = 0; $i < count( $textinputs ); $i++ ) {\r
- $text = urldecode( $textinputs[$i] );\r
-\r
- // Strip all tags for the text. (by FredCK - #339 / #681)\r
- $text = preg_replace( "/<[^>]+>/", " ", $text ) ;\r
-\r
- $lines = explode( "\n", $text );\r
- fwrite ( $fh, "%\n" ); # exit terse mode\r
- fwrite ( $fh, "^$input_separator\n" );\r
- fwrite ( $fh, "!\n" ); # enter terse mode\r
- foreach( $lines as $key=>$value ) {\r
- # use carat on each line to escape possible aspell commands\r
- fwrite( $fh, "^$value\n" );\r
- }\r
- }\r
- fclose( $fh );\r
-\r
- # exec aspell command - redirect STDERR to STDOUT\r
- $cmd = "$aspell_prog $aspell_opts < $tempfile 2>&1";\r
- if( $aspellret = shell_exec( $cmd )) {\r
- $linesout = explode( "\n", $aspellret );\r
- $index = 0;\r
- $text_input_index = -1;\r
- # parse each line of aspell return\r
- foreach( $linesout as $key=>$val ) {\r
- $chardesc = substr( $val, 0, 1 );\r
- # if '&', then not in dictionary but has suggestions\r
- # if '#', then not in dictionary and no suggestions\r
- # if '*', then it is a delimiter between text inputs\r
- # if '@' then version info\r
- if( $chardesc == '&' || $chardesc == '#' ) {\r
- $line = explode( " ", $val, 5 );\r
- print_words_elem( $line[1], $index, $text_input_index );\r
- if( isset( $line[4] )) {\r
- $suggs = explode( ", ", $line[4] );\r
- } else {\r
- $suggs = array();\r
- }\r
- print_suggs_elem( $suggs, $index, $text_input_index );\r
- $index++;\r
- } elseif( $chardesc == '*' ) {\r
- $text_input_index++;\r
- print_textindex_decl( $text_input_index );\r
- $index = 0;\r
- } elseif( $chardesc != '@' && $chardesc != "" ) {\r
- # assume this is error output\r
- $aspell_err .= $val;\r
- }\r
- }\r
- if( $aspell_err ) {\r
- $aspell_err = "Error executing `$cmd`\\n$aspell_err";\r
- error_handler( $aspell_err );\r
- }\r
- } else {\r
- error_handler( "System error: Aspell program execution failed (`$cmd`)" );\r
- }\r
- } else {\r
- error_handler( "System error: Could not open file '$tempfile' for writing" );\r
- }\r
-\r
- # close temp file, delete file\r
- unlink( $tempfile );\r
-}\r
-\r
-\r
-?>\r
-<html>\r
-<head>\r
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8">\r
-<link rel="stylesheet" type="text/css" href="<?php echo $spellercss ?>" />\r
-<script language="javascript" src="<?php echo $word_win_src ?>"></script>\r
-<script language="javascript">\r
-var suggs = new Array();\r
-var words = new Array();\r
-var textinputs = new Array();\r
-var error;\r
-<?php\r
-\r
-print_textinputs_var();\r
-\r
-print_checker_results();\r
-\r
-?>\r
-\r
-var wordWindowObj = new wordWindow();\r
-wordWindowObj.originalSpellings = words;\r
-wordWindowObj.suggestions = suggs;\r
-wordWindowObj.textInputs = textinputs;\r
-\r
-function init_spell() {\r
- // check if any error occured during server-side processing\r
- if( error ) {\r
- alert( error );\r
- } else {\r
- // call the init_spell() function in the parent frameset\r
- if (parent.frames.length) {\r
- parent.init_spell( wordWindowObj );\r
- } else {\r
- alert('This page was loaded outside of a frameset. It might not display properly');\r
- }\r
- }\r
-}\r
-\r
-\r
-\r
-</script>\r
-\r
-</head>\r
-<!-- <body onLoad="init_spell();"> by FredCK -->\r
-<body onLoad="init_spell();" bgcolor="#ffffff">\r
-\r
-<script type="text/javascript">\r
-wordWindowObj.writeBody();\r
-</script>\r
-\r
-</body>\r
-</html>\r