]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/activity.php
Merge branch 'testing' into 0.9.x
[quix0rs-gnu-social.git] / lib / activity.php
index bd1d5d56c044ec289cbd2ec1304381b77c6d5c65..365bb6258e919d9e2f95d9cae8997f6575649e78 100644 (file)
@@ -53,6 +53,7 @@ class Activity
 {
     const SPEC   = 'http://activitystrea.ms/spec/1.0/';
     const SCHEMA = 'http://activitystrea.ms/schema/1.0/';
+    const MEDIA  = 'http://purl.org/syndication/atommedia';
 
     const VERB       = 'verb';
     const OBJECT     = 'object';
@@ -85,7 +86,7 @@ class Activity
 
     public $actor;   // an ActivityObject
     public $verb;    // a string (the URL)
-    public $object;  // an ActivityObject
+    public $objects = array();  // an array of ActivityObjects
     public $target;  // an ActivityObject
     public $context; // an ActivityObject
     public $time;    // Time of the activity
@@ -116,7 +117,8 @@ class Activity
         // Insist on a feed's root DOMElement; don't allow a DOMDocument
         if ($feed instanceof DOMDocument) {
             throw new ClientException(
-                _("Expecting a root feed element but got a whole XML document.")
+                // TRANS: Client exception thrown when a feed instance is a DOMDocument.
+                _('Expecting a root feed element but got a whole XML document.')
             );
         }
 
@@ -161,12 +163,15 @@ class Activity
             // XXX: do other implied stuff here
         }
 
-        $objectEl = $this->_child($entry, self::OBJECT);
+        $objectEls = $entry->getElementsByTagNameNS(self::SPEC, self::OBJECT);
 
-        if (!empty($objectEl)) {
-            $this->object = new ActivityObject($objectEl);
+        if ($objectEls->length > 0) {
+            for ($i = 0; $i < $objectEls->length; $i++) {
+                $objectEl = $objectEls->item($i);
+                $this->objects[] = new ActivityObject($objectEl);
+            }
         } else {
-            $this->object = new ActivityObject($entry);
+            $this->objects[] = new ActivityObject($entry);
         }
 
         $actorEl = $this->_child($entry, self::ACTOR);
@@ -175,6 +180,17 @@ class Activity
 
             $this->actor = new ActivityObject($actorEl);
 
+            // Cliqset has bad actor IDs (just nickname of user). We
+            // work around it by getting the author data and using its
+            // id instead
+
+            if (!preg_match('/^\w+:/', $this->actor->id)) {
+                $authorEl = ActivityUtils::child($entry, 'author');
+                if (!empty($authorEl)) {
+                    $authorObj = new ActivityObject($authorEl);
+                    $this->actor->id = $authorObj->id;
+                }
+            }
         } else if (!empty($feed) &&
                    $subjectEl = $this->_child($feed, self::SUBJECT)) {
 
@@ -280,8 +296,8 @@ class Activity
             }
         }
 
-        $this->object  = new ActivityObject($item);
-        $this->context = new ActivityContext($item);
+        $this->objects[] = new ActivityObject($item);
+        $this->context   = new ActivityContext($item);
     }
 
     /**
@@ -339,8 +355,10 @@ class Activity
 
         $xs->element('activity:verb', null, $this->verb);
 
-        if ($this->object) {
-            $xs->raw($this->object->asString());
+        if (!empty($this->objects)) {
+            foreach($this->objects as $object) {
+                $xs->raw($object->asString());
+            }
         }
 
         if ($this->target) {