1
0
Fork 0
pixelfed/app/Util/Lexer/Nickname.php

37 lines
700 B
PHP
Raw Normal View History

2018-04-20 01:16:27 +00:00
<?php
namespace App\Util\Lexer;
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)
{
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
if(Str::startsWith($url, '@')) {
$url = substr($url, 1);
if(!Str::of($url)->contains('@')) {
return;
}
2018-04-20 01:16:27 +00:00
}
2018-08-28 03:07:36 +00:00
$parts = explode('@', $url);
$username = $parts[0];
$domain = $parts[1];
2018-08-28 03:07:36 +00:00
return [
'domain' => $domain,
'username' => $username
];
2018-04-20 01:16:27 +00:00
}
2018-08-28 03:07:36 +00:00
}