[LON-CAPA-cvs] cvs: loncom /publisher loncleanup.pm lonpubdir.pm

www lon-capa-cvs@mail.lon-capa.org
Sat, 28 May 2005 02:18:07 -0000


www		Fri May 27 22:18:07 2005 EDT

  Modified files:              
    /loncom/publisher	loncleanup.pm lonpubdir.pm 
  Log:
  Work on making cleanup more widely available
  
  
Index: loncom/publisher/loncleanup.pm
diff -u loncom/publisher/loncleanup.pm:1.1 loncom/publisher/loncleanup.pm:1.2
--- loncom/publisher/loncleanup.pm:1.1	Fri May 27 21:32:33 2005
+++ loncom/publisher/loncleanup.pm	Fri May 27 22:18:03 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to cleanup XML files
 #
-# $Id: loncleanup.pm,v 1.1 2005/05/28 01:32:33 www Exp $
+# $Id: loncleanup.pm,v 1.2 2005/05/28 02:18:03 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -208,36 +208,50 @@
 }
 
 sub htmlclean {
-    my ($raw,$full)=@_;
+    my ($raw,$full,$blocklinefeed,$blockemptytags,$blocklowercasing,$blockdesymboling)=@_;
 # Take care of CRLF etc
-
-    $raw=~s/\r\f/\n/gs; $raw=~s/\f\r/\n/gs;
-    $raw=~s/\r\n/\n/gs; $raw=~s/\n\r/\n/gs;
-    $raw=~s/\f/\n/gs; $raw=~s/\r/\n/gs;
-    $raw=~s/\&\#10\;/\n/gs; $raw=~s/\&\#13\;/\n/gs;
-
+    unless ($blocklinefeed) {
+	$raw=~s/\r\f/\n/gs; $raw=~s/\f\r/\n/gs;
+	$raw=~s/\r\n/\n/gs; $raw=~s/\n\r/\n/gs;
+	$raw=~s/\f/\n/gs; $raw=~s/\r/\n/gs;
+	$raw=~s/\&\#10\;/\n/gs; $raw=~s/\&\#13\;/\n/gs;
+    }
 # Generate empty tags, remove wrong end tags
-    $raw=~s/\<(br|hr|img|meta|allow|basefont)([^\>\/]*?)\>/\<$1$2 \/\>/gis;
-    $raw=~s/\<\/(br|hr|img|meta|allow|basefont)\>//gis;
-    unless ($full) {
-       $raw=~s/\<[\/]*(body|head|html)\>//gis;
+    unless ($blockemptytags) {
+	$raw=~s/\<(br|hr|img|meta|allow|basefont)([^\>\/]*?)\>/\<$1$2 \/\>/gis;
+	$raw=~s/\<\/(br|hr|img|meta|allow|basefont)\>//gis;
+	unless ($full) {
+	    $raw=~s/\<[\/]*(body|head|html)\>//gis;
+	}
     }
 # Make standard tags lowercase
-    foreach ('html','body','head','meta','h1','h2','h3','h4','b','i','m',
-             'table','tr','td','th','p','br','hr','img','embed','font',
-             'a','strong','center','title','basefont','li','ol','ul',
-             'input','select','form','option','script','pre') {
-	$raw=~s/\<$_\s*\>/\<$_\>/gis;
-        $raw=~s/\<\/$_\s*\>/<\/$_\>/gis;
-        $raw=~s/\<$_\s([^\>]*)\>/<$_ $1\>/gis;
+    unless ($blocklowercasing) {
+	foreach ('html','body','head','meta','h1','h2','h3','h4','b','i','m',
+		 'table','tr','td','th','p','br','hr','img','embed','font',
+		 'a','strong','center','title','basefont','li','ol','ul',
+		 'input','select','form','option','script','pre') {
+	    $raw=~s/\<$_\s*\>/\<$_\>/gis;
+	    $raw=~s/\<\/$_\s*\>/<\/$_\>/gis;
+	    $raw=~s/\<$_\s([^\>]*)\>/<$_ $1\>/gis;
+	}
+    }
+# Replace <font face="symbol">
+    unless ($blockdesymboling) {
+	$raw=&symbolfontreplace($raw);
     }
     return $raw;
 }
 
 sub phaseone {
+    my ($r,$fn,$uname,$udom)=@_;
 }
 
 sub phasetwo {
+    my ($r,$fn,$uname,$udom)=@_;
+}
+
+sub phasethree {
+    my ($r,$fn,$uname,$udom)=@_;
 }
 
 # ---------------------------------------------------------------- Main Handler
@@ -289,7 +303,9 @@
 
   $r->print(&Apache::loncommon::bodytag('Cleanup XML Document'));
 
-  if ($env{'form.phase'} eq 'two') {
+  if ($env{'form.phase'} eq 'three') {
+      &phasethree($r,$fn,$uname,$udom);
+  } elsif ($env{'form.phase'} eq 'two') {
       &phasetwo($r,$fn,$uname,$udom);
   } else {
       &phaseone($r,$fn,$uname,$udom);
Index: loncom/publisher/lonpubdir.pm
diff -u loncom/publisher/lonpubdir.pm:1.81 loncom/publisher/lonpubdir.pm:1.82
--- loncom/publisher/lonpubdir.pm:1.81	Fri May 20 14:28:22 2005
+++ loncom/publisher/lonpubdir.pm	Fri May 27 22:18:03 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Construction Space Directory Lister
 #
-# $Id: lonpubdir.pm,v 1.81 2005/05/20 18:28:22 www Exp $
+# $Id: lonpubdir.pm,v 1.82 2005/05/28 02:18:03 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -290,6 +290,10 @@
           document.retrieveres.filename.value = theform.filename.value
           document.retrieveres.submit()
       }
+      if (activity == 'cleanup') {
+          document.cleanup.filename.value = theform.filename.value
+          document.cleanup.submit()
+      }
       return
     }
     function changename(theform,activity) {
@@ -404,6 +408,9 @@
        <form name="retrieveres" action="/adm/retrieve" target="_parent" method="post">
            <input type="hidden" name="filename" value="" />
        </form>
+       <form name="cleanup" action="/adm/cleanup" target="_parent" method="post">
+           <input type="hidden" name="filename" value="" />
+       </form>
 END
 }
 
@@ -570,6 +577,10 @@
 	$editlink=' (<a href="'.$linkdir.'/'.$filename.'?forceedit=1" target="_parent">'.&mt('EditXML').'</a>)';
 	$editlink2=' <br />(<a href="'.$linkdir.'/'.$filename.'?forceColoredit=1" target="_parent">'.&mt('Edit').'</a>)';
     }
+    if ($filename=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm|sty)$/) {
+	$editlink.='<a href="/adm/cleanup?filename=/~'.$uname.
+	    $thisdisfn.'/'.$filename.'" target="_parent">'.&mt('Clean Up').'</a>';
+    }
     if ($filename=~/\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
 	$editlink=' (<a target="_parent" href="/adm/cfile?decompress=/~'.
 	      $uname.$thisdisfn.'/'.$filename.'">'.&mt('Decompress').'</a>)';
@@ -615,6 +626,7 @@
     }
     $$pub_select .= '
 <option value="publish">'.$publish_button.'</option>'.
+'<option value="cleanup">'.&mt('Clean up').'</option>'.
 '<option value="print">'.&mt('Print').'</option>'.
 '</select>
 <input type="hidden" name="filename" value="/~'.