Annotation of loncom/xml/scripttag.pm, revision 1.7

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

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