Browse Source

return matching author url

pull/39/head
Aaron Parecki 8 years ago
parent
commit
69223cad1d
4 changed files with 68 additions and 4 deletions
  1. +12
    -4
      lib/Formats/Mf2.php
  2. +14
    -0
      tests/AuthorTest.php
  3. +22
    -0
      tests/data/author.example.com/about-with-multiple-urls
  4. +20
    -0
      tests/data/author.example.com/h-entry-author-is-url-to-h-card-with-multiple-links

+ 12
- 4
lib/Formats/Mf2.php View File

@ -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);
}
}

+ 14
- 0
tests/AuthorTest.php View File

@ -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]);

+ 22
- 0
tests/data/author.example.com/about-with-multiple-urls View File

@ -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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Author</title>
</head>
<body>
<div class="h-card">
<h2 class="p-name">Author Full Name</h2>
<a href="xmpp://user@host.example" class="u-url" rel="me">xmpp</a>
<a href="/about-with-multiple-urls" class="u-url" rel="me">Me</a>
<img src="/photo.jpg" class="u-photo">
</div>
</body>
</html>

+ 20
- 0
tests/data/author.example.com/h-entry-author-is-url-to-h-card-with-multiple-links View File

@ -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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example</title>
</head>
<body>
<div class="h-entry">
<a href="/about-with-multiple-urls" class="u-author">Author</a>
<p class="p-name e-content">Hello World</p>
</div>
</body>
</html>

Loading…
Cancel
Save