First cut at some JSON Activity Streams output

This commit is contained in:
Zach Copley
2011-02-15 20:25:39 -08:00
parent ff502bb148
commit a1b436a8c6
6 changed files with 220 additions and 6 deletions

View File

@@ -179,7 +179,7 @@ class ActivityObject
if (empty($this->type)) {
$this->type = self::PERSON; // XXX: is this fair?
}
// start with <atom:title>
$title = ActivityUtils::childHtmlContent($element, self::TITLE);
@@ -419,7 +419,7 @@ class ActivityObject
static function fromNotice(Notice $notice)
{
$object = new ActivityObject();
if (Event::handle('StartActivityObjectFromNotice', array($notice, &$object))) {
$object->type = ActivityObject::NOTE;
@@ -526,7 +526,7 @@ class ActivityObject
return $object;
}
function outputTo($xo, $tag='activity:object')
{
if (!empty($tag)) {
@@ -633,4 +633,46 @@ class ActivityObject
return $xs->getString();
}
/*
* Returns an array based on this Activity Object suitable for
* encoding as JSON.
*
* @return array $object the activity object array
*/
function asArray()
{
$object = array();
// TODO: attachedObjects
// displayName
$object['displayName'] = $this->title;
// TODO: downstreamDuplicates
// TODO: embedCode
// id
$object['id'] = $this->id;
// TODO: image
// Need to make MediaLink serialization
// objectType
$object['type'] = $this->type;
// summary
$object['summary'] = $this->summary;
// TODO: upstreamDuplicates
// url (XXX: need to put the right thing here...)
$object['url'] = $this->id;
// TODO: extensions (OStatus stuff, etc.)
return $object;
}
}