69 |
$self->{est} = new WebPAC::Search::Estraier( %{ $est_cfg } ); |
$self->{est} = new WebPAC::Search::Estraier( %{ $est_cfg } ); |
70 |
|
|
71 |
# save config parametars in object |
# save config parametars in object |
72 |
foreach my $f (qw/db_path template_path hits_on_page/) { |
foreach my $f (qw/db_path template_path hits_on_page webpac_encoding out_encoding/) { |
73 |
$self->{$f} = $c->config->{hyperestraier}->{$f} || |
$self->{$f} = $c->config->{hyperestraier}->{$f} || |
74 |
$c->config->{webpac}->{$f}; |
$c->config->{webpac}->{$f}; |
75 |
$log->debug("self->{$f} = " . $self->{$f}); |
$log->debug("self->{$f} = " . $self->{$f}); |
109 |
|
|
110 |
} |
} |
111 |
|
|
|
=head2 iconv_on_save |
|
|
|
|
|
my $out = $m->iconv_on_save( $content ); |
|
|
|
|
|
Convert data saved to disk in Webpac encoding. |
|
|
|
|
|
=cut |
|
|
|
|
|
sub iconv_on_save { |
|
|
my $self = shift; |
|
|
my $content = shift || return; |
|
|
|
|
|
$self->{iconv_save} ||= new Text::Iconv( |
|
|
$self->config->{webpac}->{out_encoding}, |
|
|
$self->config->{webpac}->{webpac_encoding}, |
|
|
); |
|
|
|
|
|
return $self->{iconv_save}->convert( $content ); |
|
|
} |
|
|
|
|
112 |
|
|
113 |
=head2 search |
=head2 search |
114 |
|
|
257 |
|
|
258 |
$m->save_html( '/full/path/to/file', $content ); |
$m->save_html( '/full/path/to/file', $content ); |
259 |
|
|
260 |
It will use C<iconv_on_save> to convert content encoding back to |
It will use C<Text::Iconv> to convert content encoding back to |
261 |
Webpac codepage, recode JavaScript Unicode entities (%u1234), |
Webpac codepage, recode JavaScript Unicode entities (%u1234), |
262 |
strip extra newlines at beginning and end, and save to |
strip extra newlines at beginning and end, and save to |
263 |
C</full/path/to/file.new> and if that succeeds, just rename |
C</full/path/to/file.new> and if that succeeds, just rename |
276 |
$content =~ s/^[\n\r]+//s; |
$content =~ s/^[\n\r]+//s; |
277 |
$content =~ s/[\n\r]+$/\n/s; |
$content =~ s/[\n\r]+$/\n/s; |
278 |
|
|
279 |
my $iconv_on_save = new Text::Iconv( |
my ($from, $to) = ( |
280 |
$self->config->{webpac}->{out_encoding}, |
$self->{out_encoding}, |
281 |
$self->config->{webpac}->{webpac_encoding}, |
$self->{webpac_encoding}, |
282 |
); |
); |
|
$self->{log}->debug( "content BEFORE : $content" ); |
|
|
no utf8; |
|
|
$content = $iconv_on_save->convert( $content ) || die "no content?"; |
|
283 |
|
|
284 |
$self->{log}->debug( "content AFTER: $content" ); |
$self->{log}->debug("using iconv to convert from $from to $to encoding"); |
285 |
|
|
286 |
|
my $iconv_on_save = new Text::Iconv($from, $to) |
287 |
|
|| $self->{log}->fatal("can't create iconv for saving"); |
288 |
|
|
289 |
|
$content = $iconv_on_save->convert( $content ) || die "no content?"; |
290 |
|
|
291 |
write_file($path . '.new', $content) || die "can't save ${path}.new $!"; |
write_file($path . '.new', {binmode => ':raw' }, $content) || die "can't save ${path}.new $!"; |
292 |
rename $path . '.new', $path || die "can't rename to $path: $!"; |
rename $path . '.new', $path || die "can't rename to $path: $!"; |
293 |
} |
} |
294 |
|
|
307 |
|
|
308 |
die "no path?" unless ($path); |
die "no path?" unless ($path); |
309 |
|
|
310 |
my $content = read_file($path) || die "can't read $path: $!"; |
my $content = read_file($path, {binmode => ':raw' }) || die "can't read $path: $!"; |
311 |
#$content = $q->escapeHTML($iconv_utf8->convert($content)); |
#$content = $q->escapeHTML($iconv_utf8->convert($content)); |
312 |
$content = $self->{iconv}->convert($content); |
$content = $self->{iconv}->convert($content); |
313 |
|
|