OStatus: pull best-sized avatar image (96x96 if found, otherwise largest, otherwise if none labeled takes the first)

This commit is contained in:
Brion Vibber
2010-02-25 18:51:44 -08:00
parent c8ddcbe0d3
commit 2feb09f434
2 changed files with 55 additions and 4 deletions

View File

@@ -912,8 +912,20 @@ class Ostatus_profile extends Memcached_DataObject
protected static function getActivityObjectAvatar($object, $hints=array())
{
if ($object->avatar) {
return $object->avatar;
if ($object->avatarLinks) {
$best = false;
// Take the exact-size avatar, or the largest avatar, or the first avatar if all sizeless
foreach ($object->avatarLinks as $avatar) {
if ($avatar->width == AVATAR_PROFILE_SIZE && $avatar->height = AVATAR_PROFILE_SIZE) {
// Exact match!
$best = $avatar;
break;
}
if (!$best || $avatar->width > $best->width) {
$best = $avatar;
}
}
return $best->url;
} else if (array_key_exists('avatar', $hints)) {
return $hints['avatar'];
}