防止重複的迴響(Commnet )與引用通告(Ping)

From: 布拉格的春
天:防止重複的迴響(Commnet )與引用通告(Ping)


止重複發表的迴響
(comment)

程式原理很簡單,如果同一文章的兩個迴響的本文、姓名、電郵、網址全都相同時,就當成重複發表的迴響而忽略掉。

修改步驟是:

1. 如果有裝了 MT-Blacklist,找出以下檔案,先備份一份,然後跳到步驟 3:

    你的MT目錄extlibjayallenMTBlPost.pm

2. 如果沒有裝 MT-Blacklist, 則找出以下檔案,先備份一份,然後繼續步驟 3:

    你的MT目錄libMTAppComments.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. 存檔後測試重複迴響看看 (寫一則迴響,連續按發表鍵數次….. )。


  程式原理與上面的差不多,修改步驟是:

1. 如果有裝了 MT-Blacklist,找出以下檔案,先備份一份,然後跳到步驟 3:

  你的MT目錄
extlibjayallenMTBlPing.pm

2. 如果沒有裝 MT-Blacklist, 則找出以下檔案,先備份一份,然後繼續步驟 3:

    你的MT目錄libMTAppTrackback.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. 存檔後想個法子測試重複的引用通告看看。

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

Google+ photo

You are commenting using your Google+ account. Log Out / 變更 )

連結到 %s

%d 位部落客按了讚: