Webfinger.php 890 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Util\Webfinger;
  3. class Webfinger
  4. {
  5. protected $user;
  6. protected $subject;
  7. protected $aliases;
  8. protected $links;
  9. public function __construct($user)
  10. {
  11. $this->subject = 'acct:'.$user->username.'@'.parse_url(config('app.url'), PHP_URL_HOST);
  12. $this->aliases = [
  13. $user->url(),
  14. $user->permalink(),
  15. ];
  16. $this->links = [
  17. [
  18. 'rel' => 'http://webfinger.net/rel/profile-page',
  19. 'type' => 'text/html',
  20. 'href' => $user->url(),
  21. ],
  22. [
  23. 'rel' => 'http://schemas.google.com/g/2010#updates-from',
  24. 'type' => 'application/atom+xml',
  25. 'href' => $user->permalink('.atom'),
  26. ],
  27. [
  28. 'rel' => 'self',
  29. 'type' => 'application/activity+json',
  30. 'href' => $user->permalink(),
  31. ],
  32. ];
  33. }
  34. public function generate()
  35. {
  36. return [
  37. 'subject' => $this->subject,
  38. 'aliases' => $this->aliases,
  39. 'links' => $this->links,
  40. ];
  41. }
  42. }