aboutsummaryrefslogtreecommitdiff
path: root/mod/groups/actions
diff options
context:
space:
mode:
Diffstat (limited to 'mod/groups/actions')
-rw-r--r--mod/groups/actions/discussion/delete.php29
-rw-r--r--mod/groups/actions/discussion/reply/delete.php26
-rw-r--r--mod/groups/actions/discussion/reply/save.php58
-rw-r--r--mod/groups/actions/discussion/save.php75
-rw-r--r--mod/groups/actions/groups/delete.php42
-rw-r--r--mod/groups/actions/groups/edit.php207
-rw-r--r--mod/groups/actions/groups/featured.php27
-rw-r--r--mod/groups/actions/groups/membership/add.php42
-rw-r--r--mod/groups/actions/groups/membership/delete_invite.php24
-rw-r--r--mod/groups/actions/groups/membership/delete_request.php20
-rw-r--r--mod/groups/actions/groups/membership/invite.php51
-rw-r--r--mod/groups/actions/groups/membership/join.php72
-rw-r--r--mod/groups/actions/groups/membership/leave.php36
-rw-r--r--mod/groups/actions/groups/membership/remove.php31
14 files changed, 740 insertions, 0 deletions
diff --git a/mod/groups/actions/discussion/delete.php b/mod/groups/actions/discussion/delete.php
new file mode 100644
index 000000000..f307aa091
--- /dev/null
+++ b/mod/groups/actions/discussion/delete.php
@@ -0,0 +1,29 @@
+<?php
+/**
+ * Delete topic action
+ *
+ */
+
+$topic_guid = (int) get_input('guid');
+
+$topic = get_entity($topic_guid);
+if (!$topic || !$topic->getSubtype() == "groupforumtopic") {
+ register_error(elgg_echo('discussion:error:notdeleted'));
+ forward(REFERER);
+}
+
+if (!$topic->canEdit()) {
+ register_error(elgg_echo('discussion:error:permissions'));
+ forward(REFERER);
+}
+
+$container = $topic->getContainerEntity();
+
+$result = $topic->delete();
+if ($result) {
+ system_message(elgg_echo('discussion:topic:deleted'));
+} else {
+ register_error(elgg_echo('discussion:error:notdeleted'));
+}
+
+forward("discussion/owner/$container->guid");
diff --git a/mod/groups/actions/discussion/reply/delete.php b/mod/groups/actions/discussion/reply/delete.php
new file mode 100644
index 000000000..88c6b79d6
--- /dev/null
+++ b/mod/groups/actions/discussion/reply/delete.php
@@ -0,0 +1,26 @@
+<?php
+/**
+ * Delete discussion reply
+ */
+
+$id = (int) get_input('annotation_id');
+
+$reply = elgg_get_annotation_from_id($id);
+if (!$reply || $reply->name != 'group_topic_post') {
+ register_error(elgg_echo('discussion:reply:error:notdeleted'));
+ forward(REFERER);
+}
+
+if (!$reply->canEdit()) {
+ register_error(elgg_echo('discussion:error:permissions'));
+ forward(REFERER);
+}
+
+$result = $reply->delete();
+if ($result) {
+ system_message(elgg_echo('discussion:reply:deleted'));
+} else {
+ register_error(elgg_echo('discussion:reply:error:notdeleted'));
+}
+
+forward(REFERER);
diff --git a/mod/groups/actions/discussion/reply/save.php b/mod/groups/actions/discussion/reply/save.php
new file mode 100644
index 000000000..f8be8aa2c
--- /dev/null
+++ b/mod/groups/actions/discussion/reply/save.php
@@ -0,0 +1,58 @@
+<?php
+/**
+ * Post a reply to discussion topic
+ *
+ */
+
+// Get input
+$entity_guid = (int) get_input('entity_guid');
+$text = get_input('group_topic_post');
+$annotation_id = (int) get_input('annotation_id');
+
+// reply cannot be empty
+if (empty($text)) {
+ register_error(elgg_echo('grouppost:nopost'));
+ forward(REFERER);
+}
+
+$topic = get_entity($entity_guid);
+if (!$topic) {
+ register_error(elgg_echo('grouppost:nopost'));
+ forward(REFERER);
+}
+
+$user = elgg_get_logged_in_user_entity();
+
+$group = $topic->getContainerEntity();
+if (!$group->canWriteToContainer()) {
+ register_error(elgg_echo('groups:notmember'));
+ forward(REFERER);
+}
+
+// if editing a reply, make sure it's valid
+if ($annotation_id) {
+ $annotation = elgg_get_annotation_from_id($annotation_id);
+ if (!$annotation->canEdit()) {
+ register_error(elgg_echo('groups:notowner'));
+ forward(REFERER);
+ }
+
+ $annotation->value = $text;
+ if (!$annotation->save()) {
+ system_message(elgg_echo('groups:forumpost:error'));
+ forward(REFERER);
+ }
+ system_message(elgg_echo('groups:forumpost:edited'));
+} else {
+ // add the reply to the forum topic
+ $reply_id = $topic->annotate('group_topic_post', $text, $topic->access_id, $user->guid);
+ if ($reply_id == false) {
+ system_message(elgg_echo('groupspost:failure'));
+ forward(REFERER);
+ }
+
+ add_to_river('river/annotation/group_topic_post/reply', 'reply', $user->guid, $topic->guid, "", 0, $reply_id);
+ system_message(elgg_echo('groupspost:success'));
+}
+
+forward(REFERER);
diff --git a/mod/groups/actions/discussion/save.php b/mod/groups/actions/discussion/save.php
new file mode 100644
index 000000000..b3e9da654
--- /dev/null
+++ b/mod/groups/actions/discussion/save.php
@@ -0,0 +1,75 @@
+<?php
+/**
+ * Topic save action
+ */
+
+// Get variables
+$title = htmlspecialchars(get_input('title', '', false), ENT_QUOTES, 'UTF-8');
+$desc = get_input("description");
+$status = get_input("status");
+$access_id = (int) get_input("access_id");
+$container_guid = (int) get_input('container_guid');
+$guid = (int) get_input('topic_guid');
+$tags = get_input("tags");
+
+elgg_make_sticky_form('topic');
+
+// validation of inputs
+if (!$title || !$desc) {
+ register_error(elgg_echo('discussion:error:missing'));
+ forward(REFERER);
+}
+
+$container = get_entity($container_guid);
+if (!$container || !$container->canWriteToContainer(0, 'object', 'groupforumtopic')) {
+ register_error(elgg_echo('discussion:error:permissions'));
+ forward(REFERER);
+}
+
+// check whether this is a new topic or an edit
+$new_topic = true;
+if ($guid > 0) {
+ $new_topic = false;
+}
+
+if ($new_topic) {
+ $topic = new ElggObject();
+ $topic->subtype = 'groupforumtopic';
+} else {
+ // load original file object
+ $topic = new ElggObject($guid);
+ if (!$topic || !$topic->canEdit()) {
+ register_error(elgg_echo('discussion:topic:notfound'));
+ forward(REFERER);
+ }
+}
+
+$topic->title = $title;
+$topic->description = $desc;
+$topic->status = $status;
+$topic->access_id = $access_id;
+$topic->container_guid = $container_guid;
+
+$tags = explode(",", $tags);
+$topic->tags = $tags;
+
+$result = $topic->save();
+
+if (!$result) {
+ register_error(elgg_echo('discussion:error:notsaved'));
+ forward(REFERER);
+}
+
+// topic saved so clear sticky form
+elgg_clear_sticky_form('topic');
+
+
+// handle results differently for new topics and topic edits
+if ($new_topic) {
+ system_message(elgg_echo('discussion:topic:created'));
+ add_to_river('river/object/groupforumtopic/create', 'create', elgg_get_logged_in_user_guid(), $topic->guid);
+} else {
+ system_message(elgg_echo('discussion:topic:updated'));
+}
+
+forward($topic->getURL());
diff --git a/mod/groups/actions/groups/delete.php b/mod/groups/actions/groups/delete.php
new file mode 100644
index 000000000..2ff6c339c
--- /dev/null
+++ b/mod/groups/actions/groups/delete.php
@@ -0,0 +1,42 @@
+<?php
+/**
+ * Delete a group
+ */
+
+$guid = (int) get_input('guid');
+if (!$guid) {
+ // backward compatible
+ elgg_deprecated_notice("Use 'guid' for group delete action", 1.8);
+ $guid = (int)get_input('group_guid');
+}
+$entity = get_entity($guid);
+
+if (!$entity->canEdit()) {
+ register_error(elgg_echo('group:notdeleted'));
+ forward(REFERER);
+}
+
+if (($entity) && ($entity instanceof ElggGroup)) {
+ // delete group icons
+ $owner_guid = $entity->owner_guid;
+ $prefix = "groups/" . $entity->guid;
+ $imagenames = array('.jpg', 'tiny.jpg', 'small.jpg', 'medium.jpg', 'large.jpg');
+ $img = new ElggFile();
+ $img->owner_guid = $owner_guid;
+ foreach ($imagenames as $name) {
+ $img->setFilename($prefix . $name);
+ $img->delete();
+ }
+
+ // delete group
+ if ($entity->delete()) {
+ system_message(elgg_echo('group:deleted'));
+ } else {
+ register_error(elgg_echo('group:notdeleted'));
+ }
+} else {
+ register_error(elgg_echo('group:notdeleted'));
+}
+
+$url_name = elgg_get_logged_in_user_entity()->username;
+forward(elgg_get_site_url() . "groups/member/{$url_name}");
diff --git a/mod/groups/actions/groups/edit.php b/mod/groups/actions/groups/edit.php
new file mode 100644
index 000000000..d0689be2e
--- /dev/null
+++ b/mod/groups/actions/groups/edit.php
@@ -0,0 +1,207 @@
+<?php
+/**
+ * Elgg groups plugin edit action.
+ *
+ * @package ElggGroups
+ */
+
+elgg_make_sticky_form('groups');
+
+/**
+ * wrapper for recursive array walk decoding
+ */
+function profile_array_decoder(&$v) {
+ $v = _elgg_html_decode($v);
+}
+
+// Get group fields
+$input = array();
+foreach (elgg_get_config('group') as $shortname => $valuetype) {
+ $input[$shortname] = get_input($shortname);
+
+ // @todo treat profile fields as unescaped: don't filter, encode on output
+ if (is_array($input[$shortname])) {
+ array_walk_recursive($input[$shortname], 'profile_array_decoder');
+ } else {
+ $input[$shortname] = _elgg_html_decode($input[$shortname]);
+ }
+
+ if ($valuetype == 'tags') {
+ $input[$shortname] = string_to_tag_array($input[$shortname]);
+ }
+}
+
+$input['name'] = htmlspecialchars(get_input('name', '', false), ENT_QUOTES, 'UTF-8');
+
+$user = elgg_get_logged_in_user_entity();
+
+$group_guid = (int)get_input('group_guid');
+$is_new_group = $group_guid == 0;
+
+if ($is_new_group
+ && (elgg_get_plugin_setting('limited_groups', 'groups') == 'yes')
+ && !$user->isAdmin()) {
+ register_error(elgg_echo("groups:cantcreate"));
+ forward(REFERER);
+}
+
+$group = new ElggGroup($group_guid); // load if present, if not create a new group
+if ($group_guid && !$group->canEdit()) {
+ register_error(elgg_echo("groups:cantedit"));
+ forward(REFERER);
+}
+
+// Assume we can edit or this is a new group
+if (sizeof($input) > 0) {
+ foreach($input as $shortname => $value) {
+ $group->$shortname = $value;
+ }
+}
+
+// Validate create
+if (!$group->name) {
+ register_error(elgg_echo("groups:notitle"));
+ forward(REFERER);
+}
+
+
+// Set group tool options
+$tool_options = elgg_get_config('group_tool_options');
+if ($tool_options) {
+ foreach ($tool_options as $group_option) {
+ $option_toggle_name = $group_option->name . "_enable";
+ $option_default = $group_option->default_on ? 'yes' : 'no';
+ $group->$option_toggle_name = get_input($option_toggle_name, $option_default);
+ }
+}
+
+// Group membership - should these be treated with same constants as access permissions?
+$is_public_membership = (get_input('membership') == ACCESS_PUBLIC);
+$group->membership = $is_public_membership ? ACCESS_PUBLIC : ACCESS_PRIVATE;
+
+if ($is_new_group) {
+ $group->access_id = ACCESS_PUBLIC;
+}
+
+$old_owner_guid = $is_new_group ? 0 : $group->owner_guid;
+$new_owner_guid = (int) get_input('owner_guid');
+
+$owner_has_changed = false;
+$old_icontime = null;
+if (!$is_new_group && $new_owner_guid && $new_owner_guid != $old_owner_guid) {
+ // verify new owner is member and old owner/admin is logged in
+ if (is_group_member($group_guid, $new_owner_guid) && ($old_owner_guid == $user->guid || $user->isAdmin())) {
+ $group->owner_guid = $new_owner_guid;
+
+ // @todo Remove this when #4683 fixed
+ $owner_has_changed = true;
+ $old_icontime = $group->icontime;
+ }
+}
+
+$must_move_icons = ($owner_has_changed && $old_icontime);
+
+$group->save();
+
+// Invisible group support
+// @todo this requires save to be called to create the acl for the group. This
+// is an odd requirement and should be removed. Either the acl creation happens
+// in the action or the visibility moves to a plugin hook
+if (elgg_get_plugin_setting('hidden_groups', 'groups') == 'yes') {
+ $visibility = (int)get_input('vis', '', false);
+ if ($visibility != ACCESS_PUBLIC && $visibility != ACCESS_LOGGED_IN) {
+ $visibility = $group->group_acl;
+ }
+
+ if ($group->access_id != $visibility) {
+ $group->access_id = $visibility;
+ }
+}
+
+$group->save();
+
+// group saved so clear sticky form
+elgg_clear_sticky_form('groups');
+
+// group creator needs to be member of new group and river entry created
+if ($is_new_group) {
+
+ // @todo this should not be necessary...
+ elgg_set_page_owner_guid($group->guid);
+
+ $group->join($user);
+ add_to_river('river/group/create', 'create', $user->guid, $group->guid, $group->access_id);
+}
+
+$has_uploaded_icon = (!empty($_FILES['icon']['type']) && substr_count($_FILES['icon']['type'], 'image/'));
+
+if ($has_uploaded_icon) {
+
+ $icon_sizes = elgg_get_config('icon_sizes');
+
+ $prefix = "groups/" . $group->guid;
+
+ $filehandler = new ElggFile();
+ $filehandler->owner_guid = $group->owner_guid;
+ $filehandler->setFilename($prefix . ".jpg");
+ $filehandler->open("write");
+ $filehandler->write(get_uploaded_file('icon'));
+ $filehandler->close();
+ $filename = $filehandler->getFilenameOnFilestore();
+
+ $sizes = array('tiny', 'small', 'medium', 'large');
+
+ $thumbs = array();
+ foreach ($sizes as $size) {
+ $thumbs[$size] = get_resized_image_from_existing_file(
+ $filename,
+ $icon_sizes[$size]['w'],
+ $icon_sizes[$size]['h'],
+ $icon_sizes[$size]['square']
+ );
+ }
+
+ if ($thumbs['tiny']) { // just checking if resize successful
+ $thumb = new ElggFile();
+ $thumb->owner_guid = $group->owner_guid;
+ $thumb->setMimeType('image/jpeg');
+
+ foreach ($sizes as $size) {
+ $thumb->setFilename("{$prefix}{$size}.jpg");
+ $thumb->open("write");
+ $thumb->write($thumbs[$size]);
+ $thumb->close();
+ }
+
+ $group->icontime = time();
+ }
+}
+
+// @todo Remove this when #4683 fixed
+if ($must_move_icons) {
+ $filehandler = new ElggFile();
+ $filehandler->setFilename('groups');
+ $filehandler->owner_guid = $old_owner_guid;
+ $old_path = $filehandler->getFilenameOnFilestore();
+
+ $sizes = array('', 'tiny', 'small', 'medium', 'large');
+
+ if ($has_uploaded_icon) {
+ // delete those under old owner
+ foreach ($sizes as $size) {
+ unlink("$old_path/{$group_guid}{$size}.jpg");
+ }
+ } else {
+ // move existing to new owner
+ $filehandler->owner_guid = $group->owner_guid;
+ $new_path = $filehandler->getFilenameOnFilestore();
+
+ foreach ($sizes as $size) {
+ rename("$old_path/{$group_guid}{$size}.jpg", "$new_path/{$group_guid}{$size}.jpg");
+ }
+ }
+}
+
+system_message(elgg_echo("groups:saved"));
+
+forward($group->getUrl());
diff --git a/mod/groups/actions/groups/featured.php b/mod/groups/actions/groups/featured.php
new file mode 100644
index 000000000..4cb9f8122
--- /dev/null
+++ b/mod/groups/actions/groups/featured.php
@@ -0,0 +1,27 @@
+<?php
+/**
+ * Feature a group
+ *
+ * @package ElggGroups
+ */
+
+$group_guid = get_input('group_guid');
+$action = get_input('action_type');
+
+$group = get_entity($group_guid);
+
+if (!elgg_instanceof($group, 'group')) {
+ register_error(elgg_echo('groups:featured_error'));
+ forward(REFERER);
+}
+
+//get the action, is it to feature or unfeature
+if ($action == "feature") {
+ $group->featured_group = "yes";
+ system_message(elgg_echo('groups:featuredon', array($group->name)));
+} else {
+ $group->featured_group = "no";
+ system_message(elgg_echo('groups:unfeatured', array($group->name)));
+}
+
+forward(REFERER);
diff --git a/mod/groups/actions/groups/membership/add.php b/mod/groups/actions/groups/membership/add.php
new file mode 100644
index 000000000..de0cba613
--- /dev/null
+++ b/mod/groups/actions/groups/membership/add.php
@@ -0,0 +1,42 @@
+<?php
+/**
+ * Add users to a group
+ *
+ * @package ElggGroups
+ */
+$logged_in_user = elgg_get_logged_in_user_entity();
+
+$user_guid = get_input('user_guid');
+if (!is_array($user_guid)) {
+ $user_guid = array($user_guid);
+}
+$group_guid = get_input('group_guid');
+$group = get_entity($group_guid);
+
+if (sizeof($user_guid)) {
+ foreach ($user_guid as $u_id) {
+ $user = get_user($u_id);
+
+ if ($user && $group && $group->canEdit()) {
+ if (!$group->isMember($user)) {
+ if (groups_join_group($group, $user)) {
+
+ // send welcome email to user
+ notify_user($user->getGUID(), $group->owner_guid,
+ elgg_echo('groups:welcome:subject', array($group->name)),
+ elgg_echo('groups:welcome:body', array(
+ $user->name,
+ $group->name,
+ $group->getURL())
+ ));
+
+ system_message(elgg_echo('groups:addedtogroup'));
+ } else {
+ // huh
+ }
+ }
+ }
+ }
+}
+
+forward(REFERER);
diff --git a/mod/groups/actions/groups/membership/delete_invite.php b/mod/groups/actions/groups/membership/delete_invite.php
new file mode 100644
index 000000000..d21aa0309
--- /dev/null
+++ b/mod/groups/actions/groups/membership/delete_invite.php
@@ -0,0 +1,24 @@
+<?php
+/**
+ * Delete an invitation to join a group.
+ *
+ * @package ElggGroups
+ */
+
+$user_guid = get_input('user_guid', elgg_get_logged_in_user_guid());
+$group_guid = get_input('group_guid');
+
+$user = get_entity($user_guid);
+
+// invisible groups require overriding access to delete invite
+$old_access = elgg_set_ignore_access(true);
+$group = get_entity($group_guid);
+elgg_set_ignore_access($old_access);
+
+// If join request made
+if (check_entity_relationship($group->guid, 'invited', $user->guid)) {
+ remove_entity_relationship($group->guid, 'invited', $user->guid);
+ system_message(elgg_echo("groups:invitekilled"));
+}
+
+forward(REFERER);
diff --git a/mod/groups/actions/groups/membership/delete_request.php b/mod/groups/actions/groups/membership/delete_request.php
new file mode 100644
index 000000000..883c9d748
--- /dev/null
+++ b/mod/groups/actions/groups/membership/delete_request.php
@@ -0,0 +1,20 @@
+<?php
+/**
+ * Delete a request to join a closed group.
+ *
+ * @package ElggGroups
+ */
+
+$user_guid = get_input('user_guid', elgg_get_logged_in_user_guid());
+$group_guid = get_input('group_guid');
+
+$user = get_entity($user_guid);
+$group = get_entity($group_guid);
+
+// If join request made
+if (check_entity_relationship($user->guid, 'membership_request', $group->guid)) {
+ remove_entity_relationship($user->guid, 'membership_request', $group->guid);
+ system_message(elgg_echo("groups:joinrequestkilled"));
+}
+
+forward(REFERER);
diff --git a/mod/groups/actions/groups/membership/invite.php b/mod/groups/actions/groups/membership/invite.php
new file mode 100644
index 000000000..db90ecf3a
--- /dev/null
+++ b/mod/groups/actions/groups/membership/invite.php
@@ -0,0 +1,51 @@
+<?php
+/**
+ * Invite users to join a group
+ *
+ * @package ElggGroups
+ */
+
+$logged_in_user = elgg_get_logged_in_user_entity();
+
+$user_guid = get_input('user_guid');
+if (!is_array($user_guid)) {
+ $user_guid = array($user_guid);
+}
+$group_guid = get_input('group_guid');
+
+if (sizeof($user_guid)) {
+ foreach ($user_guid as $u_id) {
+ $user = get_entity($u_id);
+ $group = get_entity($group_guid);
+
+ if ($user && $group && ($group instanceof ElggGroup) && $group->canEdit()) {
+
+ if (!check_entity_relationship($group->guid, 'invited', $user->guid)) {
+
+ // Create relationship
+ add_entity_relationship($group->guid, 'invited', $user->guid);
+
+ // Send email
+ $url = elgg_normalize_url("groups/invitations/$user->username");
+ $result = notify_user($user->getGUID(), $group->owner_guid,
+ elgg_echo('groups:invite:subject', array($user->name, $group->name)),
+ elgg_echo('groups:invite:body', array(
+ $user->name,
+ $logged_in_user->name,
+ $group->name,
+ $url,
+ )),
+ NULL);
+ if ($result) {
+ system_message(elgg_echo("groups:userinvited"));
+ } else {
+ register_error(elgg_echo("groups:usernotinvited"));
+ }
+ } else {
+ register_error(elgg_echo("groups:useralreadyinvited"));
+ }
+ }
+ }
+}
+
+forward(REFERER);
diff --git a/mod/groups/actions/groups/membership/join.php b/mod/groups/actions/groups/membership/join.php
new file mode 100644
index 000000000..b4f4e280c
--- /dev/null
+++ b/mod/groups/actions/groups/membership/join.php
@@ -0,0 +1,72 @@
+<?php
+/**
+ * Join a group
+ *
+ * Three states:
+ * open group so user joins
+ * closed group so request sent to group owner
+ * closed group with invite so user joins
+ *
+ * @package ElggGroups
+ */
+
+global $CONFIG;
+
+$user_guid = get_input('user_guid', elgg_get_logged_in_user_guid());
+$group_guid = get_input('group_guid');
+
+$user = get_entity($user_guid);
+
+// access bypass for getting invisible group
+$ia = elgg_set_ignore_access(true);
+$group = get_entity($group_guid);
+elgg_set_ignore_access($ia);
+
+if (($user instanceof ElggUser) && ($group instanceof ElggGroup)) {
+
+ // join or request
+ $join = false;
+ if ($group->isPublicMembership() || $group->canEdit($user->guid)) {
+ // anyone can join public groups and admins can join any group
+ $join = true;
+ } else {
+ if (check_entity_relationship($group->guid, 'invited', $user->guid)) {
+ // user has invite to closed group
+ $join = true;
+ }
+ }
+
+ if ($join) {
+ if (groups_join_group($group, $user)) {
+ system_message(elgg_echo("groups:joined"));
+ forward($group->getURL());
+ } else {
+ register_error(elgg_echo("groups:cantjoin"));
+ }
+ } else {
+ add_entity_relationship($user->guid, 'membership_request', $group->guid);
+
+ // Notify group owner
+ $url = "{$CONFIG->url}groups/requests/$group->guid";
+ $subject = elgg_echo('groups:request:subject', array(
+ $user->name,
+ $group->name,
+ ));
+ $body = elgg_echo('groups:request:body', array(
+ $group->getOwnerEntity()->name,
+ $user->name,
+ $group->name,
+ $user->getURL(),
+ $url,
+ ));
+ if (notify_user($group->owner_guid, $user->getGUID(), $subject, $body)) {
+ system_message(elgg_echo("groups:joinrequestmade"));
+ } else {
+ register_error(elgg_echo("groups:joinrequestnotmade"));
+ }
+ }
+} else {
+ register_error(elgg_echo("groups:cantjoin"));
+}
+
+forward(REFERER);
diff --git a/mod/groups/actions/groups/membership/leave.php b/mod/groups/actions/groups/membership/leave.php
new file mode 100644
index 000000000..4f34c7dde
--- /dev/null
+++ b/mod/groups/actions/groups/membership/leave.php
@@ -0,0 +1,36 @@
+<?php
+/**
+ * Leave a group action.
+ *
+ * @package ElggGroups
+ */
+
+$user_guid = get_input('user_guid');
+$group_guid = get_input('group_guid');
+
+$user = NULL;
+if (!$user_guid) {
+ $user = elgg_get_logged_in_user_entity();
+} else {
+ $user = get_entity($user_guid);
+}
+
+$group = get_entity($group_guid);
+
+elgg_set_page_owner_guid($group->guid);
+
+if (($user instanceof ElggUser) && ($group instanceof ElggGroup)) {
+ if ($group->getOwnerGUID() != elgg_get_logged_in_user_guid()) {
+ if ($group->leave($user)) {
+ system_message(elgg_echo("groups:left"));
+ } else {
+ register_error(elgg_echo("groups:cantleave"));
+ }
+ } else {
+ register_error(elgg_echo("groups:cantleave"));
+ }
+} else {
+ register_error(elgg_echo("groups:cantleave"));
+}
+
+forward(REFERER);
diff --git a/mod/groups/actions/groups/membership/remove.php b/mod/groups/actions/groups/membership/remove.php
new file mode 100644
index 000000000..650d35286
--- /dev/null
+++ b/mod/groups/actions/groups/membership/remove.php
@@ -0,0 +1,31 @@
+<?php
+/**
+ * Remove a user from a group
+ *
+ * @package ElggGroups
+ */
+
+$user_guid = get_input('user_guid');
+$group_guid = get_input('group_guid');
+
+$user = get_entity($user_guid);
+$group = get_entity($group_guid);
+
+elgg_set_page_owner_guid($group->guid);
+
+if (($user instanceof ElggUser) && ($group instanceof ElggGroup) && $group->canEdit()) {
+ // Don't allow removing group owner
+ if ($group->getOwnerGUID() != $user->getGUID()) {
+ if ($group->leave($user)) {
+ system_message(elgg_echo("groups:removed", array($user->name)));
+ } else {
+ register_error(elgg_echo("groups:cantremove"));
+ }
+ } else {
+ register_error(elgg_echo("groups:cantremove"));
+ }
+} else {
+ register_error(elgg_echo("groups:cantremove"));
+}
+
+forward(REFERER);