]> git.mjollnir.org Git - s9y.git/commitdiff
* Change order of trackback execution flow (again) to preserve
authorgarvinhicking <garvinhicking>
Sun, 14 Jan 2007 14:49:10 +0000 (14:49 +0000)
committergarvinhicking <garvinhicking>
Sun, 14 Jan 2007 14:49:10 +0000 (14:49 +0000)
      references for plugins like Track Exits, when used in conjunction
      with the entryproperties cache (garvinhicking)

docs/NEWS
include/functions_entries.inc.php
include/functions_trackbacks.inc.php

index 6b56a46d03134c921767577d685eb72908f417b8..ee7c412d8348d97a826aef0dedd99d56cb5209d5 100644 (file)
--- a/docs/NEWS
+++ b/docs/NEWS
@@ -3,6 +3,10 @@
 Version 1.1.1 ()
 ------------------------------------------------------------------------
 
+    * Change order of trackback execution flow (again) to preserve
+      references for plugins like Track Exits, when used in conjunction
+      with the entryproperties cache (garvinhicking)
     * Fixed a bug that prevented some entryproperty-plugins to execute
       on the entry detail pane. (garvinhicking, Dragonblast)
 
index ee62d7d1a6bc066596b652be17ee3a82c5edfe91..2acf7b367ff3eba8e77385ebb6fb1a67b70a2c3c 100644 (file)
@@ -1251,6 +1251,14 @@ function serendipity_updertEntry($entry) {
 
     serendipity_purgeEntry($entry['id'], $entry['timestamp']);
 
+    if (!serendipity_db_bool($entry['isdraft'])) {
+        // When saving an entry, first all references need to be gathered. But trackbacks to them
+        // shall only be send at the end of the execution flow. However, certain plugins depend on
+        // the existance of handled references. Thus we store the current references at this point,
+        // execute the plugins and then reset the found references to the original state.
+        serendipity_handle_references($entry['id'], $serendipity['blogTitle'], $drafted_entry['title'], $drafted_entry['body'] . $drafted_entry['extended'], true);
+    }
+
     // Send publish tags if either a new article has been inserted from scratch, or if the entry was previously
     // stored as draft and is now published
     $entry['categories'] =& $categories;
@@ -1261,7 +1269,9 @@ function serendipity_updertEntry($entry) {
     }
 
     if (!serendipity_db_bool($entry['isdraft'])) {
-        serendipity_handle_references($entry['id'], $serendipity['blogTitle'], $drafted_entry['title'], $drafted_entry['body'] . $drafted_entry['extended'], $newEntry);
+        // Now that plugins are executed, we go ahead into the Temple of Doom and send possibly failing trackbacks.
+        // First, original list of references is restored (inside the function call)
+        serendipity_handle_references($entry['id'], $serendipity['blogTitle'], $drafted_entry['title'], $drafted_entry['body'] . $drafted_entry['extended'], false);
     }
 
     return (int)$entry['id'];
index 1781acab71ac2d7fd8b3f7ae293a3433103dc9ce..7b0897feb7992981ba974058190a5ed70a286717 100644 (file)
@@ -415,10 +415,32 @@ FAILURE;
  * @param   string  The author of our entry
  * @param   string  The title of our entry
  * @param   string  The text of our entry
+ * @param   boolean Dry-Run, without performing trackbacks?
  * @return
  */
-function serendipity_handle_references($id, $author, $title, $text) {
+function serendipity_handle_references($id, $author, $title, $text, $dry_run = false) {
     global $serendipity;
+    static $old_references = array();
+
+    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);
+        echo "Dry-run, saving refs:<br />\n";
+        print_r($old_references);
+        echo "<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)$entry['id']);
+
+        if (is_array($old_references) && count($old_references) > 0) {
+            foreach($old_references AS $idx => $old_reference) {
+                $q = serendipity_db_insert('references', $old_reference, 'show');
+                echo $q . "<br />\n";
+                echo serendipity_db_query($q);
+                echo "<br />\n";
+            }
+        }
+    }
 
     if (!preg_match_all('@<a[^>]+?href\s*=\s*["\']?([^\'" >]+?)[ \'"][^>]*>(.+?)</a>@i', $text, $matches)) {
         $matches = array(0 => array(), 1 => array());
@@ -434,8 +456,6 @@ function serendipity_handle_references($id, $author, $title, $text) {
     $locations = $matches[0];
     $names     = $matches[1];
 
-    $tmpid = serendipity_db_escape_string($id);
-
     $checked_locations = array();
     serendipity_plugin_api::hook_event('backend_trackbacks', $locations);
     for ($i = 0, $j = count($locations); $i < $j; ++$i) {
@@ -458,7 +478,7 @@ function serendipity_handle_references($id, $author, $title, $text) {
         }
 
         $query = "SELECT COUNT(id) FROM {$serendipity['dbPrefix']}references
-                                  WHERE entry_id = '". (int)$tmpid ."'
+                                  WHERE entry_id = ". (int)$id ."
                                     AND link = '" . serendipity_db_escape_string($locations[$i]) . "'
                                     AND type = ''";
 
@@ -468,15 +488,17 @@ function serendipity_handle_references($id, $author, $title, $text) {
         }
 
         if (!isset($serendipity['noautodiscovery']) || !$serendipity['noautodiscovery']) {
-            serendipity_reference_autodiscover($locations[$i], $url, $author, $title, serendipity_trackback_excerpt($text));
+            if (!$dry_run) {
+                serendipity_reference_autodiscover($locations[$i], $url, $author, $title, serendipity_trackback_excerpt($text));
+            }
             $checked_locations[$locations[$i]] = true; // Store trackbacked link so that no further trackbacks will be sent to the same link
         }
     }
-    serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}references WHERE entry_id='" . (int)$tmpid . "' AND type = ''");
+    serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}references WHERE entry_id=" . (int)$id . " AND type = ''");
 
     for ($i = 0; $i < $j; ++$i) {
         $query = "INSERT INTO {$serendipity['dbPrefix']}references (entry_id, name, link) VALUES(";
-        $query .= "'" . (int)$tmpid . "', '" . serendipity_db_escape_string(strip_tags($names[$i])) . "', '";
+        $query .= (int)$id . ", '" . serendipity_db_escape_string(strip_tags($names[$i])) . "', '";
         $query .= serendipity_db_escape_string($locations[$i]) . "')";
 
         serendipity_db_query($query);
@@ -487,7 +509,7 @@ function serendipity_handle_references($id, $author, $title, $text) {
 
     foreach ($matches[1] as $citation) {
         $query = "INSERT INTO {$serendipity['dbPrefix']}references (entry_id, name) VALUES(";
-        $query .= "'" . (int)$tmpid . "', '" . serendipity_db_escape_string($citation) . "')";
+        $query .= (int)$id . ", '" . serendipity_db_escape_string($citation) . "')";
 
         serendipity_db_query($query);
     }