Let activity objects write directly to activity's own outputter

This commit is contained in:
Evan Prodromou 2010-12-20 13:26:57 -05:00
parent 25d03c42e6
commit 24f9a991b6
2 changed files with 40 additions and 49 deletions

View File

@ -349,32 +349,7 @@ class Activity
if ($this->verb == ActivityVerb::POST && count($this->objects) == 1) { if ($this->verb == ActivityVerb::POST && count($this->objects) == 1) {
$obj = $this->objects[0]; $obj = $this->objects[0];
$obj->outputTo($xs, null);
$xs->element('id', null, $obj->id);
$xs->element('activity:object-type', null, $obj->type);
if (!empty($obj->title)) {
$xs->element('title', null, $obj->title);
} else {
// XXX need a better default title
$xs->element('title', null, _('Post'));
}
if (!empty($obj->content)) {
$xs->element('content', array('type' => 'html'), $obj->content);
}
if (!empty($obj->summary)) {
$xs->element('summary', null, $obj->summary);
}
if (!empty($obj->link)) {
$xs->element('link', array('rel' => 'alternate',
'type' => 'text/html'),
$obj->link);
}
// XXX: some object types might have other values here.
} else { } else {
$xs->element('id', null, $this->id); $xs->element('id', null, $this->id);
@ -408,12 +383,12 @@ class Activity
$xs->element('name', array(), $this->actor->title); $xs->element('name', array(), $this->actor->title);
} }
$xs->elementEnd('author'); $xs->elementEnd('author');
$xs->raw($this->actor->asString('activity:actor')); $this->actor->outputTo($xs, 'activity:actor');
} }
if ($this->verb != ActivityVerb::POST || count($this->objects) != 1) { if ($this->verb != ActivityVerb::POST || count($this->objects) != 1) {
foreach($this->objects as $object) { foreach($this->objects as $object) {
$xs->raw($object->asString()); $object->outputTo($xs, 'activity:object');
} }
} }
@ -467,7 +442,7 @@ class Activity
} }
if ($this->target) { if ($this->target) {
$xs->raw($this->target->asString('activity:target')); $this->target->outputTo($xs, 'activity:target');
} }
foreach ($this->categories as $cat) { foreach ($this->categories as $cat) {

View File

@ -489,18 +489,18 @@ class ActivityObject
return $object; return $object;
} }
function asString($tag='activity:object') function outputTo($xo, $tag='activity:object')
{ {
$xs = new XMLStringer(true); if (!empty($tag)) {
$xo->elementStart($tag);
}
$xs->elementStart($tag); $xo->element('activity:object-type', null, $this->type);
$xs->element('activity:object-type', null, $this->type); $xo->element(self::ID, null, $this->id);
$xs->element(self::ID, null, $this->id);
if (!empty($this->title)) { if (!empty($this->title)) {
$xs->element( $xo->element(
self::TITLE, self::TITLE,
null, null,
common_xml_safe_str($this->title) common_xml_safe_str($this->title)
@ -508,7 +508,7 @@ class ActivityObject
} }
if (!empty($this->summary)) { if (!empty($this->summary)) {
$xs->element( $xo->element(
self::SUMMARY, self::SUMMARY,
null, null,
common_xml_safe_str($this->summary) common_xml_safe_str($this->summary)
@ -517,7 +517,7 @@ class ActivityObject
if (!empty($this->content)) { if (!empty($this->content)) {
// XXX: assuming HTML content here // XXX: assuming HTML content here
$xs->element( $xo->element(
ActivityUtils::CONTENT, ActivityUtils::CONTENT,
array('type' => 'html'), array('type' => 'html'),
common_xml_safe_str($this->content) common_xml_safe_str($this->content)
@ -525,7 +525,7 @@ class ActivityObject
} }
if (!empty($this->link)) { if (!empty($this->link)) {
$xs->element( $xo->element(
'link', 'link',
array( array(
'rel' => 'alternate', 'rel' => 'alternate',
@ -540,7 +540,7 @@ class ActivityObject
|| $this->type == ActivityObject::GROUP) { || $this->type == ActivityObject::GROUP) {
foreach ($this->avatarLinks as $avatar) { foreach ($this->avatarLinks as $avatar) {
$xs->element( $xo->element(
'link', array( 'link', array(
'rel' => 'avatar', 'rel' => 'avatar',
'type' => $avatar->type, 'type' => $avatar->type,
@ -554,7 +554,7 @@ class ActivityObject
} }
if (!empty($this->geopoint)) { if (!empty($this->geopoint)) {
$xs->element( $xo->element(
'georss:point', 'georss:point',
null, null,
$this->geopoint $this->geopoint
@ -562,10 +562,26 @@ class ActivityObject
} }
if (!empty($this->poco)) { if (!empty($this->poco)) {
$xs->raw($this->poco->asString()); $xo->raw($this->poco->asString());
} }
$xs->elementEnd($tag); foreach ($this->extra as $el) {
list($extraTag, $attrs, $content) = $el;
$xo->element($extraTag, $attrs, $content);
}
if (!empty($tag)) {
$xo->elementEnd($tag);
}
return;
}
function asString($tag='activity:object')
{
$xs = new XMLStringer(true);
$this->outputTo($xs, $tag);
return $xs->getString(); return $xs->getString();
} }