root/mt-ban-ascii/trunk/mt-ban-ascii.pl

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

added author link and more changelog

  • Property svn:keywords set to Id Revision
Line 
1 package MT::Plugin::BanASCII;
2 # $Id$
3 # mt-ban-ascii.pl
4 # - Junk or moderate ASCII or Latin-1 comment using MT3 JunkFilter API
5 #
6 # It requires Perl 5.8 or over.
7 #
8 # Author:  Tatsuhiko Miyagawa <miyagawa at bulknews.net>
9 # License: same as Perl
10 #
11
12 use strict;
13 our $VERSION = "0.92";
14
15 # 'deny' or 'moderate'
16 our $Method = "junk";
17
18 use MT;
19 use MT::JunkFilter qw(ABSTAIN);
20
21 use base qw( MT::Plugin );
22
23 my $plugin = MT::Plugin::BanASCII->new({
24     author_name => 'Tatsuhiko Miyagawa',
25     author_link => 'http://blog.bulknews.net/mt/',
26     name => "BanASCII",
27     version => $VERSION,
28     description => "Junk or moderate ASCII or Latin-1 comment",
29 });
30
31 MT->add_plugin($plugin);
32 MT->register_junk_filter({
33     name => 'BanASCII',
34     plugin => $plugin,
35     code => sub { $plugin->handler(@_) },
36 });
37
38 sub handler {
39     my($plugin, $obj) = @_;
40     require Encode;
41     my $charset = MT::ConfigMgr->instance->PublishCharset;
42     my $text = Encode::decode($charset, $obj->all_text);
43     if ($text =~ /^[\x00-\xff]+$/) {
44         if ($Method eq 'junk') {
45             return (-1, "ASCII or Latin-1 comment");
46         } elsif ($Method eq 'moderate') {
47             $obj->moderate;
48             return (0, "Moderated ASCII or Latin-1 comment");
49         }
50     }
51     return ABSTAIN;
52 }
53
54 1;
Note: See TracBrowser for help on using the browser.