123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?php
- if (!defined('GNUSOCIAL')) { exit(1); }
- class NewgroupAction extends FormAction
- {
- protected $group;
- protected $form = 'GroupEdit';
- function getGroup() {
- return $this->group;
- }
- function title()
- {
-
- return _('New group');
- }
- protected function doPreparation()
- {
-
- if (!$this->scoped->hasRight(Right::CREATEGROUP)) {
-
- $this->clientError(_('You are not allowed to create groups on this site.'), 403);
- }
- }
- protected function getInstructions()
- {
-
- return _('Use this form to create a new group.');
- }
- protected function doPost()
- {
- if (Event::handle('StartGroupSaveForm', array($this))) {
- $nickname = Nickname::normalize($this->trimmed('newnickname'), true);
- $fullname = $this->trimmed('fullname');
- $homepage = $this->trimmed('homepage');
- $description = $this->trimmed('description');
- $location = $this->trimmed('location');
- $private = $this->boolean('private');
- $aliasstring = $this->trimmed('aliases');
- if (!is_null($homepage) && (strlen($homepage) > 0) &&
- !common_valid_http_url($homepage)) {
-
- throw new ClientException(_('Homepage is not a valid URL.'));
- } else if (!is_null($fullname) && mb_strlen($fullname) > 255) {
-
- throw new ClientException(_('Full name is too long (maximum 255 characters).'));
- } else if (User_group::descriptionTooLong($description)) {
-
-
- throw new ClientException(sprintf(_m('Description is too long (maximum %d character).',
- 'Description is too long (maximum %d characters).',
- User_group::maxDescription()),
- User_group::maxDescription()));
- } else if (!is_null($location) && mb_strlen($location) > 255) {
-
- throw new ClientException(_('Location is too long (maximum 255 characters).'));
- }
- if (!empty($aliasstring)) {
- $aliases = array_map(array('Nickname', 'normalize'), array_unique(preg_split('/[\s,]+/', $aliasstring)));
- } else {
- $aliases = array();
- }
- if (count($aliases) > common_config('group', 'maxaliases')) {
-
-
- throw new ClientException(sprintf(_m('Too many aliases! Maximum %d allowed.',
- 'Too many aliases! Maximum %d allowed.',
- common_config('group', 'maxaliases')),
- common_config('group', 'maxaliases')));
- }
- if ($private) {
- $force_scope = 1;
- $join_policy = User_group::JOIN_POLICY_MODERATE;
- } else {
- $force_scope = 0;
- $join_policy = User_group::JOIN_POLICY_OPEN;
- }
-
- assert(!is_null($this->scoped));
- $group = User_group::register(array('nickname' => $nickname,
- 'fullname' => $fullname,
- 'homepage' => $homepage,
- 'description' => $description,
- 'location' => $location,
- 'aliases' => $aliases,
- 'userid' => $this->scoped->id,
- 'join_policy' => $join_policy,
- 'force_scope' => $force_scope,
- 'local' => true));
- $this->group = $group;
- Event::handle('EndGroupSaveForm', array($this));
- common_redirect($group->homeUrl(), 303);
- }
- }
- }
|