X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=web%2Fbrowse.cgi;h=916d946ac31fe5fee3a00648f045e762198e2e13;hb=d4fc673006523d2a972a74943f880fcd47c658dd;hp=54b32836b71809bad527e8e7ef2366cb32da1ba5;hpb=088ced45eeedf8f61cf17396010d4ea9b7d2a6c8;p=webpac2
diff --git a/web/browse.cgi b/web/browse.cgi
index 54b3283..916d946 100755
--- a/web/browse.cgi
+++ b/web/browse.cgi
@@ -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,11 @@ my $abs_path = abs_path($0);
$abs_path =~ s#/[^/]*$#/../#;
my $db_path = $abs_path . '/db/';
-my $template = 'html_ffzg.tt';
+my $template_file = 'html_ffzg.tt';
+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,
@@ -32,7 +40,39 @@ my $self = $q->url( '-path_info'=>1, '-query'=>0, '-full'=>0 );
my $rec = $q->param('rec') || 1;
-print $q->header;
+print $q->header( -charset => 'utf-8' );
+
+##---- some handy subs
+
+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#) {
@@ -41,20 +81,19 @@ if ($q->path_info =~ m#xml#) {
if (@ds && $#ds > 0) {
print qq{