2018-04-20 01:16:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Util\Lexer;
|
|
|
|
|
2021-02-04 03:55:49 +00:00
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
2018-08-28 03:07:36 +00:00
|
|
|
class Nickname
|
|
|
|
{
|
2018-04-20 01:16:27 +00:00
|
|
|
public static function normalizeProfileUrl($url)
|
|
|
|
{
|
2021-02-04 03:55:49 +00:00
|
|
|
if(!Str::of($url)->contains('@')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(Str::startsWith($url, 'acct:')) {
|
2018-08-28 03:07:36 +00:00
|
|
|
$url = str_replace('acct:', '', $url);
|
|
|
|
}
|
2018-04-20 01:16:27 +00:00
|
|
|
|
2021-02-04 03:55:49 +00:00
|
|
|
if(Str::startsWith($url, '@')) {
|
2020-07-27 02:09:45 +00:00
|
|
|
$url = substr($url, 1);
|
2021-02-04 03:55:49 +00:00
|
|
|
|
|
|
|
if(!Str::of($url)->contains('@')) {
|
|
|
|
return;
|
|
|
|
}
|
2018-04-20 01:16:27 +00:00
|
|
|
}
|
2018-08-28 03:07:36 +00:00
|
|
|
|
2020-07-27 02:09:45 +00:00
|
|
|
$parts = explode('@', $url);
|
|
|
|
$username = $parts[0];
|
|
|
|
$domain = $parts[1];
|
2018-08-28 03:07:36 +00:00
|
|
|
|
2021-02-04 03:55:49 +00:00
|
|
|
return [
|
|
|
|
'domain' => $domain,
|
|
|
|
'username' => $username
|
|
|
|
];
|
2018-04-20 01:16:27 +00:00
|
|
|
}
|
2018-08-28 03:07:36 +00:00
|
|
|
}
|