]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/OStatus/lib/feeddiscovery.php
Merge branch 'master' into testing
[quix0rs-gnu-social.git] / plugins / OStatus / lib / feeddiscovery.php
index 7de80b335785681154ec0ec866cccb6b2762dbef..4ac243832617b89b00737b3e497f9ed27dc662a4 100644 (file)
@@ -73,6 +73,7 @@ class FeedDiscovery
     public $uri;
     public $type;
     public $feed;
+    public $root;
 
     /** Post-initialize query helper... */
     public function getLink($rel, $type=null)
@@ -83,7 +84,7 @@ class FeedDiscovery
 
     public function getAtomLink($rel, $type=null)
     {
-        return ActivityUtils::getLink($this->feed->documentElement, $rel, $type);
+        return ActivityUtils::getLink($this->root, $rel, $type);
     }
 
     /**
@@ -103,7 +104,7 @@ class FeedDiscovery
             $response = $client->get($url);
         } catch (HTTP_Request2_Exception $e) {
             common_log(LOG_ERR, __METHOD__ . " Failure for $url - " . $e->getMessage());
-            throw new FeedSubBadURLException($e);
+            throw new FeedSubBadURLException($e->getMessage());
         }
 
         if ($htmlOk) {
@@ -154,9 +155,27 @@ class FeedDiscovery
             $this->uri = $sourceurl;
             $this->type = $type;
             $this->feed = $feed;
+
+            $el = $this->feed->documentElement;
+
+            // Looking for the "root" element: RSS channel or Atom feed
+
+            if ($el->tagName == 'rss') {
+                $channels = $el->getElementsByTagName('channel');
+                if ($channels->length > 0) {
+                    $this->root = $channels->item(0);
+                } else {
+                    throw new FeedSubBadXmlException($sourceurl);
+                }
+            } else if ($el->tagName == 'feed') {
+                $this->root = $el;
+            } else {
+                throw new FeedSubBadXmlException($sourceurl);
+            }
+
             return $this->uri;
         } else {
-            throw new FeedSubBadXmlException($url);
+            throw new FeedSubBadXmlException($sourceurl);
         }
     }