]> git.mjollnir.org Git - s9y.git/commitdiff
Fix track exit ids off by one when being used in conjunction with caching plugin
authorgarvinhicking <garvinhicking>
Wed, 21 Mar 2007 10:53:46 +0000 (10:53 +0000)
committergarvinhicking <garvinhicking>
Wed, 21 Mar 2007 10:53:46 +0000 (10:53 +0000)
docs/NEWS
include/functions_trackbacks.inc.php
plugins/serendipity_event_trackexits/serendipity_event_trackexits.php

index a3a08fc0b9ff29552c56e71165ded94e22af9330..6d9f381b671b8e73df620bc97a403fa3cddd1d31 100644 (file)
--- a/docs/NEWS
+++ b/docs/NEWS
@@ -3,6 +3,9 @@
 Version 1.2 ()
 ------------------------------------------------------------------------
 
+    * Fix track exit url ids off by one when being used in conjunction
+      with caching plugin (garvinhicking)
+
     * Fix permalink patterns for some cases to properly detect
       pagination variables instead of interpreting search words
       as those. (garvinhicking)
index 3c6a9113d03fff244bc9dc690a0135264a9433f8..ae36c60d0e7f0bcc57f3fef98a47c4ab688611a2 100644 (file)
@@ -421,20 +421,35 @@ FAILURE;
 function serendipity_handle_references($id, $author, $title, $text, $dry_run = false) {
     global $serendipity;
     static $old_references = array();
+    static $debug = false;
 
     if ($dry_run) {
         // Store the current list of references. We might need to restore them for later user.
         $old_references = serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}references WHERE type = '' AND entry_id = " . (int)$id, false, 'assoc');
+        if (is_array($old_references) && count($old_references) > 0) {
+            $current_references = array();
+            foreach($old_references AS $idx => $old_reference) {
+                // We need the current reference ID to restore it later.
+                $current_references[$old_reference['link']] = $old_reference;
+            }
+        }
+        if ($debug) echo "Got references in dry run: <pre>" . print_r($current_references, true) . "</pre><br />\n";
     } else {
         // A dry-run was called previously and restorable references are found. Restore them now.
         serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}references WHERE type = '' AND entry_id = " . (int)$id);
+        if ($debug) echo "Deleted references.<br />\n";
 
         if (is_array($old_references) && count($old_references) > 0) {
+            $current_references = array();
             foreach($old_references AS $idx => $old_reference) {
+                // We need the current reference ID to restore it later.
+                $current_references[$old_reference['link']] = $old_reference;
                 $q = serendipity_db_insert('references', $old_reference, 'show');
                 serendipity_db_query($q);
             }
         }
+
+        if ($debug) echo "Got references in final run: <pre>" . print_r($current_references, true) . "</pre><br />\n";
     }
 
     if (!preg_match_all('@<a[^>]+?href\s*=\s*["\']?([^\'" >]+?)[ \'"][^>]*>(.+?)</a>@i', $text, $matches)) {
@@ -490,13 +505,39 @@ function serendipity_handle_references($id, $author, $title, $text, $dry_run = f
         }
     }
     serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}references WHERE entry_id=" . (int)$id . " AND type = ''");
+    if ($debug) echo "Deleted references again.<br />\n";
 
-    for ($i = 0; $i < $j; ++$i) {
-        $query = "INSERT INTO {$serendipity['dbPrefix']}references (entry_id, name, link) VALUES(";
-        $query .= (int)$id . ", '" . serendipity_db_escape_string(strip_tags($names[$i])) . "', '";
-        $query .= serendipity_db_escape_string($locations[$i]) . "')";
+    if (!is_array($old_references)) {
+        $old_references = array();
+    }
 
-        serendipity_db_query($query);
+    for ($i = 0; $i < $j; ++$i) {
+        $i_link     = serendipity_db_escape_string(strip_tags($names[$i]));
+        $i_location = serendipity_db_escape_string($locations[$i]);
+        if (isset($current_references[$locations[$i]])) {
+            $query = "INSERT INTO {$serendipity['dbPrefix']}references (id, entry_id, name, link) VALUES(";
+            $query .= (int)$current_references[$locations[$i]]['id'] . ", " . (int)$id . ", '" . $i_link . "', '" . $i_location . "')";
+            serendipity_db_query($query);
+        } else {
+            $query = "INSERT INTO {$serendipity['dbPrefix']}references (entry_id, name, link) VALUES(";
+            $query .= (int)$id . ", '" . $i_link . "', '" . $i_location . "')";
+            serendipity_db_query($query);
+            $old_references[] = array(
+                'id'       => serendipity_db_insert_id('references', 'id'),
+                'name'     => $i_link,
+                'link'     => $i_location,
+                'entry_id' => (int)$id
+            );
+        }
+        
+        if ($debug) {
+            echo "Current lookup for {$locations[$i]} is <pre>" . print_r($current_references[$locations[$i]], true) . "</pre><br />\n";
+            echo $query . "<br />\n";
+        }
+    }
+    
+    if ($debug) {
+        echo "Old/Saved locations: <pre>" . print_r($old_references, true) . "</pre><br />\n";
     }
 
     // Add citations
index 818c3bda0737efe8651f5cec86328b6cb64b77c2..1b8b1cbd52e4f5f27890e7db847c49b9c556a331 100644 (file)
@@ -118,7 +118,9 @@ class serendipity_event_trackexits extends serendipity_event
                     if (empty($serendipity['encodeExitsCallback_entry_id'])) {
                         $this->links = array();
                     } else {
+                        #echo "SELECT id, link FROM {$serendipity['dbPrefix']}references WHERE entry_id = {$serendipity['encodeExitsCallback_entry_id']} AND type = ''<br />\n";
                         $this->links = serendipity_db_query("SELECT id, link FROM {$serendipity['dbPrefix']}references WHERE entry_id = {$serendipity['encodeExitsCallback_entry_id']} AND type = ''", false, 'both', false, 'link', 'id');
+                        #echo "<pre>" . print_r($this->links, true) . "</pre><br />\n";
                     }
 
                     foreach ($this->markup_elements as $temp) {