]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Slightly better ActivityStreams JSON output
authorEvan Prodromou <evan@e14n.com>
Tue, 4 Jun 2013 21:00:51 +0000 (17:00 -0400)
committerEvan Prodromou <evan@e14n.com>
Tue, 4 Jun 2013 21:00:51 +0000 (17:00 -0400)
lib/activity.php
lib/activityobject.php
lib/activityverb.php

index 592c56bcbd1bc85f61916c779c4f7824120f212e..b8c94262685473fa7c8acae82d576bb629a42b0c 100644 (file)
@@ -397,37 +397,6 @@ class Activity
                 $activity['object']['objectType'] = 'activity';
             }
 
-            // Context stuff. For now I'm just sticking most of it
-            // in a property called "context"
-
-            if (!empty($this->context)) {
-
-                if (!empty($this->context->location)) {
-                    $loc = $this->context->location;
-
-                    $activity['location'] = array(
-                        'objectType' => 'place',
-                        'position' => sprintf("%+02.5F%+03.5F/", $loc->lat, $loc->lon),
-                        'lat' => $loc->lat,
-                        'lon' => $loc->lon
-                    );
-
-                    $name = $loc->getName();
-
-                    if ($name) {
-                        $activity['location']['displayName'] = $name;
-                    }
-                    
-                    $url = $loc->getURL();
-
-                    if ($url) {
-                        $activity['location']['url'] = $url;
-                    }
-                }
-
-                $activity['to']      = $this->context->getToArray();
-                $activity['context'] = $this->context->asArray();
-            }
 
             // Instead of adding enclosures as an extension to JSON
             // Activities, it seems like we should be using the
@@ -471,6 +440,51 @@ class Activity
                 $activity['object']['attachments'] = $attachments;
             }
         }
+        
+        // Context stuff.
+
+        if (!empty($this->context)) {
+
+            if (!empty($this->context->location)) {
+                $loc = $this->context->location;
+
+                $activity['location'] = array(
+                    'objectType' => 'place',
+                    'position' => sprintf("%+02.5F%+03.5F/", $loc->lat, $loc->lon),
+                    'lat' => $loc->lat,
+                    'lon' => $loc->lon
+                );
+
+                $name = $loc->getName();
+
+                if ($name) {
+                    $activity['location']['displayName'] = $name;
+                }
+                    
+                $url = $loc->getURL();
+
+                if ($url) {
+                    $activity['location']['url'] = $url;
+                }
+            }
+
+            $activity['to']      = $this->context->getToArray();
+
+            $ctxarr = $this->context->asArray();
+
+            if (array_key_exists('inReplyTo', $ctxarr)) {
+                $activity['object']['inReplyTo'] = $ctxarr['inReplyTo'];
+                unset($ctxarr['inReplyTo']);
+            }
+
+            if (!array_key_exists('status_net', $activity)) {
+                $activity['status_net'] = array();
+            }
+
+            foreach ($ctxarr as $key => $value) {
+                $activity['status_net'][$key] = $value;
+            }
+        }
 
         // published
         $activity['published'] = self::iso8601Date($this->time);
@@ -496,10 +510,8 @@ class Activity
         //             eceived a remote notice? Probably not.
 
         // verb
-        //
-        // We can probably use the whole schema URL here but probably the
-        // relative simple name is easier to parse
-        $activity['verb'] = substr($this->verb, strrpos($this->verb, '/') + 1);
+
+        $activity['verb'] = ActivityVerb::canonical($this->verb);
 
         // url
         $activity['url'] = $this->id;
@@ -527,7 +539,15 @@ class Activity
         foreach ($this->extra as $e) {
             list($objectName, $props, $txt) = $e;
             if (!empty($objectName)) {
-                $activity[$objectName] = $props;
+                $parts = explode(":", $objectName);
+                if (count($parts) == 2 && $parts[0] == "statusnet") {
+                    if (!array_key_exists('status_net', $activity)) {
+                        $activity['status_net'] = array();
+                    }
+                    $activity['status_net'][$parts[1]] = $props;
+                } else {
+                    $activity[$objectName] = $props;
+                }
             }
         }
 
index f1c708db2e38e832d1ef3925f9b19bf1e57dbe0e..13592ad32b240fb6f52362f6712519b3cf1bb8fd 100644 (file)
@@ -778,4 +778,13 @@ class ActivityObject
         }
         return array_filter($object);
     }
+
+    static function canonicalType($type) {
+        $ns = 'http://activitystrea.ms/schema/1.0/';
+        if (substr($type, 0, mb_strlen($ns)) == $ns) {
+            return substr($type, mb_strlen($ns));
+        } else {
+            return $type;
+        }
+    }
 }
index 5ee68f28804fcda7eba1589f0e4c682d7cad8cdb..513605b620a84356e7c82e2e3ad7c4bf05ff35de 100644 (file)
@@ -63,4 +63,13 @@ class ActivityVerb
 
     // For simple profile-update pings; no content to share.
     const UPDATE_PROFILE = 'http://ostatus.org/schema/1.0/update-profile';
+
+    static function canonical($verb) {
+        $ns = 'http://activitystrea.ms/schema/1.0/';
+        if (substr($verb, 0, mb_strlen($ns)) == $ns) {
+            return substr($verb, mb_strlen($ns));
+        } else {
+            return $verb;
+        }
+    }
 }