--- trunk/web/browse.cgi 2005/11/14 16:15:27 49
+++ trunk/web/browse.cgi 2005/11/20 20:44:15 77
@@ -1,9 +1,13 @@
#!/usr/bin/perl -w
+use strict;
+
use Cwd qw/abs_path/;
use CGI::Carp qw(fatalsToBrowser);
use CGI::Simple;
use File::Slurp;
+use Data::Dumper;
+use Text::Iconv;
use lib '../lib';
@@ -14,7 +18,13 @@
$abs_path =~ s#/[^/]*$#/../#;
my $db_path = $abs_path . '/db/';
-my $template = 'html_ffzg.tt';
+my $template_path = "$abs_path/conf/output/tt";
+opendir(my $dir, $template_path) || die "can't open template path $template_path: $!";
+my @templates = grep { /\.tt$/i } readdir($dir);
+my $css_file = 'user.css';
+
+my $iconv_utf8 = new Text::Iconv('ISO-8859-2', 'UTF-8');
+my $iconv_loc = new Text::Iconv('UTF-8', 'ISO-8859-2');
my $db = new WebPAC::DB(
path => $db_path,
@@ -23,7 +33,7 @@
);
my $out = new WebPAC::Output::TT(
- include_path => "$abs_path/conf/output/tt",
+ include_path => $template_path,
filters => { foo => sub { shift } },
);
@@ -31,30 +41,62 @@
my $self = $q->url( '-path_info'=>1, '-query'=>0, '-full'=>0 );
my $rec = $q->param('rec') || 1;
+my $template_filename = $q->param('template') || $templates[0];
+
+print $q->header( -charset => 'utf-8' );
+
+##---- some handy subs
-print $q->header;
+sub update_file($$) {
+ my ($path, $content) = @_;
+
+ $content = $iconv_loc->convert( $content ) || die "no content?";
+
+ sub _conv_js {
+ my $t = shift || return;
+ return $iconv_loc->convert(chr(hex($t)));
+ }
+ $content =~ s/%u([a-fA-F0-9]{4})/_conv_js($1)/gex;
+ $content =~ s/^[\n\r]+//s;
+ $content =~ s/[\n\r]+$//s;
+
+ write_file($path . '.new', $content) || die "can't save ${path}.new $!";
+ rename $path . '.new', $path || die "can't rename to $path: $!";
+}
+
+sub get_file_in_html($) {
+ my ($path) = @_;
+
+ die "no path?" unless ($path);
+
+ my $content = read_file($path) || die "can't read $path: $!";
+ $content = $q->escapeHTML($iconv_utf8->convert($content));
+
+ return $content;
+}
+
+##----
if ($q->path_info =~ m#xml#) {
- my @ds = $db->load_ds($rec);
+ my $ds = $db->load_ds($rec);
- if (@ds && $#ds > 0) {
+ if ($ds) {
print qq{