-
- if (!$lrdd) {
- $parts = @parse_url($uri);
- if (!$parts || empty($parts["host"]) || empty($parts["path"])) {
- return [];
- }
-
- $host = $parts['scheme'] . '://' . $parts["host"];
- if (!empty($parts["port"])) {
- $host .= ':'.$parts["port"];
- }
-
- $path_parts = explode("/", trim($parts["path"], "/"));
-
- $nick = array_pop($path_parts);
-
- do {
- $lrdd = self::hostMeta($host);
- $host .= "/".array_shift($path_parts);
- } while (!$lrdd && (sizeof($path_parts) > 0));
- }
-
- if (!$lrdd) {
- Logger::log("No lrdd data found for ".$uri, Logger::DEBUG);
- return [];
- }
-
- foreach ($lrdd as $type => $template) {
- if ($webfinger) {
- continue;
- }
-
- $path = str_replace('{uri}', urlencode($uri), $template);
- $webfinger = self::webfinger($path, $type);
-
- if (!$webfinger && (strstr($uri, "@"))) {
- $path = str_replace('{uri}', urlencode("acct:".$uri), $template);
- $webfinger = self::webfinger($path, $type);
- }
-
- // Special treatment for Mastodon
- // Problem is that Mastodon uses an URL format like http://domain.tld/@nick
- // But the webfinger for this format fails.
- if (!$webfinger && !empty($nick)) {
- // Mastodon uses a "@" as prefix for usernames in their url format
- $nick = ltrim($nick, '@');
-
- $addr = $nick."@".$host;
-
- $path = str_replace('{uri}', urlencode("acct:".$addr), $template);
- $webfinger = self::webfinger($path, $type);
- }
- }