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