Rationalize group activity stuff
This commit is contained in:
parent
7e0872c7ca
commit
e61edb55d9
|
@ -399,25 +399,41 @@ class User_group extends Memcached_DataObject
|
||||||
return $xs->getString();
|
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()
|
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');
|
* Returns an XML string fragment with group information as an
|
||||||
$xs->element('id', null, $this->permalink());
|
* Activity Streams noun object with the given element type.
|
||||||
$xs->element('title', null, $this->getBestName());
|
*
|
||||||
$xs->element(
|
* Assumes that 'activity', 'georss', and 'poco' namespace has been
|
||||||
'link', array(
|
* previously defined.
|
||||||
'rel' => 'avatar',
|
*
|
||||||
'href' => empty($this->homepage_logo)
|
* @param string $element one of 'actor', 'subject', 'object', 'target'
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function asActivityNoun($element)
|
||||||
|
{
|
||||||
|
$noun = ActivityObject::fromGroup($this);
|
||||||
|
return $noun->asString('activity:' . $element);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAvatar()
|
||||||
|
{
|
||||||
|
return empty($this->homepage_logo)
|
||||||
? User_group::defaultLogo(AVATAR_PROFILE_SIZE)
|
? User_group::defaultLogo(AVATAR_PROFILE_SIZE)
|
||||||
: $this->homepage_logo
|
: $this->homepage_logo;
|
||||||
)
|
|
||||||
);
|
|
||||||
$xs->elementEnd('activity:subject');
|
|
||||||
|
|
||||||
return $xs->getString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static function register($fields) {
|
static function register($fields) {
|
||||||
|
|
|
@ -223,6 +223,37 @@ class PoCo
|
||||||
return $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()
|
function getPrimaryURL()
|
||||||
{
|
{
|
||||||
foreach ($this->urls as $url) {
|
foreach ($this->urls as $url) {
|
||||||
|
@ -621,6 +652,21 @@ class ActivityObject
|
||||||
return $object;
|
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')
|
function asString($tag='activity:object')
|
||||||
{
|
{
|
||||||
$xs = new XMLStringer(true);
|
$xs = new XMLStringer(true);
|
||||||
|
@ -656,8 +702,7 @@ class ActivityObject
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->type == ActivityObject::PERSON
|
if ($this->type == ActivityObject::PERSON) {
|
||||||
|| $this->type == ActivityObject::GROUP) {
|
|
||||||
$xs->element(
|
$xs->element(
|
||||||
'link', array(
|
'link', array(
|
||||||
'type' => empty($this->avatar) ? 'image/png' : $this->avatar->mediatype,
|
'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)) {
|
if (!empty($this->geopoint)) {
|
||||||
$xs->element(
|
$xs->element(
|
||||||
'georss:point',
|
'georss:point',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user