Annotation of loncom/xml/lonxml.pm, revision 1.73
1.2 sakharuk 1: # The LearningOnline Network with CAPA
1.3 sakharuk 2: # XML Parser Module
1.2 sakharuk 3: #
1.3 sakharuk 4: # last modified 06/26/00 by Alexander Sakharuk
1.33 www 5: # 11/6 Gerd Kortemeyer
1.45 www 6: # 6/1/1 Gerd Kortemeyer
1.56 albertel 7: # 2/21,3/13 Guy
1.68 www 8: # 3/29,5/4 Gerd Kortemeyer
1.73 ! harris41 9: # 5/10 Scott Harrison
1.2 sakharuk 10:
1.4 albertel 11: package Apache::lonxml;
1.33 www 12: use vars
1.72 albertel 13: qw(@pwd @outputstack $redirection $import @extlinks $metamode $evaluate);
1.1 sakharuk 14: use strict;
15: use HTML::TokeParser;
1.3 sakharuk 16: use Safe;
1.40 albertel 17: use Safe::Hole;
1.13 albertel 18: use Opcode;
1.72 albertel 19:
20: sub register {
21: my $space;
22: my @taglist;
23: my $temptag;
24: ($space,@taglist) = @_;
25: foreach $temptag (@taglist) {
26: $Apache::lonxml::alltags{$temptag}=$space;
27: }
28: }
29:
1.46 www 30: use Apache::Constants qw(:common);
1.71 www 31: use Apache::lontexconvert;
1.72 albertel 32: use Apache::style;
33: use Apache::run;
34: use Apache::londefdef;
35: use Apache::scripttag;
36: use Apache::edit;
37: #================================================== Main subroutine: xmlparse
38: #debugging control, to turn on debugging modify the correct handler
39: $Apache::lonxml::debug=0;
40:
41: #path to the directory containing the file currently being processed
42: @pwd=();
43:
44: #these two are used for capturing a subset of the output for later processing,
45: #don't touch them directly use &startredirection and &endredirection
46: @outputstack = ();
47: $redirection = 0;
48:
49: #controls wheter the <import> tag actually does
50: $import = 1;
51: @extlinks=();
52:
53: # meta mode is a bit weird only some output is to be turned off
54: #<output> tag turns metamode off (defined in londefdef.pm)
55: $metamode = 0;
56:
57: # turns on and of run::evaluate actually derefencing var refs
58: $evaluate = 1;
1.7 albertel 59:
1.68 www 60:
61: sub xmlbegin {
62: my $output='';
63: if ($ENV{'browser.mathml'}) {
64: $output='<?xml version="1.0"?>'
65: .'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'
66: .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
67: .'[<!ENTITY mathns "http://www.w3.org/1998/Math/MathML">]>'
68: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
69: .'xmlns="http://www.w3.org/TR/REC-html40">';
70: } else {
71: $output='<html>';
72: }
73: return $output;
74: }
75:
76: sub xmlend {
77: return '</html>';
78: }
79:
1.70 www 80: sub fontsettings() {
81: my $headerstring='';
82: if (($ENV{'browser.os'} eq 'mac') && (!$ENV{'browser.mathml'})) {
83: $headerstring.=
84: '<meta Content-Type="text/html; charset=x-mac-roman">';
85: }
86: return $headerstring;
87: }
88:
1.68 www 89: sub registerurl {
90: return (<<ENDSCRIPT);
91: <script language="JavaScript">
1.71 www 92: // BEGIN LON-CAPA Internal
1.69 www 93: function LONCAPAreg() {
94: if (window.location.pathname!="/res/adm/pages/menu.html") {
95: menu=window.open("","LONCAPAmenu");
96: menu.currentURL=window.location.pathname;
97: menu.currentStale=0;
98: }
99: }
100:
101: function LONCAPAstale() {
102: if (window.location.pathname!="/res/adm/pages/menu.html") {
103: menu=window.open("","LONCAPAmenu");
104: menu.currentStale=1;
105: }
1.68 www 106: }
1.71 www 107: // END LON-CAPA Internal
1.68 www 108: </script>
109: ENDSCRIPT
1.69 www 110: }
111:
112: sub loadevents() {
113: return 'LONCAPAreg();';
114: }
115:
116: sub unloadevents() {
117: return 'LONCAPAstale();';
1.68 www 118: }
119:
1.48 albertel 120: sub printalltags {
121: my $temp;
122: foreach $temp (sort keys %Apache::lonxml::alltags) {
1.64 albertel 123: &Apache::lonxml::debug("$temp -- $Apache::lonxml::alltags{$temp}");
1.48 albertel 124: }
125: }
1.31 sakharuk 126:
1.3 sakharuk 127: sub xmlparse {
128:
1.18 albertel 129: my ($target,$content_file_string,$safeinit,%style_for_target) = @_;
1.41 albertel 130: if ($target eq 'meta') {
1.59 albertel 131: $Apache::lonxml::redirection = 0;
132: $Apache::lonxml::metamode = 1;
1.72 albertel 133: $Apache::lonxml::evaluate = 1;
1.55 albertel 134: $Apache::lonxml::import = 0;
1.47 albertel 135: } elsif ($target eq 'grade') {
1.55 albertel 136: &startredirection;
1.59 albertel 137: $Apache::lonxml::metamode = 0;
1.72 albertel 138: $Apache::lonxml::evaluate = 1;
1.55 albertel 139: $Apache::lonxml::import = 1;
1.72 albertel 140: } elsif ($target eq 'modified') {
141: $Apache::lonxml::redirection = 0;
142: $Apache::lonxml::metamode = 0;
143: $Apache::lonxml::evaluate = 0;
144: $Apache::lonxml::import = 0;
1.44 albertel 145: } else {
1.72 albertel 146: $Apache::lonxml::redirection = 0;
1.59 albertel 147: $Apache::lonxml::metamode = 0;
1.72 albertel 148: $Apache::lonxml::evaluate = 1;
1.55 albertel 149: $Apache::lonxml::import = 1;
1.32 sakharuk 150: }
1.48 albertel 151: #&printalltags();
1.16 albertel 152: my @pars = ();
1.23 albertel 153: @Apache::lonxml::pwd=();
154: my $pwd=$ENV{'request.filename'};
155: $pwd =~ s:/[^/]*$::;
156: &newparser(\@pars,\$content_file_string,$pwd);
1.3 sakharuk 157: my $currentstring = '';
158: my $finaloutput = '';
159: my $newarg = '';
1.16 albertel 160: my $result;
1.24 sakharuk 161:
1.3 sakharuk 162: my $safeeval = new Safe;
1.40 albertel 163: my $safehole = new Safe::Hole;
1.6 albertel 164: $safeeval->permit("entereval");
1.13 albertel 165: $safeeval->permit(":base_math");
1.19 albertel 166: $safeeval->deny(":base_io");
1.40 albertel 167: $safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT');
1.19 albertel 168: #need to inspect this class of ops
169: # $safeeval->deny(":base_orig");
1.21 albertel 170: $safeinit .= ';$external::target='.$target.';';
1.26 albertel 171: $safeinit .= ';$external::randomseed='.&Apache::lonnet::rndseed().';';
1.21 albertel 172: &Apache::run::run($safeinit,$safeeval);
1.3 sakharuk 173: #-------------------- Redefinition of the target in the case of compound target
174:
175: ($target, my @tenta) = split('&&',$target);
176:
177: my @stack = ();
178: my @parstack = ();
1.17 albertel 179: &initdepth;
1.3 sakharuk 180: my $token;
1.16 albertel 181: while ( $#pars > -1 ) {
182: while ($token = $pars[$#pars]->get_token) {
1.57 albertel 183: if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) {
1.61 albertel 184: if ($metamode<1) { $result=$token->[1]; }
1.57 albertel 185: } elsif ($token->[0] eq 'PI') {
1.61 albertel 186: if ($metamode<1) { $result=$token->[2]; }
1.16 albertel 187: } elsif ($token->[0] eq 'S') {
188: # add tag to stack
189: push (@stack,$token->[1]);
190: # add parameters list to another stack
191: push (@parstack,&parstring($token));
1.19 albertel 192: &increasedepth($token);
1.16 albertel 193: if (exists $style_for_target{$token->[1]}) {
1.61 albertel 194: if ($Apache::lonxml::redirection) {
1.55 albertel 195: $Apache::lonxml::outputstack['-1'] .=
196: &recurse($style_for_target{$token->[1]},$target,$safeeval,
197: \%style_for_target,@parstack);
1.41 albertel 198: } else {
1.55 albertel 199: $finaloutput .= &recurse($style_for_target{$token->[1]},$target,
200: $safeeval,\%style_for_target,@parstack);
1.41 albertel 201: }
1.16 albertel 202: } else {
1.17 albertel 203: $result = &callsub("start_$token->[1]", $target, $token,\@parstack,
1.41 albertel 204: \@pars, $safeeval, \%style_for_target);
1.16 albertel 205: }
206: } elsif ($token->[0] eq 'E') {
207: #clear out any tags that didn't end
1.55 albertel 208: while ($token->[1] ne $stack[$#stack] && ($#stack > -1)) {
209: &Apache::lonxml::warning("Unbalanced tags in resource $stack['-1']");
1.43 albertel 210: pop @stack;pop @parstack;&decreasedepth($token);
211: }
1.16 albertel 212:
213: if (exists $style_for_target{'/'."$token->[1]"}) {
1.61 albertel 214: if ($Apache::lonxml::redirection) {
1.55 albertel 215: $Apache::lonxml::outputstack['-1'] .=
216: &recurse($style_for_target{'/'."$token->[1]"},
217: $target,$safeeval,\%style_for_target,@parstack);
218: } else {
219: $finaloutput .= &recurse($style_for_target{'/'."$token->[1]"},
220: $target,$safeeval,\%style_for_target,
221: @parstack);
222: }
1.59 albertel 223:
1.16 albertel 224: } else {
1.17 albertel 225: $result = &callsub("end_$token->[1]", $target, $token, \@parstack,
1.55 albertel 226: \@pars,$safeeval, \%style_for_target);
1.13 albertel 227: }
1.57 albertel 228: } else {
229: &Apache::lonxml::error("Unknown token event :$token->[0]:$token->[1]:");
1.16 albertel 230: }
1.55 albertel 231: #evaluate variable refs in result
1.25 sakharuk 232: if ($result ne "") {
1.24 sakharuk 233: if ( $#parstack > -1 ) {
1.55 albertel 234: if ($Apache::lonxml::redirection) {
235: $Apache::lonxml::outputstack['-1'] .=
236: &Apache::run::evaluate($result,$safeeval,$parstack[$#parstack]);
237: } else {
238: $finaloutput .= &Apache::run::evaluate($result,$safeeval,
239: $parstack[$#parstack]);
240: }
1.16 albertel 241: } else {
242: $finaloutput .= &Apache::run::evaluate($result,$safeeval,'');
1.13 albertel 243: }
1.16 albertel 244: $result = '';
1.55 albertel 245: }
246: if ($token->[0] eq 'E') {
247: pop @stack;pop @parstack;&decreasedepth($token);
1.2 sakharuk 248: }
1.5 albertel 249: }
1.16 albertel 250: pop @pars;
1.23 albertel 251: pop @Apache::lonxml::pwd;
1.3 sakharuk 252: }
1.24 sakharuk 253:
1.59 albertel 254: # if ($target eq 'meta') {
255: # $finaloutput.=&endredirection;
256: # }
1.67 www 257:
258: if (($ENV{'QUERY_STRING'}) && ($target eq 'web')) {
259: $finaloutput=&afterburn($finaloutput);
260: }
261:
1.3 sakharuk 262: return $finaloutput;
1.15 albertel 263: }
264:
1.67 www 265:
1.15 albertel 266: sub recurse {
267:
268: my @innerstack = ();
269: my @innerparstack = ();
270: my ($newarg,$target,$safeeval,$style_for_target,@parstack) = @_;
1.16 albertel 271: my @pat = ();
1.23 albertel 272: &newparser(\@pat,\$newarg);
1.15 albertel 273: my $tokenpat;
274: my $partstring = '';
275: my $output='';
1.16 albertel 276: my $decls='';
277: while ( $#pat > -1 ) {
278: while ($tokenpat = $pat[$#pat]->get_token) {
1.57 albertel 279: if (($tokenpat->[0] eq 'T') || ($tokenpat->[0] eq 'C') || ($tokenpat->[0] eq 'D') ) {
1.61 albertel 280: if ($metamode<1) { $partstring=$tokenpat->[1]; }
1.57 albertel 281: } elsif ($tokenpat->[0] eq 'PI') {
1.61 albertel 282: if ($metamode<1) { $partstring=$tokenpat->[2]; }
1.16 albertel 283: } elsif ($tokenpat->[0] eq 'S') {
284: push (@innerstack,$tokenpat->[1]);
285: push (@innerparstack,&parstring($tokenpat));
1.19 albertel 286: &increasedepth($tokenpat);
1.16 albertel 287: $partstring = &callsub("start_$tokenpat->[1]",
288: $target, $tokenpat, \@innerparstack,
289: \@pat, $safeeval, $style_for_target);
290: } elsif ($tokenpat->[0] eq 'E') {
291: #clear out any tags that didn't end
292: while ($tokenpat->[1] ne $innerstack[$#innerstack]
1.43 albertel 293: && ($#innerstack > -1)) {
1.49 albertel 294: &Apache::lonxml::warning("Unbalanced tags in resource $innerstack['-1']");
1.43 albertel 295: pop @innerstack;pop @innerparstack;&decreasedepth($tokenpat);
296: }
1.16 albertel 297: $partstring = &callsub("end_$tokenpat->[1]",
298: $target, $tokenpat, \@innerparstack,
299: \@pat, $safeeval, $style_for_target);
1.57 albertel 300: } else {
301: &Apache::lonxml::error("Unknown token event :$tokenpat->[0]:$tokenpat->[1]:");
1.16 albertel 302: }
303: #pass both the variable to the style tag, and the tag we
304: #are processing inside the <definedtag>
305: if ( $partstring ne "" ) {
306: if ( $#parstack > -1 ) {
307: if ( $#innerparstack > -1 ) {
308: $decls= $parstack[$#parstack].$innerparstack[$#innerparstack];
309: } else {
310: $decls= $parstack[$#parstack];
311: }
312: } else {
313: if ( $#innerparstack > -1 ) {
314: $decls=$innerparstack[$#innerparstack];
315: } else {
316: $decls='';
317: }
318: }
319: $output .= &Apache::run::evaluate($partstring,$safeeval,$decls);
320: $partstring = '';
321: }
1.17 albertel 322: if ($tokenpat->[0] eq 'E') { pop @innerstack;pop @innerparstack;
1.19 albertel 323: &decreasedepth($tokenpat);}
1.15 albertel 324: }
1.16 albertel 325: pop @pat;
1.23 albertel 326: pop @Apache::lonxml::pwd;
1.15 albertel 327: }
328: return $output;
1.7 albertel 329: }
330:
331: sub callsub {
1.14 albertel 332: my ($sub,$target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.7 albertel 333: my $currentstring='';
1.72 albertel 334: my $nodefault;
1.7 albertel 335: {
1.59 albertel 336: my $sub1;
1.7 albertel 337: no strict 'refs';
1.59 albertel 338: if ($target eq 'edit' && $token->[0] eq 'S') {
339: $currentstring = &Apache::edit::tag_start($target,$token,$parstack,$parser,
340: $safeeval,$style);
341: }
1.68 www 342: my $tag=$token->[1];
343: my $space=$Apache::lonxml::alltags{$tag};
344: if (!$space) {
345: $tag=~tr/A-Z/a-z/;
346: $sub=~tr/A-Z/a-z/;
347: $space=$Apache::lonxml::alltags{$tag}
348: }
349: if ($space) {
1.72 albertel 350: #&Apache::lonxml::debug("Calling sub $sub in $space $metamode<br />\n");
1.24 sakharuk 351: $sub1="$space\:\:$sub";
1.17 albertel 352: $Apache::lonxml::curdepth=join('_',@Apache::lonxml::depthcounter);
1.72 albertel 353: ($currentstring,$nodefault) = &$sub1($target,$token,$parstack,$parser,
354: $safeeval,$style);
1.7 albertel 355: } else {
1.72 albertel 356: #&Apache::lonxml::debug("NOT Calling sub $sub in $space $metamode<br />\n");
1.62 sakharuk 357: if ($metamode <1) {
358: if (defined($token->[4]) && ($metamode < 1)) {
1.72 albertel 359: $currentstring = $token->[4];
1.62 sakharuk 360: } else {
1.72 albertel 361: $currentstring = $token->[2];
1.62 sakharuk 362: }
1.7 albertel 363: }
1.59 albertel 364: }
1.72 albertel 365: &Apache::lonxml::debug("nodefalt:$nodefault:");
366: if ($currentstring eq '' && $nodefault eq '') {
367: if ($target eq 'edit') {
368: if ($token->[0] eq 'S') {
369: $currentstring = &Apache::edit::tag_start($token,$target);
370: } elsif ($token->[0] eq 'E') {
371: $currentstring = &Apache::edit::tag_end($token,$target);
372: }
373: } elsif ($target eq 'modified') {
374: if ($token->[0] eq 'S') {
375: $currentstring = $token->[4];
376: } else {
377: $currentstring = $token->[2];
378: }
379: }
1.7 albertel 380: }
381: use strict 'refs';
382: }
383: return $currentstring;
1.17 albertel 384: }
385:
1.55 albertel 386: sub startredirection {
387: $Apache::lonxml::redirection++;
388: push (@Apache::lonxml::outputstack, '');
389: }
390:
391: sub endredirection {
392: if (!$Apache::lonxml::redirection) {
1.72 albertel 393: &Apache::lonxml::error("Endredirection was called, before a startredirection, perhaps you have unbalanced tags. Some debuging information:".join ":",caller);
1.55 albertel 394: return '';
395: }
396: $Apache::lonxml::redirection--;
397: pop @Apache::lonxml::outputstack;
398: }
399:
1.17 albertel 400: sub initdepth {
401: @Apache::lonxml::depthcounter=();
402: $Apache::lonxml::depth=-1;
403: $Apache::lonxml::olddepth=-1;
404: }
405:
406: sub increasedepth {
1.19 albertel 407: my ($token) = @_;
1.17 albertel 408: $Apache::lonxml::depth++;
409: $Apache::lonxml::depthcounter[$Apache::lonxml::depth]++;
410: if ($Apache::lonxml::depthcounter[$Apache::lonxml::depth]==1) {
411: $Apache::lonxml::olddepth=$Apache::lonxml::depth;
412: }
1.42 albertel 413: my $curdepth=join('_',@Apache::lonxml::depthcounter);
1.64 albertel 414: &Apache::lonxml::debug("s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n");
1.54 albertel 415: #print "<br />s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n";
1.17 albertel 416: }
417:
418: sub decreasedepth {
1.19 albertel 419: my ($token) = @_;
1.17 albertel 420: $Apache::lonxml::depth--;
1.36 albertel 421: if ($Apache::lonxml::depth<$Apache::lonxml::olddepth-1) {
422: $#Apache::lonxml::depthcounter--;
423: $Apache::lonxml::olddepth=$Apache::lonxml::depth+1;
424: }
1.43 albertel 425: if ( $Apache::lonxml::depth < -1) {
1.49 albertel 426: &Apache::lonxml::warning("Unbalanced tags in resource");
1.43 albertel 427: $Apache::lonxml::depth='-1';
428: }
1.42 albertel 429: my $curdepth=join('_',@Apache::lonxml::depthcounter);
1.64 albertel 430: &Apache::lonxml::debug("e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n");
1.54 albertel 431: #print "<br />e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n";
1.1 sakharuk 432: }
1.19 albertel 433:
434: sub get_all_text {
435:
436: my($tag,$pars)= @_;
437: my $depth=0;
438: my $token;
439: my $result='';
1.57 albertel 440: if ( $tag =~ m:^/: ) {
441: my $tag=substr($tag,1);
442: # &Apache::lonxml::debug("have:$tag:");
443: while (($depth >=0) && ($token = $pars->get_token)) {
444: # &Apache::lonxml::debug("e token:$token->[0]:$depth:$token->[1]");
445: if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
446: $result.=$token->[1];
447: } elsif ($token->[0] eq 'PI') {
448: $result.=$token->[2];
449: } elsif ($token->[0] eq 'S') {
450: if ($token->[1] eq $tag) { $depth++; }
451: $result.=$token->[4];
452: } elsif ($token->[0] eq 'E') {
453: if ( $token->[1] eq $tag) { $depth--; }
454: #skip sending back the last end tag
455: if ($depth > -1) { $result.=$token->[2]; } else {
456: $pars->unget_token($token);
457: }
458: }
459: }
460: } else {
461: while ($token = $pars->get_token) {
462: # &Apache::lonxml::debug("s token:$token->[0]:$depth:$token->[1]");
463: if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
464: $result.=$token->[1];
465: } elsif ($token->[0] eq 'PI') {
466: $result.=$token->[2];
467: } elsif ($token->[0] eq 'S') {
468: if ( $token->[1] eq $tag) {
469: $pars->unget_token($token); last;
470: } else {
471: $result.=$token->[4];
472: }
473: } elsif ($token->[0] eq 'E') {
474: $result.=$token->[2];
1.36 albertel 475: }
1.19 albertel 476: }
477: }
1.49 albertel 478: # &Apache::lonxml::debug("Exit:$result:");
1.19 albertel 479: return $result
480: }
481:
1.23 albertel 482: sub newparser {
483: my ($parser,$contentref,$dir) = @_;
484: push (@$parser,HTML::TokeParser->new($contentref));
1.56 albertel 485: $$parser['-1']->xml_mode('1');
1.23 albertel 486: if ( $dir eq '' ) {
487: push (@Apache::lonxml::pwd, $Apache::lonxml::pwd[$#Apache::lonxml::pwd]);
488: } else {
489: push (@Apache::lonxml::pwd, $dir);
490: }
491: # &Apache::lonxml::debug("pwd:$#Apache::lonxml::pwd");
492: # &Apache::lonxml::debug("pwd:$Apache::lonxml::pwd[$#Apache::lonxml::pwd]");
493: }
1.1 sakharuk 494:
1.8 albertel 495: sub parstring {
496: my ($token) = @_;
497: my $temp='';
1.20 albertel 498: map {
1.35 www 499: unless ($_=~/\W/) {
1.42 albertel 500: my $val=$token->[2]->{$_};
1.53 albertel 501: $val =~ s/([\%\@\\])/\\$1/g;
1.51 albertel 502: #if ($val =~ m/^[\%\@]/) { $val="\\".$val; }
1.42 albertel 503: $temp .= "my \$$_=\"$val\";"
1.20 albertel 504: }
505: } @{$token->[3]};
1.8 albertel 506: return $temp;
507: }
1.22 albertel 508:
1.34 www 509: sub writeallows {
510: my $thisurl='/res/'.&Apache::lonnet::declutter(shift);
511: my $thisdir=$thisurl;
512: $thisdir=~s/\/[^\/]+$//;
513: my %httpref=();
514: map {
515: $httpref{'httpref.'.
516: &Apache::lonnet::hreflocation($thisdir,$_)}=$thisurl; } @extlinks;
517: &Apache::lonnet::appenv(%httpref);
518: }
519:
1.66 www 520: #
521: # Afterburner handles anchors, highlights and links
522: #
523: sub afterburn {
524: my $result=shift;
525: map {
526: my ($name, $value) = split(/=/,$_);
527: $value =~ tr/+/ /;
528: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
529: if (($name eq 'highlight')||($name eq 'anchor')||($name eq 'link')) {
530: unless ($ENV{'form.'.$name}) {
531: $ENV{'form.'.$name}=$value;
532: }
533: }
534: } (split(/&/,$ENV{'QUERY_STRING'}));
535: if ($ENV{'form.highlight'}) {
536: map {
537: my $anchorname=$_;
538: my $matchthis=$anchorname;
539: $matchthis=~s/\_+/\\s\+/g;
540: $result=~s/($matchthis)/\<font color=\"red\"\>$1\<\/font\>/gs;
541: } split(/\,/,$ENV{'form.highlight'});
542: }
543: if ($ENV{'form.link'}) {
544: map {
545: my ($anchorname,$linkurl)=split(/\>/,$_);
546: my $matchthis=$anchorname;
547: $matchthis=~s/\_+/\\s\+/g;
548: $result=~s/($matchthis)/\<a href=\"$linkurl\"\>$1\<\/a\>/gs;
549: } split(/\,/,$ENV{'form.link'});
550: }
551: if ($ENV{'form.anchor'}) {
552: my $anchorname=$ENV{'form.anchor'};
553: my $matchthis=$anchorname;
554: $matchthis=~s/\_+/\\s\+/g;
555: $result=~s/($matchthis)/\<a name=\"$anchorname\"\>$1\<\/a\>/s;
556: $result.=(<<"ENDSCRIPT");
557: <script>
558: document.location.hash='$anchorname';
559: </script>
560: ENDSCRIPT
561: }
562: return $result;
563: }
564:
1.24 sakharuk 565: sub handler {
566: my $request=shift;
1.68 www 567:
1.64 albertel 568: my $target='web';
1.68 www 569:
1.65 albertel 570: $Apache::lonxml::debug=0;
1.68 www 571:
1.25 sakharuk 572: if ($ENV{'browser.mathml'}) {
1.27 albertel 573: $request->content_type('text/xml');
574: } else {
575: $request->content_type('text/html');
1.25 sakharuk 576: }
1.64 albertel 577:
1.29 sakharuk 578: # $request->print(<<ENDHEADER);
579: #<html>
580: #<head>
581: #<title>Just test</title>
582: #</head>
583: #<body bgcolor="#FFFFFF">
584: #ENDHEADER
585: # &Apache::lonhomework::send_header($request);
1.27 albertel 586: $request->send_http_header;
1.64 albertel 587:
1.45 www 588: return OK if $request->header_only;
1.27 albertel 589:
590:
1.50 albertel 591: my $file=&Apache::lonnet::filelocation("",$request->uri);
1.24 sakharuk 592: my %mystyle;
1.50 albertel 593: my $result = '';
594: my $filecontents=&Apache::lonnet::getfile($file);
595: if ($filecontents == -1) {
596: &Apache::lonxml::error("<b> Unable to find <i>$file</i></b>");
597: $filecontents='';
598: } else {
599: $result = &Apache::lonxml::xmlparse($target,$filecontents,'',%mystyle);
1.66 www 600: }
1.50 albertel 601:
1.67 www 602: $request->print($result);
1.64 albertel 603:
1.34 www 604: writeallows($request->uri);
1.45 www 605: return OK;
1.24 sakharuk 606: }
607:
1.22 albertel 608: sub debug {
609: if ($Apache::lonxml::debug eq 1) {
1.54 albertel 610: print "DEBUG:".$_[0]."<br />\n";
1.22 albertel 611: }
612: }
1.49 albertel 613:
1.22 albertel 614: sub error {
1.52 albertel 615: if ($Apache::lonxml::debug eq 1) {
1.55 albertel 616: print "<b>ERROR:</b>".$_[0]."<br />\n";
1.52 albertel 617: } else {
618: print "<b>An Error occured while processing this resource. The instructor has been notified.</b> <br />";
619: #notify author
620: &Apache::lonmsg::author_res_msg($ENV{'request.filename'},$_[0]);
621: #notify course
622: if ( $ENV{'request.course.id'} ) {
623: my $users=$ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'};
624: foreach my $user (split /\,/, $users) {
625: ($user,my $domain) = split /:/, $user;
1.54 albertel 626: &Apache::lonmsg::user_normal_msg($user,$domain,"Error in $ENV{'request.filename'}",$_[0]);
1.52 albertel 627: }
628: }
629:
630: #FIXME probably shouldn't have me get everything forever.
1.54 albertel 631: &Apache::lonmsg::user_normal_msg('albertel','msu',"Error in $ENV{'request.filename'}",$_[0]);
632: #&Apache::lonmsg::user_normal_msg('albertel','103',"Error in $ENV{'request.filename'}",$_[0]);
1.52 albertel 633: }
1.22 albertel 634: }
1.49 albertel 635:
1.22 albertel 636: sub warning {
1.73 ! harris41 637: if ($ENV{'request.state'} eq 'construct') {
1.55 albertel 638: print "<b>W</b>ARNING<b>:</b>".$_[0]."<br />\n";
1.73 ! harris41 639: }
1.22 albertel 640: }
641:
1.1 sakharuk 642: 1;
643: __END__
1.68 www 644:
645:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>