Annotation of loncom/xml/scripttag.pm, revision 1.8
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.8 ! albertel 35: &Apache::run::run(&getfile("/home/httpd/html/raw/".$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,
1.8 ! albertel 52: &getfile("/home/httpd/html/raw/".$bodytext)));
1.7 albertel 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]);
1.8 ! albertel 68: my $file=&getfile("/home/httpd/html/raw/".$bodytext);
1.7 albertel 69: my $tempparser=HTML::TokeParser->new(\$file);
70: push (@$parser,$tempparser);
71: } else {
72: $result=&editfield($token->[1],$bodytext);
1.8 ! albertel 73: $result.="Click<a href=\"/res/$bodytext\">here</a> to edit<br></br>"
1.7 albertel 74: }
1.6 albertel 75: }
76:
77: sub end_import {
1.7 albertel 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<$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 90: }
1.3 albertel 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
1.1 albertel 103: }
1.3 albertel 104:
1.1 albertel 105: 1;
106: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>