From 9edc99ce3c9815c447ede66fc55fd52550391cfd Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Sun, 10 May 2020 17:18:56 -0700 Subject: [PATCH] parse h-event location as an embedded h-card --- lib/XRay/Formats/Mf2.php | 7 +++++-- tests/ParseTest.php | 13 +++++++++---- .../source.example.com/h-event-with-h-card-location | 12 ++++++++++-- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/lib/XRay/Formats/Mf2.php b/lib/XRay/Formats/Mf2.php index 6879c80..f103f26 100644 --- a/lib/XRay/Formats/Mf2.php +++ b/lib/XRay/Formats/Mf2.php @@ -342,7 +342,7 @@ class Mf2 extends Format { $hcard = [ 'type' => 'card', ]; - $properties = ['name','latitude','longitude','locality','region','country','url']; + $properties = ['name','latitude','longitude','street-address','locality','region','country-name','url']; foreach($properties as $p) { if($v=self::getPlaintext($mf2, $p)) { $hcard[$p] = $v; @@ -648,7 +648,10 @@ class Mf2 extends Format { self::collectSingleValues(['name','summary','published','start','end','duration'], ['url','featured'], $item, $url, $data); // These properties are always returned as arrays and may contain plaintext content - self::collectArrayValues(['category','location','attendee'], $item, $data, $refs, $http); + self::collectArrayValues(['category','attendee'], $item, $data, $refs, $http); + + if($location = self::parseEmbeddedHCard('location', $item, $http)) + $data['location'] = $location; // These properties are always returned as arrays and always URLs // If the value is an h-* object with a URL, the URL is used and a "ref" is added as well diff --git a/tests/ParseTest.php b/tests/ParseTest.php index 61a2f68..1032d8c 100644 --- a/tests/ParseTest.php +++ b/tests/ParseTest.php @@ -650,10 +650,15 @@ class ParseTest extends PHPUnit_Framework_TestCase { $this->assertEquals($url, $data['data']['url']); $this->assertEquals('2016-02-09T18:30', $data['data']['start']); $this->assertEquals('2016-02-09T19:30', $data['data']['end']); - $this->assertArrayHasKey('http://source.example.com/venue', $data['data']['refs']); - $this->assertEquals('card', $data['data']['refs']['http://source.example.com/venue']['type']); - $this->assertEquals('http://source.example.com/venue', $data['data']['refs']['http://source.example.com/venue']['url']); - $this->assertEquals('Venue', $data['data']['refs']['http://source.example.com/venue']['name']); + $this->assertEquals('card', $data['data']['location']['type']); + $this->assertEquals('http://source.example.com/venue', $data['data']['location']['url']); + $this->assertEquals('Venue', $data['data']['location']['name']); + $this->assertEquals('45.5', $data['data']['location']['latitude']); + $this->assertEquals('-122.6', $data['data']['location']['longitude']); + $this->assertEquals('1234 Main St', $data['data']['location']['street-address']); + $this->assertEquals('Portland', $data['data']['location']['locality']); + $this->assertEquals('Oregon', $data['data']['location']['region']); + $this->assertEquals('USA', $data['data']['location']['country-name']); } public function testEventWithFeaturedImage() { diff --git a/tests/data/source.example.com/h-event-with-h-card-location b/tests/data/source.example.com/h-event-with-h-card-location index d1ef5df..6197059 100644 --- a/tests/data/source.example.com/h-event-with-h-card-location +++ b/tests/data/source.example.com/h-event-with-h-card-location @@ -15,6 +15,14 @@ Connection: keep-alive - - Venue + + Venue + 45.5 + -122.6 + 1234 Main St + Portland + Oregon + USA + - \ No newline at end of file +