X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fpoco.php;h=baea5b33b03f79701bf253cc144da530c65445b9;hb=9143d4f38493da81328317100b34a37dd67fde54;hp=2157062b3798202b9c6a3da5b5b636a890ab515e;hpb=e458e9fe6352df6063079979b20a6924f97198f4;p=quix0rs-gnu-social.git diff --git a/lib/poco.php b/lib/poco.php index 2157062b37..baea5b33b0 100644 --- a/lib/poco.php +++ b/lib/poco.php @@ -211,30 +211,72 @@ 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(); + /** + * Output a Portable Contact as an array suitable for serializing + * as JSON + * + * @return $array the PoCo array + */ + + function asArray() + { + $poco = array(); + + $poco['preferredUsername'] = $this->preferredUsername; + $poco['displayName'] = $this->displayName; + + if (!empty($this->note)) { + $poco['note'] = $this->note; + } + + if (!empty($this->address)) { + $poco['addresses'] = $this->address->asArray(); + } + + if (!empty($this->urls)) { + + $urls = array(); + + foreach ($this->urls as $url) { + $urls[] = $url->asArray(); + } + + $poco['urls'] = $urls; + } + + return $poco; } + } +