Changeset 409
- Timestamp:
- 03/24/06 16:19:33
- Files:
-
- trunk/plagger/Makefile.PL (modified) (2 diffs)
- trunk/plagger/lib/Plagger/Plugin/Filter/TTP.pm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/plagger/Makefile.PL
r408 r409 176 176 recommends('SVN::Client'), 177 177 ], 178 'Filter::TTP' => [ 179 -default => 0, 180 recommends('URI::Find'), 181 ], 178 182 ); 179 183 … … 186 190 ); 187 191 188 install_script('bin/spotlight_comment.scpt');192 install_script('bin/spotlight_comment.scpt'); 189 193 190 194 } elsif ($^O eq 'MSWin32') { trunk/plagger/lib/Plagger/Plugin/Filter/TTP.pm
r244 r409 1 1 package Plagger::Plugin::Filter::TTP; 2 2 use strict; 3 use base qw( Plagger::Plugin );3 use base qw( Plagger::Plugin::Filter::Base ); 4 4 5 5 use URI::Find; 6 use URI::http; 6 7 7 sub register { 8 my($self, $context) = @_; 9 $context->register_hook( 10 $self, 11 'update.entry.fixup' => \&update, 12 ); 13 } 14 15 sub update { 16 my($self, $context, $args) = @_; 17 my $body = $args->{entry}->body; 18 19 my $count; 20 if ($self->conf->{text_only}) { 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 { 8 sub filter { 34 9 my($self, $body) = @_; 35 10 … … 49 24 $finder->find(\$body); 50 25 ($count, $body); 51 }52 53 sub paranoia_rewrite {54 my($self, $body) = @_;55 require HTML::Parser;56 57 my($count, $output);58 59 my $p = HTML::Parser->new(api_version => 3);60 $p->handler( default => sub { $output .= $_[0] }, "text" );61 $p->handler( text => sub {62 my($c, $body) = $self->rewrite_ttp($_[0]);63 $count += $c;64 $output .= $body;65 }, "text");66 67 $p->parse($body);68 $p->eof;69 70 ($count, $output);71 26 } 72 27
