From: garvinhicking Date: Thu, 12 Jul 2007 13:02:46 +0000 (+0000) Subject: Revert, for the time being X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=872ddd2ab34a0d03da49036f1c84cd167c54f6af;p=s9y.git Revert, for the time being --- diff --git a/include/functions_trackbacks.inc.php b/include/functions_trackbacks.inc.php index 0a97c24..1429a2b 100644 --- a/include/functions_trackbacks.inc.php +++ b/include/functions_trackbacks.inc.php @@ -498,7 +498,7 @@ function serendipity_handle_references($id, $author, $title, $text, $dry_run = f $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"; @@ -515,7 +515,7 @@ function serendipity_handle_references($id, $author, $title, $text, $dry_run = f $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'); $cr = serendipity_db_query($q); if ($debug && is_string($cr)) { @@ -527,8 +527,8 @@ function serendipity_handle_references($id, $author, $title, $text, $dry_run = f if ($debug) echo "Got references in final run:
" . print_r($current_references, true) . "

\n"; } - if (!preg_match_all('@]+?href\s*=\s*["\']?([^\'" >]+?)[ \'"][^>]*>.+?@i', $text, $matches)) { - $matches = array(0 => array()); + if (!preg_match_all('@]+?href\s*=\s*["\']?([^\'" >]+?)[ \'"][^>]*>(.+?)@i', $text, $matches)) { + $matches = array(0 => array(), 1 => array()); } else { // remove full matches array_shift($matches); @@ -539,6 +539,7 @@ function serendipity_handle_references($id, $author, $title, $text, $dry_run = f // Add URL references $locations = $matches[0]; + $names = $matches[1]; $checked_locations = array(); serendipity_plugin_api::hook_event('backend_trackbacks', $locations); @@ -553,6 +554,16 @@ function serendipity_handle_references($id, $author, $title, $text, $dry_run = f continue; } + if (preg_match_all('@]+?alt=["\']?([^\'">]+?)[\'"][^>]+?>@i', $names[$i], $img_alt)) { + if (is_array($img_alt) && is_array($img_alt[0])) { + foreach($img_alt[0] as $alt_idx => $alt_img) { + // Replace all s within a link with their respective ALT tag, so that references + // can be stored with a title. + $names[$i] = str_replace($alt_img, $img_alt[1][$alt_idx], $names[$i]); + } + } + } + $query = "SELECT COUNT(id) FROM {$serendipity['dbPrefix']}references WHERE entry_id = ". (int)$id ." AND link = '" . serendipity_db_escape_string($locations[$i]) . "' @@ -563,7 +574,7 @@ function serendipity_handle_references($id, $author, $title, $text, $dry_run = f echo $row . "
\n"; } - if ($row[0] > 0 && isset($saved_references[$locations[$i]])) { + if ($row[0] > 0 && isset($saved_references[$locations[$i] . $names[$i]])) { if ($debug) echo "Found references for $id, skipping rest
\n"; continue; } @@ -593,24 +604,25 @@ function serendipity_handle_references($id, $author, $title, $text, $dry_run = f $duplicate_check = array(); for ($i = 0; $i < $j; ++$i) { + $i_link = serendipity_db_escape_string(strip_tags($names[$i])); $i_location = serendipity_db_escape_string($locations[$i]); // No link with same description AND same text should be inserted. - if (isset($duplicate_check[$i_location])) { + if (isset($duplicate_check[$i_location . $i_link])) { continue; } - 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 . ", '$title', '" . $i_location . "')"; + $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"; } - $duplicate_check[$locations[$i]] = true; + $duplicate_check[$locations[$i] . $names[$i]] = true; } else { $query = "INSERT INTO {$serendipity['dbPrefix']}references (entry_id, name, link) VALUES("; - $query .= (int)$id . ", '$title', '" . $i_location . "')"; + $query .= (int)$id . ", '" . $i_link . "', '" . $i_location . "')"; $ins = serendipity_db_query($query); if ($debug && is_string($ins)) { echo $ins . "
\n"; @@ -618,15 +630,15 @@ function serendipity_handle_references($id, $author, $title, $text, $dry_run = f $old_references[] = array( 'id' => serendipity_db_insert_id('references', 'id'), - 'name' => '', + 'name' => $i_link, 'link' => $i_location, 'entry_id' => (int)$id ); - $duplicate_check[$i_location] = true; + $duplicate_check[$i_location . $i_link] = true; } 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"; } }