--- loncom/xml/lonxml.pm 2002/03/22 17:52:20 1.161
+++ loncom/xml/lonxml.pm 2002/09/04 21:01:33 1.193
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# XML Parser Module
#
-# $Id: lonxml.pm,v 1.161 2002/03/22 17:52:20 albertel Exp $
+# $Id: lonxml.pm,v 1.193 2002/09/04 21:01:33 albertel 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'}) {
@@ -170,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) {
@@ -190,6 +199,10 @@ sub xmlend {
$symb.':::'.$idx.'">Hide';
}
}
+ } else {
+ if ($contrib{$idx.':screenname'}) {
+ $sender=''.$contrib{$idx.':screenname'}.'';
+ }
}
$discussion.='
'.$sender.' ('.
localtime($contrib{$idx.':timestamp'}).
@@ -319,37 +332,39 @@ 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_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.=(<
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;
@@ -981,7 +1039,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]);
@@ -1104,9 +1162,9 @@ BUTTONS
ENDFOOTER
@@ -1195,7 +1253,8 @@ ENDNOTFOUND
}
}
if (!$ENV{'form.editmode'} || $ENV{'form.viewmode'}) {
- $result = &Apache::lonxml::xmlparse($target,$filecontents,'',%mystyle);
+ $result = &Apache::lonxml::xmlparse($request,$target,$filecontents,
+ '',%mystyle);
}
}
@@ -1204,7 +1263,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);
}
}
@@ -1219,13 +1281,14 @@ ENDNOTFOUND
sub debug {
if ($Apache::lonxml::debug eq 1) {
$|=1;
- print("DEBUG:".join('
',@_)."
\n");
+ print("DEBUG:".&HTML::Entities::encode($_[0])."
\n");
}
}
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