root/trunk/plagger/lib/Plagger/Plugin/Filter/TTP.pm

Revision 409 (checked in by miyagawa, 15 years ago)
  • Move Filter::TTP under new Filter::Base
  • Updated Makefile.PL
Line 
1 package Plagger::Plugin::Filter::TTP;
2 use strict;
3 use base qw( Plagger::Plugin::Filter::Base );
4
5 use URI::Find;
6 use URI::http;
7
8 sub filter {
9     my($self, $body) = @_;
10
11     local @URI::ttp::ISA = qw(URI::http);
12
13     my $count = 0;
14     my $finder = URI::Find->new(sub {
15         my ($uri, $orig_uri) = @_;
16         if ($uri->scheme eq 'ttp') {
17             $count++;
18             return qq{<a href="h$orig_uri">$orig_uri</a>};
19         } else {
20             return $orig_uri;
21         }
22     });
23
24     $finder->find(\$body);
25     ($count, $body);
26 }
27
28 1;
29
30 __END__
31
32 =head1 NAME
33
34 Plagger::Plugin::Filter::TTP - Replace ttp:// with http://
35
36 =head1 SYNOPSIS
37
38   - module: Filter::TTP
39
40 =head1 DESCRIPTION
41
42 This plugin replaces C<ttp://> with C<http://>. C<ttp://> is a widely
43 adopted way of linking an URL without leaking a referer.
44
45 =head1 CONFIG
46
47 =over 4
48
49 =item text_only
50
51 When set to 1, uses HTML::Parser to avoid replacing C<ttp://> inside
52 HTML attributes. Defaults to 0.
53
54 =back
55
56 =head1 AUTHOR
57
58 Matsuno Tokuhiro
59
60 Tatsuhiko Miyagawa
61
62 =head1 SEE ALSO
63
64 L<Plagger>, L<HTML::Parser>
65
66 =cut
Note: See TracBrowser for help on using the browser.