mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-10 00:34:50 +00:00
Update webfinger util, fix bug preventing username with dots
This commit is contained in:
parent
f6a2448b70
commit
c2d194af1d
1 changed files with 6 additions and 23 deletions
|
@ -10,32 +10,15 @@ class Nickname
|
||||||
$url = str_replace('acct:', '', $url);
|
$url = str_replace('acct:', '', $url);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!str_contains($url, '@') && filter_var($url, FILTER_VALIDATE_URL)) {
|
if(starts_with($url, '@')) {
|
||||||
$parsed = parse_url($url);
|
$url = substr($url, 1);
|
||||||
$username = str_replace(['/', '\\', '@'], '', $parsed['path']);
|
|
||||||
|
|
||||||
return ['domain' => $parsed['host'], 'username' => $username];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$parts = explode('@', $url);
|
$parts = explode('@', $url);
|
||||||
$username = null;
|
$username = $parts[0];
|
||||||
$domain = null;
|
$domain = $parts[1];
|
||||||
|
|
||||||
foreach ($parts as $part) {
|
if(parse_url(filter_var('https://test.dev', FILTER_VALIDATE_URL), PHP_URL_HOST))
|
||||||
|
|
||||||
// skip empty array slices
|
|
||||||
if (empty($part)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if slice contains . assume its a domain
|
|
||||||
if (str_contains($part, '.')) {
|
|
||||||
$domain = filter_var($part, FILTER_VALIDATE_URL) ?
|
|
||||||
parse_url($part, PHP_URL_HOST) :
|
|
||||||
$part;
|
|
||||||
} else {
|
|
||||||
$username = $part;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ['domain' => $domain, 'username' => $username];
|
return ['domain' => $domain, 'username' => $username];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue