summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2010-02-25 21:53:50 -0500
committerEvan Prodromou <evan@status.net>2010-02-25 21:53:50 -0500
commit254e210763587a6244e7d69eb55aabee5d8ccfa6 (patch)
tree45c46e54eb2e703c3217a5c30abfa9f81c0710b5
parentf9e5acbfa7a8e210e262cbc0fd1f728abdcafed9 (diff)
parent2fa953da22fe932f758882a93106672ab22c1c6d (diff)
Merge branch 'testing' of git@gitorious.org:statusnet/mainline into testing
-rw-r--r--lib/activity.php43
-rw-r--r--plugins/OStatus/classes/Ostatus_profile.php16
2 files changed, 55 insertions, 4 deletions
diff --git a/lib/activity.php b/lib/activity.php
index 161232c42..b20153213 100644
--- a/lib/activity.php
+++ b/lib/activity.php
@@ -360,6 +360,25 @@ class ActivityUtils
return null;
}
+ static function getLinks(DOMNode $element, $rel, $type=null)
+ {
+ $links = $element->getElementsByTagnameNS(self::ATOM, self::LINK);
+ $out = array();
+
+ foreach ($links as $link) {
+
+ $linkRel = $link->getAttribute(self::REL);
+ $linkType = $link->getAttribute(self::TYPE);
+
+ if ($linkRel == $rel &&
+ (is_null($type) || $linkType == $type)) {
+ $out[] = $link;
+ }
+ }
+
+ return $out;
+ }
+
/**
* Gets the first child element with the given tag
*
@@ -472,6 +491,24 @@ class AvatarLink
public $type;
public $size;
public $width;
+ public $height;
+
+ function __construct($element=null)
+ {
+ if ($element) {
+ // @fixme use correct namespaces
+ $this->url = $element->getAttribute('href');
+ $this->type = $element->getAttribute('type');
+ $width = $element->getAttribute('media:width');
+ if ($width != null) {
+ $this->width = intval($width);
+ }
+ $height = $element->getAttribute('media:height');
+ if ($height != null) {
+ $this->height = intval($height);
+ }
+ }
+ }
static function fromAvatar($avatar)
{
@@ -640,8 +677,10 @@ class ActivityObject
if ($this->type == self::PERSON || $this->type == self::GROUP) {
$this->displayName = $this->title;
- // @fixme we may have multiple avatars with different resolutions specified
- $this->avatar = ActivityUtils::getLink($element, 'avatar');
+ $avatars = ActivityUtils::getLinks($element, 'avatar');
+ foreach ($avatars as $link) {
+ $this->avatarLinks[] = new AvatarLink($link);
+ }
$this->poco = new PoCo($element);
}
diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php
index 26d776d52..75b4bef41 100644
--- a/plugins/OStatus/classes/Ostatus_profile.php
+++ b/plugins/OStatus/classes/Ostatus_profile.php
@@ -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'];
}