Merge pull request #6106 from MrPetovan/bug/6103-fix-webfinger-ostatus
Fix webfinger and OStatus support
This commit is contained in:
commit
2f9411f68f
5 changed files with 88 additions and 66 deletions
|
@ -27,7 +27,7 @@ function follow_post(App $a)
|
||||||
|
|
||||||
$uid = local_user();
|
$uid = local_user();
|
||||||
$url = Strings::escapeTags(trim($_REQUEST['url']));
|
$url = Strings::escapeTags(trim($_REQUEST['url']));
|
||||||
$return_path = 'contacts';
|
$return_path = 'follow?url=' . urlencode($url);
|
||||||
|
|
||||||
// Makes the connection request for friendica contacts easier
|
// Makes the connection request for friendica contacts easier
|
||||||
// This is just a precaution if maybe this page is called somewhere directly via POST
|
// This is just a precaution if maybe this page is called somewhere directly via POST
|
||||||
|
|
|
@ -115,6 +115,10 @@ class Logger extends BaseObject
|
||||||
$processId = $a->process_id;
|
$processId = $a->process_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!is_string($msg)) {
|
||||||
|
$msg = var_export($msg, true);
|
||||||
|
}
|
||||||
|
|
||||||
$callers = debug_backtrace();
|
$callers = debug_backtrace();
|
||||||
$logline = sprintf("%s@\t%s:\t%s:\t%s\t%s\t%s\n",
|
$logline = sprintf("%s@\t%s:\t%s:\t%s\t%s\t%s\n",
|
||||||
DateTimeFormat::utcNow(),
|
DateTimeFormat::utcNow(),
|
||||||
|
|
|
@ -8,13 +8,13 @@ use Friendica\BaseObject;
|
||||||
use Friendica\Content\Pager;
|
use Friendica\Content\Pager;
|
||||||
use Friendica\Core\Addon;
|
use Friendica\Core\Addon;
|
||||||
use Friendica\Core\Config;
|
use Friendica\Core\Config;
|
||||||
|
use Friendica\Core\Hook;
|
||||||
use Friendica\Core\L10n;
|
use Friendica\Core\L10n;
|
||||||
use Friendica\Core\Logger;
|
use Friendica\Core\Logger;
|
||||||
use Friendica\Core\Protocol;
|
use Friendica\Core\Protocol;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Core\Worker;
|
use Friendica\Core\Worker;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\Model\Profile;
|
|
||||||
use Friendica\Network\Probe;
|
use Friendica\Network\Probe;
|
||||||
use Friendica\Object\Image;
|
use Friendica\Object\Image;
|
||||||
use Friendica\Protocol\ActivityPub;
|
use Friendica\Protocol\ActivityPub;
|
||||||
|
@ -1606,7 +1606,7 @@ class Contact extends BaseObject
|
||||||
|
|
||||||
$arr = ['url' => $url, 'contact' => []];
|
$arr = ['url' => $url, 'contact' => []];
|
||||||
|
|
||||||
Addon::callHooks('follow', $arr);
|
Hook::callAll('follow', $arr);
|
||||||
|
|
||||||
if (empty($arr)) {
|
if (empty($arr)) {
|
||||||
$result['message'] = L10n::t('The contact could not be added. Please check the relevant network credentials in your Settings -> Social Networks page.');
|
$result['message'] = L10n::t('The contact could not be added. Please check the relevant network credentials in your Settings -> Social Networks page.');
|
||||||
|
|
|
@ -318,10 +318,10 @@ class Probe
|
||||||
*
|
*
|
||||||
* @return array uri data
|
* @return array uri data
|
||||||
*/
|
*/
|
||||||
public static function uri($uri, $network = "", $uid = -1, $cache = true)
|
public static function uri($uri, $network = '', $uid = -1, $cache = true)
|
||||||
{
|
{
|
||||||
if ($cache) {
|
if ($cache) {
|
||||||
$result = Cache::get("Probe::uri:".$network.":".$uri);
|
$result = Cache::get('Probe::uri:' . $network . ':' . $uri);
|
||||||
if (!is_null($result)) {
|
if (!is_null($result)) {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
@ -343,28 +343,28 @@ class Probe
|
||||||
$data = $ap_profile;
|
$data = $ap_profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($data["url"])) {
|
if (!isset($data['url'])) {
|
||||||
$data["url"] = $uri;
|
$data['url'] = $uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (x($data, "photo")) {
|
if (x($data, 'photo')) {
|
||||||
$data["baseurl"] = Network::getUrlMatch(Strings::normaliseLink(defaults($data, "baseurl", "")), Strings::normaliseLink($data["photo"]));
|
$data['baseurl'] = Network::getUrlMatch(Strings::normaliseLink(defaults($data, 'baseurl', '')), Strings::normaliseLink($data['photo']));
|
||||||
} else {
|
} else {
|
||||||
$data["photo"] = System::baseUrl().'/images/person-300.jpg';
|
$data['photo'] = System::baseUrl() . '/images/person-300.jpg';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($data["name"])) {
|
if (empty($data['name'])) {
|
||||||
if (!empty($data["nick"])) {
|
if (!empty($data['nick'])) {
|
||||||
$data["name"] = $data["nick"];
|
$data['name'] = $data['nick'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!x($data, "name")) {
|
if (!x($data, 'name')) {
|
||||||
$data["name"] = $data["url"];
|
$data['name'] = $data['url'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($data["nick"])) {
|
if (empty($data['nick'])) {
|
||||||
$data["nick"] = strtolower($data["name"]);
|
$data['nick'] = strtolower($data['name']);
|
||||||
|
|
||||||
if (strpos($data['nick'], ' ')) {
|
if (strpos($data['nick'], ' ')) {
|
||||||
$data['nick'] = trim(substr($data['nick'], 0, strpos($data['nick'], ' ')));
|
$data['nick'] = trim(substr($data['nick'], 0, strpos($data['nick'], ' ')));
|
||||||
|
@ -372,42 +372,44 @@ class Probe
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty(self::$baseurl)) {
|
if (!empty(self::$baseurl)) {
|
||||||
$data["baseurl"] = self::$baseurl;
|
$data['baseurl'] = self::$baseurl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($data["network"])) {
|
if (empty($data['network'])) {
|
||||||
$data["network"] = Protocol::PHANTOM;
|
$data['network'] = Protocol::PHANTOM;
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = self::rearrangeData($data);
|
$data = self::rearrangeData($data);
|
||||||
|
|
||||||
// Only store into the cache if the value seems to be valid
|
// Only store into the cache if the value seems to be valid
|
||||||
if (!in_array($data['network'], [Protocol::PHANTOM, Protocol::MAIL])) {
|
if (!in_array($data['network'], [Protocol::PHANTOM, Protocol::MAIL])) {
|
||||||
Cache::set("Probe::uri:".$network.":".$uri, $data, Cache::DAY);
|
Cache::set('Probe::uri:' . $network . ':' . $uri, $data, Cache::DAY);
|
||||||
|
|
||||||
/// @todo temporary fix - we need a real contact update function that updates only changing fields
|
/// @todo temporary fix - we need a real contact update function that updates only changing fields
|
||||||
/// The biggest problem is the avatar picture that could have a reduced image size.
|
/// The biggest problem is the avatar picture that could have a reduced image size.
|
||||||
/// It should only be updated if the existing picture isn't existing anymore.
|
/// It should only be updated if the existing picture isn't existing anymore.
|
||||||
/// We only update the contact when it is no probing for a specific network.
|
/// We only update the contact when it is no probing for a specific network.
|
||||||
if (($data['network'] != Protocol::FEED)
|
if (($data['network'] != Protocol::FEED)
|
||||||
&& ($network == "")
|
&& ($network == '')
|
||||||
&& $data["name"]
|
&& $data['name']
|
||||||
&& $data["nick"]
|
&& $data['nick']
|
||||||
&& $data["url"]
|
&& $data['url']
|
||||||
&& $data["addr"]
|
&& $data['addr']
|
||||||
&& $data["poll"]
|
&& $data['poll']
|
||||||
) {
|
) {
|
||||||
$fields = ['name' => $data['name'],
|
$fields = [
|
||||||
'nick' => $data['nick'],
|
'name' => $data['name'],
|
||||||
'url' => $data['url'],
|
'nick' => $data['nick'],
|
||||||
'addr' => $data['addr'],
|
'url' => $data['url'],
|
||||||
'photo' => $data['photo'],
|
'addr' => $data['addr'],
|
||||||
'keywords' => $data['keywords'],
|
'photo' => $data['photo'],
|
||||||
'location' => $data['location'],
|
'keywords' => $data['keywords'],
|
||||||
'about' => $data['about'],
|
'location' => $data['location'],
|
||||||
'notify' => $data['notify'],
|
'about' => $data['about'],
|
||||||
'network' => $data['network'],
|
'notify' => $data['notify'],
|
||||||
'server_url' => $data['baseurl']];
|
'network' => $data['network'],
|
||||||
|
'server_url' => $data['baseurl']
|
||||||
|
];
|
||||||
|
|
||||||
// This doesn't cover the case when a community isn't a community anymore
|
// This doesn't cover the case when a community isn't a community anymore
|
||||||
if (!empty($data['community']) && $data['community']) {
|
if (!empty($data['community']) && $data['community']) {
|
||||||
|
@ -427,7 +429,7 @@ class Probe
|
||||||
|
|
||||||
$fields['updated'] = DateTimeFormat::utcNow();
|
$fields['updated'] = DateTimeFormat::utcNow();
|
||||||
|
|
||||||
$condition = ['nurl' => Strings::normaliseLink($data["url"])];
|
$condition = ['nurl' => Strings::normaliseLink($data['url'])];
|
||||||
|
|
||||||
$old_fields = DBA::selectFirst('gcontact', $fieldnames, $condition);
|
$old_fields = DBA::selectFirst('gcontact', $fieldnames, $condition);
|
||||||
|
|
||||||
|
@ -444,25 +446,27 @@ class Probe
|
||||||
|
|
||||||
DBA::update('gcontact', $fields, $condition, $old_fields);
|
DBA::update('gcontact', $fields, $condition, $old_fields);
|
||||||
|
|
||||||
$fields = ['name' => $data['name'],
|
$fields = [
|
||||||
'nick' => $data['nick'],
|
'name' => $data['name'],
|
||||||
'url' => $data['url'],
|
'nick' => $data['nick'],
|
||||||
'addr' => $data['addr'],
|
'url' => $data['url'],
|
||||||
'alias' => $data['alias'],
|
'addr' => $data['addr'],
|
||||||
'keywords' => $data['keywords'],
|
'alias' => $data['alias'],
|
||||||
'location' => $data['location'],
|
'keywords' => $data['keywords'],
|
||||||
'about' => $data['about'],
|
'location' => $data['location'],
|
||||||
'batch' => $data['batch'],
|
'about' => $data['about'],
|
||||||
'notify' => $data['notify'],
|
'batch' => $data['batch'],
|
||||||
'poll' => $data['poll'],
|
'notify' => $data['notify'],
|
||||||
'request' => $data['request'],
|
'poll' => $data['poll'],
|
||||||
'confirm' => $data['confirm'],
|
'request' => $data['request'],
|
||||||
'poco' => $data['poco'],
|
'confirm' => $data['confirm'],
|
||||||
'network' => $data['network'],
|
'poco' => $data['poco'],
|
||||||
'pubkey' => $data['pubkey'],
|
'network' => $data['network'],
|
||||||
'priority' => $data['priority'],
|
'pubkey' => $data['pubkey'],
|
||||||
'writable' => true,
|
'priority' => $data['priority'],
|
||||||
'rel' => Contact::SHARING];
|
'writable' => true,
|
||||||
|
'rel' => Contact::SHARING
|
||||||
|
];
|
||||||
|
|
||||||
$fieldnames = [];
|
$fieldnames = [];
|
||||||
|
|
||||||
|
@ -474,7 +478,7 @@ class Probe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$condition = ['nurl' => Strings::normaliseLink($data["url"]), 'self' => false, 'uid' => 0];
|
$condition = ['nurl' => Strings::normaliseLink($data['url']), 'self' => false, 'uid' => 0];
|
||||||
|
|
||||||
// "$old_fields" will return a "false" when the contact doesn't exist.
|
// "$old_fields" will return a "false" when the contact doesn't exist.
|
||||||
// This won't trigger an insert. This is intended, since we only need
|
// This won't trigger an insert. This is intended, since we only need
|
||||||
|
@ -575,7 +579,7 @@ class Probe
|
||||||
{
|
{
|
||||||
$parts = parse_url($uri);
|
$parts = parse_url($uri);
|
||||||
|
|
||||||
if (!empty($parts["scheme"]) && !empty($parts["host"]) && !empty($parts["path"])) {
|
if (!empty($parts["scheme"]) && !empty($parts["host"])) {
|
||||||
$host = $parts["host"];
|
$host = $parts["host"];
|
||||||
if (!empty($parts["port"])) {
|
if (!empty($parts["port"])) {
|
||||||
$host .= ':'.$parts["port"];
|
$host .= ':'.$parts["port"];
|
||||||
|
@ -590,7 +594,7 @@ class Probe
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$path_parts = explode("/", trim($parts["path"], "/"));
|
$path_parts = explode("/", trim(defaults($parts, 'path', ''), "/"));
|
||||||
|
|
||||||
while (!$lrdd && (sizeof($path_parts) > 1)) {
|
while (!$lrdd && (sizeof($path_parts) > 1)) {
|
||||||
$host .= "/".array_shift($path_parts);
|
$host .= "/".array_shift($path_parts);
|
||||||
|
@ -979,7 +983,9 @@ class Probe
|
||||||
{
|
{
|
||||||
$hcard_url = "";
|
$hcard_url = "";
|
||||||
$data = [];
|
$data = [];
|
||||||
foreach ($webfinger["links"] as $link) {
|
// The array is reversed to take into account the order of preference for same-rel links
|
||||||
|
// See: https://tools.ietf.org/html/rfc7033#section-4.4.4
|
||||||
|
foreach (array_reverse($webfinger["links"]) as $link) {
|
||||||
if (($link["rel"] == NAMESPACE_DFRN) && !empty($link["href"])) {
|
if (($link["rel"] == NAMESPACE_DFRN) && !empty($link["href"])) {
|
||||||
$data["network"] = Protocol::DFRN;
|
$data["network"] = Protocol::DFRN;
|
||||||
} elseif (($link["rel"] == NAMESPACE_FEED) && !empty($link["href"])) {
|
} elseif (($link["rel"] == NAMESPACE_FEED) && !empty($link["href"])) {
|
||||||
|
@ -1182,7 +1188,9 @@ class Probe
|
||||||
{
|
{
|
||||||
$hcard_url = "";
|
$hcard_url = "";
|
||||||
$data = [];
|
$data = [];
|
||||||
foreach ($webfinger["links"] as $link) {
|
// The array is reversed to take into account the order of preference for same-rel links
|
||||||
|
// See: https://tools.ietf.org/html/rfc7033#section-4.4.4
|
||||||
|
foreach (array_reverse($webfinger["links"]) as $link) {
|
||||||
if (($link["rel"] == "http://microformats.org/profile/hcard") && !empty($link["href"])) {
|
if (($link["rel"] == "http://microformats.org/profile/hcard") && !empty($link["href"])) {
|
||||||
$hcard_url = $link["href"];
|
$hcard_url = $link["href"];
|
||||||
} elseif (($link["rel"] == "http://joindiaspora.com/seed_location") && !empty($link["href"])) {
|
} elseif (($link["rel"] == "http://joindiaspora.com/seed_location") && !empty($link["href"])) {
|
||||||
|
@ -1283,7 +1291,9 @@ class Probe
|
||||||
|
|
||||||
$pubkey = "";
|
$pubkey = "";
|
||||||
if (is_array($webfinger["links"])) {
|
if (is_array($webfinger["links"])) {
|
||||||
foreach ($webfinger["links"] as $link) {
|
// The array is reversed to take into account the order of preference for same-rel links
|
||||||
|
// See: https://tools.ietf.org/html/rfc7033#section-4.4.4
|
||||||
|
foreach (array_reverse($webfinger["links"]) as $link) {
|
||||||
if (($link["rel"] == "http://webfinger.net/rel/profile-page")
|
if (($link["rel"] == "http://webfinger.net/rel/profile-page")
|
||||||
&& (defaults($link, "type", "") == "text/html")
|
&& (defaults($link, "type", "") == "text/html")
|
||||||
&& ($link["href"] != "")
|
&& ($link["href"] != "")
|
||||||
|
@ -1447,7 +1457,9 @@ class Probe
|
||||||
private static function pumpio($webfinger, $addr)
|
private static function pumpio($webfinger, $addr)
|
||||||
{
|
{
|
||||||
$data = [];
|
$data = [];
|
||||||
foreach ($webfinger["links"] as $link) {
|
// The array is reversed to take into account the order of preference for same-rel links
|
||||||
|
// See: https://tools.ietf.org/html/rfc7033#section-4.4.4
|
||||||
|
foreach (array_reverse($webfinger["links"]) as $link) {
|
||||||
if (($link["rel"] == "http://webfinger.net/rel/profile-page")
|
if (($link["rel"] == "http://webfinger.net/rel/profile-page")
|
||||||
&& (defaults($link, "type", "") == "text/html")
|
&& (defaults($link, "type", "") == "text/html")
|
||||||
&& ($link["href"] != "")
|
&& ($link["href"] != "")
|
||||||
|
|
|
@ -123,7 +123,13 @@ class Feed {
|
||||||
$author["author-name"] = $value;
|
$author["author-name"] = $value;
|
||||||
}
|
}
|
||||||
if ($simulate) {
|
if ($simulate) {
|
||||||
$author["author-id"] = XML::getFirstNodeValue($xpath, '/atom:feed/atom:author/atom:uri/text()');
|
$author["author-id"] = XML::getFirstNodeValue($xpath, '/atom:feed/atom:author/atom:id/text()');
|
||||||
|
|
||||||
|
// See https://tools.ietf.org/html/rfc4287#section-3.2.2
|
||||||
|
$value = XML::getFirstNodeValue($xpath, 'atom:author/atom:uri/text()');
|
||||||
|
if ($value != "") {
|
||||||
|
$author["author-link"] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
$value = XML::getFirstNodeValue($xpath, 'atom:author/poco:preferredUsername/text()');
|
$value = XML::getFirstNodeValue($xpath, 'atom:author/poco:preferredUsername/text()');
|
||||||
if ($value != "") {
|
if ($value != "") {
|
||||||
|
|
Loading…
Reference in a new issue