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