Normalize detection helpers
Will make it easier to see what's happening when we add a third one.
This commit is contained in:
parent
63fd35dffa
commit
8edc5148d9
|
@ -103,21 +103,11 @@ class LinkbackPlugin extends Plugin
|
|||
return $orig;
|
||||
}
|
||||
|
||||
$pb = null;
|
||||
$tb = null;
|
||||
|
||||
if (array_key_exists('X-Pingback', $result->headers)) {
|
||||
$pb = $result->headers['X-Pingback'];
|
||||
|
||||
} else if(preg_match('/<(?:link|a)[ ]+href="([^"]+)"[ ]+rel="[^" ]* ?pingback ?[^" ]*"[ ]*\/?>/i', $result->body, $match)
|
||||
|| preg_match('/<(?:link|a)[ ]+rel="[^" ]* ?pingback ?[^" ]*"[ ]+href="([^"]+)"[ ]*\/?>/i', $result->body, $match)) {
|
||||
$pb = $match[1];
|
||||
}
|
||||
|
||||
$pb = $this->getPingback($result);
|
||||
if (!empty($pb)) {
|
||||
$this->pingback($result->final_url, $pb);
|
||||
} else {
|
||||
$tb = $this->getTrackback($result->body, $result->final_url);
|
||||
$tb = $this->getTrackback($result);
|
||||
if (!empty($tb)) {
|
||||
$this->trackback($result->final_url, $tb);
|
||||
}
|
||||
|
@ -126,6 +116,15 @@ class LinkbackPlugin extends Plugin
|
|||
return $orig;
|
||||
}
|
||||
|
||||
function getPingback($result) {
|
||||
if (array_key_exists('X-Pingback', $result->headers)) {
|
||||
return $result->headers['X-Pingback'];
|
||||
} else if(preg_match('/<(?:link|a)[ ]+href="([^"]+)"[ ]+rel="[^" ]* ?pingback ?[^" ]*"[ ]*\/?>/i', $result->body, $match)
|
||||
|| preg_match('/<(?:link|a)[ ]+rel="[^" ]* ?pingback ?[^" ]*"[ ]+href="([^"]+)"[ ]*\/?>/i', $result->body, $match)) {
|
||||
return $match[1];
|
||||
}
|
||||
}
|
||||
|
||||
function pingback($url, $endpoint)
|
||||
{
|
||||
$args = array($this->notice->getUrl(), $url);
|
||||
|
@ -161,8 +160,11 @@ class LinkbackPlugin extends Plugin
|
|||
// Largely cadged from trackback_cls.php by
|
||||
// Ran Aroussi <ran@blogish.org>, GPL2 or any later version
|
||||
// http://phptrackback.sourceforge.net/
|
||||
function getTrackback($text, $url)
|
||||
function getTrackback($result)
|
||||
{
|
||||
$text = $result->body;
|
||||
$url = $result->final_url;
|
||||
|
||||
if (preg_match_all('/(<rdf:RDF.*?<\/rdf:RDF>)/sm', $text, $match, PREG_SET_ORDER)) {
|
||||
for ($i = 0; $i < count($match); $i++) {
|
||||
if (preg_match('|dc:identifier="' . preg_quote($url) . '"|ms', $match[$i][1])) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user