First commit

This commit is contained in:
pezcurrel 2024-08-06 14:07:43 +02:00
parent 51cfcc931c
commit adbac86540
2 changed files with 61 additions and 0 deletions

44
web/lib/gettlds.php Normal file

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,17 @@
<?php
function postlen($post) {
global $retlds;
// echo "-A-> |{$post}|\n";
// for some reason, mastodon seems to check tld existence only on http(s) links - see next regexp
$res=preg_replace('#(^|\W)(@[a-zA-Z0-9_]+)@(([a-z0-9]([a-z0-9-]+[a-z0-9])?){1,63}\.)+([a-z0-9]([a-z0-9-]+[a-z0-9])?){1,63}\b#u', '$1$2', $post);
if (!is_null($res)) $post=$res;
// $res=preg_replace('#(^|\W)https?://(([a-z0-9]([a-z0-9-]+[a-z0-9])?){1,63}\.)+([a-z0-9]([a-z0-9-]+[a-z0-9])?){1,63}(/\S*[\w=?_-])?#u', '$1HTTP://UUUUUUUUUUUUUUUU', $post);
// on http(s) links mastodon checks if tld exists...
$res=preg_replace('#(^|\W)https?://(([a-z0-9]([a-z0-9-]+[a-z0-9])?){1,63}\.)+('.$retlds.')(/\S*[\w/=_\-])?#u', '$1UUUUUUUUUUUUUUUUUUUUUUU', $post);
if (!is_null($res)) $post=$res;
// echo "-B-> |{$post}|\n";
return mb_strlen($post,'UTF-8');
}
?>