Annotation of loncom/interface/lonspeller.pm, revision 1.4
1.1 www 1: # The LearningOnline Network with CAPA
2: # Interface routines for Aspell
3: #
1.4 ! www 4: # $Id: lonspeller.pm,v 1.3 2004/07/22 20:19:20 www Exp $
1.1 www 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: ######################################################################
29: ######################################################################
30:
31: package Apache::lonspeller;
32:
33: use Text::Aspell;
34: use Apache::lonlocal;
35: use strict;
1.2 www 36: my $speller;
1.1 www 37:
1.4 ! www 38: sub spellcheck_language {
! 39: if ($ENV{'form.lang'}) { return $ENV{'form.lang'}; }
! 40: if (&mt('spellcheck_lang') ne 'spellcheck_lang') {
! 41: return &mt('spellcheck_lang');
! 42: }
! 43: return 'en_US';
! 44: }
! 45:
! 46: sub set_language {
! 47: my $lang=&spellcheck_language();
! 48: $speller->set_option('lang',$lang);
! 49: }
! 50:
1.2 www 51: sub markeduptext {
52: my $input=shift;
53: my $output='';
1.4 ! www 54: &set_language();
1.2 www 55: foreach my $word (split(/\W+/,$input)) {
56: if ($speller->check($word)) {
57: $output.=$word.' ';
58: } else {
59: my $suggestions=join(' ',$speller->suggest($word));
60: &Apache::lonnet::logthis($suggestions);
61: $suggestions=~s/\'/\\\'/gs;
62: if ($suggestions) {
63: $output.='<a href="javascript:alert('."'".
64: $suggestions."');".
65: '">';
66: }
67: $output.='<font color="red">'.$word.'</font>';
68: if ($suggestions) { $output.='</a>'; }
69: $output.=' ';
70: }
71: }
72: return $output;
73: }
74:
1.3 www 75: sub initspeller {
76: unless (defined($speller)) {
77: $speller = Text::Aspell->new;
78: $speller->set_option('lang','en_US');
79: $speller->set_option('sug-mode','fast');
80: }
81: }
82:
83: sub handler {
84: my $r = shift;
85: &Apache::loncommon::content_type($r,'text/html');
86: $r->send_http_header;
87: return OK if $r->header_only;
88:
89: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
90:
91: &initspeller();
92: $r->print('<html><head><title>'.
93: &mt('Spell Checker').
94: '</title></head><body bgcolor="#DDDDDD">'.
95: &markeduptext($ENV{'form.text'}).
96: '</body></html>');
97: return OK;
98: }
99:
1.2 www 100: BEGIN {
1.3 www 101: &initspeller();
1.1 www 102: }
103:
104: 1;
105:
106: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>