}
}
+ public function isPerson()
+ {
+ // Maybe other things than PERSON and GROUP can have Profiles in the future?
+ return !$this->isGroup();
+ }
+
public function isLocal()
{
try {
$avatar->mediatype = image_type_to_mime_type($imagefile->type);
$avatar->filename = $filename;
$avatar->original = true;
- $avatar->url = Avatar::url($filename);
$avatar->created = common_sql_now();
// XXX: start a transaction here
}
}
+ function silenceAs(Profile $actor)
+ {
+ if (!$actor->hasRight(Right::SILENCEUSER)) {
+ throw new AuthorizationException(_('You cannot silence users on this site.'));
+ }
+ // Only administrators can silence other privileged users (such as others who have the right to silence).
+ if ($this->isPrivileged() && !$actor->hasRole(Profile_role::ADMINISTRATOR)) {
+ throw new AuthorizationException(_('You cannot silence other privileged users.'));
+ }
+ if ($this->isSilenced()) {
+ // TRANS: Client error displayed trying to silence an already silenced user.
+ throw new AlreadyFulfilledException(_('User is already silenced.'));
+ }
+ return $this->silence();
+ }
+
function unsilence()
{
$this->revokeRole(Profile_role::SILENCED);
}
}
+ function unsilenceAs(Profile $actor)
+ {
+ if (!$actor->hasRight(Right::SILENCEUSER)) {
+ // TRANS: Client error displayed trying to unsilence a user when the user does not have the right.
+ throw new AuthorizationException(_('You cannot unsilence users on this site.'));
+ }
+ if (!$this->isSilenced()) {
+ // TRANS: Client error displayed trying to unsilence a user when the target user has not been silenced.
+ throw new AlreadyFulfilledException(_('User is not silenced.'));
+ }
+ return $this->unsilence();
+ }
+
function flushVisibility()
{
// Get all notices
}
}
+ public function isPrivileged()
+ {
+ // TODO: An Event::handle so plugins can report if users are privileged.
+ // The ModHelper is the only one I care about when coding this, and that
+ // can be tested with Right::SILENCEUSER which I do below:
+ switch (true) {
+ case $this->hasRight(Right::SILENCEUSER):
+ case $this->hasRole(Profile_role::MODERATOR):
+ case $this->hasRole(Profile_role::ADMINISTRATOR):
+ case $this->hasRole(Profile_role::OWNER):
+ return true;
+ }
+
+ return false;
+ }
+
/**
* Does this user have the right to do X?
*
*/
public function getUrl()
{
- if (empty($this->profileurl) ||
- !filter_var($this->profileurl, FILTER_VALIDATE_URL)) {
- throw new InvalidUrlException($this->profileurl);
+ $url = null;
+ if ($this->isGroup()) {
+ // FIXME: Get rid of this event, it fills no real purpose, data should be in Profile->profileurl (replaces User_group->mainpage)
+ if (Event::handle('StartUserGroupHomeUrl', array($this->getGroup(), &$url))) {
+ $url = $this->getGroup()->isLocal()
+ ? common_local_url('showgroup', array('nickname' => $this->getNickname()))
+ : $this->profileurl;
+ }
+ Event::handle('EndUserGroupHomeUrl', array($this->getGroup(), $url));
+ } elseif ($this->isLocal()) {
+ $url = common_local_url('showstream', array('nickname' => $this->getNickname()));
+ } else {
+ $url = $this->profileurl;
}
- return $this->profileurl;
+ if (empty($url) ||
+ !filter_var($url, FILTER_VALIDATE_URL)) {
+ throw new InvalidUrlException($url);
+ }
+ return $url;
}
public function getNickname()
$user = User::getKV('uri', $uri);
if ($user instanceof User) {
$profile = $user->getProfile();
+ } else {
+ $group = User_group::getKV('uri', $uri);
+ if ($group instanceof User_group) {
+ $profile = $group->getProfile();
+ }
}
Event::handle('EndGetProfileFromURI', array($uri, $profile));
}
return $profile;
}
+ static function ensureCurrent()
+ {
+ $profile = self::current();
+ if (!$profile instanceof Profile) {
+ throw new AuthorizationException('A currently scoped profile is required.');
+ }
+ return $profile;
+ }
+
/**
* Magic function called at serialize() time.
*