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