1: # The LearningOnline Network with CAPA
2: # <script> definiton
3: #
4: # $Id: scripttag.pm,v 1.158 2011/12/09 22:04:55 www Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::scripttag;
30:
31: use strict;
32: use Apache::lonnet;
33: use Apache::lonlocal;
34: use Apache::style();
35:
36: #Globals
37: # this used to pass around the standard callsub arguments to a tag func
38: # so xmlparse can reenter the inner_xmlparse loop.
39:
40: @Apache::scripttag::parser_env = ();
41: BEGIN {
42: &Apache::lonxml::register('Apache::scripttag',
43: ('script','scriptlib','parserlib','import',
44: 'window','display','storetc','physnet',
45: 'standalone','comment','num','parse','algebra',
46: 'LONCAPA_INTERNAL_TURN_STYLE_ON',
47: 'LONCAPA_INTERNAL_TURN_STYLE_OFF'));
48: }
49:
50: sub start_LONCAPA_INTERNAL_TURN_STYLE_ON {
51: $Apache::lonxml::usestyle=1;
52: $Apache::lonxml::style_values='';
53: return ('','no');
54: }
55:
56: sub end_LONCAPA_INTERNAL_TURN_STYLE_ON {
57: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
58: my $end=&Apache::lonxml::get_param('end',$parstack,$safeeval);
59: if (defined($end)) {
60: &Apache::lonxml::end_tag($tagstack,$parstack,$token);
61: }
62: return ('','no');
63: }
64:
65: sub start_LONCAPA_INTERNAL_TURN_STYLE_OFF {
66: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
67: $Apache::lonxml::usestyle=0;
68: my $end=&Apache::lonxml::get_param('end',$parstack,$safeeval);
69: if (!$end) {
70: $Apache::lonxml::style_values=$$parstack[-1];
71: $Apache::lonxml::style_end_values=$$parstack[-1];
72: } else {
73: $Apache::lonxml::style_values=$Apache::lonxml::style_end_values;
74: $Apache::lonxml::style_end_values='';
75: }
76: return ('','no');
77: }
78:
79: sub end_LONCAPA_INTERNAL_TURN_STYLE_OFF {
80: return ('','no');
81: }
82:
83: sub start_script {
84: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
85: @Apache::scripttag::parser_env = @_;
86: my $result='';
87: my $type= &Apache::lonxml::get_param('type',$parstack,$safeeval);
88: &Apache::lonxml::debug("found type of $type");
89: if ($type eq "loncapa/perl") {
90: if ( $target eq "modified" ) {
91: $result=$token->[4].&Apache::edit::modifiedfield('/script',$parser);
92: } elsif ( $target eq 'web' || $target eq 'tex' ||
93: $target eq 'grade' || $target eq 'webgrade' ||
94: $target eq 'answer' || $target eq 'analyze' ) {
95: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
96: if (!$Apache::lonxml::default_homework_loaded) {
97: &Apache::lonxml::default_homework_load($safeeval);
98: }
99: &Apache::run::run($bodytext,$safeeval);
100: if (($target eq 'answer') &&
101: ($env{'form.answer_output_mode'} ne 'tex') &&
102: ($Apache::lonhomework::viewgrades == 'F')) {
103: $Apache::lonxml::evaluate--;
104: my (undef,undef,$udom,$uname)=&Apache::lonnet::whichuser();
105: my $windowopen=&Apache::lonhtmlcommon::javascript_docopen();
106: my $start_page =
107: &Apache::loncommon::start_page('Script Vars', undef,
108: {'only_body' => 1,
109: 'bgcolor' => '#FFFFFF',
110: 'js_ready' => 1,});
111: my $end_page =
112: &Apache::loncommon::end_page({'js_ready' => 1,});
113:
114: $uname =~s/\W//g;
115: $udom =~s/\W//g;
116: my $function_name =
117: join('_','LONCAPA_scriptvars',$uname,$udom,
118: $env{'form.counter'},$Apache::lonxml::curdepth);
119: my $scriptblocklog=$start_page.
120: &Apache::loncommon::start_scrollbox('500px','480px','480px').
121: '<pre>'.&Apache::run::dump($target,$safeeval).'</pre>'.
122: &Apache::loncommon::end_scrollbox().
123: $end_page;
124: $scriptblocklog=~s/\'/\\'/gs;
125: &Apache::lonxml::add_script_result(
126: &Apache::loncommon::modal_adhoc_script($function_name,500,500,$scriptblocklog).
127: "<a href=\"javascript:$function_name();void(0);\">".&mt('Script Vars')."</a><br />"
128: );
129: }
130: } elsif ($target eq "edit" ) {
131: #&Apache::run::run($bodytext,$safeeval);
132: #$result="<br /> <$token->[1]> output: <br />$bodytext<br />Source:<br />";
133: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
134: $result=&Apache::edit::tag_start($target,$token,'Script');
135: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,4);
136: } elsif ($target eq 'meta') {
137: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
138: }
139: } else {
140: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
141: if ($target ne "meta" && $target ne 'tex' && $target ne 'answer') {
142: $result = $token->[4];
143: $result.=$bodytext;
144: }
145: }
146: return $result;
147: }
148:
149: sub end_script {
150: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
151: if ( $target eq "meta" ) { return ''; }
152: my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval);
153: my $result='';
154: #other script blocks need to survive
155: if ($type ne "loncapa/perl" && $target ne 'tex') {
156: return $token->[2];
157: } elsif ($target eq 'edit' ) {
158: return &Apache::edit::end_table();
159: } elsif ($target eq 'answer') {
160: $Apache::lonxml::evaluate++;
161: }
162: return '';
163: }
164:
165: sub start_display {
166: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
167: @Apache::scripttag::parser_env = @_;
168: my $result;
169:
170: if ( $target eq "modified" ) {
171: $result=$token->[4].&Apache::edit::modifiedfield("/display",$parser);
172: } elsif ( $target eq 'web' || $target eq 'tex' ||
173: $target eq 'grade' || $target eq 'webgrade' ||
174: $target eq 'answer' || $target eq 'analyze') {
175: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/display",$parser);
176: if (!$Apache::lonxml::default_homework_loaded) {
177: &Apache::lonxml::default_homework_load($safeeval);
178: }
179: $result=&Apache::run::run($bodytext,$safeeval);
180: if ($target eq 'grade' || $target eq 'answer' ||
181: $target eq 'analyze') {
182: # grade/answer/analyxe should produce no output but if we
183: # are redirecting, the redirecter should know what to do
184: # with the output
185: if (!$Apache::lonxml::redirection) { $result=''; }
186: }
187: $Apache::lonxml::post_evaluate=0;
188: } elsif ($target eq "edit" ) {
189: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/display",$parser);
190: #$result =
191: # "<br /> <$token->[1]> output: <br />$bodytext<br />Source:<br />";
192: #$result.=&Apache::edit::editfield($token->[1],$bodytext,'',40,1);
193: $result=&Apache::edit::tag_start($target,$token,'Script With Display');
194: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,1)
195: } elsif ($target eq 'meta') {
196: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/display",$parser);
197: }
198: return $result;
199: }
200:
201: sub end_display {
202: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
203: if ($target eq 'edit' ) { return &Apache::edit::end_table(); }
204: return '';
205: }
206:
207: sub start_scriptlib {
208: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
209: my $bodytext;
210: my $result ='';
211: my $error='';
212:
213: if ($target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
214: $target eq 'meta' || $target eq 'edit' || $target eq 'answer' ||
215: $target eq 'analyze' || $target eq 'webgrade') {
216: $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
217: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
218: $$parstack[$#$parstack]);
219: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
220: $bodytext);
221: my $script=&Apache::lonnet::getfile($location);
222: if ($script == -1) {
223: if ($target eq 'edit') {
224: $error='</tr><tr><td>'.&mt('Errors').'</td><td colspan="2"><b>'.&mt(' Unable to find [_1]','<span class="LC_filename">'.$location.'</span>').'</b></td>'."\n";
225: } else {
226: &Apache::lonxml::error("<b> Unable to find <i>$location</i> for scriptlib</b>");
227: return "";
228: }
229: }
230: &Apache::run::run($script,$safeeval);
231: #&Apache::lonxml::debug("ran $bodytext:<br />".&Apache::lonnet::getfile($bodytext)."<br />");
232: }
233: if ($target eq "edit" ) {
234: $result=
235: &Apache::edit::tag_start($target,$token,'New Script Functions').
236: &Apache::edit::editline($token->[1],$bodytext,'scriptlib',40).
237: &Apache::edit::browse(undef,'textnode').
238: $error.'</td></tr>'.
239: &Apache::edit::end_table();
240: }
241: if ($target eq "modified" ) {
242: $result=$token->[4].&Apache::edit::modifiedfield("/scriptlib",$parser);
243: }
244: return $result;
245: }
246:
247: sub end_scriptlib {
248: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
249: my @result;
250: if ($target eq "edit" ) { $result[1]='no'; }
251: return @result;
252: }
253:
254: sub start_parserlib {
255: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
256: my $bodytext;
257: my $result ="";
258: my $error='';
259: if ($target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
260: $target eq 'meta' || $target eq 'edit' || $target eq 'answer' ||
261: $target eq 'analyze' || $target eq 'webgrade') {
262: $bodytext=$$parser[$#$parser]->get_text("/parserlib");
263: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
264: $$parstack[$#$parstack]);
265: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
266: $bodytext);
267: my $styletext=&Apache::lonnet::getfile($location);
268: #&Apache::lonxml::debug("found :$bodytext: in :$location: with :$styletext:");
269: if ($styletext == -1) {
270: if ($target eq 'edit') {
271: $error='</tr><tr><td>Errors</td><td colspan="2"><b> Unable to find <i>'.$location.'</i></b></td>'."\n";
272: } else {
273: &Apache::lonxml::error("<b> Unable to find <i>$location</i> for parserlib</b>");
274: return "";
275: }
276: }
277: %$style = ( %$style , &Apache::style::styleparser($target,$styletext));
278: }
279: if ($target eq "edit" ) {
280: $result=
281: &Apache::edit::tag_start($target,$token,'New Tag Definitions').
282: &Apache::edit::editline($token->[1],$bodytext,'',40).
283: $error.'</td></tr>'.
284: &Apache::edit::end_table();
285: }
286: if ($target eq "modified" ) {
287: $result=$token->[4].&Apache::edit::modifiedfield("/parserlib",$parser);
288: }
289: return $result;
290: }
291:
292: sub end_parserlib {
293: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
294: my @result;
295: if ($target eq "edit" ) { $result[1]='no'; }
296: return @result;
297: }
298:
299: sub start_window {
300: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
301: my $result = '';
302: if ($target eq 'web' || $target eq 'webgrade') {
303: &Apache::lonxml::startredirection;
304: } elsif ($target eq 'tex') {
305: $result = '\unskip\footnote{';
306: } elsif ($target eq 'edit') {
307: $result.=&Apache::edit::tag_start($target,$token);
308: $result.=&Apache::edit::text_arg('Text of Link:','linktext',$token,70);
309: $result.=&Apache::edit::text_arg('Height:','height',$token,5);
310: $result.=&Apache::edit::text_arg('Width:','width',$token,5);
311: $result.=&Apache::edit::text_arg('Mime Type:','mimetype',$token,5);
312: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
313: } elsif ($target eq 'modified') {
314: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
315: $safeeval,'linktext',
316: 'width','height',
317: 'mimetype');
318: if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
319: }
320: return $result;
321: }
322:
323: sub end_window {
324: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
325: my $result;
326: if ($target eq 'web' || $target eq 'webgrade') {
327: my $output=&Apache::lonxml::endredirection;
328: $output =~ s/[\n\r]/ /g;
329: # $output = &HTML::Entities::encode($output,'<>&"\'');
330: $output =~ s/\'/\\\'/g;
331: my $linktext= &Apache::lonxml::get_param('linktext',$parstack,$safeeval);
332: if (!$linktext) { $linktext='<sup>*</sup>'; }
333: my $width= &Apache::lonxml::get_param('width',$parstack,$safeeval);
334: if (!$width) { $width='500'; }
335: my $height= &Apache::lonxml::get_param('height',$parstack,$safeeval);
336: if (!$height) { $height='200'; }
337: my $mimetype= &Apache::lonxml::get_param('mimetype',$parstack,$safeeval)
338: || 'text/html';
339:
340: my ($start_page,$end_page);
341: if ($mimetype eq 'text/html') {
342: $start_page =
343: &Apache::loncommon::start_page($linktext, undef,
344: {'only_body' => 1,
345: 'bgcolor' => '#FFFFFF',
346: 'js_ready' => 1,});
347: $end_page =
348: &Apache::loncommon::end_page({'js_ready' => 1,});
349: }
350: $result = "<script type=\"text/javascript\">
351: //<!--
352: function LONCAPA_newwindow_$Apache::lonxml::curdepth() {
353: newWindow=open(".&Apache::lonhtmlcommon::javascript_nothing().",'new_W');
354: newWindow.close();
355: newWindow=open(".&Apache::lonhtmlcommon::javascript_nothing().",'new_W','width=$width,height=$height,scrollbars=1');
356: newWindow.".&Apache::lonhtmlcommon::javascript_docopen($mimetype).";
357: newWindow.document.writeln('$start_page $output $end_page');
358: newWindow.document.close();}
359: //-->
360: </script><a href=\"javascript:LONCAPA_newwindow_$Apache::lonxml::curdepth();void(0);\">$linktext</a>";
361: } elsif ($target eq 'tex') {
362: $result = '}';
363: } else {
364: $result = '';
365: }
366: return $result;
367: }
368:
369: sub start_import {
370: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
371: my $bodytext=$$parser[$#$parser]->get_text("/import");
372: my $result ="";
373:
374: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
375:
376: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade'
377: || $target eq 'answer' || $target eq 'tex' || $target eq 'analyze' ) {
378: # FIXME this probably needs to be smart about construction vs.
379: # non construction space.
380: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
381: my $file=&Apache::lonnet::getfile($location);
382: if ($file == -1) {
383: &Apache::lonxml::error("<b> Unable to find <i>$bodytext as $location</i> for import</b>");
384: return "";
385: }
386: my $importmode=&Apache::lonxml::get_param('importmode',$parstack,$safeeval);
387: if (($importmode eq 'problem') || ($importmode eq 'part')) {
388: # We are using import to import published problems
389: if (($importmode eq 'problem') || ($file=~/<part[^<]*>/s)) {
390: # We explicitly don't want this to be a separate part or the problem already has parts
391: $file=~s/^\s*<problem>/<library>/s;
392: $file=~s/<\/problem>\s*$/<\/library>/s;
393: } else {
394: # We want this to be a separate part, but it currently is not
395: $file=~s/^\s*<problem>/<library><part>/s;
396: $file=~s/<\/problem>\s*$/<\/part><\/library>/s;
397: }
398: }
399: my $dir=$location;
400: $dir=~s:/[^/]*$::;
401: # &Apache::lonxml::debug("directory $dir $location file $file \n<b>END</b>\n");
402: my $id= &Apache::lonxml::get_id($parstack,$safeeval);
403: if (!$id) { $id=$Apache::lonxml::curdepth; }
404: push(@Apache::inputtags::import,$id);
405: push(@Apache::inputtags::importlist,$id);
406:
407: &Apache::lonxml::newparser($parser,\$file,$dir);
408:
409: } elsif ($target eq "edit" ) {
410: $result.=&Apache::edit::tag_start($target,$token);
411: my $location=$token->[1];
412: $location=~s/^\s*//s;
413: $location=~s/\s*$//s;
414: $result.=&Apache::edit::editline($location,$bodytext,'',40);
415: $result.=&Apache::edit::browse(undef,'textnode');
416: $result.= ' <label>'.&mt('Import as:').
417: '<select name="importmode_'.$Apache::lonxml::curdepth.'">';
418: my %options=&Apache::lonlocal::texthash('' => 'as standard library',
419: 'problem' => 'as problem',
420: 'part' => 'as problem part(s)');
421: foreach my $option (sort(keys(%options))) {
422: $result.='<option value="'.$option.'"';
423: if ($option eq &Apache::lonxml::get_param('importmode',$parstack,$safeeval)) {
424: $result.=' selected="selected"';
425: }
426: $result.='>'.$options{$option}.'</option>';
427: }
428: $result.='</select></label>';
429: #FIXME this need to convert $bodytext to be a contruction space reference
430: #my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
431: #$result.="Click<a href=\"$location\">here</a> to edit<br />"
432: } elsif ($target eq 'modified') {
433: &Apache::edit::get_new_args($token,$parstack,$safeeval,'importmode');
434: $result='<import id="'.$token->[2]{'id'}.'" importmode="'.$token->[2]{'importmode'}.'">';
435: $result.=&Apache::edit::modifiedfield("/import",$parser);
436: } elsif ($target eq 'meta') {
437: my $id= &Apache::lonxml::get_id($parstack,$safeeval);
438: $result.='<import part="'.$Apache::inputtags::part;
439: if ($id) {
440: $result.='" id="'.$id;
441: }
442: $result.='" importmode="'.$token->[2]{'importmode'}.'">';
443: $result.=$bodytext;
444: $result.='</import>';
445: }
446: return $result;
447: }
448:
449: sub end_import {
450: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
451: pop(@Apache::inputtags::import);
452: my $result;
453: if ($target eq 'edit' ) { $result=&Apache::edit::end_row.
454: &Apache::edit::end_table(); }
455: return $result;
456: }
457:
458: sub start_storetc {
459: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
460: my $result = '';
461: &Apache::lonxml::startredirection;
462: return $result;
463: }
464:
465: sub end_storetc {
466: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
467: my $result;
468: my $output=&Apache::lonxml::endredirection;
469: $output =~ s/\"/\"\;/g;
470: $result = '{\bf '.$output.'.}}\write\tcfile{\protect\tcpc{ '.$output.'.}{\the\value{relpage}}}';
471: return $result;
472: }
473:
474:
475: sub start_physnet {
476: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
477: my $bodytext = '/adm/includes/physnet.sty';
478: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
479: my $cbistyletext=&Apache::lonnet::getfile($location);
480:
481: %$style = (%$style,&Apache::style::styleparser($target,$cbistyletext));
482: $$parser['-1']->unget_token($token);
483: # if ( defined($$style{'physnet'}) ) {
484: # &Apache::lonxml::newparser($parser,\$$style{'physnet'});
485: # }
486: return "";
487: }
488:
489: sub end_physnet {
490: return '';
491: }
492:
493: sub start_standalone {
494: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
495: my $result='';
496: if ($target eq 'web' || $target eq 'webgrade') {
497: if ( $env{'request.course.id'} ) {
498: my $inside = &Apache::lonxml::get_all_text("/standalone",$parser,$style);
499: } else {
500: $result='<table bgcolor="#E1E1E1" border="2"><tr><td>';
501: }
502: }
503: return $result;
504: }
505:
506: sub end_standalone {
507: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
508: my $result='';
509: if ($target eq 'web' || $target eq 'webgrade' ) {
510: if ( $env{'request.course.id'} ) {
511: } else {
512: $result='</td></tr></table>';
513: }
514: }
515: return $result;
516: }
517:
518: sub start_comment {
519: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
520: my $result='';
521: if ($target eq 'edit') {
522: $result=&Apache::edit::tag_start($target,$token);
523: my $bodytext=&Apache::lonxml::get_all_text("/comment",$parser,$style);
524: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,4)
525: } elsif ( $target eq 'modified') {
526: $result=$token->[4].&Apache::edit::modifiedfield("/comment",$parser);
527: } elsif ( $target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
528: $target eq 'answer' || $target eq 'meta' || $target eq 'analyze' ||
529: $target eq 'webgrade') {
530: #normally throw away comments
531: my $bodytext=&Apache::lonxml::get_all_text("/comment",$parser,$style);
532: }
533: return $result;
534: }
535:
536: sub end_comment {
537: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
538: if ($target eq 'edit' ) { return &Apache::edit::end_table(); }
539: return '';
540: }
541:
542:
543: sub xmlparse {
544: my ($string) = @_;
545: &Apache::lonxml::debug("xmlparse recursion starting with $string");
546: # Apache::run::evaluate does an 'eval' on the name of the subroutine
547: # if it detects something that looks like a subroutine, this ends up calling
548: # things without any arguments and since perl is nice enough to pass
549: # along the default arguments when you don't explicitly say no arguments
550: # if you call &xmlparse, it gets &xmlparse passed as it argument.
551: # Same thing soccurs with &chemparse.
552: if ($string eq '&xmlparse') { return '&xmlparse'; }
553: if ($string eq '&chemparse') { return '&chemparse'; }
554: my ($target,$token,$tagstack,$parstack,$oldparser,$safeeval,$style)=
555: @Apache::scripttag::parser_env;
556: my @parser;
557: &Apache::lonxml::newparser(\@parser,\$string);
558: &Apache::lonxml::startredirection();
559: my $result=&Apache::lonxml::inner_xmlparse($target,$tagstack,
560: $parstack,\@parser,
561: $safeeval,$style);
562: $result.=&Apache::lonxml::endredirection();
563: &Apache::lonxml::debug("target is $target xmlparse recursion ending with $result");
564: return $result;
565: }
566:
567: sub start_num {
568: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
569: my $result = '';
570: my $inside = &Apache::lonxml::get_all_text_unbalanced("/num",$parser);
571: if ($target eq 'tex' || $target eq 'web' || $target eq 'webgrade') {
572: $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
573: if (!$Apache::lonxml::default_homework_loaded) {
574: &Apache::lonxml::default_homework_load($safeeval);
575: }
576: @Apache::scripttag::parser_env = @_;
577: my $format=&Apache::lonxml::get_param('format',$parstack,$safeeval);
578: $result=&Apache::run::run("return &prettyprint(q\0$inside\0,q\0$format\0);",$safeeval);
579: }
580: return $result;
581: }
582:
583: sub end_num {
584: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
585: my $result = '';
586: return $result;
587: }
588:
589: sub start_parse {
590: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
591: my $result = '';
592: if ( $target eq 'web' || $target eq 'tex' ||
593: $target eq 'grade' || $target eq 'answer' ||
594: $target eq 'analyze'|| $target eq 'webgrade') {
595: my $inside = &Apache::lonxml::get_all_text_unbalanced("/parse",$parser);
596: $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
597: if (!$Apache::lonxml::default_homework_loaded) {
598: &Apache::lonxml::default_homework_load($safeeval);
599: }
600: @Apache::scripttag::parser_env = @_;
601: $result=&Apache::run::run("return &xmlparse(q\0$inside\0);",$safeeval);
602: if ($target eq 'grade' || $target eq 'answer' ||
603: $target eq 'analyze') {
604: # grade/answer/analyxe should produce no output but if we
605: # are redirecting, the redirecter should know what to do
606: # with the output
607: if (!$Apache::lonxml::redirection) { $result=''; }
608: }
609: }
610: return $result;
611: }
612:
613: sub end_parse {
614: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
615: my $result = '';
616: return $result;
617: }
618:
619: sub start_algebra {
620: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
621: my $result = '';
622: if ( $target eq 'web' || $target eq 'tex' ||
623: $target eq 'grade' || $target eq 'answer' ||
624: $target eq 'analyze' || $target eq 'webgrade') {
625: my $inside = &Apache::lonxml::get_all_text_unbalanced("/algebra",$parser);
626: $inside = &Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
627: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
628: my $style=&Apache::lonxml::get_param('style',$parstack,$safeeval);
629: $result=&Apache::lontexconvert::algebra($inside,$target,$style,$parstack,$safeeval);
630: }
631: $Apache::lonxml::post_evaluate=0;
632: }
633: return $result;
634: }
635:
636: sub end_algebra {
637: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
638: my $result = '';
639: return $result;
640: }
641:
642: 1;
643: __END__
644:
645: =pod
646:
647: =head1 NAME
648:
649: Apache::scripttag.pm
650:
651: =head1 SYNOPSIS
652:
653: implements <script>, <scriptlib>, <parserlib>,
654: and <import>
655:
656: This is part of the LearningOnline Network with CAPA project
657: described at http://www.lon-capa.org.
658:
659: =cut
660:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>