--- loncom/xml/lonxml.pm 2002/05/01 21:40:25 1.168
+++ loncom/xml/lonxml.pm 2002/07/16 15:02:31 1.182
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# XML Parser Module
#
-# $Id: lonxml.pm,v 1.168 2002/05/01 21:40:25 albertel Exp $
+# $Id: lonxml.pm,v 1.182 2002/07/16 15:02:31 sakharuk Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -60,7 +60,7 @@
package Apache::lonxml;
use vars
-qw(@pwd @outputstack $redirection $import @extlinks $metamode $evaluate %insertlist @namespace);
+qw(@pwd @outputstack $redirection $import @extlinks $metamode $evaluate %insertlist @namespace $prevent_entity_encode);
use strict;
use HTML::LCParser();
use HTML::TreeBuilder();
@@ -129,9 +129,15 @@ $evaluate = 1;
# stores the list of active tag namespaces
@namespace=();
+# if 0 all high ASCII characters will be encoded into HTML Entities
+$prevent_entity_encode=0;
+
# has the dynamic menu been updated to know about this resource
$Apache::lonxml::registered=0;
+# a pointer the the Apache request object
+$Apache::lonxml::request='';
+
sub xmlbegin {
my $output='';
if ($ENV{'browser.mathml'}) {
@@ -325,15 +331,22 @@ sub registerurl {
my $forcereg=shift;
my $target = shift;
my $result = '';
- if (($ENV{'request.publicaccess'}) ||
- ($ENV{'REQUEST_URI'} eq '/res/adm/pages/menu.html')) {
- return
+ if ($target eq 'edit') {
+ $result .="\n";
+ }
+ if ((($ENV{'request.publicaccess'}) ||
+ (!&Apache::lonnet::is_on_map($ENV{'REQUEST_URI'}))) &&
+ (!$forcereg)) {
+ return $result.
'';
}
if ($Apache::lonxml::registered && !$forcereg) { return ''; }
$Apache::lonxml::registered=1;
my $nothing='';
if ($ENV{'browser.type'} eq 'explorer') { $nothing='javascript:void(0);'; }
+ my $timesync='menu.syncclock(1000*'.time.');';
if (($ENV{'REQUEST_URI'}!~/^\/(res\/)*adm\//) || ($forcereg)) {
my $hwkadd='';
if ($ENV{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form)$/) {
@@ -344,7 +357,7 @@ ENDSUBM
}
if (&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) {
$hwkadd.=(<
ENDDONOTREGTHIS
}
- if ($target eq 'edit') {
- # Javascript routines for construction space:
- # openbrowser and opensearcher will start the file browser
- # (lonindexer) and searcher (lonsearchcat) respectively.
- # Inputs are the name of the html form being used
- # and the name of the element the selected URL should
- # be placed in.
- # openbrowser also takes arguments only and omit, which are
- # comma deliminated lists of file extensions to (only) show
- # or omit.
- # Here we also set currentURL=null.
- $result .=<<"ENDBROWSERSCRIPT";
-
-ENDBROWSERSCRIPT
- }
return $result;
}
@@ -508,9 +471,26 @@ sub printalltags {
}
sub xmlparse {
- my ($target,$content_file_string,$safeinit,%style_for_target) = @_;
+ my ($request,$target,$content_file_string,$safeinit,%style_for_target) = @_;
+
+ &setup_globals($request,$target);
+#
+# do we have a course style file?
+#
+
+ if ($ENV{'request.course.id'}) {
+ my $bodytext=
+ $ENV{'course.'.$ENV{'request.course.id'}.'.default_xml_style'};
+ if ($bodytext) {
+ my $location=&Apache::lonnet::filelocation('',$bodytext);
+ my $styletext=&Apache::lonnet::getfile($location);
+ if ($styletext ne '-1') {
+ %style_for_target = (%style_for_target,
+ &Apache::style::styleparser($target,$styletext));
+ }
+ }
+ }
- &setup_globals($target);
#&printalltags();
my @pars = ();
my $pwd=$ENV{'request.filename'};
@@ -566,7 +546,17 @@ sub inner_xmlparse {
while ($token = $$pars['-1']->get_token) {
if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) {
if ($metamode<1) {
- $result=$token->[1];
+ if ($target eq 'tex') {
+ my @temp_array = @$stack;
+ if ($temp_array[-1] ne 'm') {
+ if ($temp_array[-1] ne 'tt') {
+ if ($token->[1]=~m/\^/) {$token->[1]=~s/\^/\\verb|\^|/g;}
+ } else {
+ if ($token->[1]=~m/\^/) {$token->[1]=~s/\^/}\\verb|\^|{/g;}
+ }
+ }
+ }
+ $result.=$token->[1];
}
} elsif ($token->[0] eq 'PI') {
if ($metamode<1) {
@@ -624,18 +614,22 @@ sub inner_xmlparse {
#evaluate variable refs in result
if ($result ne "") {
if ( $#$parstack > -1 ) {
- if ($Apache::lonxml::redirection) {
- $Apache::lonxml::outputstack['-1'] .=
- &Apache::run::evaluate($result,$safeeval,$$parstack['-1']);
- } else {
- $finaloutput .= &Apache::run::evaluate($result,$safeeval,
- $$parstack['-1']);
- }
+ $result=&Apache::run::evaluate($result,$safeeval,$$parstack[-1]);
} else {
- $finaloutput .= &Apache::run::evaluate($result,$safeeval,'');
+ $result= &Apache::run::evaluate($result,$safeeval,'');
}
- $result = '';
}
+ # Encode any high ASCII characters
+ if (!$Apache::lonxml::prevent_entity_encode) {
+ $result=&HTML::Entities::encode($result,"\200-\377");
+ }
+ if ($Apache::lonxml::redirection) {
+ $Apache::lonxml::outputstack['-1'] .= $result;
+ } else {
+ $finaloutput.=$result;
+ }
+ $result = '';
+
if ($token->[0] eq 'E') {
&end_tag($stack,$parstack,$token);
}
@@ -648,8 +642,7 @@ sub inner_xmlparse {
# $finaloutput.=&endredirection;
# }
- # Encode any high ASCII characters
- $finaloutput=&HTML::Entities::encode($finaloutput,"\200-\377");
+
if (($ENV{'QUERY_STRING'}) && ($target eq 'web')) {
$finaloutput=&afterburn($finaloutput);
}
@@ -792,7 +785,8 @@ sub callsub {
}
sub setup_globals {
- my ($target)=@_;
+ my ($request,$target)=@_;
+ $Apache::lonxml::request=$request;
$Apache::lonxml::registered = 0;
@Apache::lonxml::pwd=();
@Apache::lonxml::extlinks=();
@@ -949,8 +943,34 @@ sub decreasedepth {
#print "
e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n";
}
-sub get_all_text {
+sub get_all_text_unbalanced {
+ my($tag,$pars)= @_;
+ my $token;
+ my $result='';
+ $tag='<'.$tag.'>';
+ while ($token = $$pars[-1]->get_token) {
+ if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
+ $result.=$token->[1];
+ } elsif ($token->[0] eq 'PI') {
+ $result.=$token->[2];
+ } elsif ($token->[0] eq 'S') {
+ $result.=$token->[4];
+ } elsif ($token->[0] eq 'E') {
+ $result.=$token->[2];
+ }
+ if ($result =~ /(.*)$tag(.*)/) {
+ &Apache::lonxml::debug('Got a winner with leftovers ::'.$2);
+ &Apache::lonxml::debug('Result is :'.$1);
+ $result=$1;
+ my $redo=$tag.$2;
+ &Apache::lonxml::newparser($pars,\$redo);
+ last;
+ }
+ }
+ return $result
+}
+sub get_all_text {
my($tag,$pars)= @_;
my $depth=0;
my $token;
@@ -1122,9 +1142,9 @@ BUTTONS
ENDFOOTER
@@ -1213,7 +1233,8 @@ ENDNOTFOUND
}
}
if (!$ENV{'form.editmode'} || $ENV{'form.viewmode'}) {
- $result = &Apache::lonxml::xmlparse($target,$filecontents,'',%mystyle);
+ $result = &Apache::lonxml::xmlparse($request,$target,$filecontents,
+ '',%mystyle);
}
}
@@ -1222,7 +1243,10 @@ ENDNOTFOUND
#
unless ($ENV{'request.state'} eq 'published') {
if ($ENV{'form.editmode'} && (!($ENV{'form.viewmode'}))) {
- $result='';
+ my $displayfile=$request->uri;
+ $displayfile=~s/^\/[^\/]*//;
+ $result=''.$displayfile.
+ '
';
$result=&inserteditinfo($result,$filecontents);
}
}
@@ -1237,7 +1261,7 @@ ENDNOTFOUND
sub debug {
if ($Apache::lonxml::debug eq 1) {
$|=1;
- print("DEBUG:".join('
',@_)."
\n");
+ print("DEBUG:".&HTML::Entities::encode($_[0])."
\n");
}
}