summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--classes/User_group.php46
-rw-r--r--lib/activity.php61
2 files changed, 90 insertions, 17 deletions
diff --git a/classes/User_group.php b/classes/User_group.php
index f24bef764..7240e2703 100644
--- a/classes/User_group.php
+++ b/classes/User_group.php
@@ -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) {
diff --git a/lib/activity.php b/lib/activity.php
index e592aad6f..0863cf8fa 100644
--- a/lib/activity.php
+++ b/lib/activity.php
@@ -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',