+ if (!empty($link['template']) && ($link['rel'] === ActivityNamespace::OSTATUSSUB)) {
+ $result['subscribe'] = $link['template'];
+ }
+ }
+
+ return $result;
+ }
+
+ /**
+ * Get webfinger data from a given URI
+ *
+ * @param string $uri
+ * @return array Webfinger array
+ */
+ private static function getWebfingerArray(string $uri)
+ {
+ $parts = parse_url($uri);
+
+ if (!empty($parts['scheme']) && !empty($parts['host'])) {
+ $host = $parts['host'];
+ if (!empty($parts['port'])) {
+ $host .= ':'.$parts['port'];
+ }
+
+ $baseurl = $parts['scheme'] . '://' . $host;
+
+ $nick = '';
+ $addr = '';
+
+ $path_parts = explode("/", trim($parts['path'] ?? '', "/"));
+ if (!empty($path_parts)) {
+ $nick = ltrim(end($path_parts), '@');
+ // When the last part of the URI is numeric then it is most likely an ID and not a nick name
+ if (!is_numeric($nick)) {
+ $addr = $nick."@".$host;
+ } else {
+ $nick = '';
+ }
+ }
+
+ $webfinger = self::getWebfinger($parts['scheme'] . '://' . $host . self::WEBFINGER, 'application/jrd+json', $uri, $addr);
+ if (empty($webfinger)) {
+ $lrdd = self::hostMeta($host);
+ }
+
+ if (empty($webfinger) && empty($lrdd)) {
+ while (empty($lrdd) && empty($webfinger) && (sizeof($path_parts) > 1)) {
+ $host .= "/".array_shift($path_parts);
+ $baseurl = $parts['scheme'] . '://' . $host;
+
+ if (!empty($nick)) {
+ $addr = $nick."@".$host;
+ }
+
+ $webfinger = self::getWebfinger($parts['scheme'] . '://' . $host . self::WEBFINGER, 'application/jrd+json', $uri, $addr);
+ if (empty($webfinger)) {
+ $lrdd = self::hostMeta($host);
+ }
+ }
+
+ if (empty($lrdd) && empty($webfinger)) {
+ return [];
+ }