1
0
Fork 0

Update Webfinger class

This commit is contained in:
Daniel Supernault 2019-06-27 01:01:20 -06:00
parent 9327d50c28
commit 91062b1f55
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7
1 changed files with 37 additions and 68 deletions

View File

@ -4,74 +4,43 @@ namespace App\Util\Webfinger;
class Webfinger class Webfinger
{ {
public $user; protected $user;
public $subject; protected $subject;
public $aliases; protected $aliases;
public $links; protected $links;
public function __construct($user) public function __construct($user)
{ {
$this->user = $user; $this->subject = 'acct:'.$user->username.'@'.parse_url(config('app.url'), PHP_URL_HOST);
$this->subject = ''; $this->aliases = [
$this->aliases = []; $user->url(),
$this->links = []; $user->permalink(),
} ];
$this->links = [
[
'rel' => 'http://webfinger.net/rel/profile-page',
'type' => 'text/html',
'href' => $user->url(),
],
[
'rel' => 'http://schemas.google.com/g/2010#updates-from',
'type' => 'application/atom+xml',
'href' => $user->permalink('.atom'),
],
[
'rel' => 'self',
'type' => 'application/activity+json',
'href' => $user->permalink(),
],
];
}
public function setSubject() public function generate()
{ {
$host = parse_url(config('app.url'), PHP_URL_HOST); return [
$username = $this->user->username; 'subject' => $this->subject,
'aliases' => $this->aliases,
$this->subject = 'acct:'.$username.'@'.$host; 'links' => $this->links,
];
return $this; }
}
public function generateAliases()
{
$this->aliases = [
$this->user->url(),
$this->user->permalink(),
];
return $this;
}
public function generateLinks()
{
$user = $this->user;
$this->links = [
[
'rel' => 'http://webfinger.net/rel/profile-page',
'type' => 'text/html',
'href' => $user->url(),
],
[
'rel' => 'http://schemas.google.com/g/2010#updates-from',
'type' => 'application/atom+xml',
'href' => $user->permalink('.atom'),
],
[
'rel' => 'self',
'type' => 'application/activity+json',
'href' => $user->permalink(),
],
];
return $this;
}
public function generate()
{
$this->setSubject();
$this->generateAliases();
$this->generateLinks();
return [
'subject' => $this->subject,
'aliases' => $this->aliases,
'links' => $this->links,
];
}
} }