1
1
Fork 0

OStatus now has "location" and "about", probing for urls added

This commit is contained in:
Michael Vogel 2016-07-08 22:31:11 +02:00
parent 0ccb171449
commit f86dac652f
2 changed files with 48 additions and 19 deletions

View file

@ -232,7 +232,6 @@ class Probe {
$nick = array_pop($path_parts); $nick = array_pop($path_parts);
$addr = $nick."@".$host; $addr = $nick."@".$host;
} }
$webfinger = false; $webfinger = false;
/// @todo Do we need the prefix "acct:" or "acct://"? /// @todo Do we need the prefix "acct:" or "acct://"?
@ -244,9 +243,22 @@ class Probe {
if (!in_array($key, array("lrdd", "lrdd-xml", "lrdd-json"))) if (!in_array($key, array("lrdd", "lrdd-xml", "lrdd-json")))
continue; continue;
// Try webfinger with the address (user@domain.tld)
$path = str_replace('{uri}', urlencode($addr), $link); $path = str_replace('{uri}', urlencode($addr), $link);
$webfinger = self::webfinger($path); $webfinger = self::webfinger($path);
// If webfinger wasn't successful then try it with the URL - possibly in the format https://...
if (!$webfinger AND ($uri != $addr)) {
$path = str_replace('{uri}', urlencode($uri), $link);
$webfinger = self::webfinger($path);
// Since the detection with the address wasn't successful, we delete it.
if ($webfinger) {
$nick = "";
$addr = "";
}
}
} }
if (!$webfinger) if (!$webfinger)
return self::feed($uri); return self::feed($uri);
@ -268,10 +280,10 @@ class Probe {
else { else {
// We overwrite the detected nick with our try if the previois routines hadn't detected it. // We overwrite the detected nick with our try if the previois routines hadn't detected it.
// Additionally it is overwritten when the nickname doesn't make sense (contains spaces). // Additionally it is overwritten when the nickname doesn't make sense (contains spaces).
if (!isset($result["nick"]) OR ($result["nick"] == "") OR (strstr($result["nick"], " "))) if ((!isset($result["nick"]) OR ($result["nick"] == "") OR (strstr($result["nick"], " "))) AND ($nick != ""))
$result["nick"] = $nick; $result["nick"] = $nick;
if (!isset($result["addr"]) OR ($result["addr"] == "")) if ((!isset($result["addr"]) OR ($result["addr"] == "")) AND ($addr != ""))
$result["addr"] = $addr; $result["addr"] = $addr;
} }
@ -680,8 +692,13 @@ class Probe {
*/ */
private function ostatus($webfinger) { private function ostatus($webfinger) {
$pubkey = "";
$data = array(); $data = array();
if (is_array($webfinger["aliases"]))
foreach($webfinger["aliases"] AS $alias)
if (strstr($alias, "@"))
$data["addr"] = str_replace('acct:', '', $alias);
$pubkey = "";
foreach ($webfinger["links"] AS $link) { foreach ($webfinger["links"] AS $link) {
if (($link["rel"] == "http://webfinger.net/rel/profile-page") AND if (($link["rel"] == "http://webfinger.net/rel/profile-page") AND
($link["type"] == "text/html") AND ($link["href"] != "")) ($link["type"] == "text/html") AND ($link["href"] != ""))
@ -736,6 +753,12 @@ class Probe {
if ($feed_data["header"]["author-id"] != "") if ($feed_data["header"]["author-id"] != "")
$data["alias"] = $feed_data["header"]["author-id"]; $data["alias"] = $feed_data["header"]["author-id"];
if ($feed_data["header"]["author-location"] != "")
$data["location"] = $feed_data["header"]["author-location"];
if ($feed_data["header"]["author-about"] != "")
$data["about"] = $feed_data["header"]["author-about"];
// OStatus has serious issues when the the url doesn't fit (ssl vs. non ssl) // OStatus has serious issues when the the url doesn't fit (ssl vs. non ssl)
// So we take the value that we just fetched, although the other one worked as well // So we take the value that we just fetched, although the other one worked as well
if ($feed_data["header"]["author-link"] != "") if ($feed_data["header"]["author-link"] != "")
@ -788,25 +811,24 @@ class Probe {
* @return array pump.io data * @return array pump.io data
*/ */
private function pumpio($webfinger) { private function pumpio($webfinger) {
$data = array(); $data = array();
foreach ($webfinger["links"] AS $link) { foreach ($webfinger["links"] AS $link) {
if (($link["rel"] == "http://webfinger.net/rel/profile-page") AND if (($link["rel"] == "http://webfinger.net/rel/profile-page") AND
($link["type"] == "text/html") AND ($link["href"] != "")) ($link["type"] == "text/html") AND ($link["href"] != ""))
$data["url"] = $link["href"]; $data["url"] = $link["href"];
elseif (($link["rel"] == "activity-inbox") AND ($link["href"] != "")) elseif (($link["rel"] == "activity-inbox") AND ($link["href"] != ""))
$data["activity-inbox"] = $link["href"]; $data["notify"] = $link["href"];
elseif (($link["rel"] == "activity-outbox") AND ($link["href"] != "")) elseif (($link["rel"] == "activity-outbox") AND ($link["href"] != ""))
$data["activity-outbox"] = $link["href"]; $data["poll"] = $link["href"];
elseif (($link["rel"] == "dialback") AND ($link["href"] != "")) elseif (($link["rel"] == "dialback") AND ($link["href"] != ""))
$data["dialback"] = $link["href"]; $data["dialback"] = $link["href"];
} }
if (isset($data["activity-inbox"]) AND isset($data["activity-outbox"]) AND if (isset($data["poll"]) AND isset($data["notify"]) AND
isset($data["dialback"]) AND isset($data["url"])) { isset($data["dialback"]) AND isset($data["url"])) {
// by now we use these fields only for the network type detection // by now we use these fields only for the network type detection
// So we unset all data that isn't used at the moment // So we unset all data that isn't used at the moment
unset($data["activity-inbox"]);
unset($data["activity-outbox"]);
unset($data["dialback"]); unset($data["dialback"]);
$data["network"] = NETWORK_PUMPIO; $data["network"] = NETWORK_PUMPIO;

View file

@ -59,8 +59,6 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
if ($attributes->name == "href") if ($attributes->name == "href")
$author["author-link"] = $attributes->textContent; $author["author-link"] = $attributes->textContent;
$author["author-id"] = $xpath->evaluate('/atom:feed/atom:author/atom:uri/text()')->item(0)->nodeValue;
if ($author["author-link"] == "") if ($author["author-link"] == "")
$author["author-link"] = $author["author-id"]; $author["author-link"] = $author["author-id"];
@ -89,10 +87,23 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
if ($value != "") if ($value != "")
$author["author-name"] = $value; $author["author-name"] = $value;
if ($simulate) {
$author["author-id"] = $xpath->evaluate('/atom:feed/atom:author/atom:uri/text()')->item(0)->nodeValue;
$value = $xpath->evaluate('atom:author/poco:preferredUsername/text()')->item(0)->nodeValue; $value = $xpath->evaluate('atom:author/poco:preferredUsername/text()')->item(0)->nodeValue;
if ($value != "") if ($value != "")
$author["author-nick"] = $value; $author["author-nick"] = $value;
$value = $xpath->evaluate('atom:author/poco:address/poco:formatted/text()', $context)->item(0)->nodeValue;
if ($value != "")
$author["author-location"] = $value;
$value = $xpath->evaluate('atom:author/poco:note/text()')->item(0)->nodeValue;
if ($value != "")
$author["author-about"] = $value;
}
$author["edited"] = $author["created"] = $xpath->query('/atom:feed/atom:updated/text()')->item(0)->nodeValue; $author["edited"] = $author["created"] = $xpath->query('/atom:feed/atom:updated/text()')->item(0)->nodeValue;
$author["app"] = $xpath->evaluate('/atom:feed/atom:generator/text()')->item(0)->nodeValue; $author["app"] = $xpath->evaluate('/atom:feed/atom:generator/text()')->item(0)->nodeValue;
@ -131,10 +142,6 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
$author["owner-link"] = $contact["url"]; $author["owner-link"] = $contact["url"];
$author["owner-name"] = $contact["name"]; $author["owner-name"] = $contact["name"];
$author["owner-avatar"] = $contact["thumb"]; $author["owner-avatar"] = $contact["thumb"];
// This is no field in the item table. So we have to unset it.
unset($author["author-nick"]);
unset($author["author-id"]);
} }
$header = array(); $header = array();