diff --git a/web/lib/mastodon-postLength.php b/web/lib/mastodon-postLength.php new file mode 100644 index 0000000..0202ce9 --- /dev/null +++ b/web/lib/mastodon-postLength.php @@ -0,0 +1,16 @@ + |{$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}\.)+('.$tldsregex.')(/\S*[\w/=_\-])?#u', '$1UUUUUUUUUUUUUUUUUUUUUUU', $post); + if (!is_null($res)) $post=$res; +// echo "-B-> |{$post}|\n"; + return mb_strlen($post,'UTF-8'); +} + +?>