Merge pull request #3829 from annando/webfinger-clean
Some Webfinger clean up
This commit is contained in:
commit
f949747e01
|
@ -36,6 +36,7 @@ function noscrape_init(App $a) {
|
||||||
'fn' => $a->profile['name'],
|
'fn' => $a->profile['name'],
|
||||||
'addr' => $a->profile['addr'],
|
'addr' => $a->profile['addr'],
|
||||||
'nick' => $which,
|
'nick' => $which,
|
||||||
|
'guid' => $a->profile['guid'],
|
||||||
'key' => $a->profile['pubkey'],
|
'key' => $a->profile['pubkey'],
|
||||||
'homepage' => System::baseUrl()."/profile/{$which}",
|
'homepage' => System::baseUrl()."/profile/{$which}",
|
||||||
'comm' => (x($a->profile,'page-flags')) && ($a->profile['page-flags'] == PAGE_COMMUNITY),
|
'comm' => (x($a->profile,'page-flags')) && ($a->profile['page-flags'] == PAGE_COMMUNITY),
|
||||||
|
|
23
mod/xrd.php
23
mod/xrd.php
|
@ -22,16 +22,14 @@ function xrd_init(App $a) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(substr($uri,0,4) === 'http') {
|
if (substr($uri, 0, 4) === 'http') {
|
||||||
$acct = false;
|
|
||||||
$name = ltrim(basename($uri), '~');
|
$name = ltrim(basename($uri), '~');
|
||||||
} else {
|
} else {
|
||||||
$acct = true;
|
|
||||||
$local = str_replace('acct:', '', $uri);
|
$local = str_replace('acct:', '', $uri);
|
||||||
if(substr($local,0,2) == '//')
|
if (substr($local, 0, 2) == '//')
|
||||||
$local = substr($local, 2);
|
$local = substr($local, 2);
|
||||||
|
|
||||||
$name = substr($local, 0, strpos($local,'@'));
|
$name = substr($local, 0, strpos($local, '@'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = dba::select('user', array(), array('nickname' => $name), array('limit' => 1));
|
$r = dba::select('user', array(), array('nickname' => $name), array('limit' => 1));
|
||||||
|
@ -41,20 +39,17 @@ function xrd_init(App $a) {
|
||||||
|
|
||||||
$profile_url = System::baseUrl().'/profile/'.$r['nickname'];
|
$profile_url = System::baseUrl().'/profile/'.$r['nickname'];
|
||||||
|
|
||||||
if ($acct) {
|
$alias = str_replace('/profile/', '/~', $profile_url);
|
||||||
$alias = $profile_url;
|
|
||||||
} else {
|
|
||||||
$alias = 'acct:'.$r['nickname'].'@'.$a->get_hostname();
|
|
||||||
|
|
||||||
|
$addr = 'acct:'.$r['nickname'].'@'.$a->get_hostname();
|
||||||
if ($a->get_path()) {
|
if ($a->get_path()) {
|
||||||
$alias .= '/'.$a->get_path();
|
$addr .= '/'.$a->get_path();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($mode == 'xml') {
|
if ($mode == 'xml') {
|
||||||
xrd_xml($a, $uri, $alias, $profile_url, $r);
|
xrd_xml($a, $addr, $alias, $profile_url, $r);
|
||||||
} else {
|
} else {
|
||||||
xrd_json($a, $uri, $alias, $profile_url, $r);
|
xrd_json($a, $addr, $alias, $profile_url, $r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +60,7 @@ function xrd_json($a, $uri, $alias, $profile_url, $r) {
|
||||||
header("Content-type: application/json; charset=utf-8");
|
header("Content-type: application/json; charset=utf-8");
|
||||||
|
|
||||||
$json = array('subject' => $uri,
|
$json = array('subject' => $uri,
|
||||||
'aliases' => array($alias),
|
'aliases' => array($alias, $profile_url),
|
||||||
'links' => array(array('rel' => NAMESPACE_DFRN, 'href' => $profile_url),
|
'links' => array(array('rel' => NAMESPACE_DFRN, 'href' => $profile_url),
|
||||||
array('rel' => NAMESPACE_FEED, 'type' => 'application/atom+xml', 'href' => System::baseUrl().'/dfrn_poll/'.$r['nickname']),
|
array('rel' => NAMESPACE_FEED, 'type' => 'application/atom+xml', 'href' => System::baseUrl().'/dfrn_poll/'.$r['nickname']),
|
||||||
array('rel' => 'http://webfinger.net/rel/profile-page', 'type' => 'text/html', 'href' => $profile_url),
|
array('rel' => 'http://webfinger.net/rel/profile-page', 'type' => 'text/html', 'href' => $profile_url),
|
||||||
|
|
|
@ -778,6 +778,10 @@ class Probe {
|
||||||
$data["nick"] = $json["nick"];
|
$data["nick"] = $json["nick"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($json["guid"])) {
|
||||||
|
$data["guid"] = $json["guid"];
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($json["comm"])) {
|
if (!empty($json["comm"])) {
|
||||||
$data["community"] = $json["comm"];
|
$data["community"] = $json["comm"];
|
||||||
}
|
}
|
||||||
|
@ -905,7 +909,6 @@ class Probe {
|
||||||
* @return array DFRN data
|
* @return array DFRN data
|
||||||
*/
|
*/
|
||||||
private static function dfrn($webfinger) {
|
private static function dfrn($webfinger) {
|
||||||
|
|
||||||
$hcard_url = "";
|
$hcard_url = "";
|
||||||
$data = array();
|
$data = array();
|
||||||
foreach ($webfinger["links"] as $link) {
|
foreach ($webfinger["links"] as $link) {
|
||||||
|
@ -937,7 +940,9 @@ class Probe {
|
||||||
|
|
||||||
if (is_array($webfinger["aliases"])) {
|
if (is_array($webfinger["aliases"])) {
|
||||||
foreach ($webfinger["aliases"] as $alias) {
|
foreach ($webfinger["aliases"] as $alias) {
|
||||||
if (substr($alias, 0, 5) == 'acct:') {
|
if (normalise_link($alias) != normalise_link($data["url"]) && ! strstr($alias, "@")) {
|
||||||
|
$data["alias"] = $alias;
|
||||||
|
} elseif (substr($alias, 0, 5) == 'acct:') {
|
||||||
$data["addr"] = substr($alias, 5);
|
$data["addr"] = substr($alias, 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1134,6 +1139,10 @@ class Probe {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($webfinger["subject"]) && (substr($webfinger["subject"], 0, 5) == 'acct:')) {
|
||||||
|
$data["addr"] = substr($webfinger["subject"], 5);
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch further information from the hcard
|
// Fetch further information from the hcard
|
||||||
$data = self::pollHcard($hcard_url, $data);
|
$data = self::pollHcard($hcard_url, $data);
|
||||||
|
|
||||||
|
@ -1172,17 +1181,20 @@ class Probe {
|
||||||
*/
|
*/
|
||||||
private static function ostatus($webfinger, $short = false) {
|
private static function ostatus($webfinger, $short = false) {
|
||||||
$data = array();
|
$data = array();
|
||||||
|
|
||||||
if (is_array($webfinger["aliases"])) {
|
if (is_array($webfinger["aliases"])) {
|
||||||
foreach ($webfinger["aliases"] as $alias) {
|
foreach ($webfinger["aliases"] as $alias) {
|
||||||
if (strstr($alias, "@")) {
|
if (strstr($alias, "@") && !strstr(normalise_link($alias), "http://")) {
|
||||||
$data["addr"] = str_replace('acct:', '', $alias);
|
$data["addr"] = str_replace('acct:', '', $alias);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_string($webfinger["subject"]) && strstr($webfinger["subject"], "@")) {
|
if (is_string($webfinger["subject"]) && strstr($webfinger["subject"], "@") &&
|
||||||
|
!strstr(normalise_link($webfinger["subject"]), "http://")) {
|
||||||
$data["addr"] = str_replace('acct:', '', $webfinger["subject"]);
|
$data["addr"] = str_replace('acct:', '', $webfinger["subject"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$pubkey = "";
|
$pubkey = "";
|
||||||
if (is_array($webfinger["links"])) {
|
if (is_array($webfinger["links"])) {
|
||||||
foreach ($webfinger["links"] as $link) {
|
foreach ($webfinger["links"] as $link) {
|
||||||
|
|
Loading…
Reference in a new issue