X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fpoco.php;h=2bc9e7276244117e0040a5a85074d3ce8b6aff85;hb=02cbafb9870999325b138620cab16c45b0fe8546;hp=2157062b3798202b9c6a3da5b5b636a890ab515e;hpb=99454be38cf1dc7f962441d23ccc0a59e7b05f3d;p=quix0rs-gnu-social.git diff --git a/lib/poco.php b/lib/poco.php index 2157062b37..2bc9e72762 100644 --- a/lib/poco.php +++ b/lib/poco.php @@ -137,12 +137,8 @@ class PoCo return null; } - function fromProfile($profile) + static function fromProfile(Profile $profile) { - if (empty($profile)) { - return null; - } - $poco = new PoCo(); $poco->preferredUsername = $profile->nickname; @@ -168,12 +164,8 @@ class PoCo return $poco; } - function fromGroup($group) + static function fromGroup(User_group $group) { - if (empty($group)) { - return null; - } - $poco = new PoCo(); $poco->preferredUsername = $group->nickname; @@ -211,30 +203,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; } + } +