]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/activityobject.php
Twitter lists compatible people tags api
[quix0rs-gnu-social.git] / lib / activityobject.php
index 7847a5d640a52b624d24e993d1026078ad2cc311..7771455443d217f53a28511de82dce7081664121 100644 (file)
@@ -64,6 +64,7 @@ class ActivityObject
     const BOOKMARK  = 'http://activitystrea.ms/schema/1.0/bookmark';
     const PERSON    = 'http://activitystrea.ms/schema/1.0/person';
     const GROUP     = 'http://activitystrea.ms/schema/1.0/group';
+    const _LIST     = 'http://activitystrea.ms/schema/1.0/list'; // LIST is reserved
     const PLACE     = 'http://activitystrea.ms/schema/1.0/place';
     const COMMENT   = 'http://activitystrea.ms/schema/1.0/comment';
     // ^^^^^^^^^^ tea!
@@ -92,6 +93,7 @@ class ActivityObject
     public $title;
     public $summary;
     public $content;
+    public $owner;
     public $link;
     public $source;
     public $avatarLinks = array();
@@ -168,6 +170,10 @@ class ActivityObject
                 Activity::MEDIA
             );
         }
+        if ($this->type == self::_LIST) {
+            $owner = ActivityUtils::child($this->element, Activity::AUTHOR, Activity::SPEC);
+            $this->owner = new ActivityObject($owner);
+        }
     }
 
     private function _fromAuthor($element)
@@ -520,13 +526,29 @@ class ActivityObject
                                                                                                                          AVATAR_MINI_SIZE);
 
                        $object->poco = PoCo::fromGroup($group);
-
-                       Event::handle('EndActivityObjectFromGroup', array($group, &$object));
+                   Event::handle('EndActivityObjectFromGroup', array($group, &$object));
                }
 
         return $object;
     }
 
+    static function fromPeopletag($ptag)
+    {
+        $object = new ActivityObject();
+        if (Event::handle('StartActivityObjectFromPeopletag', array($ptag, &$object))) {
+            $object->type    = ActivityObject::_LIST;
+
+            $object->id      = $ptag->getUri();
+            $object->title   = $ptag->tag;
+            $object->summary = $ptag->description;
+            $object->link    = $ptag->homeUrl();
+            $object->owner   = Profile::staticGet('id', $ptag->tagger);
+            $object->poco    = PoCo::fromProfile($object->owner);
+                   Event::handle('EndActivityObjectFromPeopletag', array($ptag, &$object));
+        }
+        return $object;
+    }
+
        function outputTo($xo, $tag='activity:object')
        {
                if (!empty($tag)) {
@@ -601,6 +623,11 @@ class ActivityObject
             }
         }
 
+        if(!empty($this->owner)) {
+            $owner = $this->owner->asActivityNoun(self::AUTHOR);
+            $xo->raw($owner);
+        }
+
         if (!empty($this->geopoint)) {
             $xo->element(
                 'georss:point',
@@ -645,40 +672,51 @@ class ActivityObject
     {
         $object = array();
 
-        // TODO: attachedObjects
+        // XXX: attachedObjects are added by Activity
 
         // displayName
         $object['displayName'] = $this->title;
 
-
         // TODO: downstreamDuplicates
-        // TODO: embedCode (video)
+
+        // embedCode (used for video)
 
         // id
+        //
+        // XXX: Should we use URL here? or a crazy tag URI?
         $object['id'] = $this->id;
 
         if ($this->type == ActivityObject::PERSON
             || $this->type == ActivityObject::GROUP) {
 
             // XXX: Not sure what the best avatar is to use for the
-            // author's "image". For now, I'm using the stream size
-            // one, but possibly it should be large
-            $avatarLink = null;
+            // author's "image". For now, I'm using the large size.
+
+            $avatarLarge      = null;
+            $avatarMediaLinks = array();
 
             foreach ($this->avatarLinks as $a) {
-                if ($a->height == AVATAR_STREAM_SIZE) {
-                    $avatarLink = $a;
-                    break;
+
+                // Make a MediaLink for every other Avatar
+                $avatar = new ActivityStreamsMediaLink(
+                    $a->url,
+                    $a->width,
+                    $a->height,
+                    $a->type,
+                    'avatar'
+                );
+
+                // Find the big avatar to use as the "image"
+                if ($a->height == AVATAR_PROFILE_SIZE) {
+                    $imgLink = $avatar;
                 }
+
+                $avatarMediaLinks[] = $avatar->asArray();
             }
 
-            $imgLink = new ActivityStreamsMediaLink(
-                $avatarLink->url,
-                $avatarLink->width,
-                $avatarLink->height,
-                $avatarLink->type
-            );
+            $object['avatarLinks'] = $avatarMediaLinks; // extension
 
+            // image
             $object['image']  = $imgLink->asArray();
         }
 
@@ -696,7 +734,28 @@ class ActivityObject
         // url (XXX: need to put the right thing here...)
         $object['url'] = $this->id;
 
-        // TODO: extensions (OStatus stuff, etc.)
+        /* Extensions */
+
+        foreach ($this->extra as $e) {
+            list($objectName, $props, $txt) = $e;
+            $object[$objectName] = $props;
+        }
+
+        // GeoJSON
+
+        if (!empty($this->geopoint)) {
+
+            list($lat, $long) = explode(' ', $this->geopoint);
+
+            $object['geopoint'] = array(
+                'type'        => 'Point',
+                'coordinates' => array($lat, $long)
+            );
+        }
+
+        if (!empty($this->poco)) {
+            $object['contact'] = $this->poco->asArray();
+        }
 
         return array_filter($object);
     }