From: Stephen Paul Weber Date: Wed, 14 Oct 2015 20:54:47 +0000 (-0500) Subject: Normalize detection helpers X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=8edc5148d9f3aeb60ebddda4926bc3ff1dcdd555;p=quix0rs-gnu-social.git Normalize detection helpers Will make it easier to see what's happening when we add a third one. --- 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])) {