More sensical profile::getUri()

This commit is contained in:
Zach Copley 2010-02-16 20:13:39 -08:00
parent b2a502b336
commit 2cb243808c
2 changed files with 35 additions and 12 deletions

View File

@ -722,6 +722,10 @@ StartRobotsTxt: Before outputting the robots.txt page
EndRobotsTxt: After the default robots.txt page (good place for customization) EndRobotsTxt: After the default robots.txt page (good place for customization)
- &$action: RobotstxtAction being shown - &$action: RobotstxtAction being shown
GetProfileUri: When determining the canonical URI for a given profile StartGetProfileUri: When determining the canonical URI for a given profile
- &$profile: the current profile - $profile: the current profile
- &$uri: the URI
EndGetProfileUri: After determining the canonical URI for a given profile
- $profile: the current profile
- &$uri: the URI

View File

@ -769,7 +769,7 @@ class Profile extends Memcached_DataObject
$xs->elementStart('author'); $xs->elementStart('author');
$xs->element('name', null, $this->nickname); $xs->element('name', null, $this->nickname);
$xs->element('uri', null, $this->profileurl); $xs->element('uri', null, $this->getUri());
$xs->elementEnd('author'); $xs->elementEnd('author');
return $xs->getString(); return $xs->getString();
@ -832,21 +832,40 @@ class Profile extends Memcached_DataObject
return $xs->getString(); return $xs->getString();
} }
/**
* Returns the best URI for a profile. Plugins may override.
*
* @return string $uri
*/
function getUri() function getUri()
{ {
if (Event::handle('GetProfileUri', array($this))) { $uri = null;
$remote = Remote_profile::staticGet('id', $this->id); // check for a local user first
$user = User::staticGet('id', $this->id);
if (!empty($remote)) { if (!empty($user)) {
return $remote->uri; $uri = common_local_url(
} else { 'userbyid',
return common_local_url( array('id' => $user->id)
'userbyid', );
array('id' => $this->id) } else {
);
// give plugins a chance to set the URI
if (Event::handle('StartGetProfileUri', array($this, &$uri))) {
// return OMB profile if any
$remote = Remote_profile::staticGet('id', $this->id);
if (!empty($remote)) {
$uri = $remote->uri;
}
Event::handle('EndGetProfileUri', array($this, &$uri));
} }
} }
return $uri;
} }
} }