--- loncom/imspackages/imsprocessor.pm 2018/09/03 12:43:00 1.54.4.1 +++ loncom/imspackages/imsprocessor.pm 2017/05/23 03:07:40 1.55 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Processor for IMS Packages # -# $Id: imsprocessor.pm,v 1.54.4.1 2018/09/03 12:43:00 raeburn Exp $ +# $Id: imsprocessor.pm,v 1.55 2017/05/23 03:07:40 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -29,12 +29,11 @@ package Apache::imsprocessor; use Apache::lonnet; -use Apache::loncommon; use Apache::loncleanup; use Apache::lonlocal; -use LWP::UserAgent; use HTTP::Request::Common; use LONCAPA::Configuration; +use LONCAPA::LWPReq; use strict; sub ims_config { @@ -100,9 +99,6 @@ sub create_tempdir { my ($context,$pathinfo,$timenow) = @_; my $configvars = &LONCAPA::Configuration::read_conf('loncapa.conf'); my $tempdir; - $pathinfo = &Apache::loncommon::clean_path($pathinfo); -# Collapse dots - $pathinfo =~ s/\.+/./g; if ($context eq 'DOCS') { $tempdir = $$configvars{'lonDaemons'}.'/tmp/'.$pathinfo; if (!-e "$tempdir") { @@ -134,13 +130,11 @@ sub uploadzip { $fname=~s/\s+/\_/g; # Replace all other weird characters by nothing $fname=~s/[^\w\.\-]//g; -# Collapse dots - $fname=~s/\.+/./g; # See if there is anything left unless ($fname) { return 'error: no uploaded file'; } # Save the file chomp($env{'form.uploadname'}); - open(my $fh,'>',"$tempdir/$fname"); + open(my $fh,'>'.$tempdir.'/'.$fname); print $fh $env{'form.uploadname'}; close($fh); } elsif ($context eq 'CSTR') { @@ -994,10 +988,10 @@ sub build_structure { $seqtext{$key} .= "\n"; if ($cms eq 'webctce4' && $key ne 'Top') { push @{$seqfiles}, "$seqtitle.sequence"; - open(LOCFILE,'>',"$destdir/sequences/$seqtitle.sequence"); + open(LOCFILE,">$destdir/sequences/$seqtitle.sequence"); } else { push @{$seqfiles}, "$key.sequence"; - open(LOCFILE,'>',"$destdir/sequences/$key.sequence"); + open(LOCFILE,">$destdir/sequences/$key.sequence"); } print LOCFILE $seqtext{$key}; close(LOCFILE); @@ -1027,7 +1021,7 @@ sub build_structure { &process_specials($context,'pools',$pools,\$topnum,$$items{'Top'}{contentscount},$destdir,$udom,$uname,$cdom,$crs,$timenow,$newdir,$timestamp,$resinfo,\$seqtext{'Top'},$pagesfiles,$seqfiles,$topurls,$topnames); } $seqtext{'Top'} .= "\n"; - open(TOPFILE,'>',"$destdir/sequences/Top.sequence"); + open(TOPFILE,">$destdir/sequences/Top.sequence"); print TOPFILE $seqtext{'Top'}; close(TOPFILE); push @{$seqfiles}, 'Top.sequence'; @@ -1049,7 +1043,7 @@ sub build_structure { if (grep/^$res$/,@{$packages}) { $resource = $filestem.'/resfiles/'.$res.'./index.html'; # should be entry_point } - open(PAGEFILE,'>',$filename); + open(PAGEFILE,">$filename"); print PAGEFILE qq| \n|; @@ -1238,10 +1232,10 @@ sub process_specials { if ($type eq "announcements") { push @{$pagesfiles}, "$seqnames{$type}.page"; - open(ITEM,'>',"$destdir/pages/$seqnames{$type}.page"); + open(ITEM,">$destdir/pages/$seqnames{$type}.page"); } else { push @{$seqfiles}, "$seqnames{$type}.sequence"; - open(ITEM,'>',"$destdir/sequences/$seqnames{$type}.sequence"); + open(ITEM,">$destdir/sequences/$seqnames{$type}.sequence"); } if ($type eq 'boards') { @@ -1584,7 +1578,7 @@ sub process_staff { |; - open(FILE,'>',"$destdir/resfiles/$res.html"); + open(FILE,">$destdir/resfiles/$res.html"); push @{$resrcfiles}, "$res.html"; print FILE qq| @@ -1663,7 +1657,7 @@ sub process_link { $linktag .= qq|>$$settings{title}|; } - open(FILE,'>',"$destdir/resfiles/$res.html"); + open(FILE,">$destdir/resfiles/$res.html"); push @{$resrcfiles}, "$res.html"; print FILE qq| @@ -3399,7 +3393,7 @@ sub build_category_sequences { my $curr_id = 0; my $next_id = 1; my $fh; - open($fh,'>',"$destdir/sequences/question_database.sequence"); + open($fh,">$destdir/sequences/question_database.sequence"); push @{$sequencesfiles},'question_database.sequence'; foreach my $category (sort(keys(%{$catinfo}))) { my $seqname; @@ -3465,7 +3459,7 @@ sub build_problem_container { if (!-e "$seqdir") { mkdir("$seqdir",0770); } - open($fh,'>',$$containerdir); + open($fh,">$$containerdir"); $$total{seq} ++; push @{$sequencesfiles},$mapname.'.sequence'; } else { @@ -3473,7 +3467,7 @@ sub build_problem_container { if (!-e "$pagedir") { mkdir("$pagedir",0770); } - open($fh,'>',$$containerdir); + open($fh,">$$containerdir"); $$total{page} ++; push @{$pagesfiles},$mapname.'.page'; } @@ -3931,7 +3925,7 @@ sub write_bb5_questions { $title =~ s/\s/_/g; $title =~ s/\W//g; $title .= '_'.$id; - open(PROB,'>',"$newdir/$title.problem"); + open(PROB,">$newdir/$title.problem"); print PROB $output; close PROB; } else { @@ -4549,7 +4543,7 @@ $$settings{$id}{$list}{jumbledtext}[$k] $title =~ s/\s/_/g; $title =~ s/:/_/g; $title =~ s/\//_/g; - open(PROB,'>',"$destdir/problems/$probdir/$title.problem"); + open(PROB,">$destdir/problems/$probdir/$title.problem"); print PROB $output; close PROB; } else { @@ -4948,7 +4942,7 @@ sub write_bb6_questions { $title =~ s/\s/_/g; $title =~ s/\W//g; $title .= '_'.$id; - open(PROB,'>',"$newdir/$title.problem"); + open(PROB,">$newdir/$title.problem"); print PROB $output; close PROB; } else { @@ -4963,9 +4957,9 @@ sub retrieve_image { my ($context,$res,$dirname,$cdom,$cname,$docroot,$destdir,$urlpath,$filename) = @_; my $contents; my $url = $urlpath.$filename; - my $ua=new LWP::UserAgent; + my $lonhost = $Apache::lonnet::perlvar{'lonHostID'}; my $request=new HTTP::Request('GET',$url); - my $response=$ua->request($request); + my $response=&LONCAPA::LWPReq::makerequest($lonhost,$request); if ($response->is_success) { $contents = $response->content; if (!-e "$docroot/$res") { @@ -4974,7 +4968,7 @@ sub retrieve_image { if (!-e "$docroot/$res/webimages") { mkdir("$docroot/$res/webimages",0755); } - open(my $fh,'>',"$docroot/$res/webimages/$filename"); + open(my $fh,">$docroot/$res/webimages/$filename"); print $fh $contents; close($fh); if ($context eq 'DOCS') { @@ -5067,7 +5061,7 @@ sub process_announce { } } - open(FILE,'>',"$destdir/resfiles/$res.html"); + open(FILE,">$destdir/resfiles/$res.html"); push @{$resrcfiles}, "$res.html"; print FILE qq| @@ -5273,7 +5267,7 @@ sub process_content { } } - if (!open(FILE,'>',"$destdir/resfiles/$res.html")) { + if (!open(FILE,">$destdir/resfiles/$res.html")) { &Apache::lonnet::logthis("IMS import error: Cannot open file - $destdir/resfiles/$res.html - $!"); } else { push @{$resrcfiles}, "$res.html"; @@ -5466,7 +5460,7 @@ sub angel_content { $p->parse_file($xmlfile); $p->eof; if ($type eq "PAGE") { - open(FILE,'<',$xmlfile); + open(FILE,"<$xmlfile"); @buffer = ; close(FILE); chomp(@buffer); @@ -5483,7 +5477,7 @@ sub angel_content { } } } - open(FILE,'>',"$destdir/resfiles/$res.html"); + open(FILE,">$destdir/resfiles/$res.html"); push @{$resrcfiles}, "$res.html"; print FILE qq| @@ -5519,7 +5513,7 @@ sub angel_content { sub webct4_content { my ($res,$docroot,$destdir,$settings,$dom,$user,$type,$title,$resrcfiles) = @_; if (defined($$settings{url})) { - if (!open(FILE,'>',"$destdir/resfiles/$res.html")) { + if (!open(FILE,">$destdir/resfiles/$res.html")) { &Apache::lonnet::logthis("IMS import error: Cannot open file - $destdir/resfiles/$res.html - $!"); } else { push(@{$resrcfiles}, "$res.html");