]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/OStatus/lib/discoveryhints.php
Merge branch '1.0.x' of git://gitorious.org/statusnet/mainline
[quix0rs-gnu-social.git] / plugins / OStatus / lib / discoveryhints.php
index 1bb0ad2aea90e50ea4ee59915cc947e9ccd3bfb0..a98f4a6d672af976c8882242321dd57f4f0e1b8d 100644 (file)
@@ -20,7 +20,6 @@
  */
 
 class DiscoveryHints {
-
     static function fromXRD($xrd)
     {
         $hints = array();
@@ -30,6 +29,7 @@ class DiscoveryHints {
             case Discovery::PROFILEPAGE:
                 $hints['profileurl'] = $link['href'];
                 break;
+            case Salmon::NS_MENTIONS:
             case Salmon::NS_REPLIES:
                 $hints['salmon'] = $link['href'];
                 break;
@@ -65,6 +65,10 @@ class DiscoveryHints {
     {
         $hcard = self::_hcard($body, $url);
 
+        if (empty($hcard)) {
+            return array();
+        }
+
         $hints = array();
 
         // XXX: don't copy stuff into an array and then copy it again
@@ -79,7 +83,7 @@ class DiscoveryHints {
             $hints['fullname'] = implode(' ', $hcard['n']);
         }
 
-        if (array_key_exists('photo', $hcard)) {
+        if (array_key_exists('photo', $hcard) && count($hcard['photo'])) {
             $hints['avatar'] = $hcard['photo'][0];
         }
 
@@ -98,7 +102,7 @@ class DiscoveryHints {
         if (array_key_exists('url', $hcard)) {
             if (is_string($hcard['url'])) {
                 $hints['homepage'] = $hcard['url'];
-            } else if (is_array($hcard['url'])) {
+            } else if (is_array($hcard['url']) && !empty($hcard['url'])) {
                 // HACK get the last one; that's how our hcards look
                 $hints['homepage'] = $hcard['url'][count($hcard['url'])-1];
             }
@@ -109,9 +113,10 @@ class DiscoveryHints {
 
     static function _hcard($body, $url)
     {
-        // DOMDocument::loadHTML may throw warnings on unrecognized elements.
+        // DOMDocument::loadHTML may throw warnings on unrecognized elements,
+        // and notices on unrecognized namespaces.
 
-        $old = error_reporting(error_reporting() & ~E_WARNING);
+        $old = error_reporting(error_reporting() & ~(E_WARNING | E_NOTICE));
 
         $doc = new DOMDocument();
         $doc->loadHTML($body);
@@ -227,7 +232,7 @@ class DiscoveryHints {
 
         // If it's got a scheme, use it
 
-        if ($parts['scheme'] != '') {
+        if (!empty($parts['scheme'])) {
             return $rel;
         }