From 97d164f69eaf4ec057d5e93e4fbcb73334718259 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Fri, 16 Nov 2018 18:54:06 +0100 Subject: [PATCH 1/3] Correct self attribute in ATOM feeds Fix for https://github.com/friendica/friendica/issues/6128#issuecomment-439016471 Special case for DFRN to reduce the risk of unintended side effects --- src/Protocol/OStatus.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index d65624664..5c9eed96a 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -1320,7 +1320,13 @@ class OStatus $attributes = ["href" => System::baseUrl() . "/salmon/" . $owner["nick"], "rel" => "http://salmon-protocol.org/ns/salmon-mention"]; XML::addElement($doc, $root, "link", "", $attributes); - $attributes = ["href" => System::baseUrl() . "/dfrn_poll/" . $owner["nick"], + if (empty($_SERVER['REQUEST_URI']) || strpos($_SERVER['REQUEST_URI'], '/dfrn_poll/') !== false) { + $selfUri = "/dfrn_poll/" . $owner["nick"]; + } else { + $selfUri = $_SERVER['REQUEST_URI']; + } + + $attributes = ["href" => System::baseUrl() . $selfUri, "rel" => "self", "type" => "application/atom+xml"]; XML::addElement($doc, $root, "link", "", $attributes); From d85e26d314239acfc7bb7d775a220d21bac18ad5 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Fri, 16 Nov 2018 23:29:26 +0100 Subject: [PATCH 2/3] Refactor header with feed_mode https://github.com/friendica/friendica/pull/6140#issuecomment-439475027 --- src/Protocol/OStatus.php | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index 5c9eed96a..0ea6512d1 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -1263,10 +1263,11 @@ class OStatus * @param object $doc XML document * @param array $owner Contact data of the poster * @param string $filter The related feed filter (activity, posts or comments) + * @param bool $feed_mode Behave like a regular feed for users if true * * @return object header root element */ - private static function addHeader(DOMDocument $doc, array $owner, $filter) + private static function addHeader(DOMDocument $doc, array $owner, $filter, $feed_mode = false) { $a = get_app(); @@ -1283,10 +1284,19 @@ class OStatus $root->setAttribute("xmlns:mastodon", NAMESPACE_MASTODON); $title = ''; + $selfUri = '/feed/' . $owner["nick"] . '/'; switch ($filter) { - case 'activity': $title = L10n::t('%s\'s timeline', $owner['name']); break; - case 'posts' : $title = L10n::t('%s\'s posts' , $owner['name']); break; - case 'comments': $title = L10n::t('%s\'s comments', $owner['name']); break; + case 'activity': + $title = L10n::t('%s\'s timeline', $owner['name']); + $selfUri .= $filter; + break; + case 'posts': + $title = L10n::t('%s\'s posts', $owner['name']); + break; + case 'comments': + $title = L10n::t('%s\'s comments', $owner['name']); + $selfUri .= $filter; + break; } $attributes = ["uri" => "https://friendi.ca", "version" => FRIENDICA_VERSION . "-" . DB_UPDATE_VERSION]; @@ -1320,14 +1330,10 @@ class OStatus $attributes = ["href" => System::baseUrl() . "/salmon/" . $owner["nick"], "rel" => "http://salmon-protocol.org/ns/salmon-mention"]; XML::addElement($doc, $root, "link", "", $attributes); - if (empty($_SERVER['REQUEST_URI']) || strpos($_SERVER['REQUEST_URI'], '/dfrn_poll/') !== false) { + if (!$feed_mode) { $selfUri = "/dfrn_poll/" . $owner["nick"]; - } else { - $selfUri = $_SERVER['REQUEST_URI']; } - - $attributes = ["href" => System::baseUrl() . $selfUri, - "rel" => "self", "type" => "application/atom+xml"]; + $attributes = ["href" => System::baseUrl() . $selfUri, "rel" => "self", "type" => "application/atom+xml"]; XML::addElement($doc, $root, "link", "", $attributes); if ($owner['account-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) { @@ -2212,7 +2218,7 @@ class OStatus $doc = new DOMDocument('1.0', 'utf-8'); $doc->formatOutput = true; - $root = self::addHeader($doc, $owner, $filter); + $root = self::addHeader($doc, $owner, $filter, $feed_mode); foreach ($items as $item) { if (Config::get('system', 'ostatus_debug')) { From bd19e93c094b85bc2fb40044d972dcb98ce53d7c Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 17 Nov 2018 01:36:54 +0100 Subject: [PATCH 3/3] Minor code relocation https://github.com/friendica/friendica/pull/6144/files#r234385033 --- src/Protocol/OStatus.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index 0ea6512d1..a6a5d061c 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -1299,6 +1299,10 @@ class OStatus break; } + if (!$feed_mode) { + $selfUri = "/dfrn_poll/" . $owner["nick"]; + } + $attributes = ["uri" => "https://friendi.ca", "version" => FRIENDICA_VERSION . "-" . DB_UPDATE_VERSION]; XML::addElement($doc, $root, "generator", FRIENDICA_PLATFORM, $attributes); XML::addElement($doc, $root, "id", System::baseUrl() . "/profile/" . $owner["nick"]); @@ -1330,9 +1334,6 @@ class OStatus $attributes = ["href" => System::baseUrl() . "/salmon/" . $owner["nick"], "rel" => "http://salmon-protocol.org/ns/salmon-mention"]; XML::addElement($doc, $root, "link", "", $attributes); - if (!$feed_mode) { - $selfUri = "/dfrn_poll/" . $owner["nick"]; - } $attributes = ["href" => System::baseUrl() . $selfUri, "rel" => "self", "type" => "application/atom+xml"]; XML::addElement($doc, $root, "link", "", $attributes);