/[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 27 by dpavlin, Sat May 8 20:34:26 2004 UTC revision 30 by dpavlin, Sun May 9 00:09:32 2004 UTC
# Line 35  my $tt = Template->new({ Line 35  my $tt = Template->new({
35          INCLUDE_PATH => $mws->{config}->val('global', 'templates'),          INCLUDE_PATH => $mws->{config}->val('global', 'templates'),
36          FILTERS => {          FILTERS => {
37                  'body5' => \&body5_filter,                  'body5' => \&body5_filter,
38                    'body' => \&body_filter,
39          },          },
40          EVAL_PERL => 1,          EVAL_PERL => 1,
41  });  });
# Line 84  while ( my $c = $d->accept ) { Line 85  while ( my $c = $d->accept ) {
85                  my $url = $r->url->path;                  my $url = $r->url->path;
86    
87                  # XXX LOG                  # XXX LOG
88                  print $r->method," ",$url,"\n",Dumper($param),"\n" if ($debug);                  print $r->method," ",$url,"\n";
89                    print Dumper($param),"\n" if ($debug);
90    
91                  # is this static page?                  # is this static page?
92                  if ($static_html && -f "$static_html/$url") {                  if ($static_html && -f "$static_html/$url") {
# Line 138  while ( my $c = $d->accept ) { Line 140  while ( my $c = $d->accept ) {
140                  if ($url eq "/" && !$param->{'search'}) {                  if ($url eq "/" && !$param->{'search'}) {
141                          # if first access, go to current year                          # if first access, go to current year
142                          $date_limit = $mws->fmtdate($yyyy);                          $date_limit = $mws->fmtdate($yyyy);
143                          $param->{sort} = "date desc";                          $param->{sort_by} = "date desc";
144                  }                  }
145    
146                  # ?show_id=XXXXxxxx___message_id___xxxxXXXX                  # ?show_id=XXXXxxxx___message_id___xxxxXXXX
# Line 172  while ( my $c = $d->accept ) { Line 174  while ( my $c = $d->accept ) {
174                          $tpl_var->{results} = \@res if (@res);                          $tpl_var->{results} = \@res if (@res);
175                          $tpl_var->{total_hits} = $mws->{total_hits} || 0;                          $tpl_var->{total_hits} = $mws->{total_hits} || 0;
176    
177                            # no hits, offer suggestions
178                            if (! $tpl_var->{results}) {
179                                    @{$tpl_var->{apropos}} = $mws->apropos_index($param->{'search_fld'}, $param->{'search_val'});
180                            }
181    
182                  }                  }
183    
184    
# Line 206  while ( my $c = $d->accept ) { Line 213  while ( my $c = $d->accept ) {
213    
214  # template toolkit filter  # template toolkit filter
215    
216    sub html_escape($) {
217            my $text = shift || return;
218    
219            # don't re-escape html
220            #return $text if ($text =~ /&(:?lt|gt|amp|quot);/);
221    
222            # Escape <, >, & and ", and to produce valid XML
223            my %escape = ('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;');
224            my $escape_re  = join '|' => keys %escape;
225    
226            $text =~ s/($escape_re)/$escape{$1}/gs;
227            return $text;
228    }
229    
230  #use Text::Context::EitherSide;  #use Text::Context::EitherSide;
231    
232  sub body5_filter {  sub body5_filter {
233          my $text = shift;          my $text = shift;
234          $text =~ s/^\s+//gs;  
235          $text =~ s/^[\>:\|=]+\s*.*?$//msg;      # remove quoted text          # remove quote
236          $text =~ s/[\n\r]+/\n/gs;               # compress cr/lf          $text =~ s/^[\>:\|=]+\s*.*?$/#-q-#/msg;
237            # remove quote author
238            $text =~ s/[\n\r]+[^\n\r]+:\s*(:?#-q-#[\n\r*])+//gs;
239            $text =~ s/^[^\n\r]+:\s*(:?#-q-#[\n\r]*)+//gs;
240            $text =~ s/#-q-#[\n\r]*//gs;
241            # outlook quoting
242            $text =~ s/(\s*--+\s*Original\s+Message\s*--+.*)$//si;
243            $text =~ s/(\s*--+\s*Forwarded\s+message\s*from\s+.+\s*--+.*)$//si;
244    
245            # remove signature
246            $text =~ s/[\n\r]+--\s*[\n\r]+.*$//s;
247    
248            # compress cr/lf
249            $text =~ s/[\n\r]+/\n/gs;
250    
251            # remove whitespaces
252            $text =~ s/^\n+//gs;
253            $text =~ s/[\s\n]+$//gs;
254    
255            # cut to 5 lines;
256          if ($text =~ s,^((?:.*?[\n\r]){5}).*$,$1,s) {          if ($text =~ s,^((?:.*?[\n\r]){5}).*$,$1,s) {
257                  $text =~ s/[\n\r]*$/ .../;                  $text =~ s/[\n\r]*$/ .../;
258          }          }
         $text =~ s/[\n\r]+--\s*[\n\r]+.*$//s;  
259    
260  #       my $context = Text::Context::EitherSide->new($text, context => 5);  #       my $context = Text::Context::EitherSide->new($text, context => 5);
261  #       return $context->as_string("perl");  #       return $context->as_string("perl");
262    
263            return html_escape($text);
264    }
265    
266    sub body_filter {
267            my $text = shift;
268    
269            my $sig = '';
270    
271            # remove signature
272            if ($text =~ s/([\n\r]+)(--\s*[\n\r]+.*)$//s) {
273                    $sig = "$1#-#signature##$2##signature#-#";
274            }
275    
276            # find quoted text
277            $text =~ s/^([\>:\|=]+\s*.*?)$/#-#quote1##$1##quote1#-#/msg;
278            $text =~ s/(--+\s*Original\s+Message\s*--+.*)$/#-#quote2##$1##quote2#-#/si;
279            $text =~ s/(--+\s*Forwarded\s+message\s*from\s+.+\s*--+.*)$/#-#quote3##$1##quote3#-#/si;
280    
281            $text = html_escape($text . $sig);
282            while ($text =~ s/#-#(quote|signature)(\d*)##(.+?)##\1\2#-#/<span class="$1">$3<\/span>/gs) { } ;
283          return $text;          return $text;
284  }  }
285    

Legend:
Removed from v.27  
changed lines
  Added in v.30

  ViewVC Help
Powered by ViewVC 1.1.26