From 5930736d703c998d6d153e26c0d4300152cf00ea Mon Sep 17 00:00:00 2001
From: Grischa Brockhaus <grischa@brockha.us>
Date: Thu, 12 Jul 2007 15:52:58 +0000
Subject: [PATCH] At last: Trackbacks/pingbacks for URLs will only be sent
 once, no matter what link name they have or how often the URL is referenced
 in the article. (Phew!) ;-)

---
 include/functions_trackbacks.inc.php | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/include/functions_trackbacks.inc.php b/include/functions_trackbacks.inc.php
index 9b4e52e6..4882d3db 100644
--- a/include/functions_trackbacks.inc.php
+++ b/include/functions_trackbacks.inc.php
@@ -484,6 +484,7 @@ function serendipity_handle_references($id, $author, $title, $text, $dry_run = f
     global $serendipity;
     static $old_references = array();
     static $saved_references = array();
+    static $saved_urls = array();
     static $debug = false;
 
     if ($dry_run) {
@@ -499,6 +500,7 @@ function serendipity_handle_references($id, $author, $title, $text, $dry_run = f
             foreach($old_references AS $idx => $old_reference) {
                 // We need the current reference ID to restore it later.
                 $saved_references[$old_reference['link'] . $old_reference['name']] = $current_references[$old_reference['link'] . $old_reference['name']] = $old_reference;
+                $saved_urls[$old_reference['link']] = true;
             }
         }
         if ($debug) echo "Got references in dry run: <pre>" . print_r($current_references, true) . "</pre><br />\n";
@@ -587,10 +589,13 @@ function serendipity_handle_references($id, $author, $title, $text, $dry_run = f
 
         if (!isset($serendipity['noautodiscovery']) || !$serendipity['noautodiscovery']) {
             if (!$dry_run) {
-                if ($debug) echo "Enabling autodiscovery.<br />\n";
-                serendipity_reference_autodiscover($locations[$i], $url, $author, $title, serendipity_trackback_excerpt($text));
+                if (!isset($saved_urls[$locations[$i]])){
+                    if ($debug) echo "Enabling autodiscovery.<br />\n";
+                    serendipity_reference_autodiscover($locations[$i], $url, $author, $title, serendipity_trackback_excerpt($text));
+                }
+                elseif ($debug) echo "This reference was already used before in $id and therefore will not be trackbacked again.<br/>\n";
             } elseif ($debug) {
-                echo "Skipping autodiscovery<br />\n";
+                echo "Dry run: Skipping autodiscovery<br />\n";
             }
             $checked_locations[$locations[$i]] = true; // Store trackbacked link so that no further trackbacks will be sent to the same link
         } elseif ($debug) {