version 1.2, 2005/05/28 02:18:03
|
version 1.11, 2009/09/09 17:58:37
|
Line 36 use File::Copy;
|
Line 36 use File::Copy;
|
use Apache::Constants qw(:common :http :methods); |
use Apache::Constants qw(:common :http :methods); |
use Apache::loncacc; |
use Apache::loncacc; |
use Apache::loncommon(); |
use Apache::loncommon(); |
|
use Apache::lonhtmlcommon(); |
use Apache::lonlocal; |
use Apache::lonlocal; |
use Apache::lonnet; |
use Apache::lonnet; |
|
use lib '/home/httpd/lib/perl/'; |
|
use LONCAPA; |
|
|
|
|
sub latextrans { |
sub latextrans { |
my $symbolfont=shift; |
my $symbolfont=shift; |
Line 218 sub htmlclean {
|
Line 222 sub htmlclean {
|
} |
} |
# Generate empty tags, remove wrong end tags |
# Generate empty tags, remove wrong end tags |
unless ($blockemptytags) { |
unless ($blockemptytags) { |
$raw=~s/\<(br|hr|img|meta|allow|basefont)([^\>\/]*?)\>/\<$1$2 \/\>/gis; |
$raw=~s/\<(br|hr|img|meta|embed|allow|basefont)([^\>]*?)\>/\<$1$2 \/\>/gis; |
$raw=~s/\<\/(br|hr|img|meta|allow|basefont)\>//gis; |
$raw=~s/\<\/(br|hr|img|meta|embed|allow|basefont)\>//gis; |
|
$raw=~s/\/ \/\>/\/\>/gs; |
unless ($full) { |
unless ($full) { |
$raw=~s/\<[\/]*(body|head|html)\>//gis; |
$raw=~s/\<[\/]*(body|head|html)\>//gis; |
} |
} |
Line 244 sub htmlclean {
|
Line 249 sub htmlclean {
|
|
|
sub phaseone { |
sub phaseone { |
my ($r,$fn,$uname,$udom)=@_; |
my ($r,$fn,$uname,$udom)=@_; |
|
$r->print( |
|
&Apache::lonhtmlcommon::start_pick_box() |
|
.&Apache::lonhtmlcommon::row_title(&mt('Select actions to attempt')) |
|
.'<input type="checkbox" name="linefeed" checked="checked" /> ' |
|
.&mt('Linefeeds, formfeeds, and carriage returns') |
|
.'<br />' |
|
.'<input type="checkbox" name="empty" checked="checked" /> ' |
|
.&mt('Empty tags') |
|
.'<br />' |
|
.'<input type="checkbox" name="lower" checked="checked" /> ' |
|
.&mt('Lower casing') |
|
.'<br />' |
|
.'<input type="checkbox" name="symbol" checked="checked" /> ' |
|
.&mt('Symbol font') |
|
.&Apache::lonhtmlcommon::row_closure(1) |
|
.&Apache::lonhtmlcommon::end_pick_box() |
|
); |
|
|
|
$r->print( |
|
'<input type="hidden" name="phase" value="two" />' |
|
.'<p>' |
|
.'<input type="submit" value="'.&mt('Next').'" />' |
|
.'</p>' |
|
); |
} |
} |
|
|
sub phasetwo { |
sub phasetwo { |
|
# Check original file |
my ($r,$fn,$uname,$udom)=@_; |
my ($r,$fn,$uname,$udom)=@_; |
|
open(IN,'/home/'.$uname.'/public_html/'.$fn); |
|
my $text=''; |
|
while (my $line=<IN>) { |
|
$text.=$line; |
|
} |
|
close(IN); |
|
my $uri='/~'.$uname.$fn; |
|
my $result=&Apache::lonnet::ssi_body($uri, |
|
('grade_target'=>'web', |
|
'return_only_error_and_warning_counts' => 1)); |
|
my ($errorcount,$warningcount)=split(':',$result); |
|
|
|
# Display results for original file |
|
$r->print( |
|
&Apache::lonhtmlcommon::start_pick_box() |
|
.&Apache::lonhtmlcommon::row_title(&mt('Original file')) |
|
.&Apache::lonhtmlcommon::confirm_success( |
|
&mt('[quant,_1,error]',$errorcount), $errorcount) |
|
.'<br />' |
|
.&Apache::lonhtmlcommon::confirm_success( |
|
&mt('[quant,_1,warning]',$warningcount), $warningcount) |
|
.&Apache::lonhtmlcommon::row_closure() |
|
); |
|
|
|
# Clean up file |
|
$text=&htmlclean($text,1, |
|
($env{'form.linefeed'} ne 'on'), |
|
($env{'form.empty'} ne 'on'), |
|
($env{'form.lower'} ne 'on'), |
|
($env{'form.symbol'} ne 'on')); |
|
my ($main,$ext)=($fn=~/^(.*)\.(\w+)/); |
|
my $newfn=$main.'_Auto_Cleaned_Up.'.$ext; |
|
open(OUT,'>/home/'.$uname.'/public_html'.$newfn); |
|
print OUT $text; |
|
close(OUT); |
|
my $newuri='/~'.$uname.$newfn; |
|
$result=&Apache::lonnet::ssi_body($newuri, |
|
('grade_target'=>'web', |
|
'return_only_error_and_warning_counts' => 1)); |
|
($errorcount,$warningcount)=split(':',$result); |
|
|
|
# Display results for cleaned up file |
|
$r->print( |
|
&Apache::lonhtmlcommon::row_title(&mt('Cleaned up file')) |
|
.&Apache::lonhtmlcommon::confirm_success( |
|
&mt('[quant,_1,error]',$errorcount), $errorcount) |
|
.'<br />' |
|
.&Apache::lonhtmlcommon::confirm_success( |
|
&mt('[quant,_1,warning]',$warningcount), $warningcount) |
|
.&Apache::lonhtmlcommon::row_closure() |
|
); |
|
|
|
# Display actions |
|
$r->print( |
|
&Apache::lonhtmlcommon::row_title(&mt('Actions')) |
|
.'<ul>' |
|
.'<li><a href="'.$newuri.'" target="prev">' |
|
.&mt('Open (and edit) cleaned up file in new window') |
|
.'</a></li>' |
|
.'<li><a href="/adm/diff?filename='.&escape($uri) |
|
.'&versionone=priv&filetwo='.&escape($newuri).'" target="prev">' |
|
.&mt('Show diffs in new window') |
|
.'</a></li>' |
|
.'</ul>' |
|
.&Apache::lonhtmlcommon::row_closure(1) |
|
.&Apache::lonhtmlcommon::end_pick_box() |
|
.'<p>' |
|
.'<input type="hidden" name="phase" value="three" />' |
|
.'<input type="submit" name="accept" value="' |
|
.&mt('Clean Up').'" />' |
|
.' <input type="submit" name="reject" value="' |
|
.&mt('Cancel').'" />' |
|
.'</p>' |
|
); |
} |
} |
|
|
sub phasethree { |
sub phasethree { |
my ($r,$fn,$uname,$udom)=@_; |
my ($r,$fn,$uname,$udom)=@_; |
|
my $old='/home/'.$uname.'/public_html/'.$fn; |
|
my ($main,$ext)=($fn=~/^(.*)\.(\w+)/); |
|
my $newfn=$main.'_Auto_Cleaned_Up.'.$ext; |
|
my $new='/home/'.$uname.'/public_html'.$newfn; |
|
if ($env{'form.accept'}) { |
|
$r->print( |
|
'<p class="LC_info">' |
|
.&mt('Accepting changes') |
|
.'</p>' |
|
); |
|
move($new,$old); |
|
} else { |
|
$r->print( |
|
'<p class="LC_info">' |
|
.&mt('Rejecting changes') |
|
.'</p>' |
|
); |
|
unlink($new); |
|
} |
} |
} |
|
|
# ---------------------------------------------------------------- Main Handler |
# ---------------------------------------------------------------- Main Handler |
sub handler { |
sub handler { |
|
|
my $r=shift; |
my $r=shift; |
|
my $fn=''; |
|
|
# Get query string for limited number of parameters |
# Get query string for limited number of parameters |
|
|
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, |
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, |
['filename']); |
['filename']); |
|
|
if ($env{'form.filename'}) { |
if ($env{'form.filename'}) { |
$fn=$env{'form.filename'}; |
$fn=$env{'form.filename'}; |
$fn=~s/^http\:\/\/[^\/]+//; |
$fn=~s/^https?\:\/\/[^\/]+//; |
} else { |
} else { |
$r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}. |
$r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}. |
' unspecified filename for cleanup', $r->filename); |
' unspecified filename for cleanup', $r->filename); |
return HTTP_NOT_FOUND; |
return HTTP_NOT_FOUND; |
} |
} |
|
|
unless ($fn) { |
unless ($fn) { |
$r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}. |
$r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}. |
' trying to cleanup non-existing file', $r->filename); |
' trying to cleanup non-existing file', $r->filename); |
return HTTP_NOT_FOUND; |
return HTTP_NOT_FOUND; |
} |
} |
|
|
# ----------------------------------------------------------- Start page output |
# ----------------------------------------------------------- Start page output |
my $uname; |
my $uname; |
my $udom; |
my $udom; |
|
|
|
($uname,$udom)= |
|
&Apache::loncacc::constructaccess($fn,$r->dir_config('lonDefDomain')); |
|
unless (($uname) && ($udom)) { |
|
$r->log_reason($uname.' at '.$udom. |
|
' trying to cleanup file '.$env{'form.filename'}. |
|
' ('.$fn.') - not authorized', |
|
$r->filename); |
|
return HTTP_NOT_ACCEPTABLE; |
|
} |
|
|
|
$fn=~s{/~($LONCAPA::username_re)}{}; |
|
|
|
&Apache::loncommon::content_type($r,'text/html'); |
|
$r->send_http_header; |
|
|
($uname,$udom)= |
# Breadcrumbs |
&Apache::loncacc::constructaccess($fn,$r->dir_config('lonDefDomain')); |
my $brcrum = [{'href' => &Apache::loncommon::authorspace(), |
unless (($uname) && ($udom)) { |
'text' => 'Construction Space'}, |
$r->log_reason($uname.' at '.$udom. |
{'href' => '', |
' trying to cleanup file '.$env{'form.filename'}. |
'text' => 'Cleanup XML Document'}]; |
' ('.$fn.') - not authorized', |
|
$r->filename); |
$r->print(&Apache::loncommon::start_page('Cleanup XML Document', |
return HTTP_NOT_ACCEPTABLE; |
undef, |
} |
{'bread_crumbs' => $brcrum,})); |
|
$r->print('<h2>'.$fn.'</h2>'. |
$fn=~s/\/\~(\w+)//; |
'<form action="/adm/cleanup" method="post">'. |
|
'<input type="hidden" name="filename" value="'.$env{'form.filename'}.'" />'); |
&Apache::loncommon::content_type($r,'text/html'); |
unless ($fn=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm|sty)$/) { |
$r->send_http_header; |
$r->print(&mt('Cannot cleanup this filetype')); |
|
} else { |
$r->print('<html><head><title>LON-CAPA Construction Space</title></head>'); |
if ($env{'form.phase'} eq 'three') { |
|
&phasethree($r,$fn,$uname,$udom); |
$r->print(&Apache::loncommon::bodytag('Cleanup XML Document')); |
} elsif ($env{'form.phase'} eq 'two') { |
|
&phasetwo($r,$fn,$uname,$udom); |
if ($env{'form.phase'} eq 'three') { |
} else { |
&phasethree($r,$fn,$uname,$udom); |
&phaseone($r,$fn,$uname,$udom); |
} elsif ($env{'form.phase'} eq 'two') { |
} |
&phasetwo($r,$fn,$uname,$udom); |
} |
} else { |
my $dir=$fn; |
&phaseone($r,$fn,$uname,$udom); |
$dir=~s/\/[^\/]+$/\//; |
} |
$r->print( |
|
'</form>' |
|
.&Apache::lonhtmlcommon::start_funclist() |
|
.&Apache::lonhtmlcommon::add_item_funclist( |
|
'<a href="/priv/'.$uname.'/'.$fn.'">'.&mt('Back to Source File').'</a>') |
|
.&Apache::lonhtmlcommon::add_item_funclist( |
|
'<a href="/priv/'.$uname.'/'.$dir.'">'.&mt('Back to Source Directory').'</a>') |
|
.&Apache::lonhtmlcommon::end_funclist() |
|
.&Apache::loncommon::end_page() |
|
); |
|
|
$r->print('</body></html>'); |
return OK; |
return OK; |
|
} |
} |
|
|
1; |
1; |