2 次代码提交 8edd975b11 ... 119e2262d9

作者 SHA1 备注 提交日期
  Delilah Hoare 119e2262d9 Fix "Using $this when not in object context" 2 年之前
  Delilah Hoare 4670076956 Add HTTP(S) support to LRDDMethod_WebFinger 2 年之前
共有 2 个文件被更改,包括 18 次插入9 次删除
  1. 1 1
      plugins/LRDD/LRDDPlugin.php
  2. 17 8
      plugins/LRDD/lib/lrddmethod/webfinger.php

+ 1 - 1
plugins/LRDD/LRDDPlugin.php

@@ -82,7 +82,7 @@ class LRDDPlugin extends Plugin
         $all_ids = array_merge([$xrd->subject], $xrd->aliases);
 
         if (!in_array($uri, $all_ids)) {
-            $this->log(LOG_INFO, 'The original URI was not listed itself when doing discovery on it!');
+            common_log(LOG_INFO, 'The original URI was not listed itself when doing discovery on it!');
             return null;
         }
 

+ 17 - 8
plugins/LRDD/lib/lrddmethod/webfinger.php

@@ -31,15 +31,24 @@ class LRDDMethod_WebFinger extends LRDDMethod
      */
     public function discover($uri)
     {
-        $parts = explode('@', parse_url($uri, PHP_URL_PATH), 2);
+        $scheme = mb_strtolower(parse_url($uri, PHP_URL_SCHEME));
+        switch ($scheme) {
+        case 'acct':
+            // We can't use parse_url data for this, since the 'host'
+            // entry is only set if the scheme has '://' after it.
+            $parts = explode('@', parse_url($uri, PHP_URL_PATH), 2);
 
-        if (!Discovery::isAcct($uri) || count($parts) != 2) {
-            throw new Exception('Bad resource URI: ' . $uri);
-        }
-        [, $domain] = $parts;
-        if (!filter_var($domain, FILTER_VALIDATE_IP)
-            && !filter_var(gethostbyname($domain), FILTER_VALIDATE_IP)) {
-            throw new Exception('Bad resource host.');
+            if (!Discovery::isAcct($uri) || count($parts) != 2) {
+                throw new Exception('Bad resource URI: ' . $uri);
+            }
+            [, $domain] = $parts;
+            break;
+        case 'http':
+        case 'https':
+            $domain = mb_strtolower(parse_url($uri, PHP_URL_HOST));
+            break;
+        default:
+            throw new Exception('Unable to discover resource descriptor endpoint.');
         }
 
         $link = new XML_XRD_Element_Link(