3 * StatusNet, the distributed open-source microblogging tool
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Evan Prodromou <evan@status.net>
25 * @author Sarven Capadisli <csarven@status.net>
26 * @copyright 2008-2009 StatusNet, Inc.
27 * @copyright 2013 Free Software Foundation, Inc.
28 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
29 * @link http://status.net/
32 if (!defined('STATUSNET')) {
39 * This is the form for adding a new group
43 * @author Evan Prodromou <evan@status.net>
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45 * @link http://status.net/
47 class NewgroupAction extends FormAction
57 // TRANS: Title for form to create a group.
58 return _('New group');
64 protected function prepare(array $args=array())
66 parent::prepare($args);
68 // $this->scoped is the current user profile
69 if (!$this->scoped->hasRight(Right::CREATEGROUP)) {
70 // TRANS: Client exception thrown when a user tries to create a group while banned.
71 $this->clientError(_('You are not allowed to create groups on this site.'), 403);
77 public function showContent()
79 $form = new GroupEditForm($this);
83 public function showInstructions()
85 $this->element('p', 'instructions',
86 // TRANS: Form instructions for group create form.
87 _('Use this form to create a new group.'));
90 protected function handlePost()
94 if (Event::handle('StartGroupSaveForm', array($this))) {
95 $nickname = Nickname::normalize($this->trimmed('newnickname'), true);
97 $fullname = $this->trimmed('fullname');
98 $homepage = $this->trimmed('homepage');
99 $description = $this->trimmed('description');
100 $location = $this->trimmed('location');
101 $private = $this->boolean('private');
102 $aliasstring = $this->trimmed('aliases');
104 if (!is_null($homepage) && (strlen($homepage) > 0) &&
105 !common_valid_http_url($homepage)) {
106 // TRANS: Group create form validation error.
107 throw new ClientException(_('Homepage is not a valid URL.'));
108 } else if (!is_null($fullname) && mb_strlen($fullname) > 255) {
109 // TRANS: Group create form validation error.
110 throw new ClientException(_('Full name is too long (maximum 255 characters).'));
111 } else if (User_group::descriptionTooLong($description)) {
112 // TRANS: Group create form validation error.
113 // TRANS: %d is the maximum number of allowed characters.
114 throw new ClientException(sprintf(_m('Description is too long (maximum %d character).',
115 'Description is too long (maximum %d characters).',
116 User_group::maxDescription()),
117 User_group::maxDescription()));
118 } else if (!is_null($location) && mb_strlen($location) > 255) {
119 // TRANS: Group create form validation error.
120 throw new ClientException(_('Location is too long (maximum 255 characters).'));
123 if (!empty($aliasstring)) {
124 $aliases = array_map(array('Nickname', 'normalize'), array_unique(preg_split('/[\s,]+/', $aliasstring)));
129 if (count($aliases) > common_config('group', 'maxaliases')) {
130 // TRANS: Group create form validation error.
131 // TRANS: %d is the maximum number of allowed aliases.
132 throw new ClientException(sprintf(_m('Too many aliases! Maximum %d allowed.',
133 'Too many aliases! Maximum %d allowed.',
134 common_config('group', 'maxaliases')),
135 common_config('group', 'maxaliases')));
141 $join_policy = User_group::JOIN_POLICY_MODERATE;
144 $join_policy = User_group::JOIN_POLICY_OPEN;
147 // This is set up in parent->prepare and checked in self->prepare
148 assert(!is_null($this->scoped));
150 $group = User_group::register(array('nickname' => $nickname,
151 'fullname' => $fullname,
152 'homepage' => $homepage,
153 'description' => $description,
154 'location' => $location,
155 'aliases' => $aliases,
156 'userid' => $this->scoped->id,
157 'join_policy' => $join_policy,
158 'force_scope' => $force_scope,
161 $this->group = $group;
163 Event::handle('EndGroupSaveForm', array($this));
165 common_redirect($group->homeUrl(), 303);