]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/newgroup.php
update version in README, add note about status.net
[quix0rs-gnu-social.git] / actions / newgroup.php
index 67cd6b2f18005f3efc3878a71bec65cbe92a5365..01cb636aaf80a43555221836eb1485bd7b7e0fa6 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Laconica, the distributed open-source microblogging tool
+ * StatusNet, the distributed open-source microblogging tool
  *
  * Add a new group
  *
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  * @category  Group
- * @package   Laconica
- * @author    Evan Prodromou <evan@controlyourself.ca>
- * @author    Sarven Capadisli <csarven@controlyourself.ca>
- * @copyright 2008-2009 Control Yourself, Inc.
+ * @package   StatusNet
+ * @author    Evan Prodromou <evan@status.net>
+ * @author    Sarven Capadisli <csarven@status.net>
+ * @copyright 2008-2009 StatusNet, Inc.
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link      http://laconi.ca/
+ * @link      http://status.net/
  */
 
-if (!defined('LACONICA')) {
+if (!defined('STATUSNET') && !defined('LACONICA')) {
     exit(1);
 }
 
@@ -38,10 +38,10 @@ if (!defined('LACONICA')) {
  * This is the form for adding a new group
  *
  * @category Group
- * @package  Laconica
- * @author   Evan Prodromou <evan@controlyourself.ca>
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link     http://laconi.ca/
+ * @link     http://status.net/
  */
 
 class NewgroupAction extends Action
@@ -123,6 +123,7 @@ class NewgroupAction extends Action
         $homepage    = $this->trimmed('homepage');
         $description = $this->trimmed('description');
         $location    = $this->trimmed('location');
+        $aliasstring = $this->trimmed('aliases');
 
         if (!Validate::string($nickname, array('min_length' => 1,
                                                'max_length' => 64,
@@ -153,6 +154,37 @@ class NewgroupAction extends Action
             return;
         }
 
+        if (!empty($aliasstring)) {
+            $aliases = array_map('common_canonical_nickname', array_unique(preg_split('/[\s,]+/', $aliasstring)));
+        } else {
+            $aliases = array();
+        }
+
+        if (count($aliases) > common_config('group', 'maxaliases')) {
+            $this->showForm(sprintf(_('Too many aliases! Maximum %d.'),
+                                    common_config('group', 'maxaliases')));
+            return;
+        }
+
+        foreach ($aliases as $alias) {
+            if (!Validate::string($alias, array('min_length' => 1,
+                                                'max_length' => 64,
+                                                'format' => NICKNAME_FMT))) {
+                $this->showForm(sprintf(_('Invalid alias: "%s"'), $alias));
+                return;
+            }
+            if ($this->nicknameExists($alias)) {
+                $this->showForm(sprintf(_('Alias "%s" already in use. Try another one.'),
+                                        $alias));
+                return;
+            }
+            // XXX assumes alphanum nicknames
+            if (strcmp($alias, $nickname) == 0) {
+                $this->showForm(_('Alias can\'t be the same as nickname.'));
+                return;
+            }
+        }
+
         $cur = common_current_user();
 
         // Checked in prepare() above
@@ -177,6 +209,12 @@ class NewgroupAction extends Action
             $this->serverError(_('Could not create group.'));
         }
 
+        $result = $group->setAliases($aliases);
+
+        if (!$result) {
+            $this->serverError(_('Could not create aliases.'));
+        }
+
         $member = new Group_member();
 
         $member->group_id   = $group->id;
@@ -199,7 +237,18 @@ class NewgroupAction extends Action
     function nicknameExists($nickname)
     {
         $group = User_group::staticGet('nickname', $nickname);
-        return (!is_null($group) && $group != false);
+
+        if (!empty($group)) {
+            return true;
+        }
+
+        $alias = Group_alias::staticGet('alias', $nickname);
+
+        if (!empty($alias)) {
+            return true;
+        }
+
+        return false;
     }
 }