[LON-CAPA-cvs] cvs: rat(version_2_11_X) / lonwrapper.pm

raeburn raeburn at source.lon-capa.org
Tue Jul 30 20:36:10 EDT 2019


raeburn		Wed Jul 31 00:36:10 2019 EDT

  Modified files:              (Branch: version_2_11_X)
    /rat	lonwrapper.pm 
  Log:
  - For 2.11
    Backport 1.69
  
  
Index: rat/lonwrapper.pm
diff -u rat/lonwrapper.pm:1.49.2.5 rat/lonwrapper.pm:1.49.2.6
--- rat/lonwrapper.pm:1.49.2.5	Sun Jul 28 04:05:38 2019
+++ rat/lonwrapper.pm	Wed Jul 31 00:36:10 2019
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Wrapper for external and binary files as standalone resources
 #
-# $Id: lonwrapper.pm,v 1.49.2.5 2019/07/28 04:05:38 raeburn Exp $
+# $Id: lonwrapper.pm,v 1.49.2.6 2019/07/31 00:36:10 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -40,7 +40,7 @@
 
 # ================================================================ Main Handler
 sub wrapper {
-    my ($url,$brcrum,$absolute,$is_ext,$is_pdf,$title) = @_;
+    my ($r,$url,$brcrum,$absolute,$is_ext,$is_pdf,$title) = @_;
 
     my $forcereg;
     unless ($env{'form.folderpath'}) {
@@ -52,7 +52,7 @@
                                           'show' => 'Show content in pop-up window',
                                         );
 
-    my $anchor;
+    my ($anchor,$uselink);
     if ($is_ext) {
         if ($env{'form.symb'}) {
             (undef,undef,my $res) = &Apache::lonnet::decode_symb($env{'form.symb'});
@@ -62,6 +62,12 @@
         } elsif ($env{'form.anchor'} ne '') {
             $anchor = '#'.$env{'form.anchor'};
         }
+        unless (($is_pdf) && ($env{'browser.mobile'})) {
+            my $hostname = $r->hostname();
+            my $lonhost = $r->dir_config('lonHostID');
+            my $ip = &Apache::lonnet::get_host_ip($lonhost);
+            $uselink = &Apache::loncommon::is_nonframeable($url,$absolute,$hostname,$ip);
+        }
     }
 
     my $noiframe = &Apache::loncommon::modal_link($url.$anchor,$lt{'show'},500,400);
@@ -82,31 +88,39 @@
     my $startpage = &Apache::loncommon::start_page('Menu',undef,$args);
     my $endpage = &Apache::loncommon::end_page();
 
+    if (($uselink) && ($title eq '')) {
+        if ($env{'form.symb'}) {
+            $title=&Apache::lonnet::gettitle($env{'form.symb'});
+        } else {
+            my $symb=&Apache::lonnet::symbread($r->uri);
+            if ($symb) {
+                $title=&Apache::lonnet::gettitle($symb);
+            }
+        }
+    }
     if ($env{'browser.mobile'}) {
         my $output = $startpage;
         if ($is_pdf) {
-            if ($title eq '') {
-                $title = $env{'form.title'};
-                if ($title eq '') {
-                    unless ($env{'request.enc'}) {
-                        ($title) = ($url =~ m{/([^/]+)$});
-                        $title =~ s/(\?[^\?]+)$//;
-                    }
-                }
-            }
-            unless ($title eq '') {
-                $output .= $title.'<br />';
-            }
-            $output .= '<a href="'.$url.'">'.&mt('Link to PDF (for mobile devices)').'</a>';
+            $linktext = &mt('Link to PDF (for mobile devices)');
+            $output .= &create_link($url,$anchor,$title,$linktext);
         } else {
-            $output .= '<div style="overflow:scroll; -webkit-overflow-scrolling:touch;">'."\n".
-                       '<iframe src="'.$url.$anchor.'" height="100%" width="100%" frameborder="0">'."\n".
-                       "$lt{'noif'} $noiframe\n".
-                       "</iframe>\n".
-                       "</div>\n";
+            if ($uselink) {
+                $linktext = &mt('Link to resource');
+                $output .= &create_link($url,$anchor,$title,$linktext);
+            } else {
+                my $dest = &HTML::Entities::encode($url.$anchor,'&<>"');
+                $output .= '<div style="overflow:scroll; -webkit-overflow-scrolling:touch;">'."\n".
+                           '<iframe src="'.$dest.'" height="100%" width="100%" frameborder="0">'."\n".
+                           "$lt{'noif'} $noiframe\n".
+                           "</iframe>\n".
+                           "</div>\n";
+            }
         }
         $output .= $endpage;
         return $output;
+    } elsif ($uselink) {
+        $linktext = &mt('Link to resource');
+        return $startpage.&create_link($url,$anchor,$title,$linktext).$endpage;
     } else {
         my $offset = 5;
         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
@@ -150,6 +164,26 @@
     }
 }
 
+sub create_link {
+    my ($url,$anchor,$title,$linktext) = @_;
+    my $shownlink;
+    if ($title eq '') {
+        $title = $env{'form.title'};
+        if ($title eq '') {
+            unless ($env{'request.enc'}) {
+                ($title) = ($url =~ m{/([^/]+)$});
+                $title =~ s/(\?[^\?]+)$//;
+            }
+        }
+    }
+    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;
+}
+
 sub handler {
     my $r=shift;
     &Apache::loncommon::content_type($r,'text/html');
@@ -235,7 +269,7 @@
         # encrypt url if not external
         &Apache::lonenc::check_encrypt(\$url) if $url !~ /^https?\:/ ;
 
-        $r->print( wrapper($url,$brcrum,$absolute,$is_ext,$is_pdf) );
+        $r->print( wrapper($r,$url,$brcrum,$absolute,$is_ext,$is_pdf) );
 
     } # not just the menu
     
@@ -262,10 +296,14 @@
 
 =over
 
-=item wrapper($url,$brcrum,$absolute,$is_ext,$is_pdf,$title))
+=item wrapper($r,$url,$brcrum,$absolute,$is_ext,$is_pdf,$title))
 
 =over
 
+=item $r
+
+request object
+
 =item $url
 
 url to display by including in an iframe within a




More information about the LON-CAPA-cvs mailing list