WebfingerUrl.php 858 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace App\Util\Webfinger;
  3. use App\Util\Lexer\Nickname;
  4. use App\Services\InstanceService;
  5. class WebfingerUrl
  6. {
  7. public static function get($url)
  8. {
  9. $n = Nickname::normalizeProfileUrl($url);
  10. if(!$n || !isset($n['domain'], $n['username'])) {
  11. return false;
  12. }
  13. if(in_array($n['domain'], InstanceService::getBannedDomains())) {
  14. return false;
  15. }
  16. return 'https://' . $n['domain'] . '/.well-known/webfinger?resource=acct:' . $n['username'] . '@' . $n['domain'];
  17. }
  18. public static function generateWebfingerUrl($url)
  19. {
  20. $url = Nickname::normalizeProfileUrl($url);
  21. $domain = $url['domain'];
  22. $username = $url['username'];
  23. $path = "https://{$domain}/.well-known/webfinger?resource=acct:{$username}@{$domain}";
  24. return $path;
  25. }
  26. }