File:  [LON-CAPA] / rat / lonwrapper.pm
Revision 1.45: download - view: text, annotated - select for diffs
Tue Oct 15 10:17:19 2013 UTC (10 years, 6 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- wrapper() takes additional fourth argument -- $is_ext (true if item
  being wrapped is an external resource.

    1: # The LearningOnline Network with CAPA
    2: # Wrapper for external and binary files as standalone resources
    3: #
    4: # $Id: lonwrapper.pm,v 1.45 2013/10/15 10:17:19 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: 
   41: # ================================================================ Main Handler
   42: sub wrapper {
   43:     my ($url,$brcrum,$absolute,$is_ext) = @_;
   44: 
   45:     my $forcereg;
   46:     unless ($env{'form.folderpath'}) {
   47:         $forcereg = 1;
   48:     }
   49: 
   50:     my $args = {'bgcolor' => '#FFFFFF'};
   51:     if ($forcereg) {
   52:         $args->{'force_register'} = $forcereg;
   53:     }
   54:     if (ref($brcrum) eq 'ARRAY') {
   55:         $args->{'bread_crumbs'} = $brcrum;
   56:     }
   57:     if ($absolute) {
   58:         $args->{'use_absolute'} = $absolute; 
   59:     }
   60: 
   61:     my $startpage =  Apache::loncommon::start_page('Menu',undef,$args);
   62:     my $endpage =  Apache::loncommon::end_page();
   63: 
   64:     my $script = Apache::lonhtmlcommon::scripttag(<<SCRIPT );
   65:     \$(document).ready( function() {
   66:         \$(window).unbind('resize').resize(function(){
   67:             var header;
   68:             var offset = 5;
   69:             var height = 0;
   70:             var hdrtop = 0;
   71:             if (\$('div.LC_head_subbox:first').length) {
   72:                 header = \$('div.LC_head_subbox:first');
   73:                 offset = 9;
   74:             } else {
   75:                 if (\$('#LC_breadcrumbs').length) {
   76:                     header = \$('#LC_breadcrumbs');
   77:                 }
   78:             }
   79:             if (header.length) {
   80:                 height = header.height();
   81:                 hdrtop = header.position().top;
   82:             }
   83:             var pos = height + hdrtop + offset;
   84:             \$('.LC_iframecontainer').css('top', pos);
   85:         });
   86:     });
   87:     window.onload = function(){  \$(window).trigger('resize') }; 
   88: SCRIPT
   89: 
   90:     # javascript will position the iframe if window was resized (or zoomed)
   91:     return <<ENDFRAME;
   92:     $startpage
   93:     $script
   94:     <div class="LC_iframecontainer">
   95:         <iframe src="$url">No iframe support!</iframe>
   96:     </div>
   97:     $endpage
   98: ENDFRAME
   99: }
  100: 
  101: sub handler {
  102:     my $r=shift;
  103:     &Apache::loncommon::content_type($r,'text/html');
  104:     $r->send_http_header;
  105: 
  106:     return OK if $r->header_only;
  107: 
  108:     my $url = $r->uri;
  109:     my ($is_ext,$brcrum,$absolute);
  110: 
  111:     for ($url){
  112:         s|^/adm/wrapper||;
  113:         $is_ext = $_ =~ s|^/ext/|http://|;         
  114:         s|http://https://|https://|;
  115:         s|&colon;|:|g;              
  116:     }
  117: 
  118:     if ($is_ext) {
  119:         my $hostname = $r->hostname();
  120:         my $lonhost = &Apache::lonnet::host_from_dns($hostname);
  121:         if ($lonhost) {
  122:             my $actual = &Apache::lonnet::absolute_url($hostname);
  123:             my $expected = $Apache::lonnet::protocol{$lonhost}.'://'.$hostname; 
  124:             unless ($actual eq $expected) {
  125:                 $absolute = $expected;
  126:             }
  127:         }
  128:         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  129:             ['forceedit','register','folderpath','symb','idx','title']);
  130:         if (($env{'form.forceedit'}) &&
  131:             (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
  132:             (($env{'form.folderpath'} =~ /^supplemental/) ||
  133:              ($env{'form.symb'} =~ /^uploaded/))) {
  134:             $r->print(
  135:                 &Apache::lonextresedit::display_editor($url,$env{'form.folderpath'},
  136:                                                        $env{'form.symb'},
  137:                                                        $env{'form.idx'}));
  138:             return OK;
  139:         } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
  140:             my $crstype = &Apache::loncommon::course_type();
  141:             my $title = $env{'form.title'};
  142:             if ($title eq '') {
  143:                 $title = &mt('External Resource');
  144:             }
  145:             $brcrum =
  146:                 &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
  147:         }
  148:     }
  149: 
  150: #
  151: # Actual URL
  152: #
  153:     if ($url=~/$LONCAPA::assess_re/) {
  154: #
  155: # This is uploaded homework
  156: #
  157:         $env{'request.state'}='uploaded';
  158:         &Apache::lonhomework::renderpage($r,$url);
  159:     } else {
  160: #
  161: # This is not homework
  162: #
  163:         if ($is_ext) {
  164:             $ENV{'QUERY_STRING'} =~ s/(^|\&)symb=[^\&]*/$1/;
  165:             $ENV{'QUERY_STRING'} =~ s/\&$//;
  166:         }
  167: 
  168:         unless ($ENV{'QUERY_STRING'} eq '') {
  169:             $url.=(($url=~/\?/)?'&':'?').$ENV{'QUERY_STRING'};
  170:         }
  171: 
  172:         # encrypt url if not external
  173:         &Apache::lonenc::check_encrypt(\$url) if $url !~ /^https?\:/ ;
  174: 
  175:         $r->print( wrapper($url,$brcrum,$absolute,$is_ext) );
  176: 
  177:     } # not just the menu
  178:     
  179:     return OK;
  180: } # handler
  181: 
  182: 1;
  183: __END__
  184: 
  185: =pod
  186: 
  187: =head1 NAME
  188: 
  189: Apache::lonwrapper - External and binary file management.
  190: 
  191: =head1 SYNOPSIS
  192: 
  193: Wrapper for external and binary files as standalone resources. Edit handler for rat maps; TeX content handler.
  194: 
  195: This is part of the LearningOnline Network with CAPA project
  196: described at http://www.lon-capa.org.
  197: 
  198: =head1 Subroutines
  199: 
  200: =over
  201: 
  202: =item wrapper($url,$brcrum,$absolute,$is_ext)
  203: 
  204: =over
  205: 
  206: =item $url 
  207:  
  208: url to display by including in an iframe within a
  209: LON-CAPA page which has a standard LON-CAPA inline menu.
  210: 
  211: =item $brcrum
  212: 
  213: breadcrumbs for unregistered urls
  214: (i.e., external resources in Supplemental Content).
  215: 
  216: =item $absolute 
  217: 
  218: contains protocol (http or https) followed by
  219: the hostname, if menu items in the standard LON-CAPA
  220: interface created by the call to loncommon::start_page()
  221: within &wrapper() need to use absolute URLs rather than
  222: relative URLs.
  223: 
  224: That will be the case where an external resource has been 
  225: served from port 80, when the server customarily serves
  226: requests using Apache/SSL (i.e., port 443). mod_rewrite 
  227: is used to switch requests for external resources  
  228: from https:// to http:// where the the URL of the remote site 
  229: specified in the resource itself is http://.
  230: 
  231: This is done to avoid default mixed content blocking
  232: in Firefox 23 and later, when serving from Apache/SSL.
  233: 
  234: =item $is_ext
  235: 
  236: true if URL is for an external resource.
  237: 
  238: =back
  239: 
  240: Returns markup for the entire page.
  241: 
  242: =item handler()
  243: 
  244: =back
  245: 
  246: =cut
  247: 
  248: 
  249: 
  250: 
  251: 
  252: 
  253: 

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