2013-10-20 14:32:56 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* WebFinger resource for Profile objects
|
|
|
|
*
|
|
|
|
* @package GNUsocial
|
|
|
|
* @author Mikael Nordfeldth
|
|
|
|
* @copyright 2013 Free Software Foundation, Inc.
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
|
|
|
* @link http://status.net/
|
|
|
|
*/
|
|
|
|
|
|
|
|
class WebFingerResource_Profile extends WebFingerResource
|
|
|
|
{
|
2013-11-01 15:54:59 +00:00
|
|
|
const PROFILEPAGE = 'http://webfinger.net/rel/profile-page';
|
|
|
|
|
2013-10-20 14:32:56 +01:00
|
|
|
public function __construct(Profile $object)
|
|
|
|
{
|
|
|
|
// The type argument above verifies that it's our class
|
|
|
|
parent::__construct($object);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAliases()
|
|
|
|
{
|
|
|
|
$aliases = array();
|
|
|
|
|
2016-06-25 19:13:19 +01:00
|
|
|
// only persons ("accounts" or "agents" actually) have acct: URIs
|
|
|
|
if ($this->object->isPerson()) {
|
|
|
|
try {
|
|
|
|
// Try to create an acct: URI if we're dealing with a profile
|
|
|
|
$aliases[] = $this->reconstructAcct();
|
|
|
|
} catch (WebFingerReconstructionException $e) {
|
|
|
|
common_debug("WebFinger reconstruction for Profile failed (id={$this->object->getID()})");
|
|
|
|
}
|
2013-10-20 14:32:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return array_merge($aliases, parent::getAliases());
|
|
|
|
}
|
|
|
|
|
2013-10-28 17:26:00 +00:00
|
|
|
public function reconstructAcct()
|
2013-10-20 14:32:56 +01:00
|
|
|
{
|
|
|
|
$acct = null;
|
|
|
|
|
|
|
|
if (Event::handle('StartWebFingerReconstruction', array($this->object, &$acct))) {
|
|
|
|
// TODO: getUri may not always give us the correct host on remote users?
|
|
|
|
$host = parse_url($this->object->getUri(), PHP_URL_HOST);
|
2016-06-25 19:13:19 +01:00
|
|
|
if (empty($this->object->getNickname()) || empty($host)) {
|
2013-10-20 14:32:56 +01:00
|
|
|
throw new WebFingerReconstructionException($this->object);
|
|
|
|
}
|
2016-06-25 19:13:19 +01:00
|
|
|
$acct = mb_strtolower(sprintf('acct:%s@%s', $this->object->getNickname(), $host));
|
2013-10-20 14:32:56 +01:00
|
|
|
|
|
|
|
Event::handle('EndWebFingerReconstruction', array($this->object, &$acct));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $acct;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function updateXRD(XML_XRD $xrd)
|
|
|
|
{
|
|
|
|
if (Event::handle('StartWebFingerProfileLinks', array($xrd, $this->object))) {
|
|
|
|
|
2016-06-25 19:13:19 +01:00
|
|
|
if (common_config('site', 'fancy')) {
|
|
|
|
$apiRoot = common_path('api/', true);
|
|
|
|
} else {
|
|
|
|
$apiRoot = common_path('index.php/api/', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Profile page, can give more metadata from Link header or HTML parsing
|
2013-11-01 15:54:59 +00:00
|
|
|
$xrd->links[] = new XML_XRD_Element_Link(self::PROFILEPAGE,
|
|
|
|
$this->object->getUrl(), 'text/html');
|
2013-10-20 14:32:56 +01:00
|
|
|
|
|
|
|
// XFN
|
|
|
|
$xrd->links[] = new XML_XRD_Element_Link('http://gmpg.org/xfn/11',
|
|
|
|
$this->object->getUrl(), 'text/html');
|
2016-06-25 19:13:19 +01:00
|
|
|
if ($this->object->isPerson()) {
|
|
|
|
// FOAF for user
|
|
|
|
$xrd->links[] = new XML_XRD_Element_Link('describedby',
|
2013-10-20 14:32:56 +01:00
|
|
|
common_local_url('foaf',
|
2016-06-25 19:13:19 +01:00
|
|
|
array('nickname' => $this->object->getNickname())),
|
2013-10-20 14:32:56 +01:00
|
|
|
'application/rdf+xml');
|
|
|
|
|
2016-06-25 19:13:19 +01:00
|
|
|
// nickname discovery for apps etc.
|
|
|
|
$link = new XML_XRD_Element_Link('http://apinamespace.org/atom',
|
2013-10-20 14:32:56 +01:00
|
|
|
common_local_url('ApiAtomService',
|
2016-06-25 19:13:19 +01:00
|
|
|
array('id' => $this->object->getNickname())),
|
2013-10-20 14:32:56 +01:00
|
|
|
'application/atomsvc+xml');
|
2016-06-25 19:13:19 +01:00
|
|
|
// XML_XRD must implement changing properties first $link['http://apinamespace.org/atom/username'] = $this->object->getNickname();
|
|
|
|
$xrd->links[] = clone $link;
|
|
|
|
|
|
|
|
$link = new XML_XRD_Element_Link('http://apinamespace.org/twitter', $apiRoot);
|
|
|
|
// XML_XRD must implement changing properties first $link['http://apinamespace.org/twitter/username'] = $this->object->getNickname();
|
|
|
|
$xrd->links[] = clone $link;
|
|
|
|
|
|
|
|
} elseif ($this->object->isGroup()) {
|
|
|
|
// FOAF for group
|
|
|
|
$xrd->links[] = new XML_XRD_Element_Link('describedby',
|
|
|
|
common_local_url('foafgroup',
|
|
|
|
array('nickname' => $this->object->getNickname())),
|
|
|
|
'application/rdf+xml');
|
2013-10-20 14:32:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Event::handle('EndWebFingerProfileLinks', array($xrd, $this->object));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|