Annotation of rat/lonwrapper.pm, revision 1.49.2.5
1.1 www 1: # The LearningOnline Network with CAPA
2: # Wrapper for external and binary files as standalone resources
3: #
1.49.2.5! raeburn 4: # $Id: lonwrapper.pm,v 1.49.2.4 2017/03/14 04:12:10 raeburn Exp $
1.4 www 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: #
1.1 www 28:
1.29 jms 29:
1.1 www 30: package Apache::lonwrapper;
31:
32: use strict;
33: use Apache::Constants qw(:common);
1.38 droeschl 34: use Apache::lonenc();
1.18 albertel 35: use Apache::lonnet;
1.42 raeburn 36: use Apache::lonlocal;
37: use Apache::loncommon();
38: use Apache::lonhtmlcommon();
39: use Apache::lonextresedit();
1.1 www 40:
41: # ================================================================ Main Handler
1.21 albertel 42: sub wrapper {
1.49 raeburn 43: my ($url,$brcrum,$absolute,$is_ext,$is_pdf,$title) = @_;
1.23 albertel 44:
1.42 raeburn 45: my $forcereg;
46: unless ($env{'form.folderpath'}) {
47: $forcereg = 1;
48: }
49:
1.46 raeburn 50: my %lt = &Apache::lonlocal::texthash(
51: 'noif' => 'No iframe support.',
52: 'show' => 'Show content in pop-up window',
53: );
54:
1.49.2.1 raeburn 55: my $anchor;
1.49.2.2 raeburn 56: if ($is_ext) {
57: if ($env{'form.symb'}) {
58: (undef,undef,my $res) = &Apache::lonnet::decode_symb($env{'form.symb'});
1.49.2.3 raeburn 59: if ($res =~ /(#[^#]+)$/) {
1.49.2.2 raeburn 60: $anchor = $1;
61: }
62: } elsif ($env{'form.anchor'} ne '') {
63: $anchor = '#'.$env{'form.anchor'};
1.49.2.1 raeburn 64: }
65: }
66:
67: my $noiframe = &Apache::loncommon::modal_link($url.$anchor,$lt{'show'},500,400);
1.42 raeburn 68: my $args = {'bgcolor' => '#FFFFFF'};
69: if ($forcereg) {
70: $args->{'force_register'} = $forcereg;
71: }
72: if (ref($brcrum) eq 'ARRAY') {
1.45 raeburn 73: $args->{'bread_crumbs'} = $brcrum;
1.42 raeburn 74: }
1.44 raeburn 75: if ($absolute) {
1.49.2.4 raeburn 76: $args->{'use_absolute'} = $absolute;
77: }
78: if ($env{'form.only_body'}) {
79: $args->{'only_body'} = $env{'form.only_body'};
1.44 raeburn 80: }
1.42 raeburn 81:
1.46 raeburn 82: my $startpage = &Apache::loncommon::start_page('Menu',undef,$args);
83: my $endpage = &Apache::loncommon::end_page();
1.38 droeschl 84:
1.46 raeburn 85: if ($env{'browser.mobile'}) {
1.47 raeburn 86: my $output = $startpage;
87: if ($is_pdf) {
88: if ($title eq '') {
1.49 raeburn 89: $title = $env{'form.title'};
90: if ($title eq '') {
91: unless ($env{'request.enc'}) {
92: ($title) = ($url =~ m{/([^/]+)$});
93: $title =~ s/(\?[^\?]+)$//;
94: }
1.47 raeburn 95: }
96: }
97: unless ($title eq '') {
98: $output .= $title.'<br />';
99: }
100: $output .= '<a href="'.$url.'">'.&mt('Link to PDF (for mobile devices)').'</a>';
101: } else {
102: $output .= '<div style="overflow:scroll; -webkit-overflow-scrolling:touch;">'."\n".
1.49.2.1 raeburn 103: '<iframe src="'.$url.$anchor.'" height="100%" width="100%" frameborder="0">'."\n".
1.47 raeburn 104: "$lt{'noif'} $noiframe\n".
105: "</iframe>\n".
106: "</div>\n";
107: }
108: $output .= $endpage;
109: return $output;
1.46 raeburn 110: } else {
1.49.2.3 raeburn 111: my $offset = 5;
112: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
113: if ($env{'form.inhibitmenu'} eq 'yes') {
114: $offset = 0;
115: }
1.46 raeburn 116: my $script = &Apache::lonhtmlcommon::scripttag(<<SCRIPT);
117: \$(document).ready( function() {
118: \$(window).unbind('resize').resize(function(){
1.49.2.3 raeburn 119: var header = null;
120: var offset = $offset;
1.46 raeburn 121: var height = 0;
122: var hdrtop = 0;
123: if (\$('div.LC_head_subbox:first').length) {
124: header = \$('div.LC_head_subbox:first');
125: offset = 9;
126: } else {
127: if (\$('#LC_breadcrumbs').length) {
128: header = \$('#LC_breadcrumbs');
129: }
130: }
1.49.2.3 raeburn 131: if (header != null && header.length) {
1.46 raeburn 132: height = header.height();
133: hdrtop = header.position().top;
1.42 raeburn 134: }
1.46 raeburn 135: var pos = height + hdrtop + offset;
136: \$('.LC_iframecontainer').css('top', pos);
137: });
1.38 droeschl 138: });
1.46 raeburn 139: window.onload = function(){ \$(window).trigger('resize') };
1.39 droeschl 140: SCRIPT
1.46 raeburn 141: # javascript will position the iframe if window was resized (or zoomed)
142: return <<ENDFRAME;
143: $startpage
144: $script
145: <div class="LC_iframecontainer">
1.49.2.1 raeburn 146: <iframe src="$url$anchor">$lt{'noif'} $noiframe</iframe>
1.46 raeburn 147: </div>
148: $endpage
1.38 droeschl 149: ENDFRAME
1.46 raeburn 150: }
1.21 albertel 151: }
152:
153: sub handler {
154: my $r=shift;
155: &Apache::loncommon::content_type($r,'text/html');
156: $r->send_http_header;
157:
158: return OK if $r->header_only;
159:
1.38 droeschl 160: my $url = $r->uri;
1.49.2.5! raeburn 161: my ($is_ext,$brcrum,$absolute,$is_pdf,$cdom,$cnum,$hostname);
1.38 droeschl 162:
163: for ($url){
164: s|^/adm/wrapper||;
165: $is_ext = $_ =~ s|^/ext/|http://|;
166: s|http://https://|https://|;
167: s|:|:|g;
1.21 albertel 168: }
169:
1.47 raeburn 170: if ($url =~ /\.pdf$/i) {
171: $is_pdf = 1;
172: }
173:
1.42 raeburn 174: if ($is_ext) {
175: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.49.2.2 raeburn 176: ['forceedit','register','folderpath','symb','idx','title','anchor']);
1.42 raeburn 177: if (($env{'form.forceedit'}) &&
178: (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
179: (($env{'form.folderpath'} =~ /^supplemental/) ||
180: ($env{'form.symb'} =~ /^uploaded/))) {
1.49.2.2 raeburn 181: if ($env{'form.symb'}) {
182: (undef,undef,my $res) = &Apache::lonnet::decode_symb($env{'form.symb'});
183: if ($res =~ /(#[^#]+)$/) {
184: $url .= $1;
185: }
186: } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
187: if ($env{'form.anchor'} ne '') {
188: $url .= '#'.$env{'form.anchor'};
189: }
190: }
1.49.2.5! raeburn 191: if (($url =~ /^http:/) && ($ENV{'SERVER_PORT'} == 443)) {
! 192: $hostname = $r->hostname();
! 193: }
! 194: my $type = 'ext';
1.42 raeburn 195: $r->print(
196: &Apache::lonextresedit::display_editor($url,$env{'form.folderpath'},
197: $env{'form.symb'},
1.49.2.5! raeburn 198: $env{'form.idx'},$type,$cdom,
! 199: $cnum,$hostname));
1.42 raeburn 200: return OK;
201: } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
202: my $crstype = &Apache::loncommon::course_type();
1.43 raeburn 203: my $title = $env{'form.title'};
204: if ($title eq '') {
205: $title = &mt('External Resource');
206: }
1.42 raeburn 207: $brcrum =
1.43 raeburn 208: &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
1.42 raeburn 209: }
210: }
211:
1.21 albertel 212: #
213: # Actual URL
214: #
1.41 www 215: if ($url=~/$LONCAPA::assess_re/) {
1.21 albertel 216: #
217: # This is uploaded homework
218: #
1.38 droeschl 219: $env{'request.state'}='uploaded';
220: &Apache::lonhomework::renderpage($r,$url);
1.21 albertel 221: } else {
222: #
223: # This is not homework
224: #
1.38 droeschl 225: if ($is_ext) {
1.49 raeburn 226: $absolute = $env{'request.use_absolute'};
1.38 droeschl 227: $ENV{'QUERY_STRING'} =~ s/(^|\&)symb=[^\&]*/$1/;
1.42 raeburn 228: $ENV{'QUERY_STRING'} =~ s/\&$//;
1.38 droeschl 229: }
230:
1.35 raeburn 231: unless ($ENV{'QUERY_STRING'} eq '') {
1.38 droeschl 232: $url.=(($url=~/\?/)?'&':'?').$ENV{'QUERY_STRING'};
1.35 raeburn 233: }
1.38 droeschl 234:
235: # encrypt url if not external
236: &Apache::lonenc::check_encrypt(\$url) if $url !~ /^https?\:/ ;
237:
1.47 raeburn 238: $r->print( wrapper($url,$brcrum,$absolute,$is_ext,$is_pdf) );
1.38 droeschl 239:
1.21 albertel 240: } # not just the menu
1.38 droeschl 241:
1.21 albertel 242: return OK;
1.13 www 243: } # handler
1.1 www 244:
245: 1;
246: __END__
247:
1.30 jms 248: =pod
1.1 www 249:
1.30 jms 250: =head1 NAME
251:
252: Apache::lonwrapper - External and binary file management.
253:
254: =head1 SYNOPSIS
255:
256: Wrapper for external and binary files as standalone resources. Edit handler for rat maps; TeX content handler.
257:
258: This is part of the LearningOnline Network with CAPA project
259: described at http://www.lon-capa.org.
260:
261: =head1 Subroutines
262:
263: =over
264:
1.49 raeburn 265: =item wrapper($url,$brcrum,$absolute,$is_ext,$is_pdf,$title))
1.30 jms 266:
1.45 raeburn 267: =over
268:
1.46 raeburn 269: =item $url
270:
1.45 raeburn 271: url to display by including in an iframe within a
272: LON-CAPA page which has a standard LON-CAPA inline menu.
273:
274: =item $brcrum
275:
276: breadcrumbs for unregistered urls
1.42 raeburn 277: (i.e., external resources in Supplemental Content).
1.45 raeburn 278:
1.46 raeburn 279: =item $absolute
1.45 raeburn 280:
281: contains protocol (http or https) followed by
282: the hostname, if menu items in the standard LON-CAPA
283: interface created by the call to loncommon::start_page()
284: within &wrapper() need to use absolute URLs rather than
285: relative URLs.
286:
287: That will be the case where an external resource has been
288: served from port 80, when the server customarily serves
289: requests using Apache/SSL (i.e., port 443). mod_rewrite
1.49 raeburn 290: is used to switch requests for external resources and
291: the syllabus: /public/<domain>/<courseid>/syllabus
292: (which might also point at an external resource)
1.45 raeburn 293: from https:// to http:// where the the URL of the remote site
294: specified in the resource itself is http://.
295:
296: This is done to avoid default mixed content blocking
297: in Firefox 23 and later, when serving from Apache/SSL.
298:
299: =item $is_ext
300:
301: true if URL is for an external resource.
302:
1.47 raeburn 303: =item $is_pdf
304:
305: true if URL is for a PDF (based on file extension).
306:
1.49 raeburn 307: =item $title
308:
309: optional. If wrapped item is a PDF, and $env{'browser.mobile'}
310: is true, a link to a PDF is shown. The "title" will be displayed
311: above the link, but if not provided as an arg, $env{'form.title'}
312: will be used, otherwise, the filename will be displayed (unless
313: hidden URL set for the resource).
314:
1.45 raeburn 315: =back
316:
1.38 droeschl 317: Returns markup for the entire page.
1.30 jms 318:
319: =item handler()
320:
321: =back
322:
323: =cut
1.1 www 324:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>