mastodon_postlen.php 834 B

1234567891011121314151617
  1. <?php
  2. function postlen($post) {
  3. global $retlds;
  4. // echo "-A-> |{$post}|\n";
  5. // for some reason, mastodon seems to check tld existence only on http(s) links - see next regexp
  6. $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);
  7. if (!is_null($res)) $post=$res;
  8. // $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);
  9. // on http(s) links mastodon checks if tld exists...
  10. $res=preg_replace('#(^|\W)https?://(([a-z0-9]([a-z0-9-]+[a-z0-9])?){1,63}\.)+('.$retlds.')(/\S*[\w/=_\-])?#u', '$1UUUUUUUUUUUUUUUUUUUUUUU', $post);
  11. if (!is_null($res)) $post=$res;
  12. // echo "-B-> |{$post}|\n";
  13. return mb_strlen($post,'UTF-8');
  14. }
  15. ?>