]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/OStatus/lib/feeddiscovery.php
fix up hub queueing to work w/ stomp queues
[quix0rs-gnu-social.git] / plugins / OStatus / lib / feeddiscovery.php
index 9bc7892fb2db0e641e7f75b4af45fb8e9424bcce..39985fc90278012dc15f9cc77382f13ad96e554e 100644 (file)
@@ -168,7 +168,13 @@ class FeedDiscovery
         }
 
         // Ok... now on to the links!
+        // Types listed in order of priority -- we'll prefer Atom if available.
         // @fixme merge with the munger link checks
+        $feeds = array(
+            'application/atom+xml' => false,
+            'application/rss+xml' => false,
+        );
+        
         $nodes = $dom->getElementsByTagName('link');
         for ($i = 0; $i < $nodes->length; $i++) {
             $node = $nodes->item($i);
@@ -181,17 +187,21 @@ class FeedDiscovery
                     $type = trim($type->value);
                     $href = trim($href->value);
 
-                    $feedTypes = array(
-                        'application/rss+xml',
-                        'application/atom+xml',
-                    );
-                    if (trim($rel) == 'alternate' && in_array($type, $feedTypes)) {
-                        return $this->resolveURI($href, $base);
+                    if (trim($rel) == 'alternate' && array_key_exists($type, $feeds) && empty($feeds[$type])) {
+                        // Save the first feed found of each type...
+                        $feeds[$type] = $this->resolveURI($href, $base);
                     }
                 }
             }
         }
 
+        // Return the highest-priority feed found
+        foreach ($feeds as $type => $url) {
+            if ($url) {
+                return $url;
+            }
+        }
+
         return false;
     }