From: Zach Copley Date: Fri, 18 Feb 2011 06:36:14 +0000 (-0800) Subject: Add PoCo to Activity Streams JSON X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=11f77b2fcaf2b029fb0a298253bb99b0d96cd7b8;p=quix0rs-gnu-social.git Add PoCo to Activity Streams JSON --- diff --git a/lib/activityobject.php b/lib/activityobject.php index ae2f4649e5..a69e1a1b42 100644 --- a/lib/activityobject.php +++ b/lib/activityobject.php @@ -726,6 +726,10 @@ class ActivityObject ); } + if (!empty($this->poco)) { + $object['contact'] = $this->poco->asArray(); + } + return array_filter($object); } } diff --git a/lib/activitystreamjsondocument.php b/lib/activitystreamjsondocument.php index f74bb6d2e6..2b99d19eb7 100644 --- a/lib/activitystreamjsondocument.php +++ b/lib/activitystreamjsondocument.php @@ -115,7 +115,6 @@ class ActivityStreamJSONDocument $act = $notice->asActivity($cur); $act->extra[] = $notice->noticeInfo($cur); - array_push($this->doc['items'], $act->asArray()); } diff --git a/lib/poco.php b/lib/poco.php index d7b082163e..baea5b33b0 100644 --- a/lib/poco.php +++ b/lib/poco.php @@ -241,4 +241,42 @@ class PoCo $url->outputTo($xo); } } + + /** + * 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; + } + } + diff --git a/lib/pocoaddress.php b/lib/pocoaddress.php index d9f6ff2bde..22d4d02b13 100644 --- a/lib/pocoaddress.php +++ b/lib/pocoaddress.php @@ -56,4 +56,17 @@ class PoCoAddress $xo->elementEnd('poco:address'); } } + + /** + * Return this PoCo address as an array suitable for serializing in JSON + * + * @return array the address + */ + + function asArray() + { + if (!empty($this->formatted)) { + return array('formatted' => $this->formatted); + } + } } diff --git a/lib/pocourl.php b/lib/pocourl.php index 786793b280..e375f125a0 100644 --- a/lib/pocourl.php +++ b/lib/pocourl.php @@ -67,4 +67,24 @@ class PoCoURL } $xo->elementEnd('poco:urls'); } + + /** + * Return this PoCo URL as an array suitable for serializing in JSON + * + * @array $url the url + */ + + function asArray() + { + $url = array(); + + $url['type'] = $this->type; + $url['value'] = $this->value; + + if (!empty($this->primary)) { + $url['primary'] = 'true'; + } + + return $url; + } }