/[mws]/trunk/httpd.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/httpd.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 6 by dpavlin, Wed May 5 13:42:27 2004 UTC revision 13 by dpavlin, Thu May 6 16:53:40 2004 UTC
# Line 15  use MWS; Line 15  use MWS;
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({
# Line 26  my $tt = Template->new({ Line 24  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 ) {
# Line 69  while ( my $c = $d->accept ) { Line 69  while ( my $c = $d->accept ) {
69                  # XXX LOG                  # XXX LOG
70                  print $r->method," ",$url,Dumper($param);                  print $r->method," ",$url,Dumper($param);
71    
72                  # generate HTML                  # template file name (use ?format=html as default)
73                    my $tpl_file = 'master.';
74                    $tpl_file .= $param->{'format'} || 'html';
75    
76                    #
77                    # implement functionality and generate HTML
78                    #
79                  my $html;                  my $html;
80    
81                  my $s=$param->{'search'};                  if ($param->{'search_val'} && $param->{'search_fld'} && !$param->{'search'}) {
82                            $param->{'search'} = $param->{'search_fld'}.":".$param->{'search_val'};
83                    }
84    
85                  if ($s) {                  my $tpl_var = {
86                            param   => $param
87                    };
88    
89                          print STDERR "search: $s\n";                  # show search results
90                    # ?search=foo:bar
91                    if ($param->{'search'}) {
92    
93                          my $results = $mws->search($s);                          print STDERR "search: ",$param->{'search'},"\n";
94    
95                            my $results = $mws->search($param->{'search'});
96                          my @res = $mws->fetch_all_results();                          my @res = $mws->fetch_all_results();
97    
98                          my $tpl_file = 'master.';                          $tpl_var->{results} = \@res;
                         $tpl_file .= $param->{'format'} || 'html';  
99    
100                          $tt->process($tpl_file, {  
101                                  query   => $s,                  #
102                                  results => \@res,                  # ?show_id=XXXXxxxx___message_id___xxxxXXXX
103                                  param   => $param,                  } elsif ($param->{'show_id'}) {
104                          }, \$html) || die $tt->error();                          
105                            my $row = $mws->fetch_result_by_id($param->{'show_id'});
106                            $tpl_var->{message} = $row;
107                  }                  }
108    
109                    $tt->process($tpl_file, $tpl_var, \$html) || die $tt->error();
110    
111                    #
112                    # 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    
# Line 104  while ( my $c = $d->accept ) { Line 124  while ( my $c = $d->accept ) {
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]+){5}.*$/$1/s;          $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&lt;--[cut]--8&lt;--</span>,s;
135            $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    

Legend:
Removed from v.6  
changed lines
  Added in v.13

  ViewVC Help
Powered by ViewVC 1.1.26