File:  [LON-CAPA] / loncom / xml / scripttag.pm
Revision 1.8: download - view: text, annotated - select for diffs
Fri Aug 11 14:24:18 2000 UTC (23 years, 9 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- stopped using /raw/

    1: # The LearningOnline Network with CAPA
    2: # <script> definiton
    3: 
    4: 
    5: package Apache::scripttag; 
    6: 
    7: use strict;
    8: use Apache::lonnet;
    9: 
   10: sub BEGIN {
   11:   &Apache::lonxml::register('Apache::scripttag',('script','scriptlib',
   12: 						 'parserlib','import'));
   13: }
   14: 
   15: sub start_script {
   16:   my ($target,$token,$parstack,$parser,$safeeval)=@_;
   17:   my $result="";
   18:   my $bodytext=$$parser[$#$parser]->get_text("/script");
   19:   if ($target ne "edit" ) {
   20:     $result = &Apache::run::run($bodytext,$safeeval);
   21:   } else {
   22:     $result=&editfield($token->[1],$bodytext);
   23:   }
   24:   return $result;
   25: }
   26: 
   27: sub end_script {}
   28: 
   29: sub start_scriptlib {
   30:   my ($target,$token,$parstack,$parser,$safeeval)=@_;
   31:   my $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
   32:   my $result ="";
   33:   if ($target ne "edit" ) {
   34:     $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
   35:     &Apache::run::run(&getfile("/home/httpd/html/raw/".$bodytext),$safeeval);
   36:     #print "ran $bodytext:<br>".&getfile($bodytext)."<br>";
   37:   } else {
   38:     $result=&editfield($token->[1],$bodytext);
   39:   }
   40:   return $result;
   41: }
   42: 
   43: sub end_scriptlib {}
   44: 
   45: sub start_parserlib {
   46:   my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
   47:   my $bodytext=$$parser[$#$parser]->get_text("/parserlib");
   48:   my $result ="";
   49:   if ($target ne "edit" ) {
   50:     $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
   51:     %$style = ( %$style , &Apache::style::styleparser($target, 
   52: 		&getfile("/home/httpd/html/raw/".$bodytext)));
   53:   } else {
   54:     $result=&editfield($token->[1],$bodytext);
   55:   }
   56:   return $result;
   57: }
   58: 
   59: sub end_parserlib {
   60: }
   61: 
   62: sub start_import {
   63:   my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
   64:   my $bodytext=$$parser[$#$parser]->get_text("/import");
   65:   my $result ="";
   66:   if ($target ne "edit" ) {
   67:     $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
   68:     my $file=&getfile("/home/httpd/html/raw/".$bodytext);
   69:     my $tempparser=HTML::TokeParser->new(\$file);
   70:     push (@$parser,$tempparser);
   71:   } else {
   72:     $result=&editfield($token->[1],$bodytext);
   73:     $result.="Click<a href=\"/res/$bodytext\">here</a> to edit<br></br>"
   74:   }
   75: }
   76: 
   77: sub end_import {
   78: }
   79: 
   80: sub editfield {
   81:   my ($tag,$data)=@_;
   82:   
   83:   my $count=0;
   84:   my $maxlength=-1;
   85:   map { $count++;
   86: 	if (length($_) > $maxlength) { $maxlength = length ($_); }
   87:       } split ("\n", $data);
   88: 	  
   89:   return "<br></br>\n&lt;$tag&gt;<br></br>\n&nbsp;&nbsp;&nbsp;<textarea rows=\"$count\" cols=\"$maxlength\" name=homework_edit_".$Apache::lonxml::curdepth.">$data</textarea><br></br>\n&lt;/$tag&gt;<br></br>\n";
   90: }
   91: 
   92: sub getfile {
   93:   my ($filename) = @_;
   94:   my $a="";
   95:   &Apache::lonnet::repcopy($filename);
   96:   {
   97:     my $fh=Apache::File->new($filename);
   98:     while (<$fh>) {
   99:       $a .=$_;
  100:     }
  101:   }
  102:   return $a
  103: }
  104: 
  105: 1;
  106: __END__

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