--- loncom/xml/scripttag.pm 2012/08/07 14:50:17 1.166 +++ loncom/xml/scripttag.pm 2015/01/19 15:36:16 1.173 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # '; + } + + } elsif ($target eq 'meta') { my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser); } @@ -127,34 +163,110 @@ sub start_script { if ($target ne "meta" && $target ne 'tex' && $target ne 'answer') { $result = $token->[4]; $result.=$bodytext; - if ($type eq "text/javascript") { - my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1); - if (($src =~ /\.js$/) && ($src !~ m{^(/|https?://)})) { - my ($path,$scriptname) = ($src =~ m{^(.+)/([^/]*)$}); - my $docuri = - $Apache::lonnet::env{'request.noversionuri'}; - my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; - my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; - if ($docuri =~ m{^(\Q/uploaded/$cdom/$cnum\E)/(docs/.*/)[^/]+$}) { - my $prefix = $1; - my $relpath = $2; - my $cleanrelpath; - foreach my $dir (split(/\//,$relpath.$path)) { - next if ($dir eq '.'); - if ($dir eq '..') { - $cleanrelpath =~ s{([^/]+/)$}{}; - } else { - $cleanrelpath .= $dir.'/'; + my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1); + my $url=&Apache::lonnet::hreflocation('',$env{'request.filename'}); + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + if ($src ne '') { + if ($src !~ m{^(/|https?://)}) { + my $cleanhref = &Apache::londefdef::clean_docs_httpref($src,$url,$cdom,$cnum); + if ($cleanhref) { + &Apache::lonxml::extlink($cleanhref); + } + } + } elsif (($type eq 'text/javascript') && ($bodytext ne '')) { + if ($url =~ m{^\Q/uploaded/$cdom/$cnum/\E(docs|supplemental)/}) { + if ($bodytext =~ m{\.addMediaSrc\((["'])((?!\1).)+\1\);}) { + my $quote = $1; + if ($bodytext =~ m{\Q.addMediaSrc($quote\E([^$quote]+)\Q$quote)\E}) { + my $fname = $1; + my $cleanhref = + &Apache::londefdef::clean_docs_httpref($fname,$url,$cdom,$cnum); + if ($cleanhref) { + &Apache::lonxml::extlink($cleanhref); + } + } + } + if ($bodytext =~ m{\.set\w+(Src|Swf)\(["']}i) { + my @srcs = split(/\.set/,$bodytext); + if (scalar(@srcs) > 1) { + foreach my $item (@srcs) { + if ($item =~ m{^(FlashPlayerSwf|MediaSrc|XMPSrc|ConfigurationSrc|PosterImageSrc)\((['"])(?:(?!\2).)+\2\)}is) { + my $srctype = $1; + my $quote = $2; + my ($fname) = ($item =~ m{^\Q$srctype($quote\E([^$quote]+)\Q$quote)\E}); + my $cleanhref = + &Apache::londefdef::clean_docs_httpref($fname,$url,$cdom,$cnum); + if ($cleanhref) { + &Apache::lonxml::extlink($cleanhref); + if ($srctype eq 'ConfigurationSrc') { + if ($cleanhref =~ m{^(.+/)configuration_express\.xml$}) { +# +# Camtasia 8.1: express_show/spritesheet.png needed, and included in zip archive. +# Not referenced directly in
.html or
_player.html files, +# so call lonxml::extlink() here to include httpref for the uploaded file. +# (where
is name user gave to file/archive). +# + + my $spritesheet = $1.'express_show/spritesheet.png'; + if (&Apache::lonnet::repcopy_userfile($spritesheet) eq 'ok') { + &Apache::lonxml::extlink($spritesheet); + } + } +# +# Camtasia 8.4: express_show/spritesheet.min.css needed, and included in zip archive. +# Not referenced directly in
.html or
_player.html files, +# so call lonxml::extlink() here to include httpref for the uploaded file. +# (where
is name user gave to file/archive). +# + my $spritesheet_css = $1.'express_show/spritesheet.min.css'; + if (&Apache::lonnet::repcopy_userfile($spritesheet_css) eq 'ok') { + &Apache::lonxml::extlink($spritesheet_css); + } + } elsif ($srctype eq 'PosterImageSrc') { + if ($fname =~ m{^(.+)_First_Frame\.png$}) { + my $prefix = $1; + my ($path) = ($cleanhref =~ m{^(.+/)\Q$fname\E}); +# +# Camtasia 8.1:
_Thumbnails.png needed, and included in zip archive. +# Not referenced directly in
.html or
_player.html files, +# so call lonxml::extlink() here to include httpref for the uploaded file +# (where
is name user gave to file/archive). +# + my $thumbnail = $path.$prefix.'_Thumbnails.png'; + if (&Apache::lonnet::repcopy_userfile($thumbnail) eq 'ok') { + &Apache::lonxml::extlink($thumbnail); + } + } + } + } + } } } - $cleanrelpath =~ s{/$}{}; - if ($cleanrelpath ne '') { - $src = $prefix.'/'.$cleanrelpath.'/'.$scriptname; - } else { - $src = $prefix.'/'.$scriptname; + } + if ($bodytext =~ /\(document,\s*(['"])script\1,\s*\[([^\]]+)\]\);/s) { + my $scriptslist = $2; + my @srcs = split(/\s*,\s*/,$scriptslist); + foreach my $src (@srcs) { + if ($src =~ /(["'])(?:(?!\1).)+\.js\1/) { + my $quote = $1; + my ($fname) = ($src =~ m/\Q$quote\E([^$quote]+)\Q$quote\E/); + my $cleanhref = + &Apache::londefdef::clean_docs_httpref($fname,$url,$cdom,$cnum); + if ($cleanhref) { + &Apache::lonxml::extlink($cleanhref); + } + } } - if ($src ne '') { - &Apache::lonxml::extlink($src); + } + if ($bodytext =~ m{loadScript\(\s*(['"])((?:(?!\1).)+\.js)\1,\s*function}is) { + my $fname = $2; + if ($fname) { + my $cleanhref = + &Apache::londefdef::clean_docs_httpref($fname,$url,$cdom,$cnum); + if ($cleanhref) { + &Apache::lonxml::extlink($cleanhref); + } } } }