From 8edc5148d9f3aeb60ebddda4926bc3ff1dcdd555 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 14 Oct 2015 15:54:47 -0500 Subject: [PATCH] Normalize detection helpers Will make it easier to see what's happening when we add a third one. --- plugins/Linkback/LinkbackPlugin.php | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/plugins/Linkback/LinkbackPlugin.php b/plugins/Linkback/LinkbackPlugin.php index 85dcf502c7..57a788457a 100644 --- a/plugins/Linkback/LinkbackPlugin.php +++ b/plugins/Linkback/LinkbackPlugin.php @@ -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 , 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('/()/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])) {