]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Add PoCo to Activity Streams JSON
authorZach Copley <zach@status.net>
Fri, 18 Feb 2011 06:36:14 +0000 (22:36 -0800)
committerZach Copley <zach@status.net>
Fri, 18 Feb 2011 06:36:14 +0000 (22:36 -0800)
lib/activityobject.php
lib/activitystreamjsondocument.php
lib/poco.php
lib/pocoaddress.php
lib/pocourl.php

index ae2f4649e50cd9c908d9d3040a8607eb884247b9..a69e1a1b42fe688cff0e22dfe76f29d196183bc7 100644 (file)
@@ -726,6 +726,10 @@ class ActivityObject
             );
         }
 
+        if (!empty($this->poco)) {
+            $object['contact'] = $this->poco->asArray();
+        }
+
         return array_filter($object);
     }
 }
index f74bb6d2e6d93bb0a0587e6e189931cc9387bb4c..2b99d19eb76f27151c3fced17d7bca3b2416b78e 100644 (file)
@@ -115,7 +115,6 @@ class ActivityStreamJSONDocument
 
         $act          = $notice->asActivity($cur);
         $act->extra[] = $notice->noticeInfo($cur);
-
         array_push($this->doc['items'], $act->asArray());
     }
 
index d7b082163ee21eb4199be57d17463f49f21f7fc5..baea5b33b03f79701bf253cc144da530c65445b9 100644 (file)
@@ -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;
+    }
+
 }
+
index d9f6ff2bdefa8ea988cbb6200a30c2ffa71bd0f7..22d4d02b13d8d08e147c7d7b716d3978b22af084 100644 (file)
@@ -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);
+        }
+    }
 }
index 786793b280d67e2ec53735eb4a1fb4bc8effcff6..e375f125a0a514ec612f2c71bc121af798e321df 100644 (file)
@@ -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;
+    }
 }