Annotation of loncom/xml/scripttag.pm, revision 1.28
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',
1.20 sakharuk 12: 'parserlib','import',
1.24 albertel 13: 'footnote','display'));
1.1 albertel 14: }
15:
16: sub start_script {
1.2 albertel 17: my ($target,$token,$parstack,$parser,$safeeval)=@_;
1.17 albertel 18: my $args ='';
19: if ( $#$parstack > -1 ) {
20: $args=$$parstack[$#$parstack];
21: }
22: my $type = &Apache::run::run("{$args;".'return $type}',$safeeval);
1.24 albertel 23: my $result='';
1.18 albertel 24: #&Apache::lonxml::debug("found type of $type");
1.17 albertel 25: if ($type eq "loncapa/perl") {
1.21 albertel 26: my $bodytext=&Apache::lonxml::get_all_text("/script",$$parser[$#$parser]);
1.17 albertel 27:
28: if ( $target eq "modified" ) {
1.28 ! albertel 29:
! 30: } elsif ( $target eq "web" || $target eq "grade" ) {
! 31: &Apache::run::run($bodytext,$safeeval);
! 32: } elsif ($target eq "edit" ) {
! 33: &Apache::run::run($bodytext,$safeeval);
1.24 albertel 34: $result="<br> <$token->[1]> output: <br>$bodytext<br>Source:<br>";
35: $result.=&editfield($token->[1],$bodytext);
1.17 albertel 36: }
37: } else {
1.28 ! albertel 38: if ($target ne "meta") { $result = $token->[4]; }
1.13 albertel 39: }
1.24 albertel 40: return $result;
1.17 albertel 41: }
1.13 albertel 42:
1.17 albertel 43: sub end_script {
44: my ($target,$token,$parstack,$parser,$safeeval)=@_;
1.28 ! albertel 45: if ( $target eq "meta" ) { return ''; }
! 46: # return $token->[2];
! 47: return '';
1.24 albertel 48: }
49:
50: sub start_display {
51: my ($target,$token,$parstack,$parser,$safeeval)=@_;
52: my $args ='';
53: if ( $#$parstack > -1 ) {
54: $args=$$parstack[$#$parstack];
55: }
56: my $bodytext=&Apache::lonxml::get_all_text("/display",$$parser[$#$parser]);
57:
58: if ( $target eq "modified" ) {
59: }
60: my $result=&Apache::run::run($bodytext,$safeeval);
1.26 albertel 61: if ($target eq 'grade' ) {
62: # grade should produce no output
63: $result='';
64: }
1.24 albertel 65: if ($target eq "edit" ) {
66: $result =
67: "<br> <$token->[1]> output: <br>$bodytext<br>Source:<br>";
68: $result.=&editfield($token->[1],$bodytext);
69: }
70: return $result;
71: }
72:
73: sub end_display {
1.1 albertel 74: }
1.3 albertel 75:
76: sub start_scriptlib {
77: my ($target,$token,$parstack,$parser,$safeeval)=@_;
1.5 albertel 78: my $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
1.3 albertel 79: my $result ="";
1.13 albertel 80:
1.18 albertel 81: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
82: $$parstack[$#$parstack]);
83: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
84: $bodytext);
85: my $script=&Apache::lonnet::getfile($location);
86: if ($script == -1) {
87: &Apache::lonxml::error("<b> Unable to find <i>$location</i> for scriptlib</b>");
88: return "";
89: }
90: &Apache::run::run($script,$safeeval);
91: #&Apache::lonxml::debug("ran $bodytext:<br>".&Apache::lonnet::getfile($bodytext)."<br>");
1.13 albertel 92:
93: if ($target eq "edit" ) {
94: $result.=&editfield($token->[1],$bodytext);
1.3 albertel 95: }
96: return $result;
97: }
98:
99: sub end_scriptlib {}
1.4 albertel 100:
101: sub start_parserlib {
102: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.6 albertel 103: my $bodytext=$$parser[$#$parser]->get_text("/parserlib");
1.7 albertel 104: my $result ="";
1.13 albertel 105:
1.18 albertel 106: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
107: $$parstack[$#$parstack]);
108: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
109: $bodytext);
110: my $styletext=&Apache::lonnet::getfile($location);
1.28 ! albertel 111: #&Apache::lonxml::debug("found :$bodytext: in :$location: with :$styletext:");
1.18 albertel 112: if ($styletext == -1) {
113: &Apache::lonxml::error("<b> Unable to find <i>$location</i> for parserlib</b>");
114: return "";
115: }
116: %$style = ( %$style , &Apache::style::styleparser($target,$styletext));
1.13 albertel 117:
118: if ($target eq "edit" ) {
1.7 albertel 119: $result=&editfield($token->[1],$bodytext);
120: }
121: return $result;
1.4 albertel 122: }
123:
124: sub end_parserlib {
1.6 albertel 125: }
126:
1.19 sakharuk 127: sub start_footnote {
128: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.20 sakharuk 129: my $result = '';
130: $Apache::lonxml::redirection = 0;
1.19 sakharuk 131: return $result;
132: }
133:
134: sub end_footnote {
135: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.20 sakharuk 136: $Apache::lonxml::outputstack =~ s/\"/\"\;/g;
137: my $result = "<a href=\"javascript:newWindow=open(\'\',\'new_W\',\'width=500,height=200\');newWindow.document.open(\'text/html\',\'replace\');newWindow.document.writeln(\'<html><head><title>newwindow</title></head><body bgcolor="#FFFFFF"> $Apache::lonxml::outputstack </body></html>\');newWindow.document.close();void(0);\"><sup>*</sup></a>";
138: $Apache::lonxml::outputstack = "";
139: $Apache::lonxml::redirection = 1;
140: return $result;
1.19 sakharuk 141: }
142:
1.6 albertel 143: sub start_import {
1.7 albertel 144: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.6 albertel 145: my $bodytext=$$parser[$#$parser]->get_text("/import");
1.7 albertel 146: my $result ="";
1.13 albertel 147:
148: $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
1.18 albertel 149: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
150: my $file=&Apache::lonnet::getfile($location);
151: if ($file == -1) {
152: &Apache::lonxml::error("<b> Unable to find <i>$bodytext $location</i> for import</b>");
153: return "";
1.14 albertel 154: }
155:
1.18 albertel 156: my $dir=$location;
157: $dir=~s:/[^/]*$::;
158: &Apache::lonxml::newparser($parser,\$file,$dir);
1.13 albertel 159:
160: if ($target eq "edit" ) {
161: $result.=&editfield($token->[1],$bodytext);
1.8 albertel 162: $result.="Click<a href=\"/res/$bodytext\">here</a> to edit<br></br>"
1.7 albertel 163: }
1.27 albertel 164: return '';
1.6 albertel 165: }
166:
167: sub end_import {
1.7 albertel 168: }
169:
170: sub editfield {
171: my ($tag,$data)=@_;
172:
173: my $count=0;
174: my $maxlength=-1;
175: map { $count++;
176: if (length($_) > $maxlength) { $maxlength = length ($_); }
177: } split ("\n", $data);
178:
179: 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 180: }
1.3 albertel 181:
1.18 albertel 182: sub getfilenothere {
1.3 albertel 183: my ($filename) = @_;
184: my $a="";
1.11 tsai 185:
1.12 tsai 186: $filename=~ s/^\s*(\S+)\s*$/$1/; ## strip off leading and trailing spaces
1.10 albertel 187: $filename="/home/httpd/html/res".$filename;
188: if (! -e $filename ) {
189: &Apache::lonnet::subscribe($filename);
190: &Apache::lonnet::repcopy($filename);
191: }
1.14 albertel 192: if (! -e $filename ) { return -1; };
1.11 tsai 193: my $fh=Apache::File->new($filename);
194: while (<$fh>) {
1.3 albertel 195: $a .=$_;
196: }
197: return $a
1.1 albertel 198: }
1.3 albertel 199:
1.1 albertel 200: 1;
201: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>