File:
[LON-CAPA] /
loncom /
xml /
scripttag.pm
Revision
1.37:
download - view:
text,
annotated -
select for diffs
Fri May 4 21:17:24 2001 UTC (23 years, 2 months ago) by
albertel
Branches:
MAIN
CVS tags:
HEAD
- large changes to start generating a editing enviroment
- <script> <scriptlib> <parserlib> work in edit in envrioment
- callsub needs to be reorganized
- added evaluate global to lonxml, turns off evaluation of $var
1: # The LearningOnline Network with CAPA
2: # <script> definiton
3: # 2/21 Guy
4:
5: package Apache::scripttag;
6:
7: use strict;
8: use Apache::lonnet;
9:
10: sub BEGIN {
11: &Apache::lonxml::register('Apache::scripttag',('script','scriptlib',
12: 'parserlib','import',
13: 'window','display'));
14: }
15:
16: sub start_script {
17: my ($target,$token,$parstack,$parser,$safeeval)=@_;
18: my $args ='';
19: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
20: my $type = &Apache::run::run("{$args;".'return $type}',$safeeval);
21: my $result='';
22: #&Apache::lonxml::debug("found type of $type");
23: if ($type eq "loncapa/perl") {
24: my $bodytext=&Apache::lonxml::get_all_text("/script",$$parser[$#$parser]);
25:
26: if ( $target eq "modified" ) {
27: $result=$token->[4].$bodytext;
28: } elsif ( $target eq "web" || $target eq "grade" ) {
29: &Apache::run::run($bodytext,$safeeval);
30: } elsif ($target eq "edit" ) {
31: &Apache::run::run($bodytext,$safeeval);
32: $result="<br /> <$token->[1]> output: <br />$bodytext<br />Source:<br />";
33: $result.=&Apache::edit::editfield($token->[1],$bodytext);
34: }
35: } else {
36: if ($target ne "meta") { $result = $token->[4]; }
37: }
38: return $result;
39: }
40:
41: sub end_script {
42: my ($target,$token,$parstack,$parser,$safeeval)=@_;
43: if ( $target eq "meta" ) { return ''; }
44: my $args ='';
45: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
46: my $type = &Apache::run::run("{$args;".'return $type}',$safeeval);
47: my $result='';
48: #other script blocks need to survive
49: if ($type ne "loncapa/perl") { return $token->[2]; }
50: return '';
51: }
52:
53: sub start_display {
54: my ($target,$token,$parstack,$parser,$safeeval)=@_;
55: my $args ='';
56: if ( $#$parstack > -1 ) {
57: $args=$$parstack[$#$parstack];
58: }
59: my $bodytext=&Apache::lonxml::get_all_text("/display",$$parser[$#$parser]);
60:
61: if ( $target eq "modified" ) {
62: }
63: my $result=&Apache::run::run($bodytext,$safeeval);
64: if ($target eq 'grade' ) {
65: # grade should produce no output
66: $result='';
67: }
68: if ($target eq "edit" ) {
69: $result =
70: "<br /> <$token->[1]> output: <br />$bodytext<br />Source:<br />";
71: $result.=&Apache::edit::editfield($token->[1],$bodytext);
72: }
73: return $result;
74: }
75:
76: sub end_display {
77: }
78:
79: sub start_scriptlib {
80: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
81: my $bodytext;
82: my $result ='';
83: my $error='';
84:
85: if ($target eq 'web' || $target eq 'grade' || $target eq 'meta' || $target eq 'edit') {
86: $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
87: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
88: $$parstack[$#$parstack]);
89: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
90: $bodytext);
91: my $script=&Apache::lonnet::getfile($location);
92: if ($script == -1) {
93: if ($target eq 'edit') {
94: $error='</tr><tr><td>Errors</td><td colspan="2"><b> Unable to find <i>'.$location.'</i></b></td>'."\n";
95: } else {
96: &Apache::lonxml::error("<b> Unable to find <i>$location</i> for scriptlib</b>");
97: return "";
98: }
99: }
100: &Apache::run::run($script,$safeeval);
101: #&Apache::lonxml::debug("ran $bodytext:<br />".&Apache::lonnet::getfile($bodytext)."<br />");
102: }
103: if ($target eq "edit" ) {
104: $result=
105: &Apache::edit::tag_start($token->[1]).
106: &Apache::edit::editfield($token->[1],$bodytext,'New Script Functions').
107: $error;
108: }
109: if ($target eq "modified" ) {
110: $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
111: $result=&Apache::edit::modifiedfield($token);
112: &Apache::lonxml::debug($result);
113: }
114: return $result;
115: }
116:
117: sub end_scriptlib {
118: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
119: my $result='';
120: # if ($target eq "edit" ) { $result=" "; }
121: return $result;
122: }
123:
124: sub start_parserlib {
125: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
126: my $bodytext;
127: my $result ="";
128: my $error='';
129:
130: if ($target eq 'web' || $target eq 'grade' || $target eq 'meta' || $target eq 'edit') {
131: $bodytext=$$parser[$#$parser]->get_text("/parserlib");
132: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
133: $$parstack[$#$parstack]);
134: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
135: $bodytext);
136: my $styletext=&Apache::lonnet::getfile($location);
137: #&Apache::lonxml::debug("found :$bodytext: in :$location: with :$styletext:");
138: if ($styletext == -1) {
139: if ($target eq 'edit') {
140: $error='</tr><tr><td>Errors</td><td colspan="2"><b> Unable to find <i>'.$location.'</i></b></td>'."\n";
141: } else {
142: &Apache::lonxml::error("<b> Unable to find <i>$location</i> for parserlib</b>");
143: return "";
144: }
145: }
146: %$style = ( %$style , &Apache::style::styleparser($target,$styletext));
147: }
148: if ($target eq "edit" ) {
149: $result=
150: &Apache::edit::tag_start($token->[1]).
151: &Apache::edit::editfield($token->[1],$bodytext,"New Tag Definitions").
152: $error;
153: }
154: if ($target eq "modified" ) {
155: $bodytext=$$parser[$#$parser]->get_text("/parserlib");
156: $result=&Apache::edit::modifiedfield($token);
157: &Apache::lonxml::debug($result);
158: }
159: return $result;
160: }
161:
162: sub end_parserlib {
163: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
164: my $result='';
165: # if ($target eq "edit" ) {
166: # $result=&Apache::edit::tag_end($target,$token,$parstack,$parser,
167: # $safeeval,$style);
168: # }
169: return $result;
170: }
171:
172: sub start_window {
173: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
174: my $result = '';
175: if ($target eq 'web') {
176: &Apache::lonxml::startredirection;
177: } elsif ($target eq 'tex') {
178: $result = '\footnote{';
179: }
180: return $result;
181: }
182:
183: sub end_window {
184: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
185: my $result;
186: if ($target eq 'web') {
187: my $output=&Apache::lonxml::endredirection;
188: $output =~ s/\"/\"\;/g;
189: $result = "<a href=\"javascript:newWindow=open(\'\',\'new_W\',\'width=500,height=200,scrollbars=1\');newWindow.document.open(\'text/html\',\'replace\');newWindow.document.writeln(\'<html><head><title>newwindow</title></head><body bgcolor="#FFFFFF"> $output </body></html>\');newWindow.document.close();void(0);\"><sup>*</sup></a>";
190: } elsif ($target eq 'tex') {
191: $result = '}';
192: } else {
193: $result = '';
194: }
195: return $result;
196: }
197:
198: sub start_import {
199: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
200: my $bodytext=$$parser[$#$parser]->get_text("/import");
201: my $result ="";
202:
203: $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
204: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
205: my $file=&Apache::lonnet::getfile($location);
206: if ($file == -1) {
207: &Apache::lonxml::error("<b> Unable to find <i>$bodytext $location</i> for import</b>");
208: return "";
209: }
210:
211: my $dir=$location;
212: $dir=~s:/[^/]*$::;
213: # &Apache::lonxml::debug("directory $dir $location file $file \n<b>END</b>\n");
214: &Apache::lonxml::newparser($parser,\$file,$dir);
215:
216: if ($target eq "edit" ) {
217: $result.=&Apache::edit::editfield($token->[1],$bodytext);
218: $result.="Click<a href=\"/res/$bodytext\">here</a> to edit<br />"
219: }
220: return '';
221: }
222:
223: sub end_import {
224: }
225:
226: sub start_meta {
227: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
228: my $result = '';
229: if ($target ne 'meta') {
230: $result = &Apache::lonxml::get_all_text("/meta",$$parser[$#$parser]);
231: $result = '';
232: return $result;
233: } else {
234: return $result;
235: }
236: }
237:
238: sub end_meta {
239: }
240:
241: sub getfilenothere {
242: my ($filename) = @_;
243: my $a="";
244:
245: $filename=~ s/^\s*(\S+)\s*$/$1/; ## strip off leading and trailing spaces
246: $filename="/home/httpd/html/res".$filename;
247: if (! -e $filename ) {
248: &Apache::lonnet::subscribe($filename);
249: &Apache::lonnet::repcopy($filename);
250: }
251: if (! -e $filename ) { return -1; };
252: my $fh=Apache::File->new($filename);
253: while (<$fh>) {
254: $a .=$_;
255: }
256: return $a
257: }
258:
259: 1;
260: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>