From 18f6429f32faebc6244a9a7176d0fce08bad41c8 Mon Sep 17 00:00:00 2001 From: onli Date: Sat, 15 Apr 2017 02:19:45 +0200 Subject: [PATCH] Add rel=trackback header and discovery (#438) --- include/functions_trackbacks.inc.php | 59 +++++++++++++++------------- templates/2k11/index.tpl | 1 + 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/include/functions_trackbacks.inc.php b/include/functions_trackbacks.inc.php index 515f2c3e..824b5791 100644 --- a/include/functions_trackbacks.inc.php +++ b/include/functions_trackbacks.inc.php @@ -172,42 +172,47 @@ function serendipity_trackback_autodiscover($res, $loc, $url, $author, $title, $ $is_wp = false; $wp_check = false; - if (preg_match('@((' . preg_quote($loc, '@') . '|' . preg_quote($loc2, '@') . ')/?trackback/)@i', $res, $wp_loc)) { - // We found a WP-blog that may not advertise RDF-Tags! - $is_wp = true; - } + // the new detection method via rel=trackback should have priority + if (preg_match('@link\s*rel=["\']trackback["\'].*href=["\'](https?:[^"\']+)["\']@i', $res, $matches)) { + $trackURI = trim($matches[1]); + } else { + if (preg_match('@((' . preg_quote($loc, '@') . '|' . preg_quote($loc2, '@') . ')/?trackback/)@i', $res, $wp_loc)) { + // We found a WP-blog that may not advertise RDF-Tags! + $is_wp = true; + } - if (!preg_match('@trackback:ping(\s*rdf:resource)?\s*=\s*["\'](https?:[^"\']+)["\']@i', $res, $matches)) { - $matches = array(); - serendipity_plugin_api::hook_event('backend_trackback_check', $matches, $loc); + if (!preg_match('@trackback:ping(\s*rdf:resource)?\s*=\s*["\'](https?:[^"\']+)["\']@i', $res, $matches)) { + $matches = array(); + serendipity_plugin_api::hook_event('backend_trackback_check', $matches, $loc); - // Plugins may say that a URI is valid, in situations where a blog has no valid RDF metadata - if (empty($matches[2])) { - if ($is_wp) { - $wp_check = true; - } else { - echo '
• ' . sprintf(TRACKBACK_FAILED, TRACKBACK_NOT_FOUND) . '
'; - return false; + // Plugins may say that a URI is valid, in situations where a blog has no valid RDF metadata + if (empty($matches[2])) { + if ($is_wp) { + $wp_check = true; + } else { + echo '
• ' . sprintf(TRACKBACK_FAILED, TRACKBACK_NOT_FOUND) . '
'; + return false; + } } } - } - $trackURI = trim($matches[2]); + $trackURI = trim($matches[2]); - if (preg_match('@dc:identifier\s*=\s*["\'](https?:[^\'"]+)["\']@i', $res, $test)) { - if ($loc != $test[1] && $loc2 != $test[1]) { - if ($is_wp) { - $wp_check = true; - } else { - echo '
• ' . sprintf(TRACKBACK_FAILED, TRACKBACK_URI_MISMATCH) . '
'; - return false; + if (preg_match('@dc:identifier\s*=\s*["\'](https?:[^\'"]+)["\']@i', $res, $test)) { + if ($loc != $test[1] && $loc2 != $test[1]) { + if ($is_wp) { + $wp_check = true; + } else { + echo '
• ' . sprintf(TRACKBACK_FAILED, TRACKBACK_URI_MISMATCH) . '
'; + return false; + } } } - } - // If $wp_check is set it means no RDF metadata was found, and we simply try the /trackback/ url. - if ($wp_check) { - $trackURI = $wp_loc[0]; + // If $wp_check is set it means no RDF metadata was found, and we simply try the /trackback/ url. + if ($wp_check) { + $trackURI = $wp_loc[0]; + } } $data = 'url=' . rawurlencode($url) diff --git a/templates/2k11/index.tpl b/templates/2k11/index.tpl index 1a96f39c..4c76fcc2 100644 --- a/templates/2k11/index.tpl +++ b/templates/2k11/index.tpl @@ -38,6 +38,7 @@ {if $entry_id} + {/if} {serendipity_hookPlugin hook="frontend_header"}