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

Revision 410 (checked in by miyagawa, 15 years ago)

oops

Line 
1 package Plagger::Plugin::Filter::Profanity;
2 use strict;
3 use base qw( Plagger::Plugin::Filter::Base );
4
5 use Regexp::Common qw(profanity_us);
6
7 our $RE = $RE{profanity}{us}{normal}{label}{-keep}{-dist=>3};
8 our @Bogus = ('!','@','$','*','%','#','~','=');
9
10 sub filter {
11     my($self, $body) = @_;
12     my $count = $body =~ s/$RE/bogus_string(length($1))/eg;
13     return ($count, $body);
14 }
15
16 sub bogus_string {
17     my $len = shift;
18     return join '', map $Bogus[$_ % $#Bogus], 0..$len-1;
19 }
20
21 1;
22
23 __END__
24
25 =head1 NAME
26
27 Plagger::Plugin::Filter::Profanity - Profanity filter for entry body
28
29 =head1 SYNOPSIS
30
31   - module: Filter::Profanity
32     config:
33       text_only: 1
34
35 =head1 DESCRIPTION
36
37 This plugin filters bad English terms into something like I<!@$~>
38 using Regexp::Common::profanity_us.
39
40 =head1 CONFIG
41
42 =over 4
43
44 =item text_only
45
46 When set to 1, uses HTML::Parser to avoid replacing bad terms inside
47 HTML tags.
48
49 =back
50
51 =head1 AUTHOR
52
53 Tatsuhiko Miyagawa
54
55 =head1 SEE ALSO
56
57 L<Plagger>, L<Regexp::Common::profanity_us>
58
59 =cut
Note: See TracBrowser for help on using the browser.