Annotation of loncom/xml/scripttag.pm, revision 1.143
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # <script> definiton
1.58 www 3: #
1.143 ! albertel 4: # $Id: scripttag.pm,v 1.142 2007/08/03 23:29:54 albertel Exp $
1.58 www 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: #
1.116 www 28:
1.47 albertel 29: package Apache::scripttag;
1.1 albertel 30:
31: use strict;
1.3 albertel 32: use Apache::lonnet;
1.42 sakharuk 33: use Apache::style;
1.1 albertel 34:
1.47 albertel 35: #Globals
36: # this used to pass around the standard callsub arguments to a tag func
37: # so xmlparse can reenter the inner_xmlparse loop.
38:
39: @Apache::scripttag::parser_env = ();
1.61 harris41 40: BEGIN {
1.62 albertel 41: &Apache::lonxml::register('Apache::scripttag',
42: ('script','scriptlib','parserlib','import',
43: 'window','display','storetc','physnet',
1.123 albertel 44: 'standalone','comment','num','parse','algebra',
1.86 albertel 45: 'LONCAPA_INTERNAL_TURN_STYLE_ON',
1.100 albertel 46: 'LONCAPA_INTERNAL_TURN_STYLE_OFF',
1.86 albertel 47: 'LONCAPA_INTERNAL_LONHTTPD_PORT'));
1.81 albertel 48: }
49:
50: sub start_LONCAPA_INTERNAL_TURN_STYLE_ON {
51: $Apache::lonxml::usestyle=1;
1.89 albertel 52: $Apache::lonxml::style_values='';
1.81 albertel 53: return ('','no');
54: }
55:
56: sub end_LONCAPA_INTERNAL_TURN_STYLE_ON {
1.91 albertel 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: }
1.100 albertel 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 {
1.86 albertel 80: return ('','no');
81: }
82:
1.143 ! albertel 83: =pod
! 84:
! 85: =item start_LONCAPA_INTERNAL_LONHTTPD_PORT
! 86:
! 87: emits a pice of javascript that says a global js variable to the
! 88: current lonhttp port, currently used by the remote control to find out
! 89: where to load images from
! 90:
! 91: =cut
! 92:
1.86 albertel 93: sub start_LONCAPA_INTERNAL_LONHTTPD_PORT {
94: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.137 albertel 95: if ($target eq 'web' || $target eq 'webgrade') {
1.86 albertel 96: return '<script type="text/javascript">var lonhttpdport=\''.
1.143 ! albertel 97: &Apache::loncommon::lonhttpd_port().'\';</script>';
1.86 albertel 98: }
99: return ('','no');
100: }
101:
102: sub end_LONCAPA_INTERNAL_LONHTTPD_PORT {
1.81 albertel 103: return ('','no');
1.1 albertel 104: }
105:
106: sub start_script {
1.40 albertel 107: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.47 albertel 108: @Apache::scripttag::parser_env = @_;
1.24 albertel 109: my $result='';
1.39 albertel 110: my $type= &Apache::lonxml::get_param('type',$parstack,$safeeval);
111: &Apache::lonxml::debug("found type of $type");
1.17 albertel 112: if ($type eq "loncapa/perl") {
113: if ( $target eq "modified" ) {
1.103 albertel 114: $result=$token->[4].&Apache::edit::modifiedfield('/script',$parser);
1.54 albertel 115: } elsif ( $target eq 'web' || $target eq 'tex' ||
1.130 albertel 116: $target eq 'grade' || $target eq 'webgrade' ||
117: $target eq 'answer' || $target eq 'analyze' ) {
1.107 albertel 118: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
1.79 albertel 119: if (!$Apache::lonxml::default_homework_loaded) {
120: &Apache::lonxml::default_homework_load($safeeval);
121: }
122: &Apache::run::run($bodytext,$safeeval);
1.88 albertel 123: if (($target eq 'answer') &&
1.126 albertel 124: ($env{'form.answer_output_mode'} ne 'tex') &&
1.88 albertel 125: ($Apache::lonhomework::viewgrades == 'F')) {
1.79 albertel 126: $Apache::lonxml::evaluate--;
1.138 albertel 127: my (undef,undef,$udom,$uname)=&Apache::lonnet::whichuser();
1.118 www 128: my $windowopen=&Apache::lonhtmlcommon::javascript_docopen();
1.135 albertel 129: my $start_page =
130: &Apache::loncommon::start_page('Script Vars', undef,
131: {'only_body' => 1,
132: 'bgcolor' => '#FFFFFF',
133: 'js_ready' => 1,});
134: my $end_page =
135: &Apache::loncommon::end_page({'js_ready' => 1,});
136:
1.140 albertel 137: $uname =~s/\W//g;
138: $udom =~s/\W//g;
1.141 albertel 139: my $script_var ="<script type=\"text/javascript\">
1.124 albertel 140: // <![CDATA[
1.135 albertel 141: function LONCAPA_scriptvars_".$uname."_".$udom."_"."$Apache::lonxml::curdepth() {newWindow=open('','new_W','width=500,height=500,scrollbars=1,resizable=yes');newWindow.$windowopen;newWindow.document.writeln('$start_page<pre>";
1.99 albertel 142: my $listing=&Apache::run::dump($target,$safeeval);
1.128 albertel 143: $listing=~s/\\/\\\\/g;
1.99 albertel 144: $listing=~s/\'/\\\'/g;
1.141 albertel 145: $script_var.=$listing;
146: $script_var.= "<\\/pre>$end_page');newWindow.document.close();newWindow.focus()}
1.124 albertel 147: // ]]>
1.121 albertel 148: </script><a href=\"javascript:LONCAPA_scriptvars_".$uname."_".$udom."_$Apache::lonxml::curdepth();void(0);\">Script Vars</a><br />";
1.141 albertel 149: &Apache::lonxml::add_script_result($script_var);
1.79 albertel 150: }
1.28 albertel 151: } elsif ($target eq "edit" ) {
1.41 albertel 152: #&Apache::run::run($bodytext,$safeeval);
153: #$result="<br /> <$token->[1]> output: <br />$bodytext<br />Source:<br />";
1.107 albertel 154: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
1.103 albertel 155: $result=&Apache::edit::tag_start($target,$token,'Script');
156: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,4);
1.107 albertel 157: } elsif ($target eq 'meta') {
158: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
1.17 albertel 159: }
160: } else {
1.108 matthew 161: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
1.115 albertel 162: if ($target ne "meta" && $target ne 'tex') {
1.112 albertel 163: $result = $token->[4];
164: $result.=$bodytext;
165: }
1.13 albertel 166: }
1.24 albertel 167: return $result;
1.17 albertel 168: }
1.13 albertel 169:
1.17 albertel 170: sub end_script {
1.40 albertel 171: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.28 albertel 172: if ( $target eq "meta" ) { return ''; }
1.39 albertel 173: my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval);
1.29 albertel 174: my $result='';
175: #other script blocks need to survive
1.115 albertel 176: if ($type ne "loncapa/perl" && $target ne 'tex') {
1.53 albertel 177: return $token->[2];
178: } elsif ($target eq 'edit' ) {
179: return &Apache::edit::end_table();
1.78 albertel 180: } elsif ($target eq 'answer') {
1.53 albertel 181: $Apache::lonxml::evaluate++;
182: }
1.28 albertel 183: return '';
1.24 albertel 184: }
185:
186: sub start_display {
1.40 albertel 187: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.119 albertel 188: @Apache::scripttag::parser_env = @_;
1.48 albertel 189: my $result;
1.39 albertel 190:
1.24 albertel 191: if ( $target eq "modified" ) {
1.103 albertel 192: $result=$token->[4].&Apache::edit::modifiedfield("/display",$parser);
1.54 albertel 193: } elsif ( $target eq 'web' || $target eq 'tex' ||
1.130 albertel 194: $target eq 'grade' || $target eq 'webgrade' ||
195: $target eq 'answer' || $target eq 'analyze') {
1.107 albertel 196: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/display",$parser);
1.80 albertel 197: if (!$Apache::lonxml::default_homework_loaded) {
198: &Apache::lonxml::default_homework_load($safeeval);
199: }
200: $result=&Apache::run::run($bodytext,$safeeval);
201: if ($target eq 'grade' || $target eq 'answer' ||
202: $target eq 'analyze') {
1.114 albertel 203: # grade/answer/analyxe should produce no output but if we
204: # are redirecting, the redirecter should know what to do
205: # with the output
206: if (!$Apache::lonxml::redirection) { $result=''; }
1.80 albertel 207: }
1.101 albertel 208: $Apache::lonxml::post_evaluate=0;
1.48 albertel 209: } elsif ($target eq "edit" ) {
1.110 albertel 210: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/display",$parser);
1.48 albertel 211: #$result =
212: # "<br /> <$token->[1]> output: <br />$bodytext<br />Source:<br />";
213: #$result.=&Apache::edit::editfield($token->[1],$bodytext,'',40,1);
214: $result=&Apache::edit::tag_start($target,$token,'Script With Display');
1.77 albertel 215: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,1)
1.107 albertel 216: } elsif ($target eq 'meta') {
217: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/display",$parser);
1.24 albertel 218: }
219: return $result;
220: }
221:
222: sub end_display {
1.48 albertel 223: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
224: if ($target eq 'edit' ) { return &Apache::edit::end_table(); }
225: return '';
1.1 albertel 226: }
1.3 albertel 227:
228: sub start_scriptlib {
1.40 albertel 229: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.37 albertel 230: my $bodytext;
231: my $result ='';
232: my $error='';
233:
1.106 albertel 234: if ($target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
235: $target eq 'meta' || $target eq 'edit' || $target eq 'answer' ||
1.137 albertel 236: $target eq 'analyze' || $target eq 'webgrade') {
1.37 albertel 237: $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
238: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
239: $$parstack[$#$parstack]);
240: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
241: $bodytext);
242: my $script=&Apache::lonnet::getfile($location);
243: if ($script == -1) {
244: if ($target eq 'edit') {
245: $error='</tr><tr><td>Errors</td><td colspan="2"><b> Unable to find <i>'.$location.'</i></b></td>'."\n";
246: } else {
247: &Apache::lonxml::error("<b> Unable to find <i>$location</i> for scriptlib</b>");
248: return "";
249: }
250: }
251: &Apache::run::run($script,$safeeval);
252: #&Apache::lonxml::debug("ran $bodytext:<br />".&Apache::lonnet::getfile($bodytext)."<br />");
1.18 albertel 253: }
1.13 albertel 254: if ($target eq "edit" ) {
1.37 albertel 255: $result=
1.49 albertel 256: &Apache::edit::tag_start($target,$token,'New Script Functions').
1.83 matthew 257: &Apache::edit::editline($token->[1],$bodytext,'scriptlib',40).
258: &Apache::edit::browse(undef,'textnode').
1.49 albertel 259: $error.'</td></tr>'.
260: &Apache::edit::end_table();
1.37 albertel 261: }
262: if ($target eq "modified" ) {
1.103 albertel 263: $result=$token->[4].&Apache::edit::modifiedfield("/scriptlib",$parser);
1.3 albertel 264: }
265: return $result;
266: }
267:
1.37 albertel 268: sub end_scriptlib {
1.40 albertel 269: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.49 albertel 270: my @result;
271: if ($target eq "edit" ) { $result[1]='no'; }
272: return @result;
1.37 albertel 273: }
1.4 albertel 274:
275: sub start_parserlib {
1.40 albertel 276: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.37 albertel 277: my $bodytext;
1.7 albertel 278: my $result ="";
1.37 albertel 279: my $error='';
1.106 albertel 280: if ($target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
281: $target eq 'meta' || $target eq 'edit' || $target eq 'answer' ||
1.137 albertel 282: $target eq 'analyze' || $target eq 'webgrade') {
1.37 albertel 283: $bodytext=$$parser[$#$parser]->get_text("/parserlib");
284: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
285: $$parstack[$#$parstack]);
286: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
287: $bodytext);
288: my $styletext=&Apache::lonnet::getfile($location);
289: #&Apache::lonxml::debug("found :$bodytext: in :$location: with :$styletext:");
290: if ($styletext == -1) {
291: if ($target eq 'edit') {
292: $error='</tr><tr><td>Errors</td><td colspan="2"><b> Unable to find <i>'.$location.'</i></b></td>'."\n";
293: } else {
294: &Apache::lonxml::error("<b> Unable to find <i>$location</i> for parserlib</b>");
295: return "";
296: }
297: }
298: %$style = ( %$style , &Apache::style::styleparser($target,$styletext));
1.18 albertel 299: }
1.13 albertel 300: if ($target eq "edit" ) {
1.37 albertel 301: $result=
1.49 albertel 302: &Apache::edit::tag_start($target,$token,'New Tag Definitions').
1.68 albertel 303: &Apache::edit::editline($token->[1],$bodytext,'',40).
1.49 albertel 304: $error.'</td></tr>'.
305: &Apache::edit::end_table();
1.37 albertel 306: }
307: if ($target eq "modified" ) {
1.103 albertel 308: $result=$token->[4].&Apache::edit::modifiedfield("/parserlib",$parser);
1.7 albertel 309: }
310: return $result;
1.4 albertel 311: }
312:
313: sub end_parserlib {
1.40 albertel 314: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.49 albertel 315: my @result;
316: if ($target eq "edit" ) { $result[1]='no'; }
317: return @result;
1.6 albertel 318: }
319:
1.30 sakharuk 320: sub start_window {
1.105 albertel 321: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
322: my $result = '';
1.137 albertel 323: if ($target eq 'web' || $target eq 'webgrade') {
1.105 albertel 324: &Apache::lonxml::startredirection;
325: } elsif ($target eq 'tex') {
326: $result = '\unskip\footnote{';
327: } elsif ($target eq 'edit') {
328: $result.=&Apache::edit::tag_start($target,$token);
329: $result.=&Apache::edit::text_arg('Text of Link:','linktext',$token,70);
1.131 albertel 330: $result.=&Apache::edit::text_arg('Height:','height',$token,5);
331: $result.=&Apache::edit::text_arg('Width:','width',$token,5);
1.105 albertel 332: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
333: } elsif ($target eq 'modified') {
334: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1.129 raeburn 335: $safeeval,'linktext',
1.105 albertel 336: 'width','height');
337: if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
338: }
339: return $result;
1.19 sakharuk 340: }
341:
1.30 sakharuk 342: sub end_window {
1.40 albertel 343: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.30 sakharuk 344: my $result;
1.137 albertel 345: if ($target eq 'web' || $target eq 'webgrade') {
1.34 albertel 346: my $output=&Apache::lonxml::endredirection;
1.97 albertel 347: $output =~ s/[\n\r]/ /g;
1.98 albertel 348: # $output = &HTML::Entities::encode($output,'<>&"\'');
349: $output =~ s/\'/\\\'/g;
1.92 albertel 350: my $linktext= &Apache::lonxml::get_param('linktext',$parstack,$safeeval);
351: if (!$linktext) { $linktext='<sup>*</sup>'; }
352: my $width= &Apache::lonxml::get_param('width',$parstack,$safeeval);
353: if (!$width) { $width='500'; }
354: my $height= &Apache::lonxml::get_param('height',$parstack,$safeeval);
355: if (!$height) { $height='200'; }
1.135 albertel 356:
357: my $start_page =
358: &Apache::loncommon::start_page($linktext, undef,
359: {'only_body' => 1,
360: 'bgcolor' => '#FFFFFF',
361: 'js_ready' => 1,});
362: my $end_page =
363: &Apache::loncommon::end_page({'js_ready' => 1,});
1.136 albertel 364: $result = "<script type=\"text/javascript\">
365: //<!--
366: function LONCAPA_newwindow_$Apache::lonxml::curdepth() {
367: newWindow=open(".&Apache::lonhtmlcommon::javascript_nothing().",'new_W','width=$width,height=$height,scrollbars=1');
368: newWindow.".&Apache::lonhtmlcommon::javascript_docopen().";
369: newWindow.document.writeln('$start_page $output $end_page');
370: newWindow.document.close();}
371: //-->
372: </script><a href=\"javascript:LONCAPA_newwindow_$Apache::lonxml::curdepth();void(0);\">$linktext</a>";
1.35 sakharuk 373: } elsif ($target eq 'tex') {
374: $result = '}';
1.30 sakharuk 375: } else {
1.35 sakharuk 376: $result = '';
1.30 sakharuk 377: }
1.20 sakharuk 378: return $result;
1.19 sakharuk 379: }
380:
1.6 albertel 381: sub start_import {
1.40 albertel 382: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.31 albertel 383: my $bodytext=$$parser[$#$parser]->get_text("/import");
1.7 albertel 384: my $result ="";
1.13 albertel 385:
386: $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
1.14 albertel 387:
1.135 albertel 388: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade'
389: || $target eq 'answer' || $target eq 'tex' || $target eq 'analyze' ) {
1.46 albertel 390: # FIXME this probably needs to be smart about construction vs.
391: # non construction space.
392: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
393: my $file=&Apache::lonnet::getfile($location);
394: if ($file == -1) {
395: &Apache::lonxml::error("<b> Unable to find <i>$bodytext as $location</i> for import</b>");
396: return "";
397: }
1.13 albertel 398:
1.46 albertel 399: my $dir=$location;
400: $dir=~s:/[^/]*$::;
401: # &Apache::lonxml::debug("directory $dir $location file $file \n<b>END</b>\n");
1.142 albertel 402: my $id= &Apache::lonxml::get_id($parstack,$safeeval);
1.57 albertel 403: if (!$id) { $id=$Apache::lonxml::curdepth; }
404: push(@Apache::inputtags::import,$id);
1.90 albertel 405: push(@Apache::inputtags::importlist,$id);
1.87 sakharuk 406:
407: &Apache::lonxml::newparser($parser,\$file,$dir);
408:
1.56 albertel 409: } elsif ($target eq "edit" ) {
1.46 albertel 410: $result.=&Apache::edit::tag_start($target,$token);
1.68 albertel 411: $result.=&Apache::edit::editline($token->[1],$bodytext,'',40);
1.83 matthew 412: $result.=&Apache::edit::browse(undef,'textnode');
1.46 albertel 413: #FIXME this need to convert $bodytext to be a contruction space reference
414: #my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
415: #$result.="Click<a href=\"$location\">here</a> to edit<br />"
1.56 albertel 416: } elsif ($target eq 'modified') {
1.103 albertel 417: $result=$token->[4].&Apache::edit::modifiedfield("/import",$parser);
1.56 albertel 418: } elsif ($target eq 'meta') {
1.142 albertel 419: my $id= &Apache::lonxml::get_id($parstack,$safeeval);
1.57 albertel 420: $result.='<import part="'.$Apache::inputtags::part;
421: if ($id) {
422: $result.='" id="'.$id;
423: }
424: $result.='">';
1.56 albertel 425: $result.=$bodytext;
426: $result.='</import>';
1.46 albertel 427: }
428: return $result;
1.6 albertel 429: }
430:
431: sub end_import {
1.69 albertel 432: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.57 albertel 433: pop(@Apache::inputtags::import);
1.69 albertel 434: my $result;
1.120 albertel 435: if ($target eq 'edit' ) { $result=&Apache::edit::end_row.
436: &Apache::edit::end_table(); }
1.69 albertel 437: return $result;
1.1 albertel 438: }
1.42 sakharuk 439:
440: sub start_storetc {
1.43 albertel 441: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.42 sakharuk 442: my $result = '';
443: &Apache::lonxml::startredirection;
444: return $result;
445: }
446:
447: sub end_storetc {
1.43 albertel 448: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.42 sakharuk 449: my $result;
450: my $output=&Apache::lonxml::endredirection;
451: $output =~ s/\"/\"\;/g;
1.52 albertel 452: $result = '{\bf '.$output.'.}}\write\tcfile{\protect\tcpc{ '.$output.'.}{\the\value{relpage}}}';
453: return $result;
1.42 sakharuk 454: }
455:
456:
457: sub start_physnet {
1.45 sakharuk 458: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.50 www 459: my $bodytext = '/adm/includes/physnet.sty';
1.45 sakharuk 460: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
461: my $cbistyletext=&Apache::lonnet::getfile($location);
1.42 sakharuk 462:
1.45 sakharuk 463: %$style = (%$style,&Apache::style::styleparser($target,$cbistyletext));
1.59 albertel 464: $$parser['-1']->unget_token($token);
465: # if ( defined($$style{'physnet'}) ) {
466: # &Apache::lonxml::newparser($parser,\$$style{'physnet'});
467: # }
1.45 sakharuk 468: return "";
469: }
1.42 sakharuk 470:
1.45 sakharuk 471: sub end_physnet {
1.47 albertel 472: return '';
1.42 sakharuk 473: }
1.62 albertel 474:
475: sub start_standalone {
476: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.75 albertel 477: my $result='';
1.137 albertel 478: if ($target eq 'web' || $target eq 'webgrade') {
1.126 albertel 479: if ( $env{'request.course.id'} ) {
1.133 albertel 480: my $inside = &Apache::lonxml::get_all_text("/standalone",$parser,$style);
1.75 albertel 481: } else {
482: $result='<table bgcolor="#E1E1E1" border="2"><tr><td>';
483: }
1.62 albertel 484: }
1.75 albertel 485: return $result;
1.62 albertel 486: }
487:
488: sub end_standalone {
1.75 albertel 489: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
490: my $result='';
1.137 albertel 491: if ($target eq 'web' || $target eq 'webgrade' ) {
1.126 albertel 492: if ( $env{'request.course.id'} ) {
1.75 albertel 493: } else {
494: $result='</td></tr></table>';
495: }
496: }
497: return $result;
1.74 albertel 498: }
499:
500: sub start_comment {
501: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
502: my $result='';
503: if ($target eq 'edit') {
504: $result=&Apache::edit::tag_start($target,$token);
1.133 albertel 505: my $bodytext=&Apache::lonxml::get_all_text("/comment",$parser,$style);
1.77 albertel 506: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,4)
1.74 albertel 507: } elsif ( $target eq 'modified') {
1.103 albertel 508: $result=$token->[4].&Apache::edit::modifiedfield("/comment",$parser);
1.137 albertel 509: } elsif ( $target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
510: $target eq 'answer' || $target eq 'meta' || $target eq 'analyze' ||
511: $target eq 'webgrade') {
1.74 albertel 512: #normally throw away comments
1.133 albertel 513: my $bodytext=&Apache::lonxml::get_all_text("/comment",$parser,$style);
1.74 albertel 514: }
515: return $result;
516: }
517:
518: sub end_comment {
519: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
520: if ($target eq 'edit' ) { return &Apache::edit::end_table(); }
1.62 albertel 521: return '';
522: }
523:
1.42 sakharuk 524:
1.47 albertel 525: sub xmlparse {
526: my ($string) = @_;
1.111 albertel 527: &Apache::lonxml::debug("xmlparse recursion starting with $string");
1.113 albertel 528: # Apache::run::evaluate does an 'eval' on the name of the subroutine
529: # if it detects something that looks like a subroutine, this ends up calling
530: # things without any arguments and since perl is nice enough to pass
531: # along the default arguments when you don't explicitly say no arguments
532: # if you call &xmlparse, it gets &xmlparse passed as it argument.
533: # Same thing soccurs with &chemparse.
1.111 albertel 534: if ($string eq '&xmlparse') { return '&xmlparse'; }
1.113 albertel 535: if ($string eq '&chemparse') { return '&chemparse'; }
1.47 albertel 536: my ($target,$token,$tagstack,$parstack,$oldparser,$safeeval,$style)=
537: @Apache::scripttag::parser_env;
538: my @parser;
539: &Apache::lonxml::newparser(\@parser,\$string);
1.132 albertel 540: &Apache::lonxml::startredirection();
1.47 albertel 541: my $result=&Apache::lonxml::inner_xmlparse($target,$tagstack,
542: $parstack,\@parser,
543: $safeeval,$style);
1.132 albertel 544: $result.=&Apache::lonxml::endredirection();
1.122 albertel 545: &Apache::lonxml::debug("target is $target xmlparse recursion ending with $result");
1.47 albertel 546: return $result;
547: }
1.3 albertel 548:
1.122 albertel 549: sub start_num {
550: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
551: my $result = '';
552: my $inside = &Apache::lonxml::get_all_text_unbalanced("/num",$parser);
1.137 albertel 553: if ($target eq 'tex' || $target eq 'web' || $target eq 'webgrade') {
1.122 albertel 554: $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
555: if (!$Apache::lonxml::default_homework_loaded) {
556: &Apache::lonxml::default_homework_load($safeeval);
557: }
558: @Apache::scripttag::parser_env = @_;
559: my $format=&Apache::lonxml::get_param('format',$parstack,$safeeval);
560: $result=&Apache::run::run("return &prettyprint(q\0$inside\0,q\0$format\0);",$safeeval);
561: }
562: return $result;
563: }
564:
565: sub end_num {
566: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
567: my $result = '';
568: return $result;
569: }
570:
571: sub start_parse {
572: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
573: my $result = '';
1.137 albertel 574: if ( $target eq 'web' || $target eq 'tex' ||
575: $target eq 'grade' || $target eq 'answer' ||
576: $target eq 'analyze'|| $target eq 'webgrade') {
1.122 albertel 577: my $inside = &Apache::lonxml::get_all_text_unbalanced("/parse",$parser);
578: $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
579: if (!$Apache::lonxml::default_homework_loaded) {
580: &Apache::lonxml::default_homework_load($safeeval);
581: }
582: @Apache::scripttag::parser_env = @_;
583: $result=&Apache::run::run("return &xmlparse(q\0$inside\0);",$safeeval);
1.134 albertel 584: if ($target eq 'grade' || $target eq 'answer' ||
585: $target eq 'analyze') {
586: # grade/answer/analyxe should produce no output but if we
587: # are redirecting, the redirecter should know what to do
588: # with the output
589: if (!$Apache::lonxml::redirection) { $result=''; }
590: }
1.122 albertel 591: }
592: return $result;
593: }
594:
595: sub end_parse {
596: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
597: my $result = '';
598: return $result;
599: }
1.123 albertel 600:
601: sub start_algebra {
602: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
603: my $result = '';
1.137 albertel 604: if ( $target eq 'web' || $target eq 'tex' ||
605: $target eq 'grade' || $target eq 'answer' ||
606: $target eq 'analyze' || $target eq 'webgrade') {
1.123 albertel 607: my $inside = &Apache::lonxml::get_all_text_unbalanced("/algebra",$parser);
608: $inside = &Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
609: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
1.125 albertel 610: my $style=&Apache::lonxml::get_param('style',$parstack,$safeeval);
611: $result=&Apache::lontexconvert::algebra($inside,$target,$style);
1.123 albertel 612: }
613: $Apache::lonxml::post_evaluate=0;
614: }
615: return $result;
616: }
617:
618: sub end_algebra {
619: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
620: my $result = '';
621: return $result;
622: }
623:
1.1 albertel 624: 1;
625: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>