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