From f5128015be8db59106b57daf64c4a0d27e3ecccd Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 27 Dec 2010 09:46:25 -0800 Subject: [PATCH] Use outputTo() instead of asString() for including sub-elements --- lib/activity.php | 2 +- lib/activityobject.php | 2 +- lib/atomcategory.php | 11 ++++++++--- lib/poco.php | 18 +++++++++++------- lib/pocoaddress.php | 17 ++++++++++------- lib/pocourl.php | 17 +++++++++++------ 6 files changed, 42 insertions(+), 25 deletions(-) diff --git a/lib/activity.php b/lib/activity.php index 85d3efa21a..8d7ae1540b 100644 --- a/lib/activity.php +++ b/lib/activity.php @@ -440,7 +440,7 @@ class Activity } foreach ($this->categories as $cat) { - $xs->raw($cat->asString()); + $cat->outputTo($xs); } // can be either URLs or enclosure objects diff --git a/lib/activityobject.php b/lib/activityobject.php index 3df35f84b0..b5e6013b4b 100644 --- a/lib/activityobject.php +++ b/lib/activityobject.php @@ -570,7 +570,7 @@ class ActivityObject } if (!empty($this->poco)) { - $xo->raw($this->poco->asString()); + $this->poco->outputTo($xo); } foreach ($this->extra as $el) { diff --git a/lib/atomcategory.php b/lib/atomcategory.php index 9763023f75..e527877cb0 100644 --- a/lib/atomcategory.php +++ b/lib/atomcategory.php @@ -59,6 +59,13 @@ class AtomCategory } function asString() + { + $xs = new XMLStringer(); + $this->outputTo($xs); + return $xs->getString(); + } + + function outputTo($xo) { $attribs = array(); if ($this->term !== null) { @@ -70,8 +77,6 @@ class AtomCategory if ($this->label !== null) { $attribs['label'] = $this->label; } - $xs = new XMLStringer(); - $xs->element('category', $attribs); - return $xs->getString(); + $xo->element('category', $attribs); } } diff --git a/lib/poco.php b/lib/poco.php index 2157062b37..d7b082163e 100644 --- a/lib/poco.php +++ b/lib/poco.php @@ -211,30 +211,34 @@ class PoCo function asString() { $xs = new XMLStringer(true); - $xs->element( + $this->outputTo($xs); + return $xs->getString(); + } + + function outputTo($xo) + { + $xo->element( 'poco:preferredUsername', null, $this->preferredUsername ); - $xs->element( + $xo->element( 'poco:displayName', null, $this->displayName ); if (!empty($this->note)) { - $xs->element('poco:note', null, common_xml_safe_str($this->note)); + $xo->element('poco:note', null, common_xml_safe_str($this->note)); } if (!empty($this->address)) { - $xs->raw($this->address->asString()); + $this->address->outputTo($xo); } foreach ($this->urls as $url) { - $xs->raw($url->asString()); + $url->outputTo($xo); } - - return $xs->getString(); } } diff --git a/lib/pocoaddress.php b/lib/pocoaddress.php index 60873bdc42..d9f6ff2bde 100644 --- a/lib/pocoaddress.php +++ b/lib/pocoaddress.php @@ -42,15 +42,18 @@ class PoCoAddress // @todo Other address fields function asString() + { + $xs = new XMLStringer(true); + $this->outputTo($xs); + return $xs->getString(); + } + + function outputTo($xo) { if (!empty($this->formatted)) { - $xs = new XMLStringer(true); - $xs->elementStart('poco:address'); - $xs->element('poco:formatted', null, common_xml_safe_str($this->formatted)); - $xs->elementEnd('poco:address'); - return $xs->getString(); + $xo->elementStart('poco:address'); + $xo->element('poco:formatted', null, common_xml_safe_str($this->formatted)); + $xo->elementEnd('poco:address'); } - - return null; } } diff --git a/lib/pocourl.php b/lib/pocourl.php index 803484d760..786793b280 100644 --- a/lib/pocourl.php +++ b/lib/pocourl.php @@ -53,13 +53,18 @@ class PoCoURL function asString() { $xs = new XMLStringer(true); - $xs->elementStart('poco:urls'); - $xs->element('poco:type', null, $this->type); - $xs->element('poco:value', null, $this->value); + $this->outputTo($xs); + return $xs->getString(); + } + + function outputTo($xo) + { + $xo->elementStart('poco:urls'); + $xo->element('poco:type', null, $this->type); + $xo->element('poco:value', null, $this->value); if (!empty($this->primary)) { - $xs->element('poco:primary', null, 'true'); + $xo->element('poco:primary', null, 'true'); } - $xs->elementEnd('poco:urls'); - return $xs->getString(); + $xo->elementEnd('poco:urls'); } } -- 2.39.5