summaryrefslogtreecommitdiff
path: root/lib/activity.php
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-02-25 18:51:44 -0800
committerBrion Vibber <brion@pobox.com>2010-02-25 18:51:44 -0800
commit2feb09f4346e54805f68a9f677f5a94340875d8e (patch)
tree1c4f2161154853bb672b05755c6ee52df22d5858 /lib/activity.php
parentc8ddcbe0d32fb072456587fc554f6b78db672fa7 (diff)
OStatus: pull best-sized avatar image (96x96 if found, otherwise largest, otherwise if none labeled takes the first)
Diffstat (limited to 'lib/activity.php')
-rw-r--r--lib/activity.php43
1 files changed, 41 insertions, 2 deletions
diff --git a/lib/activity.php b/lib/activity.php
index 0f30e8bf5..b64a82f0a 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);
}