]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Rationalize group activity stuff
authorZach Copley <zach@status.net>
Thu, 25 Feb 2010 21:34:43 +0000 (13:34 -0800)
committerZach Copley <zach@status.net>
Thu, 25 Feb 2010 21:34:43 +0000 (13:34 -0800)
classes/User_group.php
lib/activity.php

index f24bef7647ec2b3bd62c1f047f2eec3ddaa6b5a7..7240e27037b32c91a6b6ba37a01e566fbb93b850 100644 (file)
@@ -399,25 +399,41 @@ class User_group extends Memcached_DataObject
         return $xs->getString();
     }
 
+    /**
+     * Returns an XML string fragment with group information as an
+     * Activity Streams <activity:subject> element.
+     *
+     * Assumes that 'activity' namespace has been previously defined.
+     *
+     * @return string
+     */
     function asActivitySubject()
     {
-        $xs = new XMLStringer(true);
+        return $this->asActivityNoun('subject');
+    }
 
-        $xs->elementStart('activity:subject');
-        $xs->element('activity:object', null, 'http://activitystrea.ms/schema/1.0/group');
-        $xs->element('id', null, $this->permalink());
-        $xs->element('title', null, $this->getBestName());
-        $xs->element(
-            'link', array(
-                'rel'  => 'avatar',
-                'href' =>  empty($this->homepage_logo)
-                    ? User_group::defaultLogo(AVATAR_PROFILE_SIZE)
-                    : $this->homepage_logo
-            )
-        );
-        $xs->elementEnd('activity:subject');
+    /**
+     * Returns an XML string fragment with group information as an
+     * Activity Streams noun object with the given element type.
+     *
+     * Assumes that 'activity', 'georss', and 'poco' namespace has been
+     * previously defined.
+     *
+     * @param string $element one of 'actor', 'subject', 'object', 'target'
+     *
+     * @return string
+     */
+    function asActivityNoun($element)
+    {
+        $noun = ActivityObject::fromGroup($this);
+        return $noun->asString('activity:' . $element);
+    }
 
-        return $xs->getString();
+    function getAvatar()
+    {
+        return empty($this->homepage_logo)
+            ? User_group::defaultLogo(AVATAR_PROFILE_SIZE)
+            : $this->homepage_logo;
     }
 
     static function register($fields) {
index e592aad6ffe3f73ae4137cb6f9d02335d420d090..0863cf8fa77b1e5498968b18c7f3cf5f43a90047 100644 (file)
@@ -223,6 +223,37 @@ class PoCo
         return $poco;
     }
 
+    function fromGroup($group)
+    {
+        if (empty($group)) {
+            return null;
+        }
+
+        $poco = new PoCo();
+
+        $poco->preferredUsername = $group->nickname;
+        $poco->displayName       = $group->getBestName();
+
+        $poco->note = $group->description;
+
+        $paddy = new PoCoAddress();
+        $paddy->formatted = $group->location;
+        $poco->address = $paddy;
+
+        if (!empty($group->homepage)) {
+            array_push(
+                $poco->urls,
+                new PoCoURL(
+                    'homepage',
+                    $group->homepage,
+                    true
+                )
+            );
+        }
+
+        return $poco;
+    }
+
     function getPrimaryURL()
     {
         foreach ($this->urls as $url) {
@@ -621,6 +652,21 @@ class ActivityObject
         return $object;
     }
 
+    static function fromGroup($group)
+    {
+        $object = new ActivityObject();
+
+        $object->type   = ActivityObject::GROUP;
+        $object->id     = $group->getUri();
+        $object->title  = $group->getBestName();
+        $object->link   = $group->getUri();
+        $object->avatar = $group->getAvatar();
+
+        $object->poco = PoCo::fromGroup($group);
+
+        return $object;
+    }
+
     function asString($tag='activity:object')
     {
         $xs = new XMLStringer(true);
@@ -656,8 +702,7 @@ class ActivityObject
             );
         }
 
-        if ($this->type == ActivityObject::PERSON
-            || $this->type == ActivityObject::GROUP) {
+        if ($this->type == ActivityObject::PERSON) {
             $xs->element(
                 'link', array(
                     'type' => empty($this->avatar) ? 'image/png' : $this->avatar->mediatype,
@@ -670,6 +715,18 @@ class ActivityObject
             );
         }
 
+        // XXX: Gotta figure out mime-type! Gar.
+
+        if ($this->type == ActivityObject::GROUP) {
+            $xs->element(
+                'link', array(
+                    'rel'  => 'avatar',
+                    'href' => $this->avatar
+                ),
+                null
+            );
+        }
+
         if (!empty($this->geopoint)) {
             $xs->element(
                 'georss:point',