Browse Source

if there is exactly one item and it's an h-entry, use that

pull/39/head
Aaron Parecki 5 years ago
parent
commit
ee5e48e1ef
3 changed files with 76 additions and 0 deletions
  1. +8
    -0
      lib/Formats/Mf2.php
  2. +10
    -0
      tests/ParseTest.php
  3. +58
    -0
      tests/data/source.example.com/bridgy-example

+ 8
- 0
lib/Formats/Mf2.php View File

@ -9,6 +9,14 @@ class Mf2 {
public static function parse($mf2, $url, $http) {
if(count($mf2['items']) == 0)
return false;
// If there is only one item on the page, just use that
if(count($mf2['items']) == 1) {
$item = $mf2['items'][0];
if(in_array('h-entry', $item['type']) || in_array('h-cite', $item['type'])) {
Parse::debug("mf2.0: Recognized $url as an h-entry it is the only item on the page");
return self::parseAsHEntry($mf2, $item, $http, $url);
}
}
// Check if the list of items is a bunch of h-entrys and return as a feed
// Unless this page's URL matches one of the entries, then treat it as a permalink

+ 10
- 0
tests/ParseTest.php View File

@ -246,4 +246,14 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('Hello World', $data['data']['content']['text']);
}
public function testBridgyExampleWithNoMatchingURL() {
$url = 'http://source.example.com/bridgy-example';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('entry', $data['data']['type']);
}
}

+ 58
- 0
tests/data/source.example.com/bridgy-example View File

@ -0,0 +1,58 @@
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>I'm at SmartMathPro by P'Pan (@t Once Academy) in Bangrak, Bangkok swarmapp.com/c/4m4AboRbm45</title>
<style type="text/css">
body {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
.p-uid {
display: none;
}
.u-photo {
max-width: 50px;
border-radius: 4px;
}
.e-content {
margin-top: 10px;
font-size: 1.3em;
}
</style>
</head>
<article class="h-entry h-as-note">
<span class="p-uid">tag:twitter.com,2013:705248246067806209</span>
<time class="dt-published" datetime="2016-03-03T04:27:39+00:00">2016-03-03T04:27:39+00:00</time>
<span class="p-author h-card">
<a class="p-name u-url" href="https://twitter.com/NNanpartoonoi">ณณแนน</a>
<img class="u-photo" src="https://twitter.com/NNanpartoonoi/profile_image?size=original" alt="" />
</span>
<a class="u-url" href="https://twitter.com/NNanpartoonoi/status/705248246067806209">https://twitter.com/NNanpartoonoi/status/705248246067806209</a>
<div class="e-content p-name">
I'm at SmartMathPro by P'Pan (<a href="https://twitter.com/t">@t</a> Once Academy) in Bangrak, Bangkok <a href="https://www.swarmapp.com/c/4m4AboRbm45">swarmapp.com/c/4m4AboRbm45</a>
</div>
<span class="u-category h-card h-card">
<a class="p-name u-url" href="https://twitter.com/t">⚡️</a>
<a class="u-url" href="http://tantek.com/"></a>
</span>
</article>
</html>

Loading…
Cancel
Save