Issue 2957: The avatar problem with mastodon should now finally be solved

This commit is contained in:
Michael 2017-04-02 12:37:22 +00:00
parent ed3aa9fa73
commit 94f3f0887b
3 changed files with 49 additions and 42 deletions

View file

@ -888,33 +888,36 @@ class Probe {
* @return array OStatus data
*/
private function ostatus($webfinger) {
$data = array();
if (is_array($webfinger["aliases"]))
foreach($webfinger["aliases"] AS $alias)
if (strstr($alias, "@"))
if (is_array($webfinger["aliases"])) {
foreach ($webfinger["aliases"] AS $alias) {
if (strstr($alias, "@")) {
$data["addr"] = str_replace('acct:', '', $alias);
}
}
}
if (is_string($webfinger["subject"]) AND strstr($webfinger["subject"], "@"))
if (is_string($webfinger["subject"]) AND strstr($webfinger["subject"], "@")) {
$data["addr"] = str_replace('acct:', '', $webfinger["subject"]);
}
$pubkey = "";
foreach ($webfinger["links"] AS $link) {
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"];
elseif (($link["rel"] == "salmon") AND ($link["href"] != ""))
} elseif (($link["rel"] == "salmon") AND ($link["href"] != "")) {
$data["notify"] = $link["href"];
elseif (($link["rel"] == NAMESPACE_FEED) AND ($link["href"] != ""))
} elseif (($link["rel"] == NAMESPACE_FEED) AND ($link["href"] != "")) {
$data["poll"] = $link["href"];
elseif (($link["rel"] == "magic-public-key") AND ($link["href"] != "")) {
} elseif (($link["rel"] == "magic-public-key") AND ($link["href"] != "")) {
$pubkey = $link["href"];
if (substr($pubkey, 0, 5) === 'data:') {
if (strstr($pubkey, ','))
if (strstr($pubkey, ',')) {
$pubkey = substr($pubkey, strpos($pubkey, ',') + 1);
else
} else {
$pubkey = substr($pubkey, 5);
}
} elseif (normalise_link($pubkey) == 'http://') {
$ret = z_fetch_url($pubkey);
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
@ -930,16 +933,15 @@ class Probe {
$e = base64url_decode($key[2]);
$data["pubkey"] = metopem($m,$e);
}
}
}
if (isset($data["notify"]) AND isset($data["pubkey"]) AND
isset($data["poll"]) AND isset($data["url"])) {
$data["network"] = NETWORK_OSTATUS;
} else
} else {
return false;
}
// Fetch all additional data from the feed
$ret = z_fetch_url($data["poll"]);
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
@ -947,32 +949,32 @@ class Probe {
}
$feed = $ret['body'];
$feed_data = feed_import($feed,$dummy1,$dummy2, $dummy3, true);
if (!$feed_data)
if (!$feed_data) {
return false;
if ($feed_data["header"]["author-name"] != "")
}
if ($feed_data["header"]["author-name"] != "") {
$data["name"] = $feed_data["header"]["author-name"];
if ($feed_data["header"]["author-nick"] != "")
}
if ($feed_data["header"]["author-nick"] != "") {
$data["nick"] = $feed_data["header"]["author-nick"];
if ($feed_data["header"]["author-avatar"] != "")
$data["photo"] = $feed_data["header"]["author-avatar"];
if ($feed_data["header"]["author-id"] != "")
}
if ($feed_data["header"]["author-avatar"] != "") {
$data["photo"] = ostatus::fix_avatar($feed_data["header"]["author-avatar"], $data["url"]);
}
if ($feed_data["header"]["author-id"] != "") {
$data["alias"] = $feed_data["header"]["author-id"];
if ($feed_data["header"]["author-location"] != "")
}
if ($feed_data["header"]["author-location"] != "") {
$data["location"] = $feed_data["header"]["author-location"];
if ($feed_data["header"]["author-about"] != "")
}
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)
// 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"] != "") {
$data["url"] = $feed_data["header"]["author-link"];
}
/// @todo Fetch location and "about" from the feed as well
return $data;
}

View file

@ -100,7 +100,7 @@ function network_to_name($s, $profile = "") {
$networkname = str_replace($search, $replace, $s);
if ((in_array($s, array(NETWORK_DIASPORA, NETWORK_OSTATUS))) AND ($profile != "")) {
if ((in_array($s, array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) AND ($profile != "")) {
$r = q("SELECT `gserver`.`platform` FROM `gcontact`
INNER JOIN `gserver` ON `gserver`.`nurl` = `gcontact`.`server_url`
WHERE `gcontact`.`nurl` = '%s' AND `platform` != ''",

View file

@ -35,7 +35,7 @@ class ostatus {
*
* @return string fixed avatar path
*/
private static function fix_avatar($avatar, $base) {
public static function fix_avatar($avatar, $base) {
$base_parts = parse_url($base);
// Remove all parts that could create a problem
@ -56,7 +56,11 @@ class ostatus {
$query = isset($parts['query']) ? '?' . $parts['query'] : '';
$fragment = isset($parts['fragment']) ? '#' . $parts['fragment'] : '';
return $scheme.$host.$port.$path.$query.$fragment;
$fixed = $scheme.$host.$port.$path.$query.$fragment;
logger('Base: '.$base.' - Avatar: '.$avatar.' - Fixed: '.$fixed, LOGGER_DATA);
return $fixed;
}
/**
@ -531,7 +535,7 @@ class ostatus {
$item["author-name"] = $orig_author["author-name"];
$item["author-link"] = $orig_author["author-link"];
$item["author-avatar"] = self::fix_avatar($orig_author["author-avatar"], $orig_author["author-link"]);
$item["author-avatar"] = $orig_author["author-avatar"];
$item["body"] = add_page_info_to_body(html2bbcode($orig_body));
$item["created"] = $orig_created;
@ -1104,10 +1108,11 @@ class ostatus {
$arr["owner-name"] = $single_conv->actor->portablecontacts_net->displayName;
$arr["owner-link"] = $actor;
$arr["owner-avatar"] = $single_conv->actor->image->url;
$arr["owner-avatar"] = self::fix_avatar($single_conv->actor->image->url, $arr["owner-link"]);
$arr["author-name"] = $arr["owner-name"];
$arr["author-link"] = $actor;
$arr["author-avatar"] = $single_conv->actor->image->url;
$arr["author-link"] = $arr["owner-link"];
$arr["author-avatar"] = $arr["owner-avatar"];
$arr["body"] = add_page_info_to_body(html2bbcode($single_conv->content));
if (isset($single_conv->status_net->notice_info->source))
@ -1158,11 +1163,11 @@ class ostatus {
$arr["edited"] = $single_conv->object->published;
$arr["author-name"] = $single_conv->object->actor->displayName;
if ($arr["owner-name"] == '')
if ($arr["owner-name"] == '') {
$arr["author-name"] = $single_conv->object->actor->contact->displayName;
}
$arr["author-link"] = $single_conv->object->actor->url;
$arr["author-avatar"] = $single_conv->object->actor->image->url;
$arr["author-avatar"] = self::fix_avatar($single_conv->object->actor->image->url, $arr["author-link"]);
$arr["app"] = $single_conv->object->provider->displayName."#";
//$arr["verb"] = $single_conv->object->verb;