From cac816382a3127760d5b56df790ba0b505dcaf90 Mon Sep 17 00:00:00 2001 From: Garvin Hicking Date: Wed, 20 Jun 2007 11:31:52 +0000 Subject: [PATCH] Patch reference handling function so that it can deal with multiple identical URLs --- include/functions_trackbacks.inc.php | 54 +++++++++++++++++++++------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/include/functions_trackbacks.inc.php b/include/functions_trackbacks.inc.php index aeceb13c..94b58c80 100644 --- a/include/functions_trackbacks.inc.php +++ b/include/functions_trackbacks.inc.php @@ -427,26 +427,38 @@ function serendipity_handle_references($id, $author, $title, $text, $dry_run = f 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 = '' OR type IS NULL) AND entry_id = " . (int)$id, false, 'assoc'); + + if ($debug && is_string($old_references)) { + echo $old_references . "
\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. - $saved_references[$old_reference['link']] = $current_references[$old_reference['link']] = $old_reference; + $saved_references[$old_reference['link'] . $old_reference['name']] = $current_references[$old_reference['link'] . $old_reference['name']] = $old_reference; } } if ($debug) echo "Got references in dry run:
" . print_r($current_references, true) . "

\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 = '' OR type IS NULL) AND entry_id = " . (int)$id); + $del = serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}references WHERE (type = '' OR type IS NULL) AND entry_id = " . (int)$id); + if ($debug && is_string($del)) { + echo $del . "
\n"; + } + if ($debug) echo "Deleted references.
\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; + $current_references[$old_reference['link'] . $old_reference['name']] = $old_reference; $q = serendipity_db_insert('references', $old_reference, 'show'); - serendipity_db_query($q); + $cr = serendipity_db_query($q); + if ($debug && is_string($cr)) { + echo $cr . "
\n"; + } } } @@ -496,7 +508,11 @@ function serendipity_handle_references($id, $author, $title, $text, $dry_run = f AND (type = '' OR type IS NULL)"; $row = serendipity_db_query($query, true, 'num'); - if ($row[0] > 0 && isset($saved_references[$locations[$i]])) { + if ($debug && is_string($row)) { + echo $row . "
\n"; + } + + if ($row[0] > 0 && isset($saved_references[$locations[$i] . $names[$i]])) { if ($debug) echo "Found references for $id, skipping rest
\n"; continue; } @@ -513,7 +529,11 @@ function serendipity_handle_references($id, $author, $title, $text, $dry_run = f echo "Skipping full autodiscovery
\n"; } } - serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}references WHERE entry_id=" . (int)$id . " AND (type = '' OR type IS NULL)"); + $del = serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}references WHERE entry_id=" . (int)$id . " AND (type = '' OR type IS NULL)"); + if ($debug && is_string($del)) { + echo $del . "
\n"; + } + if ($debug) echo "Deleted references again.
\n"; if (!is_array($old_references)) { @@ -523,14 +543,21 @@ function serendipity_handle_references($id, $author, $title, $text, $dry_run = f 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]])) { + if (isset($current_references[$locations[$i] . $names[$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); + $query .= (int)$current_references[$locations[$i] . $names[$i]]['id'] . ", " . (int)$id . ", '" . $i_link . "', '" . $i_location . "')"; + $ins = serendipity_db_query($query); + if ($debug && is_string($ins)) { + echo $ins . "
\n"; + } } else { $query = "INSERT INTO {$serendipity['dbPrefix']}references (entry_id, name, link) VALUES("; $query .= (int)$id . ", '" . $i_link . "', '" . $i_location . "')"; - serendipity_db_query($query); + $ins = serendipity_db_query($query); + if ($debug && is_string($ins)) { + echo $ins . "
\n"; + } + $old_references[] = array( 'id' => serendipity_db_insert_id('references', 'id'), 'name' => $i_link, @@ -540,7 +567,7 @@ function serendipity_handle_references($id, $author, $title, $text, $dry_run = f } if ($debug) { - echo "Current lookup for {$locations[$i]} is
" . print_r($current_references[$locations[$i]], true) . "

\n"; + echo "Current lookup for {$locations[$i]}{$names[$i]} is
" . print_r($current_references[$locations[$i] . $names[$i]], true) . "

\n"; echo $query . "
\n"; } } @@ -556,7 +583,10 @@ function serendipity_handle_references($id, $author, $title, $text, $dry_run = f $query = "INSERT INTO {$serendipity['dbPrefix']}references (entry_id, name) VALUES("; $query .= (int)$id . ", '" . serendipity_db_escape_string($citation) . "')"; - serendipity_db_query($query); + $cite = serendipity_db_query($query); + if ($debug && is_string($cite)) { + echo $cite . "
\n"; + } } }