4 |
use warnings; |
use warnings; |
5 |
use base 'Catalyst::Controller'; |
use base 'Catalyst::Controller'; |
6 |
|
|
7 |
|
use HTML::Tidy; |
8 |
use Data::Dumper; |
use Data::Dumper; |
9 |
|
|
10 |
=head1 NAME |
=head1 NAME |
66 |
my $template_full_path = "$template_path/$template_filename"; |
my $template_full_path = "$template_path/$template_filename"; |
67 |
|
|
68 |
if ($c->req->params->{save_template}) { |
if ($c->req->params->{save_template}) { |
69 |
|
|
70 |
|
$c->response->content_type('text/html; charset=utf-8'); |
71 |
|
|
72 |
my $t = $c->req->params->{template_content}; |
my $t = $c->req->params->{template_content}; |
73 |
my $size = length($t); |
my $size = length($t); |
74 |
$c->log->debug("saving $template_full_path, $size bytes"); |
$c->log->debug("saving $template_full_path, $size bytes"); |
84 |
|
|
85 |
if (! -r $template_full_path) { |
if (! -r $template_full_path) { |
86 |
$c->log->warn("can't find '$template_full_path': $!"); |
$c->log->warn("can't find '$template_full_path': $!"); |
87 |
|
$c->response->content_type('text/html; charset=utf-8'); |
88 |
$c->res->output("can't find template '$template_full_path'"); |
$c->res->output("can't find template '$template_full_path'"); |
89 |
return; |
return; |
90 |
} |
} |
122 |
my $css_full_path = "$css_path/$css_filename"; |
my $css_full_path = "$css_path/$css_filename"; |
123 |
|
|
124 |
if ($c->req->params->{save_css}) { |
if ($c->req->params->{save_css}) { |
125 |
|
|
126 |
|
$c->response->content_type('text/html; charset=utf-8'); |
127 |
|
|
128 |
my $t = $c->req->params->{css_content}; |
my $t = $c->req->params->{css_content}; |
129 |
my $size = length($t); |
my $size = length($t); |
130 |
$c->log->debug("saving $css_full_path, $size bytes"); |
$c->log->debug("saving $css_full_path, $size bytes"); |
169 |
|
|
170 |
my $webpac = $c->comp('Model::WebPAC'); |
my $webpac = $c->comp('Model::WebPAC'); |
171 |
|
|
172 |
$c->res->output( |
my $html = $webpac->record( mfn => $mfn, template => $template_filename ); |
173 |
$webpac->record( mfn => $mfn, template => $template_filename ) |
|
174 |
); |
if ($html) { |
175 |
|
$c->log->debug('check html with tidy'); |
176 |
|
my $tidy = new HTML::Tidy; |
177 |
|
$tidy->ignore( text => [ |
178 |
|
qr/DOCTYPE/, qr/unsupported/, qr/proprietary/i, |
179 |
|
qr/invalid character code/, |
180 |
|
qr/inserting missing 'title' element/, |
181 |
|
qr/lacks "summary" attribute/, |
182 |
|
] ); |
183 |
|
if ( $tidy->parse('html', $html) ) { |
184 |
|
if ( $tidy->messages ) { |
185 |
|
$html .= '<div class="tidy">HTML Tidy output:'; |
186 |
|
|
187 |
|
my @lines = split(/[\n\r]+/, $html); |
188 |
|
|
189 |
|
# Escape <, >, & and ", and to produce valid XML |
190 |
|
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); |
191 |
|
my $escape_re = join '|' => keys %escape; |
192 |
|
|
193 |
|
|
194 |
|
foreach my $m ( $tidy->messages ) { |
195 |
|
my $c = $lines[ ( $m->line - 2 ) ]; |
196 |
|
my $txt = $m->as_string; |
197 |
|
$c =~ s/($escape_re)/$escape{$1}/g; |
198 |
|
$txt =~ s/($escape_re)/$escape{$1}/g; |
199 |
|
my $class = ''; |
200 |
|
$class = ' class="tidy_'.lc($1).'"' if ($txt =~ /(Warning|Error):/s); |
201 |
|
$html .= "<div${class}>$txt | <tt>$c</tt></div>"; |
202 |
|
} |
203 |
|
$html .= '</div>'; |
204 |
|
} |
205 |
|
} else { |
206 |
|
$html .= qq{<div class="tidy tidy_error">Can't parse this record with HTML Tidy!</div>}; |
207 |
|
} |
208 |
|
} |
209 |
|
|
210 |
|
|
211 |
|
$c->response->content_type('text/html; charset=utf-8'); |
212 |
|
$c->res->output( $html ); |
213 |
} |
} |
214 |
|
|
215 |
|
|