Browse Source

support articles and summary

pull/78/head v1.6.1
Aaron Parecki 3 years ago
parent
commit
85d973916f
No known key found for this signature in database GPG Key ID: 276C2817346D6056
4 changed files with 94 additions and 0 deletions
  1. +9
    -0
      lib/XRay/Formats/ActivityStreams.php
  2. +34
    -0
      tests/ActivityStreamsTest.php
  3. +25
    -0
      tests/data/activitystreams.example/article.json
  4. +26
    -0
      tests/data/activitystreams.example/sensitive.json

+ 9
- 0
lib/XRay/Formats/ActivityStreams.php View File

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

+ 34
- 0
tests/ActivityStreamsTest.php View File

@ -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('<p>This is the content of an <b>ActivityStreams</b> article</p>', $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']);
}
}

+ 25
- 0
tests/data/activitystreams.example/article.json View File

@ -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": "<p>This is the content of an <b>ActivityStreams</b> article</p>",
"to": [
"https://www.w3.org/ns/activitystreams#Public"
],
"tag": [
{
"id": "https://aaronparecki.com/tag/activitystreams",
"name": "#activitystreams",
"type": "Hashtag"
}
]
}

+ 26
- 0
tests/data/activitystreams.example/sensitive.json View File

@ -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"
}
]
}

Loading…
Cancel
Save