]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Normalize detection helpers
authorStephen Paul Weber <singpolyma@singpolyma.net>
Wed, 14 Oct 2015 20:54:47 +0000 (15:54 -0500)
committerStephen Paul Weber <singpolyma@singpolyma.net>
Wed, 14 Oct 2015 20:54:47 +0000 (15:54 -0500)
Will make it easier to see what's happening when we add a third one.

plugins/Linkback/LinkbackPlugin.php

index 85dcf502c7d37205e1279ac10faaa09a86c7effd..57a788457a8f26253c54ada50adc2fe0705e42f8 100644 (file)
@@ -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])) {