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