From 11f77b2fcaf2b029fb0a298253bb99b0d96cd7b8 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 17 Feb 2011 22:36:14 -0800 Subject: [PATCH] Add PoCo to Activity Streams JSON --- lib/activityobject.php | 4 ++++ lib/activitystreamjsondocument.php | 1 - lib/poco.php | 38 ++++++++++++++++++++++++++++++ lib/pocoaddress.php | 13 ++++++++++ lib/pocourl.php | 20 ++++++++++++++++ 5 files changed, 75 insertions(+), 1 deletion(-) 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; + } }