Diff for /loncom/xml/lonxml.pm between versions 1.173 and 1.192

version 1.173, 2002/05/23 21:24:06 version 1.192, 2002/09/04 06:55:27
Line 176  sub xmlend { Line 176  sub xmlend {
  unless (($hidden) && (!$seeid)) {   unless (($hidden) && (!$seeid)) {
                  my $message=$contrib{$idx.':message'};                   my $message=$contrib{$idx.':message'};
                  $message=~s/\n/\<br \/\>/g;                   $message=~s/\n/\<br \/\>/g;
    $message=&Apache::lontexconvert::msgtexconverted($message);
                  if ($message) {                   if ($message) {
                   if ($hidden) {                    if ($hidden) {
       $message='<font color="#888888">'.$message.'</font>';        $message='<font color="#888888">'.$message.'</font>';
Line 331  sub registerurl { Line 332  sub registerurl {
     my $forcereg=shift;      my $forcereg=shift;
     my $target = shift;      my $target = shift;
     my $result = '';      my $result = '';
     if (($ENV{'request.publicaccess'}) ||       if ($target eq 'edit') {
        (!&Apache::lonnet::is_on_map($ENV{'REQUEST_URI'}))) {          $result .="<script>\n".
  return               "if (typeof menu != 'undefined') {menu.currentURL=null;}\n".
               &Apache::loncommon::browser_and_searcher_javascript().
                   "\n</script>\n";
       }
       if ((($ENV{'request.publicaccess'}) || 
            (!&Apache::lonnet::is_on_map($ENV{'REQUEST_URI'}))) &&
           (!$forcereg)) {
    return $result.
          '<script>function LONCAPAreg(){} function LONCAPAstale(){}</script>';           '<script>function LONCAPAreg(){} function LONCAPAstale(){}</script>';
     }      }
     if ($Apache::lonxml::registered && !$forcereg) { return ''; }      if ($Apache::lonxml::registered && !$forcereg) { return ''; }
     $Apache::lonxml::registered=1;      $Apache::lonxml::registered=1;
     my $nothing='';      my $nothing='';
     if ($ENV{'browser.type'} eq 'explorer') { $nothing='javascript:void(0);'; }      if ($ENV{'browser.type'} eq 'explorer') { $nothing='javascript:void(0);'; }
       my $timesync='menu.syncclock(1000*'.time.');';
     if (($ENV{'REQUEST_URI'}!~/^\/(res\/)*adm\//) || ($forcereg)) {      if (($ENV{'REQUEST_URI'}!~/^\/(res\/)*adm\//) || ($forcereg)) {
         my $hwkadd='';          my $hwkadd='';
         if ($ENV{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form)$/) {          if ($ENV{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form)$/) {
Line 367  ENDPARM Line 376  ENDPARM
     function LONCAPAreg() {      function LONCAPAreg() {
   menu=window.open("$nothing","LONCAPAmenu","",false);    menu=window.open("$nothing","LONCAPAmenu","",false);
           menu.clearTimeout(menu.menucltim);            menu.clearTimeout(menu.menucltim);
             $timesync
   menu.currentURL=window.location.pathname;    menu.currentURL=window.location.pathname;
             menu.reloadURL=window.location.pathname;
           menu.currentStale=0;            menu.currentStale=0;
           menu.clearbut(3,1);            menu.clearbut(3,1);
           menu.switchbutton            menu.switchbutton
Line 375  ENDPARM Line 386  ENDPARM
           menu.switchbutton            menu.switchbutton
        (8,1,'eval.gif','evaluate','this','gopost("/adm/evaluate",currentURL)');         (8,1,'eval.gif','evaluate','this','gopost("/adm/evaluate",currentURL)');
           menu.switchbutton            menu.switchbutton
     (8,2,'fdbk.gif','feedback','on this','gopost("/adm/feedback",currentURL)');      (8,2,'fdbk.gif','feedback','discuss','gopost("/adm/feedback",currentURL)');
           menu.switchbutton            menu.switchbutton
      (8,3,'prt.gif','prepare','printout','gopost("/adm/printout",currentURL)');       (8,3,'prt.gif','prepare','printout','gopost("/adm/printout",currentURL)');
           menu.switchbutton            menu.switchbutton
Line 394  ENDPARM Line 405  ENDPARM
     function LONCAPAstale() {      function LONCAPAstale() {
   menu=window.open("$nothing","LONCAPAmenu","",false);    menu=window.open("$nothing","LONCAPAmenu","",false);
           menu.currentStale=1;            menu.currentStale=1;
           menu.switchbutton            if (menu.reloadURL!='' && menu.reloadURL!= null) { 
              (3,1,'reload.gif','return','location','go(currentURL)');               menu.switchbutton
                (3,1,'reload.gif','return','location','go(reloadURL)');
     }
           menu.clearbut(7,1);            menu.clearbut(7,1);
           menu.clearbut(7,2);            menu.clearbut(7,2);
           menu.clearbut(7,3);            menu.clearbut(7,3);
Line 418  ENDREGTHIS Line 431  ENDREGTHIS
   
     function LONCAPAreg() {      function LONCAPAreg() {
   menu=window.open("$nothing","LONCAPAmenu","",false);    menu=window.open("$nothing","LONCAPAmenu","",false);
             $timesync
           menu.currentStale=1;            menu.currentStale=1;
           menu.clearbut(2,1);            menu.clearbut(2,1);
           menu.clearbut(2,3);            menu.clearbut(2,3);
Line 439  ENDREGTHIS Line 453  ENDREGTHIS
 </script>  </script>
 ENDDONOTREGTHIS  ENDDONOTREGTHIS
     }      }
     if ($target eq 'edit') {  
  # Javascript routines for construction space:  
  # openbrowser and opensearcher will start the file browser  
  # (lonindexer) and searcher (lonsearchcat) respectively.  
  # Inputs are the name of the html form being used  
  # and the name of the element the selected URL should  
  # be placed in.  
         # openbrowser also takes arguments only and omit, which are  
         # comma deliminated lists of file extensions to (only) show   
         # or omit.  
         # Here we also set currentURL=null.  
         $result .=<<"ENDBROWSERSCRIPT";  
 <script>  
     menu.currentURL=null;  
     var editbrowser;  
     function openbrowser(formname,elementname,only,omit) {  
         var url = '/res/?';  
         if (editbrowser == null) {  
             url += 'launch=1&';  
         }  
         url += 'catalogmode=interactive&';  
         url += 'mode=edit&';  
         url += 'form=' + formname + '&';  
         if (only != null) {  
             url += 'only=' + only + '&';  
         }   
         if (omit != null) {  
             url += 'omit=' + omit + '&';  
         }  
         url += 'element=' + elementname + '';  
         var title = 'Browser';  
         var options = 'scrollbars=1,resizable=1,menubar=0';  
         options += ',width=700,height=600';  
         editbrowser = open(url,title,options,'1');  
         editbrowser.focus();  
     }  
     var editsearcher;  
     function opensearcher(formname,elementname) {  
         var url = '/adm/searchcat?';  
         if (editsearcher == null) {  
             url += 'launch=1&';  
         }  
         url += 'catalogmode=interactive&';  
         url += 'mode=edit&';  
         url += 'form=' + formname + '&';  
         url += 'element=' + elementname + '';  
         var title = 'Search';  
         var options = 'scrollbars=1,resizable=1,menubar=0';  
         options += ',width=700,height=600';  
         editsearcher = open(url,title,options,'1');  
         editsearcher.focus();  
     }  
 </script>  
 ENDBROWSERSCRIPT  
     }  
     return $result;      return $result;
 }  }
   
Line 517  sub xmlparse { Line 476  sub xmlparse {
  my ($request,$target,$content_file_string,$safeinit,%style_for_target) = @_;   my ($request,$target,$content_file_string,$safeinit,%style_for_target) = @_;
   
  &setup_globals($request,$target);   &setup_globals($request,$target);
   #
   # do we have a course style file?
   #
   
    if ($ENV{'request.course.id'}) {
        my $bodytext=
    $ENV{'course.'.$ENV{'request.course.id'}.'.default_xml_style'};
        if ($bodytext) {
          my $location=&Apache::lonnet::filelocation('',$bodytext);
          my $styletext=&Apache::lonnet::getfile($location);
          if ($styletext ne '-1') {
             %style_for_target = (%style_for_target,
                             &Apache::style::styleparser($target,$styletext));
          }
       }
    }
   
  #&printalltags();   #&printalltags();
  my @pars = ();   my @pars = ();
  my $pwd=$ENV{'request.filename'};   my $pwd=$ENV{'request.filename'};
Line 563  sub htmlclean { Line 539  sub htmlclean {
     return $output;      return $output;
 }  }
   
   sub latex_special_symbols {
       my ($current_token,$stack,$parstack)=@_;
       $current_token=~s/\\/\\char92 /g;
       $current_token=~s/\^/\\char94 /g;
       $current_token=~s/\~/\\char126 /g;
       $current_token=~s/(&[^a-z#])/\\$1/g;
       $current_token=~s/([^&]\#)/\\$1/g;
       $current_token=~s/(\$|_|{|})/\\$1/g;
       $current_token=~s/\\char92 /\\texttt{\\char92}/g;
       $current_token=~s/>/\$>\$/g; #more
       $current_token=~s/</\$<\$/g; #less
       if ($current_token=~m/\d%/) {$current_token =~ s/(\d)%/$1\\%/g;} #percent after digit
       if ($current_token=~m/\s%/) {$current_token =~ s/(\s)%/$1\\%/g;} #persent after space
       return $current_token;
   }
   
 sub inner_xmlparse {  sub inner_xmlparse {
   my ($target,$stack,$parstack,$pars,$safeeval,$style_for_target)=@_;    my ($target,$stack,$parstack,$pars,$safeeval,$style_for_target)=@_;
   my $finaloutput = '';    my $finaloutput = '';
Line 572  sub inner_xmlparse { Line 564  sub inner_xmlparse {
     while ($token = $$pars['-1']->get_token) {      while ($token = $$pars['-1']->get_token) {
       if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) {        if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) {
  if ($metamode<1) {   if ($metamode<1) {
   $result=$token->[1];      my $text=$token->[1];
       if ($token->[0] eq 'C') {
    $text = '%'.$text;
    $text =~ s/[\n\r]//g;
       }
       $result.=$text;
  }   }
       } elsif ($token->[0] eq 'PI') {        } elsif ($token->[0] eq 'PI') {
  if ($metamode<1) {   if ($metamode<1) {
Line 635  sub inner_xmlparse { Line 632  sub inner_xmlparse {
   $result= &Apache::run::evaluate($result,$safeeval,'');    $result= &Apache::run::evaluate($result,$safeeval,'');
  }   }
       }        }
         if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) {
    if ($target eq 'tex') {
       $result=&latex_special_symbols($result,$stack,$parstack);
    }
         }
   
       # Encode any high ASCII characters        # Encode any high ASCII characters
       if (!$Apache::lonxml::prevent_entity_encode) {        if (!$Apache::lonxml::prevent_entity_encode) {
  $result=&HTML::Entities::encode($result,"\200-\377");   $result=&HTML::Entities::encode($result,"\200-\377");
Line 761  sub callsub { Line 764  sub callsub {
     }      }
     if (!$deleted) {      if (!$deleted) {
       if ($space) {        if ($space) {
  #&Apache::lonxml::debug("Calling sub $sub in $space $metamode");   &Apache::lonxml::debug("Calling sub $sub in $space $metamode");
  $sub1="$space\:\:$sub";   $sub1="$space\:\:$sub";
  ($currentstring,$nodefault) = &$sub1($target,$token,$tagstack,   ($currentstring,$nodefault) = &$sub1($target,$token,$tagstack,
      $parstack,$parser,$safeeval,       $parstack,$parser,$safeeval,
      $style);       $style);
       } else {        } else {
  #&Apache::lonxml::debug("NOT Calling sub $sub in $space $metamode");   &Apache::lonxml::debug("NOT Calling sub $sub in $space $metamode");
  if ($metamode <1) {   if ($metamode <1) {
   if (defined($token->[4]) && ($metamode < 1)) {    if (defined($token->[4]) && ($metamode < 1)) {
     $currentstring = $token->[4];      $currentstring = $token->[4];
Line 959  sub decreasedepth { Line 962  sub decreasedepth {
 #print "<br />e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n";  #print "<br />e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n";
 }  }
   
 sub get_all_text {  sub get_all_text_unbalanced {
   #there is a copy of this in lonpublisher.pm
    my($tag,$pars)= @_;
    my $token;
    my $result='';
    $tag='<'.$tag.'>';
    while ($token = $$pars[-1]->get_token) {
      if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
        $result.=$token->[1];
      } elsif ($token->[0] eq 'PI') {
        $result.=$token->[2];
      } elsif ($token->[0] eq 'S') {
        $result.=$token->[4];
      } elsif ($token->[0] eq 'E')  {
        $result.=$token->[2];
      }
      if ($result =~ /(.*)$tag(.*)/) {
        &Apache::lonxml::debug('Got a winner with leftovers ::'.$2);
        &Apache::lonxml::debug('Result is :'.$1);
        $result=$1;
        my $redo=$tag.$2;
        &Apache::lonxml::newparser($pars,\$redo);
        last;
      }
    }
    return $result
   }
   
   sub get_all_text {
  my($tag,$pars)= @_;   my($tag,$pars)= @_;
  my $depth=0;   my $depth=0;
  my $token;   my $token;
Line 1233  ENDNOTFOUND Line 1263  ENDNOTFOUND
 #  #
   unless ($ENV{'request.state'} eq 'published') {    unless ($ENV{'request.state'} eq 'published') {
     if ($ENV{'form.editmode'} && (!($ENV{'form.viewmode'}))) {      if ($ENV{'form.editmode'} && (!($ENV{'form.viewmode'}))) {
       $result='<html><body bgcolor="#FFFFFF"></body></html>';   my $displayfile=$request->uri;
           $displayfile=~s/^\/[^\/]*//;
         $result='<html><body bgcolor="#FFFFFF"><h3>'.$displayfile.
                 '</h3></body></html>';
       $result=&inserteditinfo($result,$filecontents);        $result=&inserteditinfo($result,$filecontents);
     }      }
   }    }
Line 1248  ENDNOTFOUND Line 1281  ENDNOTFOUND
 sub debug {  sub debug {
   if ($Apache::lonxml::debug eq 1) {    if ($Apache::lonxml::debug eq 1) {
     $|=1;      $|=1;
     print("DEBUG:".join('<br />',@_)."<br />\n");      print("DEBUG:".&HTML::Entities::encode($_[0])."<br />\n");
   }    }
 }  }
   

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


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