--- loncom/xml/lonxml.pm 2002/02/21 04:11:25 1.152
+++ loncom/xml/lonxml.pm 2002/05/24 20:51:55 1.174
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# XML Parser Module
#
-# $Id: lonxml.pm,v 1.152 2002/02/21 04:11:25 albertel Exp $
+# $Id: lonxml.pm,v 1.174 2002/05/24 20:51:55 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -60,15 +60,16 @@
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::TreeBuilder;
-use Safe;
-use Safe::Hole;
-use Math::Cephes qw(:trigs :hypers :bessels erf erfc);
-use Math::Random qw(:all);
-use Opcode;
+use HTML::LCParser();
+use HTML::TreeBuilder();
+use HTML::Entities();
+use Safe();
+use Safe::Hole();
+use Math::Cephes();
+use Math::Random();
+use Opcode();
sub register {
my ($space,@taglist) = @_;
@@ -89,15 +90,15 @@ sub deregister {
}
use Apache::Constants qw(:common);
-use Apache::lontexconvert;
-use Apache::style;
-use Apache::run;
-use Apache::londefdef;
-use Apache::scripttag;
-use Apache::edit;
-use Apache::lonnet;
-use Apache::File;
-use Apache::loncommon;
+use Apache::lontexconvert();
+use Apache::style();
+use Apache::run();
+use Apache::londefdef();
+use Apache::scripttag();
+use Apache::edit();
+use Apache::lonnet();
+use Apache::File();
+use Apache::loncommon();
#================================================== Main subroutine: xmlparse
#debugging control, to turn on debugging modify the correct handler
@@ -128,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'}) {
@@ -175,10 +182,12 @@ sub xmlend {
}
my $sender='Anonymous';
if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {
- $sender=$contrib{$idx.':sendername'}.' at '.
- $contrib{$idx.':senderdomain'};
+ $sender=$contrib{$idx.':plainname'}.' ('.
+ $contrib{$idx.':sendername'}.' at '.
+ $contrib{$idx.':senderdomain'}.')';
if ($contrib{$idx.':anonymous'}) {
- $sender.=' (anonymous)';
+ $sender.=' [anonymous] '.
+ $contrib{$idx.':screenname'};
}
if ($seeid) {
if ($hidden) {
@@ -189,6 +198,10 @@ sub xmlend {
$symb.':::'.$idx.'">Hide';
}
}
+ } else {
+ if ($contrib{$idx.':screenname'}) {
+ $sender=''.$contrib{$idx.':screenname'}.'';
+ }
}
$discussion.='
'.$sender.' ('.
localtime($contrib{$idx.':timestamp'}).
@@ -316,45 +329,46 @@ sub fontsettings() {
sub registerurl {
my $forcereg=shift;
- if ($ENV{'request.publicaccess'}) {
+ my $target = shift;
+ my $result = '';
+ if (($ENV{'request.publicaccess'}) ||
+ (!&Apache::lonnet::is_on_map($ENV{'REQUEST_URI'}))) {
return
'';
}
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.clock.setTime(1000*'.time.');';
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.=(<
// BEGIN LON-CAPA Internal
function LONCAPAreg() {
- menu=window.open("","LONCAPAmenu");
+ menu=window.open("$nothing","LONCAPAmenu","",false);
menu.clearTimeout(menu.menucltim);
+ $timesync
menu.currentURL=window.location.pathname;
menu.currentStale=0;
menu.clearbut(3,1);
@@ -380,7 +394,7 @@ ENDPARM
}
function LONCAPAstale() {
- menu=window.open("","LONCAPAmenu");
+ menu=window.open("$nothing","LONCAPAmenu","",false);
menu.currentStale=1;
menu.switchbutton
(3,1,'reload.gif','return','location','go(currentURL)');
@@ -399,13 +413,14 @@ ENDPARM
ENDREGTHIS
} else {
- return (<
// BEGIN LON-CAPA Internal
function LONCAPAreg() {
- menu=window.open("","LONCAPAmenu");
+ menu=window.open("$nothing","LONCAPAmenu","",false);
+ $timesync
menu.currentStale=1;
menu.clearbut(2,1);
menu.clearbut(2,3);
@@ -426,8 +441,63 @@ ENDREGTHIS
// END LON-CAPA Internal
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;
}
sub loadevents() {
@@ -447,9 +517,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'};
@@ -485,7 +555,7 @@ sub htmlclean {
my $output= $tree->as_HTML(undef,' ');
- $output=~s/\<(br|hr|img|meta|allow)([^\>\/]*)\>/\<$1$2 \/\>/gis;
+ $output=~s/\<(br|hr|img|meta|allow)(.*?)\>/\<$1$2 \/\>/gis;
$output=~s/\<\/(br|hr|img|meta|allow)\>//gis;
unless ($full) {
$output=~s/\<[\/]*(body|head|html)\>//gis;
@@ -563,18 +633,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);
}
@@ -587,6 +661,7 @@ sub inner_xmlparse {
# $finaloutput.=&endredirection;
# }
+
if (($ENV{'QUERY_STRING'}) && ($target eq 'web')) {
$finaloutput=&afterburn($finaloutput);
}
@@ -729,7 +804,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=();
@@ -758,6 +834,11 @@ sub setup_globals {
$Apache::lonxml::metamode = 0;
$Apache::lonxml::evaluate = 0;
$Apache::lonxml::import = 0;
+ } elsif ($target eq 'analyze') {
+ $Apache::lonxml::redirection = 0;
+ $Apache::lonxml::metamode = 0;
+ $Apache::lonxml::evaluate = 1;
+ $Apache::lonxml::import = 1;
} else {
$Apache::lonxml::redirection = 0;
$Apache::lonxml::metamode = 0;
@@ -931,7 +1012,7 @@ 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');
if ( $dir eq '' ) {
push (@Apache::lonxml::pwd, $Apache::lonxml::pwd[$#Apache::lonxml::pwd]);
@@ -978,16 +1059,8 @@ sub writeallows {
#
sub afterburn {
my $result=shift;
- foreach (split(/&/,$ENV{'QUERY_STRING'})) {
- my ($name, $value) = split(/=/,$_);
- $value =~ tr/+/ /;
- $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
- if (($name eq 'highlight')||($name eq 'anchor')||($name eq 'link')) {
- unless ($ENV{'form.'.$name}) {
- $ENV{'form.'.$name}=$value;
- }
- }
- }
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
+ ['highlight','anchor','link']);
if ($ENV{'form.highlight'}) {
foreach (split(/\,/,$ENV{'form.highlight'})) {
my $anchorname=$_;
@@ -1049,19 +1122,23 @@ SIMPLECONTENT
sub inserteditinfo {
my ($result,$filecontents)=@_;
- $filecontents =~ s::</textarea>:ig;
+ $filecontents = &HTML::Entities::encode($filecontents);
# my $editheader='Edit below
';
+ my $buttons=(<
+
+
+BUTTONS
my $editfooter=(<
ENDFOOTER
# $result=~s/(\]*\>)/$1$editheader/is;
@@ -1075,6 +1152,13 @@ sub get_target {
if ( defined($ENV{'form.grade_target'})
&& ($viewgrades == 'F' )) {
return ($ENV{'form.grade_target'});
+ } elsif (defined($ENV{'form.grade_target'})) {
+ if (($ENV{'form.grade_target'} eq 'web') ||
+ ($ENV{'form.grade_target'} eq 'tex') ) {
+ return $ENV{'form.grade_target'}
+ } else {
+ return 'web';
+ }
} else {
return 'web';
}
@@ -1133,7 +1217,7 @@ ENDNOTFOUND
$filecontents='';
if ($ENV{'request.state'} ne 'published') {
$filecontents=&createnewhtml();
- $ENV{'form.showmode'}='Edit'; #force edit mode
+ $ENV{'form.editmode'}='Edit'; #force edit mode
}
} else {
unless ($ENV{'request.state'} eq 'published') {
@@ -1141,8 +1225,9 @@ ENDNOTFOUND
$filecontents=&htmlclean($filecontents,1);
}
}
- if ($ENV{'form.showmode'} ne 'Edit') {
- $result = &Apache::lonxml::xmlparse($target,$filecontents,'',%mystyle);
+ if (!$ENV{'form.editmode'} || $ENV{'form.viewmode'}) {
+ $result = &Apache::lonxml::xmlparse($request,$target,$filecontents,
+ '',%mystyle);
}
}
@@ -1150,7 +1235,7 @@ ENDNOTFOUND
# Edit action? Insert editing commands
#
unless ($ENV{'request.state'} eq 'published') {
- if ($ENV{'form.showmode'} eq 'Edit') {
+ if ($ENV{'form.editmode'} && (!($ENV{'form.viewmode'}))) {
$result='';
$result=&inserteditinfo($result,$filecontents);
}
@@ -1172,7 +1257,8 @@ sub debug {
sub error {
if (($Apache::lonxml::debug eq 1) || ($ENV{'request.state'} eq 'construct') ) {
- print "ERROR:".join('
',@_)."
\n";
+ # If printing in construction space, put the error inside
+ print "ERROR:".join("\n",@_)."\n";
} else {
print "An Error occured while processing this resource. The instructor has been notified.
";
#notify author
@@ -1205,6 +1291,7 @@ sub get_param {
if ( ! $context ) { $context = -1; }
my $args ='';
if ( $#$parstack > (-2-$context) ) { $args=$$parstack[$context]; }
+ if ( ! $args ) { return undef; }
if ( $args =~ /my \$$param=\"/ ) {
return &Apache::run::run("{$args;".'return $'.$param.'}',$safeeval); #'
} else {