From 15743d411dc285530e016c6935f4bc6c1779b5ee Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Sat, 11 Nov 2017 10:37:29 -0800 Subject: [PATCH] Find author when author is a property of the h-feed closes #32 --- lib/XRay/Formats/Mf2.php | 15 ++++++++ tests/FeedTest.php | 20 ++++++++++ .../feed.example.com/h-feed-with-child-author | 37 +++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 tests/data/feed.example.com/h-feed-with-child-author diff --git a/lib/XRay/Formats/Mf2.php b/lib/XRay/Formats/Mf2.php index f8ffd1a..5afd6ba 100644 --- a/lib/XRay/Formats/Mf2.php +++ b/lib/XRay/Formats/Mf2.php @@ -675,6 +675,21 @@ class Mf2 extends Format { } } + // Also check the "author" property + // (for finding the author of an h-feed's children when the author is the p-author property of the h-feed) + if(isset($i['properties']['author'])) { + foreach($i['properties']['author'] as $ic) { + if(self::isHCard($ic)) { + + if(array_key_exists('url', $ic['properties']) + and in_array($authorPage, $ic['properties']['url']) + ) { + return self::parseAsHCard($ic, $http)['data']; + } + + } + } + } } } diff --git a/tests/FeedTest.php b/tests/FeedTest.php index f00aaaf..738084d 100644 --- a/tests/FeedTest.php +++ b/tests/FeedTest.php @@ -87,6 +87,26 @@ class FeedTest extends PHPUnit_Framework_TestCase { $this->assertEquals('Four', $data->items[3]->name); } + public function testTopLevelHFeedWithChildAuthor() { + $url = 'http://feed.example.com/h-feed-with-child-author'; + $response = $this->parse(['url' => $url, 'expect' => 'feed']); + + $body = $response->getContent(); + $this->assertEquals(200, $response->getStatusCode()); + $data = json_decode($body)->data; + + $this->assertEquals('feed', $data->type); + $this->assertEquals(4, count($data->items)); + $this->assertEquals('One', $data->items[0]->name); + $this->assertEquals('Two', $data->items[1]->name); + $this->assertEquals('Three', $data->items[2]->name); + $this->assertEquals('Four', $data->items[3]->name); + $this->assertEquals('Author Name', $data->items[0]->author->name); + $this->assertEquals('Author Name', $data->items[1]->author->name); + $this->assertEquals('Author Name', $data->items[2]->author->name); + $this->assertEquals('Author Name', $data->items[3]->author->name); + } + public function testHCardWithChildHEntrys() { $url = 'http://feed.example.com/h-card-with-child-h-entrys'; $response = $this->parse(['url' => $url, 'expect' => 'feed']); diff --git a/tests/data/feed.example.com/h-feed-with-child-author b/tests/data/feed.example.com/h-feed-with-child-author new file mode 100644 index 0000000..14fc8c9 --- /dev/null +++ b/tests/data/feed.example.com/h-feed-with-child-author @@ -0,0 +1,37 @@ +HTTP/1.1 200 OK +Server: Apache +Date: Wed, 09 Dec 2015 03:29:14 GMT +Content-Type: text/html; charset=utf-8 +Connection: keep-alive + + + + Test + + + +
+ + + Author Name +
+ + +