Add lots of fun avatars to our Atom output

This commit is contained in:
Zach Copley 2010-02-25 16:06:49 -08:00
parent bac959ad46
commit 7922edb5b6
4 changed files with 123 additions and 30 deletions

View File

@ -1096,6 +1096,7 @@ class Notice extends Memcached_DataObject
'xmlns:thr' => 'http://purl.org/syndication/thread/1.0', 'xmlns:thr' => 'http://purl.org/syndication/thread/1.0',
'xmlns:georss' => 'http://www.georss.org/georss', 'xmlns:georss' => 'http://www.georss.org/georss',
'xmlns:activity' => 'http://activitystrea.ms/spec/1.0/', 'xmlns:activity' => 'http://activitystrea.ms/spec/1.0/',
'xmlns:media' => 'http://purl.org/syndication/atommedia',
'xmlns:poco' => 'http://portablecontacts.net/spec/1.0', 'xmlns:poco' => 'http://portablecontacts.net/spec/1.0',
'xmlns:ostatus' => 'http://ostatus.org/schema/1.0'); 'xmlns:ostatus' => 'http://ostatus.org/schema/1.0');
} else { } else {

View File

@ -465,6 +465,57 @@ class ActivityUtils
} }
} }
// XXX: Arg! This wouldn't be necessary if we used Avatars conistently
class AvatarLink
{
public $url;
public $type;
public $size;
public $width;
static function fromAvatar($avatar)
{
if (empty($avatar)) {
return null;
}
$alink = new AvatarLink();
$alink->type = $avatar->mediatype;
$alink->height = $avatar->mediatype;
$alink->width = $avatar->width;
$alink->url = $avatar->displayUrl();
return $alink;
}
static function fromFilename($filename, $size)
{
$alink = new AvatarLink();
$alink->url = $filename;
$alink->height = $size;
if (!empty($filename)) {
$alink->width = $size;
$alink->type = self::mediatype($filename);
} else {
$alink->url = User_group::defaultLogo($size);
$alink->type = 'image/png';
}
return $alink;
}
// yuck!
static function mediatype($filename) {
$ext = strtolower(end(explode('.', $filename)));
if ($ext == 'jpeg') {
$ext = 'jpg';
}
// hope we don't support any others
$types = array('png', 'gif', 'jpg', 'jpeg');
if (in_array($ext, $types)) {
return 'image/' . $ext;
}
return null;
}
}
/** /**
* A noun-ish thing in the activity universe * A noun-ish thing in the activity universe
* *
@ -521,7 +572,7 @@ class ActivityObject
public $content; public $content;
public $link; public $link;
public $source; public $source;
public $avatar; public $avatarLinks = array();
public $geopoint; public $geopoint;
public $poco; public $poco;
public $displayName; public $displayName;
@ -641,13 +692,40 @@ class ActivityObject
$object->id = $profile->getUri(); $object->id = $profile->getUri();
$object->title = $profile->getBestName(); $object->title = $profile->getBestName();
$object->link = $profile->profileurl; $object->link = $profile->profileurl;
$avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
if ($avatar) { $orig = $profile->getOriginalAvatar();
$object->avatar = $avatar->displayUrl();
if (!empty($orig)) {
$object->avatarLinks[] = AvatarLink::fromAvatar($orig);
}
$sizes = array(
AVATAR_PROFILE_SIZE,
AVATAR_STREAM_SIZE,
AVATAR_MINI_SIZE
);
foreach ($sizes as $size) {
$alink = null;
$avatar = $profile->getAvatar($size);
if (!empty($avatar)) {
$alink = AvatarLink::fromAvatar($avatar);
} else {
$alink = new AvatarLink();
$alink->type = 'image/png';
$alink->height = $size;
$alink->width = $size;
$alink->url = Avatar::defaultImage($size);
}
$object->avatarLinks[] = $alink;
} }
if (isset($profile->lat) && isset($profile->lon)) { if (isset($profile->lat) && isset($profile->lon)) {
$object->geopoint = (float)$profile->lat . ' ' . (float)$profile->lon; $object->geopoint = (float)$profile->lat
. ' ' . (float)$profile->lon;
} }
$object->poco = PoCo::fromProfile($profile); $object->poco = PoCo::fromProfile($profile);
@ -663,13 +741,28 @@ class ActivityObject
$object->id = $group->getUri(); $object->id = $group->getUri();
$object->title = $group->getBestName(); $object->title = $group->getBestName();
$object->link = $group->getUri(); $object->link = $group->getUri();
$object->avatar = $group->getAvatar();
$object->avatarLinks[] = AvatarLink::fromFilename(
$group->homepage_logo,
AVATAR_PROFILE_SIZE
);
$object->avatarLinks[] = AvatarLink::fromFilename(
$group->stream_logo,
AVATAR_STREAM_SIZE
);
$object->avatarLinks[] = AvatarLink::fromFilename(
$group->mini_logo,
AVATAR_MINI_SIZE
);
$object->poco = PoCo::fromGroup($group); $object->poco = PoCo::fromGroup($group);
return $object; return $object;
} }
function asString($tag='activity:object') function asString($tag='activity:object')
{ {
$xs = new XMLStringer(true); $xs = new XMLStringer(true);
@ -705,29 +798,21 @@ class ActivityObject
); );
} }
if ($this->type == ActivityObject::PERSON) { if ($this->type == ActivityObject::PERSON
$xs->element( || $this->type == ActivityObject::GROUP) {
'link', array(
'type' => empty($this->avatar) ? 'image/png' : $this->avatar->mediatype,
'rel' => 'avatar',
'href' => empty($this->avatar)
? Avatar::defaultImage(AVATAR_PROFILE_SIZE)
: $this->avatar
),
null
);
}
// XXX: Gotta figure out mime-type! Gar. foreach ($this->avatarLinks as $avatar) {
$xs->element(
if ($this->type == ActivityObject::GROUP) { 'link', array(
$xs->element( 'rel' => 'avatar',
'link', array( 'type' => $avatar->type,
'rel' => 'avatar', 'media:width' => $avatar->width,
'href' => $this->avatar 'media:height' => $avatar->height,
), 'href' => $avatar->url
null ),
); null
);
}
} }
if (!empty($this->geopoint)) { if (!empty($this->geopoint)) {
@ -1038,7 +1123,8 @@ class Activity
'xmlns:activity' => 'http://activitystrea.ms/spec/1.0/', 'xmlns:activity' => 'http://activitystrea.ms/spec/1.0/',
'xmlns:georss' => 'http://www.georss.org/georss', 'xmlns:georss' => 'http://www.georss.org/georss',
'xmlns:ostatus' => 'http://ostatus.org/schema/1.0', 'xmlns:ostatus' => 'http://ostatus.org/schema/1.0',
'xmlns:poco' => 'http://portablecontacts.net/spec/1.0'); 'xmlns:poco' => 'http://portablecontacts.net/spec/1.0',
'xmlns:media' => 'http://purl.org/syndication/atommedia');
} else { } else {
$attrs = array(); $attrs = array();
} }

View File

@ -64,6 +64,11 @@ class AtomNoticeFeed extends Atom10Feed
'http://activitystrea.ms/spec/1.0/' 'http://activitystrea.ms/spec/1.0/'
); );
$this->addNamespace(
'media',
'http://purl.org/syndication/atommedia'
);
$this->addNamespace( $this->addNamespace(
'poco', 'poco',
'http://portablecontacts.net/spec/1.0' 'http://portablecontacts.net/spec/1.0'

View File

@ -401,7 +401,8 @@ class Ostatus_profile extends Memcached_DataObject
'xmlns:thr' => 'http://purl.org/syndication/thread/1.0', 'xmlns:thr' => 'http://purl.org/syndication/thread/1.0',
'xmlns:georss' => 'http://www.georss.org/georss', 'xmlns:georss' => 'http://www.georss.org/georss',
'xmlns:ostatus' => 'http://ostatus.org/schema/1.0', 'xmlns:ostatus' => 'http://ostatus.org/schema/1.0',
'xmlns:poco' => 'http://portablecontacts.net/spec/1.0'); 'xmlns:poco' => 'http://portablecontacts.net/spec/1.0',
'xmlns:media' => 'http://purl.org/syndication/atommedia');
$entry = new XMLStringer(); $entry = new XMLStringer();
$entry->elementStart('entry', $attributes); $entry->elementStart('entry', $attributes);