From 85d973916fa575d51a8099af874ac45367331f12 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Mon, 30 Jul 2018 19:20:56 -0700 Subject: [PATCH] support articles and summary --- lib/XRay/Formats/ActivityStreams.php | 9 +++++ tests/ActivityStreamsTest.php | 34 +++++++++++++++++++ .../data/activitystreams.example/article.json | 25 ++++++++++++++ .../activitystreams.example/sensitive.json | 26 ++++++++++++++ 4 files changed, 94 insertions(+) create mode 100644 tests/data/activitystreams.example/article.json create mode 100644 tests/data/activitystreams.example/sensitive.json diff --git a/lib/XRay/Formats/ActivityStreams.php b/lib/XRay/Formats/ActivityStreams.php index 8dd3f52..910d7d9 100644 --- a/lib/XRay/Formats/ActivityStreams.php +++ b/lib/XRay/Formats/ActivityStreams.php @@ -32,6 +32,7 @@ class ActivityStreams extends Format { switch($as2['type']) { case 'Person': return self::parseAsHCard($as2, $url, $http, $opts); + case 'Article': case 'Note': return self::parseAsHEntry($as2, $url, $http, $opts); } @@ -63,6 +64,14 @@ class ActivityStreams extends Format { } catch(\Exception $e){} } + if(isset($as2['name'])) { + $data['name'] = $as2['name']; + } + + if(isset($as2['summary'])) { + $data['summary'] = $as2['summary']; + } + if(isset($as2['content'])) { $html = trim(self::sanitizeHTML($as2['content'])); $text = trim(self::stripHTML($html)); diff --git a/tests/ActivityStreamsTest.php b/tests/ActivityStreamsTest.php index 31342c0..4d3f95d 100644 --- a/tests/ActivityStreamsTest.php +++ b/tests/ActivityStreamsTest.php @@ -53,6 +53,25 @@ class ActivityStreamsTest extends PHPUnit_Framework_TestCase { $this->assertEquals('https://aaronparecki.com/', $data['data']['author']['url']); } + public function testArticle() { + $url = 'http://activitystreams.example/article.json'; + $response = $this->parse(['url' => $url]); + + $body = $response->getContent(); + $this->assertEquals(200, $response->getStatusCode()); + $data = json_decode($body, true); + + $this->assertEquals('activity+json', $data['source-format']); + $this->assertEquals('article', $data['data']['post-type']); + $this->assertEquals($url, $data['data']['url']); + $this->assertEquals('An Article', $data['data']['name']); + $this->assertEquals('This is the content of an ActivityStreams article', $data['data']['content']['text']); + $this->assertEquals('

This is the content of an ActivityStreams article

', $data['data']['content']['html']); + $this->assertEquals('aaronpk', $data['data']['author']['name']); + $this->assertEquals('https://aaronparecki.com/images/profile.jpg', $data['data']['author']['photo']); + $this->assertEquals('https://aaronparecki.com/', $data['data']['author']['url']); + } + public function testPhoto() { $url = 'http://activitystreams.example/photo.json'; $response = $this->parse(['url' => $url]); @@ -139,4 +158,19 @@ class ActivityStreamsTest extends PHPUnit_Framework_TestCase { $this->assertSame(['activitystreams'], $data['data']['category']); } + public function testSensitiveContent() { + $url = 'http://activitystreams.example/sensitive.json'; + $response = $this->parse(['url' => $url]); + + $body = $response->getContent(); + $this->assertEquals(200, $response->getStatusCode()); + $data = json_decode($body, true); + + $this->assertEquals('activity+json', $data['source-format']); + $this->assertEquals('note', $data['data']['post-type']); + $this->assertEquals('sensitive topic', $data['data']['summary']); + $this->assertEquals('This is the text content of a sensitive ActivityStreams note', $data['data']['content']['text']); + $this->assertArrayNotHasKey('name', $data['data']); + } + } diff --git a/tests/data/activitystreams.example/article.json b/tests/data/activitystreams.example/article.json new file mode 100644 index 0000000..8e06016 --- /dev/null +++ b/tests/data/activitystreams.example/article.json @@ -0,0 +1,25 @@ +HTTP/1.1 200 OK +Server: Apache +Date: Wed, 30 Jul 2018 03:29:14 GMT +Content-Type: application/activity+json +Connection: keep-alive + +{ + "@context": "https://www.w3.org/ns/activitystreams", + "id": "http://activitystreams.example/article.json", + "type": "Article", + "published": "2018-07-12T13:02:04-07:00", + "attributedTo": "https://activitystreams.example/aaronpk", + "name": "An Article", + "content": "

This is the content of an ActivityStreams article

", + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "tag": [ + { + "id": "https://aaronparecki.com/tag/activitystreams", + "name": "#activitystreams", + "type": "Hashtag" + } + ] +} diff --git a/tests/data/activitystreams.example/sensitive.json b/tests/data/activitystreams.example/sensitive.json new file mode 100644 index 0000000..40ed91a --- /dev/null +++ b/tests/data/activitystreams.example/sensitive.json @@ -0,0 +1,26 @@ +HTTP/1.1 200 OK +Server: Apache +Date: Wed, 30 Jul 2018 03:29:14 GMT +Content-Type: application/activity+json +Connection: keep-alive + +{ + "@context": "https://www.w3.org/ns/activitystreams", + "id": "http://activitystreams.example/sensitive.json", + "type": "Note", + "published": "2018-07-12T13:02:04-07:00", + "attributedTo": "https://activitystreams.example/aaronpk", + "sensitive": true, + "summary": "sensitive topic", + "content": "This is the text content of a sensitive ActivityStreams note", + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "tag": [ + { + "id": "https://aaronparecki.com/tag/activitystreams", + "name": "#activitystreams", + "type": "Hashtag" + } + ] +}