package MT::Plugin::BanNonJapaneseComment; # mt-ban-nonja-com.pl # - Deny or moderate Non Japanese comment using MT3 CommentFilter API # # Author: Yasuhiro Horiuchi # License: same as Perl # use strict; our $VERSION = "0.2"; # 'deny' or 'moderate' our $Method = "deny"; # charcter repetation our $CharRep = 3; # number of match our $NofMatch = 1; use MT; use MT::Plugin; use MT::I18N; my $plugin = MT::Plugin->new({ name => "BanNonJapaneseComment v$VERSION", description => "Deny or moderate Non japanese comment", }); MT->add_plugin($plugin); MT->add_callback('CommentFilter', 2, $plugin, \&handler); sub handler { my($eh, $app, $comment) = @_; my $charset = MT::ConfigMgr->instance->PublishCharset; my $text = MT::I18N::encode_text($comment->text, $charset, 'euc'); my @match = $text =~ /((?:\xA4[\xA1-\xF3]|\xA1[\xAB\xAC\xB5\xB6])|(?:\xA5[\xA1-\xF6]|\xA1[\xA6\xBC\xB3\xB4])){$CharRep,}/g; if ( @match < $NofMatch ) { my $remote_ip = $ENV{'HTTP_X_FORWARDED_FOR'} || $app->remote_ip; $app->log("Non Japanese comment from $remote_ip: $Method"); no strict 'refs'; return $Method->($app, $comment); } return 1; } sub moderate { my($app, $comment) = @_; $comment->visible(0); return 1; } sub deny { my($app, $comment) = @_; return 0; } 1;