--- loncom/xml/lonxml.pm 2002/07/29 22:06:38 1.186 +++ loncom/xml/lonxml.pm 2002/10/08 17:09:09 1.199 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # XML Parser Module # -# $Id: lonxml.pm,v 1.186 2002/07/29 22:06:38 www Exp $ +# $Id: lonxml.pm,v 1.199 2002/10/08 17:09:09 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -99,6 +99,7 @@ use Apache::edit(); use Apache::lonnet(); use Apache::File(); use Apache::loncommon(); +use Apache::lonfeedback(); #================================================== Main subroutine: xmlparse #debugging control, to turn on debugging modify the correct handler @@ -154,6 +155,7 @@ sub xmlbegin { } sub xmlend { + my ($discussiononly,$symb)=@_; my $discussion=''; if ($ENV{'request.course.id'}) { my $crs='/'.$ENV{'request.course.id'}; @@ -162,14 +164,18 @@ sub xmlend { } $crs=~s/\_/\//g; my $seeid=&Apache::lonnet::allowed('rin',$crs); - my $symb=&Apache::lonnet::symbread(); + unless ($symb) { + $symb=&Apache::lonnet::symbread(); + } if ($symb) { my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'}, $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, $ENV{'course.'.$ENV{'request.course.id'}.'.num'}); if ($contrib{'version'}) { - $discussion.= - '<address><hr /><h2>Course Discussion of Resource</h2>'; + unless ($discussiononly) { + $discussion.= + '<address><hr />'; + } my $idx; for ($idx=1;$idx<=$contrib{'version'};$idx++) { my $hidden=($contrib{'hidden'}=~/\.$idx\./); @@ -181,14 +187,24 @@ sub xmlend { if ($hidden) { $message='<font color="#888888">'.$message.'</font>'; } + my $screenname=&Apache::loncommon::screenname( + $contrib{$idx.':sendername'}, + $contrib{$idx.':senderdomain'}); + my $plainname=&Apache::loncommon::nickname( + $contrib{$idx.':sendername'}, + $contrib{$idx.':senderdomain'}); + my $sender='Anonymous'; if ((!$contrib{$idx.':anonymous'}) || ($seeid)) { - $sender=$contrib{$idx.':plainname'}.' ('. + $sender=&Apache::loncommon::aboutmewrapper( + $plainname, + $contrib{$idx.':sendername'}, + $contrib{$idx.':senderdomain'}).' ('. $contrib{$idx.':sendername'}.' at '. $contrib{$idx.':senderdomain'}.')'; if ($contrib{$idx.':anonymous'}) { $sender.=' [anonymous] '. - $contrib{$idx.':screenname'}; + $screenname; } if ($seeid) { if ($hidden) { @@ -200,8 +216,8 @@ sub xmlend { } } } else { - if ($contrib{$idx.':screenname'}) { - $sender='<i>'.$contrib{$idx.':screenname'}.'</i>'; + if ($screenname) { + $sender='<i>'.$screenname.'</i>'; } } $discussion.='<p><b>'.$sender.'</b> ('. @@ -211,11 +227,28 @@ sub xmlend { } } } - $discussion.='</address>'; + unless ($discussiononly) { + $discussion.='</address>'; + } + } + if ($discussiononly) { + $discussion.=(<<ENDDISCUSS); +<form action="/adm/feedback" method="post" name="mailform"> +<input type="submit" name="discuss" value="Post Discussion" /> +<input type="submit" name="anondiscuss" value="Post Anonymous Discussion" /> +<input type="hidden" name="symb" value="$symb" /> +<input type="hidden" name="sendit" value="true" /> +<br /> +<font size="1">Note: in anonymous discussion, your name is visible only to +course faculty</font><br /> +<textarea name=comment cols=60 rows=10 wrap=hard></textarea> +</form> +ENDDISCUSS + $discussion.=&Apache::lonfeedback::generate_preview_button(); } } } - return $discussion.'</html>'; + return $discussion.($discussiononly?'':'</html>'); } sub tokeninputfield { @@ -332,8 +365,10 @@ sub registerurl { my $forcereg=shift; my $target = shift; my $result = ''; + if ($target eq 'edit') { - $result .="<script>\n menu.currentURL=null;\n". + $result .="<script>\n". + "if (typeof menu != 'undefined') {menu.currentURL=null;}\n". &Apache::loncommon::browser_and_searcher_javascript(). "\n</script>\n"; } @@ -538,6 +573,26 @@ sub htmlclean { return $output; } +sub latex_special_symbols { + my ($current_token,$stack,$parstack)=@_; + $current_token=~s/\\/\\char92 /g; + $current_token=~s/\^/\\char94 /g; + $current_token=~s/\~/\\char126 /g; + $current_token=~s/(&[^a-z\#])/\\$1/g; + if ($current_token=~/ \#\w/) { + $current_token=~s/ \#(\w)/ \\#$1/; + } else { + $current_token=~s/([^&])(\#)/$1\\$2/g; + } + $current_token=~s/(\$|_|{|})/\\$1/g; + $current_token=~s/\\char92 /\\texttt{\\char92}/g; + $current_token=~s/>/\$>\$/g; #more + $current_token=~s/</\$<\$/g; #less + if ($current_token=~m/\d%/) {$current_token =~ s/(\d)%/$1\\%/g;} #percent after digit + if ($current_token=~m/\s%/) {$current_token =~ s/(\s)%/$1\\%/g;} #persent after space + return $current_token; +} + sub inner_xmlparse { my ($target,$stack,$parstack,$pars,$safeeval,$style_for_target)=@_; my $finaloutput = ''; @@ -547,19 +602,12 @@ 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) { - 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;} - } - if ($token->[1]=~m/>/) {$token->[1]=~s/>/\$>\$/g;} - if ($token->[1]=~m/</) {$token->[1]=~s/</\$<\$/g;} - } + my $text=$token->[1]; + if ($token->[0] eq 'C' && $target eq 'tex') { + $text = '%'.$text; + $text =~ s/[\n\r]//g; } - $result.=$token->[1]; + $result.=$text; } } elsif ($token->[0] eq 'PI') { if ($metamode<1) { @@ -622,6 +670,12 @@ sub inner_xmlparse { $result= &Apache::run::evaluate($result,$safeeval,''); } } + if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) { + if ($target eq 'tex') { + $result=&latex_special_symbols($result,$stack,$parstack); + } + } + # Encode any high ASCII characters if (!$Apache::lonxml::prevent_entity_encode) { $result=&HTML::Entities::encode($result,"\200-\377"); @@ -748,13 +802,13 @@ sub callsub { } if (!$deleted) { if ($space) { - #&Apache::lonxml::debug("Calling sub $sub in $space $metamode"); + &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"); + &Apache::lonxml::debug("NOT Calling sub $sub in $space $metamode"); if ($metamode <1) { if (defined($token->[4]) && ($metamode < 1)) { $currentstring = $token->[4]; @@ -947,6 +1001,7 @@ sub decreasedepth { } sub get_all_text_unbalanced { +#there is a copy of this in lonpublisher.pm my($tag,$pars)= @_; my $token; my $result='';