From 8703fe4032f91efa8649f0ad3f6436a2620b42dd Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 10 Nov 2018 08:17:33 -0500 Subject: [PATCH 1/7] Accept data structure in Logger::devLog --- src/Core/Logger.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Core/Logger.php b/src/Core/Logger.php index c9253a83e9..f9cb8cde01 100644 --- a/src/Core/Logger.php +++ b/src/Core/Logger.php @@ -115,6 +115,10 @@ class Logger extends BaseObject $processId = $a->process_id; } + if (!is_string($msg)) { + $msg = var_export($msg, true); + } + $callers = debug_backtrace(); $logline = sprintf("%s@\t%s:\t%s:\t%s\t%s\t%s\n", DateTimeFormat::utcNow(), From aaae7b56dfa658eb04ae757caaff4e591a684f8c Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 10 Nov 2018 08:18:16 -0500 Subject: [PATCH 2/7] Replace obsolete Addon::callHooks call with Hook::callAll in Model\Contact --- src/Model/Contact.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 8e150b5065..1c90d0c815 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -8,13 +8,13 @@ use Friendica\BaseObject; use Friendica\Content\Pager; use Friendica\Core\Addon; use Friendica\Core\Config; +use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBA; -use Friendica\Model\Profile; use Friendica\Network\Probe; use Friendica\Object\Image; use Friendica\Protocol\ActivityPub; @@ -1606,7 +1606,7 @@ class Contact extends BaseObject $arr = ['url' => $url, 'contact' => []]; - Addon::callHooks('follow', $arr); + Hook::callAll('follow', $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.'); From 10a8be79430c5b3550fa6097171d9663320208f8 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 10 Nov 2018 08:22:47 -0500 Subject: [PATCH 3/7] Accept URLs with no trailing slash in Probe::uri --- src/Network/Probe.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Network/Probe.php b/src/Network/Probe.php index d870e06f97..aa770b92ee 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -575,7 +575,7 @@ class Probe { $parts = parse_url($uri); - if (!empty($parts["scheme"]) && !empty($parts["host"]) && !empty($parts["path"])) { + if (!empty($parts["scheme"]) && !empty($parts["host"])) { $host = $parts["host"]; if (!empty($parts["port"])) { $host .= ':'.$parts["port"]; @@ -590,7 +590,7 @@ class Probe return []; } - $path_parts = explode("/", trim($parts["path"], "/")); + $path_parts = explode("/", trim(defaults($parts, 'path', ''), "/")); while (!$lrdd && (sizeof($path_parts) > 1)) { $host .= "/".array_shift($path_parts); From 94a71d9ffc3e0294e01be07a55183ae8a9986406 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 10 Nov 2018 08:23:11 -0500 Subject: [PATCH 4/7] Honor preference order in webfinger links --- src/Network/Probe.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Network/Probe.php b/src/Network/Probe.php index aa770b92ee..16ae0eff1d 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -979,7 +979,9 @@ class Probe { $hcard_url = ""; $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"])) { $data["network"] = Protocol::DFRN; } elseif (($link["rel"] == NAMESPACE_FEED) && !empty($link["href"])) { @@ -1182,7 +1184,9 @@ class Probe { $hcard_url = ""; $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"])) { $hcard_url = $link["href"]; } elseif (($link["rel"] == "http://joindiaspora.com/seed_location") && !empty($link["href"])) { @@ -1283,7 +1287,9 @@ class Probe $pubkey = ""; 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") && (defaults($link, "type", "") == "text/html") && ($link["href"] != "") @@ -1447,7 +1453,9 @@ class Probe private static function pumpio($webfinger, $addr) { $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") && (defaults($link, "type", "") == "text/html") && ($link["href"] != "") From a6a3c268bb399f52f0c091659ebdfc31a62b832d Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 10 Nov 2018 08:24:10 -0500 Subject: [PATCH 5/7] Use atom:author/atom:uri as profile-link in Feed::import - Use atom:author/atom:id as profile-id --- src/Protocol/Feed.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Protocol/Feed.php b/src/Protocol/Feed.php index 71ebe5506b..d63b57b8c9 100644 --- a/src/Protocol/Feed.php +++ b/src/Protocol/Feed.php @@ -123,7 +123,13 @@ class Feed { $author["author-name"] = $value; } 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()'); if ($value != "") { From 7242b706f0c77847f95e3a0fd01fb6b6efffba7a Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 10 Nov 2018 08:24:31 -0500 Subject: [PATCH 6/7] Improve return path in mod/follow --- mod/follow.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/follow.php b/mod/follow.php index 08f664d393..b92424c208 100644 --- a/mod/follow.php +++ b/mod/follow.php @@ -27,7 +27,7 @@ function follow_post(App $a) $uid = local_user(); $url = Strings::escapeTags(trim($_REQUEST['url'])); - $return_path = 'contacts'; + $return_path = 'follow?url=' . urlencode($url); // Makes the connection request for friendica contacts easier // This is just a precaution if maybe this page is called somewhere directly via POST From 1892462920f947f921322eb1f2a4cf1999ab1f00 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 10 Nov 2018 08:24:53 -0500 Subject: [PATCH 7/7] Fix formatting in Probe::uri --- src/Network/Probe.php | 116 ++++++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 56 deletions(-) diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 16ae0eff1d..9c57d624f8 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -318,10 +318,10 @@ class Probe * * @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) { - $result = Cache::get("Probe::uri:".$network.":".$uri); + $result = Cache::get('Probe::uri:' . $network . ':' . $uri); if (!is_null($result)) { return $result; } @@ -343,28 +343,28 @@ class Probe $data = $ap_profile; } - if (!isset($data["url"])) { - $data["url"] = $uri; + if (!isset($data['url'])) { + $data['url'] = $uri; } - if (x($data, "photo")) { - $data["baseurl"] = Network::getUrlMatch(Strings::normaliseLink(defaults($data, "baseurl", "")), Strings::normaliseLink($data["photo"])); + if (x($data, 'photo')) { + $data['baseurl'] = Network::getUrlMatch(Strings::normaliseLink(defaults($data, 'baseurl', '')), Strings::normaliseLink($data['photo'])); } else { - $data["photo"] = System::baseUrl().'/images/person-300.jpg'; + $data['photo'] = System::baseUrl() . '/images/person-300.jpg'; } - if (empty($data["name"])) { - if (!empty($data["nick"])) { - $data["name"] = $data["nick"]; + if (empty($data['name'])) { + if (!empty($data['nick'])) { + $data['name'] = $data['nick']; } - if (!x($data, "name")) { - $data["name"] = $data["url"]; + if (!x($data, 'name')) { + $data['name'] = $data['url']; } } - if (empty($data["nick"])) { - $data["nick"] = strtolower($data["name"]); + if (empty($data['nick'])) { + $data['nick'] = strtolower($data['name']); if (strpos($data['nick'], ' ')) { $data['nick'] = trim(substr($data['nick'], 0, strpos($data['nick'], ' '))); @@ -372,42 +372,44 @@ class Probe } if (!empty(self::$baseurl)) { - $data["baseurl"] = self::$baseurl; + $data['baseurl'] = self::$baseurl; } - if (empty($data["network"])) { - $data["network"] = Protocol::PHANTOM; + if (empty($data['network'])) { + $data['network'] = Protocol::PHANTOM; } $data = self::rearrangeData($data); // Only store into the cache if the value seems to be valid 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 /// 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. /// We only update the contact when it is no probing for a specific network. if (($data['network'] != Protocol::FEED) - && ($network == "") - && $data["name"] - && $data["nick"] - && $data["url"] - && $data["addr"] - && $data["poll"] + && ($network == '') + && $data['name'] + && $data['nick'] + && $data['url'] + && $data['addr'] + && $data['poll'] ) { - $fields = ['name' => $data['name'], - 'nick' => $data['nick'], - 'url' => $data['url'], - 'addr' => $data['addr'], - 'photo' => $data['photo'], - 'keywords' => $data['keywords'], - 'location' => $data['location'], - 'about' => $data['about'], - 'notify' => $data['notify'], - 'network' => $data['network'], - 'server_url' => $data['baseurl']]; + $fields = [ + 'name' => $data['name'], + 'nick' => $data['nick'], + 'url' => $data['url'], + 'addr' => $data['addr'], + 'photo' => $data['photo'], + 'keywords' => $data['keywords'], + 'location' => $data['location'], + 'about' => $data['about'], + 'notify' => $data['notify'], + 'network' => $data['network'], + 'server_url' => $data['baseurl'] + ]; // This doesn't cover the case when a community isn't a community anymore if (!empty($data['community']) && $data['community']) { @@ -427,7 +429,7 @@ class Probe $fields['updated'] = DateTimeFormat::utcNow(); - $condition = ['nurl' => Strings::normaliseLink($data["url"])]; + $condition = ['nurl' => Strings::normaliseLink($data['url'])]; $old_fields = DBA::selectFirst('gcontact', $fieldnames, $condition); @@ -444,25 +446,27 @@ class Probe DBA::update('gcontact', $fields, $condition, $old_fields); - $fields = ['name' => $data['name'], - 'nick' => $data['nick'], - 'url' => $data['url'], - 'addr' => $data['addr'], - 'alias' => $data['alias'], - 'keywords' => $data['keywords'], - 'location' => $data['location'], - 'about' => $data['about'], - 'batch' => $data['batch'], - 'notify' => $data['notify'], - 'poll' => $data['poll'], - 'request' => $data['request'], - 'confirm' => $data['confirm'], - 'poco' => $data['poco'], - 'network' => $data['network'], - 'pubkey' => $data['pubkey'], - 'priority' => $data['priority'], - 'writable' => true, - 'rel' => Contact::SHARING]; + $fields = [ + 'name' => $data['name'], + 'nick' => $data['nick'], + 'url' => $data['url'], + 'addr' => $data['addr'], + 'alias' => $data['alias'], + 'keywords' => $data['keywords'], + 'location' => $data['location'], + 'about' => $data['about'], + 'batch' => $data['batch'], + 'notify' => $data['notify'], + 'poll' => $data['poll'], + 'request' => $data['request'], + 'confirm' => $data['confirm'], + 'poco' => $data['poco'], + 'network' => $data['network'], + 'pubkey' => $data['pubkey'], + 'priority' => $data['priority'], + 'writable' => true, + 'rel' => Contact::SHARING + ]; $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. // This won't trigger an insert. This is intended, since we only need