File:  [LON-CAPA] / rat / lonwrapper.pm
Revision 1.46: download - view: text, annotated - select for diffs
Tue Oct 22 23:13:54 2013 UTC (10 years, 6 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_11_0_RC2, HEAD
- Prevent truncation of content in external resources by using
  "overflow:scroll; -webkit-overflow-scrolling:touch" style for div wrapped
  around iframe used to contain external URL, when mobile device (e.g.,
  iPad, iPhone etc.).

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

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