X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FUser_group.php;h=5a9991fe9e3fd936221b64ef69b5d7f1362e2994;hb=f1a14ba8015b690a10099f5d1e41ff320d2b6b88;hp=cffc7864586d7a542764fcb1ec3d621725ca6ee1;hpb=9a6ceb3303a98d1c5fba3587f32d0377e55062cc;p=quix0rs-gnu-social.git diff --git a/classes/User_group.php b/classes/User_group.php index cffc786458..5a9991fe9e 100644 --- a/classes/User_group.php +++ b/classes/User_group.php @@ -476,7 +476,18 @@ class User_group extends Memcached_DataObject } static function register($fields) { + if (!empty($fields['userid'])) { + $profile = Profile::staticGet('id', $fields['userid']); + if ($profile && !$profile->hasRight(Right::CREATEGROUP)) { + common_log(LOG_WARNING, "Attempted group creation from banned user: " . $profile->nickname); + + // 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); + } + } + // MAGICALLY put fields into current scope + // @fixme kill extract(); it makes debugging absurdly hard extract($fields); @@ -488,6 +499,9 @@ class User_group extends Memcached_DataObject // fill in later... $uri = null; } + if (empty($mainpage)) { + $mainpage = common_local_url('showgroup', array('nickname' => $nickname)); + } $group->nickname = $nickname; $group->fullname = $fullname; @@ -498,64 +512,70 @@ class User_group extends Memcached_DataObject $group->mainpage = $mainpage; $group->created = common_sql_now(); - $result = $group->insert(); + if (Event::handle('StartGroupSave', array(&$group))) { - if (!$result) { - common_log_db_error($group, 'INSERT', __FILE__); - // TRANS: Server exception thrown when creating a group failed. - throw new ServerException(_('Could not create group.')); - } + $result = $group->insert(); - if (!isset($uri) || empty($uri)) { - $orig = clone($group); - $group->uri = common_local_url('groupbyid', array('id' => $group->id)); - $result = $group->update($orig); if (!$result) { - common_log_db_error($group, 'UPDATE', __FILE__); - // TRANS: Server exception thrown when updating a group URI failed. - throw new ServerException(_('Could not set group URI.')); + common_log_db_error($group, 'INSERT', __FILE__); + // TRANS: Server exception thrown when creating a group failed. + throw new ServerException(_('Could not create group.')); } - } - $result = $group->setAliases($aliases); + if (!isset($uri) || empty($uri)) { + $orig = clone($group); + $group->uri = common_local_url('groupbyid', array('id' => $group->id)); + $result = $group->update($orig); + if (!$result) { + common_log_db_error($group, 'UPDATE', __FILE__); + // TRANS: Server exception thrown when updating a group URI failed. + throw new ServerException(_('Could not set group URI.')); + } + } - if (!$result) { - // TRANS: Server exception thrown when creating group aliases failed. - throw new ServerException(_('Could not create aliases.')); - } + $result = $group->setAliases($aliases); - $member = new Group_member(); + if (!$result) { + // TRANS: Server exception thrown when creating group aliases failed. + throw new ServerException(_('Could not create aliases.')); + } - $member->group_id = $group->id; - $member->profile_id = $userid; - $member->is_admin = 1; - $member->created = $group->created; + $member = new Group_member(); - $result = $member->insert(); + $member->group_id = $group->id; + $member->profile_id = $userid; + $member->is_admin = 1; + $member->created = $group->created; - if (!$result) { - common_log_db_error($member, 'INSERT', __FILE__); - // TRANS: Server exception thrown when setting group membership failed. - throw new ServerException(_('Could not set group membership.')); - } + $result = $member->insert(); + + if (!$result) { + common_log_db_error($member, 'INSERT', __FILE__); + // TRANS: Server exception thrown when setting group membership failed. + throw new ServerException(_('Could not set group membership.')); + } - if ($local) { - $local_group = new Local_group(); + if ($local) { + $local_group = new Local_group(); - $local_group->group_id = $group->id; - $local_group->nickname = $nickname; - $local_group->created = common_sql_now(); + $local_group->group_id = $group->id; + $local_group->nickname = $nickname; + $local_group->created = common_sql_now(); - $result = $local_group->insert(); + $result = $local_group->insert(); - if (!$result) { - common_log_db_error($local_group, 'INSERT', __FILE__); - // TRANS: Server exception thrown when saving local group information failed. - throw new ServerException(_('Could not save local group info.')); + if (!$result) { + common_log_db_error($local_group, 'INSERT', __FILE__); + // TRANS: Server exception thrown when saving local group information failed. + throw new ServerException(_('Could not save local group info.')); + } } + + $group->query('COMMIT'); + + Event::handle('EndGroupSave', array($group)); } - $group->query('COMMIT'); return $group; }