X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Fnewgroup.php;h=ef8346c03ef053b37868da8933d0e10db7216a14;hb=2a8ab1c6cae572d324339b211625c4d219db0c89;hp=0845f4d6d9116d6e4209cd963d2906b9b19368e9;hpb=cfa699e445641c2f81eec1c44d12c122efbc1797;p=quix0rs-gnu-social.git diff --git a/actions/newgroup.php b/actions/newgroup.php index 0845f4d6d9..ef8346c03e 100644 --- a/actions/newgroup.php +++ b/actions/newgroup.php @@ -24,13 +24,12 @@ * @author Evan Prodromou * @author Sarven Capadisli * @copyright 2008-2009 StatusNet, Inc. + * @copyright 2013 Free Software Foundation, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ -if (!defined('STATUSNET')) { - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } /** * Add a new group @@ -45,53 +44,39 @@ if (!defined('STATUSNET')) { */ class NewgroupAction extends FormAction { + protected $group; + + protected $form = 'GroupEdit'; + + function getGroup() { + return $this->group; + } + function title() { // TRANS: Title for form to create a group. return _('New group'); } - /** - * Prepare to run - */ - protected function prepare($args) + protected function doPreparation() { - parent::prepare($args); - - if (!common_logged_in()) { - // TRANS: Client error displayed trying to create a group while not logged in. - $this->clientError(_('You must be logged in to create a group.')); - return false; - } - // $this->scoped is the current user profile if (!$this->scoped->hasRight(Right::CREATEGROUP)) { // TRANS: Client exception thrown when a user tries to create a group while banned. - throw new ClientException(_('You are not allowed to create groups on this site.'), 403); + $this->clientError(_('You are not allowed to create groups on this site.'), 403); } - - return true; - } - - public function showContent() - { - $form = new GroupEditForm($this); - $form->show(); } - public function showInstructions() + protected function getInstructions() { - $this->element('p', 'instructions', - // TRANS: Form instructions for group create form. - _('Use this form to create a new group.')); + // TRANS: Form instructions for group create form. + return _('Use this form to create a new group.'); } - protected function handlePost() + protected function doPost() { - parent::handlePost(); - if (Event::handle('StartGroupSaveForm', array($this))) { - $nickname = Nickname::normalize($this->trimmed('newnickname')); + $nickname = Nickname::normalize($this->trimmed('newnickname'), true); $fullname = $this->trimmed('fullname'); $homepage = $this->trimmed('homepage'); @@ -100,16 +85,8 @@ class NewgroupAction extends FormAction $private = $this->boolean('private'); $aliasstring = $this->trimmed('aliases'); - if ($this->nicknameExists($nickname)) { - // TRANS: Group create form validation error. - throw new ClientException(_('Nickname already in use. Try another one.')); - } else if (!User_group::allowedNickname($nickname)) { - // TRANS: Group create form validation error. - throw new ClientException(_('Not a valid nickname.')); - } else if (!is_null($homepage) && (strlen($homepage) > 0) && - !Validate::uri($homepage, - array('allowed_schemes' => - array('http', 'https')))) { + if (!is_null($homepage) && (strlen($homepage) > 0) && + !common_valid_http_url($homepage)) { // TRANS: Group create form validation error. throw new ClientException(_('Homepage is not a valid URL.')); } else if (!is_null($fullname) && mb_strlen($fullname) > 255) { @@ -128,7 +105,7 @@ class NewgroupAction extends FormAction } if (!empty($aliasstring)) { - $aliases = array_map('common_canonical_nickname', array_unique(preg_split('/[\s,]+/', $aliasstring))); + $aliases = array_map(array('Nickname', 'normalize'), array_unique(preg_split('/[\s,]+/', $aliasstring))); } else { $aliases = array(); } @@ -140,25 +117,6 @@ class NewgroupAction extends FormAction 'Too many aliases! Maximum %d allowed.', common_config('group', 'maxaliases')), common_config('group', 'maxaliases'))); - return; - } - - foreach ($aliases as $alias) { - if (!Nickname::isValid($alias)) { - // TRANS: Group create form validation error. - // TRANS: %s is the invalid alias. - throw new ClientException(sprintf(_('Invalid alias: "%s"'), $alias)); - } - if ($this->nicknameExists($alias)) { - // TRANS: Group create form validation error. %s is the already used alias. - throw new ClientException(sprintf(_('Alias "%s" already in use. Try another one.'), - $alias)); - } - // XXX assumes alphanum nicknames - if (strcmp($alias, $nickname) == 0) { - // TRANS: Group create form validation error. - throw new ClientException(_('Alias cannot be the same as nickname.')); - } } if ($private) { @@ -190,21 +148,4 @@ class NewgroupAction extends FormAction common_redirect($group->homeUrl(), 303); } } - - function nicknameExists($nickname) - { - $local = Local_group::getKV('nickname', $nickname); - - if (!empty($local)) { - return true; - } - - $alias = Group_alias::getKV('alias', $nickname); - - if (!empty($alias)) { - return true; - } - - return false; - } }