/**
* Table Definition for profile
*/
-require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
-
class Profile extends Managed_DataObject
{
###START_AUTOCODE
return true;
}
+ public function getObjectType()
+ {
+ // FIXME: More types... like peopletags and whatever
+ if ($this->isGroup()) {
+ return ActivityObject::GROUP;
+ } else {
+ return ActivityObject::PERSON;
+ }
+ }
+
public function getAvatar($width, $height=null)
{
return Avatar::byProfile($this, $width, $height);
*/
function asActivityNoun($element)
{
- $noun = ActivityObject::fromProfile($this);
+ $noun = $this->asActivityObject();
return $noun->asString('activity:' . $element);
}
+ public function asActivityObject()
+ {
+ $object = new ActivityObject();
+
+ if (Event::handle('StartActivityObjectFromProfile', array($this, &$object))) {
+ $object->type = $this->getObjectType();
+ $object->id = $this->getUri();
+ $object->title = $this->getBestName();
+ $object->link = $this->getUrl();
+
+ try {
+ $avatar = Avatar::getUploaded($this);
+ $object->avatarLinks[] = AvatarLink::fromAvatar($avatar);
+ } catch (NoAvatarException $e) {
+ // Could not find an original avatar to link
+ }
+
+ $sizes = array(
+ AVATAR_PROFILE_SIZE,
+ AVATAR_STREAM_SIZE,
+ AVATAR_MINI_SIZE
+ );
+
+ foreach ($sizes as $size) {
+ $alink = null;
+ try {
+ $avatar = Avatar::byProfile($this, $size);
+ $alink = AvatarLink::fromAvatar($avatar);
+ } catch (NoAvatarException $e) {
+ $alink = new AvatarLink();
+ $alink->type = 'image/png';
+ $alink->height = $size;
+ $alink->width = $size;
+ $alink->url = Avatar::defaultImage($size);
+ }
+
+ $object->avatarLinks[] = $alink;
+ }
+
+ if (isset($this->lat) && isset($this->lon)) {
+ $object->geopoint = (float)$this->lat
+ . ' ' . (float)$this->lon;
+ }
+
+ $object->poco = PoCo::fromProfile($this);
+
+ if ($this->isLocal()) {
+ $object->extra[] = array('followers', array('url' => common_local_url('subscribers', array('nickname' => $this->getNickname()))));
+ }
+
+ Event::handle('EndActivityObjectFromProfile', array($this, &$object));
+ }
+
+ return $object;
+ }
+
/**
* Returns the profile's canonical url, not necessarily a uri/unique id
*
static function fromProfile(Profile $profile)
{
- $object = new ActivityObject();
-
- if (Event::handle('StartActivityObjectFromProfile', array($profile, &$object))) {
- $object->type = ActivityObject::PERSON;
- $object->id = $profile->getUri();
- $object->title = $profile->getBestName();
- $object->link = $profile->profileurl;
-
- try {
- $avatar = Avatar::getUploaded($profile);
- $object->avatarLinks[] = AvatarLink::fromAvatar($avatar);
- } catch (NoAvatarException $e) {
- // Could not find an original avatar to link
- }
-
- $sizes = array(
- AVATAR_PROFILE_SIZE,
- AVATAR_STREAM_SIZE,
- AVATAR_MINI_SIZE
- );
-
- foreach ($sizes as $size) {
- $alink = null;
- try {
- $avatar = Avatar::byProfile($profile, $size);
- $alink = AvatarLink::fromAvatar($avatar);
- } catch (NoAvatarException $e) {
- $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)) {
- $object->geopoint = (float)$profile->lat
- . ' ' . (float)$profile->lon;
- }
-
- $object->poco = PoCo::fromProfile($profile);
-
- if ($profile->isLocal()) {
- $object->extra[] = array('followers', array('url' => common_local_url('subscribers', array('nickname' => $profile->nickname))));
- }
-
- Event::handle('EndActivityObjectFromProfile', array($profile, &$object));
- }
-
- return $object;
+ return $profile->asActivityObject();
}
static function fromGroup(User_group $group)