--- loncom/xml/lonxml.pm 2002/04/03 18:47:39 1.164 +++ loncom/xml/lonxml.pm 2002/05/23 21:24:06 1.173 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # XML Parser Module # -# $Id: lonxml.pm,v 1.164 2002/04/03 18:47:39 www Exp $ +# $Id: lonxml.pm,v 1.173 2002/05/23 21:24:06 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -60,9 +60,9 @@ 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::TokeParser(); +use HTML::LCParser(); use HTML::TreeBuilder(); use HTML::Entities(); use Safe(); @@ -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'}) { @@ -326,7 +332,7 @@ sub registerurl { my $target = shift; my $result = ''; if (($ENV{'request.publicaccess'}) || - ($ENV{'REQUEST_URI'} eq '/res/adm/pages/menu.html')) { + (!&Apache::lonnet::is_on_map($ENV{'REQUEST_URI'}))) { return '<script>function LONCAPAreg(){} function LONCAPAstale(){}</script>'; } @@ -336,26 +342,20 @@ sub registerurl { if ($ENV{'browser.type'} eq 'explorer') { $nothing='javascript:void(0);'; } if (($ENV{'REQUEST_URI'}!~/^\/(res\/)*adm\//) || ($forcereg)) { my $hwkadd=''; - if ($ENV{'REQUEST_URI'}=~/\.(problem|exam|quiz|assess|survey|form)$/) { + if ($ENV{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form)$/) { if (&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) { $hwkadd.=(<<ENDSUBM); - menu.switchbutton - (7,1,'subm.gif','view sub','missions', - 'gocmd("/adm/grades","submission")'); + menu.switchbutton(7,1,'subm.gif','view sub','missions','gocmd("/adm/grades","submission")'); ENDSUBM } if (&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) { $hwkadd.=(<<ENDGRDS); - menu.switchbutton - (7,2,'pgrd.gif','problem','grades', - 'gocmd("/adm/grades","viewgrades")'); + menu.switchbutton(7,2,'pgrd.gif','problem','grades','gocmd("/adm/grades","gradingmenu")'); ENDGRDS } if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) { $hwkadd.=(<<ENDPARM); - menu.switchbutton - (7,3,'pparm.gif','problem','parms', - 'gocmd("/adm/parmset","set")'); + menu.switchbutton(7,3,'pparm.gif','problem','parms','gocmd("/adm/parmset","set")'); ENDPARM } } @@ -446,8 +446,13 @@ ENDDONOTREGTHIS # 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"; <script> + menu.currentURL=null; var editbrowser; function openbrowser(formname,elementname,only,omit) { var url = '/res/?'; @@ -509,9 +514,9 @@ 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($target); + &setup_globals($request,$target); #&printalltags(); my @pars = (); my $pwd=$ENV{'request.filename'}; @@ -625,18 +630,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); } @@ -649,6 +658,7 @@ sub inner_xmlparse { # $finaloutput.=&endredirection; # } + if (($ENV{'QUERY_STRING'}) && ($target eq 'web')) { $finaloutput=&afterburn($finaloutput); } @@ -791,7 +801,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=(); @@ -998,9 +1009,8 @@ sub get_all_text { sub newparser { my ($parser,$contentref,$dir) = @_; - push (@$parser,HTML::TokeParser->new($contentref)); + push (@$parser,HTML::LCParser->new($contentref)); $$parser['-1']->xml_mode('1'); -# $$parser['-1']->attr_encoded('1'); if ( $dir eq '' ) { push (@Apache::lonxml::pwd, $Apache::lonxml::pwd[$#Apache::lonxml::pwd]); } else { @@ -1122,9 +1132,9 @@ BUTTONS <a name="editsection" /> <form method="post"> <input type="hidden" name="editmode" value="Edit" /> -$buttons +$buttons<br /> <textarea cols="80" rows="40" name="filecont">$filecontents</textarea> -$buttons +<br />$buttons <br /> </form> ENDFOOTER @@ -1213,7 +1223,8 @@ ENDNOTFOUND } } if (!$ENV{'form.editmode'} || $ENV{'form.viewmode'}) { - $result = &Apache::lonxml::xmlparse($target,$filecontents,'',%mystyle); + $result = &Apache::lonxml::xmlparse($request,$target,$filecontents, + '',%mystyle); } } @@ -1243,7 +1254,8 @@ sub debug { sub error { if (($Apache::lonxml::debug eq 1) || ($ENV{'request.state'} eq 'construct') ) { - print "<b>ERROR:</b>".join('<br />',@_)."<br />\n"; + # If printing in construction space, put the error inside <pre></pre> + print "<b>ERROR:</b>".join("\n",@_)."\n"; } else { print "<b>An Error occured while processing this resource. The instructor has been notified.</b> <br />"; #notify author