我想我是有點遲鈍加上懶惰的,碰到幾次有人重複發表迴響或通告的情形時都不以為意,只是動手刪掉多餘的…… ~"~
直到今天又來了一次之後我才開始動手搜尋解決方法,應該早就有人受不了而搞出了解決方法了吧?我只要拿香當背後靈就好了….. ^^
Anyway, 在 MT Extensions 這個地方有不少好料可找,搜尋了一下就找到了防止重複發表迴響 (Comment )與引用通告 (Ping) 的兩個 Hack,也就是要改程式啦….。
- 防止重複發表的迴響 (comment)
程式原理很簡單,如果同一文章的兩個迴響的本文、姓名、電郵、網址全都相同時,就當成重複發表的迴響而忽略掉。
修改步驟是:
1. 如果有裝了 MT-Blacklist,找出以下檔案,先備份一份,然後跳到步驟 3:
你的MT目錄\extlib\jayallen\MTBlPost.pm
2. 如果沒有裝 MT-Blacklist, 則找出以下檔案,先備份一份,然後繼續步驟 3:
你的MT目錄\lib\MT\App\Comments.pm
3. 檔案中搜尋字串 $comment->save;
4. 在此一字串的前面加上以下的程式碼:
## BEGIN HACK Avoid Duplicate Comments
## http://www.nonplus.net/software/mt/AvoidingDuplicateComments.htm
if(my @existing_comments = MT::Comment->load({
blog_id => $comment->blog_id,
entry_id => $comment->entry_id})) {
foreach my $c (@existing_comments) {
next unless (($c->author||") eq ($comment->author||")
&& ($c->email||") eq ($comment->email||")
&& ($c->text||") eq ($comment->text||"));
my $link_url;
if (!$q->param(‘static’)) {
my $url = $app->base . $app->uri;
$url .= ‘?entry_id=’ . $q->param(‘entry_id’);
$link_url = $url;
} else {
my $static = $q->param(‘static’);
if ($static == 1) {
$link_url = $entry->permalink;
} else {
$link_url = $static . ‘#’ . $c->id;
}
}
return $app->redirect($link_url);
}
}
## END HACK Avoid Duplicate Comments
5. 存檔後測試重複迴響看看 (寫一則迴響,連續按發表鍵數次….. )。
- 防止重複的引用通告 (ping)
程式原理與上面的差不多,修改步驟是:
1. 如果有裝了 MT-Blacklist,找出以下檔案,先備份一份,然後跳到步驟 3:
你的MT目錄\extlib\jayallen\MTBlPing.pm
2. 如果沒有裝 MT-Blacklist, 則找出以下檔案,先備份一份,然後繼續步驟 3:
你的MT目錄\lib\MT\App\Trackback.pm
3. 檔案中搜尋字串 $ping->save;
4. 在此一字串的前面加上以下的程式碼:
## BEGIN HACK Avoid Duplicate Trackback Pings
## http://www.nonplus.net/software/mt/AvoidingDuplicateTrackbackPings.htm
my $duplicate_ping = 0;
if(my @existing_pings = MT::TBPing->load({
blog_id => $ping->blog_id,
tb_id => $ping->tb_id })) {
foreach my $p (@existing_pings) {
next unless ($p->source_url eq $ping->source_url);
# If everything is the same, simply return
return $app->_response if (($p->ip eq $ping->ip)
&& ($p->title eq $ping->title)
&& ($p->blog_name eq $ping->blog_name)
&& ($p->excerpt eq $ping->excerpt));
# If something is different, copy new values to old ping
$p->ip($ping->ip);
$p->title($ping->title);
$p->blog_name($ping->blog_name);
$p->excerpt($ping->excerpt);
# and replace new ping with old ping
$ping = $p;
$duplicate_ping = 1;
last;
}
}
## END HACK Avoid Duplicate Trackback Pings
5. 存檔後想個法子測試重複的引用通告看看。
相關文章:

重複迴響測試………
[回應]