Browse Source

add h-x-app vocabulary

closes #13
pull/60/head v1.4.9
Aaron Parecki 3 years ago
parent
commit
aba067234c
No known key found for this signature in database GPG Key ID: 276C2817346D6056
5 changed files with 86 additions and 1 deletions
  1. +1
    -1
      lib/XRay/Formats/HTML.php
  2. +28
    -0
      lib/XRay/Formats/Mf2.php
  3. +28
    -0
      tests/ParseTest.php
  4. +14
    -0
      tests/data/source.example.com/h-app
  5. +15
    -0
      tests/data/source.example.com/h-x-app

+ 1
- 1
lib/XRay/Formats/HTML.php View File

@ -96,8 +96,8 @@ class HTML extends Format {
if($mf2 && count($mf2['items']) > 0) {
$data = Formats\Mf2::parse($mf2, $url, $http, $opts);
$result = array_merge($result, $data);
if($data) {
$result = array_merge($result, $data);
if($fragment) {
$result['info'] = [
'found_fragment' => $foundFragment

+ 28
- 0
lib/XRay/Formats/Mf2.php View File

@ -55,6 +55,10 @@ class Mf2 extends Format {
#Parse::debug("mf2:0: Recognized $url as an h-card it is the only item on the page");
return self::parseAsHCard($item, $http, $url, $url);
}
if(in_array('h-app', $item['type']) || in_array('h-x-app', $item['type'])) {
#Parse::debug("mf2:0: Recognized $url as an h-feed because it is the only item on the page");
return self::parseAsHApp($mf2, $item, $http, $url);
}
if(in_array('h-feed', $item['type'])) {
#Parse::debug("mf2:0: Recognized $url as an h-feed because it is the only item on the page");
return self::parseAsHFeed($mf2, $http, $url);
@ -83,6 +87,8 @@ class Mf2 extends Format {
return self::parseAsHProduct($mf2, $item, $http, $url);
} elseif(in_array('h-item', $item['type'])) {
return self::parseAsHItem($mf2, $item, $http, $url);
} elseif(in_array('h-app', $item['type']) || in_array('h-x-app', $item['type'])) {
return self::parseAsHApp($mf2, $item, $http, $url);
} elseif(in_array('h-feed', $item['type'])) {
return self::parseAsHFeed($mf2, $http, $url);
} else {
@ -116,6 +122,8 @@ class Mf2 extends Format {
return self::parseAsHProduct($mf2, $item, $http, $url);
} elseif(in_array('h-item', $item['type'])) {
return self::parseAsHItem($mf2, $item, $http, $url);
} elseif(in_array('h-app', $item['type']) || in_array('h-x-app', $item['type'])) {
return self::parseAsHApp($mf2, $item, $http, $url);
}
}
}
@ -162,6 +170,9 @@ class Mf2 extends Format {
} elseif(in_array('h-item', $item['type'])) {
#Parse::debug("mf2:6: $url is falling back to the first h-item on the page");
return self::parseAsHItem($mf2, $item, $http, $url);
} elseif(in_array('h-app', $item['type']) || in_array('h-x-app', $item['type'])) {
#Parse::debug("mf2:6: $url is falling back to the first h-item on the page");
return self::parseAsHApp($mf2, $item, $http, $url);
}
}
@ -543,6 +554,23 @@ class Mf2 extends Format {
return $response;
}
private static function parseAsHApp($mf2, $item, $http, $url) {
$data = [
'type' => 'app'
];
self::collectSingleValues(['name'], ['url','logo'], $item, $url, $data);
if(!isset($data['url']))
$data['url'] = $url;
$response = [
'data' => $data
];
return $response;
}
private static function parseAsHEvent($mf2, $item, $http, $url) {
$data = [
'type' => 'event'

+ 28
- 0
tests/ParseTest.php View File

@ -613,4 +613,32 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('http://example.com/photo.jpg', $data['data']['photo'][0]);
}
public function testHApp() {
$url = 'http://source.example.com/h-app';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('app', $data->data->type);
$this->assertEquals('http://source.example.com/images/quill.png', $data->data->logo);
$this->assertEquals('Quill', $data->data->name);
$this->assertEquals($url, $data->data->url);
$this->assertObjectNotHasAttribute('photo', $data->data);
}
public function testHXApp() {
$url = 'http://source.example.com/h-x-app';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('app', $data->data->type);
$this->assertEquals('http://source.example.com/images/quill.png', $data->data->logo);
$this->assertEquals('Quill', $data->data->name);
$this->assertEquals($url, $data->data->url);
$this->assertObjectNotHasAttribute('photo', $data->data);
}
}

+ 14
- 0
tests/data/source.example.com/h-app View File

@ -0,0 +1,14 @@
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
<html>
<head>
<title>Test</title>
</head>
<body class="h-app">
<img src="/images/quill.png" class="u-logo p-name" alt="Quill">
</body>
</html>

+ 15
- 0
tests/data/source.example.com/h-x-app View File

@ -0,0 +1,15 @@
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
<html>
<head>
<title>Test</title>
</head>
<body class="h-x-app">
<img src="/images/quill.png" class="u-logo p-name" alt="Quill">
<a href="" class="u-url"></a>
</body>
</html>

Loading…
Cancel
Save