--- rat/lonpage.pm 2020/03/03 01:16:31 1.134 +++ rat/lonpage.pm 2020/03/04 16:33:31 1.135 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Page Handler # -# $Id: lonpage.pm,v 1.134 2020/03/03 01:16:31 raeburn Exp $ +# $Id: lonpage.pm,v 1.135 2020/03/04 16:33:31 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -44,6 +44,7 @@ use Apache::lonhomework; use Apache::lonparmset; use Apache::lonenc(); use HTML::TokeParser; +use HTML::Entities(); use GDBM_File; use Apache::lonsequence; use lib '/home/httpd/lib/perl/'; @@ -187,6 +188,8 @@ sub handler { if (-e "$fn.db") { my %buttonshide; my $hostname = $r->hostname(); + my $lonhost = $r->dir_config('lonHostID'); + my $ip = &Apache::lonnet::get_host_ip($lonhost); if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER(),0640)) { # ------------------------------------------------------------------- Hash tied my $firstres=$hash{'map_start_'.$requrl}; @@ -304,11 +307,17 @@ sub handler { foreach (@colcont) { my $src=$hash{'src_'.$_}; my $plainsrc = $src; + my $anchor; if ($hash{'ext_'.$_} eq 'true:') { $cellexternal{$_}=($hash{'ext_'.$_} eq 'true:'); $src =~ s{^/ext/}{http://}; $src =~ s{http://https://}{https://}; + if ($src =~ /(\#[^#]+)$/) { + $anchor = $1; + $src =~ s/\#[^#]+$//; + } } + my $unencsrc = $src; my ($extension)=($src=~/\.(\w+)$/); if ($hash{'encrypted_'.$_}) { $src=&Apache::lonenc::encrypted($src); @@ -322,21 +331,50 @@ sub handler { &Apache::loncommon::fileembstyle($extension); if ($cellexternal{$_}) { if (($target eq 'tex') || ($target eq 'tex_answer')) { - my $shown = $src; - if ($hash{'encrypted_'.$_}) { + my $shown = $src.$anchor; + if (($hash{'encrypted_'.$_}) && (!$env{'request.role.adv'})) { $shown = &mt('URL not shown (encrypted)'); } my $title=&Apache::lonnet::gettitle($symb); $title = &Apache::lonxml::latex_special_symbols($title); + $shown = &Apache::lonxml::latex_special_symbols($shown); $ssibody{$_} = ' \strut \\\\ \textit{'.$title.'} \strut \\\\ '.$shown.'\\\\'; } else { my $showsrc = $src; + my ($is_pdf,$title,$linktext); + if ($unencsrc =~ /\.pdf$/i) { + $is_pdf = 1; + } if (($hash{'encrypted_'.$_}) && ($symb)) { - $showsrc .= '?symb='.&Apache::lonenc::encrypted($symb); + $title=&Apache::lonnet::gettitle(&Apache::lonenc::encrypted($symb)); + } else { + $title=&Apache::lonnet::gettitle($symb); } - $ssibody{$_} = <No iframe support! + if ($env{'browser.mobile'}) { + if ($is_pdf) { + $linktext = &mt('Link to PDF (for mobile devices)'); + $ssibody{$_} = &create_extlink($unencsrc,$anchor,$title,$linktext); + } else { + $linktext = &mt('Link to resource'); + $ssibody{$_} = &create_extlink($unencsrc,$anchor,$title,$linktext); + } + } else { + my $absolute = $env{'request.use_absolute'}; + my $uselink = &Apache::loncommon::is_nonframeable($unencsrc,$absolute,$hostname,$ip); + if (($uselink) || (($ENV{'SERVER_PORT'} == 443) && ($unencsrc =~ m{^http://}))) { + $linktext = &mt('Link to resource'); + $ssibody{$_} = &create_extlink($unencsrc,$anchor,$title,$linktext); + } else { + if (($hash{'encrypted_'.$_}) && ($symb) && (!$env{'request.role.adv'})) { + $showsrc .= '?symb='.&Apache::lonenc::encrypted($symb); + } elsif ($anchor) { + $showsrc .= $anchor + } + $ssibody{$_} = <No iframe support! ENDEXT + } + } } } elsif ($cellemb{$_} eq 'ssi') { # --------------------------------------------------------- This is an SSI cell @@ -798,10 +836,7 @@ ENDEXT } $r->print('>'); } - unless (($cellexternal{$rid}) && - ($target eq 'tex') && ($target eq 'tex_answer')) { - $r->print($ssibody{$rid}); - } + $r->print($ssibody{$rid}); unless (($target eq 'tex') || ($target eq 'tex_answer')) { $r->print(''); } @@ -1084,6 +1119,16 @@ END return; } +sub create_extlink { + my ($url,$anchor,$title,$linktext) = @_; + my $shownlink; + unless ($title eq '') { + $shownlink = ''.$title.'
'; + } + my $dest = &HTML::Entities::encode($url.$anchor,'&<>"'); + $shownlink .= ''.$linktext.''; + return $shownlink; +} 1; __END__ 500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.