Use only nick as handle if nick and domain is the same

This commit is contained in:
sørenpeter 2024-12-25 14:55:12 +01:00
parent e34e18b718
commit 8c12444459
3 changed files with 15 additions and 6 deletions

View file

@ -16,6 +16,7 @@ class TwtxtFile {
public $mainURL = ''; // First found URL
public $URLs = [];
public $nick = '';
public $domain = '';
public $avatar = '';
public $emoji = '';
public $description = '';
@ -456,8 +457,7 @@ function getTwtsFromTwtxtString($url) {
}
}
// Clean up nick if set to something like `@soren@darch.dk` instead of just `soren`
// mosty for (re)feeds from Mastodon etc.
// Clean up nick if set to something like `@soren@darch.dk` instead of just `soren` - mosty for (re)feeds from Mastodon etc.
if (str_contains($twtxtData->nick, "@")) {
$str = $twtxtData->nick;
$str = ltrim($str, "@");
@ -465,17 +465,25 @@ function getTwtsFromTwtxtString($url) {
}
// Fallback for nick and url if not set in twtxt.txt
// TODO: Use nick from local follow list as fallback?
if ($twtxtData->nick === "") {
$str = parse_url($url, PHP_URL_HOST);
$str = str_replace("www.", "", $str);
$str = explode(".", $str)[0]; // take the first [0] from splitting the host at "."
//$str = explode(".", $str)[0]; // take the first [0] from splitting the host at "."
$twtxtData->nick = $str;
}
if ($twtxtData->mainURL === "") {
$twtxtData->mainURL = $url;
}
// Use only nick as handle if nick and domain is the same
$twtxtData->domain = parse_url($twtxtData->mainURL, PHP_URL_HOST);
if ($twtxtData->nick === $twtxtData->domain) {
$twtxtData->domain = "";
} else {
$twtxtData->domain = "@".$twtxtData->domain;
}
if (!str_starts_with($currentLine, '#')) {
$explodedLine = explode("\t", $currentLine);
@ -550,6 +558,7 @@ function getTwtsFromTwtxtString($url) {
$twt->emoji = $twtxtData->emoji;
$twt->nick = $twtxtData->nick;
$twt->mainURL = $twtxtData->mainURL;
$twt->domain = $twtxtData->domain;
$twtxtData->twts[$timestamp] = $twt;
}

View file

@ -63,7 +63,7 @@ if ($is_gallery) {
<div>
<a href="<?=$profileURL?>" class="author">
<strong><?=$profile->nick?></strong>@<?=parse_url($profile->mainURL, PHP_URL_HOST);?>
<strong>@<?=$profile->nick?></strong><?=$profile->domain?>
</a>
<p><?=$profile->description?></p>

View file

@ -15,7 +15,7 @@
</a>
<div>
<a href="<?=$baseURL?>/profile?url=<?=$twt->mainURL?>" class="author">
<strong><?=$twt->nick?></strong>@<?=parse_url($twt->mainURL, PHP_URL_HOST);?>
<strong>@<?=$twt->nick?></strong><?=$twt->domain?>
</a>
<div class="twt-msg">