[LON-CAPA-cvs] cvs: rat(version_2_11_X) / lonpage.pm
raeburn
raeburn at source.lon-capa.org
Wed Nov 11 16:52:05 EST 2020
raeburn Wed Nov 11 21:52:05 2020 EDT
Modified files: (Branch: version_2_11_X)
/rat lonpage.pm
Log:
- For 2.11
Backport 1.139
Index: rat/lonpage.pm
diff -u rat/lonpage.pm:1.111.2.12 rat/lonpage.pm:1.111.2.13
--- rat/lonpage.pm:1.111.2.12 Thu Mar 12 07:46:14 2020
+++ rat/lonpage.pm Wed Nov 11 21:52:05 2020
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Page Handler
#
-# $Id: lonpage.pm,v 1.111.2.12 2020/03/12 07:46:14 raeburn Exp $
+# $Id: lonpage.pm,v 1.111.2.13 2020/11/11 21:52:05 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -246,6 +246,8 @@
my %ssilink=();
my %ssivlink=();
my %ssialink=();
+ my %cssrefs=();
+ my %httpref=();
my %cellemb=();
my %cellexternal=();
@@ -401,6 +403,7 @@
my $bodydef=0;
my $thisxml=0;
my @rlinks=();
+ my @css_hrefs=();
if ($output=~/\?xml/) {
$isxml=1;
$thisxml=1;
@@ -443,6 +446,14 @@
($bodydef==0)) {
$allscript.="\n\n"
.$parser->get_text('/script');
+ } elsif (($token->[1] eq 'link') &&
+ ($bodydef==0)) {
+ if (($token->[2]->{'href'} !~ m{^/adm/}) &&
+ ($token->[2]->{'rel'} eq 'stylesheet')) {
+ $css_hrefs[$#css_hrefs+1]=
+ $token->[2]->{'href'};
+
+ }
}
}
}
@@ -564,6 +575,28 @@
$output=~s/(\"|\'|\=\s*)$_(\"|\'|\s|\>)/$1$newlocation$2/;
}
}
+ foreach my $css_href (@css_hrefs) {
+ next if ($css_href eq '');
+ unless ($css_href =~ m{https?://}) {
+ my $proburl = &Apache::lonnet::clutter($plainsrc);
+ unless ($css_href =~ m{^/}) {
+ my $probdir = $proburl;
+ $probdir=~s/\/[^\/]*$//;
+ $css_href = &Apache::lonnet::hreflocation($probdir,$css_href);
+ }
+ if ($css_href =~ m{^/(res|uploaded)/}) {
+ unless (($env{'httpref.'.$css_href}) ||
+ ($httpref{'httpref.'.$css_href}) ||
+ (&Apache::lonnet::is_on_map($css_href))) {
+ if ($env{'httpref.'.$proburl}) {
+ $proburl = $env{'httpref.'.$proburl};
+ }
+ $httpref{'httpref.'.$css_href} = $proburl;
+ }
+ }
+ }
+ $cssrefs{$css_href} = 1;
+ }
# -------------------------------------------------- Deal with Applet codebases
$output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
$ssibody{$_}=$output;
@@ -663,6 +696,21 @@
}
}
}
+ if (keys(%cssrefs)) {
+ my $links;
+ if (keys(%cssrefs)) {
+ foreach my $css_href (keys(%cssrefs)) {
+ next unless ($css_href =~ m{^(/res/|/uploaded/|https?://)});
+ $links .= '<link rel="stylesheet" type="text/css" href="'.$css_href.'" />'."\n";
+ }
+ }
+ if ($links) {
+ if (keys(%httpref)) {
+ &Apache::lonnet::appenv(\%httpref);
+ }
+ $allscript .= "\n$links";
+ }
+ }
# ------------------------------------------------------------------ Start body
$r->print(&Apache::loncommon::start_page(undef,$allscript,
{'force_register' => 1,
More information about the LON-CAPA-cvs
mailing list