Changeset 217
- Timestamp:
- 03/01/06 18:26:07
- Files:
-
- trunk/plagger/lib/Plagger/Plugin/Filter/TTP.pm (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/plagger/lib/Plagger/Plugin/Filter/TTP.pm
r185 r217 2 2 use strict; 3 3 use base qw( Plagger::Plugin ); 4 4 5 use URI::Find; 5 6 … … 16 17 my $body = $args->{entry}->body; 17 18 19 my $count; 20 if ($self->conf->{html_paranoia}) { 21 ($count, $body) = $self->paranoia_rewrite($body); 22 } else { 23 ($count, $body) = $self->rewrite_ttp($body); 24 } 25 26 if ($count) { 27 $context->log(info => "Rewrite $count ttp:// link(s) to http://"); 28 } 29 30 $args->{entry}->body($body); 31 } 32 33 sub rewrite_ttp { 34 my($self, $body) = @_; 35 18 36 local @URI::ttp::ISA = qw(URI::http); 19 37 … … 22 40 return ($uri->scheme eq 'ttp') ? qq{<a href="h$orig_uri">$orig_uri</a>} : $orig_uri; 23 41 }); 24 $finder->find(\$body);25 42 26 $args->{entry}->body($body); 43 my $count = $finder->find(\$body); 44 45 ($count, $body); 46 } 47 48 sub paranoia_rewrite { 49 my($self, $body) = @_; 50 require HTML::Parser; 51 52 my($count, $output); 53 54 my $p = HTML::Parser->new(api_version => 3); 55 $p->handler( default => sub { $output .= $_[0] }, "text" ); 56 $p->handler( text => sub { 57 my($c, $body) = $self->rewrite_ttp($_[0]); 58 $count += $c; 59 $output .= $body; 60 }, "text"); 61 62 $p->parse($body); 63 $p->eof; 64 65 ($count, $output); 27 66 } 28 67 … … 44 83 adopted way of linking an URL without leaking a referer. 45 84 85 =head1 CONFIG 86 87 =over 4 88 89 =item html_paranoia 90 91 When set to 1, uses HTML::Parser to avoid replacing C<ttp://> inside 92 HTML elements. Defaults to 0. 93 94 =back 95 46 96 =head1 AUTHOR 47 97 48 98 Matsuno Tokuhiro 49 99 100 Tatsuhiko Miyagawa 101 50 102 =head1 SEE ALSO 51 103 52 L<Plagger> 104 L<Plagger>, L<HTML::Parser> 53 105 54 106 =cut
