/** * Take arguments for running * * @param array $args $_REQUEST args * * @return boolean success flag */ protected function prepare(array $args = array()) { parent::prepare($args); $this->group = $this->getTargetGroup($this->arg('id')); if (empty($this->group)) { $alias = Group_alias::getKV('alias', common_canonical_nickname($this->arg('id'))); if (!empty($alias)) { $args = array('id' => $alias->group_id, 'format' => $this->format); common_redirect(common_local_url('ApiGroupShow', $args), 301); } else { // TRANS: Client error displayed when trying to show a group that could not be found. $this->clientError(_('Group not found.'), 404); } return; } return true; }
protected function prepare(array $args = array()) { parent::prepare($args); $nickname_arg = $this->arg('nickname'); $nickname = common_canonical_nickname($nickname_arg); // Permanent redirect on non-canonical nickname if ($nickname_arg != $nickname) { $args = array('nickname' => $nickname); if ($this->page != 1) { $args['page'] = $this->page; } common_redirect(common_local_url('showgroup', $args), 301); } if (!$nickname) { // TRANS: Client error displayed if no nickname argument was given requesting a group page. $this->clientError(_('No nickname.'), 404); } $local = Local_group::getKV('nickname', $nickname); if (!$local) { $alias = Group_alias::getKV('alias', $nickname); if ($alias) { $args = array('id' => $alias->group_id); if ($this->page != 1) { $args['page'] = $this->page; } common_redirect(common_local_url('groupbyid', $args), 301); } else { common_log(LOG_NOTICE, "Couldn't find local group for nickname '{$nickname}'"); // TRANS: Client error displayed if no remote group with a given name was found requesting group page. $this->clientError(_('No such group.'), 404); } } $this->group = User_group::getKV('id', $local->group_id); if (!$this->group instanceof User_group) { // TRANS: Client error displayed if no local group with a given name was found requesting group page. $this->clientError(_('No such group.'), 404); } }
/** * Is the nickname already in use locally? Checks the User table. * * @param string $str * @return Profile|null Returns Profile if nickname found, otherwise null */ public static function isTaken($str) { $found = User::getKV('nickname', $str); if ($found instanceof User) { return $found->getProfile(); } $found = Local_group::getKV('nickname', $str); if ($found instanceof Local_group) { return $found->getProfile(); } $found = Group_alias::getKV('alias', $str); if ($found instanceof Group_alias) { return $found->getProfile(); } return null; }
static function getForNickname($nickname, Profile $profile = null) { $nickname = Nickname::normalize($nickname); // Are there any matching remote groups this profile's in? if ($profile instanceof Profile) { $group = $profile->getGroups(0, null); while ($group instanceof User_group && $group->fetch()) { if ($group->nickname == $nickname) { // @fixme is this the best way? return clone $group; } } } // If not, check local groups. $group = Local_group::getKV('nickname', $nickname); if ($group instanceof Local_group) { return User_group::getKV('id', $group->group_id); } $alias = Group_alias::getKV('alias', $nickname); if ($alias instanceof Group_alias) { return User_group::getKV('id', $alias->group_id); } return null; }