File:
[LON-CAPA] /
loncom /
xml /
scripttag.pm
Revision
1.57:
download - view:
text,
annotated -
select for diffs
Mon Nov 12 20:27:28 2001 UTC (22 years, 9 months ago) by
albertel
Branches:
MAIN
CVS tags:
stable_2001_fall,
HEAD
- <import> now puts info in .meta files abut what is being imported
- Apache::inputtags::import exists, list the <import> ids that we are in
- start_response, properly sets the Apache::inputtags::response id to the
join() of Apache::inputtags::import and the id="" arg of the response
- <import> gets an id at publication time
1: # The LearningOnline Network with CAPA
2: # <script> definiton
3: # 2/21 Guy
4: # 8/20 Gerd Kortemeyer
5:
6: package Apache::scripttag;
7:
8: use strict;
9: use Apache::lonnet;
10: use Apache::style;
11:
12: #Globals
13: # this used to pass around the standard callsub arguments to a tag func
14: # so xmlparse can reenter the inner_xmlparse loop.
15:
16: @Apache::scripttag::parser_env = ();
17: sub BEGIN {
18: &Apache::lonxml::register('Apache::scripttag',('script','scriptlib',
19: 'parserlib','import',
20: 'window','display',
21: 'storetc','physnet'));
22: }
23:
24: sub start_script {
25: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
26: @Apache::scripttag::parser_env = @_;
27: my $result='';
28: my $type= &Apache::lonxml::get_param('type',$parstack,$safeeval);
29: &Apache::lonxml::debug("found type of $type");
30: if ($type eq "loncapa/perl") {
31: my $bodytext=&Apache::lonxml::get_all_text("/script",$$parser[$#$parser]);
32: if ( $target eq "modified" ) {
33: $result=$token->[4].&Apache::edit::modifiedfield();
34: } elsif ( $target eq 'web' || $target eq 'tex' ||
35: $target eq 'grade' || $target eq 'answer') {
36: &Apache::run::run($bodytext,$safeeval);
37: if (($ENV{'request.state'} eq 'construct') && ($target eq 'answer')) {
38: $Apache::lonxml::evaluate--;
39: $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"><pre>";
40: my $listing= &Apache::run::dump($target,$safeeval);
41: $listing =~ s/\n/\\n/g;
42: $result.=$listing;
43: $result.= "</pre></body></html>\');newWindow.document.close();void(0);\">Script Vars</a><br />";
44: }
45: } elsif ($target eq "edit" ) {
46: #&Apache::run::run($bodytext,$safeeval);
47: #$result="<br /> <$token->[1]> output: <br />$bodytext<br />Source:<br />";
48: $result=&Apache::edit::tag_start($target,$token,'Script');
49: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',50,4);
50: }
51: } else {
52: if ($target ne "meta") { $result = $token->[4]; }
53: }
54: return $result;
55: }
56:
57: sub end_script {
58: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
59: if ( $target eq "meta" ) { return ''; }
60: my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval);
61: my $result='';
62: #other script blocks need to survive
63: if ($type ne "loncapa/perl") {
64: return $token->[2];
65: } elsif ($target eq 'edit' ) {
66: return &Apache::edit::end_table();
67: } elsif (($ENV{'request.state'} eq 'construct') && ($target eq 'answer')) {
68: $Apache::lonxml::evaluate++;
69: }
70: return '';
71: }
72:
73: sub start_display {
74: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
75:
76: my $result;
77: my $bodytext=&Apache::lonxml::get_all_text("/display",$$parser[$#$parser]);
78:
79: if ( $target eq "modified" ) {
80: $result=$token->[4].&Apache::edit::modifiedfield();
81: } elsif ( $target eq 'web' || $target eq 'tex' ||
82: $target eq 'grade' || $target eq 'answer') {
83: $result=&Apache::run::run($bodytext,$safeeval);
84: if ($target eq 'grade' || $target eq 'answer' ) {
85: $result=''; # grade should produce no output
86: }
87: } elsif ($target eq "edit" ) {
88: #$result =
89: # "<br /> <$token->[1]> output: <br />$bodytext<br />Source:<br />";
90: #$result.=&Apache::edit::editfield($token->[1],$bodytext,'',40,1);
91: $result=&Apache::edit::tag_start($target,$token,'Script With Display');
92: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',40,1)
93: }
94: return $result;
95: }
96:
97: sub end_display {
98: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
99: if ($target eq 'edit' ) { return &Apache::edit::end_table(); }
100: return '';
101: }
102:
103: sub start_scriptlib {
104: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
105: my $bodytext;
106: my $result ='';
107: my $error='';
108:
109: if ($target eq 'web' || $target eq 'grade' || $target eq 'meta' || $target eq 'edit' || $target eq 'answer') {
110: $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
111: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
112: $$parstack[$#$parstack]);
113: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
114: $bodytext);
115: my $script=&Apache::lonnet::getfile($location);
116: if ($script == -1) {
117: if ($target eq 'edit') {
118: $error='</tr><tr><td>Errors</td><td colspan="2"><b> Unable to find <i>'.$location.'</i></b></td>'."\n";
119: } else {
120: &Apache::lonxml::error("<b> Unable to find <i>$location</i> for scriptlib</b>");
121: return "";
122: }
123: }
124: &Apache::run::run($script,$safeeval);
125: #&Apache::lonxml::debug("ran $bodytext:<br />".&Apache::lonnet::getfile($bodytext)."<br />");
126: }
127: if ($target eq "edit" ) {
128: $result=
129: &Apache::edit::tag_start($target,$token,'New Script Functions').
130: &Apache::edit::editfield($token->[1],$bodytext,'',40,1).
131: $error.'</td></tr>'.
132: &Apache::edit::end_table();
133: }
134: if ($target eq "modified" ) {
135: $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
136: $result=&Apache::edit::modifiedfield($token);
137: &Apache::lonxml::debug($result);
138: }
139: return $result;
140: }
141:
142: sub end_scriptlib {
143: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
144: my @result;
145: if ($target eq "edit" ) { $result[1]='no'; }
146: return @result;
147: }
148:
149: sub start_parserlib {
150: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
151: my $bodytext;
152: my $result ="";
153: my $error='';
154: if ($target eq 'web' || $target eq 'grade' || $target eq 'meta' || $target eq 'edit' || $target eq 'answer') {
155: $bodytext=$$parser[$#$parser]->get_text("/parserlib");
156: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
157: $$parstack[$#$parstack]);
158: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
159: $bodytext);
160: my $styletext=&Apache::lonnet::getfile($location);
161: #&Apache::lonxml::debug("found :$bodytext: in :$location: with :$styletext:");
162: if ($styletext == -1) {
163: if ($target eq 'edit') {
164: $error='</tr><tr><td>Errors</td><td colspan="2"><b> Unable to find <i>'.$location.'</i></b></td>'."\n";
165: } else {
166: &Apache::lonxml::error("<b> Unable to find <i>$location</i> for parserlib</b>");
167: return "";
168: }
169: }
170: %$style = ( %$style , &Apache::style::styleparser($target,$styletext));
171: }
172: if ($target eq "edit" ) {
173: $result=
174: &Apache::edit::tag_start($target,$token,'New Tag Definitions').
175: &Apache::edit::editfield($token->[1],$bodytext,'',40,1).
176: $error.'</td></tr>'.
177: &Apache::edit::end_table();
178: }
179: if ($target eq "modified" ) {
180: $bodytext=$$parser[$#$parser]->get_text("/parserlib");
181: $result=&Apache::edit::modifiedfield($token);
182: &Apache::lonxml::debug($result);
183: }
184: return $result;
185: }
186:
187: sub end_parserlib {
188: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
189: my @result;
190: if ($target eq "edit" ) { $result[1]='no'; }
191: return @result;
192: }
193:
194: sub start_window {
195: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
196: my $result = '';
197: if ($target eq 'web') {
198: &Apache::lonxml::startredirection;
199: } elsif ($target eq 'tex') {
200: $result = '\unskip\footnote{';
201: }
202: return $result;
203: }
204:
205: sub end_window {
206: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
207: my $result;
208: if ($target eq 'web') {
209: my $output=&Apache::lonxml::endredirection;
210: $output =~ s/\"/\"\;/g;
211: $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>";
212: } elsif ($target eq 'tex') {
213: $result = '}';
214: } else {
215: $result = '';
216: }
217: return $result;
218: }
219:
220: sub start_import {
221: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
222: my $bodytext=$$parser[$#$parser]->get_text("/import");
223: my $result ="";
224:
225: $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
226:
227: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer') {
228: # FIXME this probably needs to be smart about construction vs.
229: # non construction space.
230: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
231: my $file=&Apache::lonnet::getfile($location);
232: if ($file == -1) {
233: &Apache::lonxml::error("<b> Unable to find <i>$bodytext as $location</i> for import</b>");
234: return "";
235: }
236:
237: my $dir=$location;
238: $dir=~s:/[^/]*$::;
239: # &Apache::lonxml::debug("directory $dir $location file $file \n<b>END</b>\n");
240: my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
241: if (!$id) { $id=$Apache::lonxml::curdepth; }
242: push(@Apache::inputtags::import,$id);
243: &Apache::lonxml::newparser($parser,\$file,$dir);
244: } elsif ($target eq "edit" ) {
245: $result.=&Apache::edit::tag_start($target,$token);
246: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',40,1);
247: #FIXME this need to convert $bodytext to be a contruction space reference
248: #my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
249: #$result.="Click<a href=\"$location\">here</a> to edit<br />"
250: } elsif ($target eq 'modified') {
251: $bodytext=$$parser[$#$parser]->get_text("/import");
252: $result=&Apache::edit::modifiedfield($token);
253: &Apache::lonxml::debug($result);
254: } elsif ($target eq 'meta') {
255: my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
256: $result.='<import part="'.$Apache::inputtags::part;
257: if ($id) {
258: $result.='" id="'.$id;
259: }
260: $result.='">';
261: $result.=$bodytext;
262: $result.='</import>';
263: }
264: return $result;
265: }
266:
267: sub end_import {
268: pop(@Apache::inputtags::import);
269: return '';
270: }
271:
272: sub start_storetc {
273: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
274: my $result = '';
275: &Apache::lonxml::startredirection;
276: return $result;
277: }
278:
279: sub end_storetc {
280: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
281: my $result;
282: my $output=&Apache::lonxml::endredirection;
283: $output =~ s/\"/\"\;/g;
284: $result = '{\bf '.$output.'.}}\write\tcfile{\protect\tcpc{ '.$output.'.}{\the\value{relpage}}}';
285: return $result;
286: }
287:
288:
289: sub start_physnet {
290: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
291: my $bodytext = '/adm/includes/physnet.sty';
292: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
293: my $cbistyletext=&Apache::lonnet::getfile($location);
294:
295: %$style = (%$style,&Apache::style::styleparser($target,$cbistyletext));
296: if ( defined($$style{'physnet'}) ) {
297: &Apache::lonxml::newparser($parser,\$$style{'physnet'});
298: }
299: return "";
300: }
301:
302: sub end_physnet {
303: return '';
304: }
305:
306: sub xmlparse {
307: my ($string) = @_;
308: &Apache::lonxml::debug("Got $string");
309: my ($target,$token,$tagstack,$parstack,$oldparser,$safeeval,$style)=
310: @Apache::scripttag::parser_env;
311: my @parser;
312: &Apache::lonxml::newparser(\@parser,\$string);
313: my $result=&Apache::lonxml::inner_xmlparse($target,$tagstack,
314: $parstack,\@parser,
315: $safeeval,$style);
316: return $result;
317: }
318:
319: 1;
320: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>