From 69223cad1d87797a95894fb0f72fcb62d624073a Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Sat, 20 Feb 2016 17:32:35 -0800 Subject: [PATCH] return matching author url --- lib/Formats/Mf2.php | 16 ++++++++++---- tests/AuthorTest.php | 14 ++++++++++++ .../about-with-multiple-urls | 22 +++++++++++++++++++ ...uthor-is-url-to-h-card-with-multiple-links | 20 +++++++++++++++++ 4 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 tests/data/author.example.com/about-with-multiple-urls create mode 100644 tests/data/author.example.com/h-entry-author-is-url-to-h-card-with-multiple-links diff --git a/lib/Formats/Mf2.php b/lib/Formats/Mf2.php index 4d308c5..fd7b23f 100644 --- a/lib/Formats/Mf2.php +++ b/lib/Formats/Mf2.php @@ -118,7 +118,7 @@ class Mf2 { return $data; } - private static function parseHCard($item, \p3k\HTTP $http) { + private static function parseHCard($item, \p3k\HTTP $http, $authorURL=false) { $data = [ 'type' => 'card', 'name' => null, @@ -128,8 +128,16 @@ class Mf2 { $properties = ['url','name','photo']; foreach($properties as $p) { - if($v = self::getPlaintext($item, $p)) + if($p == 'url' && $authorURL) { + // If there is a matching author URL, use that one + foreach($item['properties']['url'] as $url) { + if($url == $authorURL) { + $data['url'] = $url; + } + } + } else if($v = self::getPlaintext($item, $p)) { $data[$p] = $v; + } } return $data; @@ -195,7 +203,7 @@ class Mf2 { and array_key_exists('uid', $i['properties']) and in_array($authorPage, $i['properties']['uid']) ) { - return self::parseHCard($i, $http); + return self::parseHCard($i, $http, $authorPage); } // 7.3 "else if author-page has 1+ h-card with url property which matches the href of a rel-me link on the author-page" @@ -204,7 +212,7 @@ class Mf2 { and array_key_exists('url', $i['properties']) and count(array_intersect($i['properties']['url'], $relMeLinks)) > 0 ) { - return self::parseHCard($i, $http); + return self::parseHCard($i, $http, $authorPage); } } diff --git a/tests/AuthorTest.php b/tests/AuthorTest.php index ed3229f..280417d 100644 --- a/tests/AuthorTest.php +++ b/tests/AuthorTest.php @@ -83,6 +83,20 @@ class AuthorTest extends PHPUnit_Framework_TestCase { $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo); } + public function testHEntryAuthorIsUrlToHCardWithMultipleLinks() { + $url = 'http://author.example.com/h-entry-author-is-url-to-h-card-with-multiple-links'; + $response = $this->parse(['url' => $url]); + + $body = $response->getContent(); + + $this->assertEquals(200, $response->getStatusCode()); + $data = json_decode($body); + + $this->assertEquals('http://author.example.com/about-with-multiple-urls', $data->data->author->url); + $this->assertEquals('Author Full Name', $data->data->author->name); + $this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo); + } + public function testHEntryHasHCardAndUrlAuthor() { $url = 'http://author.example.com/h-entry-has-h-card-and-url-author'; $response = $this->parse(['url' => $url]); diff --git a/tests/data/author.example.com/about-with-multiple-urls b/tests/data/author.example.com/about-with-multiple-urls new file mode 100644 index 0000000..b25bdff --- /dev/null +++ b/tests/data/author.example.com/about-with-multiple-urls @@ -0,0 +1,22 @@ +HTTP/1.1 200 OK +Server: Apache +Date: Wed, 09 Dec 2015 03:29:14 GMT +Content-Type: text/html; charset=utf-8 + + + + + + Author + + + +
+

Author Full Name

+ xmpp + Me + +
+ + + \ No newline at end of file diff --git a/tests/data/author.example.com/h-entry-author-is-url-to-h-card-with-multiple-links b/tests/data/author.example.com/h-entry-author-is-url-to-h-card-with-multiple-links new file mode 100644 index 0000000..de6a124 --- /dev/null +++ b/tests/data/author.example.com/h-entry-author-is-url-to-h-card-with-multiple-links @@ -0,0 +1,20 @@ +HTTP/1.1 200 OK +Server: Apache +Date: Wed, 09 Dec 2015 03:29:14 GMT +Content-Type: text/html; charset=utf-8 + + + + + + Example + + + +
+ Author +

Hello World

+
+ + + \ No newline at end of file