--- rat/lonwrapper.pm 2016/11/29 19:53:58 1.54 +++ rat/lonwrapper.pm 2017/11/30 14:41:30 1.65 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Wrapper for external and binary files as standalone resources # -# $Id: lonwrapper.pm,v 1.54 2016/11/29 19:53:58 damieng Exp $ +# $Id: lonwrapper.pm,v 1.65 2017/11/30 14:41:30 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,$title) = @_; + my ($url,$brcrum,$absolute,$is_ext,$is_pdf,$exttool,$linktext,$explanation, + $title,$width,$height) = @_; my $forcereg; unless ($env{'form.folderpath'}) { @@ -74,13 +76,16 @@ sub wrapper { $args->{'bread_crumbs'} = $brcrum; } if ($absolute) { - $args->{'use_absolute'} = $absolute; + $args->{'use_absolute'} = $absolute; + } + if ($env{'form.only_body'}) { + $args->{'only_body'} = $env{'form.only_body'}; } 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 '') { @@ -96,14 +101,51 @@ sub wrapper { $output .= $title.'
'; } $output .= ''.&mt('Link to PDF (for mobile devices)').''; - } elsif ($exttool eq 'window') { - $output .= '
'. - ''. - &mt('Launch External Tool').''. - '
'; + } elsif (($exttool eq 'window') || ($exttool eq 'tab')) { + if ($linktext eq '') { + $linktext = &mt('Launch External Tool'); + } + $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"; @@ -111,11 +153,16 @@ sub wrapper { $output .= $endpage; return $output; } else { + my $offset = 5; + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']); + if ($env{'form.inhibitmenu'} eq 'yes') { + $offset = 0; + } my $script = &Apache::lonhtmlcommon::scripttag(<"'); return < - + $endpage ENDFRAME @@ -156,7 +204,8 @@ sub handler { return OK if $r->header_only; my $url = $r->uri; - my ($is_ext,$brcrum,$absolute,$is_pdf,$exttool,$cdom,$cnum); + my ($is_ext,$brcrum,$absolute,$is_pdf,$exttool,$cdom,$cnum,$hostname, + $linktext,$explanation,$width,$height); for ($url){ s|^/adm/wrapper||; @@ -168,14 +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'],$cdom,$cnum); + 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_lti($cdom,'consumer'); + 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)) { @@ -196,16 +263,16 @@ sub handler { } } my $type = 'ext'; - my %ltitools; if ($exttool) { $type = 'tool'; - %ltitools = &Apache::lonnet::get_domain_ltitools($cdom); + } elsif (($url =~ /^http:/) && ($ENV{'SERVER_PORT'} == 443)) { + $hostname = $r->hostname(); } $r->print( &Apache::lonextresedit::display_editor($url,$env{'form.folderpath'}, $env{'form.symb'}, $env{'form.idx'},$type,$cdom, - $cnum,\%ltitools)); + $cnum,$hostname)); return OK; } elsif ($env{'form.folderpath'} =~ /^supplemental/) { my $crstype = &Apache::loncommon::course_type(); @@ -225,7 +292,7 @@ sub handler { # # Actual URL # - if ($url=~/$LONCAPA::assess_re/) { + if (($url=~/$LONCAPA::assess_re/) && (!$exttool)) { # # This is uploaded homework # @@ -246,11 +313,12 @@ sub handler { } # encrypt url if not external - unless ($is_ext || $exttool) { + unless ($is_ext) { &Apache::lonenc::check_encrypt(\$url); } - $r->print( wrapper($url,$brcrum,$absolute,$is_ext,$is_pdf,$exttool) ); + $r->print( wrapper($url,$brcrum,$absolute,$is_ext,$is_pdf,$exttool, + $linktext,$explanation,undef,$width,$height) ); } # not just the menu @@ -277,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