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

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

import mt-ban-ascii

  • 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     name => "BanASCII",
25     version => $VERSION,
26     description => "Junk or moderate ASCII or Latin-1 comment",
27 });
28
29 MT->add_plugin($plugin);
30 MT->register_junk_filter({
31     name => 'BanASCII',
32     plugin => $plugin,
33     code => sub { $plugin->handler(@_) },
34 });
35
36 sub handler {
37     my($plugin, $obj) = @_;
38     require Encode;
39     my $charset = MT::ConfigMgr->instance->PublishCharset;
40     my $text = Encode::decode($charset, $obj->all_text);
41     if ($text =~ /^[\x00-\xff]+$/) {
42         if ($Method eq 'junk') {
43             return (-1, "ASCII or Latin-1 comment");
44         } elsif ($Method eq 'moderate') {
45             $obj->moderate;
46             return (0, "Moderated ASCII or Latin-1 comment");
47         }
48     }
49     return ABSTAIN;
50 }
51
52 1;
Note: See TracBrowser for help on using the browser.