Slightly better ActivityStreams JSON output
This commit is contained in:
parent
08c72a00e8
commit
cba2b1ad9c
@ -397,37 +397,6 @@ class Activity
|
|||||||
$activity['object']['objectType'] = 'activity';
|
$activity['object']['objectType'] = 'activity';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Context stuff. For now I'm just sticking most of it
|
|
||||||
// in a property called "context"
|
|
||||||
|
|
||||||
if (!empty($this->context)) {
|
|
||||||
|
|
||||||
if (!empty($this->context->location)) {
|
|
||||||
$loc = $this->context->location;
|
|
||||||
|
|
||||||
$activity['location'] = array(
|
|
||||||
'objectType' => 'place',
|
|
||||||
'position' => sprintf("%+02.5F%+03.5F/", $loc->lat, $loc->lon),
|
|
||||||
'lat' => $loc->lat,
|
|
||||||
'lon' => $loc->lon
|
|
||||||
);
|
|
||||||
|
|
||||||
$name = $loc->getName();
|
|
||||||
|
|
||||||
if ($name) {
|
|
||||||
$activity['location']['displayName'] = $name;
|
|
||||||
}
|
|
||||||
|
|
||||||
$url = $loc->getURL();
|
|
||||||
|
|
||||||
if ($url) {
|
|
||||||
$activity['location']['url'] = $url;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$activity['to'] = $this->context->getToArray();
|
|
||||||
$activity['context'] = $this->context->asArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Instead of adding enclosures as an extension to JSON
|
// Instead of adding enclosures as an extension to JSON
|
||||||
// Activities, it seems like we should be using the
|
// Activities, it seems like we should be using the
|
||||||
@ -471,6 +440,51 @@ class Activity
|
|||||||
$activity['object']['attachments'] = $attachments;
|
$activity['object']['attachments'] = $attachments;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Context stuff.
|
||||||
|
|
||||||
|
if (!empty($this->context)) {
|
||||||
|
|
||||||
|
if (!empty($this->context->location)) {
|
||||||
|
$loc = $this->context->location;
|
||||||
|
|
||||||
|
$activity['location'] = array(
|
||||||
|
'objectType' => 'place',
|
||||||
|
'position' => sprintf("%+02.5F%+03.5F/", $loc->lat, $loc->lon),
|
||||||
|
'lat' => $loc->lat,
|
||||||
|
'lon' => $loc->lon
|
||||||
|
);
|
||||||
|
|
||||||
|
$name = $loc->getName();
|
||||||
|
|
||||||
|
if ($name) {
|
||||||
|
$activity['location']['displayName'] = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
$url = $loc->getURL();
|
||||||
|
|
||||||
|
if ($url) {
|
||||||
|
$activity['location']['url'] = $url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$activity['to'] = $this->context->getToArray();
|
||||||
|
|
||||||
|
$ctxarr = $this->context->asArray();
|
||||||
|
|
||||||
|
if (array_key_exists('inReplyTo', $ctxarr)) {
|
||||||
|
$activity['object']['inReplyTo'] = $ctxarr['inReplyTo'];
|
||||||
|
unset($ctxarr['inReplyTo']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!array_key_exists('status_net', $activity)) {
|
||||||
|
$activity['status_net'] = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($ctxarr as $key => $value) {
|
||||||
|
$activity['status_net'][$key] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// published
|
// published
|
||||||
$activity['published'] = self::iso8601Date($this->time);
|
$activity['published'] = self::iso8601Date($this->time);
|
||||||
@ -496,10 +510,8 @@ class Activity
|
|||||||
// eceived a remote notice? Probably not.
|
// eceived a remote notice? Probably not.
|
||||||
|
|
||||||
// verb
|
// verb
|
||||||
//
|
|
||||||
// We can probably use the whole schema URL here but probably the
|
$activity['verb'] = ActivityVerb::canonical($this->verb);
|
||||||
// relative simple name is easier to parse
|
|
||||||
$activity['verb'] = substr($this->verb, strrpos($this->verb, '/') + 1);
|
|
||||||
|
|
||||||
// url
|
// url
|
||||||
$activity['url'] = $this->id;
|
$activity['url'] = $this->id;
|
||||||
@ -527,7 +539,15 @@ class Activity
|
|||||||
foreach ($this->extra as $e) {
|
foreach ($this->extra as $e) {
|
||||||
list($objectName, $props, $txt) = $e;
|
list($objectName, $props, $txt) = $e;
|
||||||
if (!empty($objectName)) {
|
if (!empty($objectName)) {
|
||||||
$activity[$objectName] = $props;
|
$parts = explode(":", $objectName);
|
||||||
|
if (count($parts) == 2 && $parts[0] == "statusnet") {
|
||||||
|
if (!array_key_exists('status_net', $activity)) {
|
||||||
|
$activity['status_net'] = array();
|
||||||
|
}
|
||||||
|
$activity['status_net'][$parts[1]] = $props;
|
||||||
|
} else {
|
||||||
|
$activity[$objectName] = $props;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -778,4 +778,13 @@ class ActivityObject
|
|||||||
}
|
}
|
||||||
return array_filter($object);
|
return array_filter($object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function canonicalType($type) {
|
||||||
|
$ns = 'http://activitystrea.ms/schema/1.0/';
|
||||||
|
if (substr($type, 0, mb_strlen($ns)) == $ns) {
|
||||||
|
return substr($type, mb_strlen($ns));
|
||||||
|
} else {
|
||||||
|
return $type;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,4 +63,13 @@ class ActivityVerb
|
|||||||
|
|
||||||
// For simple profile-update pings; no content to share.
|
// For simple profile-update pings; no content to share.
|
||||||
const UPDATE_PROFILE = 'http://ostatus.org/schema/1.0/update-profile';
|
const UPDATE_PROFILE = 'http://ostatus.org/schema/1.0/update-profile';
|
||||||
|
|
||||||
|
static function canonical($verb) {
|
||||||
|
$ns = 'http://activitystrea.ms/schema/1.0/';
|
||||||
|
if (substr($verb, 0, mb_strlen($ns)) == $ns) {
|
||||||
|
return substr($verb, mb_strlen($ns));
|
||||||
|
} else {
|
||||||
|
return $verb;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user