68 |
|
|
69 |
$self->{est} = new WebPAC::Search::Estraier( %{ $est_cfg } ); |
$self->{est} = new WebPAC::Search::Estraier( %{ $est_cfg } ); |
70 |
|
|
71 |
my $db_path = $c->config->{webpac}->{db_path}; |
# save config parametars in object |
72 |
my $template_path = $c->config->{webpac}->{template_path}; |
foreach my $f (qw/db_path template_path hits_on_page/) { |
73 |
$self->{template_path} = $template_path; |
$self->{$f} = $c->config->{hyperestraier}->{$f} || |
74 |
|
$c->config->{webpac}->{$f}; |
75 |
|
$log->debug("self->{$f} = " . $self->{$f}); |
76 |
|
} |
77 |
|
my $db_path = $self->{db_path}; |
78 |
|
my $template_path = $self->{template_path}; |
79 |
|
|
80 |
$log->debug("using db path '$db_path', template path '$template_path'"); |
$log->debug("using db path '$db_path', template path '$template_path'"); |
81 |
|
|
104 |
"'" |
"'" |
105 |
); |
); |
106 |
|
|
|
# save config parametars in object |
|
|
foreach my $f (qw/hits_on_page/) { |
|
|
$self->{$f} = $c->config->{hyperestraier}->{$f}; |
|
|
$log->debug("self->{$f} = " . $self->{$f}); |
|
|
} |
|
107 |
|
|
108 |
return $self; |
return $self; |
109 |
|
|
119 |
|
|
120 |
sub iconv_on_save { |
sub iconv_on_save { |
121 |
my $self = shift; |
my $self = shift; |
122 |
|
my $content = shift || return; |
123 |
|
|
124 |
$self->{iconv_save} ||= new Text::Iconv( |
$self->{iconv_save} ||= new Text::Iconv( |
125 |
$self->config->{webpac}->{out_encoding}, |
$self->config->{webpac}->{out_encoding}, |
126 |
$self->config->{webpac}->{webpac_encoding}, |
$self->config->{webpac}->{webpac_encoding}, |
127 |
); |
); |
128 |
|
|
129 |
$self->{iconv_save}->convert( @_ ); |
return $self->{iconv_save}->convert( $content ); |
130 |
} |
} |
131 |
|
|
132 |
|
|
236 |
return \@html_results; |
return \@html_results; |
237 |
} |
} |
238 |
|
|
239 |
|
=head2 record |
240 |
|
|
241 |
|
my $html = $m->record( |
242 |
|
mfn => 42, |
243 |
|
template => 'foo.tt', |
244 |
|
); |
245 |
|
|
246 |
|
This will load one record, convert it to html using C<template> and return |
247 |
|
it. |
248 |
|
|
249 |
|
=cut |
250 |
|
|
251 |
|
sub record { |
252 |
|
my $self = shift; |
253 |
|
|
254 |
|
my $args = {@_}; |
255 |
|
my $log = $self->{log}; |
256 |
|
$log->debug("args: " . Dumper( $args )); |
257 |
|
|
258 |
|
foreach my $f (qw/mfn template/) { |
259 |
|
$log->die("need $f") unless ($args->{$f}); |
260 |
|
} |
261 |
|
|
262 |
|
my $mfn = $args->{mfn}; |
263 |
|
|
264 |
|
my $ds = $self->{db}->load_ds( $mfn ) || $log->error("can't load_ds( $mfn )") && next; |
265 |
|
|
266 |
|
my $html = $self->{out}->apply( |
267 |
|
template => $args->{template}, |
268 |
|
data => $ds, |
269 |
|
); |
270 |
|
|
271 |
|
$html = $self->{iconv}->convert( $html ) || $log->error("can't convert: $html"); |
272 |
|
|
273 |
|
return $html; |
274 |
|
} |
275 |
|
|
276 |
=head2 save_html |
=head2 save_html |
277 |
|
|
278 |
$m->save_html( '/full/path/to/file', $content ); |
$m->save_html( '/full/path/to/file', $content ); |
288 |
sub save_html { |
sub save_html { |
289 |
my ($self, $path, $content) = @_; |
my ($self, $path, $content) = @_; |
290 |
|
|
|
$content = $self->iconv_on_save( $content ) || die "no content?"; |
|
|
|
|
291 |
sub _conv_js { |
sub _conv_js { |
292 |
my $t = shift || return; |
my $t = shift || return; |
293 |
return $self->{iconv}->convert(chr(hex($t))); |
return $self->{iconv}->convert(chr(hex($t))); |
296 |
$content =~ s/^[\n\r]+//s; |
$content =~ s/^[\n\r]+//s; |
297 |
$content =~ s/[\n\r]+$/\n/s; |
$content =~ s/[\n\r]+$/\n/s; |
298 |
|
|
299 |
|
my $iconv_on_save = new Text::Iconv( |
300 |
|
$self->config->{webpac}->{out_encoding}, |
301 |
|
$self->config->{webpac}->{webpac_encoding}, |
302 |
|
); |
303 |
|
$self->{log}->debug( "content BEFORE : $content" ); |
304 |
|
no utf8; |
305 |
|
$content = $iconv_on_save->convert( $content ) || die "no content?"; |
306 |
|
|
307 |
|
$self->{log}->debug( "content AFTER: $content" ); |
308 |
|
|
309 |
write_file($path . '.new', $content) || die "can't save ${path}.new $!"; |
write_file($path . '.new', $content) || die "can't save ${path}.new $!"; |
310 |
rename $path . '.new', $path || die "can't rename to $path: $!"; |
rename $path . '.new', $path || die "can't rename to $path: $!"; |
311 |
} |
} |