]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/newgroup.php
Merge branch 'fix-twitter-uri' into 'master'
[quix0rs-gnu-social.git] / actions / newgroup.php
index dd264ce055da25be0c62e97e2979f34a466bb52d..ef8346c03ef053b37868da8933d0e10db7216a14 100644 (file)
@@ -29,9 +29,7 @@
  * @link      http://status.net/
  */
 
-if (!defined('STATUSNET')) {
-    exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 /**
  * Add a new group
@@ -46,47 +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(array $args=array())
+    protected function doPreparation()
     {
-        parent::prepare($args);
-
         // $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.
             $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');
@@ -95,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) {
@@ -123,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();
             }
@@ -135,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) {
@@ -185,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;
-    }
 }