[LON-CAPA-cvs] cvs: loncom / lonencurl.pm rat lonpage.pm
raeburn
raeburn at source.lon-capa.org
Wed Mar 4 11:33:35 EST 2020
raeburn Wed Mar 4 16:33:35 2020 EDT
Modified files:
/rat lonpage.pm
/loncom lonencurl.pm
Log:
- External resource(s) in a composite page.
- Support external resource with anchor
- Support display where encrypted URL parameter is set for resource.
- Display as link, not iframe, on (a) mobile devices, (b) if resource's
server has Content-Security-Policy or X-Frame-Options set to prevent
iframe use, or (c) URL is http, but LON-CAPA page is served https.
-------------- next part --------------
Index: rat/lonpage.pm
diff -u rat/lonpage.pm:1.134 rat/lonpage.pm:1.135
--- rat/lonpage.pm:1.134 Tue Mar 3 01:16:31 2020
+++ rat/lonpage.pm Wed Mar 4 16:33:31 2020
@@ -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::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 @@
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 @@
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 @@
&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{$_} = <<ENDEXT;
-<iframe src="$showsrc" width="100%">No iframe support!</iframe>
+ 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{$_} = <<ENDEXT;
+<iframe src="$showsrc" width="100%" height="300px">No iframe support!</iframe>
ENDEXT
+ }
+ }
}
} elsif ($cellemb{$_} eq 'ssi') {
# --------------------------------------------------------- This is an SSI cell
@@ -798,10 +836,7 @@
}
$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('</font>');
}
@@ -1084,6 +1119,16 @@
return;
}
+sub create_extlink {
+ my ($url,$anchor,$title,$linktext) = @_;
+ my $shownlink;
+ unless ($title eq '') {
+ $shownlink = '<span style="font-weight:bold;">'.$title.'</span><br />';
+ }
+ my $dest = &HTML::Entities::encode($url.$anchor,'&<>"');
+ $shownlink .= '<a href="'.$dest.'">'.$linktext.'</a>';
+ return $shownlink;
+}
1;
__END__
Index: loncom/lonencurl.pm
diff -u loncom/lonencurl.pm:1.6 loncom/lonencurl.pm:1.7
--- loncom/lonencurl.pm:1.6 Mon Feb 22 03:36:57 2016
+++ loncom/lonencurl.pm Wed Mar 4 16:33:35 2020
@@ -2,7 +2,7 @@
# The LearningOnline Network
# URL translation for encrypted filenames
#
-# $Id: lonencurl.pm,v 1.6 2016/02/22 03:36:57 raeburn Exp $
+# $Id: lonencurl.pm,v 1.7 2020/03/04 16:33:35 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -80,8 +80,27 @@
if ($redirect eq '') {
$redirect=&Apache::lonenc::unencrypted($r->uri);
if ($redirect =~ m{^/adm/wrapper/ext/[^\#]+(\#.+)$}) {
- $anchor = $1;
- $redirect =~ s/\#.+$//;
+ $anchor = $1;
+ $redirect =~ s/\#.+$//;
+ } elsif (($redirect =~ m{^https?://}) && ($r->args)) {
+ my $symb;
+ foreach my $item (split(/\&/,$r->args)) {
+ my ($key,$value) = split(/=/,$item);
+ if ($key eq 'symb') {
+ $symb = &Apache::lonenc::unencrypted($value);
+ last;
+ }
+ }
+ if ($symb) {
+ my ($map,$id,$res) = &Apache::lonnet::decode_symb($symb);
+ if (($map =~ /\.page$/) && ($res =~ m{^ext/})) {
+ if ($res =~ /(\#[^#]+)$/) {
+ $anchor = $1;
+ }
+ $r->headers_out->set(Location => $redirect.$anchor);
+ return REDIRECT;
+ }
+ }
}
}
if ($r->args) { $redirect.='?'.$r->args; }
More information about the LON-CAPA-cvs
mailing list