webfinger cleanup

This commit is contained in:
zotlabs 2017-04-11 22:02:29 -07:00 committed by Mario Vavti
parent ab369ab91d
commit 32eead1542

View File

@ -38,6 +38,9 @@ class Wfinger extends \Zotlabs\Web\Controller {
$channel = str_replace('acct:','',$resource); $channel = str_replace('acct:','',$resource);
if(strpos($channel,'@') !== false) { if(strpos($channel,'@') !== false) {
$host = substr($channel,strpos($channel,'@')+1); $host = substr($channel,strpos($channel,'@')+1);
// If the webfinger address points off site, redirect to the correct site
if(strcasecmp($host,\App::get_hostname())) { if(strcasecmp($host,\App::get_hostname())) {
goaway('https://' . $host . '/.well-known/webfinger?f=&resource=' . $resource . (($zot) ? '&zot=' . $zot : '')); goaway('https://' . $host . '/.well-known/webfinger?f=&resource=' . $resource . (($zot) ? '&zot=' . $zot : ''));
} }
@ -77,54 +80,54 @@ class Wfinger extends \Zotlabs\Web\Controller {
} }
} }
$result['aliases'] = array(); $result['aliases'] = [];
$result['properties'] = array( $result['properties'] = [
'http://webfinger.net/ns/name' => $r[0]['channel_name'], 'http://webfinger.net/ns/name' => $r[0]['channel_name'],
'http://xmlns.com/foaf/0.1/name' => $r[0]['channel_name'] 'http://xmlns.com/foaf/0.1/name' => $r[0]['channel_name']
); ];
foreach($aliases as $alias) foreach($aliases as $alias)
if($alias != $resource) if($alias != $resource)
$result['aliases'][] = $alias; $result['aliases'][] = $alias;
$result['links'] = array( $result['links'] = [
array( [
'rel' => 'http://webfinger.net/rel/avatar', 'rel' => 'http://webfinger.net/rel/avatar',
'type' => $r[0]['xchan_photo_mimetype'], 'type' => $r[0]['xchan_photo_mimetype'],
'href' => $r[0]['xchan_photo_l'] 'href' => $r[0]['xchan_photo_l']
), ],
array( [
'rel' => 'http://webfinger.net/rel/profile-page', 'rel' => 'http://webfinger.net/rel/profile-page',
'href' => z_root() . '/profile/' . $r[0]['channel_address'], 'href' => z_root() . '/profile/' . $r[0]['channel_address'],
), ],
array( [
'rel' => 'http://webfinger.net/rel/blog', 'rel' => 'http://webfinger.net/rel/blog',
'href' => z_root() . '/channel/' . $r[0]['channel_address'], 'href' => z_root() . '/channel/' . $r[0]['channel_address'],
), ],
array( [
'rel' => 'http://ostatus.org/schema/1.0/subscribe', 'rel' => 'http://ostatus.org/schema/1.0/subscribe',
'template' => z_root() . '/follow/url={uri}', 'template' => z_root() . '/follow/url={uri}',
), ],
array( [
'rel' => 'http://purl.org/zot/protocol', 'rel' => 'http://purl.org/zot/protocol',
'href' => z_root() . '/.well-known/zot-info' . '?address=' . $r[0]['xchan_addr'], 'href' => z_root() . '/.well-known/zot-info' . '?address=' . $r[0]['xchan_addr'],
), ],
array( [
'rel' => 'magic-public-key', 'rel' => 'magic-public-key',
'href' => 'data:application/magic-public-key,' . salmon_key($r[0]['channel_pubkey']), 'href' => 'data:application/magic-public-key,' . salmon_key($r[0]['channel_pubkey']),
) ]
); ];
if($zot) { if($zot) {
// get a zotinfo packet and return it with webfinger // get a zotinfo packet and return it with webfinger
$result['zot'] = zotinfo(array('address' => $r[0]['xchan_addr'])); $result['zot'] = zotinfo( [ 'address' => $r[0]['xchan_addr'] ]);
} }
} }
else { else {
@ -132,7 +135,7 @@ class Wfinger extends \Zotlabs\Web\Controller {
killme(); killme();
} }
$arr = array('channel' => $r[0], 'request' => $_REQUEST, 'result' => $result); $arr = [ 'channel' => $r[0], 'request' => $_REQUEST, 'result' => $result ];
call_hooks('webfinger',$arr); call_hooks('webfinger',$arr);
json_return_and_die($arr['result'],'application/jrd+json'); json_return_and_die($arr['result'],'application/jrd+json');