Annotation of loncom/xml/scripttag.pm, revision 1.13
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.13 ! albertel 18: # my $bodytext=$$parser[$#$parser]->get_text("/script");
! 19: my $bodytext=&Apache::lonxml::get_all_text("script",$$parser[$#$parser]);
! 20:
! 21: if ( $target eq "modified" ) {
! 22:
! 23: }
! 24:
! 25: # print "<br> script runs $bodytext</br>";
! 26: $result = &Apache::run::run($bodytext,$safeeval);
! 27:
! 28: if ($target eq "edit" ) {
! 29: $result= "<br> <$token->[1]> output: <br>$bodytext<br>Source:<br>";
! 30: $result.=&editfield($token->[1],$bodytext);
1.2 albertel 31: }
32: return $result;
1.1 albertel 33: }
34:
1.3 albertel 35: sub end_script {}
36:
37: sub start_scriptlib {
38: my ($target,$token,$parstack,$parser,$safeeval)=@_;
1.5 albertel 39: my $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
1.3 albertel 40: my $result ="";
1.13 ! albertel 41:
! 42: $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
! 43: &Apache::run::run(&getfile($bodytext),$safeeval);
! 44: #print "ran $bodytext:<br>".&getfile($bodytext)."<br>";
! 45:
! 46: if ($target eq "edit" ) {
! 47: $result.=&editfield($token->[1],$bodytext);
1.3 albertel 48: }
49: return $result;
50: }
51:
52: sub end_scriptlib {}
1.4 albertel 53:
54: sub start_parserlib {
55: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.6 albertel 56: my $bodytext=$$parser[$#$parser]->get_text("/parserlib");
1.7 albertel 57: my $result ="";
1.13 ! albertel 58:
! 59: $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
! 60: %$style = ( %$style , &Apache::style::styleparser($target,
1.9 albertel 61: &getfile($bodytext)));
1.13 ! albertel 62:
! 63: if ($target eq "edit" ) {
1.7 albertel 64: $result=&editfield($token->[1],$bodytext);
65: }
66: return $result;
1.4 albertel 67: }
68:
69: sub end_parserlib {
1.6 albertel 70: }
71:
72: sub start_import {
1.7 albertel 73: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.6 albertel 74: my $bodytext=$$parser[$#$parser]->get_text("/import");
1.7 albertel 75: my $result ="";
1.13 ! albertel 76:
! 77: $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
! 78: my $file=&getfile($bodytext);
! 79: my $tempparser=HTML::TokeParser->new(\$file);
! 80: push (@$parser,$tempparser);
! 81:
! 82: if ($target eq "edit" ) {
! 83: $result.=&editfield($token->[1],$bodytext);
1.8 albertel 84: $result.="Click<a href=\"/res/$bodytext\">here</a> to edit<br></br>"
1.7 albertel 85: }
1.6 albertel 86: }
87:
88: sub end_import {
1.7 albertel 89: }
90:
91: sub editfield {
92: my ($tag,$data)=@_;
93:
94: my $count=0;
95: my $maxlength=-1;
96: map { $count++;
97: if (length($_) > $maxlength) { $maxlength = length ($_); }
98: } split ("\n", $data);
99:
100: return "<br></br>\n<$tag><br></br>\n <textarea rows=\"$count\" cols=\"$maxlength\" name=homework_edit_".$Apache::lonxml::curdepth.">$data</textarea><br></br>\n</$tag><br></br>\n";
1.4 albertel 101: }
1.3 albertel 102:
103: sub getfile {
104: my ($filename) = @_;
105: my $a="";
1.11 tsai 106:
1.12 tsai 107: $filename=~ s/^\s*(\S+)\s*$/$1/; ## strip off leading and trailing spaces
1.10 albertel 108: $filename="/home/httpd/html/res".$filename;
109: if (! -e $filename ) {
110: &Apache::lonnet::subscribe($filename);
111: &Apache::lonnet::repcopy($filename);
112: }
1.11 tsai 113: my $fh=Apache::File->new($filename);
114: while (<$fh>) {
1.3 albertel 115: $a .=$_;
116: }
117: return $a
1.1 albertel 118: }
1.3 albertel 119:
1.1 albertel 120: 1;
121: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>