Diff for /loncom/xml/scripttag.pm between versions 1.165 and 1.173

version 1.165, 2012/02/05 23:00:06 version 1.173, 2015/01/19 15:36:16
Line 31  package Apache::scripttag; Line 31  package Apache::scripttag;
 use strict;  use strict;
 use Apache::lonnet;  use Apache::lonnet;
 use Apache::lonlocal;  use Apache::lonlocal;
   use Apache::lonxml();
   use Apache::londefdef();
 use Apache::style();  use Apache::style();
   
 #Globals  #Globals
Line 109  sub start_script { Line 111  sub start_script {
      $env{'form.counter'},$Apache::lonxml::curdepth);       $env{'form.counter'},$Apache::lonxml::curdepth);
             &Apache::lonxml::add_script_result(              &Apache::lonxml::add_script_result(
              &Apache::loncommon::modal_adhoc_window($function_name,500,500,               &Apache::loncommon::modal_adhoc_window($function_name,500,500,
                             '<pre>'.&Apache::run::dump($target,$safeeval).'</pre>',                              '<pre style="background-color:#ffffff;">'.
                               &Apache::run::dump($target,$safeeval).'</pre>',
                             &mt('Script Vars'))."<br />");                              &mt('Script Vars'))."<br />");
  }   }
     } elsif ($target eq "edit" ) {      } elsif ($target eq "edit" ) {
       #&Apache::run::run($bodytext,$safeeval);        #&Apache::run::run($bodytext,$safeeval);
       #$result="<br /> &lt;$token->[1]&gt; output: <br />$bodytext<br />Source:<br />";        #$result="<br /> &lt;$token->[1]&gt; output: <br />$bodytext<br />Source:<br />";
  my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);      my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
  $result=&Apache::edit::tag_start($target,$token,'Script');      $result=&Apache::edit::tag_start($target,$token,'Script');
  $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,4);  
           my $depth = $Apache::lonxml::curdepth;
           $result.='<span id="LC_edit_problem_codemirror">';
           unless ($env{'environment.nocodemirror'}) {
               # only show button if codemirror activated
               $result.='<input type="button" id="fitsize'.$depth.'" value="'.&mt("Dynamic size").
               '" onclick="autosize(\''.$depth.'\')" />';
           }
           $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,4).'</span>';
   
           unless ($env{'environment.nocodemirror'}) {
               $result.='<script type="text/javascript">
                   var cm'.$depth.' = CodeMirror.fromTextArea(document.getElementById("homework_edit_'.$depth.'"),
                   {
                       mode: "perl",
                       lineWrapping: true,
                       lineNumbers: true,
                       tabSize: 4,
                       indentUnit: 4,
                       autoCloseBrackets: true,
                       styleActiveLine: true,
                       
                       extraKeys: {
                           "Tab": "indentMore",
                           "Shift-Tab": "indentLess"
                       }
                   });
                   if(sessionStorage.getItem("autosized_'.$depth.'") != null) {
                       document.getElementById("fitsize'.$depth.'").value = "'.&mt("Fixed size").'";
                       cm'.$depth.'.setSize("","auto");
                   }
               </script>';
           }
                   
   
     } elsif ($target eq 'meta') {      } elsif ($target eq 'meta') {
  my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);   my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
     }      }
Line 126  sub start_script { Line 163  sub start_script {
       if ($target ne "meta" && $target ne 'tex' && $target ne 'answer') {        if ($target ne "meta" && $target ne 'tex' && $target ne 'answer') {
   $result = $token->[4];    $result = $token->[4];
   $result.=$bodytext;    $result.=$bodytext;
           if ($type eq "text/javascript") {            my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
               my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);            my $url=&Apache::lonnet::hreflocation('',$env{'request.filename'});
               if (($src =~ /\.js$/) && ($src !~ m{^(/|https?://)})) {            my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   my ($path,$scriptname) = ($src =~ m{^(.+)/([^/]*)$});            my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   my $docuri =            if ($src ne '') {
                       $Apache::lonnet::env{'request.noversionuri'};                if ($src !~ m{^(/|https?://)}) {
                   my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};                    my $cleanhref = &Apache::londefdef::clean_docs_httpref($src,$url,$cdom,$cnum);
                   my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};                    if ($cleanhref) {
                   if ($docuri =~ m{^(\Q/uploaded/$cdom/$cnum\E)/(docs/.*/)[^/]+$}) {                        &Apache::lonxml::extlink($cleanhref);
                       my $prefix = $1;                    }
                       my $relpath = $2;                }
                       my $cleanrelpath;            } elsif (($type eq 'text/javascript') && ($bodytext ne '')) {
                       foreach my $dir (split(/\//,$relpath.$path)) {                if ($url =~ m{^\Q/uploaded/$cdom/$cnum/\E(docs|supplemental)/}) {
                           next if ($dir eq '.');                    if ($bodytext =~ m{\.addMediaSrc\((["'])((?!\1).)+\1\);}) {
                           if ($dir eq '..') {                        my $quote = $1;
                               $cleanrelpath =~ s{([^/]+/)$}{};                        if ($bodytext =~ m{\Q.addMediaSrc($quote\E([^$quote]+)\Q$quote)\E}) {
                           } else {                            my $fname = $1;
                               $cleanrelpath .= $dir.'/';                            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 <main>.html or <main>_player.html files,
   # so call lonxml::extlink() here to include httpref for the uploaded file.
   # (where <main> 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 <main>.html or <main>_player.html files,
   # so call lonxml::extlink() here to include httpref for the uploaded file.
   # (where <main> 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: <main>_Thumbnails.png needed, and included in zip archive.
   # Not referenced directly in <main>.html or <main>_player.html files,
   # so call lonxml::extlink() here to include httpref for the uploaded file
   # (where <main> 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 '') {                    if ($bodytext =~ /\(document,\s*(['"])script\1,\s*\[([^\]]+)\]\);/s) {
                           $src = $prefix.'/'.$cleanrelpath.'/'.$scriptname;                        my $scriptslist = $2;
                       } else {                        my @srcs = split(/\s*,\s*/,$scriptslist);
                           $src = $prefix.'/'.$scriptname;                        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);
                             }
                       }                        }
                   }                    }
               }                }

Removed from v.1.165  
changed lines
  Added in v.1.173


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>