--- loncom/interface/londocs.pm 2017/01/24 15:52:58 1.619 +++ loncom/interface/londocs.pm 2017/05/07 13:57:58 1.625 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.619 2017/01/24 15:52:58 raeburn Exp $ +# $Id: londocs.pm,v 1.625 2017/05/07 13:57:58 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -654,11 +654,12 @@ sub group_import { } } if ($url) { - if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/exttool)s?\:?(.*)$}) { + if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/exttool)\:?(.*)$}) { $url = $1; my $marker = $2; my $info = $3; my ($toolid,%toolhash,%toolsettings); + my @extras = ('linktext','explanation','crslabel','crstitle'); my @toolinfo = split(/:/,$info); if ($residx) { %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum); @@ -668,28 +669,36 @@ sub group_import { } $toolid =~ s/\D//g; ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'}, + $toolhash{'linktext'},$toolhash{'explanation'}, $toolhash{'crslabel'},$toolhash{'crstitle'}) = @toolinfo; - $toolhash{'crslabel'} = &unescape($toolhash{'crslabel'}); - $toolhash{'crstitle'} = &unescape($toolhash{'crstitle'}); + foreach my $item (@extras) { + $toolhash{$item} = &unescape($toolhash{$item}); + } if (ref($ltitoolsref) eq 'HASH') { my @deleted; if (ref($ltitoolsref->{$toolid}) eq 'HASH') { - if ($ltitoolsref->{$toolid}->{'url'} =~ m{^https://}) { - $url =~ s/exttool$/exttools/; - } $toolhash{'id'} = $toolid; if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'window')) { if ($toolhash{'target'} eq 'window') { foreach my $item ('width','height') { $toolhash{$item} =~ s/^\s+//; $toolhash{$item} =~ s/\s+$//; + if ($toolhash{$item} =~ /\D/) { + delete($toolhash{$item}); + if ($residx) { + if ($toolsettings{$item}) { + push(@deleted,$item); + } + } + } } } } elsif ($residx) { $toolhash{'target'} = $toolsettings{'target'}; if ($toolhash{'target'} eq 'window') { - $toolhash{'width'} = $toolsettings{'width'}; - $toolhash{'height'} = $toolsettings{'height'}; + foreach my $item ('width','height') { + $toolhash{$item} = $toolsettings{$item}; + } } } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') { $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'}; @@ -699,31 +708,35 @@ sub group_import { } } if ($toolhash{'target'} eq 'iframe') { - delete($toolhash{'width'}); - delete($toolhash{'height'}); - if ($residx) { - if ($toolsettings{'width'}) { - push(@deleted,'width'); - } - if ($toolsettings{'height'}) { - push(@deleted,'height'); + foreach my $item ('width','height','linktext','explanation') { + delete($toolhash{$item}); + if ($residx) { + if ($toolsettings{$item}) { + push(@deleted,$item); + } } } } if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') { - foreach my $item ('label','title') { + foreach my $item ('label','title','linktext','explanation') { + my $crsitem; + if (($item eq 'label') || ($item eq 'title')) { + $crsitem = 'crs'.$item; + } else { + $crsitem = $item; + } if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) { - $toolhash{'crs'.$item} =~ s/^\s+//; - $toolhash{'crs'.$item} =~ s/\s+$//; - if ($toolhash{'crs'.$item} eq '') { - delete($toolhash{'crs'.$item}); + $toolhash{$crsitem} =~ s/^\s+//; + $toolhash{$crsitem} =~ s/\s+$//; + if ($toolhash{$crsitem} eq '') { + delete($toolhash{$crsitem}); } } else { - delete($toolhash{'crs'.$item}); + delete($toolhash{$crsitem}); } - if (($residx) && (exists($toolsettings{'crs'.$item}))) { - unless (exists($toolhash{'crs'.$item})) { - push(@deleted,'crs'.$item); + if (($residx) && (exists($toolsettings{$crsitem}))) { + unless (exists($toolhash{$crsitem})) { + push(@deleted,$crsitem); } } } @@ -920,7 +933,7 @@ sub docs_change_log { '// '."\n". @@ -1279,7 +1292,7 @@ sub print_paste_buffer { my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1]; if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) { $is_external = 1; - } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$}) { + } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttool$}) { $is_exttool = 1; } if ($folder =~ /^supplemental/) { @@ -1490,7 +1503,7 @@ sub supp_pasteable { ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) || ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) || ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) || - ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttools?$})) { + ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/exttool$})) { return 1; } return; @@ -3009,7 +3022,7 @@ sub handle_edit_cmd { sub editor { my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype, $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref, - $canedit,$navmapref,$hiddentop)=@_; + $canedit,$hostname,$navmapref,$hiddentop)=@_; my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container); if ($allowed) { (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain, @@ -3339,7 +3352,8 @@ sub editor { $output .= &entryline($idx,$name,$url,$folder,$allowed,$res, $coursenum,$coursedom,$crstype, $pathitem,$supplementalflag,$container, - \%filters,\%curr_groups,$ltitoolsref,$canedit,$isencrypted,$navmapref); + \%filters,\%curr_groups,$ltitoolsref,$canedit, + $isencrypted,$navmapref,$hostname); $idx++; $shown++; } @@ -3720,7 +3734,7 @@ sub is_supplemental_title { sub entryline { my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom, $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups, - $ltitoolsref,$canedit,$isencrypted,$navmapref)=@_; + $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_; my ($foldertitle,$renametitle,$oldtitle); if (&is_supplemental_title($title)) { ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title); @@ -3837,7 +3851,7 @@ END |/aboutme$ |/navmaps$ |/bulletinboard$ - |/exttools?$ + |/exttool$ |\.html$)}x) || $isexternal) { $skip_confirm = 1; @@ -3969,7 +3983,7 @@ END } } - my ($editlink,$extresform,$anchor,$hiddenres); + my ($editlink,$extresform,$anchor,$hiddenres,$nomodal); my $orig_url = $url; $orig_url=~s{http(:|:)//https(:|:)//}{https$2//}; $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/}; @@ -3987,10 +4001,23 @@ END } elsif ($url!~/\.(sequence|page)$/) { $url='/adm/coursedocs/showdoc'.$url; } - } elsif ($url=~m|^/ext/|) { - $url='/adm/wrapper'.$url; - } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) { + } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) { + my $wrapped = $1; + my $exturl = $2; + if ($wrapped eq '') { + $url='/adm/wrapper'.$url; + } + if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) { + $nomodal = 1; + } + } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttool$}) { $url='/adm/wrapper'.$url; + } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") { + if (($ENV{'SERVER_PORT'} == 443) && + ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) { + $url .= '?usehttp=1'; + $nomodal = 1; + } } if (&Apache::lonnet::symbverify($symb,$url)) { my $shownsymb = $symb; @@ -4020,7 +4047,7 @@ END if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) || $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) { $checkencrypt = 1; - } else { + } elsif (ref($navmapref)) { unless (ref($$navmapref)) { $$navmapref = Apache::lonnavmaps::navmap->new(); } @@ -4048,11 +4075,26 @@ END $url=''; } } - } elsif ($supplementalflag) { + } elsif ($supplementalflag) { if ($isexternal) { if ($url =~ /^([^#]+)#([^#]+)$/) { $url = $1; $anchor = $2; + if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) { + if ($hostname ne '') { + $url = 'http://'.$hostname.$url; + } + $nomodal = 1; + } + } + } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) { + if (($ENV{'SERVER_PORT'} == 443) && + ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) { + if ($hostname ne '') { + $url = 'http://'.$hostname.$url; + } + $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1'; + $nomodal = 1; } } } @@ -4075,25 +4117,29 @@ END my $encryptmap = ((&LONCAPA::map::getparameter($orderidx, 'parameter_encrypturl'))[0]=~/^yes$/i); unless ($hiddenmap) { - unless (ref($$navmapref)) { - $$navmapref = Apache::lonnavmaps::navmap->new(); - } - if (ref($$navmapref)) { - if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') { - my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1); - unless (@resources) { - $hiddenmap = 1; - unless ($env{'request.role.adv'}) { - $url = ''; - $hiddenfolder = 1; + if (ref($navmapref)) { + unless (ref($$navmapref)) { + $$navmapref = Apache::lonnavmaps::navmap->new(); + } + if (ref($$navmapref)) { + if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') { + my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1); + unless (@resources) { + $hiddenmap = 1; + unless ($env{'request.role.adv'}) { + $url = ''; + $hiddenfolder = 1; + } } } } } } unless ($encryptmap) { - if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') { - $encryptmap = 1; + if ((ref($navmapref)) && (ref($$navmapref))) { + if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') { + $encryptmap = 1; + } } } @@ -4139,7 +4185,7 @@ $form_end; } } elsif ($supplementalflag && !$allowed) { my $isexttool; - if ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) { + if ($url=~m{^/adm/$coursedom/$coursenum/\d+/exttool$}) { $url='/adm/wrapper'.$url; $isexttool = 1; } @@ -4164,7 +4210,7 @@ $form_end; &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem, undef,undef,undef,undef,undef,undef, undef,$disabled); - } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/exttools?$}) { + } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/exttool$}) { ($editlink,$extresform) = &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem, undef,undef,undef,'tool',$coursedom, @@ -4183,7 +4229,8 @@ $form_end; $forceedit, undef,$symb, &escape($env{'form.folderpath'}), - $renametitle,'','',1,$suppanchor); + $renametitle,$hostname, + '','',1,$suppanchor); if ($jscall) { $editlink = ''.&mt('Edit').' '."\n"; @@ -4200,6 +4247,7 @@ $form_end; $reinit = &mt('(re-initialize course to access)'); } $line.=''.$editlink.$renamelink; + my $link; if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) { $line.=''; } elsif ($url) { @@ -4210,9 +4258,20 @@ $form_end; $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&'); } } - $line.=&Apache::loncommon::modal_link(&js_escape($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'. - (($anchor ne '')?$anchor:'')), - '',600,500); + if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) { + $link = 'http://'.$hostname.$url; + } else { + $link = $url; + } + $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'. + (($anchor ne '')?$anchor:'')); + if ($nomodal) { + $line.=''. + ''; + } else { + $line.=&Apache::loncommon::modal_link($link, + '',600,500); + } } else { $line.=''; } @@ -4220,9 +4279,12 @@ $form_end; if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) { $line.=''.$title.''; } elsif ($url) { - $line.=&Apache::loncommon::modal_link(&js_escape($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'. - (($anchor ne '')?$anchor:'')), - $title,600,500); + if ($nomodal) { + $line.=''. + $title.''; + } else { + $line.=&Apache::loncommon::modal_link($link,$title,600,500); + } } elsif (($hiddenfolder) || ($hiddenres)) { $line.=$title.' '.&mt('(Hidden)').''; } else { @@ -5343,8 +5405,9 @@ sub handler { my $tabidstr = join("','",@tabids); %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom); my $posslti = keys(%ltitools); + my $hostname = $r->hostname(); $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti, - $londocroot,$canedit,\$navmap). + $londocroot,$canedit,$hostname,\$navmap). &history_tab_js(). &inject_data_js(). &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid). @@ -5746,7 +5809,7 @@ HIDDENFORM } # - + my $hostname = $r->hostname(); my $savefolderpath; if ($allowed) { @@ -6216,7 +6279,7 @@ unless ($container eq 'page') { unless (($supplementalflag || $toolsflag)) { my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype, $supplementalflag,\%orderhash,$iconpath,$pathitem, - \%ltitools,$canedit,\$navmap,$hiddentop); + \%ltitools,$canedit,$hostname,\$navmap,$hiddentop); undef($navmap); if ($error) { $r->print('

'.$error.'

'); @@ -6365,7 +6428,7 @@ my %suporderhash = ( if ($supplementalflag) { my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype, $supplementalflag,\%suporderhash,$iconpath,$pathitem, - \%ltitools,$canedit); + \%ltitools,$canedit,$hostname); if ($error) { $r->print('

'.$error.'

'); } else { @@ -6385,7 +6448,7 @@ my %suporderhash = ( } } elsif ($supplementalflag) { my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype, - $supplementalflag,'',$iconpath,$pathitem); + $supplementalflag,'',$iconpath,$pathitem,'','',$hostname); if ($error) { $r->print('

'.$error.'

'); } @@ -6759,7 +6822,8 @@ END } sub editing_js { - my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,$londocroot,$canedit,$navmapref) = @_; + my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti, + $londocroot,$canedit,$hostname,$navmapref) = @_; my %js_lt = &Apache::lonlocal::texthash( p_mnf => 'Name of New Folder', t_mnf => 'New Folder', @@ -6836,6 +6900,19 @@ sub editing_js { } $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='. &HTML::Entities::encode($caller,'<>&"'); + if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) { + if (($ENV{'SERVER_PORT'} == 443) && + ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) { + if ($hostname ne '') { + $backtourl = 'http://'.$hostname.$backtourl; + } + $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1'; + } + } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) { + if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) { + $backtourl = 'http://'.$hostname.$backtourl; + } + } if ($anchor ne '') { $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"'); }