pixelfed/app/Util/Webfinger/Webfinger.php

96 lines
1.9 KiB
PHP
Raw Normal View History

2018-04-20 01:17:15 +00:00
<?php
namespace App\Util\Webfinger;
use App\User;
use App\Util\Lexer\Nickname;
class Webfinger {
public $user;
public $subject;
public $aliases;
public $links;
public function __construct($user)
{
$this->user = $user;
$this->subject = '';
$this->aliases = array();
$this->links = array();
}
public function setSubject()
{
$host = parse_url(config('app.url'), PHP_URL_HOST);
$username = $this->user->username;
$this->subject = 'acct:'.$username.'@'.$host;
return $this;
}
public function generateAliases()
{
$host = parse_url(config('app.url'), PHP_URL_HOST);
$username = $this->user->username;
$url = $this->user->url();
$this->aliases = [
'acct:'.$username.'@'.$host,
$url
];
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',
2018-05-20 03:04:18 +00:00
'href' => url("/users/{$user->username}.atom")
2018-04-20 01:17:15 +00:00
],
[
2018-05-20 03:04:18 +00:00
'rel' => 'self',
'type' => 'application/activity+json',
'href' => $user->permalink()
2018-04-20 01:17:15 +00:00
],
[
2018-05-20 03:04:18 +00:00
'rel' => 'magic-public-key',
'href' => null//$user->public_key
2018-04-20 01:17:15 +00:00
],
[
2018-05-20 03:04:18 +00:00
'rel' => 'salmon',
'href' => $user->permalink('/salmon')
2018-04-20 01:17:15 +00:00
],
[
'rel' => 'http://ostatus.org/schema/1.0/subscribe',
'href' => url('/main/ostatussub?profile={uri}')
]
];
return $this;
}
public function generate()
{
$this->setSubject();
$this->generateAliases();
$this->generateLinks();
return [
'subject' => $this->subject,
'aliases' => $this->aliases,
'links' => $this->links
];
}
}