]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/OStatus/lib/feeddiscovery.php
Debugging log fix.
[quix0rs-gnu-social.git] / plugins / OStatus / lib / feeddiscovery.php
index 4809f9d35cafaaeeb1231ddfa21c043f9558b8f1..02c3ce02122940ebe91a7e2847f287f4962438bf 100644 (file)
@@ -22,7 +22,9 @@
  * @maintainer Brion Vibber <brion@status.net>
  */
 
-if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
+if (!defined('STATUSNET')) {
+    exit(1);
+}
 
 class FeedSubBadURLException extends FeedSubException
 {
@@ -48,6 +50,10 @@ class FeedSubNoFeedException extends FeedSubException
 {
 }
 
+class FeedSubNoSalmonException extends FeedSubException
+{
+}
+
 class FeedSubBadXmlException extends FeedSubException
 {
 }
@@ -87,6 +93,16 @@ class FeedDiscovery
         return ActivityUtils::getLink($this->root, $rel, $type);
     }
 
+    /**
+     * Get the referenced PuSH hub link from an Atom feed.
+     *
+     * @return mixed string or false
+     */
+    public function getHubLink()
+    {
+        return $this->getAtomLink('hub');
+    }
+
     /**
      * @param string $url
      * @param bool $htmlOk pass false here if you don't want to follow web pages.
@@ -102,16 +118,16 @@ class FeedDiscovery
         try {
             $client = new HTTPClient();
             $response = $client->get($url);
-        } catch (HTTP_Request2_Exception $e) {
+        } catch (Exception $e) {
             common_log(LOG_ERR, __METHOD__ . " Failure for $url - " . $e->getMessage());
-            throw new FeedSubBadURLException($e);
+            throw new FeedSubBadURLException($e->getMessage());
         }
 
         if ($htmlOk) {
             $type = $response->getHeader('Content-Type');
             $isHtml = preg_match('!^(text/html|application/xhtml\+xml)!i', $type);
             if ($isHtml) {
-                $target = $this->discoverFromHTML($response->getUrl(), $response->getBody());
+                $target = $this->discoverFromHTML($response->getEffectiveUrl(), $response->getBody());
                 if (!$target) {
                     throw new FeedSubNoFeedException($url);
                 }
@@ -133,7 +149,7 @@ class FeedDiscovery
             throw new FeedSubBadResponseException($response->getStatus());
         }
 
-        $sourceurl = $response->getUrl();
+        $sourceurl = $response->getEffectiveUrl();
         $body = $response->getBody();
         if (!$body) {
             throw new FeedSubEmptyException($sourceurl);
@@ -186,8 +202,9 @@ class FeedDiscovery
      */
     function discoverFromHTML($url, $body)
     {
-        // DOMDocument::loadHTML may throw warnings on unrecognized elements.
-        $old = error_reporting(error_reporting() & ~E_WARNING);
+        // DOMDocument::loadHTML may throw warnings on unrecognized elements,
+        // and notices on unrecognized namespaces.
+        $old = error_reporting(error_reporting() & ~(E_WARNING | E_NOTICE));
         $dom = new DOMDocument();
         $ok = $dom->loadHTML($body);
         error_reporting($old);