From c85331d8acf68f1a5e70257246daee0d2e935215 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 27 Mar 2017 20:58:15 +0000 Subject: [PATCH 1/2] Reestablish the communication with Mastodon --- include/Probe.php | 71 ++++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/include/Probe.php b/include/Probe.php index c91b2cdf27..78199e772b 100644 --- a/include/Probe.php +++ b/include/Probe.php @@ -177,6 +177,8 @@ class Probe { $path_parts = explode("/", trim($parts["path"], "/")); + $nick = array_pop($path_parts); + do { $lrdd = self::xrd($host); $host .= "/".array_shift($path_parts); @@ -200,6 +202,19 @@ class Probe { $path = str_replace('{uri}', urlencode("acct:".$uri), $link); $webfinger = self::webfinger($path); } + + // 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 AND isset($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), $link); + $webfinger = self::webfinger($path); + } } if (!is_array($webfinger["links"])) @@ -315,7 +330,34 @@ class Probe { * @return array uri data */ private function detect($uri, $network, $uid) { - if (strstr($uri, '@')) { + $parts = parse_url($uri); + + if (isset($parts["scheme"]) AND isset($parts["host"]) AND isset($parts["path"])) { + + /// @todo: Ports? + $host = $parts["host"]; + + if ($host == 'twitter.com') + return array("network" => NETWORK_TWITTER); + + $lrdd = self::xrd($host); + + $path_parts = explode("/", trim($parts["path"], "/")); + + while (!$lrdd AND (sizeof($path_parts) > 1)) { + $host .= "/".array_shift($path_parts); + $lrdd = self::xrd($host); + } + if (!$lrdd) + return self::feed($uri); + + $nick = array_pop($path_parts); + + // Mastodon uses a "@" as prefix for usernames in their url format + $nick = ltrim($nick, '@'); + + $addr = $nick."@".$host; + } elseif (strstr($uri, '@')) { // If the URI starts with "mailto:" then jump directly to the mail detection if (strpos($url,'mailto:') !== false) { $uri = str_replace('mailto:', '', $url); @@ -341,32 +383,9 @@ class Probe { $addr = $uri; } else { - $parts = parse_url($uri); - if (!isset($parts["scheme"]) OR - !isset($parts["host"]) OR - !isset($parts["path"])) - return false; - - /// @todo: Ports? - $host = $parts["host"]; - - if ($host == 'twitter.com') - return array("network" => NETWORK_TWITTER); - - $lrdd = self::xrd($host); - - $path_parts = explode("/", trim($parts["path"], "/")); - - while (!$lrdd AND (sizeof($path_parts) > 1)) { - $host .= "/".array_shift($path_parts); - $lrdd = self::xrd($host); - } - if (!$lrdd) - return self::feed($uri); - - $nick = array_pop($path_parts); - $addr = $nick."@".$host; + return false; } + $webfinger = false; /// @todo Do we need the prefix "acct:" or "acct://"? From 4fc1ebd4ea0466a0ea33adca483c55247fe6dd98 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 27 Mar 2017 21:02:56 +0000 Subject: [PATCH 2/2] Doing some Hypolyzation --- include/Probe.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/include/Probe.php b/include/Probe.php index 78199e772b..d0b799bfba 100644 --- a/include/Probe.php +++ b/include/Probe.php @@ -337,9 +337,9 @@ class Probe { /// @todo: Ports? $host = $parts["host"]; - if ($host == 'twitter.com') + if ($host == 'twitter.com') { return array("network" => NETWORK_TWITTER); - + } $lrdd = self::xrd($host); $path_parts = explode("/", trim($parts["path"], "/")); @@ -348,9 +348,9 @@ class Probe { $host .= "/".array_shift($path_parts); $lrdd = self::xrd($host); } - if (!$lrdd) + if (!$lrdd) { return self::feed($uri); - + } $nick = array_pop($path_parts); // Mastodon uses a "@" as prefix for usernames in their url format @@ -373,14 +373,14 @@ class Probe { $host = substr($uri,strpos($uri, '@') + 1); $nick = substr($uri,0, strpos($uri, '@')); - if (strpos($uri, '@twitter.com')) + if (strpos($uri, '@twitter.com')) { return array("network" => NETWORK_TWITTER); - + } $lrdd = self::xrd($host); - if (!$lrdd) + if (!$lrdd) { return self::mail($uri, $uid); - + } $addr = $uri; } else { return false;