Make Profile->getFancyUrl() somewhat better on fallback

It tries to get a referential identifier apart from the fullname trying
with acct: URI, profile URL and lastly URI.
This commit is contained in:
Mikael Nordfeldth 2016-03-01 23:48:32 +01:00
parent ddd60e7142
commit 4abb3f19bf
1 changed files with 18 additions and 6 deletions

View File

@ -218,18 +218,30 @@ class Profile extends Managed_DataObject
}
/**
* Gets the full name (if filled) with nickname as a parenthetical, or the nickname alone
* if no fullname is provided.
* Gets the full name (if filled) with acct URI, URL, or URI as a
* parenthetical (in that order, for each not found). If no full
* name is found only the second part is returned, without ()s.
*
* @return string
*/
function getFancyName()
{
if ($this->getFullname()) {
// TRANS: Full name of a profile or group (%1$s) followed by acct URI (%2$s) in parentheses without acct:.
return sprintf(_m('FANCYNAME','%1$s (%2$s)'), $this->getFullname(), $this->getAcctUri());
$uri = null;
try {
$uri = $this->getAcctUri();
} catch (ProfileNoAcctUriException $e) {
try {
$uri = $this->getUrl();
} catch (InvalidUrlException $e) {
$uri = $this->getUri();
}
}
if (mb_strlen($this->getFullname()) > 0) {
// TRANS: Full name of a profile or group (%1$s) followed by some URI (%2$s) in parentheses.
return sprintf(_m('FANCYNAME','%1$s (%2$s)'), $this->getFullname(), $uri);
} else {
return $this->getAcctUri(false);
return $uri;
}
}