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