Add rel=trackback header and discovery (#438)

This commit is contained in:
onli 2017-04-15 02:19:45 +02:00
parent 565b8ef51d
commit 18f6429f32
2 changed files with 33 additions and 27 deletions

View File

@ -172,42 +172,47 @@ function serendipity_trackback_autodiscover($res, $loc, $url, $author, $title, $
$is_wp = false; $is_wp = false;
$wp_check = false; $wp_check = false;
if (preg_match('@((' . preg_quote($loc, '@') . '|' . preg_quote($loc2, '@') . ')/?trackback/)@i', $res, $wp_loc)) { // the new detection method via rel=trackback should have priority
// We found a WP-blog that may not advertise RDF-Tags! if (preg_match('@link\s*rel=["\']trackback["\'].*href=["\'](https?:[^"\']+)["\']@i', $res, $matches)) {
$is_wp = true; $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)) { if (!preg_match('@trackback:ping(\s*rdf:resource)?\s*=\s*["\'](https?:[^"\']+)["\']@i', $res, $matches)) {
$matches = array(); $matches = array();
serendipity_plugin_api::hook_event('backend_trackback_check', $matches, $loc); 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 // Plugins may say that a URI is valid, in situations where a blog has no valid RDF metadata
if (empty($matches[2])) { if (empty($matches[2])) {
if ($is_wp) { if ($is_wp) {
$wp_check = true; $wp_check = true;
} else { } else {
echo '<div>&#8226; ' . sprintf(TRACKBACK_FAILED, TRACKBACK_NOT_FOUND) . '</div>'; echo '<div>&#8226; ' . sprintf(TRACKBACK_FAILED, TRACKBACK_NOT_FOUND) . '</div>';
return false; return false;
}
} }
} }
}
$trackURI = trim($matches[2]); $trackURI = trim($matches[2]);
if (preg_match('@dc:identifier\s*=\s*["\'](https?:[^\'"]+)["\']@i', $res, $test)) { if (preg_match('@dc:identifier\s*=\s*["\'](https?:[^\'"]+)["\']@i', $res, $test)) {
if ($loc != $test[1] && $loc2 != $test[1]) { if ($loc != $test[1] && $loc2 != $test[1]) {
if ($is_wp) { if ($is_wp) {
$wp_check = true; $wp_check = true;
} else { } else {
echo '<div>&#8226; ' . sprintf(TRACKBACK_FAILED, TRACKBACK_URI_MISMATCH) . '</div>'; echo '<div>&#8226; ' . sprintf(TRACKBACK_FAILED, TRACKBACK_URI_MISMATCH) . '</div>';
return false; return false;
}
} }
} }
}
// If $wp_check is set it means no RDF metadata was found, and we simply try the /trackback/ url. // If $wp_check is set it means no RDF metadata was found, and we simply try the /trackback/ url.
if ($wp_check) { if ($wp_check) {
$trackURI = $wp_loc[0]; $trackURI = $wp_loc[0];
}
} }
$data = 'url=' . rawurlencode($url) $data = 'url=' . rawurlencode($url)

View File

@ -38,6 +38,7 @@
<link rel="alternate" type="application/rss+xml" title="{$blogTitle} RSS feed" href="{$serendipityBaseURL}{$serendipityRewritePrefix}feeds/index.rss2"> <link rel="alternate" type="application/rss+xml" title="{$blogTitle} RSS feed" href="{$serendipityBaseURL}{$serendipityRewritePrefix}feeds/index.rss2">
<link rel="alternate" type="application/x.atom+xml" title="{$blogTitle} Atom feed" href="{$serendipityBaseURL}{$serendipityRewritePrefix}feeds/atom.xml"> <link rel="alternate" type="application/x.atom+xml" title="{$blogTitle} Atom feed" href="{$serendipityBaseURL}{$serendipityRewritePrefix}feeds/atom.xml">
{if $entry_id} {if $entry_id}
<link rel="trackback" type="application/x-www-form-urlencoded" href="{$serendipityBaseURL}comment.php?type=trackback&amp;entry_id={$entry_id}">
<link rel="pingback" href="{$serendipityBaseURL}comment.php?type=pingback&amp;entry_id={$entry_id}"> <link rel="pingback" href="{$serendipityBaseURL}comment.php?type=pingback&amp;entry_id={$entry_id}">
{/if} {/if}
{serendipity_hookPlugin hook="frontend_header"} {serendipity_hookPlugin hook="frontend_header"}