1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-29 11:15:09 +00:00
pixelfed/app/Util/Webfinger/Webfinger.php

78 lines
1.5 KiB
PHP
Raw Normal View History

2018-04-20 01:17:15 +00:00
<?php
namespace App\Util\Webfinger;
2018-08-28 03:07:36 +00:00
class Webfinger
{
public $user;
public $subject;
public $aliases;
public $links;
2018-04-20 01:17:15 +00:00
2018-08-28 03:07:36 +00:00
public function __construct($user)
{
$this->user = $user;
$this->subject = '';
$this->aliases = [];
$this->links = [];
}
2018-04-20 01:17:15 +00:00
2018-08-28 03:07:36 +00:00
public function setSubject()
{
$host = parse_url(config('app.url'), PHP_URL_HOST);
$username = $this->user->username;
2018-04-20 01:17:15 +00:00
2018-08-28 03:07:36 +00:00
$this->subject = 'acct:'.$username.'@'.$host;
2018-04-20 01:17:15 +00:00
2018-08-28 03:07:36 +00:00
return $this;
}
2018-04-20 01:17:15 +00:00
2018-08-28 03:07:36 +00:00
public function generateAliases()
{
$this->aliases = [
2018-08-05 19:30:11 +00:00
$this->user->url(),
2018-08-28 03:07:36 +00:00
$this->user->permalink(),
2018-04-20 01:17:15 +00:00
];
2018-08-28 03:07:36 +00:00
return $this;
}
public function generateLinks()
{
$user = $this->user;
2018-04-20 01:17:15 +00:00
2018-08-28 03:07:36 +00:00
$this->links = [
2018-04-20 01:17:15 +00:00
[
2018-08-28 03:07:36 +00:00
'rel' => 'http://webfinger.net/rel/profile-page',
2018-04-20 01:17:15 +00:00
'type' => 'text/html',
2018-08-28 03:07:36 +00:00
'href' => $user->url(),
2018-04-20 01:17:15 +00:00
],
[
2018-08-28 03:07:36 +00:00
'rel' => 'http://schemas.google.com/g/2010#updates-from',
2018-04-20 01:17:15 +00:00
'type' => 'application/atom+xml',
2018-08-28 03:07:36 +00:00
'href' => $user->permalink('.atom'),
2018-04-20 01:17:15 +00:00
],
[
2018-08-28 03:07:36 +00:00
'rel' => 'self',
2018-05-20 03:04:18 +00:00
'type' => 'application/activity+json',
2018-08-28 03:07:36 +00:00
'href' => $user->permalink(),
],
2018-04-20 01:17:15 +00:00
];
2018-08-28 03:07:36 +00:00
return $this;
}
public function generate()
{
$this->setSubject();
$this->generateAliases();
$this->generateLinks();
2018-04-20 01:17:15 +00:00
2018-08-28 03:07:36 +00:00
return [
2018-04-20 01:17:15 +00:00
'subject' => $this->subject,
'aliases' => $this->aliases,
2018-08-28 03:07:36 +00:00
'links' => $this->links,
2018-04-20 01:17:15 +00:00
];
2018-08-28 03:07:36 +00:00
}
}