diff options
Diffstat (limited to 'mod/groups/actions')
-rw-r--r-- | mod/groups/actions/addtogroup.php | 117 | ||||
-rw-r--r-- | mod/groups/actions/delete.php | 31 | ||||
-rw-r--r-- | mod/groups/actions/featured.php | 58 | ||||
-rw-r--r-- | mod/groups/actions/groupskillinvitation.php | 36 | ||||
-rw-r--r-- | mod/groups/actions/groupskillrequest.php | 42 | ||||
-rw-r--r-- | mod/groups/actions/invite.php | 47 | ||||
-rw-r--r-- | mod/groups/actions/join.php | 85 | ||||
-rw-r--r-- | mod/groups/actions/joinrequest.php | 34 | ||||
-rw-r--r-- | mod/groups/actions/leave.php | 61 |
9 files changed, 222 insertions, 289 deletions
diff --git a/mod/groups/actions/addtogroup.php b/mod/groups/actions/addtogroup.php index 2da045fc6..651b90abb 100644 --- a/mod/groups/actions/addtogroup.php +++ b/mod/groups/actions/addtogroup.php @@ -1,92 +1,77 @@ <?php +/** + * Add a user to a group + * + * @package ElggGroups + */ +$logged_in_user = get_loggedin_user(); - /** - * Add a user to a group - * - * @package ElggGroups - */ +$user_guid = get_input('user_guid'); +if (!is_array($user_guid)) + $user_guid = array($user_guid); +$group_guid = get_input('group_guid'); - // Load configuration - global $CONFIG; +if (sizeof($user_guid)) { + foreach ($user_guid as $u_id) { + $user = get_entity($u_id); + $group = get_entity($group_guid); - $logged_in_user = get_loggedin_user(); + set_page_owner($group->guid); - $user_guid = get_input('user_guid'); - if (!is_array($user_guid)) - $user_guid = array($user_guid); - $group_guid = get_input('group_guid'); + if ($user && $group) { - if (sizeof($user_guid)) - { - foreach ($user_guid as $u_id) - { - $user = get_entity($u_id); - $group = get_entity($group_guid); + //if (get_loggedin_userid() == $group->owner_guid) + if ($group->canEdit()) { - set_page_owner($group->guid); - - if ( $user && $group) { - - //if (get_loggedin_userid() == $group->owner_guid) - if ($group->canEdit()) - { - - // If the group is open or the user has requested membership - if ( + // If the group is open or the user has requested membership + if ( (check_entity_relationship($user->guid, 'membership_request', $group->guid)) || ($group->isPublicMembership()) - ) - { + ) { - if (!$group->isMember($user)) - { - // Remove relationships - remove_entity_relationship($group->guid, 'invited', $user->guid); - remove_entity_relationship($user->guid, 'membership_request', $group->guid); + if (!$group->isMember($user)) { + // Remove relationships + remove_entity_relationship($group->guid, 'invited', $user->guid); + remove_entity_relationship($user->guid, 'membership_request', $group->guid); - //add_entity_relationship($user->guid, 'member', $group->guid); - $group->join($user); + //add_entity_relationship($user->guid, 'member', $group->guid); + $group->join($user); - // send welcome email - notify_user($user->getGUID(), $group->owner_guid, + // send welcome email + 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())), NULL); - system_message(elgg_echo('groups:addedtogroup')); - } - else - register_error(elgg_echo("groups:cantjoin")); + system_message(elgg_echo('groups:addedtogroup')); } else - { - if ($user->isFriend()) - { - - // Create relationship - add_entity_relationship($group->guid, 'invited', $user->guid); - - // Send email - $url = elgg_get_site_url()."pg/groups/invited?user_guid={$user->guid}&group_guid={$group->guid}"; - if (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)) - system_message(elgg_echo("groups:userinvited")); - else - register_error(elgg_echo("groups:usernotinvited")); - - } + register_error(elgg_echo("groups:cantjoin")); + } + else { + if ($user->isFriend()) { + + // Create relationship + add_entity_relationship($group->guid, 'invited', $user->guid); + + // Send email + $url = elgg_get_site_url() . "pg/groups/invited?user_guid={$user->guid}&group_guid={$group->guid}"; + if (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)) + system_message(elgg_echo("groups:userinvited")); else register_error(elgg_echo("groups:usernotinvited")); } + else + register_error(elgg_echo("groups:usernotinvited")); } - else - register_error(elgg_echo("groups:notowner")); } + else + register_error(elgg_echo("groups:notowner")); } } +} - forward(REFERER); - -?> +forward(REFERER); diff --git a/mod/groups/actions/delete.php b/mod/groups/actions/delete.php index 2983bc2ce..5672e8c47 100644 --- a/mod/groups/actions/delete.php +++ b/mod/groups/actions/delete.php @@ -1,19 +1,20 @@ <?php - global $CONFIG; +/** + * Delete a group + */ - $guid = (int)get_input('group_guid'); - $entity = get_entity($guid); - - if (($entity) && ($entity instanceof ElggGroup)) - { - if ($entity->delete()) - system_message(elgg_echo('group:deleted')); - else - register_error(elgg_echo('group:notdeleted')); - } +$guid = (int)get_input('group_guid'); +$entity = get_entity($guid); + +if (($entity) && ($entity instanceof ElggGroup)) +{ + if ($entity->delete()) + system_message(elgg_echo('group:deleted')); else register_error(elgg_echo('group:notdeleted')); - - $url_name = get_loggedin_user()->username; - forward(elgg_get_site_url()."pg/groups/member/{$url_name}"); -?>
\ No newline at end of file +} +else + register_error(elgg_echo('group:notdeleted')); + +$url_name = get_loggedin_user()->username; +forward(elgg_get_site_url() . "pg/groups/member/{$url_name}"); diff --git a/mod/groups/actions/featured.php b/mod/groups/actions/featured.php index a63b93c0d..72ca7eebd 100644 --- a/mod/groups/actions/featured.php +++ b/mod/groups/actions/featured.php @@ -1,35 +1,27 @@ -<?php - - /** - * Join a group action. - * - * @package ElggGroups - */ +<?php +/** + * Feature a group + * + * @package ElggGroups + */ - global $CONFIG; - - $group_guid = get_input('group_guid'); - $action = get_input('action_type'); - - $group = get_entity($group_guid); - - if($group){ - - //get the action, is it to feature or unfeature - if($action == "feature"){ - - $group->featured_group = "yes"; - system_message(elgg_echo('groups:featuredon')); - - } - - if($action == "unfeature"){ - - $group->featured_group = "no"; - system_message(elgg_echo('groups:unfeatured')); - - } - + +$group_guid = get_input('group_guid'); +$action = get_input('action_type'); + +$group = get_entity($group_guid); + +if ($group) { + //get the action, is it to feature or unfeature + if ($action == "feature") { + $group->featured_group = "yes"; + system_message(elgg_echo('groups:featuredon')); } - - forward(REFERER);
\ No newline at end of file + + if ($action == "unfeature") { + $group->featured_group = "no"; + system_message(elgg_echo('groups:unfeatured')); + } +} + +forward(REFERER); diff --git a/mod/groups/actions/groupskillinvitation.php b/mod/groups/actions/groupskillinvitation.php index c5f1d9bf5..503c41939 100644 --- a/mod/groups/actions/groupskillinvitation.php +++ b/mod/groups/actions/groupskillinvitation.php @@ -1,26 +1,20 @@ <?php - /** - * Delete an invitation to join a closed group. - * - * @package ElggGroups - */ +/** + * Delete an invitation to join a closed group. + * + * @package ElggGroups + */ - // Load configuration - global $CONFIG; +$user_guid = get_input('user_guid', get_loggedin_userid()); +$group_guid = get_input('group_guid'); - $user_guid = get_input('user_guid', get_loggedin_userid()); - $group_guid = get_input('group_guid'); +$user = get_entity($user_guid); +$group = get_entity($group_guid); - $user = get_entity($user_guid); - $group = get_entity($group_guid); +// 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")); +} - // 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); - -?>
\ No newline at end of file +forward(REFERER); diff --git a/mod/groups/actions/groupskillrequest.php b/mod/groups/actions/groupskillrequest.php index 7b53fe37b..f7f8a5157 100644 --- a/mod/groups/actions/groupskillrequest.php +++ b/mod/groups/actions/groupskillrequest.php @@ -1,26 +1,20 @@ <?php - /** - * Delete a user request to join a closed group. - * - * @package ElggGroups - */ +/** + * Delete a user request to join a closed group. + * + * @package ElggGroups + */ - // Load configuration - global $CONFIG; - - $user_guid = get_input('user_guid', get_loggedin_userid()); - $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); - -?>
\ No newline at end of file +$user_guid = get_input('user_guid', get_loggedin_userid()); +$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/invite.php b/mod/groups/actions/invite.php index eef8fb5ce..e8eeb3330 100644 --- a/mod/groups/actions/invite.php +++ b/mod/groups/actions/invite.php @@ -1,63 +1,54 @@ <?php - /** * Invite a user to join a group * * @package ElggGroups */ -// Load configuration -global $CONFIG; - $logged_in_user = get_loggedin_user(); $user_guid = get_input('user_guid'); -if (!is_array($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) - { +if (sizeof($user_guid)) { + foreach ($user_guid as $u_id) { $user = get_entity($u_id); $group = get_entity($group_guid); if ( $user && $group) { - if (($group instanceof ElggGroup) && ($group->canEdit())) - { - if (!check_entity_relationship($group->guid, 'invited', $user->guid)) - { - if ($user->isFriend()) - { + if (($group instanceof ElggGroup) && ($group->canEdit())) { + if (!check_entity_relationship($group->guid, 'invited', $user->guid)) { + if ($user->isFriend()) { // Create relationship add_entity_relationship($group->guid, 'invited', $user->guid); // Send email - $url = "{$CONFIG->url}pg/groups/invitations/{$user->username}"; - if (notify_user($user->getGUID(), $group->owner_guid, + $url = elgg_normalize_url("pg/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)) + NULL); + if ($result) { system_message(elgg_echo("groups:userinvited")); - else + } else { register_error(elgg_echo("groups:usernotinvited")); - - } - else + } + } else { register_error(elgg_echo("groups:usernotinvited")); - } - else + } + } else { register_error(elgg_echo("groups:useralreadyinvited")); - } - else + } + } else { register_error(elgg_echo("groups:notowner")); + } } } } forward(REFERER); - -?> diff --git a/mod/groups/actions/join.php b/mod/groups/actions/join.php index 95c9660ff..e058cdc22 100644 --- a/mod/groups/actions/join.php +++ b/mod/groups/actions/join.php @@ -1,61 +1,50 @@ <?php - /** - * Join a group action. - * - * @package ElggGroups - */ +/** + * Join a group action. + * + * @package ElggGroups + */ - // Load configuration - global $CONFIG; +$user_guid = get_input('user_guid', get_loggedin_userid()); +$group_guid = get_input('group_guid'); - $user_guid = get_input('user_guid', get_loggedin_userid()); - $group_guid = get_input('group_guid'); +// @todo fix for #287 +// disable access to get entity. +$invitations = groups_get_invited_groups($user_guid, TRUE); - // @todo fix for #287 - // disable access to get entity. - $invitations = groups_get_invited_groups($user_guid, TRUE); +if (in_array($group_guid, $invitations)) { + $ia = elgg_set_ignore_access(TRUE); +} - if (in_array($group_guid, $invitations)) { - $ia = elgg_set_ignore_access(TRUE); - } - - $user = get_entity($user_guid); - $group = get_entity($group_guid); +$user = get_entity($user_guid); +$group = get_entity($group_guid); - set_page_owner($group->guid); +set_page_owner($group->guid); - if (($user instanceof ElggUser) && ($group instanceof ElggGroup)) - { - if ($group->isPublicMembership() || $group->canEdit($user->guid)) - { - if ($group->join($user)) - { - system_message(elgg_echo("groups:joined")); +if (($user instanceof ElggUser) && ($group instanceof ElggGroup)) { + if ($group->isPublicMembership() || $group->canEdit($user->guid)) { + if ($group->join($user)) { + system_message(elgg_echo("groups:joined")); - // Remove any invite or join request flags - remove_entity_relationship($group->guid, 'invited', $user->guid); - remove_entity_relationship($user->guid, 'membership_request', $group->guid); + // Remove any invite or join request flags + remove_entity_relationship($group->guid, 'invited', $user->guid); + remove_entity_relationship($user->guid, 'membership_request', $group->guid); - // add to river - add_to_river('river/relationship/member/create','join',$user->guid,$group->guid); + // add to river + add_to_river('river/relationship/member/create','join',$user->guid,$group->guid); - forward($group->getURL()); - exit; - } - else - register_error(elgg_echo("groups:cantjoin")); - } - else - { - // Closed group, request membership - system_message(elgg_echo('groups:privategroup')); - forward(elgg_add_action_tokens_to_url("action/groups/joinrequest?user_guid=$user_guid&group_guid=$group_guid", FALSE)); - exit; + forward($group->getURL()); + } else { + register_error(elgg_echo("groups:cantjoin")); } + } else { + // Closed group, request membership + system_message(elgg_echo('groups:privategroup')); + forward(elgg_add_action_tokens_to_url("action/groups/joinrequest?user_guid=$user_guid&group_guid=$group_guid", FALSE)); } - else - register_error(elgg_echo("groups:cantjoin")); +} else { + register_error(elgg_echo("groups:cantjoin")); +} + +forward(REFERER); - forward(REFERER); - exit; -?> diff --git a/mod/groups/actions/joinrequest.php b/mod/groups/actions/joinrequest.php index b61afbed6..c1d41e8e8 100644 --- a/mod/groups/actions/joinrequest.php +++ b/mod/groups/actions/joinrequest.php @@ -5,9 +5,6 @@ * @package ElggGroups */ -// Load configuration -global $CONFIG; - $user_guid = get_input('user_guid', get_loggedin_userid()); $group_guid = get_input('group_guid'); @@ -27,17 +24,14 @@ $group = get_entity($group_guid); set_page_owner($group->guid); // If not a member of this group -if (($group) && ($user) && (!$group->isMember($user))) -{ +if (($group) && ($user) && (!$group->isMember($user))) { // If open group or invite exists if ( ($group->isPublicMembership()) || (check_entity_relationship($group->guid, 'invited', $user->guid)) - ) - { + ) { //$ia = elgg_set_ignore_access(TRUE); - if ($group->join($user)) - { + if ($group->join($user)) { // Remove relationships remove_entity_relationship($group->guid, 'invited', $user->guid); remove_entity_relationship($user->guid, 'membership_request', $group->guid); @@ -47,33 +41,29 @@ if (($group) && ($user) && (!$group->isMember($user))) elgg_set_ignore_access($ia); forward($group->getURL()); - exit; - } - else { + } else { elgg_set_ignore_access($ia); system_message(elgg_echo('groups:cantjoin')); } - } - else - { + } else { // If join request not already made - if (!check_entity_relationship($user->guid, 'membership_request', $group->guid)) - { + if (!check_entity_relationship($user->guid, 'membership_request', $group->guid)) { // Add membership requested add_entity_relationship($user->guid, 'membership_request', $group->guid); // Send email - $url = "{$CONFIG->url}mod/groups/membershipreq.php?group_guid={$group->guid}"; + $url = elgg_normalize_url("mod/groups/membershipreq.php?group_guid={$group->guid}"); if (notify_user($group->owner_guid, $user->getGUID(), elgg_echo('groups:request:subject', array($user->name, $group->name)), elgg_echo('groups:request:body', array($group->getOwnerEntity()->name, $user->name, $group->name, $user->getURL(), $url)), - NULL)) + NULL)) { system_message(elgg_echo("groups:joinrequestmade")); - else + } else { register_error(elgg_echo("groups:joinrequestnotmade")); - } - else + } + } else { system_message(elgg_echo("groups:joinrequestmade")); + } } } diff --git a/mod/groups/actions/leave.php b/mod/groups/actions/leave.php index ebb473817..a9163a3d1 100644 --- a/mod/groups/actions/leave.php +++ b/mod/groups/actions/leave.php @@ -1,39 +1,36 @@ <?php - /** - * Leave a group action. - * - * @package ElggGroups - */ +/** + * Leave a group action. + * + * @package ElggGroups + */ - // Load configuration - global $CONFIG; - - $user_guid = get_input('user_guid'); - $group_guid = get_input('group_guid'); - - $user = NULL; - if (!$user_guid) $user = get_loggedin_user(); - else - $user = get_entity($user_guid); - - $group = get_entity($group_guid); +$user_guid = get_input('user_guid'); +$group_guid = get_input('group_guid'); - set_page_owner($group->guid); - - if (($user instanceof ElggUser) && ($group instanceof ElggGroup)) - { - if ($group->getOwnerGUID() != get_loggedin_userid()) { - if ($group->leave($user)) - system_message(elgg_echo("groups:left")); - else - register_error(elgg_echo("groups:cantleave")); +$user = NULL; +if (!$user_guid) { + $user = get_loggedin_user(); +} else { + $user = get_entity($user_guid); +} + +$group = get_entity($group_guid); + +set_page_owner($group->guid); + +if (($user instanceof ElggUser) && ($group instanceof ElggGroup)) { + if ($group->getOwnerGUID() != get_loggedin_userid()) { + if ($group->leave($user)) { + system_message(elgg_echo("groups:left")); } else { register_error(elgg_echo("groups:cantleave")); } - } - else + } else { register_error(elgg_echo("groups:cantleave")); - - forward(REFERER); - exit; -?>
\ No newline at end of file + } +} else { + register_error(elgg_echo("groups:cantleave")); +} + +forward(REFERER); |