]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Add generator to JSON output
authorEvan Prodromou <evan@e14n.com>
Fri, 7 Jun 2013 15:34:54 +0000 (11:34 -0400)
committerEvan Prodromou <evan@e14n.com>
Fri, 7 Jun 2013 15:35:06 +0000 (11:35 -0400)
classes/Notice.php
lib/activity.php
lib/activityobject.php

index abec8b7af4e719f305156a7f7afce4c79ed4d0c0..9a4b6db7fffadf8d5b62ee573f5b32bc003e99aa 100644 (file)
@@ -1614,6 +1614,12 @@ class Notice extends Managed_DataObject
 
             $act->context = $ctx;
 
+            $source = $this->getSource();
+
+            if ($source) {
+                $act->generator = ActivityObject::fromNoticeSource($source);
+            }
+
             // Source
 
             $atom_feed = $profile->getAtomFeed();
index ecae96b50ab0951f9e6fa2af387c11a42af2797c..779be2a9ad0840b18c81281e114839f7b38f9f2f 100644 (file)
@@ -106,7 +106,7 @@ class Activity
     public $source;  // ActivitySource object representing 'home feed'
     public $selfLink; // <link rel='self' type='application/atom+xml'>
     public $editLink; // <link rel='edit' type='application/atom+xml'>
-
+    public $generator; // ActivityObject representing the generating application
     /**
      * Turns a regular old Atom <entry> into a magical activity
      *
@@ -366,8 +366,11 @@ class Activity
         // content
         $activity['content'] = $this->content;
 
-        // generator <-- We could use this when we know a notice is created
-        //               locally. Or if we know the upstream Generator.
+        // generator
+
+        if (!empty($this->generator)) {
+            $activity['generator'] = $this->generator->asArray();
+        }
 
         // icon <-- possibly a mini object representing verb?
 
index 1352b5bda82ca569ab67e64e7bd64aacbb00676a..31cdb06af78c5dd1786dc2c0d31cb68a5772d5a1 100644 (file)
@@ -72,6 +72,7 @@ class ActivityObject
     const SERVICE   = 'http://activitystrea.ms/schema/1.0/service';
     const IMAGE     = 'http://activitystrea.ms/schema/1.0/image';
     const COLLECTION = 'http://activitystrea.ms/schema/1.0/collection';
+    const APPLICATION = 'http://activitystrea.ms/schema/1.0/application';
 
     // Atom elements we snarf
 
@@ -597,6 +598,46 @@ class ActivityObject
         return $object;
     }
 
+    static function fromNoticeSource(Notice_source $source)
+    {
+        $object = new ActivityObject();
+
+        if (Event::handle('StartActivityObjectFromNoticeSource', array($source, &$object))) {
+            $object->type = ActivityObject::APPLICATION;
+
+            if (in_array($source->code, array('web', 'xmpp', 'mail', 'omb', 'system', 'api'))) {
+                // We use one ID for all well-known StatusNet sources
+                $object->id = "tag:status.net,2009:notice-source:".$source->code;
+            } else if ($source->url) {
+                // They registered with an URL
+                $object->id = $source->url;
+            } else {
+                // Locally-registered, no URL
+                $object->id = TagURI::mint("notice-source:".$source->code);
+            }
+
+            if ($source->url) {
+                $object->link = $source->url;
+            }
+
+            if ($source->name) {
+                $object->title = $source->name;
+            } else {
+                $object->title = $source->code;
+            }
+
+            if ($source->created) {
+                $object->date = $source->created;
+            }
+            
+            $object->extras[] = array('status_net', array('source_code' => $source->code));
+
+            Event::handle('EndActivityObjectFromNoticeSource', array($source, &$object));
+        }
+
+        return $object;
+    }
+
     function outputTo($xo, $tag='activity:object')
     {
         if (!empty($tag)) {
@@ -799,7 +840,7 @@ class ActivityObject
             // summary
             $object['summary'] = $this->summary;
 
-            // summary
+            // content
             $object['content'] = $this->content;
 
             // published (probably don't need. Might be useful for repeats.)