const DETECT_UNSPECIFIC = [self::DETECT_MANUAL, self::DETECT_HEADER, self::DETECT_BODY, self::DETECT_HOST_META, self::DETECT_CONTACTS, self::DETECT_AP_ACTOR];
// Implementation specific endpoints
+ // @todo Possibly add Lemmy detection via the endpoint /api/v3/site
const DETECT_FRIENDIKA = 10;
const DETECT_FRIENDICA = 11;
const DETECT_STATUSNET = 12;
public static function reachable(string $profile, string $server = '', string $network = '', bool $force = false): bool
{
if ($server == '') {
- $contact = Contact::getByURL($profile, null, ['baseurl']);
+ $contact = Contact::getByURL($profile, null, ['baseurl', 'network']);
if (!empty($contact['baseurl'])) {
$server = $contact['baseurl'];
+ } elseif ($contact['network'] == Protocol::DIASPORA) {
+ $parts = parse_url($profile);
+ unset($parts['path']);
+ $server = (string)Uri::fromParts($parts);
}
}
/**
* Remove unwanted content from the given URL
*
- * @param string $url
+ * @param string $dirtyUrl
*
* @return string cleaned URL
+ * @throws Exception
*/
- public static function cleanURL(string $url): string
+ public static function cleanURL(string $dirtyUrl): string
{
- $url = trim($url, '/');
- $url = str_replace('/index.php', '', $url);
-
- $urlparts = parse_url($url);
- if (empty($urlparts)) {
+ try {
+ $url = str_replace('/index.php', '', trim($dirtyUrl, '/'));
+ return (string)(new Uri($url))->withUserInfo('')->withQuery('')->withFragment('');
+ } catch (\Throwable $e) {
+ Logger::warning('Invalid URL', ['dirtyUrl' => $dirtyUrl, 'url' => $url]);
return '';
}
-
- unset($urlparts['user']);
- unset($urlparts['pass']);
- unset($urlparts['query']);
- unset($urlparts['fragment']);
- return (string)Uri::fromParts($urlparts);
}
/**