* Change order of trackback execution flow (again) to preserve

references for plugins like Track Exits, when used in conjunction
      with the entryproperties cache (garvinhicking)
This commit is contained in:
Garvin Hicking 2007-01-14 14:49:28 +00:00
parent c30314974d
commit 917f049889
3 changed files with 45 additions and 9 deletions

View File

@ -23,6 +23,10 @@ Version 1.2 ()
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)

View 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'];

View 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);
}