Diff for /loncom/xml/lonxml.pm between versions 1.270 and 1.277

version 1.270, 2003/08/11 20:05:53 version 1.277, 2003/09/15 13:38:19
Line 69  use Safe::Hole(); Line 69  use Safe::Hole();
 use Math::Cephes();  use Math::Cephes();
 use Math::Random();  use Math::Random();
 use Opcode();  use Opcode();
   use POSIX qw(strftime);
   
   
 sub register {  sub register {
Line 174  sub xmlbegin { Line 175  sub xmlbegin {
 }  }
   
 sub xmlend {  sub xmlend {
     my ($discussiononly,$symb)=@_;      return &Apache::lonfeedback::list_discussion().'</html>';
     my $discussion='';  
     if ($ENV{'request.course.id'}) {  
        my $crs='/'.$ENV{'request.course.id'};  
        if ($ENV{'request.course.sec'}) {  
           $crs.='_'.$ENV{'request.course.sec'};  
        }                   
        $crs=~s/\_/\//g;  
        my $seeid=&Apache::lonnet::allowed('rin',$crs);  
        unless ($symb) {  
            $symb=&Apache::lonnet::symbread();  
        }  
        if ($symb) {  
           my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},  
                      $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},  
      $ENV{'course.'.$ENV{'request.course.id'}.'.num'});  
           if ($contrib{'version'}) {  
               unless ($discussiononly) {  
                  $discussion.=  
                   '<address><hr />';  
      }  
               my $idx;  
               for ($idx=1;$idx<=$contrib{'version'};$idx++) {  
  my $hidden=($contrib{'hidden'}=~/\.$idx\./);  
  my $deleted=($contrib{'deleted'}=~/\.$idx\./);  
  unless ((($hidden) && (!$seeid)) || ($deleted)) {  
                  my $message=$contrib{$idx.':message'};  
                  $message=~s/\n/\<br \/\>/g;  
  $message=&Apache::lontexconvert::msgtexconverted($message);  
                  if ($contrib{$idx.':attachmenturl'}) {  
                      my ($fname,$ft)  
                         =($contrib{$idx.':attachmenturl'}=~/\/(\w+)\.(\w+)$/);  
      $message.='<p>Attachment: <a href="'.  
        &Apache::lonnet::tokenwrapper($contrib{$idx.':attachmenturl'}).  
                      '"><tt>'.$fname.'.'.$ft.'</tt></a>';  
                  }  
                  if ($message) {  
                   if ($hidden) {  
       $message='<font color="#888888">'.$message.'</font>';  
                   }  
                   my $screenname=&Apache::loncommon::screenname(  
                                $contrib{$idx.':sendername'},  
        $contrib{$idx.':senderdomain'});  
                   my $plainname=&Apache::loncommon::nickname(  
                                $contrib{$idx.':sendername'},  
        $contrib{$idx.':senderdomain'});  
   
                   my $sender='Anonymous';  
                   if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {  
                       $sender=&Apache::loncommon::aboutmewrapper(  
                                $plainname,  
                                $contrib{$idx.':sendername'},  
                                $contrib{$idx.':senderdomain'}).' ('.  
                               $contrib{$idx.':sendername'}.' at '.  
       $contrib{$idx.':senderdomain'}.')';  
                       if ($contrib{$idx.':anonymous'}) {  
   $sender.=' [anonymous] '.  
                                      $screenname;  
                       }  
                       if ($seeid) {  
   if ($hidden) {  
                              $sender.=' <a href="/adm/feedback?unhide='.  
  $symb.':::'.$idx.'">Make Visible</a>';  
                           } else {  
                              $sender.=' <a href="/adm/feedback?hide='.  
  $symb.':::'.$idx.'">Hide</a>';  
   }                       
                           $sender.=' <a href="/adm/feedback?deldisc='.  
  $symb.':::'.$idx.'">Delete</a>';  
                       }  
                   } else {  
                       if ($screenname) {  
   $sender='<i>'.$screenname.'</i>';  
                       }  
                   }  
   $discussion.='<p><b>'.$sender.'</b> ('.  
                       localtime($contrib{$idx.':timestamp'}).  
                       '):<blockquote>'.$message.  
                       '</blockquote></p>';  
         }  
                }   
               }  
               unless ($discussiononly) {  
                  $discussion.='</address>';  
       }  
           }  
           if ($discussiononly) {  
       $discussion.=(<<ENDDISCUSS);  
 <form action="/adm/feedback" method="post" name="mailform" enctype="multipart/form-data">  
 <input type="submit" name="discuss" value="Post Discussion" />  
 <input type="submit" name="anondiscuss" value="Post Anonymous Discussion" />  
 <input type="hidden" name="symb" value="$symb" />  
 <input type="hidden" name="sendit" value="true" />  
 <br />  
 <font size="1">Note: in anonymous discussion, your name is visible only to  
 course faculty</font><br />  
 <textarea name=comment cols=60 rows=10 wrap=hard></textarea>  
 <p>  
 Attachment (128 KB max size): <input type="file" name="attachment" />  
 </p>  
 </form>  
 ENDDISCUSS  
              $discussion.=&Apache::lonfeedback::generate_preview_button();  
           }  
        }  
     }  
     return $discussion.($discussiononly?'':'</html>');  
 }  }
   
 sub tokeninputfield {  sub tokeninputfield {
Line 477  sub htmlclean { Line 372  sub htmlclean {
 }  }
   
 sub latex_special_symbols {  sub latex_special_symbols {
     my ($current_token,$stack,$parstack,$where)=@_;      my ($string,$where)=@_;
     if ($where eq 'header') {      if ($where eq 'header') {
  $current_token =~ s/(\\|_|\^)/ /g;   $string =~ s/(\\|_|\^)/ /g;
  $current_token =~ s/(\$|%|\#|&|\{|\})/\\$1/g;   $string =~ s/(\$|%|\#|&|\{|\})/\\$1/g;
    $string =~ s/_/ /g;
     } else {      } else {
  $current_token=~s/\\ /\\char92 /g;   $string=~s/\\ /\\char92 /g;
  $current_token=~s/\^/\\char94 /g;   $string=~s/\^/\\char94 /g;
  $current_token=~s/\~/\\char126 /g;   $string=~s/\~/\\char126 /g;
  $current_token=~s/(&[^A-Za-z\#])/\\$1/g;   $string=~s/(&[^A-Za-z\#])/\\$1/g;
  $current_token=~s/([^&])\#/$1\\#/g;   $string=~s/([^&])\#/$1\\#/g;
  $current_token=~s/(\$|_|{|})/\\$1/g;   $string=~s/(\$|_|{|})/\\$1/g;
  $current_token=~s/\\char92 /\\texttt{\\char92}/g;   $string=~s/\\char92 /\\texttt{\\char92}/g;
  $current_token=~s/(>|<)/\$$1\$/g; #more or less   $string=~s/(>|<)/\$$1\$/g; #more or less
  if ($current_token=~m/\d%/) {$current_token =~ s/(\d)%/$1\\%/g;} #percent after digit   if ($string=~m/\d%/) {$string =~ s/(\d)%/$1\\%/g;} #percent after digit
  if ($current_token=~m/\s%/) {$current_token =~ s/(\s)%/$1\\%/g;} #persent after space   if ($string=~m/\s%/) {$string =~ s/(\s)%/$1\\%/g;} #percent after space
  if ($current_token eq '%.') {$current_token = '\%.';} #persent at the end of statement   if ($string eq '%.') {$string = '\%.';} #percent at the end of statement
     }      }
     return $current_token;      return $string;
 }  }
   
 sub inner_xmlparse {  sub inner_xmlparse {
Line 584  sub inner_xmlparse { Line 480  sub inner_xmlparse {
       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') ) {
   #Style file definitions should be correct    #Style file definitions should be correct
   if ($target eq 'tex' && ($Apache::lonxml::usestyle)) {    if ($target eq 'tex' && ($Apache::lonxml::usestyle)) {
       $result=&latex_special_symbols($result,$stack,$parstack);        $result=&latex_special_symbols($result);
   }    }
       }        }
   
Line 1137  sub storefile { Line 1033  sub storefile {
     if (my $fh=Apache::File->new('>'.$file)) {      if (my $fh=Apache::File->new('>'.$file)) {
  print $fh $contents;   print $fh $contents;
         $fh->close();          $fh->close();
           return 1;
     } else {      } else {
       &warning("Unable to save file $file");   &warning("Unable to save file $file");
    return 0;
     }      }
 }  }
   
Line 1160  SIMPLECONTENT Line 1058  SIMPLECONTENT
   return $filecontents;    return $filecontents;
 }  }
   
   sub createnewsty {
     my $filecontents=(<<SIMPLECONTENT);
   <definetag name="">
       <render>
          <web></web>
          <tex></tex>
       </render>
   </definetag>
   SIMPLECONTENT
     return $filecontents;
   }
   
   
 sub inserteditinfo {  sub inserteditinfo {
       my ($result,$filecontents)=@_;        my ($result,$filecontents,$filetype)=@_;
       $filecontents = &HTML::Entities::encode($filecontents);        $filecontents = &HTML::Entities::encode($filecontents);
 #      my $editheader='<a href="#editsection">Edit below</a><hr />';  #      my $editheader='<a href="#editsection">Edit below</a><hr />';
       my $xml_help = Apache::loncommon::helpLatexCheatsheet();        my $xml_help = '';
         if ($filetype eq 'html') {
     $xml_help=Apache::loncommon::helpLatexCheatsheet();
         }
         my $cleanbut = '';
         if ($filetype eq 'html') {
     $cleanbut='<input type="submit" name="attemptclean" 
                          value="Save and then attempt to clean HTML" />';
         }
       my $titledisplay=&display_title();        my $titledisplay=&display_title();
       my $buttons=(<<BUTTONS);        my $buttons=(<<BUTTONS);
 <input type="submit" name="attemptclean"   $cleanbut
        value="Save and then attempt to clean HTML" />  
 <input type="submit" name="savethisfile" value="Save this" />  <input type="submit" name="savethisfile" value="Save this" />
 <input type="submit" name="viewmode" value="View" />  <input type="submit" name="viewmode" value="View" />
 BUTTONS  BUTTONS
Line 1237  sub handler { Line 1154  sub handler {
   
   
     my $file=&Apache::lonnet::filelocation("",$request->uri);      my $file=&Apache::lonnet::filelocation("",$request->uri);
       my $filetype;
       if ($file =~ /\.sty$/) {
    $filetype='sty';
       } else {
    $filetype='html';
       }
 #  #
 # Edit action? Save file.  # Edit action? Save file.
 #  #
     unless ($ENV{'request.state'} eq 'published') {      unless ($ENV{'request.state'} eq 'published') {
  if (($ENV{'form.savethisfile'}) || ($ENV{'form.attemptclean'})) {   if (($ENV{'form.savethisfile'}) || ($ENV{'form.attemptclean'})) {
     &storefile($file,$ENV{'form.filecont'});      if (&storefile($file,$ENV{'form.filecont'})) {
    $request->print("<font COLOR=\"#0000FF\">Updated: ". strftime("%d %b %H:%M:%S",localtime())." </font>");
       } 
  }   }
     }      }
     my %mystyle;      my %mystyle;
Line 1261  sub handler { Line 1186  sub handler {
 ENDNOTFOUND  ENDNOTFOUND
     $filecontents='';      $filecontents='';
  if ($ENV{'request.state'} ne 'published') {   if ($ENV{'request.state'} ne 'published') {
     $filecontents=&createnewhtml();      if ($filetype eq 'sty') {
    $filecontents=&createnewsty();
       } else {
    $filecontents=&createnewhtml();
       }
     $ENV{'form.editmode'}='Edit'; #force edit mode      $ENV{'form.editmode'}='Edit'; #force edit mode
  }   }
     } else {      } else {
Line 1289  ENDNOTFOUND Line 1218  ENDNOTFOUND
     $displayfile=~s/^\/[^\/]*//;      $displayfile=~s/^\/[^\/]*//;
     $result='<html><body bgcolor="#FFFFFF"><h3>'.$displayfile.      $result='<html><body bgcolor="#FFFFFF"><h3>'.$displayfile.
  '</h3></body></html>';   '</h3></body></html>';
     $result=&inserteditinfo($result,$filecontents);      $result=&inserteditinfo($result,$filecontents,$filetype);
  }   }
     }      }
           if ($filetype eq 'html') { writeallows($request->uri); }
     writeallows($request->uri);  
           
   
     $request->print($result);      $request->print($result);

Removed from v.1.270  
changed lines
  Added in v.1.277


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