--- loncom/xml/lonxml.pm 2002/01/17 17:42:34 1.149
+++ loncom/xml/lonxml.pm 2002/09/04 04:55:13 1.191
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# XML Parser Module
#
-# $Id: lonxml.pm,v 1.149 2002/01/17 17:42:34 albertel Exp $
+# $Id: lonxml.pm,v 1.191 2002/09/04 04:55:13 albertel 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'}) {
@@ -169,16 +176,19 @@ sub xmlend {
unless (($hidden) && (!$seeid)) {
my $message=$contrib{$idx.':message'};
$message=~s/\n/\
/g;
+ $message=&Apache::lontexconvert::msgtexconverted($message);
if ($message) {
if ($hidden) {
$message=''.$message.'';
}
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 +199,10 @@ sub xmlend {
$symb.':::'.$idx.'">Hide';
}
}
+ } else {
+ if ($contrib{$idx.':screenname'}) {
+ $sender=''.$contrib{$idx.':screenname'}.'';
+ }
}
$discussion.='
'.$sender.' ('.
localtime($contrib{$idx.':timestamp'}).
@@ -316,46 +330,55 @@ sub fontsettings() {
sub registerurl {
my $forcereg=shift;
- if ($ENV{'request.publicaccess'}) {
- return
+ my $target = shift;
+ my $result = '';
+ 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_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.=(<
\n");
+ &Apache::lonxml::debug("Calling sub $sub in $space $metamode");
$sub1="$space\:\:$sub";
($currentstring,$nodefault) = &$sub1($target,$token,$tagstack,
$parstack,$parser,$safeeval,
$style);
} else {
- #&Apache::lonxml::debug("NOT Calling sub $sub in $space $metamode
\n");
+ &Apache::lonxml::debug("NOT Calling sub $sub in $space $metamode");
if ($metamode <1) {
if (defined($token->[4]) && ($metamode < 1)) {
$currentstring = $token->[4];
@@ -717,7 +806,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=();
@@ -746,6 +836,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;
@@ -869,8 +964,35 @@ sub decreasedepth {
#print "
e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n";
}
-sub get_all_text {
+sub get_all_text_unbalanced {
+#there is a copy of this in lonpublisher.pm
+ 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;
@@ -885,10 +1007,10 @@ sub get_all_text {
} elsif ($token->[0] eq 'PI') {
$result.=$token->[2];
} elsif ($token->[0] eq 'S') {
- if ($token->[1] eq $tag) { $depth++; }
+ if ($token->[1] =~ /^$tag$/i) { $depth++; }
$result.=$token->[4];
} elsif ($token->[0] eq 'E') {
- if ( $token->[1] eq $tag) { $depth--; }
+ if ( $token->[1] =~ /^$tag$/i) { $depth--; }
#skip sending back the last end tag
if ($depth > -1) { $result.=$token->[2]; } else {
$pars->unget_token($token);
@@ -903,7 +1025,7 @@ sub get_all_text {
} elsif ($token->[0] eq 'PI') {
$result.=$token->[2];
} elsif ($token->[0] eq 'S') {
- if ( $token->[1] eq $tag) {
+ if ( $token->[1] =~ /^$tag$/i) {
$pars->unget_token($token); last;
} else {
$result.=$token->[4];
@@ -919,7 +1041,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]);
@@ -936,7 +1058,7 @@ sub parstring {
foreach (@{$token->[3]}) {
unless ($_=~/\W/) {
my $val=$token->[2]->{$_};
- $val =~ s/([\%\@\\])/\\$1/g;
+ $val =~ s/([\%\@\\\"])/\\$1/g;
#if ($val =~ m/^[\%\@]/) { $val="\\".$val; }
$temp .= "my \$$_=\"$val\";"
}
@@ -966,16 +1088,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=$_;
@@ -1016,10 +1130,8 @@ sub storefile {
}
}
-sub inserteditinfo {
- my ($result,$filecontents)=@_;
- unless ($filecontents) {
- $filecontents=(<