File:  [LON-CAPA] / rat / lonwrapper.pm
Revision 1.49.2.11.2.5: download - view: text, annotated - select for diffs
Fri Oct 6 17:35:54 2023 UTC (7 months ago) by raeburn
Branches: version_2_11_4_msu
Diff to branchpoint 1.49.2.11: preferred, unified
- For 2.11.4 (modified)
  Include changes in 1.83

    1: # The LearningOnline Network with CAPA
    2: # Wrapper for external and binary files as standalone resources
    3: #
    4: # $Id: lonwrapper.pm,v 1.49.2.11.2.5 2023/10/06 17:35:54 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: 
   29: 
   30: package Apache::lonwrapper;
   31: 
   32: use strict;
   33: use Apache::Constants qw(:common);
   34: use Apache::lonenc();
   35: use Apache::lonnet;
   36: use Apache::lonlocal;
   37: use Apache::loncommon();
   38: use Apache::lonhtmlcommon();
   39: use Apache::lonextresedit();
   40: use Apache::lonexttool();
   41: use Apache::lonhomework();
   42: use Apache::lonnavmaps();
   43: use LONCAPA qw(:DEFAULT :match);
   44: use HTML::Entities();
   45: use Digest::MD5();
   46: 
   47: # ================================================================ Main Handler
   48: sub wrapper {
   49:     my ($r,$url,$brcrum,$absolute,$is_ext,$is_pdf,$exttool,$linktext,$explanation,
   50:         $title,$width,$height,$reuse,$is_supp) = @_;
   51: 
   52:     my $forcereg;
   53:     unless ($env{'form.folderpath'}) {
   54:         $forcereg = 1;
   55:     }
   56:     my %lt = &Apache::lonlocal::texthash(
   57:                                           'noif' => 'No iframe support.',
   58:                                           'show' => 'Show content in pop-up window',
   59:                                         );
   60: 
   61:     (undef,undef,undef,undef,undef,undef,my $clientmobile) =
   62:         &Apache::loncommon::decode_user_agent($r);
   63: 
   64:     my ($anchor,$uselink);
   65:     if ($is_ext) {
   66:         if ($env{'form.symb'}) {
   67:             (undef,undef,my $res) = &Apache::lonnet::decode_symb($env{'form.symb'});
   68:             if ($res =~ /(#[^#]+)$/) {
   69:                 $anchor = $1;
   70:             }
   71:         } elsif ($env{'form.anchor'} ne '') {
   72:             $anchor = '#'.$env{'form.anchor'};
   73:         }
   74:         if (($is_ext eq 'tab') || ($is_ext eq 'window')) {
   75:             $uselink = 1;
   76:         }
   77:         unless (($is_pdf && $clientmobile) || $uselink) {
   78:             my $hostname = $r->hostname();
   79:             my $lonhost = $r->dir_config('lonHostID');
   80:             my $ip = &Apache::lonnet::get_host_ip($lonhost);
   81:             $uselink = &Apache::loncommon::is_nonframeable($url,$absolute,$hostname,$ip);
   82:         }
   83:     }
   84: 
   85:     my $noiframe = &Apache::loncommon::modal_link($url.$anchor,$lt{'show'},500,400);
   86:     my $args = {'bgcolor' => '#FFFFFF'};
   87:     if ($forcereg) {
   88:         $args->{'force_register'} = $forcereg;
   89:     }
   90:     if (ref($brcrum) eq 'ARRAY') {
   91:         $args->{'bread_crumbs'} = $brcrum;
   92:     }
   93:     if ($absolute) {
   94:         $args->{'use_absolute'} = $absolute;
   95:     }
   96:     if ($env{'form.only_body'}) {
   97:         $args->{'only_body'} = $env{'form.only_body'};
   98:     } elsif (($is_supp) && ($env{'form.folderpath'} ne '')) {
   99:         $args->{'bread_crumbs_nomenu'} = 1;
  100:     }
  101: 
  102:     my ($countdown,$donemsg,$headjs);
  103:     if (($exttool) && (&Apache::lonnet::EXT('resource.0.gradable') =~ /^yes$/i)) {
  104:         $Apache::lonhomework::browse = &Apache::lonnet::allowed('bre',$url);
  105:         if ($env{'form.markaccess'}) {
  106:             my $symb=&Apache::lonnet::symbread($url);
  107:             my @interval=&Apache::lonnet::EXT('resource.0.interval',$symb);
  108:             my ($timelimit) = split(/_/,$interval[0]);
  109:             my $setres = &Apache::lonnet::set_first_access($interval[1],$timelimit);
  110:             if ($setres eq 'ok') {
  111:                 delete($env{'form.markaccess'});
  112:             }
  113:         } elsif ($env{'form.LC_interval_done'} eq 'true') {
  114:             my $symb=&Apache::lonnet::symbread($url);
  115:             if ($symb) {
  116:                 (my $donebuttonresult,$donemsg) = &Apache::lonhomework::zero_timer($symb);
  117:                 undef($env{'form.LC_interval_done'});
  118:                 undef($env{'form.LC_interval_done_proctorpass'});
  119:             }
  120:         }
  121:         my ($status,$result,$resource_due) =
  122:             &Apache::lonexttool::gradabletool_access_check();
  123:         undef($Apache::lonhomework::browse);
  124:         if ($status eq 'CAN_ANSWER') {
  125:             if ($resource_due) {
  126:                 my $time_left = $resource_due - time();
  127:                 if ($resource_due && ($time_left > 0)) {
  128:                     $countdown ='
  129: <script type="text/javascript">
  130: // <![CDATA['."\n".
  131:                              &Apache::lonhtmlcommon::countdown().'
  132: // ]]>
  133: </script>'."\n".
  134:                     &Apache::lonhtmlcommon::set_due_date($resource_due);
  135:                 }
  136:             }
  137:         } else {
  138:             if ($status eq 'SHOW_ANSWER') {
  139:                 $result = &Apache::lonexttool::display_score().
  140:                           &Apache::lonfeedback::list_discussion('tool','OPEN');
  141:             }
  142:             return &Apache::loncommon::start_page('Menu',undef,$args).
  143:                    $result.
  144:                    &Apache::loncommon::end_page();
  145:         }
  146:     }
  147: 
  148: #
  149: # Where iframe is in use, if window.onload() executes before the custom resize function
  150: # has been defined (jQuery), two global javascript vars (LCnotready and LCresizedef)
  151: # are used to ensure document.ready() triggers a call to resize, so the iframe contents
  152: # do not obscure the Functions menu.
  153: #
  154: 
  155:     unless ($clientmobile || ($exttool eq 'window') || ($exttool eq 'tab') || $uselink) {
  156:         $headjs = '
  157: <script type="text/javascript">
  158: // <![CDATA[
  159: var LCnotready = 0;
  160: var LCresizedef = 0;
  161: // ]]>
  162: </script>'."\n";
  163:     }
  164: 
  165:     my $startpage = &Apache::loncommon::start_page('Menu',$headjs,$args).$countdown.$donemsg;
  166:     my $endpage = &Apache::loncommon::end_page();
  167: 
  168:     if (($uselink) && ($title eq '')) {
  169:         if ($env{'form.symb'}) {
  170:             $title=&Apache::lonnet::gettitle($env{'form.symb'});
  171:         } elsif (!$is_supp) {
  172:             my $symb=&Apache::lonnet::symbread($r->uri);
  173:             if ($symb) {
  174:                 $title=&Apache::lonnet::gettitle($symb);
  175:             }
  176:         }
  177:     }
  178:     if ($clientmobile || ($exttool eq 'window') || ($exttool eq 'tab') ||
  179:         ($is_ext eq 'tab') || ($is_ext eq 'window')) {
  180:         my $output = $startpage;
  181:         if ($is_pdf) {
  182:             $linktext = &mt('Link to PDF (for mobile devices)');
  183:             $output .= &create_link($url,$anchor,$title,$linktext);
  184:         } elsif (($exttool eq 'window') || ($exttool eq 'tab') ||
  185:                  ($is_ext eq 'tab') || ($is_ext eq 'window')) {
  186:             my $preamble;
  187:             if ($linktext eq '') {
  188:                 if ($exttool) {
  189:                     $linktext = &mt('Launch External Tool');
  190:                 } else {
  191:                     $linktext = &mt('Link to External Resource');
  192:                 }
  193:             }
  194:             if ($exttool) {
  195:                 $url = &HTML::Entities::encode($url,'"<>&');
  196:             } else {
  197:                 $url = &HTML::Entities::encode($url.$anchor,'&<>"');
  198:             }
  199:             if (($exttool eq 'tab') || ($is_ext eq 'tab')) {
  200:                 my $target;
  201:                 if ($exttool) {
  202:                     $target = 'LCExternalToolTab';
  203:                 } else {
  204:                     if ($reuse) {
  205:                         $target = 'LCExternalResTab';
  206:                     } else {
  207:                         $target = '_blank';
  208:                     }
  209:                     if ($title ne '') {
  210:                         $preamble = '<span style="font-weight:bold;">'.$title.'</span><br />';
  211:                     }
  212:                 }
  213:                 $output .= '<div>'.$preamble.
  214:                            '<a href="'.$url.'" target="'.$target.'" style="padding:0;clear:both;margin:0;border:0">'.
  215:                            $linktext.'</a>'.
  216:                            '</div>';
  217:             } else {
  218:                 my ($target,$extlinkimg);
  219:                 if ($exttool) {
  220:                     $target = 'LCExternalToolPopUp';
  221:                 } else {
  222:                     $target = 'LCExternalResPopUp';
  223:                     if ($title ne '') {
  224:                         $preamble = '<span style="font-weight:bold;">'.$title.'</span><br />';
  225:                     }
  226:                     $extlinkimg = '<img src="'.&Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/externallink.gif').'" width="19" height="18" border="0" />';
  227:                     unless ($reuse) {
  228:                         my $resid;
  229:                         if ($env{'request.course.id'}) {
  230:                             unless (($is_supp) || ($env{'form.folderpath'} =~ /^supplemental/)) {
  231:                                 my $symb=&Apache::lonnet::symbread($r->uri);
  232:                                 if ($symb) {
  233:                                     my $navmap = Apache::lonnavmaps::navmap->new();
  234:                                     if (ref($navmap)) {
  235:                                         my $res = $navmap->getBySymb($symb);
  236:                                         if (ref($res)) {
  237:                                             $resid = $res->id;
  238:                                             $resid =~ s/\./_/g;
  239:                                         }
  240:                                     }
  241:                                 }
  242:                             }
  243:                         }
  244:                         if ($resid eq '') {
  245:                             $resid = substr(Digest::MD5::md5_hex(Digest::MD5::md5_hex(time(). {}. rand(). $$)), 0, 8);
  246:                         }
  247:                         &js_escape(\$resid);
  248:                         $target .= $resid;
  249:                     }
  250:                 }
  251:                 $output .= <<"ENDLINK";
  252: <script type="text/javascript">
  253: // <![CDATA[
  254: var windowObjectReference = null;
  255: var PreviousUrl;
  256: 
  257: function openSinglePopup(strUrl) {
  258:     if (windowObjectReference == null || windowObjectReference.closed) {
  259:         windowObjectReference = window.open(strUrl, "$target",
  260:                                             "height=$height,width=$width,scrollbars=yes,resizable=yes,status=yes,menubar=no,location=no'");
  261:     } else if(PreviousUrl != strUrl) {
  262:         windowObjectReference = window.open(strUrl, "$target",
  263:                                             "height=$height,width=$width,scrollbars=yes,resizable=yes,status=yes,menubar=no,location=no'");
  264:         windowObjectReference.focus();
  265:     } else {
  266:         windowObjectReference.focus();
  267:     };
  268:     PreviousUrl = strUrl;
  269: }
  270: // ]]>
  271: </script>
  272: <div>$preamble
  273: <a href="$url" target="$target" onclick="openSinglePopup(this.href); return false;">
  274: $linktext$extlinkimg</a>
  275: </div>
  276: ENDLINK
  277:             }
  278:             if ($exttool) {
  279:                 if ($explanation ne '') {
  280:                     $output .= '<div>'.$explanation.'</div>';
  281:                 }
  282:                 if (&Apache::lonnet::EXT('resource.0.gradable')) {
  283:                     $output .= &Apache::lonfeedback::list_discussion('tool','OPEN');
  284:                 }
  285:             }
  286:         } else {
  287:             if ($uselink) {
  288:                 $linktext = &mt('Link to resource');
  289:                 $output .= &create_link($url,$anchor,$title,$linktext);
  290:             } else {
  291:                 my $dest = &HTML::Entities::encode($url.$anchor,'&<>"');
  292:                 $output .= '<div style="overflow:scroll; -webkit-overflow-scrolling:touch;">'."\n".
  293:                            '<iframe src="'.$dest.'" height="100%" width="100%" frameborder="0">'."\n".
  294:                            "$lt{'noif'} $noiframe\n".
  295:                            "</iframe>\n".
  296:                            "</div>\n";
  297:             }
  298:         }
  299:         $output .= $endpage;
  300:         return $output;
  301:     } elsif ($uselink) {
  302:         $linktext = &mt('Link to resource');
  303:         return $startpage.&create_link($url,$anchor,$title,$linktext).$endpage;
  304:     } else {
  305:         my $offset = 5;
  306:         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
  307:         if (($env{'form.inhibitmenu'} eq 'yes') || ($env{'form.only_body'})) {
  308:             $offset = 0;
  309:         }
  310:         my $script = &Apache::lonhtmlcommon::scripttag(<<SCRIPT);
  311:         \$(document).ready( function() {
  312:             \$(window).unbind('resize').resize(function(){
  313:                 var header = null;
  314:                 var offset = $offset;
  315:                 var height = 0;
  316:                 var hdrtop = 0;
  317:                 if (\$('div.LC_head_subbox:first').length) {
  318:                     header = \$('div.LC_head_subbox:first');
  319:                     offset = 9;
  320:                 } else {
  321:                     if (\$('#LC_breadcrumbs').length) {
  322:                         header = \$('#LC_breadcrumbs');
  323:                     }
  324:                 }
  325:                 if (header != null && header.length) {
  326:                     height = header.height();
  327:                     hdrtop = header.position().top;
  328:                 }
  329:                 var pos = height + hdrtop + offset;
  330:                 \$('.LC_iframecontainer').css('top', pos);
  331:             });
  332:             LCresizedef = 1;
  333:             if (LCnotready == 1) {
  334:                 LCnotready = 0;
  335:                 \$(window).trigger('resize');
  336:             }
  337:         });
  338:         window.onload = function(){
  339:             if (LCresizedef) {
  340:                 LCnotready = 0;
  341:                 \$(window).trigger('resize');
  342:             } else {
  343:                 LCnotready = 1;
  344:             }
  345:         };
  346: SCRIPT
  347:         # javascript will position the iframe if window was resized (or zoomed)
  348:         my $dest = &HTML::Entities::encode($url.$anchor,'&<>"');
  349:         return <<ENDFRAME;
  350:         $startpage
  351:         $script
  352:         <div class="LC_iframecontainer">
  353:             <iframe src="$dest">$lt{'noif'} $noiframe</iframe>
  354:         </div>
  355:         $endpage
  356: ENDFRAME
  357:     }
  358: }
  359: 
  360: sub create_link {
  361:     my ($url,$anchor,$title,$linktext) = @_;
  362:     my $shownlink;
  363:     if ($title eq '') {
  364:         $title = $env{'form.title'};
  365:         if ($title eq '') {
  366:             unless ($env{'request.enc'}) {
  367:                 ($title) = ($url =~ m{/([^/]+)$});
  368:                 $title =~ s/(\?[^\?]+)$//;
  369:             }
  370:         }
  371:     }
  372:     unless ($title eq '') {
  373:         $shownlink = '<span style="font-weight:bold;">'.$title.'</span><br />';
  374:     }
  375:     my $dest = &HTML::Entities::encode($url.$anchor,'&<>"');
  376:     $shownlink .= '<a href="'.$dest.'">'.$linktext.'</a>';
  377:     return $shownlink;
  378: }
  379: 
  380: sub handler {
  381:     my $r=shift;
  382:     &Apache::loncommon::content_type($r,'text/html');
  383:     $r->send_http_header;
  384: 
  385:     return OK if $r->header_only;
  386: 
  387:     my $url = $r->uri;
  388:     my ($is_ext,$brcrum,$absolute,$is_pdf,$exttool,$cdom,$cnum,$hostname,
  389:         $linktext,$explanation,$width,$height,$reuse,$is_supp);
  390: 
  391:     for ($url){
  392:         s|^/adm/wrapper||;
  393:         $is_ext = $_ =~ s|^/ext/|http://|;
  394:         s|http://https://|https://| if ($is_ext);
  395:         s|&colon;|:|g;
  396:     }
  397: 
  398:     if ($url =~ /\.pdf$/i) {
  399:         $is_pdf = 1;
  400:     } elsif (($is_ext) && ($env{'request.course.id'})) {
  401:         if ($env{'course.'.$env{'request.course.id'}.'.extresource'}) {
  402:             (my $selected,$reuse,$width,$height) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.extresource'});
  403:             if ($selected eq 'tab') {
  404:                 $is_ext = 'tab';
  405:                 $width = '';
  406:                 $height = '';
  407:             } elsif ($selected eq 'window') {
  408:                 $is_ext = 'window';
  409:                 unless ($width =~ /^\d+$/) {
  410:                     $width = '';
  411:                 }
  412:                 unless ($height =~ /^\d+$/) {
  413:                     $height = '';
  414:                 }
  415:             } else {
  416:                 $width = '';
  417:                 $height = '';
  418:                 $reuse = '';
  419:             }
  420:         }
  421:     } elsif ($url =~ m{^/adm/($match_domain)/($match_courseid)/(\d+)/ext\.tool$}) {
  422:         $cdom = $1;
  423:         $cnum = $2;
  424:         my $marker = $3;
  425:         $exttool = 'iframe';
  426:         my $exttoolremote;
  427:         my %toolhash = &Apache::lonnet::get('exttool_'.$marker,['target','linktext','explanation','id','width','height'],
  428:                                             $cdom,$cnum);
  429:         if ($toolhash{'id'}) {
  430:             my ($idx,%ltitools);
  431:             if ($toolhash{'id'} =~ /^c(\d+)$/) {
  432:                 $idx = $1;
  433:                 %ltitools = &Apache::lonnet::get_course_lti($cnum,$cdom,'consumer');
  434:             } else {
  435:                 $idx = $toolhash{'id'};
  436:                 %ltitools = &Apache::lonnet::get_domain_lti($cdom,'consumer');
  437:             }
  438:             if (ref($ltitools{$idx}) eq 'HASH') {
  439:                 $exttoolremote = $ltitools{$idx}{'url'};
  440:             }
  441:         }
  442:         if ($toolhash{'target'} eq 'window') {
  443:             $exttool = 'window';
  444:             $width = $toolhash{'width'};
  445:             $height = $toolhash{'height'};
  446:         } elsif ($toolhash{'target'} eq 'tab') {
  447:             $exttool = 'tab';
  448:         }
  449:         if (($exttool eq 'window') || ($exttool eq 'tab')) {
  450:             $linktext = $toolhash{'linktext'};
  451:             $explanation = $toolhash{'explanation'};
  452:         } elsif (($exttoolremote =~ /^http:/) && ($ENV{'SERVER_PORT'} == 443)) {
  453:             $exttool = 'tab';
  454:         }
  455:     }
  456:     if (($is_ext) || ($exttool)) {
  457:         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  458:             ['forceedit','register','folderpath','symb','idx','title','anchor','only_body']);
  459:         if (($env{'form.forceedit'}) &&
  460:             (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
  461:             (($env{'form.folderpath'} =~ /^supplemental/) ||
  462:              ($env{'form.symb'} =~ /^uploaded/))) {
  463:             if ($env{'form.symb'}) {
  464:                 (undef,undef,my $res) = &Apache::lonnet::decode_symb($env{'form.symb'});
  465:                 if ($res =~ /(#[^#]+)$/) {
  466:                     $url .= $1;
  467:                 }
  468:             } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
  469:                 if ($env{'form.anchor'} ne '') {
  470:                     $url .= '#'.$env{'form.anchor'};
  471:                 }
  472:                 $is_supp = 1;
  473:             }
  474:             my $type = 'ext';
  475:             if ($exttool) {
  476:                 $type = 'tool';
  477:             } elsif (($url =~ /^http:/) && ($ENV{'SERVER_PORT'} == 443)) {
  478:                 $hostname = $r->hostname();
  479:             }
  480:             $r->print(
  481:                 &Apache::lonextresedit::display_editor($url,$env{'form.folderpath'},
  482:                                                        $env{'form.symb'},
  483:                                                        $env{'form.idx'},$type,$cdom,
  484:                                                        $cnum,$hostname));
  485:             return OK;
  486:         } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
  487:             my $crstype = &Apache::loncommon::course_type();
  488:             my $title = $env{'form.title'};
  489:             if ($title eq '') {
  490:                 if ($is_ext) {
  491:                     $title = &mt('External Resource');
  492:                 } else {
  493:                     $title = &mt('External Tool');
  494:                 }
  495:             }
  496:             $title = &HTML::Entities::encode($title,'\'"<>&');
  497:             $is_supp = 1;
  498:             if ($env{'request.course.id'}) {
  499:                 $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  500:                 $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  501:                 &Apache::loncommon::validate_folderpath(1,'',$cnum,$cdom);
  502:             }
  503:             unless ($env{'form.only_body'}) { 
  504:                 $brcrum =
  505:                     &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
  506:             }
  507:         }
  508:     } elsif ($env{'request.course.id'}) {
  509:         my $courseurl = &Apache::lonnet::courseid_to_courseurl($env{'request.course.id'});
  510:         $courseurl =~ s{^/}{};
  511:         if ($url =~ m{^\Q/uploaded/$courseurl/supplemental/\E}) {
  512:             $is_supp = 1;
  513:             &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  514:                                                     ['folderpath','title','only_body']);
  515:             if ($env{'form.folderpath'}) {
  516:                 $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  517:                 $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  518:                 &Apache::loncommon::validate_folderpath(1,'',$cnum,$cdom);
  519:             }
  520:             my $title = $env{'form.title'};
  521:             $title = &HTML::Entities::encode($title,'\'"<>&');
  522:             my $crstype = &Apache::loncommon::course_type();
  523:             unless ($env{'form.only_body'}) {
  524:                 $brcrum =
  525:                     &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
  526:             }
  527:         }
  528:     }
  529: 
  530: #
  531: # Actual URL
  532: #
  533:     if (($url=~/$LONCAPA::assess_re/) && (!$exttool)) {
  534: #
  535: # This is uploaded homework
  536: #
  537:         $env{'request.state'}='uploaded';
  538:         &Apache::lonhomework::renderpage($r,$url);
  539:     } else {
  540: #
  541: # This is not homework
  542: #
  543:         if (($is_ext) || ($exttool)) {
  544:             $absolute = $env{'request.use_absolute'};
  545:             $ENV{'QUERY_STRING'} =~ s/(^|\&)symb=[^\&]*/$1/;
  546:             $ENV{'QUERY_STRING'} =~ s/\&$//;
  547:         }
  548: 
  549:         unless ($ENV{'QUERY_STRING'} eq '') {
  550:             $url.=(($url=~/\?/)?'&':'?').$ENV{'QUERY_STRING'};
  551:         }
  552: 
  553:         # encrypt url if not external
  554:         unless ($is_ext) {
  555:             &Apache::lonenc::check_encrypt(\$url);
  556:         }
  557: 
  558:         $r->print( wrapper($r,$url,$brcrum,$absolute,$is_ext,$is_pdf,$exttool,
  559:                            $linktext,$explanation,undef,$width,$height,$reuse,
  560:                            $is_supp) );
  561: 
  562:     } # not just the menu
  563:     
  564:     return OK;
  565: } # handler
  566: 
  567: 1;
  568: __END__
  569: 
  570: =pod
  571: 
  572: =head1 NAME
  573: 
  574: Apache::lonwrapper - External and binary file management.
  575: 
  576: =head1 SYNOPSIS
  577: 
  578: Wrapper for external and binary files as standalone resources. Edit handler for rat maps; TeX content handler.
  579: 
  580: This is part of the LearningOnline Network with CAPA project
  581: described at http://www.lon-capa.org.
  582: 
  583: =head1 Subroutines
  584: 
  585: =over
  586: 
  587: =item wrapper($r,$url,$brcrum,$absolute,$is_ext,$is_pdf,$exttool,$linktext,$explanation,$title,$width,$height,$reuse,$is_supp)
  588: 
  589: =over
  590: 
  591: =item $r
  592: 
  593: request object
  594: 
  595: =item $url
  596: 
  597: url to display either by including in an iframe within a
  598: LON-CAPA page which has a standard LON-CAPA inline menu,
  599: or in some cases launched in a separate tab or window,
  600: launched via a link in a LON-CAPA page with standard inline
  601: menu.
  602: 
  603: =item $brcrum
  604: 
  605: breadcrumbs for unregistered urls
  606: (i.e., external resources in Supplemental Content).
  607: 
  608: =item $absolute
  609: 
  610: contains protocol (http or https) followed by
  611: the hostname, if menu items in the standard LON-CAPA
  612: interface created by the call to loncommon::start_page()
  613: within &wrapper() need to use absolute URLs rather than
  614: relative URLs.
  615: 
  616: That will be the case where an external resource has been 
  617: served from port 80, when the server customarily serves
  618: requests using Apache/SSL (i.e., port 443). mod_rewrite 
  619: is used to switch requests for external resources and
  620: the syllabus: /public/<domain>/<courseid>/syllabus
  621: (which might also point at an external resource)
  622: from https:// to http:// where the the URL of the remote site 
  623: specified in the resource itself is http://.
  624: 
  625: This is done to avoid default mixed content blocking
  626: in Firefox 23 and later, when serving from Apache/SSL.
  627: 
  628: =item $is_ext
  629: 
  630: true if URL is for an external resource. Default true value
  631: is 1 (display in iframe, unless $uselink is true).
  632: If external resource is to be displayed in a tab,
  633: value of $is_ext will be tab, if to be displayed in a pop-up window,
  634: value of $is_ext will be window.
  635: 
  636: =item $is_pdf
  637: 
  638: true if URL is for a PDF (based on file extension).
  639: 
  640: =item $exttool
  641: 
  642: If URL is for an External Tool, will contain the target type: iframe, window or tab.
  643: 
  644: =item $linktext
  645: 
  646: optional. If URL is for an External Tool, and target type is window or tab,
  647: then the link text may be an option set in the course for each tool instance,
  648: or may be a default defined in the domain for all instances of the tool.
  649: 
  650: =item $explanation
  651: 
  652: optional. If URL is for an External Tool, and target type is window or tab,
  653: then the explanation is an option set in the course for each tool instance,
  654: or may be a default defined in the domain for all instances of the tool.
  655: 
  656: =item $title
  657: 
  658: optional. If wrapped item is a PDF, and $clientmobile is true,
  659: a link to a PDF is shown. The "title" will be displayed
  660: above the link, but if not provided as an arg, $env{'form.title'}
  661: will be used, otherwise, the filename will be displayed (unless
  662: hidden URL set for the resource).
  663: 
  664: =item $width
  665: 
  666: optional. If URL is for an External Tool, and target type is window,
  667: then a default width may have been defined in the domain for all instances of
  668: the tool.  If so, that width will be used for the window opened (via a link)
  669: to launch the external tool. If the URL is for an External Resource, and
  670: $is_ext is window, then a default width (px) may have been defined in the current
  671: course for all external resource instances.
  672: 
  673: =item $height
  674: 
  675: optional. If URL is for an External Tool, and target type is window,
  676: then a default height may have been defined in the domain for all instances of
  677: the tool.  If so, that height will be used for the window opened (via a link)
  678: to launch the external tool.  If the URL is for an External Resource, and
  679: $is_ext is window, then a default height (px) may have been defined in the current
  680: course for all external resource instances.
  681: 
  682: =item $reuse
  683: 
  684: optional. If the URL is for an External Resource, and $is_ext is tab or window,
  685: then $reuse will be true if the same tab or window is to be reused for display
  686: of all external resource instances in a a course.
  687: 
  688: =back
  689: 
  690: Returns markup for the entire page.
  691: 
  692: =item handler()
  693: 
  694: Content handler for requests for: /adm/wrapper/...
  695: used for content to be displayed in an iframe, or launched in a separate tab
  696: or window via a link.  The target URL is extracted from the requested URL, by
  697: removing the /adm/wrapper prefix.
  698: 
  699: The target URL will typically be a PDF served from the current server, an
  700: external resource URL served from a different server, or an external tool
  701: (from an LTI Provider) launched from LON-CAPA (as LTI Consumer) and launched
  702: via a link.
  703: 
  704: If the request included forceedit in the query string, and the requester has
  705: rights to modify course content, then the editor will be displayed to allow
  706: changes to be made to the resource (e.g., change the URL of the external resource,
  707: or change the setting for the external tool instance).
  708: 
  709: If not in edit mode, then the wrapper() subroutine will be called to generate the
  710: standard LON-CAPA inline menu, and then either a link to launch a separate tab or
  711: window, or an iframe to display the content inline.
  712: 
  713: =back
  714: 
  715: =cut
  716: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>