15 |
use Data::Dumper; |
use Data::Dumper; |
16 |
|
|
17 |
my $d = HTTP::Daemon->new( Reuse => 1, LocalPort => 6969 ) || die; |
my $d = HTTP::Daemon->new( Reuse => 1, LocalPort => 6969 ) || die; |
|
print "Please contact me at: <URL:", $d->url, ">\n"; |
|
|
|
|
18 |
my $cgi = new CGI::Lite; |
my $cgi = new CGI::Lite; |
19 |
my $mws = MWS->new('global.conf'); |
my $mws = MWS->new('global.conf'); |
20 |
my $tt = Template->new({ |
my $tt = Template->new({ |
24 |
}, |
}, |
25 |
}); |
}); |
26 |
|
|
27 |
|
print "Web server ready at: ", $d->url, "\n"; |
28 |
|
|
29 |
|
|
30 |
while ( my $c = $d->accept ) { |
while ( my $c = $d->accept ) { |
31 |
while ( my $r = $c->get_request ) { |
while ( my $r = $c->get_request ) { |
78 |
# |
# |
79 |
my $html; |
my $html; |
80 |
|
|
81 |
|
if ($param->{'search_val'} && $param->{'search_fld'} && !$param->{'search'}) { |
82 |
|
$param->{'search'} = $param->{'search_fld'}.":".$param->{'search_val'}; |
83 |
|
} |
84 |
|
|
85 |
|
my $tpl_var = { |
86 |
|
param => $param |
87 |
|
}; |
88 |
|
|
89 |
# show search results |
# show search results |
90 |
# ?search=foo:bar |
# ?search=foo:bar |
91 |
if ($param->{'search'}) { |
if ($param->{'search'}) { |
95 |
my $results = $mws->search($param->{'search'}); |
my $results = $mws->search($param->{'search'}); |
96 |
my @res = $mws->fetch_all_results(); |
my @res = $mws->fetch_all_results(); |
97 |
|
|
98 |
$tt->process($tpl_file, { |
$tpl_var->{results} = \@res; |
99 |
query => $param->{'search'}, |
|
|
results => \@res, |
|
|
param => $param, |
|
|
}, \$html) || die $tt->error(); |
|
100 |
|
|
101 |
# |
# |
102 |
# ?show_id=XXXXxxxx___message_id___xxxxXXXX |
# ?show_id=XXXXxxxx___message_id___xxxxXXXX |
103 |
} elsif ($param->{'show_id'}) { |
} elsif ($param->{'show_id'}) { |
104 |
|
|
105 |
my $row = $mws->fetch_result_by_id($param->{'show_id'}); |
my $row = $mws->fetch_result_by_id($param->{'show_id'}); |
106 |
$tt->process($tpl_file, { |
$tpl_var->{message} = $row; |
|
message => $row, |
|
|
}, \$html) || die $tt->error(); |
|
107 |
} |
} |
108 |
|
|
109 |
|
$tt->process($tpl_file, $tpl_var, \$html) || die $tt->error(); |
110 |
|
|
111 |
# |
# |
112 |
# send HTMLto client |
# send HTMLto client |
113 |
# |
# |
114 |
|
|
115 |
my $res = HTTP::Response->new(RC_OK); |
my $res = HTTP::Response->new(RC_OK); |
116 |
$res->header( 'Content-type' => 'text/html; charset=iso-8859-2' ); |
$res->header( 'Content-type' => 'text/html; charset=UTF-8' ); |
117 |
$res->content($html); |
$res->content($html); |
118 |
$c->send_response($res); |
$c->send_response($res); |
119 |
|
|
124 |
|
|
125 |
# template toolkit filter |
# template toolkit filter |
126 |
|
|
127 |
|
#use Text::Context::EitherSide; |
128 |
|
|
129 |
sub body5_filter { |
sub body5_filter { |
130 |
my $text = shift; |
my $text = shift; |
131 |
$text =~ s/^\s+//gs; |
$text =~ s/^\s+//gs; |
132 |
$text =~ s/[\n\r]+[\>:\|=]+\s*.*?[\n\r]+//sg; # remove quoted text |
$text =~ s/^[\>:\|=]+\s*.*?$//msg; # remove quoted text |
133 |
|
$text =~ s/[\n\r]+/\n/gs; # compress cr/lf |
134 |
$text =~ s,^((?:.*?[\n\r]){5}).*$,$1<span style="color:#808080">--8<--[cut]--8<--</span>,s; |
$text =~ s,^((?:.*?[\n\r]){5}).*$,$1<span style="color:#808080">--8<--[cut]--8<--</span>,s; |
135 |
$text =~ s/[\n\r]+--\s*[\n\r]+.*$//s; |
$text =~ s/[\n\r]+--\s*[\n\r]+.*$//s; |
136 |
|
|
137 |
|
# my $context = Text::Context::EitherSide->new($text, context => 5); |
138 |
|
# return $context->as_string("perl"); |
139 |
|
|
140 |
return $text; |
return $text; |
141 |
} |
} |
142 |
|
|