[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm
raeburn
raeburn at source.lon-capa.org
Tue Nov 10 12:19:17 EST 2020
raeburn Tue Nov 10 17:19:17 2020 EDT
Modified files:
/loncom/interface loncommon.pm
Log:
- Move &css_links() from grades.pm to loncommon.pm to facilitate reuse.
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1348 loncom/interface/loncommon.pm:1.1349
--- loncom/interface/loncommon.pm:1.1348 Thu Oct 1 10:16:33 2020
+++ loncom/interface/loncommon.pm Tue Nov 10 17:19:17 2020
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.1348 2020/10/01 10:16:33 raeburn Exp $
+# $Id: loncommon.pm,v 1.1349 2020/11/10 17:19:17 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -4893,6 +4893,59 @@
}
}
+sub css_links {
+ my ($currsymb,$level) = @_;
+ my ($links, at symbs,%cssrefs,%httpref);
+ if ($level eq 'map') {
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ if (ref($navmap)) {
+ my ($map,undef,$url)=&Apache::lonnet::decode_symb($currsymb);
+ my @resources = $navmap->retrieveResources($map,sub { $_[0]->is_problem() },0,0);
+ foreach my $res (@resources) {
+ if (ref($res) && $res->symb()) {
+ push(@symbs,$res->symb());
+ }
+ }
+ }
+ } else {
+ @symbs = ($currsymb);
+ }
+ foreach my $symb (@symbs) {
+ my $css_href = &Apache::lonnet::EXT('resource.0.cssfile',$symb);
+ if ($css_href =~ /\S/) {
+ unless ($css_href =~ m{https?://}) {
+ my $url = (&Apache::lonnet::decode_symb($symb))[-1];
+ my $proburl = &Apache::lonnet::clutter($url);
+ my ($probdir) = ($proburl =~ m{(.+)/[^/]+$});
+ unless ($css_href =~ m{^/}) {
+ $css_href = &Apache::lonnet::hreflocation($probdir,$css_href);
+ }
+ if ($css_href =~ m{^/(res|uploaded)/}) {
+ unless (($httpref{'httpref.'.$css_href}) ||
+ (&Apache::lonnet::is_on_map($css_href))) {
+ my $thisurl = $proburl;
+ if ($env{'httpref.'.$proburl}) {
+ $thisurl = $env{'httpref.'.$proburl};
+ }
+ $httpref{'httpref.'.$css_href} = $thisurl;
+ }
+ }
+ }
+ $cssrefs{$css_href} = 1;
+ }
+ }
+ if (keys(%httpref)) {
+ &Apache::lonnet::appenv(\%httpref);
+ }
+ 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";
+ }
+ }
+ return $links;
+}
+
=pod
=item * &get_student_answers()
More information about the LON-CAPA-cvs
mailing list