X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FNetwork%2FProbe.php;h=810885323df40873630a12b839bfa934c82f0a87;hb=797db32992481ea1e6a581f32950bec52209afe4;hp=64855b83a1b6180093614af2ba9a8ea7fa2c5bf5;hpb=516018861e011865a902587876d484d6f0f42a66;p=friendica.git diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 64855b83a1..810885323d 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -1,6 +1,6 @@ getScheme()) { + return $uri->__toString(); } // Remove the URL fragment, since these shouldn't be part of any profile URL - unset($parts['fragment']); - - $URI = Network::unparseURL($parts); + $uri = $uri->withFragment(''); - return $URI; + return $uri->__toString(); } /** @@ -508,16 +507,17 @@ class Probe * Get webfinger data from a given URI * * @param string $uri - * @return array Webfinger array + * @return array + * @throws HTTPException\InternalServerErrorException */ - private static function getWebfingerArray(string $uri) + private static function getWebfingerArray(string $uri): array { $parts = parse_url($uri); if (!empty($parts['scheme']) && !empty($parts['host'])) { $host = $parts['host']; if (!empty($parts['port'])) { - $host .= ':'.$parts['port']; + $host .= ':' . $parts['port']; } $baseurl = $parts['scheme'] . '://' . $host; @@ -525,32 +525,27 @@ class Probe $nick = ''; $addr = ''; - $path_parts = explode("/", trim($parts['path'] ?? '', "/")); + $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 = ''; - } + $addr = $nick . '@' . $host; } - $webfinger = self::getWebfinger($parts['scheme'] . '://' . $host . self::WEBFINGER, 'application/jrd+json', $uri, $addr); + $webfinger = self::getWebfinger($parts['scheme'] . '://' . $host . self::WEBFINGER, HttpClient::ACCEPT_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); + $host .= '/' . array_shift($path_parts); $baseurl = $parts['scheme'] . '://' . $host; if (!empty($nick)) { - $addr = $nick."@".$host; + $addr = $nick . '@' . $host; } - $webfinger = self::getWebfinger($parts['scheme'] . '://' . $host . self::WEBFINGER, 'application/jrd+json', $uri, $addr); + $webfinger = self::getWebfinger($parts['scheme'] . '://' . $host . self::WEBFINGER, HttpClient::ACCEPT_JRD_JSON, $uri, $addr); if (empty($webfinger)) { $lrdd = self::hostMeta($host); } @@ -568,13 +563,13 @@ class Probe $nick = substr($uri, 0, strpos($uri, '@')); $addr = $uri; - $webfinger = self::getWebfinger('https://' . $host . self::WEBFINGER, 'application/jrd+json', $uri, $addr); + $webfinger = self::getWebfinger('https://' . $host . self::WEBFINGER, HttpClient::ACCEPT_JRD_JSON, $uri, $addr); if (self::$istimeout) { return []; } if (empty($webfinger)) { - $webfinger = self::getWebfinger('http://' . $host . self::WEBFINGER, 'application/jrd+json', $uri, $addr); + $webfinger = self::getWebfinger('http://' . $host . self::WEBFINGER, HttpClient::ACCEPT_JRD_JSON, $uri, $addr); if (self::$istimeout) { return []; } @@ -682,46 +677,31 @@ class Probe 'uri' => $uri, 'network' => $network, 'uid' => $uid, - 'result' => [], + 'result' => null, ]; Hook::callAll('probe_detect', $hookData); - if ($hookData['result']) { - if (!is_array($hookData['result'])) { - return []; - } else { - return $hookData['result']; - } + if (isset($hookData['result'])) { + return is_array($hookData['result']) ? $hookData['result'] : []; } $parts = parse_url($uri); - - if (!empty($parts['scheme']) && !empty($parts['host'])) { - if (in_array($parts['host'], ['twitter.com', 'mobile.twitter.com'])) { - return self::twitter($uri); - } - } elseif (strstr($uri, '@')) { - // If the URI starts with "mailto:" then jump directly to the mail detection - if (strpos($uri, 'mailto:') !== false) { - $uri = str_replace('mailto:', '', $uri); - return self::mail($uri, $uid); - } - - if ($network == Protocol::MAIL) { - return self::mail($uri, $uid); - } - - if (Strings::endsWith($uri, '@twitter.com') - || Strings::endsWith($uri, '@mobile.twitter.com') - ) { - return self::twitter($uri); - } - } else { + if (empty($parts['scheme']) && empty($parts['host']) && !strstr($parts['path'], '@')) { Logger::info('URI was not detectable', ['uri' => $uri]); return []; } + // If the URI starts with "mailto:" then jump directly to the mail detection + if (strpos($uri, 'mailto:') !== false) { + $uri = str_replace('mailto:', '', $uri); + return self::mail($uri, $uid); + } + + if ($network == Protocol::MAIL) { + return self::mail($uri, $uid); + } + Logger::info('Probing start', ['uri' => $uri]); if (!empty($ap_profile['addr']) && ($ap_profile['addr'] != $uri)) { @@ -1742,33 +1722,6 @@ class Probe return $data; } - /** - * Check for twitter contact - * - * @param string $uri - * - * @return array twitter data - */ - private static function twitter($uri) - { - if (preg_match('=([^@]+)@(?:mobile\.)?twitter\.com$=i', $uri, $matches)) { - $nick = $matches[1]; - } elseif (preg_match('=^https?://(?:mobile\.)?twitter\.com/(.+)=i', $uri, $matches)) { - $nick = $matches[1]; - } else { - return []; - } - - $data = []; - $data['url'] = 'https://twitter.com/' . $nick; - $data['addr'] = $nick . '@twitter.com'; - $data['nick'] = $data['name'] = $nick; - $data['network'] = Protocol::TWITTER; - $data['baseurl'] = 'https://twitter.com'; - - return $data; - } - /** * Checks HTML page for RSS feed link * @@ -1996,8 +1949,6 @@ class Probe $data["name"] .= $perspart->text; } } - - $data["name"] = Strings::escapeTags($data["name"]); } } } @@ -2048,7 +1999,7 @@ class Probe /** * Fetch the last date that the contact had posted something (publically) * - * @param string $data probing result + * @param array $data probing result * @return string last activity */ public static function getLastUpdate(array $data)