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