diff --git a/lib/Formats/Mf2.php b/lib/Formats/Mf2.php index a8b6468..0da9307 100644 --- a/lib/Formats/Mf2.php +++ b/lib/Formats/Mf2.php @@ -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 diff --git a/tests/ParseTest.php b/tests/ParseTest.php index 9104cdb..4e628ca 100644 --- a/tests/ParseTest.php +++ b/tests/ParseTest.php @@ -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']); + } + } diff --git a/tests/data/source.example.com/bridgy-example b/tests/data/source.example.com/bridgy-example new file mode 100644 index 0000000..5421bf5 --- /dev/null +++ b/tests/data/source.example.com/bridgy-example @@ -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 + + + + + +I'm at SmartMathPro by P'Pan (@t Once Academy) in Bangrak, Bangkok swarmapp.com/c/4m4AboRbm45 + + +
+ tag:twitter.com,2013:705248246067806209 + + + + + ณณแนน + + + + https://twitter.com/NNanpartoonoi/status/705248246067806209 +
+ + I'm at SmartMathPro by P'Pan (@t Once Academy) in Bangrak, Bangkok swarmapp.com/c/4m4AboRbm45 +
+ + + + + ⚡️ + + + + + + + +
+ +