Merge branch 'testing' of git@gitorious.org:statusnet/mainline into testing

This commit is contained in:
Evan Prodromou 2010-02-25 19:59:01 -05:00
commit 1cae324555
5 changed files with 127 additions and 31 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

@ -1698,7 +1698,8 @@ function common_url_to_nickname($url)
# Strip starting, ending slashes # Strip starting, ending slashes
$path = preg_replace('@/$@', '', $parts['path']); $path = preg_replace('@/$@', '', $parts['path']);
$path = preg_replace('@^/@', '', $path); $path = preg_replace('@^/@', '', $path);
if (strpos($path, '/') === false) { $path = basename($path);
if ($path) {
return common_nicknamize($path); return common_nicknamize($path);
} }
} }

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);
@ -1165,6 +1166,8 @@ class Ostatus_profile extends Memcached_DataObject
$profile->profileurl = $object->link; $profile->profileurl = $object->link;
} else if (array_key_exists('profileurl', $hints)) { } else if (array_key_exists('profileurl', $hints)) {
$profile->profileurl = $hints['profileurl']; $profile->profileurl = $hints['profileurl'];
} else if (Validate::uri($object->id, array('allowed_schemes' => array('http', 'https')))) {
$profile->profileurl = $object->id;
} }
$profile->bio = self::getActivityObjectBio($object, $hints); $profile->bio = self::getActivityObjectBio($object, $hints);