Diff for /loncom/interface/lonspeller.pm between versions 1.3 and 1.10

version 1.3, 2004/07/22 20:19:20 version 1.10, 2005/02/17 08:29:43
Line 30 Line 30
   
 package Apache::lonspeller;  package Apache::lonspeller;
   
   use Apache::Constants qw(:common);
 use Text::Aspell;  use Text::Aspell;
 use Apache::lonlocal;  use Apache::lonlocal;
   use Apache::lontexconvert();
   use HTML::LCParser;
 use strict;  use strict;
   
 my $speller;  my $speller;
   my $insidelink;
   
 sub markeduptext {  sub spellcheck_language {
       if ($ENV{'form.lang'}) { return $ENV{'form.lang'}; }
       if (&mt('spellcheck_lang') ne 'spellcheck_lang') {
    return &mt('spellcheck_lang');
       }
       return 'en_US';
   }
   
   sub set_language {
       my $lang=&spellcheck_language();
       $speller->set_option('lang',$lang);
   }
   
   sub textsection {
     my $input=shift;      my $input=shift;
     my $output='';      my $output='';
     foreach my $word (split(/\W+/,$input)) {      &set_language();
  if ($speller->check($word)) {      foreach my $word (split(/\b/,$input)) {
     $output.=$word.' ';   if (($word=~/\W/) || ($word=~/^(lt|gt|nbsp|amp)$/i)
       || ($speller->check($word))) {
       $output.=$word;
  } else {   } else {
     my $suggestions=join(' ',$speller->suggest($word));      my $suggestions=join(' ',$speller->suggest($word));
     &Apache::lonnet::logthis($suggestions);  
     $suggestions=~s/\'/\\\'/gs;      $suggestions=~s/\'/\\\'/gs;
     if ($suggestions) {      if (($suggestions) && (!$insidelink)) {
  $output.='<a href="javascript:alert('."'".   my $html=&Apache::lonxml::xmlbegin('encode');
     $suggestions."');".   $output.='<a href="javascript:spellwin=window.open('.
     '">';      &Apache::lonhtmlcommon::javascript_nothing().
       ',\'spellwin\',\'height=140,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no\');'.
                       'spellwin.'.&Apache::lonhtmlcommon::javascript_docopen().';spellwin.document.writeln(\''.$html.'<head></head><body><h3>'.$word.
                       '</h3>'.$suggestions.'</body></html>\');spellwin.document.close();spellwin.focus()">';
     }      }
     $output.='<font color="red">'.$word.'</font>';      $output.='<font color="red">'.$word.'</font>';
     if ($suggestions) { $output.='</a>'; }      if (($suggestions) && (!$insidelink)) { $output.='</a>'; }
     $output.=' ';   }
       }
       return $output;
   }
   
   
   sub markeduptext {
       my $input=shift;
       my $output='';
       my $parser=HTML::LCParser->new(\$input);
       $insidelink=0;
       my $token;
       while ($token=$parser->get_token) {
    if ($token->[0] eq 'T') {
       $output.=&textsection($token->[1]);
    } elsif ($token->[0] eq 'S') {
       $output.=$token->[4];
       foreach my $tag ('m','script') {
    if ($token->[1] eq $tag) {
       $output.=$parser->get_text('/'.$tag);
    }
       }
       if ($token->[1] eq 'a') {
    $insidelink=1;
       }
    } elsif ($token->[0] eq 'E') {
       $output.=$token->[2];
       if ($token->[1] eq 'a') {
    $insidelink=0;
       }
  }   }
     }      }
       $insidelink=0;
     return $output;      return $output;
 }  }
   
Line 62  sub initspeller { Line 114  sub initspeller {
     unless (defined($speller)) {      unless (defined($speller)) {
  $speller = Text::Aspell->new;   $speller = Text::Aspell->new;
  $speller->set_option('lang','en_US');   $speller->set_option('lang','en_US');
  $speller->set_option('sug-mode','fast');  
     }      }
       $insidelink=0;
 }  }
   
 sub handler {  sub handler {
Line 75  sub handler { Line 127  sub handler {
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});      &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
   
     &initspeller();      &initspeller();
     $r->print('<html><head><title>'.      my $html=&Apache::lonxml::xmlbegin();
       $r->print($html.'<head><title>'.
       &mt('Spell Checker').        &mt('Spell Checker').
       '</title></head><body bgcolor="#DDDDDD">'.        '</title></head><body bgcolor="#DDDDDD">'.
       &markeduptext($ENV{'form.text'}).        &Apache::lontexconvert::msgtexconverted(
        &markeduptext($ENV{'form.text'})).
       '</body></html>');        '</body></html>');
     return OK;      return OK;
 }  }

Removed from v.1.3  
changed lines
  Added in v.1.10


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>