version 1.99, 2001/07/03 20:58:27
|
version 1.103, 2001/07/27 00:18:59
|
Line 92 sub xmlbegin {
|
Line 92 sub xmlbegin {
|
} |
} |
|
|
sub xmlend { |
sub xmlend { |
return '</html>'; |
my $discussion=''; |
|
if ($ENV{'request.course.id'}) { |
|
my $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>'; |
|
my $idx; |
|
for ($idx=1;$idx<=$contrib{'version'};$idx++) { |
|
my $message=$contrib{$idx.':message'}; |
|
$message=~s/\n/\<br \/\>/g; |
|
$discussion.='<p><b>'.$contrib{$idx.':sendername'}.' at '. |
|
$contrib{$idx.':senderdomain'}.'</b> ('. |
|
localtime($contrib{$idx.':timestamp'}). |
|
'):<blockquote>'.$message. |
|
'</blockquote></p>'; |
|
} |
|
$discussion.='</address>'; |
|
} |
|
} |
|
} |
|
return $discussion.'</html>'; |
} |
} |
|
|
sub fontsettings() { |
sub fontsettings() { |
Line 105 sub fontsettings() {
|
Line 129 sub fontsettings() {
|
} |
} |
|
|
sub registerurl { |
sub registerurl { |
|
my $forcereg=shift; |
if ($Apache::lonxml::registered) { return ''; } |
if ($Apache::lonxml::registered) { return ''; } |
if ($ENV{'REQUEST_URI'}!~/^\/(res\/)*adm\//) { |
if (($ENV{'REQUEST_URI'}!~/^\/(res\/)*adm\//) || ($forcereg)) { |
my $hwkadd=''; |
my $hwkadd=''; |
if ($ENV{'REQUEST_URI'}=~/\.(problem|exam|quiz|assess|survey|form)$/) { |
if ($ENV{'REQUEST_URI'}=~/\.(problem|exam|quiz|assess|survey|form)$/) { |
if (&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) { |
if (&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) { |
Line 233 sub xmlparse {
|
Line 258 sub xmlparse {
|
&setup_globals($target); |
&setup_globals($target); |
#&printalltags(); |
#&printalltags(); |
my @pars = (); |
my @pars = (); |
@Apache::lonxml::pwd=(); |
|
my $pwd=$ENV{'request.filename'}; |
my $pwd=$ENV{'request.filename'}; |
$pwd =~ s:/[^/]*$::; |
$pwd =~ s:/[^/]*$::; |
&newparser(\@pars,\$content_file_string,$pwd); |
&newparser(\@pars,\$content_file_string,$pwd); |
my $currentstring = ''; |
|
my $finaloutput = ''; |
|
my $newarg = ''; |
|
my $result; |
|
|
|
my $safeeval = new Safe; |
my $safeeval = new Safe; |
my $safehole = new Safe::Hole; |
my $safehole = new Safe::Hole; |
Line 252 sub xmlparse {
|
Line 272 sub xmlparse {
|
my @stack = (); |
my @stack = (); |
my @parstack = (); |
my @parstack = (); |
&initdepth; |
&initdepth; |
my $token; |
|
while ( $#pars > -1 ) { |
|
while ($token = $pars[$#pars]->get_token) { |
|
if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) { |
|
if ($metamode<1) { $result=$token->[1]; } |
|
} elsif ($token->[0] eq 'PI') { |
|
if ($metamode<1) { $result=$token->[2]; } |
|
} elsif ($token->[0] eq 'S') { |
|
# add tag to stack |
|
push (@stack,$token->[1]); |
|
# add parameters list to another stack |
|
push (@parstack,&parstring($token)); |
|
&increasedepth($token); |
|
if (exists $style_for_target{$token->[1]}) { |
|
if ($Apache::lonxml::redirection) { |
|
$Apache::lonxml::outputstack['-1'] .= |
|
&recurse($style_for_target{$token->[1]},$target,$safeeval, |
|
\%style_for_target,@parstack); |
|
} else { |
|
$finaloutput .= &recurse($style_for_target{$token->[1]},$target, |
|
$safeeval,\%style_for_target,@parstack); |
|
} |
|
} else { |
|
$result = &callsub("start_$token->[1]", $target, $token, \@stack, |
|
\@parstack, \@pars, $safeeval, \%style_for_target); |
|
} |
|
} elsif ($token->[0] eq 'E') { |
|
#clear out any tags that didn't end |
|
while ($token->[1] ne $stack[$#stack] && ($#stack > -1)) { |
|
&Apache::lonxml::warning("Unbalanced tags in resource $stack['-1']"); |
|
&end_tag(\@stack,\@parstack,$token); |
|
} |
|
|
|
if (exists $style_for_target{'/'."$token->[1]"}) { |
|
if ($Apache::lonxml::redirection) { |
|
$Apache::lonxml::outputstack['-1'] .= |
|
&recurse($style_for_target{'/'."$token->[1]"}, |
|
$target,$safeeval,\%style_for_target,@parstack); |
|
} else { |
|
$finaloutput .= &recurse($style_for_target{'/'."$token->[1]"}, |
|
$target,$safeeval,\%style_for_target, |
|
@parstack); |
|
} |
|
|
|
} else { |
|
$result = &callsub("end_$token->[1]", $target, $token, \@stack, |
|
\@parstack, \@pars,$safeeval, \%style_for_target); |
|
} |
|
} else { |
|
&Apache::lonxml::error("Unknown token event :$token->[0]:$token->[1]:"); |
|
} |
|
#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[$#parstack]); |
|
} else { |
|
$finaloutput .= &Apache::run::evaluate($result,$safeeval, |
|
$parstack[$#parstack]); |
|
} |
|
} else { |
|
$finaloutput .= &Apache::run::evaluate($result,$safeeval,''); |
|
} |
|
$result = ''; |
|
} |
|
if ($token->[0] eq 'E') { |
|
&end_tag(\@stack,\@parstack,$token); |
|
} |
|
} |
|
pop @pars; |
|
pop @Apache::lonxml::pwd; |
|
} |
|
|
|
# if ($target eq 'meta') { |
|
# $finaloutput.=&endredirection; |
|
# } |
|
|
|
if (($ENV{'QUERY_STRING'}) && ($target eq 'web')) { |
my $finaloutput = &inner_xmlparse($target,\@stack,\@parstack,\@pars, |
$finaloutput=&afterburn($finaloutput); |
$safeeval,\%style_for_target); |
} |
|
|
|
return $finaloutput; |
return $finaloutput; |
} |
} |
|
|
|
sub inner_xmlparse { |
|
my ($target,$stack,$parstack,$pars,$safeeval,$style_for_target)=@_; |
|
&Apache::lonxml::debug('Reentrant parser starting, again?'); |
|
my $finaloutput = ''; |
|
my $result; |
|
my $token; |
|
while ( $#$pars > -1 ) { |
|
while ($token = $$pars['-1']->get_token) { |
|
if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) { |
|
if ($metamode<1) { |
|
$result=$token->[1]; |
|
} |
|
} elsif ($token->[0] eq 'PI') { |
|
if ($metamode<1) { |
|
$result=$token->[2]; |
|
} |
|
} elsif ($token->[0] eq 'S') { |
|
# add tag to stack |
|
push (@$stack,$token->[1]); |
|
# add parameters list to another stack |
|
push (@$parstack,&parstring($token)); |
|
&increasedepth($token); |
|
if (exists $$style_for_target{$token->[1]}) { |
|
if ($Apache::lonxml::redirection) { |
|
$Apache::lonxml::outputstack['-1'] .= |
|
&recurse($$style_for_target{$token->[1]},$target,$safeeval, |
|
$style_for_target,@$parstack); |
|
} else { |
|
$finaloutput .= &recurse($$style_for_target{$token->[1]},$target, |
|
$safeeval,$style_for_target,@$parstack); |
|
} |
|
} else { |
|
$result = &callsub("start_$token->[1]", $target, $token, $stack, |
|
$parstack, $pars, $safeeval, $style_for_target); |
|
} |
|
} elsif ($token->[0] eq 'E') { |
|
#clear out any tags that didn't end |
|
while ($token->[1] ne $$stack['-1'] && ($#$stack > -1)) { |
|
&Apache::lonxml::warning("Unbalanced tags in resource $$stack['-1']"); |
|
&end_tag($stack,$parstack,$token); |
|
} |
|
|
|
if (exists $$style_for_target{'/'."$token->[1]"}) { |
|
if ($Apache::lonxml::redirection) { |
|
$Apache::lonxml::outputstack['-1'] .= |
|
&recurse($$style_for_target{'/'."$token->[1]"}, |
|
$target,$safeeval,$style_for_target,@$parstack); |
|
} else { |
|
$finaloutput .= &recurse($$style_for_target{'/'."$token->[1]"}, |
|
$target,$safeeval,$style_for_target, |
|
@$parstack); |
|
} |
|
|
|
} else { |
|
$result = &callsub("end_$token->[1]", $target, $token, $stack, |
|
$parstack, $pars,$safeeval, $style_for_target); |
|
} |
|
} else { |
|
&Apache::lonxml::error("Unknown token event :$token->[0]:$token->[1]:"); |
|
} |
|
#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']); |
|
} |
|
} else { |
|
$finaloutput .= &Apache::run::evaluate($result,$safeeval,''); |
|
} |
|
$result = ''; |
|
} |
|
if ($token->[0] eq 'E') { |
|
&end_tag($stack,$parstack,$token); |
|
} |
|
} |
|
pop @$pars; |
|
pop @Apache::lonxml::pwd; |
|
} |
|
|
|
# if ($target eq 'meta') { |
|
# $finaloutput.=&endredirection; |
|
# } |
|
|
|
if (($ENV{'QUERY_STRING'}) && ($target eq 'web')) { |
|
$finaloutput=&afterburn($finaloutput); |
|
} |
|
return $finaloutput; |
|
} |
|
|
sub recurse { |
sub recurse { |
|
|
my @innerstack = (); |
my @innerstack = (); |
my @innerparstack = (); |
my @innerparstack = (); |
my ($newarg,$target,$safeeval,$style_for_target,@parstack) = @_; |
my ($newarg,$target,$safeeval,$style_for_target,@parstack) = @_; |
Line 469 sub callsub {
|
Line 502 sub callsub {
|
sub setup_globals { |
sub setup_globals { |
my ($target)=@_; |
my ($target)=@_; |
$Apache::lonxml::registered = 0; |
$Apache::lonxml::registered = 0; |
|
@Apache::lonxml::pwd=(); |
if ($target eq 'meta') { |
if ($target eq 'meta') { |
$Apache::lonxml::redirection = 0; |
$Apache::lonxml::redirection = 0; |
$Apache::lonxml::metamode = 1; |
$Apache::lonxml::metamode = 1; |
Line 503 sub init_safespace {
|
Line 537 sub init_safespace {
|
$safeeval->permit(":base_math"); |
$safeeval->permit(":base_math"); |
$safeeval->permit("sort"); |
$safeeval->permit("sort"); |
$safeeval->deny(":base_io"); |
$safeeval->deny(":base_io"); |
|
$safehole->wrap(\&Apache::scripttag::xmlparse,$safeeval,'&xmlparse'); |
$safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT'); |
$safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT'); |
|
|
$safehole->wrap(\&Math::Cephes::asin,$safeeval,'&asin'); |
$safehole->wrap(\&Math::Cephes::asin,$safeeval,'&asin'); |