]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/activity.php
Merge branch 'testing' into privategroup
[quix0rs-gnu-social.git] / lib / activity.php
index e29bc1a25da093b812bcf28beb194e19ca0b3e4b..7a33c23b141d05b5d07abbc7553f9f1041d660ba 100644 (file)
@@ -182,6 +182,9 @@ class Activity
         $actorEl = $this->_child($entry, self::ACTOR);
 
         if (!empty($actorEl)) {
+            // Standalone <activity:actor> elements are a holdover from older
+            // versions of ActivityStreams. Newer feeds should have this data
+            // integrated straight into <atom:author>.
 
             $this->actor = new ActivityObject($actorEl);
 
@@ -196,19 +199,24 @@ class Activity
                     $this->actor->id = $authorObj->id;
                 }
             }
-        } else if (!empty($feed) &&
-                   $subjectEl = $this->_child($feed, self::SUBJECT)) {
-
-            $this->actor = new ActivityObject($subjectEl);
-
         } else if ($authorEl = $this->_child($entry, self::AUTHOR, self::ATOM)) {
 
+            // An <atom:author> in the entry overrides any author info on
+            // the surrounding feed.
             $this->actor = new ActivityObject($authorEl);
 
         } else if (!empty($feed) && $authorEl = $this->_child($feed, self::AUTHOR,
                                                               self::ATOM)) {
 
+            // If there's no <atom:author> on the entry, it's safe to assume
+            // the containing feed's authorship info applies.
             $this->actor = new ActivityObject($authorEl);
+        } else if (!empty($feed) &&
+                   $subjectEl = $this->_child($feed, self::SUBJECT)) {
+
+            // Feed subject is used for things like groups.
+            // Should actually possibly not be interpreted as an actor...?
+            $this->actor = new ActivityObject($subjectEl);
         }
 
         $contextEl = $this->_child($entry, self::CONTEXT);
@@ -327,7 +335,7 @@ class Activity
         return null;
     }
 
-    function asString($namespace=false, $author=true)
+    function asString($namespace=false, $author=true, $source=false)
     {
         $xs = new XMLStringer(true);
 
@@ -349,32 +357,7 @@ class Activity
         if ($this->verb == ActivityVerb::POST && count($this->objects) == 1) {
 
             $obj = $this->objects[0];
-
-            $xs->element('id', null, $obj->id);
-            $xs->element('activity:object-type', null, $obj->type);
-            
-            if (!empty($obj->title)) {
-                $xs->element('title', null, $obj->title);
-            } else {
-                // XXX need a better default title
-                $xs->element('title', null, _('Post'));
-            }
-
-            if (!empty($obj->content)) {
-                $xs->element('content', array('type' => 'html'), $obj->content);
-            }
-            
-            if (!empty($obj->summary)) {
-                $xs->element('summary', null, $obj->summary);
-            }
-            
-            if (!empty($obj->link)) {
-                $xs->element('link', array('rel' => 'alternate',
-                                           'type' => 'text/html'),
-                             $obj->link);
-            }
-
-            // XXX: some object types might have other values here.
+                       $obj->outputTo($xs, null);
 
         } else {
             $xs->element('id', null, $this->id);
@@ -402,18 +385,12 @@ class Activity
         $xs->element('updated', null, $published);
             
         if ($author) {
-            $xs->elementStart('author');
-            $xs->element('uri', array(), $this->actor->id);
-            if ($this->actor->title) {
-                $xs->element('name', array(), $this->actor->title);
-            }
-            $xs->elementEnd('author');
-            $xs->raw($this->actor->asString('activity:actor'));
+            $this->actor->outputTo($xs, 'author');
         }
 
         if ($this->verb != ActivityVerb::POST || count($this->objects) != 1) {
             foreach($this->objects as $object) {
-                $xs->raw($object->asString());
+                $object->outputTo($xs, 'activity:object');
             }
         }
 
@@ -467,11 +444,11 @@ class Activity
         }
 
         if ($this->target) {
-            $xs->raw($this->target->asString('activity:target'));
+            $this->target->outputTo($xs, 'activity:target');
         }
 
         foreach ($this->categories as $cat) {
-            $xs->raw($cat->asString());
+            $cat->outputTo($xs);
         }
 
         // can be either URLs or enclosure objects
@@ -494,7 +471,7 @@ class Activity
 
         // Info on the source feed
 
-        if (!empty($this->source)) {
+        if ($source && !empty($this->source)) {
             $xs->elementStart('source');
            
             $xs->element('id', null, $this->source->id);
@@ -549,7 +526,9 @@ class Activity
 
         $xs->elementEnd('entry');
 
-        return $xs->getString();
+        $str = $xs->getString();
+       
+        return $str;
     }
 
     private function _child($element, $tag, $namespace=self::SPEC)