package MT::Plugin::BanNonJapaneseCommentText; # mt-ban-nonja-comment.pl # - Deny or moderate Non Japanese comment text using MT3 CommentFilter API # # Author: Yasuhiro Horiuchi # custmised for comment-text by daryl. # License: same as Perl # use strict; our $VERSION = "0.2d2"; # charcter repetation our $CharRep = 3; # number of match our $NofMatch = 1; use MT; use MT::Plugin; use MT::I18N; use MT::Comment; use MT::TBPing; my $plugin = MT::Plugin->new({ name => "BanNonJapaneseComment Text v$VERSION", description => "Deny Non japanese comment text", }); 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 text from $remote_ip"); return 0; } if( $text =~ '