Browse Source

parse h-event location as an embedded h-card

master v1.11.0
Aaron Parecki 4 years ago
parent
commit
9edc99ce3c
No known key found for this signature in database GPG Key ID: 276C2817346D6056
3 changed files with 24 additions and 8 deletions
  1. +5
    -2
      lib/XRay/Formats/Mf2.php
  2. +9
    -4
      tests/ParseTest.php
  3. +10
    -2
      tests/data/source.example.com/h-event-with-h-card-location

+ 5
- 2
lib/XRay/Formats/Mf2.php View File

@ -342,7 +342,7 @@ class Mf2 extends Format {
$hcard = [ $hcard = [
'type' => 'card', '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) { foreach($properties as $p) {
if($v=self::getPlaintext($mf2, $p)) { if($v=self::getPlaintext($mf2, $p)) {
$hcard[$p] = $v; $hcard[$p] = $v;
@ -648,7 +648,10 @@ class Mf2 extends Format {
self::collectSingleValues(['name','summary','published','start','end','duration'], ['url','featured'], $item, $url, $data); 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 // 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 // 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 // If the value is an h-* object with a URL, the URL is used and a "ref" is added as well

+ 9
- 4
tests/ParseTest.php View File

@ -650,10 +650,15 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($url, $data['data']['url']); $this->assertEquals($url, $data['data']['url']);
$this->assertEquals('2016-02-09T18:30', $data['data']['start']); $this->assertEquals('2016-02-09T18:30', $data['data']['start']);
$this->assertEquals('2016-02-09T19:30', $data['data']['end']); $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() { public function testEventWithFeaturedImage() {

+ 10
- 2
tests/data/source.example.com/h-event-with-h-card-location View File

@ -15,6 +15,14 @@ Connection: keep-alive
<time class="dt-start" datetime="2016-02-09T18:30">Feb 9, 6:30pm</time> - <time class="dt-end" datetime="2016-02-09T19:30">7:30pm</time> <time class="dt-start" datetime="2016-02-09T18:30">Feb 9, 6:30pm</time> - <time class="dt-end" datetime="2016-02-09T19:30">7:30pm</time>
<a href="/venue" class="p-location h-card">Venue</a>
<a href="/venue" class="p-location h-card">
<span class="p-name">Venue</span>
<span class="p-latitude">45.5</span>
<span class="p-longitude">-122.6</span>
<span class="p-street-address">1234 Main St</span>
<span class="p-locality">Portland</span>
<span class="p-region">Oregon</span>
<span class="p-country-name">USA</span>
</a>
</body> </body>
</html>
</html>

Loading…
Cancel
Save