[LON-CAPA-cvs] cvs: loncom /interface spellcheck.pm

foxr foxr at source.lon-capa.org
Mon Aug 27 07:09:56 EDT 2012


foxr		Mon Aug 27 11:09:56 2012 EDT

  Modified files:              
    /loncom/interface	spellcheck.pm 
  Log:
  BZ 838 Ajax Spellcheck module required by jquery-spellcheck - tested with 
  GET -- Need to test with POST.
  
  
Index: loncom/interface/spellcheck.pm
diff -u loncom/interface/spellcheck.pm:1.1 loncom/interface/spellcheck.pm:1.2
--- loncom/interface/spellcheck.pm:1.1	Tue Aug 21 10:31:52 2012
+++ loncom/interface/spellcheck.pm	Mon Aug 27 11:09:56 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Printout
 #
-# $Id: spellcheck.pm,v 1.1 2012/08/21 10:31:52 foxr Exp $
+# $Id: spellcheck.pm,v 1.2 2012/08/27 11:09:56 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -26,6 +26,8 @@
 #
 #
 package Apache::spellcheck;
+use CGI qw(:standard);
+use Apache::Constants qw(:common);
 use strict;
 use Text::Aspell;
 
@@ -79,7 +81,7 @@
     my @mis_spelled;
     foreach my $word (@word_list) {
 	if (!$checker->check($word)) {
-	    push (@mis_spelled $word);
+	    push (@mis_spelled, $word);
 	}
     }
     return &array_to_json(\@mis_spelled);
@@ -98,7 +100,7 @@
     my $checker = Text::Aspell->new;
     $checker->set_option('lang', $lang);
 
-    @suggestions = $checker->suggest($word);
+    my @suggestions = $checker->suggest($word);
 
     return &array_to_json(\@suggestions);
 }
@@ -115,16 +117,25 @@
 
 sub handler {
     my $r = shift;
+    my $raw_params;
+
+    if ($r->method eq 'POST') {
+	$raw_params = $r->content();
+    } else {
+	$raw_params = $r->args();
+    }
+    my $query = CGI->new($raw_params);
 
     # Figure out the language defaulting to english.
 
     my $language = "en-US";
-    if ($r->param{'lang'}) {
-	$language = $r->param{'lang'};
+    if ($query->param('lang')) {
+	$language = $query->param('lang');
     }
     #  Regardless, response Content type: is application/json:
 
-    $h->header_out('Content-Type', 'application/json');
+    $r->content_type( 'application/json');
+    $r->send_http_header;
 
     # Whether we are suggesting or spell checking
     # depends on which of the suggest or text args are present:
@@ -132,13 +143,17 @@
 
     my $data;
 
-    if ($h->args{'text'}) {
-	$data =  &spell_check($h->args{'text'}, $language);
-    } eslif ($h->args{'suggest'}) {
-	$data = &suggest_spellings($h->args{'suggest'}, $language);
+    if ($query->param('text')) {
+	$data =  &spell_check($query->param('text'), $language);
+    } elsif ($query->param('suggest')) {
+	$data = &suggest_spellings($query->param('suggest'), $language);
     } else {
 	die "Invalid request";
     }
     $r->print($data);
 
+    return OK;
 }
+
+    1;
+__END__




More information about the LON-CAPA-cvs mailing list