--- rat/lonwrapper.pm 2017/04/25 22:19:03 1.60 +++ rat/lonwrapper.pm 2017/05/10 19:25:28 1.64 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Wrapper for external and binary files as standalone resources # -# $Id: lonwrapper.pm,v 1.60 2017/04/25 22:19:03 raeburn Exp $ +# $Id: lonwrapper.pm,v 1.64 2017/05/10 19:25:28 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -38,11 +38,13 @@ use Apache::loncommon(); use Apache::lonhtmlcommon(); use Apache::lonextresedit(); use Apache::lonexttool(); -use LONCAPA qw(:DEFAULT :match);; +use LONCAPA qw(:DEFAULT :match); +use HTML::Entities(); # ================================================================ Main Handler sub wrapper { - my ($url,$brcrum,$absolute,$is_ext,$is_pdf,$exttool,$linktext,$explanation,$title) = @_; + my ($url,$brcrum,$absolute,$is_ext,$is_pdf,$exttool,$linktext,$explanation, + $title,$width,$height) = @_; my $forcereg; unless ($env{'form.folderpath'}) { @@ -83,7 +85,7 @@ sub wrapper { my $startpage = &Apache::loncommon::start_page('Menu',undef,$args); my $endpage = &Apache::loncommon::end_page(); - if (($env{'browser.mobile'}) || ($exttool eq 'window')) { + if (($env{'browser.mobile'}) || ($exttool eq 'window') || ($exttool eq 'tab')) { my $output = $startpage; if ($is_pdf) { if ($title eq '') { @@ -99,20 +101,51 @@ sub wrapper { $output .= $title.'
'; } $output .= ''.&mt('Link to PDF (for mobile devices)').''; - } elsif ($exttool eq 'window') { + } elsif (($exttool eq 'window') || ($exttool eq 'tab')) { if ($linktext eq '') { $linktext = &mt('Launch External Tool'); } - $output .= '
'. - ''. - $linktext.''. - '
'; + $url = &HTML::Entities::encode($url,'"<>&'); + if ($exttool eq 'tab') { + $output .= '
'. + ''. + $linktext.''. + '
'; + } else { + $output .= <<"ENDLINK"; + +
+ +$linktext +
+ENDLINK + } if ($explanation ne '') { $output .= '
'.$explanation.'
'; } } else { + my $dest = &HTML::Entities::encode($url.$anchor,'&<>"'); $output .= '
'."\n". - '\n". "
\n"; @@ -151,11 +184,12 @@ sub wrapper { window.onload = function(){ \$(window).trigger('resize') }; SCRIPT # javascript will position the iframe if window was resized (or zoomed) + my $dest = &HTML::Entities::encode($url.$anchor,'&<>"'); return < - + $endpage ENDFRAME @@ -171,7 +205,7 @@ sub handler { my $url = $r->uri; my ($is_ext,$brcrum,$absolute,$is_pdf,$exttool,$cdom,$cnum,$hostname, - $linktext,$explanation); + $linktext,$explanation,$width,$height); for ($url){ s|^/adm/wrapper||; @@ -183,17 +217,32 @@ sub handler { if ($url =~ /\.pdf$/i) { $is_pdf = 1; - } elsif ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/exttools?$}) { + } elsif ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) { $cdom = $1; $cnum = $2; my $marker = $3; $exttool = 'iframe'; - my %toolhash = &Apache::lonnet::get('exttool_'.$marker,['target','linktext','explanation'], + my $exttoolremote; + my %toolhash = &Apache::lonnet::get('exttool_'.$marker,['target','linktext','explanation','id','width','height'], $cdom,$cnum); + if ($toolhash{'id'}) { + my %ltitools = &Apache::lonnet::get_domain_ltitools($cdom); + if (ref($ltitools{$toolhash{'id'}}) eq 'HASH') { + $exttoolremote = $ltitools{$toolhash{'id'}}{'url'}; + } + } if ($toolhash{'target'} eq 'window') { - $exttool = 'window'; + $exttool = 'window'; + $width = $toolhash{'width'}; + $height = $toolhash{'height'}; + } elsif ($toolhash{'target'} eq 'tab') { + $exttool = 'tab'; + } + if (($exttool eq 'window') || ($exttool eq 'tab')) { $linktext = $toolhash{'linktext'}; $explanation = $toolhash{'explanation'}; + } elsif (($exttoolremote =~ /^http:/) && ($ENV{'SERVER_PORT'} == 443)) { + $exttool = 'tab'; } } if (($is_ext) || ($exttool)) { @@ -243,7 +292,7 @@ sub handler { # # Actual URL # - if ($url=~/$LONCAPA::assess_re/) { + if (($url=~/$LONCAPA::assess_re/) && (!$exttool)) { # # This is uploaded homework # @@ -268,7 +317,8 @@ sub handler { &Apache::lonenc::check_encrypt(\$url); } - $r->print( wrapper($url,$brcrum,$absolute,$is_ext,$is_pdf,$exttool,$linktext,$explanation) ); + $r->print( wrapper($url,$brcrum,$absolute,$is_ext,$is_pdf,$exttool, + $linktext,$explanation,undef,$width,$height) ); } # not just the menu @@ -295,7 +345,7 @@ described at http://www.lon-capa.org. =over -=item wrapper($url,$brcrum,$absolute,$is_ext,$is_pdf,$title)) +=item wrapper($url,$brcrum,$absolute,$is_ext,$is_pdf,$linktext,$explanation,$title,$width,$height) =over