NP_BlockManyLinkComment
2006年9月1日
転職と引越しで忙しく、久々の書き込みになった。5月からの4ヶ月間、ブログもほったらかしになっていたが、案の定コメントスパムにやられた。
現在のところスパム対策として、コメント書き込み用の form の表示に Javascript を使用している。が、どうやら Javascript 機能を搭載したスパムロボットがやってきたらしい。今ところ特徴としては、数多くの『http://』を含むということがあげられるので、これで対処できそう。簡単なプラグインを作成してみた。
NP_BlockManyLinkComment.php
3つ以上のリンクを含むコメントをブロックするという仕様である。これで様子を見てみよう。
(2006-09-11 追記)
最初のバージョンでは、『<A HREF=』というパターンにやられたので、少し変更。(→ 2006-09-12 ブロックを確認)
現在のところスパム対策として、コメント書き込み用の form の表示に Javascript を使用している。が、どうやら Javascript 機能を搭載したスパムロボットがやってきたらしい。今ところ特徴としては、数多くの『http://』を含むということがあげられるので、これで対処できそう。簡単なプラグインを作成してみた。
NP_BlockManyLinkComment.php
<?php
class NP_BlockManyLinkComment extends NucleusPlugin {
function getName() { return get_class($this); }
function getMinNucleusVersion() { return 220; }
function getAuthor() { return 'Katsumi'; }
function getVersion() { return '0.1'; }
function getURL() {return 'http://hp.vector.co.jp/authors/VA016157/';}
function getDescription() { return get_class($this).' plugin'; }
function supportsFeature($what) { return (int)($what=='SqlTablePrefix'); }
function getEventList() { return array('PreAddComment'); }
function event_PreAddComment(&$data){
$allowedNum=2;
preg_match_all('/<a href=[^>].*<\\/a>/i',$data['comment']['body'],$matches1);
preg_match_all('/http:\\/\\//i',$data['comment']['body'],$matches2);
if (count($matches1[0])<=$allowedNum && count($matches2[0])<=$allowedNum) return; // Return if less than allowed number.
?><html><head><title>Error</title><body>
Sorry, but comment with more than <?php echo $allowedNum?> links is not accepted.
</body></html><?php
exit;
}
}
?>3つ以上のリンクを含むコメントをブロックするという仕様である。これで様子を見てみよう。
(2006-09-11 追記)
最初のバージョンでは、『<A HREF=』というパターンにやられたので、少し変更。(→ 2006-09-12 ブロックを確認)