3
use CGI qw/ :standard /;
4
use File::Temp qw/ tempfile tempdir /;
6
# my $spellercss = '/speller/spellerStyle.css'; # by FredCK
7
my $spellercss = '../spellerStyle.css'; # by FredCK
8
# my $wordWindowSrc = '/speller/wordWindow.js'; # by FredCK
9
my $wordWindowSrc = '../wordWindow.js'; # by FredCK
10
my @textinputs = param( 'textinputs[]' ); # array
11
# my $aspell_cmd = 'aspell'; # by FredCK (for Linux)
12
my $aspell_cmd = '"C:\Program Files\Aspell\bin\aspell.exe"'; # by FredCK (for Windows)
14
# my $aspell_opts = "-a --lang=$lang --encoding=utf-8"; # by FredCK
15
my $aspell_opts = "-a --lang=$lang --encoding=utf-8 -H --rem-sgml-check=alt"; # by FredCK
16
my $input_separator = "A";
18
# set the 'wordtext' JavaScript variable to the submitted text.
20
for( my $i = 0; $i <= $#textinputs; $i++ ) {
21
print "textinputs[$i] = decodeURIComponent('" . escapeQuote( $textinputs[$i] ) . "')\n";
25
sub printTextIdxDecl {
27
print "words[$idx] = [];\n";
28
print "suggs[$idx] = [];\n";
32
my( $textIdx, $wordIdx, $word ) = @_;
33
print "words[$textIdx][$wordIdx] = '" . escapeQuote( $word ) . "';\n";
37
my( $textIdx, $wordIdx, @suggs ) = @_;
38
print "suggs[$textIdx][$wordIdx] = [";
39
for my $i ( 0..$#suggs ) {
40
print "'" . escapeQuote( $suggs[$i] ) . "'";
48
sub printCheckerResults {
49
my $textInputIdx = -1;
53
my $dir = tempdir( CLEANUP => 1 );
54
my( $fh, $tmpfilename ) = tempfile( DIR => $dir );
56
# temp file was created properly?
58
# open temp file, add the submitted text.
59
for( my $i = 0; $i <= $#textinputs; $i++ ) {
60
$text = url_decode( $textinputs[$i] );
61
# Strip all tags for the text. (by FredCK - #339 / #681)
62
$text =~ s/<[^>]+>/ /g;
63
@lines = split( /\n/, $text );
64
print $fh "\%\n"; # exit terse mode
65
print $fh "^$input_separator\n";
66
print $fh "!\n"; # enter terse mode
67
for my $line ( @lines ) {
68
# use carat on each line to escape possible aspell commands
74
my $cmd = "$aspell_cmd $aspell_opts < $tmpfilename 2>&1";
75
open ASPELL, "$cmd |" or handleError( "Could not execute `$cmd`\\n$!" ) and return;
76
# parse each line of aspell return
77
for my $ret ( <ASPELL> ) {
79
# if '&', then not in dictionary but has suggestions
80
# if '#', then not in dictionary and no suggestions
81
# if '*', then it is a delimiter between text inputs
84
printTextIdxDecl( $textInputIdx );
87
} elsif( $ret =~ /^(&|#)/ ) {
88
my @tokens = split( " ", $ret, 5 );
89
printWordsElem( $textInputIdx, $wordIdx, $tokens[1] );
92
@suggs = split( ", ", $tokens[4] );
94
printSuggsElem( $textInputIdx, $wordIdx, @suggs );
97
$unhandledText .= $ret;
100
close ASPELL or handleError( "Error executing `$cmd`\\n$unhandledText" ) and return;
111
print "error = '" . escapeQuote( $err ) . "';\n";
115
local $_ = @_ ? shift : $_;
117
# change + signs to spaces
119
# change hex escapes to the proper characters
120
s/%([a-fA-F0-9]{2})/pack "H2", $1/eg;
124
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
126
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
129
Content-type: text/html; charset=utf-8
133
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
134
<link rel="stylesheet" type="text/css" href="$spellercss"/>
135
<script src="$wordWindowSrc"></script>
136
<script type="text/javascript">
137
var suggs = new Array();
138
var words = new Array();
139
var textinputs = new Array();
145
printCheckerResults();
148
var wordWindowObj = new wordWindow();
149
wordWindowObj.originalSpellings = words;
150
wordWindowObj.suggestions = suggs;
151
wordWindowObj.textInputs = textinputs;
154
function init_spell() {
155
// check if any error occured during server-side processing
159
// call the init_spell() function in the parent frameset
160
if (parent.frames.length) {
161
parent.init_spell( wordWindowObj );
163
error = "This page was loaded outside of a frameset. ";
164
error += "It might not display properly";
173
<body onLoad="init_spell();">
175
<script type="text/javascript">
176
wordWindowObj.writeBody();