--- loncom/publisher/loncleanup.pm 2005/05/28 18:53:50 1.3
+++ loncom/publisher/loncleanup.pm 2011/11/14 00:20:31 1.16
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to cleanup XML files
#
-# $Id: loncleanup.pm,v 1.3 2005/05/28 18:53:50 albertel Exp $
+# $Id: loncleanup.pm,v 1.16 2011/11/14 00:20:31 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -36,8 +36,12 @@ use File::Copy;
use Apache::Constants qw(:common :http :methods);
use Apache::loncacc;
use Apache::loncommon();
+use Apache::lonhtmlcommon();
use Apache::lonlocal;
use Apache::lonnet;
+use lib '/home/httpd/lib/perl/';
+use LONCAPA;
+
sub latextrans {
my $symbolfont=shift;
@@ -218,8 +222,9 @@ sub htmlclean {
}
# Generate empty tags, remove wrong end tags
unless ($blockemptytags) {
- $raw=~s/\<(br|hr|img|meta|allow|basefont)([^\>\/]*?)\>/\<$1$2 \/\>/gis;
- $raw=~s/\<\/(br|hr|img|meta|allow|basefont)\>//gis;
+ $raw=~s/\<(br|hr|img|meta|embed|allow|basefont)([^\>]*?)\>/\<$1$2 \/\>/gis;
+ $raw=~s/\<\/(br|hr|img|meta|embed|allow|basefont)\>//gis;
+ $raw=~s/\/ \/\>/\/\>/gs;
unless ($full) {
$raw=~s/\<[\/]*(body|head|html)\>//gis;
}
@@ -244,21 +249,142 @@ sub htmlclean {
sub phaseone {
my ($r,$fn,$uname,$udom)=@_;
+ $r->print(
+ &Apache::lonhtmlcommon::start_pick_box()
+ .&Apache::lonhtmlcommon::row_title(&mt('Select actions to attempt'))
+ .' '
+ .&mt('Linefeeds, formfeeds, and carriage returns')
+ .'
'
+ .' '
+ .&mt('Empty tags')
+ .'
'
+ .' '
+ .&mt('Lower casing')
+ .'
'
+ .' '
+ .&mt('Symbol font')
+ .&Apache::lonhtmlcommon::row_closure(1)
+ .&Apache::lonhtmlcommon::end_pick_box()
+ );
+
+ $r->print(
+ ''
+ .'
' + .'' + .'
' + ); } sub phasetwo { + # Check original file my ($r,$fn,$uname,$udom)=@_; + my $text=''; + my $londocroot = $r->dir_config('lonDocRoot'); + if (open(IN,"<$londocroot/priv/$udom/$uname".$fn)) { + while (my $line=' + .'' + .'' + .' ' + .'
' + ); } sub phasethree { my ($r,$fn,$uname,$udom)=@_; + my $old=$r->dir_config('lonDocRoot')."/priv/$udom/$uname".$fn; + my ($main,$ext)=($fn=~/^(.*)\.(\w+)/); + my $newfn=$main.'_Auto_Cleaned_Up.'.$ext; + my $new=$r->dir_config('lonDocRoot')."/priv/$udom/$uname".$newfn; + if ($env{'form.accept'}) { + $r->print( + '' + .&mt('Accepting changes') + .'
' + ); + move($new,$old); + } else { + $r->print( + '' + .&mt('Rejecting changes') + .'
' + ); + unlink($new); + } } # ---------------------------------------------------------------- Main Handler sub handler { my $r=shift; - + my $fn=''; # Get query string for limited number of parameters @@ -267,7 +393,7 @@ sub handler { if ($env{'form.filename'}) { $fn=$env{'form.filename'}; - $fn=~s/^http\:\/\/[^\/]+//; + $fn=~s{^https?\://[^/]+}{}; } else { $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}. ' unspecified filename for cleanup', $r->filename); @@ -284,8 +410,7 @@ sub handler { my $uname; my $udom; - ($uname,$udom)= - &Apache::loncacc::constructaccess($fn,$r->dir_config('lonDefDomain')); + ($uname,$udom)=&Apache::loncacc::constructaccess($fn); unless (($uname) && ($udom)) { $r->log_reason($uname.' at '.$udom. ' trying to cleanup file '.$env{'form.filename'}. @@ -294,24 +419,47 @@ sub handler { return HTTP_NOT_ACCEPTABLE; } - $fn=~s/\/\~(\w+)//; - &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; - $r->print('