From f2c6b669add048177255cce0bbd76bf09e980e00 Mon Sep 17 00:00:00 2001
From: Grischa Brockhaus <github@brockha.us>
Date: Tue, 17 Jan 2012 12:55:09 +0100
Subject: [PATCH] Deny duplicate pingbacks and send message about new pingbacks
 found in blog.

---
 include/functions_comments.inc.php   | 6 +++---
 include/functions_trackbacks.inc.php | 7 +++++++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/include/functions_comments.inc.php b/include/functions_comments.inc.php
index 3eec2cf4..0d5615ae 100644
--- a/include/functions_comments.inc.php
+++ b/include/functions_comments.inc.php
@@ -876,7 +876,7 @@ function serendipity_insertComment($id, $commentInfo, $type = 'NORMAL', $source
     // Send mail to the author if he chose to receive these mails, or if the comment is awaiting moderation
     if ($status != 'confirm' && (serendipity_db_bool($ca['moderate_comments'])
         || ($type == 'NORMAL' && serendipity_db_bool($row['mail_comments']))
-        || ($type == 'TRACKBACK' && serendipity_db_bool($row['mail_trackbacks'])))) {
+        || (($type == 'TRACKBACK' || $type == 'PINGBACK') && serendipity_db_bool($row['mail_trackbacks'])))) {
         serendipity_sendComment($cid, $row['email'], $name, $email, $url, $id, $row['title'], $comments, $type, serendipity_db_bool($ca['moderate_comments']), $referer);
     }
 
@@ -1133,7 +1133,7 @@ function serendipity_sendComment($comment_id, $to, $fromName, $fromEmail, $fromU
     }
 
     $entryURI   = serendipity_archiveURL($id, $title, 'baseURL');
-    $path       = ($type == 'TRACKBACK') ? 'trackback' : 'comment';
+    $path       = ($type == 'TRACKBACK' || $type == 'PINGBACK') ? 'trackback' : 'comment';
 
     // Check for using Tokens
     if ($serendipity['useCommentTokens']) {
@@ -1167,7 +1167,7 @@ function serendipity_sendComment($comment_id, $to, $fromName, $fromEmail, $fromU
         $action_more .= "\n" . str_repeat(' ', 3) . $action;
     } 
 
-    if ($type == 'TRACKBACK') {
+    if ($type == 'TRACKBACK' || $type == 'PINGBACK') {
 
         /******************* TRACKBACKS *******************/
         $subject =  ($moderate_comment ? '[' . REQUIRES_REVIEW . '] ' : '') . NEW_TRACKBACK_TO . ' ' . $title;
diff --git a/include/functions_trackbacks.inc.php b/include/functions_trackbacks.inc.php
index 28ebd044..6815c366 100644
--- a/include/functions_trackbacks.inc.php
+++ b/include/functions_trackbacks.inc.php
@@ -400,6 +400,13 @@ function add_pingback ($id, $postdata) {
         }
         
         if ($id>0) {
+            // first check, if we already have this pingback
+            $comments = serendipity_fetchComments($id,1,'co.id',true,'PINGBACK'," AND co.url='$remote'");
+            if (is_array($comments) && sizeof($comments) == 1) {
+                log_pingback("We already have that PINGBACK!");
+                return 0; // We already have it!
+            }
+            // We don't have it, so save the pingback
             serendipity_saveComment($id, $comment, 'PINGBACK');
             return 1;
         } else {